Debian Codegraph @

src/shared/cpu-set-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <sched.h>
5
6 #include "conf-parser-forward.h"
7 #include "shared-forward.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 void cpu_set_done(CPUSet *c);
16 #define cpu_set_done_and_replace(a, b) \
17 ({ \
18 CPUSet *_a = &(a), *_b = &(b); \
19 cpu_set_done(_a); \
20 *_a = TAKE_STRUCT(*_b); \
21 0; \
22 })
23
24 int cpu_set_realloc(CPUSet *c, size_t n);
25 int cpu_set_add(CPUSet *c, size_t i);
26 int cpu_set_add_set(CPUSet *c, const CPUSet *src);
27 int cpu_set_add_range(CPUSet *c, size_t start, size_t end);
28 int cpu_set_add_all(CPUSet *c);
29
30 char* cpu_set_to_string(const CPUSet *c);
31 char* cpu_set_to_range_string(const CPUSet *c);
32 char* cpu_set_to_mask_string(const CPUSet *c);
33
34 CONFIG_PARSER_PROTOTYPE(config_parse_cpu_set);
35 int parse_cpu_set(const char *s, CPUSet *ret);
36
37 int cpu_set_to_dbus(const CPUSet *c, uint8_t **ret, size_t *ret_size);
38 int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *ret);
39
40 int cpus_in_affinity_mask(void);
41
42 static inline size_t cpu_set_count(const CPUSet *c) {
43 if (!c)
44 return 0;
45 if (c->allocated <= 0)
46 return 0;
47 return CPU_COUNT_S(c->allocated, c->set);
48 }
49
50 int cpus_online(unsigned *ret);