]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/cpuset.h
2 * This file may be redistributed under the terms of the
3 * GNU Lesser General Public License.
5 #ifndef UTIL_LINUX_CPUSET_H
6 #define UTIL_LINUX_CPUSET_H
11 * Fallback for old or obscure libcs without dynamically allocated cpusets
13 * The following macros are based on code from glibc.
15 * The GNU C Library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 #if !HAVE_DECL_CPU_ALLOC
22 # define CPU_ZERO_S(setsize, cpusetp) \
25 size_t __imax = (setsize) / sizeof (__cpu_mask); \
26 __cpu_mask *__bits = (cpusetp)->__bits; \
27 for (__i = 0; __i < __imax; ++__i) \
31 # define CPU_SET_S(cpu, setsize, cpusetp) \
32 ({ size_t __cpu = (cpu); \
33 __cpu < 8 * (setsize) \
34 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
35 |= __CPUMASK (__cpu)) \
38 # define CPU_ISSET_S(cpu, setsize, cpusetp) \
39 ({ size_t __cpu = (cpu); \
40 __cpu < 8 * (setsize) \
41 ? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
42 & __CPUMASK (__cpu))) != 0 \
45 # define CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
46 ({ __cpu_mask *__arr1 = (cpusetp1)->__bits; \
47 __cpu_mask *__arr2 = (cpusetp2)->__bits; \
48 size_t __imax = (setsize) / sizeof (__cpu_mask); \
50 for (__i = 0; __i < __imax; ++__i) \
51 if (__arr1[__i] != __arr2[__i]) \
55 extern int __cpuset_count_s(size_t setsize
, const cpu_set_t
*set
);
56 # define CPU_COUNT_S(setsize, cpusetp) __cpuset_count_s(setsize, cpusetp)
58 # define CPU_ALLOC_SIZE(count) \
59 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
60 # define CPU_ALLOC(count) (malloc(CPU_ALLOC_SIZE(count)))
61 # define CPU_FREE(cpuset) (free(cpuset))
63 #endif /* !HAVE_DECL_CPU_ALLOC */
66 #define cpuset_nbits(setsize) (8 * (setsize))
69 * The @idx parameter returns an index of the first mask from @ary array where
72 * Returns: 0 if found, otherwise 1.
74 static inline int cpuset_ary_isset(size_t cpu
, cpu_set_t
**ary
, size_t nmemb
,
75 size_t setsize
, size_t *idx
)
79 for (i
= 0; i
< nmemb
; i
++) {
80 if (CPU_ISSET_S(cpu
, setsize
, ary
[i
])) {
88 extern int get_max_number_of_cpus(void);
90 extern cpu_set_t
*cpuset_alloc(int ncpus
, size_t *setsize
, size_t *nbits
);
91 extern void cpuset_free(cpu_set_t
*set
);
93 extern char *cpulist_create(char *str
, size_t len
, cpu_set_t
*set
, size_t setsize
);
94 extern int cpulist_parse(const char *str
, cpu_set_t
*set
, size_t setsize
, int fail
);
96 extern char *cpumask_create(char *str
, size_t len
, cpu_set_t
*set
, size_t setsize
);
97 extern int cpumask_parse(const char *str
, cpu_set_t
*set
, size_t setsize
);
99 #endif /* UTIL_LINUX_CPUSET_H */