if you have more than 8 cpus, combine the cpu lines by default.
ok?
Index: machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.78
diff -u -p -r1.78 machine.c
--- machine.c 4 Jul 2014 05:58:31 -0000 1.78
+++ machine.c 16 Sep 2014 11:46:41 -0000
@@ -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)
Index: machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.17
diff -u -p -r1.17 machine.h
--- machine.h 5 Jun 2012 18:52:53 -0000 1.17
+++ machine.h 16 Sep 2014 11:46:41 -0000
@@ -93,3 +93,5 @@ extern char *format_next_process(cadd
extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
+
+int getncpu(void);
Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.81
diff -u -p -r1.81 top.c
--- top.c 7 Apr 2014 15:49:22 -0000 1.81
+++ top.c 16 Sep 2014 11:46:41 -0000
@@ -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) {