CPU frequency

Julian M. Mason jmason at cs.hmc.edu
Wed Jun 16 01:59:59 PDT 2004


My 5.2.1-RELEASE install offers a 'mount_linprocfs' command; running 
# mount_linprocfs none /proc
gives me a very linux-esque /proc filesystem, including /proc/cpuinfo,
which includes CPU frequency.

    --Mac

On Tue, Jun 15, 2004 at 11:32:01PM -0500, Dan Nelson wrote:
> In the last episode (Jun 16), CAVELIER Grgory said:
> > How can I get the CPU frequency from a C program ???
> > Under Linux, I used the /proc filesystem but how can I do this with 
> > FreeBSD (I have version 5.2.1)
> 
> Try 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/sysctl.h>
> #include <sys/types.h>
> int main(void)
> {
> 	long mhz;
> 	size_t mhzsize = sizeof(mhz);
> 
> 	if (sysctlbyname("hw.clockrate", &mhz, &mhzsize, NULL, 0))
> 	{
> 		perror("cannot get MHz");
> 		return 1;
> 	}
> 
> 	printf("%ld\n", mhz);
> 	return 0;
> }
> 
> 
> You could also use machdep.tsc_freq to get the exact clock rate in Hz.
> 
> -- 
> 	Dan Nelson
> 	dnelson at allantgroup.com
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> 

-- 
Julian "Mac" Mason                          jmason at cs.hmc.edu
Computer Science '06                           (909)-607-3129
Harvey Mudd College


More information about the freebsd-questions mailing list