rem: system_time_setup((int)((time_base_ticks / timer_usecs) * 1000000));
add: expired = ((s_high << 8) | s_low) - ((high << 8) | low); p3 *= TIMER_CLKNUM_HZ;   { unsigned i; unsigned k; uint64 C; uint64 x0; uint64 x1; uint64 a, b, c;   k = 0; for (i = 0; i< 32; i++) { if (expired & (1<<i)) k = i; } k /= 3;  C = 1000000ULL << 32; x0 = expired >> k; x1 = expired & ((1 << k) - 1);  a = ((C * x0) / p3) << k; b = (((C * x0) % p3) << k) / p3; c = (C * x1) / p3; #if 0 dprintf("a=%Ld\n", a); dprintf("b=%Ld\n", b); dprintf("c=%Ld\n", c); dprintf("%d %Ld\n", expired, p3); #endif cv_factor = a + b + c; #if 0 dprintf("cvf=%Ld\n", cv_factor); #endif }  if (p3 / expired / 1000000000LL) dprintf("CPU at %Ld.%03Ld GHz\n", p3/expired/1000000000LL, ((p3/expired)%1000000000LL)/1000000LL); else dprintf("CPU at %Ld.%03Ld MHz\n", p3/expired/1000000LL, ((p3/expired)%1000000LL)/1000LL);
context: static void calculate_cpu_conversion_factor(void){	unsigned char	low, high;	unsigned long	expired;	long long		t1, t2;	long long       time_base_ticks;	double			timer_usecs;	/* program the timer to count down mode */	outb(0x34, 0x43);	outb(0xff, 0x40);		/* low and then high */	outb(0xff, 0x40);	t1 = rdtsc();	execute_n_instructions(32*20000);	t2 = rdtsc();	outb(0x00, 0x43); /* latch counter value */	low = inb(0x40);	high = inb(0x40);	expired = (unsigned long)0xffff - ((((unsigned long)high) << 8) + low);	timer_usecs = (expired * 1.0) / (TIMER_CLKNUM_HZ/1000000.0);	time_base_ticks = t2 -t1;	dprintf("CPU at %d Hz\n", (int)((time_base_ticks / timer_usecs) * 1000000));	system_time_setup((int)((time_base_ticks / timer_usecs) * 1000000));}