sched.h 6.4 KB

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