From owner-freebsd-questions Mon Jul 30 13: 1:23 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mail.communityconnect.com (mail.communityconnect.com [209.10.169.57]) by hub.freebsd.org (Postfix) with ESMTP id A500637B403 for ; Mon, 30 Jul 2001 13:01:16 -0700 (PDT) (envelope-from marius@mail.communityconnect.com) Received: from amavis by mail.communityconnect.com with scanned-ok (Exim 3.20 #1) id 15RJDz-0001FQ-00 for questions@freebsd.org; Mon, 30 Jul 2001 16:01:11 -0400 Received: from [206.28.215.90] (helo=utterlux.hq.communitconnect.com) by mail.communityconnect.com with esmtp (Exim 3.20 #1) id 15RJDr-0000e6-00; Mon, 30 Jul 2001 16:01:03 -0400 Date: Mon, 30 Jul 2001 16:01:06 -0400 (EDT) From: Marius X-Sender: marius@utterlux.hq.communitconnect.com To: Jim Freeze Cc: questions@FreeBSD.ORG Subject: Re: getting cpu info In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Cool, thanks. On Mon, 30 Jul 2001, Jim Freeze wrote: > Here is a little piece of c code that was previously posted here. > Works great. > > Sample output: > > % machid > FreeBSD CPU Information > Version 0.1 > http://tribune.intranova.net > > Architecture: i386 > Number of CPUs: 1 > CPU Model: AMD-K6(tm) 3D processor > CPU Speed: 400MHz > Total Memory: 60MB > User Memory: 47MB > > > --begin code--- > /* > * FreeBSD CPU Information 0.1 > * --------------------------- > * Simple program to display the total RAM, and CPU information. > * Compile: cc -o cpuinfo cpuinfo.c > * --------------------------- > * Omachonu Ogali > */ > > /* Sample Output > * Architecture: i386 > * Number of CPUs: 1 > * CPU Model: Pentium II/Pentium II Xeon/Celeron > * CPU Speed: 400MHz > * Total Memory: 124MB > * User Memory: 104MB > */ > > #include > #include > #include > #include > #include > > extern int errno; > > int main(void) > { > int len, numcpu, cpuspeed, totalmem, usermem; > char cpuarch[64], cpumodel[64]; > > printf("FreeBSD CPU Information\n"); > printf("Version 0.1\n"); > printf("http://tribune.intranova.net\n\n"); > > len = sizeof(cpuarch); > if (sysctlbyname("hw.machine_arch", &cpuarch, &len, NULL, NULL) == -1) { > perror("sysctlbyname()"); > return -1; > } > > len = sizeof(cpumodel); > if (sysctlbyname("hw.model", &cpumodel, &len, NULL, NULL) == -1) { > perror("sysctlbyname()"); > return -1; > } > > len = sizeof(cpuspeed); > if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &len, NULL, NULL) == -1) > { > perror("sysctlbyname()"); > return -1; > } > > len = sizeof(numcpu); > if (sysctlbyname("hw.ncpu", &numcpu, &len, NULL, NULL) == -1) { > perror("sysctlbyname()"); > return -1; > } > > len = sizeof(totalmem); > if (sysctlbyname("hw.physmem", &totalmem, &len, NULL, NULL) == -1) { > perror("sysctlbyname()"); > return -1; > } > > len = sizeof(usermem); > if (sysctlbyname("hw.usermem", &usermem, &len, NULL, NULL) == -1) { > perror("sysctlbyname()"); > return -1; > } > > cpuspeed = cpuspeed / 1000000; > totalmem = (totalmem - 1048576) / 1048576; > usermem = (usermem - 1048576) / 1048576; > > printf("Architecture:\t%s\n", cpuarch); > printf("Number of CPUs:\t%d\n", numcpu); > printf("CPU Model:\t%s\n", cpumodel); > printf("CPU Speed:\t%dMHz\n", cpuspeed); > printf("Total Memory:\t%dMB\n", totalmem); > printf("User Memory:\t%dMB\n", usermem); > printf("\n"); > > return 0; > } > --end code--- > > On Mon, 30 Jul 2001, Marius wrote: > > > > > I am trying to audit our company's network of *nix machines to find > > candidates for replacement for newer faster models. I basically want > > write a script that logs in, executes some commands, and saves the > > appropriate info. Perl is certainly up to the task, so that isn't a > > problem. I'm just not sure how to grab the appropriate cpu info from our > > FreeBSD machines. Linux has `cat /proc/cpuinfo` but I can't think > > of anything similar in FreeBSD. > > > > I am most of the way there, I have everything I need except the speed of > > the cpu(s) in MHz. Anybody know a quick and easy way to grab the cpu speed > > on a machine without rebooting it? I can do a lot with sysctl > > to get memory resources and the number of cpu's, but a listing for > > speed has thus far eluded me. > > > > # sysctl hw.physmem > > # sysctl hw.ncpu > > > > Tell me most of what I want to know, but hw.model is not specific enough > > for my purposes. Am I overlooking a sysctl variable, or is there some > > other utility I could use? Anyone have a suggestion? > > > > Obviously this stuff would be in the boot messages of these machines, but > > these machines are in production, and I would rather not reboot them. And > > because of that 'darned' stability that FreeBSD has, the boot messages > > have long ago been wiped out of dmesg.yesterday and dmesg.today. ;) > > > > Any pointers would be appreciated. Please cc: me, as I am subscribed to > > stable, but not questions. > > > > --------------------------------------------------------------- > > -Marius M. Rex > > > > "Do not try to solve all life's problems at once -- learn to > > dread each day as it comes." > > -- Donald Kaul > > > > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > > > > > ========================================================= > Jim Freeze > jim@freeze.org > --------------------------------------------------------- > No comment at this time. > http://www.freeze.org > ========================================================= > > Do not try to solve all life's problems at once -- learn to dread each day as it comes. -- Donald Kaul To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message