| plan 9 kernel history: overview | file list | diff list |
1994/0809/pc/clock.c (diff list | history)
| 1994/0806/sys/src/9/pc/clock.c:27,33 – 1994/0809/sys/src/9/pc/clock.c:27,34 (short | long | prev | next) | ||
|
use cpufreq and cpumhz.
preempt user processes even in kernel. (BUG fix?)
start with longer loops for 586+ (hw BUG fix?)
rsc Fri Mar 4 12:44:25 2005 | ||
| 1992/0923 | Freq= 1193182, /* Real clock frequency */ | |
| 1991/0705 | }; | |
| 1994/0716 |
| |
| 1994/0809 | static int cpufreq = 66000000; static int cpumhz = 66; | |
| 1994/0716 | static int cputype = 486; static int loopconst = 100; | |
| 1992/0923 | ||
| 1994/0806/sys/src/9/pc/clock.c:59,72 – 1994/0809/sys/src/9/pc/clock.c:60,75 | ||
| 1993/1124 | nrun = (nrdy+nrun)*1000; MACHP(0)->load = (MACHP(0)->load*19+nrun)/20; | |
| 1994/0507 |
| |
| 1994/0809 | if(up && up->state == Running){ | |
| 1994/0507 | if(anyready()) sched(); /* user profiling clock */ | |
| 1994/0512 |
| |
| 1994/0507 |
| |
| 1994/0809 | if((ur->cs&0xffff) == UESEL){ islow = 1; spllo(); /* in case we fault */ (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); } | |
| 1994/0507 | } | |
| 1993/1124 | ||
| 1994/0512 | /* | |
| 1994/0806/sys/src/9/pc/clock.c:96,102 – 1994/0809/sys/src/9/pc/clock.c:99,105 | ||
| 1994/0302 | void printcpufreq(void) { | |
| 1994/0719 |
| |
| 1994/0809 | print("CPU is a %ud MHz (%ud Hz) %d\n", cpumhz, cpufreq, cputype); | |
| 1994/0302 | } | |
| 1991/0704 | void | |
| 1994/0806/sys/src/9/pc/clock.c:105,110 – 1994/0809/sys/src/9/pc/clock.c:108,128 | ||
| 1992/0923 | ulong x, y; /* change in counter */ | |
| 1994/0716 | ulong cycles, loops; | |
| 1992/0922 | ||
| 1994/0809 | switch(cputype = x86()){ case 386: loops = 10000; cycles = 32; break; case 486: loops = 10000; cycles = 22; break; default: loops = 30000; cycles = 23; break; } | |
| 1991/0709 | /* * set vector for clock interrupts */ | |
| 1994/0806/sys/src/9/pc/clock.c:117,122 – 1994/0809/sys/src/9/pc/clock.c:135,141 | ||
| 1991/0709 | outb(T0cntr, (Freq/HZ)); /* low byte */ outb(T0cntr, (Freq/HZ)>>8); /* high byte */ | |
| 1992/0922 | ||
| 1994/0809 | ||
| 1992/0922 | /* | |
| 1994/0716 | * measure time for the loop * | |
| 1994/0806/sys/src/9/pc/clock.c:129,135 – 1994/0809/sys/src/9/pc/clock.c:148,153 | ||
| 1994/0716 | * prefetch buffer. * | |
| 1992/0922 | */ | |
| 1994/0716 |
| |
| 1992/0922 | outb(Tmode, Latch0); | |
| 1992/0923 | x = inb(T0cntr); x |= inb(T0cntr)<<8; | |
| 1994/0806/sys/src/9/pc/clock.c:141,147 – 1994/0809/sys/src/9/pc/clock.c:159,165 | ||
| 1992/0923 | /* | |
| 1994/0716 | * counter goes at twice the frequency, once per transition, | |
| 1994/0809 | * i.e., twice per square wave | |
| 1992/0923 | */ | |
| 1994/0716 | x >>= 1; | |
| 1994/0806/sys/src/9/pc/clock.c:148,167 – 1994/0809/sys/src/9/pc/clock.c:166,176 | ||
| 1994/0716 | /* * figure out clock frequency and a loop multiplier for delay(). */ | |
| 1994/0719 |
| |
| 1994/0716 |
| |
| 1994/0717 |
| |
| 1994/0716 |
| |
| 1994/0806 |
| |
| 1994/0716 |
| |
| 1994/0717 | cpufreq = loops*((cycles*Freq)/x); | |
| 1994/0716 | loopconst = (cpufreq/1000)/cycles; /* AAM+LOOP's for 1 ms */ | |
| 1994/0719 |
| |
| 1994/0809 | /* * add in possible .1% error and convert to MHz */ cpumhz = (cpufreq + cpufreq/1000)/1000000; | |
| 1991/0808 | } | |