1 #ifndef _SCHED_H 2 #define _SCHED_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 #include <features.h> 8 9 #define __NEED_struct_timespec 10 #define __NEED_pid_t 11 #define __NEED_time_t 12 13 #ifdef _GNU_SOURCE 14 #define __NEED_size_t 15 #endif 16 17 #include <bits/alltypes.h> 18 19 #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ 20 struct sched_param { 21 int sched_priority; 22 int __reserved1; 23 #if _REDIR_TIME64 24 long __reserved2[4]; 25 #else 26 struct { 27 time_t __reserved1; 28 long __reserved2; 29 } __reserved2[2]; 30 #endif 31 int __reserved3; 32 }; 33 34 int sched_get_priority_max(int); 35 int sched_get_priority_min(int); 36 int sched_getparam(pid_t, struct sched_param *); 37 int sched_getscheduler(pid_t); 38 int sched_rr_get_interval(pid_t, struct timespec *); 39 int sched_setparam(pid_t, const struct sched_param *); 40 int sched_setscheduler(pid_t, int, const struct sched_param *); 41 #endif 42 int sched_yield(void); 43 44 #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ 45 #define SCHED_OTHER 0 46 #define SCHED_FIFO 1 47 #define SCHED_RR 2 48 #define SCHED_BATCH 3 49 #define SCHED_IDLE 5 50 #define SCHED_DEADLINE 6 51 #define SCHED_RESET_ON_FORK 0x40000000 52 53 #ifdef _GNU_SOURCE 54 #define CSIGNAL 0x000000ff 55 #define CLONE_NEWTIME 0x00000080 56 #define CLONE_VM 0x00000100 57 #define CLONE_FS 0x00000200 58 #define CLONE_FILES 0x00000400 59 #define CLONE_SIGHAND 0x00000800 60 #define CLONE_PIDFD 0x00001000 61 #define CLONE_PTRACE 0x00002000 62 #define CLONE_VFORK 0x00004000 63 #define CLONE_PARENT 0x00008000 64 #define CLONE_THREAD 0x00010000 65 #define CLONE_NEWNS 0x00020000 66 #define CLONE_SYSVSEM 0x00040000 67 #define CLONE_SETTLS 0x00080000 68 #define CLONE_PARENT_SETTID 0x00100000 69 #define CLONE_CHILD_CLEARTID 0x00200000 70 #define CLONE_DETACHED 0x00400000 71 #define CLONE_UNTRACED 0x00800000 72 #define CLONE_CHILD_SETTID 0x01000000 73 #define CLONE_NEWCGROUP 0x02000000 74 #define CLONE_NEWUTS 0x04000000 75 #define CLONE_NEWIPC 0x08000000 76 #define CLONE_NEWUSER 0x10000000 77 #define CLONE_NEWPID 0x20000000 78 #define CLONE_NEWNET 0x40000000 79 #define CLONE_IO 0x80000000 80 int clone (int (*)(void *), void *, int, void *, ...); 81 int unshare(int); 82 int setns(int, int); 83 84 void *memcpy(void *__restrict, const void *__restrict, size_t); 85 int memcmp(const void *, const void *, size_t); 86 void *memset (void *, int, size_t); 87 void *calloc(size_t, size_t); 88 void free(void *); 89 90 typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; 91 int __sched_cpucount(size_t, const cpu_set_t *); 92 int sched_getcpu(void); 93 int sched_getaffinity(pid_t, size_t, cpu_set_t *); 94 int sched_setaffinity(pid_t, size_t, const cpu_set_t *); 95 96 #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ 97 (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) 98 99 #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) 100 #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) 101 #define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) 102 103 #define __CPU_op_func_S(func, op) \ 104 static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ 105 const cpu_set_t *__src1, const cpu_set_t *__src2) \ 106 { \ 107 size_t __i; \ 108 for (__i=0; __i<__size/sizeof(long); __i++) \ 109 ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ 110 op ((unsigned long *)__src2)[__i] ; \ 111 } 112 113 __CPU_op_func_S(AND, &) 114 __CPU_op_func_S(OR, |) 115 __CPU_op_func_S(XOR, ^) 116 117 #define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) 118 #define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) 119 #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) 120 121 #define CPU_COUNT_S(size,set) __sched_cpucount(size,set) 122 #define CPU_ZERO_S(size,set) memset(set,0,size) 123 #define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) 124 125 #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ 126 + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) 127 #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) 128 #define CPU_FREE(set) free(set) 129 130 #define CPU_SETSIZE 128 131 132 #define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) 133 #define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) 134 #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) 135 #define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) 136 #define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) 137 #define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) 138 #define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) 139 #define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) 140 #define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) 141 142 #endif 143 #endif 144 145 #if _REDIR_TIME64 146 __REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); 147 #endif 148 149 #ifdef __cplusplus 150 } 151 #endif 152 #endif 153