=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/machine.c,v retrieving revision 1.92 retrieving revision 1.93 diff -c -r1.92 -r1.93 *** src/usr.bin/top/machine.c 2018/09/22 16:50:35 1.92 --- src/usr.bin/top/machine.c 2018/09/26 17:23:13 1.93 *************** *** 1,4 **** ! /* $OpenBSD: machine.c,v 1.92 2018/09/22 16:50:35 millert Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert --- 1,4 ---- ! /* $OpenBSD: machine.c,v 1.93 2018/09/26 17:23:13 cheloha Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert *************** *** 111,116 **** --- 111,119 ---- "user", "nice", "sys", "spin", "intr", "idle", NULL }; + /* this tracks which cpus are online */ + int *cpu_online; + /* these are for detailing the memory statistics */ int memory_stats[10]; char *memorynames[] = { *************** *** 170,175 **** --- 173,192 ---- } int + getncpuonline(void) + { + int mib[] = { CTL_HW, HW_NCPUONLINE }; + int numcpu; + size_t size = sizeof(numcpu); + + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &numcpu, &size, NULL, 0) == -1) + return (-1); + + return (numcpu); + } + + int machine_init(struct statics *statics) { int pagesize, cpu; *************** *** 182,187 **** --- 199,207 ---- cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t)); if (cpu_states == NULL) err(1, NULL); + cpu_online = calloc(ncpu, sizeof(*cpu_online)); + if (cpu_online == NULL) + err(1, NULL); cp_time = calloc(ncpu, sizeof(int64_t *)); cp_old = calloc(ncpu, sizeof(int64_t *)); cp_diff = calloc(ncpu, sizeof(int64_t *)); *************** *** 243,248 **** --- 263,269 ---- void get_system_info(struct system_info *si) { + static int cp_time_mib[] = {CTL_KERN, KERN_CPTIME2, /*fillme*/0}; static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP}; static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; *************** *** 254,284 **** int i; int64_t *tmpstate; ! if (ncpu > 1) { ! int cp_time_mib[] = {CTL_KERN, KERN_CPTIME2, /*fillme*/0}; ! ! size = CPUSTATES * sizeof(int64_t); ! for (i = 0; i < ncpu; i++) { ! cp_time_mib[2] = 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); --- 275,294 ---- int i; int64_t *tmpstate; ! size = CPUSTATES * sizeof(int64_t); ! for (i = 0; i < ncpu; i++) { ! cp_time_mib[2] = i; ! tmpstate = cpu_states + (CPUSTATES * i); ! if (sysctl(cp_time_mib, 3, cp_time[i], &size, NULL, 0) < 0) { ! if (errno != ENODEV) warn("sysctl kern.cp_time2 failed"); ! cpu_online[i] = 0; ! continue; } ! cpu_online[i] = 1; ! /* convert cp_time2 counts to percentages */ ! (void) percentages(CPUSTATES, tmpstate, cp_time[i], ! cp_old[i], cp_diff[i]); } size = sizeof(sysload); *************** *** 317,322 **** --- 327,333 ---- /* set arrays and strings */ si->cpustates = cpu_states; + si->cpuonline = cpu_online; si->memory = memory_stats; si->last_pid = -1; }