From 6ba12646420904a02b9be97c595b3f9cf83e10ff Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 31 Jan 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-01-31 --- pc/archgeneric.c | 2 +- pc/dat.h | 1 + pc/fns.h | 2 +- pc/i8253.c | 39 +++++++++++++++++++++++++++------------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/pc/archgeneric.c b/pc/archgeneric.c index 3ee0ea9524cf7287acd50522070db05f91159a60..03332fb422bf48c1286580440e45a0f79a6c2eb2 100644 --- a/pc/archgeneric.c +++ b/pc/archgeneric.c @@ -138,7 +138,7 @@ cpuidentify(void) t++; } m->cpuidtype = t->name; - i8253init(t->aalcycles); + i8253init(t->aalcycles, t->family >= 5); /* * If machine check exception or page size extensions are supported diff --git a/pc/dat.h b/pc/dat.h index eb2954a5b0289911930aa8bdb309c6785f4e705d..6bb941028209254916bbee1857cdfb333d22cdd0 100644 --- a/pc/dat.h +++ b/pc/dat.h @@ -179,6 +179,7 @@ struct Mach int loopconst; int cpumhz; + int cpuhz; int cpuidax; int cpuiddx; char cpuidid[16]; diff --git a/pc/fns.h b/pc/fns.h index d2113e242f5476d32819c3663b234a2a59940119..453536699cfcc77bd053149abf49472b34694ead 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -34,7 +34,7 @@ char* getconf(char*); int i8042auxcmd(int); void i8042auxenable(void (*)(int, int)); void i8042reset(void); -void i8253init(int); +void i8253init(int, int); void i8253enable(void); uvlong i8253read(uvlong*); void i8259init(void); diff --git a/pc/i8253.c b/pc/i8253.c index eebf08742866c599aa57e211a78538fd87dfee23..0e35c9934c99ebdeab0a3e5d2896c42b2c5de8fd 100644 --- a/pc/i8253.c +++ b/pc/i8253.c @@ -27,9 +27,10 @@ enum }; void -i8253init(int aalcycles) +i8253init(int aalcycles, int havecycleclock) { int cpufreq, loops, incr, x, y; + vlong a, b; static int initialised; if(initialised == 0){ @@ -75,10 +76,14 @@ i8253init(int aalcycles) * */ outb(Tmode, Latch0); + if(havecycleclock) + rdmsr(0x10, &a); x = inb(T0cntr); x |= inb(T0cntr)<<8; aamloop(loops); outb(Tmode, Latch0); + if(havecycleclock) + rdmsr(0x10, &b); y = inb(T0cntr); y |= inb(T0cntr)<<8; x -= y; @@ -90,22 +95,32 @@ i8253init(int aalcycles) 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(). + * n.b. counter goes up by 2*Freq */ - cpufreq = loops*((aalcycles*Freq)/x); + cpufreq = loops*((aalcycles*2*Freq)/x); m->loopconst = (cpufreq/1000)/aalcycles; /* AAM+LOOP's for 1 ms */ - /* - * add in possible 0.5% error and convert to MHz - */ - m->cpumhz = (cpufreq + cpufreq/200)/1000000; + if(havecycleclock){ + + /* counter goes up by 2*Freq */ + b = (b-a)<<1; + b *= Freq; + b /= x; + + /* + * round to the nearest megahz + */ + m->cpumhz = (b+500000)/1000000L; + m->cpuhz = b; + } else { + /* + * add in possible 0.5% error and convert to MHz + */ + m->cpumhz = (cpufreq + cpufreq/200)/1000000; + m->cpuhz = cpufreq; + } } void