plan 9 kernel history: overview | file list | diff list

1994/0716/pc/clock.c (diff list | history)

1994/0715/sys/src/9/pc/clock.c:27,481994/0716/sys/src/9/pc/clock.c:27,36 (short | long | prev | next)
switch from delay to aamloop (XXX why?)
rsc Fri Mar 4 12:44:25 2005
1992/0923    
	Freq=	1193182,	/* Real clock frequency */ 
1991/0705    
}; 
 
1992/0923    
static ulong delayloop = 1000; 
1994/0716    
static int cpufreq = 66; 
static int cputype = 486; 
static int loopconst = 100; 
1992/0923    
 
1991/0719    
/* 
1992/0923    
 *  delay for l milliseconds more or less.  delayloop is set by 
 *  clockinit() to match the actual CPU speed. 
1991/0719    
 */ 
void 
delay(int l) 
{ 
1992/0923    
	ulong i; 
1991/0719    
                 
1992/0923    
	while(l-- > 0) 
		for(i=0; i < delayloop; i++) 
1991/0719    
			; 
} 
                 
1993/1124    
static void 
clock(Ureg *ur, void *arg) 
{ 
1994/0715/sys/src/9/pc/clock.c:95,1311994/0716/sys/src/9/pc/clock.c:83,103
1994/0512    
		splhi(); 
1993/1124    
} 
 
1994/0716    
 
1994/0302    
/* 
1994/0610    
 *  experimentally determined 
1994/0716    
 *  delay for l milliseconds more or less.  delayloop is set by 
 *  clockinit() to match the actual CPU speed. 
1994/0302    
 */ 
enum 
1994/0716    
void 
delay(int l) 
1994/0302    
{ 
	mul386=	380, 
	mul486=	121, 
1994/0610    
	mul586=	121, 
1994/0302    
}; 
1994/0716    
	aamloop(l*loopconst); 
} 
1994/0302    
 
void 
printcpufreq(void) 
{ 
	ulong freq; 
	int cpu; 
                 
	switch(cpu = x86()){ 
	default: 
1994/0610    
	case 586: 
		freq = mul586; 
		break; 
1994/0302    
	case 486: 
		freq = mul486; 
		break; 
	case 386: 
		freq = mul386; 
		break; 
	} 
	freq *= delayloop; 
	freq /= 10000; 
	print("CPU is a %ud MHz %d\n", freq, cpu); 
1994/0716    
	print("CPU is a %ud Hz %d\n", cpufreq, cputype); 
1994/0302    
} 
 
1991/0704    
void 
1994/0715/sys/src/9/pc/clock.c:132,1371994/0716/sys/src/9/pc/clock.c:104,110
1991/0704    
clockinit(void) 
{ 
1992/0923    
	ulong x, y;	/* change in counter */ 
1994/0716    
	ulong cycles, loops; 
1992/0922    
 
1991/0709    
	/* 
	 *  set vector for clock interrupts 
1994/0715/sys/src/9/pc/clock.c:146,1571994/0716/sys/src/9/pc/clock.c:119,140
1991/0709    
	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */ 
1992/0922    
 
	/* 
1992/0923    
	 *  measure time for delay(10) with current delayloop count 
1994/0716    
	 *  measure time for the loop 
	 * 
	 *			MOVL	loops,CX 
	 *	aaml1:	 	AAM 
	 *			LOOP	aaml1 
	 * 
	 *  the time for the loop should be independent from external 
	 *  cache's and memory system since it fits in the execution 
	 *  prefetch buffer. 
	 * 
1992/0922    
	 */ 
1994/0716    
	loops = 10000; 
1992/0922    
	outb(Tmode, Latch0); 
1992/0923    
	x = inb(T0cntr); 
	x |= inb(T0cntr)<<8; 
	delay(10); 
1994/0716    
	aamloop(loops); 
1992/0923    
	outb(Tmode, Latch0); 
	y = inb(T0cntr); 
	y |= inb(T0cntr)<<8; 
1994/0715/sys/src/9/pc/clock.c:158,1661994/0716/sys/src/9/pc/clock.c:141,165
1992/0923    
	x -= y; 
 
	/* 
1993/0915    
	 *  fix count 
1994/0716    
	 *  counter  goes at twice the frequency, once per transition, 
	 *  i.e., twice per the square wave 
1992/0923    
	 */ 
	delayloop = (delayloop*1193*10)/x; 
	if(delayloop == 0) 
		delayloop = 1; 
1994/0716    
	x >>= 1; 
 
	/* 
 	 *  figure out clock frequency and a loop multiplier for delay(). 
	 */ 
	switch(cputype = x86()){ 
	case 386: 
		cycles = 30; 
		break; 
	case 486: 
		cycles = 24; 
		break; 
	default: 
		cycles = 23; 
		break; 
	} 
	cpufreq = (cycles*loops) * (Freq/x); 
	loopconst = (cpufreq/1000)/cycles;	/* AAM+LOOP's for 1 ms */ 
1991/0808    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)