17777dab0Sopenharmony_ci#ifndef _SCHED_H 27777dab0Sopenharmony_ci#define _SCHED_H 37777dab0Sopenharmony_ci#ifdef __cplusplus 47777dab0Sopenharmony_ciextern "C" { 57777dab0Sopenharmony_ci#endif 67777dab0Sopenharmony_ci 77777dab0Sopenharmony_ci#include <features.h> 87777dab0Sopenharmony_ci 97777dab0Sopenharmony_ci#define __NEED_struct_timespec 107777dab0Sopenharmony_ci#define __NEED_pid_t 117777dab0Sopenharmony_ci#define __NEED_time_t 127777dab0Sopenharmony_ci 137777dab0Sopenharmony_ci#ifdef _GNU_SOURCE 147777dab0Sopenharmony_ci#define __NEED_size_t 157777dab0Sopenharmony_ci#endif 167777dab0Sopenharmony_ci 177777dab0Sopenharmony_ci#include <bits/alltypes.h> 187777dab0Sopenharmony_ci#include <stddef.h> 197777dab0Sopenharmony_cistruct sched_param { 207777dab0Sopenharmony_ci int sched_priority; 217777dab0Sopenharmony_ci int __reserved1; 227777dab0Sopenharmony_ci#if _REDIR_TIME64 237777dab0Sopenharmony_ci long __reserved2[4]; 247777dab0Sopenharmony_ci#else 257777dab0Sopenharmony_ci struct { 267777dab0Sopenharmony_ci time_t __reserved1; 277777dab0Sopenharmony_ci long __reserved2; 287777dab0Sopenharmony_ci } __reserved2[2]; 297777dab0Sopenharmony_ci#endif 307777dab0Sopenharmony_ci int __reserved3; 317777dab0Sopenharmony_ci}; 327777dab0Sopenharmony_ci 337777dab0Sopenharmony_ciint sched_get_priority_max(int); 347777dab0Sopenharmony_ciint sched_get_priority_min(int); 357777dab0Sopenharmony_ciint sched_getparam(pid_t, struct sched_param *); 367777dab0Sopenharmony_ciint sched_getscheduler(pid_t); 377777dab0Sopenharmony_ciint sched_rr_get_interval(pid_t, struct timespec *); 387777dab0Sopenharmony_ciint sched_setparam(pid_t, const struct sched_param *); 397777dab0Sopenharmony_ciint sched_setscheduler(pid_t, int, const struct sched_param *); 407777dab0Sopenharmony_ciint sched_yield(void); 417777dab0Sopenharmony_ci 427777dab0Sopenharmony_ci 437777dab0Sopenharmony_ci#define SCHED_OTHER 0 447777dab0Sopenharmony_ci#define SCHED_FIFO 1 457777dab0Sopenharmony_ci#define SCHED_RR 2 467777dab0Sopenharmony_ci#define SCHED_BATCH 3 477777dab0Sopenharmony_ci#define SCHED_IDLE 5 487777dab0Sopenharmony_ci#define SCHED_DEADLINE 6 497777dab0Sopenharmony_ci#define SCHED_RESET_ON_FORK 0x40000000 507777dab0Sopenharmony_ci 517777dab0Sopenharmony_ci#ifdef _GNU_SOURCE 527777dab0Sopenharmony_ci#define CSIGNAL 0x000000ff 537777dab0Sopenharmony_ci#define CLONE_VM 0x00000100 547777dab0Sopenharmony_ci#define CLONE_FS 0x00000200 557777dab0Sopenharmony_ci#define CLONE_FILES 0x00000400 567777dab0Sopenharmony_ci#define CLONE_SIGHAND 0x00000800 577777dab0Sopenharmony_ci#define CLONE_PIDFD 0x00001000 587777dab0Sopenharmony_ci#define CLONE_PTRACE 0x00002000 597777dab0Sopenharmony_ci#define CLONE_VFORK 0x00004000 607777dab0Sopenharmony_ci#define CLONE_PARENT 0x00008000 617777dab0Sopenharmony_ci#define CLONE_THREAD 0x00010000 627777dab0Sopenharmony_ci#define CLONE_NEWNS 0x00020000 637777dab0Sopenharmony_ci#define CLONE_SYSVSEM 0x00040000 647777dab0Sopenharmony_ci#define CLONE_SETTLS 0x00080000 657777dab0Sopenharmony_ci#define CLONE_PARENT_SETTID 0x00100000 667777dab0Sopenharmony_ci#define CLONE_CHILD_CLEARTID 0x00200000 677777dab0Sopenharmony_ci#define CLONE_DETACHED 0x00400000 687777dab0Sopenharmony_ci#define CLONE_UNTRACED 0x00800000 697777dab0Sopenharmony_ci#define CLONE_CHILD_SETTID 0x01000000 707777dab0Sopenharmony_ci#define CLONE_NEWCGROUP 0x02000000 717777dab0Sopenharmony_ci#define CLONE_NEWUTS 0x04000000 727777dab0Sopenharmony_ci#define CLONE_NEWIPC 0x08000000 737777dab0Sopenharmony_ci#define CLONE_NEWUSER 0x10000000 747777dab0Sopenharmony_ci#define CLONE_NEWPID 0x20000000 757777dab0Sopenharmony_ci#define CLONE_NEWNET 0x40000000 767777dab0Sopenharmony_ci#define CLONE_IO 0x80000000 777777dab0Sopenharmony_ciint clone (int (*)(void *), void *, int, void *, ...); 787777dab0Sopenharmony_ciint unshare(int); 797777dab0Sopenharmony_ciint setns(int, int); 807777dab0Sopenharmony_ci 817777dab0Sopenharmony_civoid *memcpy(void *__restrict, const void *__restrict, size_t); 827777dab0Sopenharmony_ciint memcmp(const void *, const void *, size_t); 837777dab0Sopenharmony_civoid *memset (void *, int, size_t); 847777dab0Sopenharmony_civoid *calloc(size_t, size_t); 857777dab0Sopenharmony_civoid free(void *); 867777dab0Sopenharmony_ci 877777dab0Sopenharmony_citypedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; 887777dab0Sopenharmony_cicpu_set_t* __sched_cpualloc(size_t __count); 897777dab0Sopenharmony_ciint __sched_cpucount(size_t, const cpu_set_t *); 907777dab0Sopenharmony_ciint sched_getcpu(void); 917777dab0Sopenharmony_ciint sched_getaffinity(pid_t, size_t, cpu_set_t *); 927777dab0Sopenharmony_ciint sched_setaffinity(pid_t, size_t, const cpu_set_t *); 937777dab0Sopenharmony_ci 947777dab0Sopenharmony_ci#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ 957777dab0Sopenharmony_ci (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) 967777dab0Sopenharmony_ci 977777dab0Sopenharmony_ci#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) 987777dab0Sopenharmony_ci#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) 997777dab0Sopenharmony_ci#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) 1007777dab0Sopenharmony_ci 1017777dab0Sopenharmony_ci#define __CPU_op_func_S(func, op) \ 1027777dab0Sopenharmony_cistatic __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ 1037777dab0Sopenharmony_ci const cpu_set_t *__src1, const cpu_set_t *__src2) \ 1047777dab0Sopenharmony_ci{ \ 1057777dab0Sopenharmony_ci size_t __i; \ 1067777dab0Sopenharmony_ci for (__i=0; __i<__size/sizeof(long); __i++) \ 1077777dab0Sopenharmony_ci ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ 1087777dab0Sopenharmony_ci op ((unsigned long *)__src2)[__i] ; \ 1097777dab0Sopenharmony_ci} 1107777dab0Sopenharmony_ci 1117777dab0Sopenharmony_ci__CPU_op_func_S(AND, &) 1127777dab0Sopenharmony_ci__CPU_op_func_S(OR, |) 1137777dab0Sopenharmony_ci__CPU_op_func_S(XOR, ^) 1147777dab0Sopenharmony_ci 1157777dab0Sopenharmony_ci#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) 1167777dab0Sopenharmony_ci#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) 1177777dab0Sopenharmony_ci#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) 1187777dab0Sopenharmony_ci 1197777dab0Sopenharmony_ci#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) 1207777dab0Sopenharmony_ci#define CPU_ZERO_S(size,set) memset(set,0,size) 1217777dab0Sopenharmony_ci#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) 1227777dab0Sopenharmony_ci 1237777dab0Sopenharmony_ci#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ 1247777dab0Sopenharmony_ci + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) 1257777dab0Sopenharmony_ci#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) 1267777dab0Sopenharmony_ci#define CPU_FREE(set) free(set) 1277777dab0Sopenharmony_ci 1287777dab0Sopenharmony_ci#define CPU_SETSIZE 128 1297777dab0Sopenharmony_ci 1307777dab0Sopenharmony_ci#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) 1317777dab0Sopenharmony_ci#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) 1327777dab0Sopenharmony_ci#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) 1337777dab0Sopenharmony_ci#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) 1347777dab0Sopenharmony_ci#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) 1357777dab0Sopenharmony_ci#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) 1367777dab0Sopenharmony_ci#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) 1377777dab0Sopenharmony_ci#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) 1387777dab0Sopenharmony_ci#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) 1397777dab0Sopenharmony_ci 1407777dab0Sopenharmony_ci 1417777dab0Sopenharmony_ci#endif 1427777dab0Sopenharmony_ci 1437777dab0Sopenharmony_ci#if _REDIR_TIME64 1447777dab0Sopenharmony_ci__REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); 1457777dab0Sopenharmony_ci#endif 1467777dab0Sopenharmony_ci 1477777dab0Sopenharmony_ci#ifdef __cplusplus 1487777dab0Sopenharmony_ci} 1497777dab0Sopenharmony_ci#endif 1507777dab0Sopenharmony_ci#endif 1517777dab0Sopenharmony_ci 1527777dab0Sopenharmony_ci 153