示例#1
0
/*
 * Start the real-time and statistics clocks. Leave stathz 0 since there
 * are no other timers available.
 */
void
cpu_initclocks()
{
	if (clockdev == NULL)
		panic("cpu_initclocks: no clock attached");

	tick = 1000000 / hz;	/* number of microseconds between interrupts */
	tickfix = 1000000 - (hz * tick);
	if (tickfix) {
		int ftp;

		ftp = min(ffs(tickfix), ffs(hz));
		tickfix >>= (ftp - 1);
		tickfixinterval = hz >> (ftp - 1);
        }

	/*
	 * Establish the clock interrupt; it's a special case.
	 *
	 * We establish the clock interrupt this late because if
	 * we do it at clock attach time, we may have never been at
	 * spl0() since taking over the system.  Some versions of
	 * PALcode save a clock interrupt, which would get delivered
	 * when we spl0() in autoconf.c.  If established the clock
	 * interrupt handler earlier, that interrupt would go to
	 * hardclock, which would then fall over because p->p_stats
	 * isn't set at that time.
	 */
	last_time = alpha_rpcc();
	scaled_ticks_per_cycle = ((u_int64_t)hz << FIX_SHIFT) / cycles_per_sec;
	max_cycles_per_tick = 2*cycles_per_sec / hz;

	alpha_timecounter.tc_frequency = cycles_per_sec;
	init_timecounter(&alpha_timecounter);

	platform.clockintr = (void (*) __P((void *))) handleclock;

	/*
	 * Get the clock started.
	 */
	CLOCK_INIT(clockdev);
}
示例#2
0
int main() {
	// show the monotonic time
	// the latency for doing nothing
	// with take 200 ~ 300 ns
	CLOCK_INIT(mono);
	CLOCK_MONO_BEGIN(mono);
	CLOCK_MONO_END(mono);
	CLOCK_PRINT(mono);

	Clock::StructRdtsc s, e;
	uint64_t d;

	for (int i = 0; i < 1000; i++) {
		Clock::rdtsc(s);
		sleep(1);
		Clock::rdtsc(e);
	
		// see how many cycles rdtsc needs
		d = e.cycles - s.cycles;
	
		std::cout << d << std::endl;
	}
}