=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/machine.c,v retrieving revision 1.47 retrieving revision 1.48 diff -c -r1.47 -r1.48 *** src/usr.bin/top/machine.c 2004/12/06 15:57:04 1.47 --- src/usr.bin/top/machine.c 2005/06/08 22:36:43 1.48 *************** *** 1,4 **** ! /* $OpenBSD: machine.c,v 1.47 2004/12/06 15:57:04 markus Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert --- 1,4 ---- ! /* $OpenBSD: machine.c,v 1.48 2005/06/08 22:36:43 millert Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert *************** *** 96,104 **** static int stathz; /* these are for calculating cpu state percentages */ ! static long cp_time[CPUSTATES]; ! static long cp_old[CPUSTATES]; ! static long cp_diff[CPUSTATES]; /* these are for detailing the process states */ int process_states[8]; --- 96,104 ---- static int stathz; /* these are for calculating cpu state percentages */ ! static int64_t **cp_time; ! static int64_t **cp_old; ! static int64_t **cp_diff; /* these are for detailing the process states */ int process_states[8]; *************** *** 109,115 **** }; /* these are for detailing the cpu states */ ! int cpu_states[CPUSTATES]; char *cpustatenames[] = { "user", "nice", "system", "interrupt", "idle", NULL }; --- 109,115 ---- }; /* these are for detailing the cpu states */ ! int64_t *cpu_states; char *cpustatenames[] = { "user", "nice", "system", "interrupt", "idle", NULL }; *************** *** 162,173 **** machine_init(struct statics *statics) { size_t size = sizeof(ncpu); ! int mib[2], pagesize; mib[0] = CTL_HW; mib[1] = HW_NCPU; if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1) return (-1); stathz = getstathz(); if (stathz == -1) --- 162,189 ---- machine_init(struct statics *statics) { size_t size = sizeof(ncpu); ! int mib[2], pagesize, cpu; mib[0] = CTL_HW; mib[1] = HW_NCPU; if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1) return (-1); + cpu_states = malloc(ncpu * CPUSTATES * sizeof(int64_t)); + if (cpu_states == NULL) + err(1, NULL); + cp_time = malloc(ncpu * sizeof(int64_t *)); + cp_old = malloc(ncpu * sizeof(int64_t *)); + cp_diff = malloc(ncpu * sizeof(int64_t *)); + if (cp_time == NULL || cp_old == NULL || cp_diff == NULL) + err(1, NULL); + for (cpu = 0; cpu < ncpu; cpu++) { + cp_time[cpu] = malloc(CPUSTATES * sizeof(int64_t)); + cp_old[cpu] = malloc(CPUSTATES * sizeof(int64_t)); + cp_diff[cpu] = malloc(CPUSTATES * sizeof(int64_t)); + if (cp_time[cpu] == NULL || cp_old[cpu] == NULL || + cp_diff[cpu] == NULL) + err(1, NULL); + } stathz = getstathz(); if (stathz == -1) *************** *** 216,232 **** { static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; static int vmtotal_mib[] = {CTL_VM, VM_METER}; - static int cp_time_mib[] = {CTL_KERN, KERN_CPTIME}; struct loadavg sysload; struct vmtotal vmtotal; double *infoloadp; size_t size; int i; ! size = sizeof(cp_time); ! if (sysctl(cp_time_mib, 2, &cp_time, &size, NULL, 0) < 0) ! warn("sysctl kern.cp_time failed"); size = sizeof(sysload); if (sysctl(sysload_mib, 2, &sysload, &size, NULL, 0) < 0) warn("sysctl failed"); --- 232,269 ---- { static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; static int vmtotal_mib[] = {CTL_VM, VM_METER}; struct loadavg sysload; struct vmtotal vmtotal; double *infoloadp; size_t size; int i; + int64_t *tmpstate; ! if (ncpu > 1) { ! size = CPUSTATES * sizeof(int64_t); ! for (i = 0; i < ncpu; i++) { ! int cp_time_mib[] = {CTL_KERN, KERN_CPTIME2, i}; ! tmpstate = cpu_states + (CPUSTATES * i); ! if (sysctl(cp_time_mib, 3, cp_time[i], &size, NULL, 0) < 0) ! warn("sysctl kern.cp_time2 failed"); ! /* convert cp_time2 counts to percentages */ ! (void) percentages(CPUSTATES, tmpstate, cp_time[i], ! cp_old[i], cp_diff[i]); ! } ! } else { ! int cp_time_mib[] = {CTL_KERN, KERN_CPTIME}; ! long cp_time_tmp[CPUSTATES]; + size = sizeof(cp_time_tmp); + if (sysctl(cp_time_mib, 2, cp_time_tmp, &size, NULL, 0) < 0) + warn("sysctl kern.cp_time failed"); + for (i = 0; i < CPUSTATES; i++) + cp_time[0][i] = cp_time_tmp[i]; + /* convert cp_time counts to percentages */ + (void) percentages(CPUSTATES, cpu_states, cp_time[0], + cp_old[0], cp_diff[0]); + } + size = sizeof(sysload); if (sysctl(sysload_mib, 2, &sysload, &size, NULL, 0) < 0) warn("sysctl failed"); *************** *** 234,241 **** for (i = 0; i < 3; i++) *infoloadp++ = ((double) sysload.ldavg[i]) / sysload.fscale; - /* convert cp_time counts to percentages */ - (void) percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); /* get total -- systemwide main memory usage structure */ size = sizeof(vmtotal); --- 271,276 ---- *************** *** 380,386 **** static char buf[10]; if (ncpu > 1 && pp->p_cpuid != KI_NOCPU) ! snprintf(buf, sizeof buf, "%s/%d", state_abbrev[(unsigned char)pp->p_stat], pp->p_cpuid); else snprintf(buf, sizeof buf, "%s", --- 415,421 ---- static char buf[10]; if (ncpu > 1 && pp->p_cpuid != KI_NOCPU) ! snprintf(buf, sizeof buf, "%s/%llu", state_abbrev[(unsigned char)pp->p_stat], pp->p_cpuid); else snprintf(buf, sizeof buf, "%s",