1 /** 2 * @defgroup sched Sched 3 * @ingroup libc 4 */ 5 6 #ifndef _SCHED_H 7 #define _SCHED_H 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 #include <features.h> 13 14 #define __NEED_struct_timespec 15 #define __NEED_pid_t 16 #define __NEED_time_t 17 18 #ifdef _GNU_SOURCE 19 #define __NEED_size_t 20 #endif 21 22 #include <bits/alltypes.h> 23 24 struct sched_param { 25 int sched_priority; 26 int __reserved1; 27 #if _REDIR_TIME64 28 long __reserved2[4]; 29 #else 30 struct { 31 time_t __reserved1; 32 long __reserved2; 33 } __reserved2[2]; 34 #endif 35 int __reserved3; 36 }; 37 38 /** 39 * @ingroup sched 40 * 41 * @par Description: 42 * The sched_get_priority_max() function shall return the appropriate maximum for the scheduling policy. 43 * 44 * @attention 45 * <ul> 46 * <li>LiteOS only support the scheduling policy is SCHED_RR.</li> 47 * </ul> 48 * 49 * @retval #int The sched_get_priority_max() function shall return the appropriate maximum values;\n 50 * otherwise, it shall return -1 and set errno to indicate the error. 51 * 52 * @par Errors 53 * <ul> 54 * <li><b>EINVAL</b>: The value of the policy parameter does not represent a defined scheduling policy.</li> 55 * </ul> 56 * 57 * @par Dependency: 58 * <ul><li>sched.h</li></ul> 59 * @see sched_get_priority_min 60 */ 61 int sched_get_priority_max(int); 62 63 /** 64 * @ingroup sched 65 * 66 * @par Description: 67 * The sched_get_priority_min() function shall return the appropriate minimum for the scheduling policy. 68 * 69 * @attention 70 * <ul> 71 * <li>LiteOS only support the scheduling policy is SCHED_RR.</li> 72 * </ul> 73 * 74 * @retval #int The sched_get_priority_min() function shall return the appropriate minimum values;\n 75 * otherwise, it shall return -1 and set errno to indicate the error. 76 * 77 * @par Errors 78 * <ul> 79 * <li><b>EINVAL</b>: The value of the policy parameter does not represent a defined scheduling policy.</li> 80 * </ul> 81 * 82 * @par Dependency: 83 * <ul><li>sched.h</li></ul> 84 * @see sched_get_priority_max 85 */ 86 int sched_get_priority_min(int); 87 int sched_getparam(pid_t, struct sched_param *); 88 int sched_getscheduler(pid_t); 89 int sched_rr_get_interval(pid_t, struct timespec *); 90 int sched_setparam(pid_t, const struct sched_param *); 91 int sched_setscheduler(pid_t, int, const struct sched_param *); 92 93 /** 94 * @ingroup sched 95 * 96 * @par Description: 97 * The sched_yield() function force the running thread to relinquish the processor. 98 * 99 * @attention 100 * <ul> 101 * <li>None.</li> 102 * </ul> 103 * 104 * @retval #int The sched_yield() function shall return 0 if it completes successfully;\n 105 * otherwise, it shall return -1. 106 * @par Dependency: 107 * <ul><li>sched.h</li></ul> 108 * @see None 109 */ 110 int sched_yield(void); 111 112 #define SCHED_OTHER 0 113 #define SCHED_FIFO 1 114 #define SCHED_RR 2 115 #define SCHED_BATCH 3 116 #define SCHED_IDLE 5 117 #define SCHED_DEADLINE 6 118 #define SCHED_RESET_ON_FORK 0x40000000 119 120 #ifdef __LITEOS__ 121 #define __CPU_BITTYPE unsigned long 122 #endif 123 124 #ifdef _GNU_SOURCE 125 #define CSIGNAL 0x000000ff 126 #define CLONE_VM 0x00000100 127 #define CLONE_FS 0x00000200 128 #define CLONE_FILES 0x00000400 129 #define CLONE_SIGHAND 0x00000800 130 #define CLONE_PIDFD 0x00001000 131 #define CLONE_PTRACE 0x00002000 132 #define CLONE_VFORK 0x00004000 133 #define CLONE_PARENT 0x00008000 134 #define CLONE_THREAD 0x00010000 135 #define CLONE_NEWNS 0x00020000 136 #define CLONE_SYSVSEM 0x00040000 137 #define CLONE_SETTLS 0x00080000 138 #define CLONE_PARENT_SETTID 0x00100000 139 #define CLONE_CHILD_CLEARTID 0x00200000 140 #define CLONE_DETACHED 0x00400000 141 #define CLONE_UNTRACED 0x00800000 142 #define CLONE_CHILD_SETTID 0x01000000 143 #define CLONE_NEWCGROUP 0x02000000 144 #define CLONE_NEWUTS 0x04000000 145 #define CLONE_NEWIPC 0x08000000 146 #define CLONE_NEWUSER 0x10000000 147 #define CLONE_NEWPID 0x20000000 148 #define CLONE_NEWNET 0x40000000 149 #define CLONE_IO 0x80000000 150 int clone (int (*)(void *), void *, int, void *, ...); 151 int unshare(int); 152 int setns(int, int); 153 154 void *memcpy(void *__restrict, const void *__restrict, size_t); 155 int memcmp(const void *, const void *, size_t); 156 void *memset (void *, int, size_t); 157 void *calloc(size_t, size_t); 158 void free(void *); 159 160 typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; 161 int __sched_cpucount(size_t, const cpu_set_t *); 162 int sched_getcpu(void); 163 int sched_getaffinity(pid_t, size_t, cpu_set_t *); 164 int sched_setaffinity(pid_t, size_t, const cpu_set_t *); 165 166 #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ 167 (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) 168 169 #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) 170 #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) 171 #define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) 172 173 #define __CPU_op_func_S(func, op) \ 174 static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ 175 const cpu_set_t *__src1, const cpu_set_t *__src2) \ 176 { \ 177 size_t __i; \ 178 for (__i=0; __i<__size/sizeof(long); __i++) \ 179 ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ 180 op ((unsigned long *)__src2)[__i] ; \ 181 } 182 183 __CPU_op_func_S(AND, &) 184 __CPU_op_func_S(OR, |) 185 __CPU_op_func_S(XOR, ^) 186 187 #define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) 188 #define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) 189 #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) 190 191 #define CPU_COUNT_S(size,set) __sched_cpucount(size,set) 192 #define CPU_ZERO_S(size,set) memset(set,0,size) 193 #define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) 194 195 #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ 196 + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) 197 #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) 198 #define CPU_FREE(set) free(set) 199 200 #define CPU_SETSIZE 128 201 202 #define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) 203 #define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) 204 #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) 205 #define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) 206 #define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) 207 #define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) 208 #define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) 209 #define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) 210 #define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) 211 212 #endif 213 214 #if _REDIR_TIME64 215 __REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); 216 #endif 217 218 #ifdef __cplusplus 219 } 220 #endif 221 #endif 222