summaryrefslogtreecommitdiff
path: root/usr.bin/top
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/top
parent3f27463693ec790748080c9b2f43aef7318e224e (diff)
Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.
ok kettenis deraadt
Diffstat (limited to 'usr.bin/top')
-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
5 files changed, 39 insertions, 69 deletions
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);