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