From owner-freebsd-questions@FreeBSD.ORG Wed Jun 16 08:59:59 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6075816A4CF for ; Wed, 16 Jun 2004 08:59:59 +0000 (GMT) Received: from turing.cs.hmc.edu (turing.cs.hmc.edu [134.173.42.99]) by mx1.FreeBSD.org (Postfix) with ESMTP id 53ACC43D2F for ; Wed, 16 Jun 2004 08:59:59 +0000 (GMT) (envelope-from jmason@cs.hmc.edu) Received: by turing.cs.hmc.edu (Postfix, from userid 34126) id 1FFA453B18; Wed, 16 Jun 2004 01:58:57 -0700 (PDT) Date: Wed, 16 Jun 2004 01:58:56 -0700 From: "Julian M. Mason" To: Dan Nelson Message-ID: <20040616085856.GA26476@turing.cs.hmc.edu> References: <40CFB701.9000303@yahoo.fr> <20040616043201.GN62945@dan.emsphone.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040616043201.GN62945@dan.emsphone.com> User-Agent: Mutt/1.4.2.1i cc: questions@freebsd.org cc: CAVELIER Gr??gory Subject: Re: CPU frequency X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: jmason@cs.hmc.edu List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2004 08:59:59 -0000 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 > #include > #include > #include > 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@allantgroup.com > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > -- Julian "Mac" Mason jmason@cs.hmc.edu Computer Science '06 (909)-607-3129 Harvey Mudd College