FreeBSD/sys/amd64/amd64/prof_machdep.c
/*
 * Return the time elapsed since the last call.  The units are machine-
 * dependent.
 */
Return the time elapsed since the last call.  The units are machine
dependent.
Return the time elapsed since the last call . The units are machine dependent .
int
cputime()
{
	u_int count;
	int delta;
#if defined(PERFMON) && defined(I586_PMC_GUPROF) && !defined(SMP)
	u_quad_t event_count;
#endif
	u_char high, low;
	static u_int prev_count;
	if (cputime_clock == CPUTIME_CLOCK_TSC) {
		count = (u_int)rdtsc() & ~1u;
		delta = (int)(count - prev_count) >> 1;
		prev_count = count;
		return (delta);
	}
#if defined(PERFMON) && defined(I586_PMC_GUPROF) && !defined(SMP)
	if (cputime_clock == CPUTIME_CLOCK_I586_PMC) {
		perfmon_read(0, &event_count);
		count = (u_int)event_count;
		delta = (int)(count - prev_count);
		prev_count = count;
		return (delta);
	}
#endif 
	outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
	low = inb(TIMER_CNTR0);
	high = inb(TIMER_CNTR0);
	count = ((high << 8) | low) << CPUTIME_CLOCK_I8254_SHIFT;
	delta = prev_count - count;
	prev_count = count;
	if ((int) delta <= 0)
		return (delta + (i8254_max_count << CPUTIME_CLOCK_I8254_SHIFT));
	return (delta);
}
int cputime ( ) { u_int count ; int delta ; #if defined ( PERFMON ) && defined ( I586_PMC_GUPROF ) && ! defined ( SMP ) u_quad_t event_count ; #endif u_char high , low ; static u_int prev_count ; if ( cputime_clock == CPUTIME_CLOCK_TSC ) { count = ( u_int ) rdtsc ( ) & ~ 1u ; delta = ( int ) ( count - prev_count ) >> 1 ; prev_count = count ; return ( delta ) ; } #if defined ( PERFMON ) && defined ( I586_PMC_GUPROF ) && ! defined ( SMP ) if ( cputime_clock == CPUTIME_CLOCK_I586_PMC ) { perfmon_read ( 0 , & event_count ) ; count = ( u_int ) event_count ; delta = ( int ) ( count - prev_count ) ; prev_count = count ; return ( delta ) ; } #endif outb ( TIMER_MODE , TIMER_SEL0 | TIMER_LATCH ) ; low = inb ( TIMER_CNTR0 ) ; high = inb ( TIMER_CNTR0 ) ; count = ( ( high << 8 ) | low ) << CPUTIME_CLOCK_I8254_SHIFT ; delta = prev_count - count ; prev_count = count ; if ( ( int ) delta <= 0 ) return ( delta + ( i8254_max_count << CPUTIME_CLOCK_I8254_SHIFT ) ) ; return ( delta ) ; }
Return the time elapsed since the last call.
Return the time elapsed since the last call .
/*
		 * Scale the TSC a little to make cputime()'s frequency
		 * fit in an int, assuming that the TSC frequency fits
		 * in a u_int.  Use a fixed scale since dynamic scaling
		 * would be slower and we can't really use the low bit
		 * of precision.
		 */ /*
		 * XXX permon_read() should be inlined so that the
		 * perfmon module doesn't need to be compiled with
		 * profiling disabled and so that it is fast.
		 */ /* PERFMON && I586_PMC_GUPROF && !SMP */ /*
	 * Read the current value of the 8254 timer counter 0.
	 */ /*
	 * The timer counts down from TIMER_CNTR0_MAX to 0 and then resets.
	 * While profiling is enabled, this routine is called at least twice
	 * per timer reset (for mcounting and mexitcounting hardclock()),
	 * so at most one reset has occurred since the last call, and one
	 * has occurred iff the current count is larger than the previous
	 * count.  This allows counter underflow to be detected faster
	 * than in microtime().
	 */