FreeBSD/sys/kern/kern_tc.c
/*
 * We need to be slightly careful converting cputicks to microseconds.
 * There is plenty of margin in 64 bits of microseconds (half a million
 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply
 * before divide conversion (to retain precision) we find that the
 * margin shrinks to 1.5 hours (one millionth of 146y).
 * With a three prong approach we never lose significant bits, no
 * matter what the cputick rate and length of timeinterval is.
 */
We need to be slightly careful converting cputicks to microseconds.
There is plenty of margin in 64 bits of microseconds (half a million
years) and in 64 bits at 4 GHz (146 years), but if we do a multiply
before divide conversion (to retain precision) we find that the
margin shrinks to 1.5 hours (one millionth of 146y).
With a three prong approach we never lose significant bits, no
matter what the cputick rate and length of timeinterval is.
We need to be slightly careful converting cputicks to microseconds . There is plenty of margin in 64 bits of microseconds ( half a million years ) and in 64 bits at 4 GHz ( 146 years ) but if we do a multiply before divide conversion ( to retain precision ) we find that the margin shrinks to 1 . 5 hours ( one millionth of 146y ) . With a three prong approach we never lose significant bits no matter what the cputick rate and length of timeinterval is .
uint64_t
cputick2usec(uint64_t tick)
{
	if (tick > 18446744073709551LL)		
		return (tick / (cpu_tickrate() / 1000000LL));
	else if (tick > 18446744073709LL)	
		return ((tick * 1000LL) / (cpu_tickrate() / 1000LL));
	else
		return ((tick * 1000000LL) / cpu_tickrate());
}
uint64_t cputick2usec ( uint64_t tick ) { if ( tick > 18446744073709551LL ) return ( tick / ( cpu_tickrate ( ) / 1000000LL ) ) ; else if ( tick > 18446744073709LL ) return ( ( tick * 1000LL ) / ( cpu_tickrate ( ) / 1000LL ) ) ; else return ( ( tick * 1000000LL ) / cpu_tickrate ( ) ) ; }
We need to be slightly careful converting cputicks to microseconds.
We need to be slightly careful converting cputicks to microseconds .
/* floor(2^64 / 1000) */ /* floor(2^64 / 1000000) */