* Re: how to get cpu_khz? [not found] <fa.ginsptv.1gg45b5@ifi.uio.no> @ 2001-09-17 19:11 ` John Weber 2001-09-17 19:51 ` David Fries 0 siblings, 1 reply; 5+ messages in thread From: John Weber @ 2001-09-17 19:11 UTC (permalink / raw) To: linux-kernel [-- Attachment #1: Type: text/plain, Size: 619 bytes --] David Fries wrote: > > I'm using the TSC of the Pentium processors to get some precise timing > delays for writing to a eeprom (bit banging bus operations), and it > works just fine, but the cpu_khz variable isn't exported to a kernel > module, so I hardcoded in my module. It works fine for that one > system, but obviously I don't want to hard code it for the general > case. I guess I could write my own routine to figure out what the > cpu_khz is, but it is already done, so how do I get access to it? I don't know of any official way of doing this, but here's some code (written by aa) that accomplishes this. [-- Attachment #2: MHz.c --] [-- Type: text/plain, Size: 1277 bytes --] /* * $Id: MHz.c,v 1.4 2001/05/21 18:58:01 davej Exp $ * This file is part of x86info. * (C) 2001 Dave Jones. * * Licensed under the terms of the GNU GPL License version 2. * * Estimate CPU MHz routine by Andrea Arcangeli <andrea@suse.de> * Small changes by David Sterba <sterd9am@ss1000.ms.mff.cuni.cz> * */ #include <stdio.h> #include <sys/time.h> #include <string.h> #include <unistd.h> __inline__ unsigned long long int rdtsc() { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } void estimate_MHz() { struct timezone tz; struct timeval tvstart, tvstop; unsigned long long int cycles[2]; /* gotta be 64 bit */ unsigned int microseconds; /* total time taken */ memset(&tz, 0, sizeof(tz)); /* get this function in cached memory */ gettimeofday(&tvstart, &tz); cycles[0] = rdtsc(); gettimeofday(&tvstart, &tz); /* we don't trust that this is any specific length of time */ usleep(1000000); cycles[1] = rdtsc(); gettimeofday(&tvstop, &tz); microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000) + (tvstop.tv_usec-tvstart.tv_usec); printf("%lldMHz processor (estimate).\n", (cycles[1]-cycles[0])/microseconds); } int main(void) { while (1) { estimate_MHz(); } return (0); } ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get cpu_khz? 2001-09-17 19:11 ` how to get cpu_khz? John Weber @ 2001-09-17 19:51 ` David Fries 2001-09-17 19:58 ` Richard B. Johnson 0 siblings, 1 reply; 5+ messages in thread From: David Fries @ 2001-09-17 19:51 UTC (permalink / raw) To: John Weber; +Cc: linux-kernel On Mon, Sep 17, 2001 at 03:11:26PM -0400, John Weber wrote: > David Fries wrote: > > > > I'm using the TSC of the Pentium processors to get some precise timing > > delays for writing to a eeprom (bit banging bus operations), and it > > works just fine, but the cpu_khz variable isn't exported to a kernel > > module, so I hardcoded in my module. It works fine for that one > > system, but obviously I don't want to hard code it for the general > > case. I guess I could write my own routine to figure out what the > > cpu_khz is, but it is already done, so how do I get access to it? > > I don't know of any official way of doing this, but here's some > code (written by aa) that accomplishes this. For a user space program you could just read /proc/cpuinfo, I'm actually writing a kernel driver, maybe I wasn't clear enough. I'm just frustrated because the variable I'm after, cpu_khz is already calculated at boot time (that's where /proc/cpuinfo gets its data) and that variable doesn't appear to be exported to the rest of the kernel, either that or I'm just missing something, which I would rather be the case at this point. -- +---------------------------------+ | David Fries | | dfries@mail.win.org | +---------------------------------+ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get cpu_khz? 2001-09-17 19:51 ` David Fries @ 2001-09-17 19:58 ` Richard B. Johnson 2001-09-17 21:26 ` Alan Cox 0 siblings, 1 reply; 5+ messages in thread From: Richard B. Johnson @ 2001-09-17 19:58 UTC (permalink / raw) To: David Fries; +Cc: John Weber, linux-kernel On Mon, 17 Sep 2001, David Fries wrote: > On Mon, Sep 17, 2001 at 03:11:26PM -0400, John Weber wrote: > > David Fries wrote: > > > > > > I'm using the TSC of the Pentium processors to get some precise timing > > > delays for writing to a eeprom (bit banging bus operations), and it > > > works just fine, but the cpu_khz variable isn't exported to a kernel > > > module, so I hardcoded in my module. It works fine for that one > > > system, but obviously I don't want to hard code it for the general > > > case. I guess I could write my own routine to figure out what the > > > cpu_khz is, but it is already done, so how do I get access to it? > > > > I don't know of any official way of doing this, but here's some > > code (written by aa) that accomplishes this. > > For a user space program you could just read /proc/cpuinfo, I'm > actually writing a kernel driver, maybe I wasn't clear enough. I'm > just frustrated because the variable I'm after, cpu_khz is already > calculated at boot time (that's where /proc/cpuinfo gets its data) and > that variable doesn't appear to be exported to the rest of the kernel, > either that or I'm just missing something, which I would rather be the > case at this point. > Ask Alan to export it by default. If no-go, export it in your configuration. Cheers, Dick Johnson Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips). I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get cpu_khz? 2001-09-17 19:58 ` Richard B. Johnson @ 2001-09-17 21:26 ` Alan Cox 0 siblings, 0 replies; 5+ messages in thread From: Alan Cox @ 2001-09-17 21:26 UTC (permalink / raw) To: root; +Cc: David Fries, John Weber, linux-kernel > > calculated at boot time (that's where /proc/cpuinfo gets its data) and > > that variable doesn't appear to be exported to the rest of the kernel, > > either that or I'm just missing something, which I would rather be the > > case at this point. > > > > Ask Alan to export it by default. If no-go, export it in your > configuration. Processor speed from cpu_khz is not a constant, it varies per processor on split multiplier SMP and it varies on certain kinds of power management. For delays we have udelay(). That has a chance of supporting speed changes ^ permalink raw reply [flat|nested] 5+ messages in thread
* how to get cpu_khz? @ 2001-09-17 16:43 David Fries 0 siblings, 0 replies; 5+ messages in thread From: David Fries @ 2001-09-17 16:43 UTC (permalink / raw) To: linux-kernel I'm using the TSC of the Pentium processors to get some precise timing delays for writing to a eeprom (bit banging bus operations), and it works just fine, but the cpu_khz variable isn't exported to a kernel module, so I hardcoded in my module. It works fine for that one system, but obviously I don't want to hard code it for the general case. I guess I could write my own routine to figure out what the cpu_khz is, but it is already done, so how do I get access to it? -- +---------------------------------+ | David Fries | | dfries@mail.win.org | +---------------------------------+ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-09-17 21:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <fa.ginsptv.1gg45b5@ifi.uio.no> 2001-09-17 19:11 ` how to get cpu_khz? John Weber 2001-09-17 19:51 ` David Fries 2001-09-17 19:58 ` Richard B. Johnson 2001-09-17 21:26 ` Alan Cox 2001-09-17 16:43 David Fries
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).