1
#ifndef UTIL_LINUX_CPUSET_H
2
#define UTIL_LINUX_CPUSET_H
7
* Fallback for old or obscure libcs without dynamically allocated cpusets
9
* The following macros are based on code from glibc.
11
* The GNU C Library is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public
13
* License as published by the Free Software Foundation; either
14
* version 2.1 of the License, or (at your option) any later version.
16
#if !HAVE_DECL_CPU_ALLOC
18
# define CPU_ZERO_S(setsize, cpusetp) \
21
size_t __imax = (setsize) / sizeof (__cpu_mask); \
22
__cpu_mask *__bits = (cpusetp)->__bits; \
23
for (__i = 0; __i < __imax; ++__i) \
27
# define CPU_SET_S(cpu, setsize, cpusetp) \
28
({ size_t __cpu = (cpu); \
29
__cpu < 8 * (setsize) \
30
? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
31
|= __CPUMASK (__cpu)) \
34
# define CPU_ISSET_S(cpu, setsize, cpusetp) \
35
({ size_t __cpu = (cpu); \
36
__cpu < 8 * (setsize) \
37
? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
38
& __CPUMASK (__cpu))) != 0 \
41
# define CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
42
({ __cpu_mask *__arr1 = (cpusetp1)->__bits; \
43
__cpu_mask *__arr2 = (cpusetp2)->__bits; \
44
size_t __imax = (setsize) / sizeof (__cpu_mask); \
46
for (__i = 0; __i < __imax; ++__i) \
47
if (__arr1[__i] != __arr2[__i]) \
51
extern int __cpuset_count_s(size_t setsize, const cpu_set_t *set);
52
# define CPU_COUNT_S(setsize, cpusetp) __cpuset_count_s(setsize, cpusetp)
54
# define CPU_ALLOC_SIZE(count) \
55
((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
56
# define CPU_ALLOC(count) (malloc(CPU_ALLOC_SIZE(count)))
57
# define CPU_FREE(cpuset) (free(cpuset))
59
#endif /* !HAVE_DECL_CPU_ALLOC */
62
#define cpuset_nbits(setsize) (8 * (setsize))
64
extern int get_max_number_of_cpus(void);
66
extern cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits);
67
extern void cpuset_free(cpu_set_t *set);
69
extern char *cpulist_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
70
extern int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize);
72
extern char *cpumask_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
73
extern int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize);
75
#endif /* UTIL_LINUX_CPUSET_H */