test-execute: use CPUSet too

cpu_set_malloc() was the last user. It doesn't seem useful to keep
it just to save the allocation of a few hundred bytes in a test, so
it is dropped and a fixed maximum is allocated (1024 bytes).
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-05-29 10:29:28 +02:00
parent fb39af4ce4
commit 167a776dbe
3 changed files with 8 additions and 39 deletions
+1 -30
View File
@@ -34,36 +34,7 @@ char* cpu_set_to_string(const CPUSet *a) {
return TAKE_PTR(str) ?: strdup("");
}
cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
cpu_set_t *c;
unsigned n = 1024;
/* Allocates the cpuset in the right size */
for (;;) {
c = CPU_ALLOC(n);
if (!c)
return NULL;
if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
CPU_ZERO_S(CPU_ALLOC_SIZE(n), c);
if (ncpus)
*ncpus = n;
return c;
}
CPU_FREE(c);
if (errno != EINVAL)
return NULL;
n *= 2;
}
}
static int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus) {
int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus) {
size_t need;
assert(cpu_set);
+1 -2
View File
@@ -8,8 +8,6 @@
DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
cpu_set_t* cpu_set_malloc(unsigned *ncpus);
/* This wraps the libc interface with a variable to keep the allocated size. */
typedef struct CPUSet {
cpu_set_t *set;
@@ -26,6 +24,7 @@ static inline void cpu_set_reset(CPUSet *a) {
int cpu_set_add_all(CPUSet *a, const CPUSet *b);
char* cpu_set_to_string(const CPUSet *a);
int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
int parse_cpu_set_full(
const char *rvalue,
CPUSet *cpu_set,