]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/cpuset.h
2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
7 #ifndef UTIL_LINUX_CPUSET_H
8 #define UTIL_LINUX_CPUSET_H
13 * Fallback for old or obscure libcs without dynamically allocated cpusets
15 * The following macros are based on code from glibc.
17 * The GNU C Library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 #if !HAVE_DECL_CPU_ALLOC
24 # define CPU_ZERO_S(setsize, cpusetp) \
27 size_t __imax = (setsize) / sizeof (__cpu_mask); \
28 __cpu_mask *__bits = (cpusetp)->__bits; \
29 for (__i = 0; __i < __imax; ++__i) \
33 # define CPU_SET_S(cpu, setsize, cpusetp) \
34 ({ size_t __cpu = (cpu); \
35 __cpu < 8 * (setsize) \
36 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
37 |= __CPUMASK (__cpu)) \
40 # define CPU_ISSET_S(cpu, setsize, cpusetp) \
41 ({ size_t __cpu = (cpu); \
42 __cpu < 8 * (setsize) \
43 ? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
44 & __CPUMASK (__cpu))) != 0 \
47 # define CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
48 ({ __cpu_mask *__arr1 = (cpusetp1)->__bits; \
49 __cpu_mask *__arr2 = (cpusetp2)->__bits; \
50 size_t __imax = (setsize) / sizeof (__cpu_mask); \
52 for (__i = 0; __i < __imax; ++__i) \
53 if (__arr1[__i] != __arr2[__i]) \
57 extern int __cpuset_count_s(size_t setsize
, const cpu_set_t
*set
);
58 # define CPU_COUNT_S(setsize, cpusetp) __cpuset_count_s(setsize, cpusetp)
60 # define CPU_ALLOC_SIZE(count) \
61 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
62 # define CPU_ALLOC(count) (malloc(CPU_ALLOC_SIZE(count)))
63 # define CPU_FREE(cpuset) (free(cpuset))
65 #endif /* !HAVE_DECL_CPU_ALLOC */
68 #define cpuset_nbits(setsize) (8 * (setsize))
71 * The @idx parameter returns an index of the first mask from @ary array where
74 * Returns: 0 if found, otherwise 1.
76 static inline int cpuset_ary_isset(size_t cpu
, cpu_set_t
**ary
, size_t nmemb
,
77 size_t setsize
, size_t *idx
)
81 for (i
= 0; i
< nmemb
; i
++) {
82 if (CPU_ISSET_S(cpu
, setsize
, ary
[i
])) {
90 extern int get_max_number_of_cpus(void);
92 extern cpu_set_t
*cpuset_alloc(int ncpus
, size_t *setsize
, size_t *nbits
);
93 extern void cpuset_free(cpu_set_t
*set
);
95 extern char *cpulist_create(char *str
, size_t len
, cpu_set_t
*set
, size_t setsize
);
96 extern int cpulist_parse(const char *str
, cpu_set_t
*set
, size_t setsize
, int fail
);
98 extern char *cpumask_create(char *str
, size_t len
, cpu_set_t
*set
, size_t setsize
);
99 extern int cpumask_parse(const char *str
, cpu_set_t
*set
, size_t setsize
);
101 #endif /* UTIL_LINUX_CPUSET_H */