From owner-freebsd-questions@FreeBSD.ORG Wed Jun 16 04:32:13 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 C260116A4CE for ; Wed, 16 Jun 2004 04:32:13 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5CAE743D2D for ; Wed, 16 Jun 2004 04:32:13 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i5G4W2lE004314; Tue, 15 Jun 2004 23:32:02 -0500 (CDT) (envelope-from dan) Date: Tue, 15 Jun 2004 23:32:01 -0500 From: Dan Nelson To: CAVELIER =?utf-8?Q?Gr=C3=A9gory?= Message-ID: <20040616043201.GN62945@dan.emsphone.com> References: <40CFB701.9000303@yahoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40CFB701.9000303@yahoo.fr> X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: questions@freebsd.org Subject: Re: CPU frequency X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2004 04:32:13 -0000 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