From eb1bbc245dd6554a8fbe879a4efb903f6e7788cb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 25 Oct 2015 16:50:03 -0500 Subject: Add xcount_cpus() --- toys/other/taskset.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'toys') diff --git a/toys/other/taskset.c b/toys/other/taskset.c index 4ade5f10..29ce3173 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -40,10 +40,6 @@ config TASKSET #define sched_getaffinity(pid, size, cpuset) \ syscall(__NR_sched_getaffinity, (pid_t)pid, (size_t)size, (void *)cpuset) -GLOBALS( - int nproc; -) - // mask is an array of long, which makes the layout a bit weird on big // endian systems but as long as it's consistent... @@ -120,29 +116,18 @@ void taskset_main(void) } } -static int do_nproc(struct dirtree *new) -{ - if (!new->parent) return DIRTREE_RECURSE; - if (!strncmp(new->name, "cpu", 3) && isdigit(new->name[3])) TT.nproc++; - - return 0; -} - void nproc_main(void) { - int i, j; + unsigned i, j, nproc = 0; // This can only detect 32768 processors. Call getaffinity and count bits. if (!toys.optflags && -1!=sched_getaffinity(getpid(), 4096, toybuf)) { for (i = 0; i<4096; i++) - if (toybuf[i]) - for (j=0; j<8; j++) - if (toybuf[i]&(1<