diff options
author | 2014-09-17 01:56:54 +0000 | |
---|---|---|
committer | 2014-09-17 01:56:54 +0000 | |
commit | c04b1283e739fbf0417122534870b70c67ffb15e (patch) | |
tree | 66d899b4c1efbb31574afcd3e426d4dae836cc3e | |
parent | Five year old typo reported by Theo Buehler at math dot ethz dot ch, thanks. (diff) | |
download | wireguard-openbsd-c04b1283e739fbf0417122534870b70c67ffb15e.tar.xz wireguard-openbsd-c04b1283e739fbf0417122534870b70c67ffb15e.zip |
if there are more than 8 cpus, default to combined cpu stats (like
you passed -1 on the command line).
ok kettenis@ tedu@
-rw-r--r-- | usr.bin/top/machine.c | 24 | ||||
-rw-r--r-- | usr.bin/top/machine.h | 4 | ||||
-rw-r--r-- | usr.bin/top/top.c | 9 |
3 files changed, 29 insertions, 8 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index c9b13d65ed1..44d0e1ebe3a 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.79 2014/09/15 19:08:21 miod Exp $ */ +/* $OpenBSD: machine.c,v 1.80 2014/09/17 01:56:54 dlg Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -141,14 +141,26 @@ int ncpu; unsigned int maxslp; int -machine_init(struct statics *statics) +getncpu(void) { + int mib[] = { CTL_HW, HW_NCPU }; + int ncpu; 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) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ncpu, &size, NULL, 0) == -1) + return (-1); + + return (ncpu); +} + +int +machine_init(struct statics *statics) +{ + int pagesize, cpu; + + ncpu = getncpu(); + if (ncpu == -1) return (-1); cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t)); if (cpu_states == NULL) diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index f4c3f3045d1..312d382101e 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.h,v 1.17 2012/06/05 18:52:53 brynet Exp $ */ +/* $OpenBSD: machine.h,v 1.18 2014/09/17 01:56:54 dlg Exp $ */ /* * Top users/processes display for Unix @@ -93,3 +93,5 @@ extern char *format_next_process(caddr_t, char *(*)(uid_t), pid_t *); extern uid_t proc_owner(pid_t); extern struct kinfo_proc *getprocs(int, int, int *); + +int getncpu(void); diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 45860323971..6e1d99ee8d0 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.81 2014/04/07 15:49:22 millert Exp $ */ +/* $OpenBSD: top.c,v 1.82 2014/09/17 01:56:54 dlg Exp $ */ /* * Top users/processes display for Unix @@ -250,6 +250,13 @@ parseargs(int ac, char **av) } } + i = getncpu(); + if (i == -1) + err(1, NULL); + + if (i > 8) + combine_cpus = 1; + /* get count of top processes to display (if any) */ if (optind < ac) { if ((topn = atoiwi(av[optind])) == Invalid) { |