~kris/9p

9hist

7c2b0b76d719f83699161f77270c5b1c8fef0d53 — David du Colombier 31 years ago b1ec3ce
Plan 9 from Bell Labs 1994-11-01
2 files changed, 47 insertions(+), 44 deletions(-)

M pc/clock.c
M pc/l.s
M pc/clock.c => pc/clock.c +42 -41
@@ 127,8 127,8 @@ delay(int l)
void
printcpufreq(void)
{
	print("CPU is a %ud Hz %d (CPUID: AX=0x%8.8lux, DX=0x%8.8lux)\n",
		cpufreq, cputype, cpuidax, cpuiddx);
	print("CPU is a %d MHz %s (cpuid: ax %lux dx %lux)\n",
		cpumhz, cputype->name, cpuidax, cpuiddx);
}

int


@@ 170,45 170,46 @@ clockinit(void)
	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */

	/* use biggest loop that works */
	for(loops = 10000; ; loops += 5000) {
		/*
		 *  measure time for the loop
		 *
		 *			MOVL	loops,CX
		 *	aaml1:	 	AAM
		 *			LOOP	aaml1
		 *
		 *  the time for the loop should be independent of external
		 *  cache and memory system since it fits in the execution
		 *  prefetch buffer.
		 *
		 */
		outb(Tmode, Latch0);
		x = inb(T0cntr);
		x |= inb(T0cntr)<<8;
		aamloop(loops);
		outb(Tmode, Latch0);
		y = inb(T0cntr);
		y |= inb(T0cntr)<<8;
		x -= y;

		if(x < 0)
			x += 2^16;
		if(x > (2^15))
			break;
	
		/*
		 *  counter  goes at twice the frequency, once per transition,
		 *  i.e., twice per square wave
		 */
		x >>= 1;

		/*
	 	 *  figure out clock frequency and a loop multiplier for delay().
		 */
		cpufreq = loops*((t->aalcycles*Freq)/x);
		loopconst = (cpufreq/1000)/t->aalcycles;	/* AAM+LOOP's for 1 ms */
	} while(x > 0);
	if(t->family == 3)
		loops = 10000;
	else
		loops = 30000;

	/*
	 *  measure time for the loop
	 *
	 *			MOVL	loops,CX
	 *	aaml1:	 	AAM
	 *			LOOP	aaml1
	 *
	 *  the time for the loop should be independent of external
	 *  cache and memory system since it fits in the execution
	 *  prefetch buffer.
	 *
	 */
	outb(Tmode, Latch0);
	x = inb(T0cntr);
	x |= inb(T0cntr)<<8;
	aamloop(loops);
	outb(Tmode, Latch0);
	y = inb(T0cntr);
	y |= inb(T0cntr)<<8;
	x -= y;

	if(x < 0)
		x += 2^16;

	/*
	 *  counter  goes at twice the frequency, once per transition,
	 *  i.e., twice per square wave
	 */
	x >>= 1;

	/*
 	 *  figure out clock frequency and a loop multiplier for delay().
	 */
	cpufreq = loops*((t->aalcycles*Freq)/x);
	loopconst = (cpufreq/1000)/t->aalcycles;	/* AAM+LOOP's for 1 ms */

	/*
	 *  add in possible .1% error and convert to MHz

M pc/l.s => pc/l.s +5 -3
@@ 600,10 600,12 @@ is386:
	MOVL	$(3<<8),AX
	MOVL	$0,DX
done:
	MOVL	AX, a+0(FP)
	MOVL	DX, d+4(FP)
	POPL	BX
	MOVL	a+0(FP),CX
	MOVL	AX,0(CX)
	MOVL	d+4(FP),CX
	MOVL	DX,0(CX)
	POPFL
	POPL	BX
	RET

/*