diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-05-31 11:56:40 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-05-31 11:58:48 +0200 |
commit | 5a68a246e750359819d63bcff5ef97dd9c7788fc (patch) | |
tree | 2a9af97b38d5a9780bd63e03403d0b613194a0f4 /coreutils | |
parent | fd47f056765aed515f4c71118813f07be1402bee (diff) | |
download | busybox-w32-5a68a246e750359819d63bcff5ef97dd9c7788fc.tar.gz busybox-w32-5a68a246e750359819d63bcff5ef97dd9c7788fc.tar.bz2 busybox-w32-5a68a246e750359819d63bcff5ef97dd9c7788fc.zip |
nproc: prepare for arbitrarily large CPU masks
function old new delta
get_malloc_cpu_affinity - 76 +76
nproc_main 216 206 -10
process_pid_str 250 206 -44
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 76/-54) Total: 22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/nproc.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index f1d11fa5a..a0d818c59 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -23,13 +23,11 @@ | |||
23 | //usage: "\n --ignore=N Exclude N CPUs" | 23 | //usage: "\n --ignore=N Exclude N CPUs" |
24 | //usage: ) | 24 | //usage: ) |
25 | 25 | ||
26 | #include <sched.h> | ||
27 | #include "libbb.h" | 26 | #include "libbb.h" |
28 | 27 | ||
29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 28 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
30 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 29 | int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
31 | { | 30 | { |
32 | unsigned long mask[1024]; | ||
33 | int count = 0; | 31 | int count = 0; |
34 | #if ENABLE_LONG_OPTS | 32 | #if ENABLE_LONG_OPTS |
35 | int ignore = 0; | 33 | int ignore = 0; |
@@ -52,9 +50,12 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
52 | } | 50 | } |
53 | } else | 51 | } else |
54 | #endif | 52 | #endif |
55 | if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) { | 53 | { |
56 | int i; | 54 | int i; |
57 | for (i = 0; i < ARRAY_SIZE(mask); i++) { | 55 | unsigned sz = 2 * 1024; |
56 | unsigned long *mask = get_malloc_cpu_affinity(0, &sz); | ||
57 | sz /= sizeof(long); | ||
58 | for (i = 0; i < sz; i++) { | ||
58 | unsigned long m = mask[i]; | 59 | unsigned long m = mask[i]; |
59 | while (m) { | 60 | while (m) { |
60 | if (m & 1) | 61 | if (m & 1) |