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 /libbb | |
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 'libbb')
-rw-r--r-- | libbb/Kbuild.src | 1 | ||||
-rw-r--r-- | libbb/alloc_affinity.c | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index c3b30003f..a0e2a6da7 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -10,6 +10,7 @@ lib-y:= | |||
10 | 10 | ||
11 | INSERT | 11 | INSERT |
12 | 12 | ||
13 | lib-y += alloc_affinity.o | ||
13 | lib-y += appletlib.o | 14 | lib-y += appletlib.o |
14 | lib-y += ask_confirmation.o | 15 | lib-y += ask_confirmation.o |
15 | lib-y += bb_askpass.o | 16 | lib-y += bb_askpass.o |
diff --git a/libbb/alloc_affinity.c b/libbb/alloc_affinity.c new file mode 100644 index 000000000..b6d9f649a --- /dev/null +++ b/libbb/alloc_affinity.c | |||
@@ -0,0 +1,29 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2024 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | #include <sched.h> | ||
10 | #include "libbb.h" | ||
11 | |||
12 | unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz) | ||
13 | { | ||
14 | unsigned long *mask = NULL; | ||
15 | unsigned sz_in_bytes = *sz; | ||
16 | |||
17 | for (;;) { | ||
18 | mask = xrealloc(mask, sz_in_bytes); | ||
19 | if (sched_getaffinity(pid, sz_in_bytes, (void*)mask) == 0) | ||
20 | break; /* got it */ | ||
21 | sz_in_bytes *= 2; | ||
22 | if (errno == EINVAL && (int)sz_in_bytes > 0) | ||
23 | continue; | ||
24 | bb_perror_msg_and_die("can't %cet pid %d's affinity", 'g', pid); | ||
25 | } | ||
26 | //bb_error_msg("get mask[0]:%lx sz_in_bytes:%d", mask[0], sz_in_bytes); | ||
27 | *sz = sz_in_bytes; | ||
28 | return mask; | ||
29 | } | ||