sched.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _SCHED_H
  2. #define _SCHED_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #define __NEED_struct_timespec
  8. #define __NEED_pid_t
  9. #define __NEED_time_t
  10. #ifdef _GNU_SOURCE
  11. #define __NEED_size_t
  12. #endif
  13. #include <bits/alltypes.h>
  14. struct sched_param {
  15. int sched_priority;
  16. int sched_ss_low_priority;
  17. struct timespec sched_ss_repl_period;
  18. struct timespec sched_ss_init_budget;
  19. int sched_ss_max_repl;
  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. #define SCHED_OTHER 0
  30. #define SCHED_FIFO 1
  31. #define SCHED_RR 2
  32. #define SCHED_BATCH 3
  33. #define SCHED_IDLE 5
  34. #define SCHED_DEADLINE 6
  35. #define SCHED_RESET_ON_FORK 0x40000000
  36. #ifdef _GNU_SOURCE
  37. #define CSIGNAL 0x000000ff
  38. #define CLONE_VM 0x00000100
  39. #define CLONE_FS 0x00000200
  40. #define CLONE_FILES 0x00000400
  41. #define CLONE_SIGHAND 0x00000800
  42. #define CLONE_PTRACE 0x00002000
  43. #define CLONE_VFORK 0x00004000
  44. #define CLONE_PARENT 0x00008000
  45. #define CLONE_THREAD 0x00010000
  46. #define CLONE_NEWNS 0x00020000
  47. #define CLONE_SYSVSEM 0x00040000
  48. #define CLONE_SETTLS 0x00080000
  49. #define CLONE_PARENT_SETTID 0x00100000
  50. #define CLONE_CHILD_CLEARTID 0x00200000
  51. #define CLONE_DETACHED 0x00400000
  52. #define CLONE_UNTRACED 0x00800000
  53. #define CLONE_CHILD_SETTID 0x01000000
  54. #define CLONE_NEWCGROUP 0x02000000
  55. #define CLONE_NEWUTS 0x04000000
  56. #define CLONE_NEWIPC 0x08000000
  57. #define CLONE_NEWUSER 0x10000000
  58. #define CLONE_NEWPID 0x20000000
  59. #define CLONE_NEWNET 0x40000000
  60. #define CLONE_IO 0x80000000
  61. int clone (int (*)(void *), void *, int, void *, ...);
  62. int unshare(int);
  63. int setns(int, int);
  64. void *memcpy(void *__restrict, const void *__restrict, size_t);
  65. int memcmp(const void *, const void *, size_t);
  66. void *calloc(size_t, size_t);
  67. void free(void *);
  68. typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t;
  69. int __sched_cpucount(size_t, const cpu_set_t *);
  70. int sched_getcpu(void);
  71. int sched_getaffinity(pid_t, size_t, cpu_set_t *);
  72. int sched_setaffinity(pid_t, size_t, const cpu_set_t *);
  73. #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
  74. ((set)->__bits[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
  75. #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=)
  76. #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~)
  77. #define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &)
  78. #define __CPU_op_func_S(func, op) \
  79. static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \
  80. const cpu_set_t *__src1, const cpu_set_t *__src2) \
  81. { \
  82. size_t __i; \
  83. for (__i=0; __i<__size/sizeof(long); __i++) \
  84. __dest->__bits[__i] = __src1->__bits[__i] \
  85. op __src2->__bits[__i] ; \
  86. }
  87. __CPU_op_func_S(AND, &)
  88. __CPU_op_func_S(OR, |)
  89. __CPU_op_func_S(XOR, ^)
  90. #define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d)
  91. #define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d)
  92. #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d)
  93. #define CPU_COUNT_S(size,set) __sched_cpucount(size,set)
  94. #define CPU_ZERO_S(size,set) memset(set,0,size)
  95. #define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size))
  96. #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \
  97. + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) )
  98. #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
  99. #define CPU_FREE(set) free(set)
  100. #define CPU_SETSIZE 128
  101. #define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
  102. #define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
  103. #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
  104. #define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2)
  105. #define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2)
  106. #define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2)
  107. #define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
  108. #define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
  109. #define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
  110. #endif
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif