summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2018-10-05 18:56:58 +0000
committercheloha <cheloha@cvs.openbsd.org>2018-10-05 18:56:58 +0000
commitfd76a714b23ea388683735c19b0132e96e39c3db (patch)
treeac052fcbfab87d84a530f5d602f266b8ddbcea5c /usr.bin
parent3f27463693ec790748080c9b2f43aef7318e224e (diff)
Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.
ok kettenis deraadt
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/systat/cpu.c34
-rw-r--r--usr.bin/systat/vmstat.c33
-rw-r--r--usr.bin/top/display.c35
-rw-r--r--usr.bin/top/display.h4
-rw-r--r--usr.bin/top/machine.c59
-rw-r--r--usr.bin/top/machine.h4
-rw-r--r--usr.bin/top/top.c6
7 files changed, 49 insertions, 126 deletions
diff --git a/usr.bin/systat/cpu.c b/usr.bin/systat/cpu.c
index 22f525fd626..66ee9fbff63 100644
--- a/usr.bin/systat/cpu.c
+++ b/usr.bin/systat/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.7 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.8 2018/10/05 18:56:57 cheloha Exp $ */
/*
* Copyright (c) 2013 Reyk Floeter <reyk@openbsd.org>
@@ -50,7 +50,6 @@
#include <sys/sched.h>
#include <sys/sysctl.h>
-#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@@ -100,7 +99,6 @@ field_view views_cpu[] = {
};
int cpu_count;
-int *cpu_online;
int64_t *cpu_states;
int64_t **cpu_tm;
int64_t **cpu_old;
@@ -158,13 +156,8 @@ cpu_info(void)
for (i = 0; i < cpu_count; i++) {
cpu_time_mib[2] = i;
tmpstate = cpu_states + (CPUSTATES * i);
- if (sysctl(cpu_time_mib, 3, cpu_tm[i], &size, NULL, 0) < 0) {
- if (errno != ENODEV)
- error("sysctl KERN_CPTIME2");
- cpu_online[i] = 0;
- continue;
- }
- cpu_online[i] = 1;
+ if (sysctl(cpu_time_mib, 3, cpu_tm[i], &size, NULL, 0) < 0)
+ error("sysctl KERN_CPTIME2");
percentages(CPUSTATES, tmpstate, cpu_tm[i],
cpu_old[i], cpu_diff[i]);
}
@@ -207,8 +200,6 @@ initcpu(void)
mib[1] = HW_NCPU;
if (sysctl(mib, 2, &cpu_count, &size, NULL, 0) == -1)
return (-1);
- if ((cpu_online = calloc(cpu_count, sizeof(*cpu_online))) == NULL)
- return (-1);
if ((cpu_states = calloc(cpu_count,
CPUSTATES * sizeof(int64_t))) == NULL)
return (-1);
@@ -255,21 +246,6 @@ initcpu(void)
return; \
} while (0)
-#define ADD_OFFLINE_CPU(v) do { \
- if (cur >= dispstart && cur < end) { \
- print_fld_size(FLD_CPU_CPU, (v)); \
- print_fld_str(FLD_CPU_USR, "-"); \
- print_fld_str(FLD_CPU_NIC, "-"); \
- print_fld_str(FLD_CPU_SYS, "-"); \
- print_fld_str(FLD_CPU_SPIN, "-"); \
- print_fld_str(FLD_CPU_INT, "-"); \
- print_fld_str(FLD_CPU_IDLE, "-"); \
- end_line(); \
- } \
- if (++cur >= end) \
- return; \
-} while (0)
-
void
print_cpu(void)
{
@@ -282,10 +258,6 @@ print_cpu(void)
end = num_disp;
for (c = 0; c < cpu_count; c++) {
- if (!cpu_online[c]) {
- ADD_OFFLINE_CPU(c);
- continue;
- }
states = cpu_states + (CPUSTATES * c);
for (i = 0; i < CPUSTATES; i++)
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index b59e43941fc..00a5f5764ed 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmstat.c,v 1.87 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: vmstat.c,v 1.88 2018/10/05 18:56:57 cheloha Exp $ */
/* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */
/*-
@@ -98,7 +98,6 @@ static time_t t;
static double etime;
static float hertz;
static int nintr;
-static int ncpu;
static long *intrloc;
static char **intrname;
static int ipktsrow;
@@ -201,12 +200,6 @@ initvmstat(void)
return (-1);
}
- mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
- size = sizeof(ncpu);
- if (sysctl(mib, 2, &ncpu, &size, NULL, 0) < 0)
- return (-1);
-
allocinfo(&s);
allocinfo(&s1);
allocinfo(&s2);
@@ -599,12 +592,11 @@ putfloat(double f, int l, int c, int w, int d, int nz)
static void
getinfo(struct Info *si)
{
- static int cp_time2_mib[3] = { CTL_KERN, KERN_CPTIME2, 0 };
+ static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME };
static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };
static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };
static int vmtotal_mib[2] = { CTL_VM, VM_METER };
- int mib[4], cpu, i;
- long cpu_time[CPUSTATES];
+ int mib[4], i;
size_t size;
dkreadstats();
@@ -620,21 +612,10 @@ getinfo(struct Info *si)
}
}
- memset(&si->time, 0, sizeof(si->time));
- for (cpu = 0; cpu < ncpu; cpu++) {
- cp_time2_mib[2] = cpu;
- size = sizeof(cpu_time);
- if (sysctl(cp_time2_mib, 3, &cpu_time, &size, NULL, 0) < 0) {
- if (errno != ENODEV) {
- error("Can't get KERN_CPTIME2: %s\n",
- strerror(errno));
- memset(&si->time, 0, sizeof(si->time));
- break;
- }
- continue; /* ignore offline CPUs */
- }
- for (i = 0; i < nitems(si->time); i++)
- si->time[i] += cpu_time[i];
+ size = sizeof(si->time);
+ if (sysctl(cp_time_mib, 2, &si->time, &size, NULL, 0) < 0) {
+ error("Can't get KERN_CPTIME: %s\n", strerror(errno));
+ memset(&si->time, 0, sizeof(si->time));
}
size = sizeof(si->nchstats);
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 02e348f2e7b..e2bd611e638 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.55 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: display.c,v 1.56 2018/10/05 18:56:57 cheloha Exp $ */
/*
* Top users/processes display for Unix
@@ -125,10 +125,8 @@ static int (*standendp)(void);
int
display_resize(void)
{
- int cpu_lines, display_lines, ncpuonline;
-
- ncpuonline = getncpuonline();
- cpu_lines = (combine_cpus ? 1 : ncpuonline);
+ int display_lines;
+ int cpu_lines = (combine_cpus ? 1 : ncpu);
y_mem = 2 + cpu_lines;
y_header = 4 + cpu_lines;
@@ -138,7 +136,7 @@ display_resize(void)
/* if operating in "dumb" mode, we only need one line */
display_lines = smart_terminal ? screen_length - y_procs : 1;
- y_idlecursor = y_message = 3 + cpu_lines;
+ y_idlecursor = y_message = 3 + (combine_cpus ? 1 : ncpu);
if (screen_length <= y_message)
y_idlecursor = y_message = screen_length - 1;
@@ -379,19 +377,13 @@ cpustates_tag(int cpu)
}
void
-i_cpustates(int64_t *ostates, int *online)
+i_cpustates(int64_t *ostates)
{
- int i, first, cpu, ncpuonline;
+ int i, first, cpu;
double value;
int64_t *states;
char **names, *thisname;
- ncpuonline = 0;
- for (i = 0; i < ncpu; i++) {
- if (online[i])
- ncpuonline++;
- }
-
if (combine_cpus) {
static double *values;
if (!values) {
@@ -401,8 +393,6 @@ i_cpustates(int64_t *ostates, int *online)
}
memset(values, 0, num_cpustates * sizeof(*values));
for (cpu = 0; cpu < ncpu; cpu++) {
- if (!online[cpu])
- continue;
names = cpustate_names;
states = ostates + (CPUSTATES * cpu);
i = 0;
@@ -419,11 +409,11 @@ i_cpustates(int64_t *ostates, int *online)
first = 0;
move(2, 0);
clrtoeol();
- printwp("%-3d CPUs: ", ncpuonline);
+ printwp("%-3d CPUs: ", ncpu);
while ((thisname = *names++) != NULL) {
if (*thisname != '\0') {
- value = values[i++] / ncpuonline;
+ value = values[i++] / ncpu;
/* if percentage is >= 1000, print it as 100% */
printwp((value >= 1000 ? "%s%4.0f%% %s" :
"%s%4.1f%% %s"), first++ == 0 ? "" : ", ",
@@ -440,20 +430,13 @@ i_cpustates(int64_t *ostates, int *online)
first = 0;
states = ostates + (CPUSTATES * cpu);
- if ((screen_length > 2 + cpu && 2 + cpu < y_mem) ||
- !smart_terminal) {
+ if (screen_length > 2 + cpu || !smart_terminal) {
move(2 + cpu, 0);
clrtoeol();
addstrp(cpustates_tag(cpu));
while ((thisname = *names++) != NULL) {
if (*thisname != '\0') {
- if (!online[cpu]) {
- printwp("%s%5s %s",
- first++ == 0 ? "" : ", ",
- "-", thisname);
- continue;
- }
/* retrieve the value and remember it */
value = *states++;
diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h
index 5e170ef350a..b146b04a0c6 100644
--- a/usr.bin/top/display.h
+++ b/usr.bin/top/display.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.h,v 1.13 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: display.h,v 1.14 2018/10/05 18:56:57 cheloha Exp $ */
/*
* Top users/processes display for Unix
@@ -40,7 +40,7 @@ void u_loadave(int, double *);
void i_timeofday(time_t *);
void i_procstates(int, int *, int);
void u_procstates(int, int *);
-void i_cpustates(int64_t *, int *);
+void i_cpustates(int64_t *);
void u_cpustates(int64_t *);
void i_memory(int *);
void u_memory(int *);
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 04c1d1b0443..fcf6da95869 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.93 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: machine.c,v 1.94 2018/10/05 18:56:57 cheloha Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -111,9 +111,6 @@ char *cpustatenames[] = {
"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[] = {
@@ -173,20 +170,6 @@ getncpu(void)
}
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;
@@ -199,9 +182,6 @@ machine_init(struct statics *statics)
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 *));
@@ -263,7 +243,6 @@ format_header(char *second_field, int show_threads)
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};
@@ -275,20 +254,31 @@ get_system_info(struct system_info *si)
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)
+ 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");
- cpu_online[i] = 0;
- continue;
+ /* convert cp_time2 counts to percentages */
+ (void) percentages(CPUSTATES, tmpstate, cp_time[i],
+ cp_old[i], cp_diff[i]);
}
- cpu_online[i] = 1;
- /* 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);
@@ -327,7 +317,6 @@ get_system_info(struct system_info *si)
/* set arrays and strings */
si->cpustates = cpu_states;
- si->cpuonline = cpu_online;
si->memory = memory_stats;
si->last_pid = -1;
}
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index f4ce8c88581..5cfe8d18266 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.h,v 1.23 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: machine.h,v 1.24 2018/10/05 18:56:57 cheloha Exp $ */
/*
* Top users/processes display for Unix
@@ -56,7 +56,6 @@ struct system_info {
* "active" */
int *procstates;
int64_t *cpustates;
- int *cpuonline;
int *memory;
};
@@ -96,5 +95,4 @@ extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
int getncpu(void);
-int getncpuonline(void);
int getfscale(void);
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 2014f13ea01..692ad668fc4 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.93 2018/09/26 17:23:13 cheloha Exp $ */
+/* $OpenBSD: top.c,v 1.94 2018/10/05 18:56:57 cheloha Exp $ */
/*
* Top users/processes display for Unix
@@ -251,7 +251,7 @@ parseargs(int ac, char **av)
}
}
- i = getncpuonline();
+ i = getncpu();
if (i == -1)
err(1, NULL);
@@ -467,7 +467,7 @@ restart:
ps.threads);
/* display the cpu state percentage breakdown */
- i_cpustates(system_info.cpustates, system_info.cpuonline);
+ i_cpustates(system_info.cpustates);
/* display memory stats */
i_memory(system_info.memory);