cpuset.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifndef _LINUX_CPUSET_H
  2. #define _LINUX_CPUSET_H
  3. /*
  4. * cpuset interface
  5. *
  6. * Copyright (C) 2003 BULL SA
  7. * Copyright (C) 2004-2006 Silicon Graphics, Inc.
  8. *
  9. */
  10. #include <linux/sched.h>
  11. #include <linux/cpumask.h>
  12. #include <linux/nodemask.h>
  13. #include <linux/mm.h>
  14. #include <linux/jump_label.h>
  15. #ifdef CONFIG_CPUSETS
  16. extern struct static_key cpusets_enabled_key;
  17. static inline bool cpusets_enabled(void)
  18. {
  19. return static_key_false(&cpusets_enabled_key);
  20. }
  21. static inline int nr_cpusets(void)
  22. {
  23. /* jump label reference count + the top-level cpuset */
  24. return static_key_count(&cpusets_enabled_key) + 1;
  25. }
  26. static inline void cpuset_inc(void)
  27. {
  28. static_key_slow_inc(&cpusets_enabled_key);
  29. }
  30. static inline void cpuset_dec(void)
  31. {
  32. static_key_slow_dec(&cpusets_enabled_key);
  33. }
  34. extern int cpuset_init(void);
  35. extern void cpuset_init_smp(void);
  36. extern void cpuset_update_active_cpus(bool cpu_online);
  37. extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
  38. extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
  39. extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
  40. #define cpuset_current_mems_allowed (current->mems_allowed)
  41. void cpuset_init_current_mems_allowed(void);
  42. int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
  43. extern int __cpuset_node_allowed(int node, gfp_t gfp_mask);
  44. static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
  45. {
  46. return nr_cpusets() <= 1 || __cpuset_node_allowed(node, gfp_mask);
  47. }
  48. static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
  49. {
  50. return cpuset_node_allowed(zone_to_nid(z), gfp_mask);
  51. }
  52. extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  53. const struct task_struct *tsk2);
  54. #define cpuset_memory_pressure_bump() \
  55. do { \
  56. if (cpuset_memory_pressure_enabled) \
  57. __cpuset_memory_pressure_bump(); \
  58. } while (0)
  59. extern int cpuset_memory_pressure_enabled;
  60. extern void __cpuset_memory_pressure_bump(void);
  61. extern void cpuset_task_status_allowed(struct seq_file *m,
  62. struct task_struct *task);
  63. extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
  64. struct pid *pid, struct task_struct *tsk);
  65. extern int cpuset_mem_spread_node(void);
  66. extern int cpuset_slab_spread_node(void);
  67. static inline int cpuset_do_page_mem_spread(void)
  68. {
  69. return task_spread_page(current);
  70. }
  71. static inline int cpuset_do_slab_mem_spread(void)
  72. {
  73. return task_spread_slab(current);
  74. }
  75. extern int current_cpuset_is_being_rebound(void);
  76. extern void rebuild_sched_domains(void);
  77. extern void cpuset_print_current_mems_allowed(void);
  78. /*
  79. * read_mems_allowed_begin is required when making decisions involving
  80. * mems_allowed such as during page allocation. mems_allowed can be updated in
  81. * parallel and depending on the new value an operation can fail potentially
  82. * causing process failure. A retry loop with read_mems_allowed_begin and
  83. * read_mems_allowed_retry prevents these artificial failures.
  84. */
  85. static inline unsigned int read_mems_allowed_begin(void)
  86. {
  87. if (!cpusets_enabled())
  88. return 0;
  89. return read_seqcount_begin(&current->mems_allowed_seq);
  90. }
  91. /*
  92. * If this returns true, the operation that took place after
  93. * read_mems_allowed_begin may have failed artificially due to a concurrent
  94. * update of mems_allowed. It is up to the caller to retry the operation if
  95. * appropriate.
  96. */
  97. static inline bool read_mems_allowed_retry(unsigned int seq)
  98. {
  99. if (!cpusets_enabled())
  100. return false;
  101. return read_seqcount_retry(&current->mems_allowed_seq, seq);
  102. }
  103. static inline void set_mems_allowed(nodemask_t nodemask)
  104. {
  105. unsigned long flags;
  106. task_lock(current);
  107. local_irq_save(flags);
  108. write_seqcount_begin(&current->mems_allowed_seq);
  109. current->mems_allowed = nodemask;
  110. write_seqcount_end(&current->mems_allowed_seq);
  111. local_irq_restore(flags);
  112. task_unlock(current);
  113. }
  114. extern void cpuset_post_attach_flush(void);
  115. #else /* !CONFIG_CPUSETS */
  116. static inline bool cpusets_enabled(void) { return false; }
  117. static inline int cpuset_init(void) { return 0; }
  118. static inline void cpuset_init_smp(void) {}
  119. static inline void cpuset_update_active_cpus(bool cpu_online)
  120. {
  121. partition_sched_domains(1, NULL, NULL);
  122. }
  123. static inline void cpuset_cpus_allowed(struct task_struct *p,
  124. struct cpumask *mask)
  125. {
  126. cpumask_copy(mask, cpu_possible_mask);
  127. }
  128. static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
  129. {
  130. }
  131. static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  132. {
  133. return node_possible_map;
  134. }
  135. #define cpuset_current_mems_allowed (node_states[N_MEMORY])
  136. static inline void cpuset_init_current_mems_allowed(void) {}
  137. static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  138. {
  139. return 1;
  140. }
  141. static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
  142. {
  143. return 1;
  144. }
  145. static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
  146. {
  147. return 1;
  148. }
  149. static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  150. const struct task_struct *tsk2)
  151. {
  152. return 1;
  153. }
  154. static inline void cpuset_memory_pressure_bump(void) {}
  155. static inline void cpuset_task_status_allowed(struct seq_file *m,
  156. struct task_struct *task)
  157. {
  158. }
  159. static inline int cpuset_mem_spread_node(void)
  160. {
  161. return 0;
  162. }
  163. static inline int cpuset_slab_spread_node(void)
  164. {
  165. return 0;
  166. }
  167. static inline int cpuset_do_page_mem_spread(void)
  168. {
  169. return 0;
  170. }
  171. static inline int cpuset_do_slab_mem_spread(void)
  172. {
  173. return 0;
  174. }
  175. static inline int current_cpuset_is_being_rebound(void)
  176. {
  177. return 0;
  178. }
  179. static inline void rebuild_sched_domains(void)
  180. {
  181. partition_sched_domains(1, NULL, NULL);
  182. }
  183. static inline void cpuset_print_current_mems_allowed(void)
  184. {
  185. }
  186. static inline void set_mems_allowed(nodemask_t nodemask)
  187. {
  188. }
  189. static inline unsigned int read_mems_allowed_begin(void)
  190. {
  191. return 0;
  192. }
  193. static inline bool read_mems_allowed_retry(unsigned int seq)
  194. {
  195. return false;
  196. }
  197. static inline void cpuset_post_attach_flush(void)
  198. {
  199. }
  200. #endif /* !CONFIG_CPUSETS */
  201. #endif /* _LINUX_CPUSET_H */