xref: /netbsd-src/external/bsd/nsd/dist/compat/cpuset.h (revision 811a4a0195236f69295602fbee687a174d42af9b)
1 /*
2  * cpuset.h -- CPU affinity.
3  *
4  * Copyright (c) 2020, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  *
8  */
9 #ifndef CPUSET_H
10 #define CPUSET_H
11 
12 #ifdef HAVE_SCHED_H
13 # include <sched.h>
14 #endif
15 
16 #ifdef HAVE_SYS_CPUSET_H
17 # include <sys/cpuset.h>
18 #endif
19 
20 /*
21  * CPU affinity is currently only supported on Linux and FreeBSD. Other
22  * operating systems may be supported in the future, but not all operating
23  * systems offer the same functionality. OpenBSD for example does not support
24  * any kind of CPU affinity, while Solaris offers specifying a set of
25  * processors, but a processor can only be part of a single set.
26  *
27  * NOTE: On macOS Mojave, processor_set_create returned KERN_FAILURE which
28  *       indicates processor allocation is not supported by the operating
29  *       system.
30  */
31 
32 #ifndef HAVE_CPUSET_T
33 #ifdef HAVE_CPU_SET_T
34 #define HAVE_CPUSET_T 1
35 typedef cpu_set_t cpuset_t;
36 #endif
37 #endif
38 
39 #ifndef HAVE_CPUID_T
40 #ifdef __linux__
41 typedef int cpuid_t;
42 #elif defined(__FreeBSD__) || defined(__gnu_hurd__) || defined(__DragonFly__)
43 typedef size_t cpuid_t;
44 #else
45 typedef size_t cpuid_t;
46 #endif
47 #endif
48 
49 #ifndef HAVE_CPUSET_CREATE
50 cpuset_t *cpuset_create(void);
51 #endif
52 
53 #ifndef HAVE_CPUSET_DESTROY
54 void cpuset_destroy(cpuset_t *set);
55 #endif
56 
57 #ifndef HAVE_CPUSET_ZERO
58 void cpuset_zero(cpuset_t *set);
59 #endif
60 
61 #ifndef HAVE_CPUSET_SET
62 int cpuset_set(cpuid_t cpu, cpuset_t *set);
63 #endif
64 
65 #ifndef HAVE_CPUSET_CLR
66 int cpuset_clr(cpuid_t cpu, cpuset_t *set);
67 #endif
68 
69 #ifndef HAVE_CPUSET_ISSET
70 int cpuset_isset(cpuid_t cpu, const cpuset_t *set);
71 #endif
72 
73 #ifndef HAVE_CPUSET_SIZE
74 size_t cpuset_size(const cpuset_t *set);
75 #endif
76 
77 void cpuset_or(cpuset_t *destset, const cpuset_t *srcset);
78 
79 #endif /* CPUSET_H */
80