xref: /openbmc/linux/tools/perf/util/cpu-set-sched.h (revision f16fe2d3)
1 // SPDX-License-Identifier: LGPL-2.1
2 // Definitions taken from glibc for use with older systems, same licensing.
3 #ifndef _CPU_SET_SCHED_PERF_H
4 #define _CPU_SET_SCHED_PERF_H
5 
6 #include <features.h>
7 #include <sched.h>
8 
9 #ifndef CPU_EQUAL
10 #ifndef __CPU_EQUAL_S
11 #if __GNUC_PREREQ (2, 91)
12 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
13   (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
14 #else
15 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
16   (__extension__							      \
17    ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits;			      \
18       const __cpu_mask *__arr2 = (cpusetp2)->__bits;			      \
19       size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
20       size_t __i;							      \
21       for (__i = 0; __i < __imax; ++__i)				      \
22 	if (__arr1[__i] != __arr2[__i])					      \
23 	  break;							      \
24       __i == __imax; }))
25 #endif
26 #endif // __CPU_EQUAL_S
27 
28 #define CPU_EQUAL(cpusetp1, cpusetp2) \
29   __CPU_EQUAL_S (sizeof (cpu_set_t), cpusetp1, cpusetp2)
30 #endif // CPU_EQUAL
31 
32 #ifndef CPU_OR
33 #ifndef __CPU_OP_S
34 #define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
35   (__extension__							      \
36    ({ cpu_set_t *__dest = (destset);					      \
37       const __cpu_mask *__arr1 = (srcset1)->__bits;			      \
38       const __cpu_mask *__arr2 = (srcset2)->__bits;			      \
39       size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
40       size_t __i;							      \
41       for (__i = 0; __i < __imax; ++__i)				      \
42 	((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i];    \
43       __dest; }))
44 #endif // __CPU_OP_S
45 
46 #define CPU_OR(destset, srcset1, srcset2) \
47   __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, |)
48 #endif // CPU_OR
49 
50 #endif // _CPU_SET_SCHED_PERF_H
51