Not all verified. Don't blame me !
Feedback is welcome.
#include <sys/utsname.h>
int uname(struct ustsname *name);
GetVersionEx
A simple program that gives you useful information follows (use cc -Ae).
#include <stdio.h>
#include <sys/utsname.h>
extern int _SYSTEM_ID;
extern int _CPU_REVISION;
struct utsname uts;
int main(void)
{
uname(&uts);
printf("Release = %s\n", uts.release);
printf("_SYSTEM_ID = %x\n", _SYSTEM_ID);
printf("_CPU_REVISION = %x\n", _CPU_REVISION);
}
The uts.release
is the release of HP-UX on the system
where you run the program. The _SYSTEM_ID
is the kind of
code the compiler generated. The _CPU_REVISION
is the
architecture type.
If you compile this program on a PA1.1 system, then run it on a PA2.0 system running HP-UX Release 11.0, you get results like the following:
Release = B.11.00
_SYSTEM_ID = 210
_CPU_REVISION = 214
The release, 11.00, is easy to decipher. To decode the other results,
search the file /usr/include/sys/unistd.h
:
$ grep 210 /usr/include/sys/unistd.h
# define CPU_PA_RISC1_1 0x210 /* HP PA-RISC1.1 */
$ grep 214 /usr/include/sys/unistd.h
/# define CPU_PA_RISC2_0 0x214 /* HP PA-RISC2.0 */
The compiler generated PA1.1 code, which is running on a PA2.0 system.
build this code
/* To Make: cc -std1 -O3 -tune programname.c */
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/sysinfo.h>
#include <machine/hal_sysinfo.h>
int main(int argc, char *argv[])
{
int TotalMemory;
if (getsysinfo(GSI_PHYSMEM,&TotalMemory,(unsigned long)(sizeof(int)),0,NULL) !=-1)
{
TotalMemory += 512;
fprintf(stdout,"Total Memory = %d MB\n",TotalMemory/1024); exit(0);
}
perror("PHYSMEM");
exit(1);
}
build this code
/*----------------------------------------------------------------*/
/* NOTE: this version times a simple integer-intensive loop to */
/* "measure" the clock frequency. This works on power-2, power-pc,*/
/* and power-3 architectures; but the code MUST be compiled with */
/* "cc qcpu.c -o qcpu -lxlf90" without optimization or debugging. */
/* Use of any other compiler flags might give wrong answers for */
/* the apparent clock frequency, and the apparent frequency might */
/* be wrong for other chip architectures. */
/*----------------------------------------------------------------*/
#include <sys/types.h>
#include <fcntl.h>
#include <sys/systemcfg.h>
#include <stdio.h>
#include <nlist.h>
struct nlist info;
double rtc(void);
void main()
{
int fd;
int nprocs, imp;
int i, isum;
int iter, maxiter;
double freq, maxfreq;
double time1, time2;
info.n_name = "_system_configuration";
fd = open("/dev/kmem",O_RDONLY);
knlist(&info,1,sizeof(struct nlist));
lseek(fd,info.n_value,0);
read(fd,&_system_configuration,sizeof(_system_configuration));
nprocs = _system_configuration.ncpus;
printf("number of cpus: %d\n", nprocs);
imp = _system_configuration.implementation;
if (imp == POWER_RS1)
printf("processor class: POWER_RS1\n");
else if (imp == POWER_RSC)
printf("processor class: POWER_RSC\n");
else if (imp == POWER_RS2)
printf("processor class: POWER_RS2\n");
else if (imp == POWER_601)
printf("processor class: POWER_601\n");
else if (imp == POWER_603)
printf("processor class: POWER_603\n");
else if (imp == POWER_604)
printf("processor class: POWER_604\n");
else if (imp == POWER_630)
printf("processor class: POWER_630\n");
else printf("processor class: unknown\n");
printf("L1 Inst Cache Size in KB: %d\n",_system_configuration.icache_size / 1024);
printf("L1 Data Cache Size in KB: %d\n",_system_configuration.dcache_size / 1024);
printf("L1 Data Cache Line Sz (B): %d\n",_system_configuration.dcache_line );
printf("L2 Cache Size in KB: %d\n",_system_configuration.L2_cache_size / 1024);
printf("L2 Cache Associativity : %d\n",_system_configuration.L2_cache_asc);
maxiter = 10;
maxfreq = 0.0;
for (iter=0; iter<maxiter; iter++)
{
time1 = rtc();
isum = 0;
for (i=0; i<100000; i++) isum += 1;
time2 = rtc();
freq = 0.9/(time2-time1);
if (freq > maxfreq) maxfreq = freq;
}
printf("apparent freq = %.1f MHz\n", maxfreq );
}
$Id: hardwareinfo.html,v 1.27 2006/02/23 15:21:44 adesitter Exp $
by Arnaud Desitter.