diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index c86507178047..2afe59a3e329 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.48 1994/08/10 03:51:07 wollman Exp $ + * $Id: machdep.c,v 1.49 1994/08/10 03:53:33 wollman Exp $ */ #include "npx.h" @@ -179,6 +179,7 @@ cpu_startup() * Good {morning,afternoon,evening,night}. */ printf(version); + startrtclock(); identifycpu(); printf("real memory = %d (%d pages)\n", ptoa(physmem), physmem); if (badpages) @@ -387,6 +388,14 @@ identifycpu() printf("unknown"); /* will panic below... */ } printf("-class CPU)"); +#ifdef I586_CPU + if(cpu_class == CPUCLASS_586) { + extern void calibrate_cyclecounter(); + extern int pentium_mhz; + calibrate_cyclecounter(); + printf(" %d MHz", pentium_mhz); + } +#endif if(cpu_id) printf(" Id = 0x%x",cpu_id); if(*cpu_vendor) diff --git a/sys/amd64/amd64/tsc.c b/sys/amd64/amd64/tsc.c index e40079a40bea..3c2391991c1b 100644 --- a/sys/amd64/amd64/tsc.c +++ b/sys/amd64/amd64/tsc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.6 1994/02/06 22:48:13 davidg Exp $ + * $Id: clock.c,v 1.10 1994/05/25 08:58:32 rgrimes Exp $ */ /* @@ -181,6 +181,28 @@ getit() return ((high << 8) | low); } +#ifdef I586_CPU +int pentium_mhz = 0; +static long long cycles_per_sec = 0; + +void +calibrate_cyclecounter(void) +{ + volatile long edx, eax, lasteax, lastedx; + + __asm __volatile(".byte 0x0f, 0x31" : "=a"(lasteax), "=d"(lastedx) : ); + DELAY(1000000); + __asm __volatile(".byte 0x0f, 0x31" : "=a"(eax), "=d"(edx) : ); + + /* + * This assumes that you will never have a clock rate higher + * than 4GHz, probably a good assumption. + */ + cycles_per_sec = (long long)edx + eax; + cycles_per_sec -= (long long)lastedx + lasteax; + pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +} +#endif /* * Wait "n" microseconds. @@ -432,7 +454,6 @@ spinwait(int millisecs) void cpu_initclocks() { - startrtclock(); enablertclock(); } diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c index e40079a40bea..3c2391991c1b 100644 --- a/sys/amd64/isa/clock.c +++ b/sys/amd64/isa/clock.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.6 1994/02/06 22:48:13 davidg Exp $ + * $Id: clock.c,v 1.10 1994/05/25 08:58:32 rgrimes Exp $ */ /* @@ -181,6 +181,28 @@ getit() return ((high << 8) | low); } +#ifdef I586_CPU +int pentium_mhz = 0; +static long long cycles_per_sec = 0; + +void +calibrate_cyclecounter(void) +{ + volatile long edx, eax, lasteax, lastedx; + + __asm __volatile(".byte 0x0f, 0x31" : "=a"(lasteax), "=d"(lastedx) : ); + DELAY(1000000); + __asm __volatile(".byte 0x0f, 0x31" : "=a"(eax), "=d"(edx) : ); + + /* + * This assumes that you will never have a clock rate higher + * than 4GHz, probably a good assumption. + */ + cycles_per_sec = (long long)edx + eax; + cycles_per_sec -= (long long)lastedx + lasteax; + pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +} +#endif /* * Wait "n" microseconds. @@ -432,7 +454,6 @@ spinwait(int millisecs) void cpu_initclocks() { - startrtclock(); enablertclock(); } diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index c86507178047..2afe59a3e329 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.48 1994/08/10 03:51:07 wollman Exp $ + * $Id: machdep.c,v 1.49 1994/08/10 03:53:33 wollman Exp $ */ #include "npx.h" @@ -179,6 +179,7 @@ cpu_startup() * Good {morning,afternoon,evening,night}. */ printf(version); + startrtclock(); identifycpu(); printf("real memory = %d (%d pages)\n", ptoa(physmem), physmem); if (badpages) @@ -387,6 +388,14 @@ identifycpu() printf("unknown"); /* will panic below... */ } printf("-class CPU)"); +#ifdef I586_CPU + if(cpu_class == CPUCLASS_586) { + extern void calibrate_cyclecounter(); + extern int pentium_mhz; + calibrate_cyclecounter(); + printf(" %d MHz", pentium_mhz); + } +#endif if(cpu_id) printf(" Id = 0x%x",cpu_id); if(*cpu_vendor) diff --git a/sys/i386/i386/tsc.c b/sys/i386/i386/tsc.c index e40079a40bea..3c2391991c1b 100644 --- a/sys/i386/i386/tsc.c +++ b/sys/i386/i386/tsc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.6 1994/02/06 22:48:13 davidg Exp $ + * $Id: clock.c,v 1.10 1994/05/25 08:58:32 rgrimes Exp $ */ /* @@ -181,6 +181,28 @@ getit() return ((high << 8) | low); } +#ifdef I586_CPU +int pentium_mhz = 0; +static long long cycles_per_sec = 0; + +void +calibrate_cyclecounter(void) +{ + volatile long edx, eax, lasteax, lastedx; + + __asm __volatile(".byte 0x0f, 0x31" : "=a"(lasteax), "=d"(lastedx) : ); + DELAY(1000000); + __asm __volatile(".byte 0x0f, 0x31" : "=a"(eax), "=d"(edx) : ); + + /* + * This assumes that you will never have a clock rate higher + * than 4GHz, probably a good assumption. + */ + cycles_per_sec = (long long)edx + eax; + cycles_per_sec -= (long long)lastedx + lasteax; + pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +} +#endif /* * Wait "n" microseconds. @@ -432,7 +454,6 @@ spinwait(int millisecs) void cpu_initclocks() { - startrtclock(); enablertclock(); } diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c index e40079a40bea..3c2391991c1b 100644 --- a/sys/i386/isa/clock.c +++ b/sys/i386/isa/clock.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.6 1994/02/06 22:48:13 davidg Exp $ + * $Id: clock.c,v 1.10 1994/05/25 08:58:32 rgrimes Exp $ */ /* @@ -181,6 +181,28 @@ getit() return ((high << 8) | low); } +#ifdef I586_CPU +int pentium_mhz = 0; +static long long cycles_per_sec = 0; + +void +calibrate_cyclecounter(void) +{ + volatile long edx, eax, lasteax, lastedx; + + __asm __volatile(".byte 0x0f, 0x31" : "=a"(lasteax), "=d"(lastedx) : ); + DELAY(1000000); + __asm __volatile(".byte 0x0f, 0x31" : "=a"(eax), "=d"(edx) : ); + + /* + * This assumes that you will never have a clock rate higher + * than 4GHz, probably a good assumption. + */ + cycles_per_sec = (long long)edx + eax; + cycles_per_sec -= (long long)lastedx + lasteax; + pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +} +#endif /* * Wait "n" microseconds. @@ -432,7 +454,6 @@ spinwait(int millisecs) void cpu_initclocks() { - startrtclock(); enablertclock(); } diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c index e40079a40bea..3c2391991c1b 100644 --- a/sys/isa/atrtc.c +++ b/sys/isa/atrtc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.6 1994/02/06 22:48:13 davidg Exp $ + * $Id: clock.c,v 1.10 1994/05/25 08:58:32 rgrimes Exp $ */ /* @@ -181,6 +181,28 @@ getit() return ((high << 8) | low); } +#ifdef I586_CPU +int pentium_mhz = 0; +static long long cycles_per_sec = 0; + +void +calibrate_cyclecounter(void) +{ + volatile long edx, eax, lasteax, lastedx; + + __asm __volatile(".byte 0x0f, 0x31" : "=a"(lasteax), "=d"(lastedx) : ); + DELAY(1000000); + __asm __volatile(".byte 0x0f, 0x31" : "=a"(eax), "=d"(edx) : ); + + /* + * This assumes that you will never have a clock rate higher + * than 4GHz, probably a good assumption. + */ + cycles_per_sec = (long long)edx + eax; + cycles_per_sec -= (long long)lastedx + lasteax; + pentium_mhz = ((long)cycles_per_sec + 500000) / 1000000; /* round up */ +} +#endif /* * Wait "n" microseconds. @@ -432,7 +454,6 @@ spinwait(int millisecs) void cpu_initclocks() { - startrtclock(); enablertclock(); }