]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/cpu-set-util.h
Merge pull request #16112 from poettering/nss-systemd-block-fix
[thirdparty/systemd.git] / src / shared / cpu-set-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
618234a5
LP
2#pragma once
3
618234a5
LP
4#include <sched.h>
5
6#include "macro.h"
b070c7c0 7#include "missing_syscall.h"
618234a5 8
0985c7c4
ZJS
9/* This wraps the libc interface with a variable to keep the allocated size. */
10typedef struct CPUSet {
11 cpu_set_t *set;
12 size_t allocated; /* in bytes */
13} CPUSet;
14
15static 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) {};
6d8a29b2
YW
20}
21
0985c7c4
ZJS
22int cpu_set_add_all(CPUSet *a, const CPUSet *b);
23
24char* cpu_set_to_string(const CPUSet *a);
71b28519 25char *cpu_set_to_range_string(const CPUSet *a);
167a776d 26int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
71b28519 27
0985c7c4
ZJS
28int parse_cpu_set_full(
29 const char *rvalue,
30 CPUSet *cpu_set,
31 bool warn,
32 const char *unit,
33 const char *filename, unsigned line,
34 const char *lvalue);
35int parse_cpu_set_extend(
36 const char *rvalue,
37 CPUSet *old,
38 bool warn,
39 const char *unit,
40 const char *filename,
41 unsigned line,
42 const char *lvalue);
43
44static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
45 return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
6d8a29b2 46}
f44b3035 47
c367f996
MS
48int cpu_set_to_dbus(const CPUSet *set, uint8_t **ret, size_t *allocated);
49int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *set);
50
f44b3035 51int cpus_in_affinity_mask(void);