/* * AIX CPU support (including SMP for AIX 4.x) * * John DiMarco , University of Toronto, CSLab */ #include #include #include #include #include #include extern char *kernelSymbols; extern int sep_wait, cpuflag; #ifndef MAXCPU #define MAXCPU 64 #endif /* MAXCPU */ #ifndef KMEM #define KMEM "/dev/kmem" #endif /* KMEM */ #ifndef KSYMS #define KSYMS "/unix" #endif /* KSYMS */ #ifdef SMP #define NPROCS MAXCPU #define CPUINFO "cpuinfo" #else #define cpuinfo sysinfo #define CPUINFO "sysinfo" #define NPROCS 1 #endif #define BUFFSIZE 64 int ncpus; struct cpuinfo cpu[MAXCPU]; long cp_time[NPROCS][CPU_NTIMES]; long cp_old [NPROCS][CPU_NTIMES]; int kmem; /* file descriptor for /dev/kmem. */ struct nlist nl[] = { #define N_NCPU 0 { "number_of_cpus" }, #define N_CPUINFO 1 { CPUINFO }, { "" }, }; /* Called by -version */ void version() { printf("AIX: maxcpu=%d, maxdisk=0\n", NPROCS); } /* Called at the beginning to inquire how many bars are needed. */ int num_bars() { if(!cpuflag) return 0; if (0>(kmem = open(KMEM, O_RDONLY))){ perror(KMEM); exit(1); } if (0>nlist(kernelSymbols?kernelSymbols:KSYMS, nl)){ perror(kernelSymbols?kernelSymbols:KSYMS); exit(1); } #if 1==NPROCS ncpus=1; return NPROCS; /* NOTREACHED */ #endif if ((off_t)nl[N_NCPU].n_value != lseek(kmem,(off_t)nl[N_NCPU].n_value, SEEK_SET)){ perror("lseek _number_of_cpus"); exit(1); } if (sizeof(ncpus) != read(kmem, (char *)&ncpus, sizeof(ncpus))){ perror("read _number_of_cpus"); exit(1); } return ncpus; } /* * Indicates how many levels each bar has. For most machines, each bar will * have the same stuff. But one can, for instance, display memory use on one * bar, processor levels on others, etc. */ void bar_items(nbars, items) int nbars; int items[]; /* nbars items in this */ { int i; for(i=0; igethostname(hname, MAXHOSTNAMELEN)) { perror("gethostname"); *hname = '\0'; } shorten(hname); names = (char **) xmalloc(nbars * sizeof(char *)); /* do cpu names */ for(i=0; i