sched.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Definitions for POSIX 1003.1b-1993 (aka POSIX.4) scheduling interface.
  2. Copyright (C) 1996-2020 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SCHED_H
  16. #define _SCHED_H 1
  17. #include <features.h>
  18. /* Get type definitions. */
  19. #include <bits/types.h>
  20. #define __need_size_t
  21. #define __need_NULL
  22. #include <stddef.h>
  23. #include <bits/types/time_t.h>
  24. #include <bits/types/struct_timespec.h>
  25. #ifndef __USE_XOPEN2K
  26. # include <time.h>
  27. #endif
  28. #ifndef __pid_t_defined
  29. typedef __pid_t pid_t;
  30. # define __pid_t_defined
  31. #endif
  32. /* Get system specific constant and data structure definitions. */
  33. #include <bits/sched.h>
  34. #include <bits/cpu-set.h>
  35. /* Backward compatibility. */
  36. #define sched_priority sched_priority
  37. #define __sched_priority sched_priority
  38. __BEGIN_DECLS
  39. /* Set scheduling parameters for a process. */
  40. extern int sched_setparam (__pid_t __pid, const struct sched_param *__param)
  41. __THROW;
  42. /* Retrieve scheduling parameters for a particular process. */
  43. extern int sched_getparam (__pid_t __pid, struct sched_param *__param) __THROW;
  44. /* Set scheduling algorithm and/or parameters for a process. */
  45. extern int sched_setscheduler (__pid_t __pid, int __policy,
  46. const struct sched_param *__param) __THROW;
  47. /* Retrieve scheduling algorithm for a particular purpose. */
  48. extern int sched_getscheduler (__pid_t __pid) __THROW;
  49. /* Yield the processor. */
  50. extern int sched_yield (void) __THROW;
  51. /* Get maximum priority value for a scheduler. */
  52. extern int sched_get_priority_max (int __algorithm) __THROW;
  53. /* Get minimum priority value for a scheduler. */
  54. extern int sched_get_priority_min (int __algorithm) __THROW;
  55. /* Get the SCHED_RR interval for the named process. */
  56. extern int sched_rr_get_interval (__pid_t __pid, struct timespec *__t) __THROW;
  57. #ifdef __USE_GNU
  58. /* Access macros for `cpu_set'. */
  59. # define CPU_SETSIZE __CPU_SETSIZE
  60. # define CPU_SET(cpu, cpusetp) __CPU_SET_S (cpu, sizeof (cpu_set_t), cpusetp)
  61. # define CPU_CLR(cpu, cpusetp) __CPU_CLR_S (cpu, sizeof (cpu_set_t), cpusetp)
  62. # define CPU_ISSET(cpu, cpusetp) __CPU_ISSET_S (cpu, sizeof (cpu_set_t), \
  63. cpusetp)
  64. # define CPU_ZERO(cpusetp) __CPU_ZERO_S (sizeof (cpu_set_t), cpusetp)
  65. # define CPU_COUNT(cpusetp) __CPU_COUNT_S (sizeof (cpu_set_t), cpusetp)
  66. # define CPU_SET_S(cpu, setsize, cpusetp) __CPU_SET_S (cpu, setsize, cpusetp)
  67. # define CPU_CLR_S(cpu, setsize, cpusetp) __CPU_CLR_S (cpu, setsize, cpusetp)
  68. # define CPU_ISSET_S(cpu, setsize, cpusetp) __CPU_ISSET_S (cpu, setsize, \
  69. cpusetp)
  70. # define CPU_ZERO_S(setsize, cpusetp) __CPU_ZERO_S (setsize, cpusetp)
  71. # define CPU_COUNT_S(setsize, cpusetp) __CPU_COUNT_S (setsize, cpusetp)
  72. # define CPU_EQUAL(cpusetp1, cpusetp2) \
  73. __CPU_EQUAL_S (sizeof (cpu_set_t), cpusetp1, cpusetp2)
  74. # define CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
  75. __CPU_EQUAL_S (setsize, cpusetp1, cpusetp2)
  76. # define CPU_AND(destset, srcset1, srcset2) \
  77. __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, &)
  78. # define CPU_OR(destset, srcset1, srcset2) \
  79. __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, |)
  80. # define CPU_XOR(destset, srcset1, srcset2) \
  81. __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, ^)
  82. # define CPU_AND_S(setsize, destset, srcset1, srcset2) \
  83. __CPU_OP_S (setsize, destset, srcset1, srcset2, &)
  84. # define CPU_OR_S(setsize, destset, srcset1, srcset2) \
  85. __CPU_OP_S (setsize, destset, srcset1, srcset2, |)
  86. # define CPU_XOR_S(setsize, destset, srcset1, srcset2) \
  87. __CPU_OP_S (setsize, destset, srcset1, srcset2, ^)
  88. # define CPU_ALLOC_SIZE(count) __CPU_ALLOC_SIZE (count)
  89. # define CPU_ALLOC(count) __CPU_ALLOC (count)
  90. # define CPU_FREE(cpuset) __CPU_FREE (cpuset)
  91. /* Set the CPU affinity for a task */
  92. extern int sched_setaffinity (__pid_t __pid, size_t __cpusetsize,
  93. const cpu_set_t *__cpuset) __THROW;
  94. /* Get the CPU affinity for a task */
  95. extern int sched_getaffinity (__pid_t __pid, size_t __cpusetsize,
  96. cpu_set_t *__cpuset) __THROW;
  97. #endif
  98. __END_DECLS
  99. #endif /* sched.h */