23#include "hardware.inc"
26#if CPP_mach == CPP_w95 || CPP_mach == CPP_win64_spmd || CPP_mach == CPP_p4win64_spmd || CPP_mach == CPP_wnt || CPP_mach == CPP_wmr || CPP_mach == CPP_p4win64 || CPP_mach == CPP_p4win32
35#if CPP_mach==CPP_linux || CPP_mach == CPP_linux64_spmd || CPP_mach == CPP_p4linux964_spmd || CPP_mach == CPP_il_spmd || CPP_mach == CPP_il || CPP_mach == CPP_linux_spmd || CPP_mach == CPP_linux || CPP_mach == CPP_linux964 || CPP_mach == CPP_p4linux964 || CPP_mach == CPP_p4linux932
42#include <sys/sysinfo.h>
44#include <sys/utsname.h>
47void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
59#if CPP_mach==CPP_il || CPP_mach==CPP_il_spmd
60 char * compstr=
"family :";
62 char * compstr=
"model name";
64 char * compMHZ=
"cpu MHz";
65 int cpMHZ=strlen(compMHZ);
66 int cmplen=strlen(compstr);
73 stream=fopen(
"/proc/cpuinfo",
"r");
79 lenmach=strlen(unam.machine);
81 while (fgets(ligne,255,stream) && unknown){
82 if (strncmp(compstr,ligne,cmplen)==0){
96 while (ligne[debut]==
' ' );
98 for (i=debut; i<size-1;i++) {
100 cputype[j] = ligne[i];
108 for (i=0; i<lenmach;i++) {
109 cputype[j] = unam.machine[i];
117 sprintf(cputype,
"Unknown");
119 *lencputype = strlen(cputype);
126 while (fgets(ligne,255,stream) && unknown){
127 if (strncmp(compMHZ,ligne,cpMHZ)==0){
133#if CPP_mach==CPP_il || CPP_mach==CPP_il_spmd
139 size = strlen(ligne);
140 for (i=debut; i<size-1;i++) {
145#if CPP_mach==CPP_il || CPP_mach==CPP_il_spmd
149 *frequence = atoi(freq);
158 gethostname(hostname, 256);
159 *lenhost = strlen(hostname);
163 *memory = info.totalram*info.mem_unit/(1024*1024);
164 *
swap = info.freeswap*info.mem_unit/(1024*1024);
169#elif CPP_mach == CPP_wmr || CPP_mach==CPP_wnt || CPP_mach==CPP_p4win64_spmd || CPP_mach==CPP_win64_spmd || CPP_mach==CPP_p4win64 || CPP_mach==CPP_p4win32
180#include <sys\types.h>
182#if CPP_mach == CPP_p4win64_spmd || CPP_mach==CPP_p4win64 || CPP_mach==CPP_p4win32 || CPP_mach==CPP_wnt && CPP_rel==10
184#define pclose _pclose
187void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
189 FILE * stream = NULL;
195 WORD version = MAKEWORD(1,1);
198 char RegKey_Entry[]=
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
199 char query1[] =
"ProcessorNameString";
207 MEMORYSTATUSEX statex;
211 nRet = WSAStartup(version, &wsaData);
212 len=gethostname(hostname,256);
213 len=WSAGetLastError();
214 *lenhost = strlen(hostname);
218 if ( RegOpenKeyEx ( HKEY_LOCAL_MACHINE,RegKey_Entry,0, KEY_QUERY_VALUE, &
handle ) != ERROR_SUCCESS )
goto FAIL1;
219 if ( RegQueryValueEx (
handle,query1, NULL, NULL,(LPBYTE) hname1,(LPDWORD) &mxlen1 ) != ERROR_SUCCESS )
goto FAIL1;
222 GetSystemInfo(&info);
223 if (info.dwProcessorType < 8664) {
226 else { hname2=
"x86_64"; }
228 sprintf(cputype,
"%s (%s)",hname1,hname2);
232 sprintf(cputype,
"UNKOWN");
236 *lencputype = strlen(cputype);
240 if ( RegOpenKeyEx ( HKEY_LOCAL_MACHINE,
241 "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
242 0, KEY_QUERY_VALUE, &
handle ) != ERROR_SUCCESS )
244 if ( RegQueryValueEx (
handle,
"~MHz", NULL, NULL,
245 (LPBYTE )(&mhz) ,(LPDWORD) &l ) != ERROR_SUCCESS )
248 *frequence = (int)(mhz/50.0 +0.5)*50;
254 statex.dwLength =
sizeof (statex);
256 GlobalMemoryStatus (&statex);
257 *memory = statex.dwAvailPhys/(1024*1024);
259 *
swap=statex.dwTotalPageFile/(1024*1024);
261 statex.dwLength =
sizeof (statex);
262 GlobalMemoryStatusEx (&statex);
264 *memory = statex.ullAvailPhys/(1024*1024);
265 *
swap=statex.ullTotalPageFile/(1024*1024);
272#elif CPP_mach ==CPP_hp11 || CPP_mach == CPP_hp11_spmd
279#include <sys/pstat.h>
280#include <sys/param.h>
284void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
295 struct pst_processor psp;
296 struct pst_dynamic psd;
297 struct pst_static pst;
299 unsigned long int clock_speed, scclktick;
301 FILE * stream = NULL;
303 stream = popen (
"hostname",
"r");
304 fgets(ligne,256, stream);
307 fgets(ligne,256, stream);
308 size = strlen(ligne);
309 for ( i=0 ; i< size-1; i++) {
310 hostname[i] = ligne[i] ;
312 hostname[size-1] =
'\0';
313 *lenhost = strlen(hostname);
317 stream = popen (
"model",
"r");
318 fgets(ligne,256, stream);
319 size = strlen(ligne);
320 for ( i=0 ; i< size-1; i++) {
321 cputype[i] = ligne[i] ;
324 cputype[size-1] =
'\0';
328#if CPP_mach==CPP_hp11_spmd && CPP_rel != 600|| CPP_mach==CPP_hp11 && CPP_rel != 600
333 }
while (ligne[debut] !=
'/');
337 cpt[j] = ligne[debut];
339 }
while (ligne[debut] !=
'/');
342 sprintf(cmdline,
" grep -i %s /usr/sam/lib/mo/sched.models | awk '{print $3}'",cpt);
343 stream = popen (cmdline,
"r");
344 fgets(ligne,256, stream);
347 cputype[size-1] =
' ';
353 for (i=0;i<sz-1;i++) {
354 cputype[size]=ligne[i];
360 *lencputype = strlen(cputype);
364 pstat_getprocessor(&psp,
sizeof(psp), 1, 0);
365 scclktick=sysconf(_SC_CLK_TCK);
366 clock_speed = psp.psp_iticksperclktick * scclktick;
367 clock_speed = (clock_speed/1000000);
368 *frequence = clock_speed;
371 pstat_getstatic(&pst,
sizeof(pst), (
size_t)1, 0);
372 *memory=pst.physical_memory*pst.page_size/(1024*1024);
375 pstat_getdynamic(&psd,
sizeof(psd), (
size_t)1, 0);
376 *
swap = ((psd.psd_vm*pst.page_size - pst.physical_memory*pst.page_size)>0)?(psd.psd_vm*pst.page_size - pst.physical_memory*pst.page_size)/(1024*1024):0;
383#elif CPP_mach == CPP_pwr4_spmd || CPP_mach ==CPP_pwr4
391void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
394 char ligne[256],swaps[256];
401 FILE * stream = NULL;
403 stream = popen (
"hostname",
"r");
404 fgets(ligne,256, stream);
407 fgets(ligne,256, stream);
408 size = strlen(ligne);
409 for ( i=0 ; i< size-1; i++) {
410 hostname[i] = ligne[i] ;
412 hostname[size-1] =
'\0';
415 *lenhost = strlen(hostname);
417 stream = popen (
"lscfg | grep proc | awk '{print $2}'",
"r");
419 fgets(ligne,256, stream);
420 size = strlen(ligne);
421 for (i=0;i<size-1;i++) cpt[i]=ligne[i];
425 sprintf(cmdline,
"lsattr -El %s | grep frequency | awk '{print $2}'",cpt);
427 stream = popen (cmdline,
"r");
428 fgets(ligne,256, stream);
431 *frequence = atoi(ligne) / 1000000;
435 sprintf(cmdline,
"lsattr -El %s | grep type",cpt);
437 stream = popen (cmdline,
"r");
438 fgets(ligne,256, stream);
444 }
while (ligne[debut]!=
' ');
448 }
while (ligne[debut]==
' ');
452 cputype[i] = ligne[debut] ;
455 }
while (ligne[debut]!=
' ');
459 *lencputype=strlen(cputype);
463 sprintf(cmdline,
"lsattr -El mem0 | awk '{print $2}' ");
464 stream = popen (cmdline,
"r");
465 fgets(ligne,256, stream);
468 *memory = atoi(ligne);
471 sprintf(cmdline,
"lsps -s | awk '{print $1}' ");
472 stream = popen (cmdline,
"r");
473 fgets(ligne,256, stream);
474 fgets(ligne,256, stream);
477 for (i=0;i<strlen(ligne);i++){
478 if (ligne[i]>=
'0' && ligne[i]<=
'9'){
479 swaps[lswaps]=ligne[i];
489#elif CPP_mach==CPP_sun25 || CPP_mach==CPP_sol10x64_spmd
494#include <sys/types.h>
495#include <sys/processor.h>
496#include <sys/systeminfo.h>
498#if CPP_rel == 1000 || CPP_mach==CPP_sol10x64_spmd
504void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
506 processor_info_t infop;
507 char ligne[256],swaps[256];
513 FILE * stream = NULL;
514#if CPP_rel == 1000 || CPP_mach==CPP_sol10x64_spmd
520 stream = popen (
"hostname",
"r");
521 fgets(ligne,256, stream);
524 fgets(ligne,256, stream);
525 size = strlen(ligne);
526 for ( i=0 ; i< size-1; i++) {
527 hostname[i] = ligne[i] ;
529 hostname[size-1] =
'\0';
530 *lenhost = strlen(hostname);
534 processor_info(
proc_id, &infop);
535#if CPP_rel == 1000 || CPP_mach==CPP_sol10x64_spmd
537 ksp = kstat_lookup(kc,
"cpu_info", -1, NULL);
538 kstat_read(kc, ksp, NULL);
539 knp = kstat_data_lookup(ksp,
"brand");
540 sprintf(cputype,
"%s",knp->value);
542 strcpy(cputype,infop.pi_processor_type);
544 *lencputype = strlen(cputype);
546 *frequence = infop.pi_clock;
551*memory = (int)sysconf(_SC_PHYS_PAGES)/1024 * sysconf(_SC_PAGESIZE)/1024;
554 stream = popen(
"swap -s",
"r");
555 fgets(ligne,256, stream);
561 for (i=0;i<strlen(ligne);i++)
563 if (ligne[i]>=
'0' && ligne[i]<=
'9')
565 swaps[lswap]=ligne[i];
581 *
swap = atoi(swaps)/1024;
585#elif CPP_mach==CPP_macosx64
589#include <sys/types.h>
590#include <sys/sysctl.h>
595void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
597 FILE * stream = NULL;
600 char swapstring[256],s1[256],s2[256],s3[256],s4[256];
608 gethostname(hostname,lenh);
609 *lenhost = strlen(hostname);
615 sysctlbyname(
"machdep.cpu.brand_string", cputype, &lenh, NULL, 0);
616 *lencputype = strlen(cputype);
622 sysctlbyname(
"hw.cpufrequency",&freq,&ilen, NULL, 0);
624 *frequence = (int)frq;
630 sysctlbyname(
"hw.physmem",&mem,&ilen, NULL, 0);
631 mem = mem / 1048576 ;
637 stream = popen (
"df -k /",
"r");
638 fgets(swapstring,256, stream);
639 fgets(swapstring,256, stream);
641 sscanf(swapstring,
"%s %s %s %s",s1,s2,s3,s4);
642 *
swap = atoi(s4)/1024;
654void cpuinfo_c(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
656 sprintf(hostname,
"UNKNOWN");
657 *lenhost = strlen(hostname);
658 sprintf(cputype,
"UNKNOWN");
659 *lencputype = strlen(cputype);
671void cpuinfo(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
673 cpuinfo_c(hostname,lenhost, cputype,lencputype, frequence,memory,
swap );
676void cpuinfo_(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
678 cpuinfo_c(hostname,lenhost, cputype,lencputype, frequence,memory,
swap );
681void cpuinfo__(
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
683 cpuinfo_c(hostname,lenhost, cputype,lencputype, frequence,memory,
swap );
686void _FCALL CPUINFO (
char *hostname,
int *lenhost,
char *cputype,
int *lencputype,
int *frequence,
int *memory,
int *
swap )
688 cpuinfo_c(hostname,lenhost, cputype,lencputype, frequence,memory,
swap );
void cpuinfo_(char *hostname, int *lenhost, char *cputype, int *lencputype, int *frequence, int *memory, int *swap)
void _FCALL CPUINFO(char *hostname, int *lenhost, char *cputype, int *lencputype, int *frequence, int *memory, int *swap)
void cpuinfo__(char *hostname, int *lenhost, char *cputype, int *lencputype, int *frequence, int *memory, int *swap)
void cpuinfo_c(char *hostname, int *lenhost, char *cputype, int *lencputype, int *frequence, int *memory, int *swap)
void cpuinfo(char *hostname, int *lenhost, char *cputype, int *lencputype, int *frequence, int *memory, int *swap)
*fortran !University of Stuttgart All rights reserved Inc All rights reserved ! $COPYRIGHT$ !Additional copyrights may follow ! $HEADER$ !WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING !Do ***not ***copy this file to the directory where your Fortran !fortran application is compiled unless it is absolutely necessary !Most !modern Fortran compilers now support the I command line flag