sched.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Definitions of constants and data structure for POSIX 1003.1b-1993
  2. scheduling interface.
  3. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <https://www.gnu.org/licenses/>. */
  16. #ifndef _BITS_SCHED_H
  17. #define _BITS_SCHED_H 1
  18. #ifndef _SCHED_H
  19. # error "Never include <bits/sched.h> directly; use <sched.h> instead."
  20. #endif
  21. /* Scheduling algorithms. */
  22. #define SCHED_OTHER 0
  23. #define SCHED_FIFO 1
  24. #define SCHED_RR 2
  25. #ifdef __USE_GNU
  26. # define SCHED_NORMAL 0
  27. # define SCHED_BATCH 3
  28. # define SCHED_ISO 4
  29. # define SCHED_IDLE 5
  30. # define SCHED_DEADLINE 6
  31. # define SCHED_EXT 7
  32. /* Flags that can be used in policy values. */
  33. # define SCHED_RESET_ON_FORK 0x40000000
  34. /* Flags for the sched_flags field in struct sched_attr. */
  35. #define SCHED_FLAG_RESET_ON_FORK 0x01
  36. #define SCHED_FLAG_RECLAIM 0x02
  37. #define SCHED_FLAG_DL_OVERRUN 0x04
  38. #define SCHED_FLAG_KEEP_POLICY 0x08
  39. #define SCHED_FLAG_KEEP_PARAMS 0x10
  40. #define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
  41. #define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
  42. /* Combinations of sched_flags fields. */
  43. #define SCHED_FLAG_KEEP_ALL \
  44. (SCHED_FLAG_KEEP_POLICY | SCHED_FLAG_KEEP_PARAMS)
  45. #define SCHED_FLAG_UTIL_CLAMP \
  46. (SCHED_FLAG_UTIL_CLAMP_MIN | SCHED_FLAG_UTIL_CLAMP_MAX)
  47. /* Use "" to work around incorrect macro expansion of the
  48. __has_include argument (GCC PR 80005). */
  49. # ifdef __has_include
  50. # if __has_include ("linux/sched/types.h")
  51. /* Some older Linux versions defined sched_param in <linux/sched/types.h>. */
  52. # define sched_param __glibc_mask_sched_param
  53. # include <linux/sched/types.h>
  54. # undef sched_param
  55. # endif
  56. # endif
  57. # ifndef SCHED_ATTR_SIZE_VER0
  58. # include <linux/types.h>
  59. # define SCHED_ATTR_SIZE_VER0 48
  60. # define SCHED_ATTR_SIZE_VER1 56
  61. struct sched_attr
  62. {
  63. __u32 size;
  64. __u32 sched_policy;
  65. __u64 sched_flags;
  66. __s32 sched_nice;
  67. __u32 sched_priority;
  68. __u64 sched_runtime;
  69. __u64 sched_deadline;
  70. __u64 sched_period;
  71. __u32 sched_util_min;
  72. __u32 sched_util_max;
  73. /* Additional fields may be added at the end. */
  74. };
  75. # endif /* !SCHED_ATTR_SIZE_VER0 */
  76. /* Cloning flags. */
  77. # define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */
  78. # define CLONE_VM 0x00000100 /* Set if VM shared between processes. */
  79. # define CLONE_FS 0x00000200 /* Set if fs info shared between processes. */
  80. # define CLONE_FILES 0x00000400 /* Set if open files shared between processes. */
  81. # define CLONE_SIGHAND 0x00000800 /* Set if signal handlers shared. */
  82. # define CLONE_PIDFD 0x00001000 /* Set if a pidfd should be placed
  83. in parent. */
  84. # define CLONE_PTRACE 0x00002000 /* Set if tracing continues on the child. */
  85. # define CLONE_VFORK 0x00004000 /* Set if the parent wants the child to
  86. wake it up on mm_release. */
  87. # define CLONE_PARENT 0x00008000 /* Set if we want to have the same
  88. parent as the cloner. */
  89. # define CLONE_THREAD 0x00010000 /* Set to add to same thread group. */
  90. # define CLONE_NEWNS 0x00020000 /* Set to create new namespace. */
  91. # define CLONE_SYSVSEM 0x00040000 /* Set to shared SVID SEM_UNDO semantics. */
  92. # define CLONE_SETTLS 0x00080000 /* Set TLS info. */
  93. # define CLONE_PARENT_SETTID 0x00100000 /* Store TID in userlevel buffer
  94. before MM copy. */
  95. # define CLONE_CHILD_CLEARTID 0x00200000 /* Register exit futex and memory
  96. location to clear. */
  97. # define CLONE_DETACHED 0x00400000 /* Create clone detached. */
  98. # define CLONE_UNTRACED 0x00800000 /* Set if the tracing process can't
  99. force CLONE_PTRACE on this clone. */
  100. # define CLONE_CHILD_SETTID 0x01000000 /* Store TID in userlevel buffer in
  101. the child. */
  102. # define CLONE_NEWCGROUP 0x02000000 /* New cgroup namespace. */
  103. # define CLONE_NEWUTS 0x04000000 /* New utsname group. */
  104. # define CLONE_NEWIPC 0x08000000 /* New ipcs. */
  105. # define CLONE_NEWUSER 0x10000000 /* New user namespace. */
  106. # define CLONE_NEWPID 0x20000000 /* New pid namespace. */
  107. # define CLONE_NEWNET 0x40000000 /* New network namespace. */
  108. # define CLONE_IO 0x80000000 /* Clone I/O context. */
  109. /* cloning flags intersect with CSIGNAL so can be used only with unshare and
  110. clone3 syscalls. */
  111. #define CLONE_NEWTIME 0x00000080 /* New time namespace */
  112. #endif
  113. #include <bits/types/struct_sched_param.h>
  114. __BEGIN_DECLS
  115. #ifdef __USE_GNU
  116. /* Clone current process. */
  117. extern int clone (int (*__fn) (void *__arg), void *__child_stack,
  118. int __flags, void *__arg, ...) __THROW;
  119. /* Unshare the specified resources. */
  120. extern int unshare (int __flags) __THROW;
  121. /* Get index of currently used CPU. */
  122. extern int sched_getcpu (void) __THROW;
  123. /* Get currently used CPU and NUMA node. */
  124. extern int getcpu (unsigned int *, unsigned int *) __THROW;
  125. /* Switch process to namespace of type NSTYPE indicated by FD. */
  126. extern int setns (int __fd, int __nstype) __THROW;
  127. /* Apply the scheduling attributes from *ATTR to the process or thread TID. */
  128. int sched_setattr (pid_t tid, struct sched_attr *attr, unsigned int flags)
  129. __THROW __nonnull ((2));
  130. /* Obtain the scheduling attributes of the process or thread TID and
  131. store it in *ATTR. */
  132. int sched_getattr (pid_t tid, struct sched_attr *attr, unsigned int size,
  133. unsigned int flags)
  134. __THROW __nonnull ((2));
  135. #endif
  136. __END_DECLS
  137. #endif /* bits/sched.h */