Move cpus_in_affinity_mask() to cpu-set-util.[ch]
It just seems to fit better there and it's always better to have things in shared/ rather than basic/.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "cap-list.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "condition.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "efivars.h"
|
||||
#include "env-file.h"
|
||||
#include "extract-word.h"
|
||||
|
||||
@@ -201,3 +201,37 @@ int parse_cpu_set_extend(
|
||||
|
||||
return cpu_set_add_all(old, &cpuset);
|
||||
}
|
||||
|
||||
int cpus_in_affinity_mask(void) {
|
||||
size_t n = 16;
|
||||
int r;
|
||||
|
||||
for (;;) {
|
||||
cpu_set_t *c;
|
||||
|
||||
c = CPU_ALLOC(n);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
|
||||
int k;
|
||||
|
||||
k = CPU_COUNT_S(CPU_ALLOC_SIZE(n), c);
|
||||
CPU_FREE(c);
|
||||
|
||||
if (k <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
r = -errno;
|
||||
CPU_FREE(c);
|
||||
|
||||
if (r != -EINVAL)
|
||||
return r;
|
||||
if (n > SIZE_MAX/2)
|
||||
return -ENOMEM;
|
||||
n *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,3 +45,5 @@ int parse_cpu_set_extend(
|
||||
static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
|
||||
return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
int cpus_in_affinity_mask(void);
|
||||
|
||||
Reference in New Issue
Block a user