Pages

May 14, 2011

cpuInfo

At times we may need to see the CPU load and CPU information .Usually in linux we can fulfill that with the help of /proc/cpuinfo .But we may require to know the CPU load at times on sampling time basis [ /500ms /sec /min....].So lets see how that can be achieved

Note
1. cat /proc/cpuinfo
will give processor Number

Snap
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model  : 15
model name : Intel(R)  CPU            5138  @ 2.13GHz
stepping : 11
cpu MHz  : 2133.407
cache size : 4096 KB
physical id : 0
siblings : 2
core id  : 0
cpu cores : 1
fpu  : yes
fpu_exception : yes
cpuid level : 2
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr dca lahf_lm
bogomips : 4268.84
clflush size : 64
cache_alignment : 64
address sizes : 38 bits physical, 48 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model  : 15
model name : Intel(R)            5138  @ 2.13GHz
stepping : 11
cpu MHz  : 2133.407
cache size : 4096 KB
physical id : 0
siblings : 2
core id  : 0
cpu cores : 1
fpu  : yes
fpu_exception : yes
cpuid level : 2
wp  : yes
flags  : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr dca lahf_lm
bogomips : 4266.03
clflush size : 64
cache_alignment : 64
address sizes : 38 bits physical, 48 bits virtual
power management:
2. ps -AP lists the pid of process and processorId also[PSR-column]

Program
Unix
/*
** CPUinfo, a processor information retrieving tool
**
** (example wrapper to run all functions on UNIX-like systems)
**
**
** This software is distributed under the terms of The Alasir Licence (TAL).
** You should have received a copy of the licence together with the software.
** If not, you should download it from http://www.alasir.com/licence/TAL.txt
**
**
** Copyright (c) 2007 Paul V. Bolotoff
**
** All rights reserved.
**
*/

#include
#include
#include

#if (FreeBSD)
#include
#elif (NetBSD) || (OpenBSD)
#include
#include
#elif (Linux)
#include
#endif

typedef unsigned int U32;

extern U32 cpuinfo_main(U32 mode);

extern U32 cpuinfo_scalar_ext(U32 mode);
extern U32 cpuinfo_vector_ext(U32 mode);
extern U32 cpuinfo_general_ext(U32 mode);
extern U32 cpuinfo_address_ext(U32 mode);
extern U32 cpuinfo_monitor_ext(U32 mode);
extern U32 cpuinfo_other_ext(U32 mode);

extern U32 cpuinfo_htt_check(U32 mode);

int main(int argc, char *argv[]) {
U32 ret, mask, mask2;

printf("CPUinfo (1-Dec-2007) by Rhett M. Hollander and Paul V. Bolotoff\n\n");

#if (FreeBSD)
ret = open("/dev/io", O_RDWR);
if(ret > 0) {
/* in verbose privileged mode */
mask = cpuinfo_main(3);
close(ret);
} else {
/* in verbose regular mode */
mask = cpuinfo_main(1);
}
#elif (NetBSD) || (OpenBSD)
ret = i386_iopl(3);
if(ret == 0) mask = cpuinfo_main(3);
else mask = cpuinfo_main(1);
#elif (Linux)
ret = iopl(3);
if (ret == 0) mask = cpuinfo_main(3);
else mask = cpuinfo_main(1);
#else
/* ret is here just to shut up the compiler */
ret = mask = cpuinfo_main(1);
#endif

/* processor extensions detectable through CPUID */
if(mask & 0x20000000) {
mask2 = cpuinfo_scalar_ext(1);
mask2 = cpuinfo_vector_ext(1);
mask2 = cpuinfo_general_ext(1);
mask2 = cpuinfo_address_ext(1);
mask2 = cpuinfo_monitor_ext(1);
mask2 = cpuinfo_other_ext(1);
}

/* check for Hyper-Threading (Intel Pentium 4 processors only) */
if((mask & 0x000000FF) == 0x000000F1) mask2 = cpuinfo_htt_check(1);


return(0);
}


Try:
Windows Utility

No comments: