1570af302Sopenharmony_ci#ifndef _SCHED_H 2570af302Sopenharmony_ci#define _SCHED_H 3570af302Sopenharmony_ci#ifdef __cplusplus 4570af302Sopenharmony_ciextern "C" { 5570af302Sopenharmony_ci#endif 6570af302Sopenharmony_ci 7570af302Sopenharmony_ci#include <features.h> 8570af302Sopenharmony_ci 9570af302Sopenharmony_ci#define __NEED_struct_timespec 10570af302Sopenharmony_ci#define __NEED_pid_t 11570af302Sopenharmony_ci#define __NEED_time_t 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci#ifdef _GNU_SOURCE 14570af302Sopenharmony_ci#define __NEED_size_t 15570af302Sopenharmony_ci#endif 16570af302Sopenharmony_ci 17570af302Sopenharmony_ci#include <bits/alltypes.h> 18570af302Sopenharmony_ci#include <stddef.h> 19570af302Sopenharmony_cistruct sched_param { 20570af302Sopenharmony_ci int sched_priority; 21570af302Sopenharmony_ci int __reserved1; 22570af302Sopenharmony_ci#if _REDIR_TIME64 23570af302Sopenharmony_ci long __reserved2[4]; 24570af302Sopenharmony_ci#else 25570af302Sopenharmony_ci struct { 26570af302Sopenharmony_ci time_t __reserved1; 27570af302Sopenharmony_ci long __reserved2; 28570af302Sopenharmony_ci } __reserved2[2]; 29570af302Sopenharmony_ci#endif 30570af302Sopenharmony_ci int __reserved3; 31570af302Sopenharmony_ci}; 32570af302Sopenharmony_ci 33570af302Sopenharmony_ciint sched_get_priority_max(int); 34570af302Sopenharmony_ciint sched_get_priority_min(int); 35570af302Sopenharmony_ciint sched_getparam(pid_t, struct sched_param *); 36570af302Sopenharmony_ciint sched_getscheduler(pid_t); 37570af302Sopenharmony_ciint sched_rr_get_interval(pid_t, struct timespec *); 38570af302Sopenharmony_ciint sched_setparam(pid_t, const struct sched_param *); 39570af302Sopenharmony_ciint sched_setscheduler(pid_t, int, const struct sched_param *); 40570af302Sopenharmony_ciint sched_yield(void); 41570af302Sopenharmony_ci 42570af302Sopenharmony_ci 43570af302Sopenharmony_ci#define SCHED_OTHER 0 44570af302Sopenharmony_ci#define SCHED_FIFO 1 45570af302Sopenharmony_ci#define SCHED_RR 2 46570af302Sopenharmony_ci#define SCHED_BATCH 3 47570af302Sopenharmony_ci#define SCHED_IDLE 5 48570af302Sopenharmony_ci#define SCHED_DEADLINE 6 49570af302Sopenharmony_ci#define SCHED_RESET_ON_FORK 0x40000000 50570af302Sopenharmony_ci 51570af302Sopenharmony_ci#ifdef _GNU_SOURCE 52570af302Sopenharmony_ci#define CSIGNAL 0x000000ff 53570af302Sopenharmony_ci#define CLONE_NEWTIME 0x00000080 54570af302Sopenharmony_ci#define CLONE_VM 0x00000100 55570af302Sopenharmony_ci#define CLONE_FS 0x00000200 56570af302Sopenharmony_ci#define CLONE_FILES 0x00000400 57570af302Sopenharmony_ci#define CLONE_SIGHAND 0x00000800 58570af302Sopenharmony_ci#define CLONE_PIDFD 0x00001000 59570af302Sopenharmony_ci#define CLONE_PTRACE 0x00002000 60570af302Sopenharmony_ci#define CLONE_VFORK 0x00004000 61570af302Sopenharmony_ci#define CLONE_PARENT 0x00008000 62570af302Sopenharmony_ci#define CLONE_THREAD 0x00010000 63570af302Sopenharmony_ci#define CLONE_NEWNS 0x00020000 64570af302Sopenharmony_ci#define CLONE_SYSVSEM 0x00040000 65570af302Sopenharmony_ci#define CLONE_SETTLS 0x00080000 66570af302Sopenharmony_ci#define CLONE_PARENT_SETTID 0x00100000 67570af302Sopenharmony_ci#define CLONE_CHILD_CLEARTID 0x00200000 68570af302Sopenharmony_ci#define CLONE_DETACHED 0x00400000 69570af302Sopenharmony_ci#define CLONE_UNTRACED 0x00800000 70570af302Sopenharmony_ci#define CLONE_CHILD_SETTID 0x01000000 71570af302Sopenharmony_ci#define CLONE_NEWCGROUP 0x02000000 72570af302Sopenharmony_ci#define CLONE_NEWUTS 0x04000000 73570af302Sopenharmony_ci#define CLONE_NEWIPC 0x08000000 74570af302Sopenharmony_ci#define CLONE_NEWUSER 0x10000000 75570af302Sopenharmony_ci#define CLONE_NEWPID 0x20000000 76570af302Sopenharmony_ci#define CLONE_NEWNET 0x40000000 77570af302Sopenharmony_ci#define CLONE_IO 0x80000000 78570af302Sopenharmony_ciint clone (int (*)(void *), void *, int, void *, ...); 79570af302Sopenharmony_ciint unshare(int); 80570af302Sopenharmony_ciint setns(int, int); 81570af302Sopenharmony_ci 82570af302Sopenharmony_civoid *memcpy(void *__restrict, const void *__restrict, size_t); 83570af302Sopenharmony_ciint memcmp(const void *, const void *, size_t); 84570af302Sopenharmony_civoid *memset (void *, int, size_t); 85570af302Sopenharmony_civoid *calloc(size_t, size_t); 86570af302Sopenharmony_civoid free(void *); 87570af302Sopenharmony_ci 88570af302Sopenharmony_citypedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; 89570af302Sopenharmony_cicpu_set_t* __sched_cpualloc(size_t __count); 90570af302Sopenharmony_ciint __sched_cpucount(size_t, const cpu_set_t *); 91570af302Sopenharmony_ciint sched_getcpu(void); 92570af302Sopenharmony_ciint sched_getaffinity(pid_t, size_t, cpu_set_t *); 93570af302Sopenharmony_ciint sched_setaffinity(pid_t, size_t, const cpu_set_t *); 94570af302Sopenharmony_ci 95570af302Sopenharmony_ci#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ 96570af302Sopenharmony_ci (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) 97570af302Sopenharmony_ci 98570af302Sopenharmony_ci#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) 99570af302Sopenharmony_ci#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) 100570af302Sopenharmony_ci#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) 101570af302Sopenharmony_ci 102570af302Sopenharmony_ci#define __CPU_op_func_S(func, op) \ 103570af302Sopenharmony_cistatic __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ 104570af302Sopenharmony_ci const cpu_set_t *__src1, const cpu_set_t *__src2) \ 105570af302Sopenharmony_ci{ \ 106570af302Sopenharmony_ci size_t __i; \ 107570af302Sopenharmony_ci for (__i=0; __i<__size/sizeof(long); __i++) \ 108570af302Sopenharmony_ci ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ 109570af302Sopenharmony_ci op ((unsigned long *)__src2)[__i] ; \ 110570af302Sopenharmony_ci} 111570af302Sopenharmony_ci 112570af302Sopenharmony_ci__CPU_op_func_S(AND, &) 113570af302Sopenharmony_ci__CPU_op_func_S(OR, |) 114570af302Sopenharmony_ci__CPU_op_func_S(XOR, ^) 115570af302Sopenharmony_ci 116570af302Sopenharmony_ci#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) 117570af302Sopenharmony_ci#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) 118570af302Sopenharmony_ci#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) 119570af302Sopenharmony_ci 120570af302Sopenharmony_ci#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) 121570af302Sopenharmony_ci#define CPU_ZERO_S(size,set) memset(set,0,size) 122570af302Sopenharmony_ci#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) 123570af302Sopenharmony_ci 124570af302Sopenharmony_ci#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ 125570af302Sopenharmony_ci + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) 126570af302Sopenharmony_ci#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) 127570af302Sopenharmony_ci#define CPU_FREE(set) free(set) 128570af302Sopenharmony_ci 129570af302Sopenharmony_ci#define CPU_SETSIZE 128 130570af302Sopenharmony_ci 131570af302Sopenharmony_ci#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) 132570af302Sopenharmony_ci#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) 133570af302Sopenharmony_ci#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) 134570af302Sopenharmony_ci#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) 135570af302Sopenharmony_ci#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) 136570af302Sopenharmony_ci#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) 137570af302Sopenharmony_ci#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) 138570af302Sopenharmony_ci#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) 139570af302Sopenharmony_ci#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) 140570af302Sopenharmony_ci 141570af302Sopenharmony_ci 142570af302Sopenharmony_ci#endif 143570af302Sopenharmony_ci 144570af302Sopenharmony_ci#if _REDIR_TIME64 145570af302Sopenharmony_ci__REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); 146570af302Sopenharmony_ci#endif 147570af302Sopenharmony_ci 148570af302Sopenharmony_ci#ifdef __cplusplus 149570af302Sopenharmony_ci} 150570af302Sopenharmony_ci#endif 151570af302Sopenharmony_ci#endif 152570af302Sopenharmony_ci 153570af302Sopenharmony_ci 154