clock rate probing - final patch

Stephan Meyer (sensei@munich.netsurf.de)
Wed, 29 Jan 1997 16:13:17 +0100 (MET)


This (hopefully) is the final patch to have clock rate probing for x86
processors in the kernel.
I fixed a bug "hidden" in the ULONG arithmetic which was kindly pointed
out to me by Harald Koenig.

Is "clock rate" the correct English expression for what I mean?

I kept on-the-fly calculation for two reasons:
- Sometimes, you get values which are off by one or two and would be
annoying to see in /proc/cpuinfo all the time.
- There might be people who "tune" their CPU while the computer is on :)

Patch follows (for 2.0.28, 2.1.23, 2.1.24(?))

----------------- cut here ---------------------
*** linux/arch/i386/kernel/setup.c.old Mon Jan 27 18:32:56 1997
--- linux/arch/i386/kernel/setup.c Wed Jan 29 14:47:41 1997
***************
*** 8,13 ****
--- 8,19 ----
* This file handles the architecture-dependent parts of initialization
*/

+ /*
+ * processor clock rate probing code added
+ * needs cpuid and rdtsc instructions
+ * 01/29/97 by Stephan Meyer <Stephan.Meyer@munich.netsurf.de>
+ */
+
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
***************
*** 203,208 ****
--- 209,250 ----
request_region(0xc0,0x20,"dma2");
request_region(0xf0,0x10,"npu");
}
+
+ static char * getmhz()
+ {
+ unsigned long int a,b,j,q;
+ static char buffer[20];
+ if (!have_cpuid) {
+ strcpy(buffer,"no_tsc");
+ return buffer;
+ }
+ __asm__ __volatile__ (
+ "movl $1,%%eax
+ cpuid"
+ :"=d" (a)
+ :
+ :"%eax","%ebx","%ecx","%edx");
+ if ((a & 0x10)==0) {
+ strcpy(buffer,"no_tsc");
+ return buffer;
+ }
+ j=jiffies;
+ for (;j==jiffies;); j=jiffies;
+ __asm__ __volatile__ (
+ "rdtsc"
+ : "=a" (a)
+ :
+ : "%eax","%edx");
+ for (;j==jiffies;);
+ __asm__ __volatile__ (
+ "rdtsc"
+ : "=a" (b)
+ :
+ : "%eax","%edx");
+ q=((b-a)+(500000/HZ))/(1000000/HZ);
+ sprintf(buffer,"%i MHz",(int) q);
+ return buffer;
+ }

static const char * i486model(unsigned int nr)
{
***************
*** 287,298 ****
--- 329,342 ----
len += sprintf(buffer+len,"processor\t: %d\n"
"cpu\t\t: %c86\n"
"model\t\t: %s\n"
+ "clock_rate\t: %s\n"
"vendor_id\t: %s\n",
CPUN,
CD(x86)+'0',
CD(have_cpuid) ?
getmodel(CD(x86), CD(x86_model)) :
"unknown",
+ CD(getmhz()),
CD(x86_vendor_id));

if (CD(x86_mask))
----------------------- cut here --------------------

Cheers, Stephan

-----------------------------------------------
Stephan Meyer
+49-89-4301114
Stephan.Meyer@munich.netsurf.de
http://fatman.mathematik.tu-muenchen.de/~meyer/
-----------------------------------------------