powerpc64 and 32-bit powerpc: get_cyclecount is messed up for both (presuming reliability is required)
Mark Millard
marklmi at yahoo.com
Wed May 15 04:08:49 UTC 2019
[I ignore here the difference between a processor-cycle-count
and the timebase register values, a distinction that might be
involved as well. This is just about tbr access techniques.]
/usr/src/sys/powerpc/include/cpu.h has:
static __inline u_int64_t
get_cyclecount(void)
{
u_int32_t _upper, _lower;
u_int64_t _time;
__asm __volatile(
"mftb %0\n"
"mftbu %1"
: "=r" (_lower), "=r" (_upper));
_time = (u_int64_t)_upper;
_time = (_time << 32) + _lower;
return (_time);
}
Apparently used for both powerpc64 and 32-bit powerpc.
By contrast /usr/src/sys/powerpc/include/cpufunc.h
has:
static __inline u_quad_t
mftb(void)
{
u_quad_t tb;
#ifdef __powerpc64__
__asm __volatile ("mftb %0" : "=r"(tb));
#else
uint32_t *tbup = (uint32_t *)&tb;
uint32_t *tblp = tbup + 1;
do {
*tbup = mfspr(TBR_TBU);
*tblp = mfspr(TBR_TBL);
} while (*tbup != mfspr(TBR_TBU));
#endif
return (tb);
}
Back to get_cyclecount: Note the lack of
the loop for making sure the upper and
lower halves go together (upper half did
not change).
Note also that for powerpc64 there is a
more direct access available that avoids
needing to deal with such issues.
get_cyclecount seems to be referenced in:
# grep -lr get_cyclecount /usr/src/sys/ | grep -v /include/ | more
/usr/src/sys/dev/hwpmc/hwpmc_mod.c
/usr/src/sys/dev/ocs_fc/ocs_utils.c
/usr/src/sys/dev/random/random_harvestq.c
/usr/src/sys/dev/random/randomdev.c
/usr/src/sys/dev/random/unit_test.h
/usr/src/sys/dev/de/if_devar.h
/usr/src/sys/kern/init_main.c
/usr/src/sys/kern/subr_bus.c
/usr/src/sys/kern/kern_tslog.c
/usr/src/sys/kern/kern_ktr.c
/usr/src/sys/netinet/sctp_os_bsd.h
/usr/src/sys/libkern/arc4random.c
/random/ and arc4random might well not care abouy
extra variability. But the others?
===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)
More information about the freebsd-ppc
mailing list