diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-08-10 21:15:11 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-08-10 21:15:11 -0400 |
commit | eeb0328f203cfb8990b3eee5ee31d931fc539ceb (patch) | |
tree | 99558d1b944c1cf76f33faab7e294c72480a7328 /include/sched.h | |
parent | 76fbf6ad4bb2f697512a1541d296c1f749e3b504 (diff) | |
download | musl-eeb0328f203cfb8990b3eee5ee31d931fc539ceb.tar.gz musl-eeb0328f203cfb8990b3eee5ee31d931fc539ceb.tar.bz2 musl-eeb0328f203cfb8990b3eee5ee31d931fc539ceb.tar.xz musl-eeb0328f203cfb8990b3eee5ee31d931fc539ceb.zip |
add cpu affinity interfaces
this first commit just includes the CPU_* and sched_* interfaces, not
the pthread_* interfaces, which may be added later. simple
sanity-check testing has been done for the basic interfaces, but most
of the macros have not yet been tested.
Diffstat (limited to 'include/sched.h')
-rw-r--r-- | include/sched.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/include/sched.h b/include/sched.h index 994260d0..6a6b2fcb 100644 --- a/include/sched.h +++ b/include/sched.h @@ -10,6 +10,10 @@ extern "C" { #define __NEED_pid_t #define __NEED_time_t +#ifdef _GNU_SOURCE +#define __NEED_size_t +#endif + #include <bits/alltypes.h> struct sched_param { @@ -63,6 +67,63 @@ int sched_yield(void); int clone (int (*)(void *), void *, int, void *, ...); int unshare(int); int setns(int, int); + +void *memcpy(void *__restrict, const void *__restrict, size_t); +int memcmp(const void *, const void *, size_t); +void *calloc(size_t, size_t); +void free(void *); + +typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; +int __sched_cpucount(size_t, const cpu_set_t *); +int sched_getaffinity(pid_t, size_t, cpu_set_t *); +int sched_setaffinity(pid_t, size_t, const cpu_set_t *); + +#define __CPU_op_S(i, size, set, op) ( (i)/8 >= (size) ? 0 : \ + ((set)->__bits[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) + +#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) +#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) +#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) + +#define __CPU_op_func_S(func, op) \ +static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ + const cpu_set_t *__src1, const cpu_set_t *__src2) \ +{ \ + size_t __i; \ + for (__i=0; __i<__size/sizeof(long); __i++) \ + __dest->__bits[__i] = __src1->__bits[__i] \ + op __src2->__bits[__i] ; \ +} + +__CPU_op_func_S(AND, &) +__CPU_op_func_S(OR, |) +__CPU_op_func_S(XOR, ^) + +#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) +#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) +#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) + +#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) +#define CPU_ZERO_S(size,set) memset(set,0,size) +#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) + +#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ + + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) +#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) +#define CPU_FREE(set) free(set) + +#define CPU_SETSIZE 128 + +#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) +#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) +#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) +#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) +#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) +#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) +#define CPU_EQUAL(set) CPU_EQUAL_S(sizeof(cpu_set_t),set) + #endif #ifdef __cplusplus |