How to read hw.clockrate from a kernel module?

Antonio Huete Jimenez ahuete.devel at gmail.com
Mon Oct 24 09:08:48 PDT 2011


Hi Maurizio,Yeah, I would suppose you can use either kernel_sysctl() or kernel_sysctlbyname() to get it.An example of kernel_sysctl(), which is used in more places than kernel_sysctlbyname() AFAICS:
http://pkgbox64.dragonflybsd.org/xref/DragonFly-master/sys/vfs/nwfs/nwfs_vfsops.c#360
Cheers,Antonio Huete2011/10/24 Maurizio Lombardi <m.lombardi85 at gmail.com>
Hi all,

I've a little question:
In platform/pc32/i386/identcpu.c there is the following variable defined:

------------------
static int hw_clockrate;
SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
 &hw_clockrate, 0, "CPU instruction clock rate");
------------------

I suppose it contains the current cpu speed in Mhz.
How can I properly read it's content from a kernel module?
Is it correct to do that?

--------------
const size_t var_size = sizeof(int);
int cpu_mhz;

kernel_sysctlbyname("hw.clockrate", &cpu_mhz, &var_size, NULL, 0, NULL);
--------------

Thanks for the help,

--
--------------------
Maurizio Lombardi





More information about the Kernel mailing list