cpuset.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_softwall(int node, gfp_t gfp_mask);
  44. extern int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask);
  45. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  46. {
  47. return nr_cpusets() <= 1 ||
  48. __cpuset_node_allowed_softwall(node, gfp_mask);
  49. }
  50. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  51. {
  52. return nr_cpusets() <= 1 ||
  53. __cpuset_node_allowed_hardwall(node, gfp_mask);
  54. }
  55. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  56. {
  57. return cpuset_node_allowed_softwall(zone_to_nid(z), gfp_mask);
  58. }
  59. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  60. {
  61. return cpuset_node_allowed_hardwall(zone_to_nid(z), gfp_mask);
  62. }
  63. extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  64. const struct task_struct *tsk2);
  65. #define cpuset_memory_pressure_bump() \
  66. do { \
  67. if (cpuset_memory_pressure_enabled) \
  68. __cpuset_memory_pressure_bump(); \
  69. } while (0)
  70. extern int cpuset_memory_pressure_enabled;
  71. extern void __cpuset_memory_pressure_bump(void);
  72. extern void cpuset_task_status_allowed(struct seq_file *m,
  73. struct task_struct *task);
  74. extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
  75. struct pid *pid, struct task_struct *tsk);
  76. extern int cpuset_mem_spread_node(void);
  77. extern int cpuset_slab_spread_node(void);
  78. static inline int cpuset_do_page_mem_spread(void)
  79. {
  80. return task_spread_page(current);
  81. }
  82. static inline int cpuset_do_slab_mem_spread(void)
  83. {
  84. return task_spread_slab(current);
  85. }
  86. extern int current_cpuset_is_being_rebound(void);
  87. extern void rebuild_sched_domains(void);
  88. extern void cpuset_print_task_mems_allowed(struct task_struct *p);
  89. /*
  90. * read_mems_allowed_begin is required when making decisions involving
  91. * mems_allowed such as during page allocation. mems_allowed can be updated in
  92. * parallel and depending on the new value an operation can fail potentially
  93. * causing process failure. A retry loop with read_mems_allowed_begin and
  94. * read_mems_allowed_retry prevents these artificial failures.
  95. */
  96. static inline unsigned int read_mems_allowed_begin(void)
  97. {
  98. return read_seqcount_begin(&current->mems_allowed_seq);
  99. }
  100. /*
  101. * If this returns true, the operation that took place after
  102. * read_mems_allowed_begin may have failed artificially due to a concurrent
  103. * update of mems_allowed. It is up to the caller to retry the operation if
  104. * appropriate.
  105. */
  106. static inline bool read_mems_allowed_retry(unsigned int seq)
  107. {
  108. return read_seqcount_retry(&current->mems_allowed_seq, seq);
  109. }
  110. static inline void set_mems_allowed(nodemask_t nodemask)
  111. {
  112. unsigned long flags;
  113. task_lock(current);
  114. local_irq_save(flags);
  115. write_seqcount_begin(&current->mems_allowed_seq);
  116. current->mems_allowed = nodemask;
  117. write_seqcount_end(&current->mems_allowed_seq);
  118. local_irq_restore(flags);
  119. task_unlock(current);
  120. }
  121. #else /* !CONFIG_CPUSETS */
  122. static inline bool cpusets_enabled(void) { return false; }
  123. static inline int cpuset_init(void) { return 0; }
  124. static inline void cpuset_init_smp(void) {}
  125. static inline void cpuset_update_active_cpus(bool cpu_online)
  126. {
  127. partition_sched_domains(1, NULL, NULL);
  128. }
  129. static inline void cpuset_cpus_allowed(struct task_struct *p,
  130. struct cpumask *mask)
  131. {
  132. cpumask_copy(mask, cpu_possible_mask);
  133. }
  134. static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
  135. {
  136. }
  137. static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  138. {
  139. return node_possible_map;
  140. }
  141. #define cpuset_current_mems_allowed (node_states[N_MEMORY])
  142. static inline void cpuset_init_current_mems_allowed(void) {}
  143. static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  144. {
  145. return 1;
  146. }
  147. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  148. {
  149. return 1;
  150. }
  151. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  152. {
  153. return 1;
  154. }
  155. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  156. {
  157. return 1;
  158. }
  159. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  160. {
  161. return 1;
  162. }
  163. static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  164. const struct task_struct *tsk2)
  165. {
  166. return 1;
  167. }
  168. static inline void cpuset_memory_pressure_bump(void) {}
  169. static inline void cpuset_task_status_allowed(struct seq_file *m,
  170. struct task_struct *task)
  171. {
  172. }
  173. static inline int cpuset_mem_spread_node(void)
  174. {
  175. return 0;
  176. }
  177. static inline int cpuset_slab_spread_node(void)
  178. {
  179. return 0;
  180. }
  181. static inline int cpuset_do_page_mem_spread(void)
  182. {
  183. return 0;
  184. }
  185. static inline int cpuset_do_slab_mem_spread(void)
  186. {
  187. return 0;
  188. }
  189. static inline int current_cpuset_is_being_rebound(void)
  190. {
  191. return 0;
  192. }
  193. static inline void rebuild_sched_domains(void)
  194. {
  195. partition_sched_domains(1, NULL, NULL);
  196. }
  197. static inline void cpuset_print_task_mems_allowed(struct task_struct *p)
  198. {
  199. }
  200. static inline void set_mems_allowed(nodemask_t nodemask)
  201. {
  202. }
  203. static inline unsigned int read_mems_allowed_begin(void)
  204. {
  205. return 0;
  206. }
  207. static inline bool read_mems_allowed_retry(unsigned int seq)
  208. {
  209. return false;
  210. }
  211. #endif /* !CONFIG_CPUSETS */
  212. #endif /* _LINUX_CPUSET_H */