]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include <sched.h> | |
5 | ||
6 | #include "macro.h" | |
7 | #include "missing_syscall.h" | |
8 | ||
9 | /* This wraps the libc interface with a variable to keep the allocated size. */ | |
10 | typedef struct CPUSet { | |
11 | cpu_set_t *set; | |
12 | size_t allocated; /* in bytes */ | |
13 | } CPUSet; | |
14 | ||
15 | static inline void cpu_set_reset(CPUSet *a) { | |
16 | assert((a->allocated > 0) == !!a->set); | |
17 | if (a->set) | |
18 | CPU_FREE(a->set); | |
19 | *a = (CPUSet) {}; | |
20 | } | |
21 | ||
22 | CPUSet* cpu_set_free(CPUSet *c); | |
23 | DEFINE_TRIVIAL_CLEANUP_FUNC(CPUSet*, cpu_set_free); | |
24 | ||
25 | int cpu_set_add_all(CPUSet *a, const CPUSet *b); | |
26 | int cpu_set_add(CPUSet *a, unsigned cpu); | |
27 | ||
28 | char* cpu_set_to_string(const CPUSet *a); | |
29 | char *cpu_set_to_range_string(const CPUSet *a); | |
30 | char* cpu_set_to_mask_string(const CPUSet *a); | |
31 | int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus); | |
32 | ||
33 | int parse_cpu_set_full( | |
34 | const char *rvalue, | |
35 | CPUSet *cpu_set, | |
36 | bool warn, | |
37 | const char *unit, | |
38 | const char *filename, unsigned line, | |
39 | const char *lvalue); | |
40 | int parse_cpu_set_extend( | |
41 | const char *rvalue, | |
42 | CPUSet *old, | |
43 | bool warn, | |
44 | const char *unit, | |
45 | const char *filename, | |
46 | unsigned line, | |
47 | const char *lvalue); | |
48 | ||
49 | static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){ | |
50 | return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL); | |
51 | } | |
52 | ||
53 | int cpu_set_to_dbus(const CPUSet *set, uint8_t **ret, size_t *allocated); | |
54 | int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *set); | |
55 | ||
56 | int cpus_in_affinity_mask(void); | |
57 | int cpu_mask_add_all(CPUSet *mask); |