cpuset.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/cgroup.h>
  14. #include <linux/mm.h>
  15. #ifdef CONFIG_CPUSETS
  16. extern int number_of_cpusets; /* How many cpusets are defined in system? */
  17. extern int cpuset_init(void);
  18. extern void cpuset_init_smp(void);
  19. extern void cpuset_update_active_cpus(void);
  20. extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
  21. extern int cpuset_cpus_allowed_fallback(struct task_struct *p);
  22. extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
  23. #define cpuset_current_mems_allowed (current->mems_allowed)
  24. void cpuset_init_current_mems_allowed(void);
  25. int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
  26. extern int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask);
  27. extern int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask);
  28. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  29. {
  30. return number_of_cpusets <= 1 ||
  31. __cpuset_node_allowed_softwall(node, gfp_mask);
  32. }
  33. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  34. {
  35. return number_of_cpusets <= 1 ||
  36. __cpuset_node_allowed_hardwall(node, gfp_mask);
  37. }
  38. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  39. {
  40. return cpuset_node_allowed_softwall(zone_to_nid(z), gfp_mask);
  41. }
  42. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  43. {
  44. return cpuset_node_allowed_hardwall(zone_to_nid(z), gfp_mask);
  45. }
  46. extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  47. const struct task_struct *tsk2);
  48. #define cpuset_memory_pressure_bump() \
  49. do { \
  50. if (cpuset_memory_pressure_enabled) \
  51. __cpuset_memory_pressure_bump(); \
  52. } while (0)
  53. extern int cpuset_memory_pressure_enabled;
  54. extern void __cpuset_memory_pressure_bump(void);
  55. extern const struct file_operations proc_cpuset_operations;
  56. struct seq_file;
  57. extern void cpuset_task_status_allowed(struct seq_file *m,
  58. struct task_struct *task);
  59. extern int cpuset_mem_spread_node(void);
  60. extern int cpuset_slab_spread_node(void);
  61. static inline int cpuset_do_page_mem_spread(void)
  62. {
  63. return current->flags & PF_SPREAD_PAGE;
  64. }
  65. static inline int cpuset_do_slab_mem_spread(void)
  66. {
  67. return current->flags & PF_SPREAD_SLAB;
  68. }
  69. extern int current_cpuset_is_being_rebound(void);
  70. extern void rebuild_sched_domains(void);
  71. extern void cpuset_print_task_mems_allowed(struct task_struct *p);
  72. /*
  73. * reading current mems_allowed and mempolicy in the fastpath must protected
  74. * by get_mems_allowed()
  75. */
  76. static inline void get_mems_allowed(void)
  77. {
  78. current->mems_allowed_change_disable++;
  79. /*
  80. * ensure that reading mems_allowed and mempolicy happens after the
  81. * update of ->mems_allowed_change_disable.
  82. *
  83. * the write-side task finds ->mems_allowed_change_disable is not 0,
  84. * and knows the read-side task is reading mems_allowed or mempolicy,
  85. * so it will clear old bits lazily.
  86. */
  87. smp_mb();
  88. }
  89. static inline void put_mems_allowed(void)
  90. {
  91. /*
  92. * ensure that reading mems_allowed and mempolicy before reducing
  93. * mems_allowed_change_disable.
  94. *
  95. * the write-side task will know that the read-side task is still
  96. * reading mems_allowed or mempolicy, don't clears old bits in the
  97. * nodemask.
  98. */
  99. smp_mb();
  100. --ACCESS_ONCE(current->mems_allowed_change_disable);
  101. }
  102. static inline void set_mems_allowed(nodemask_t nodemask)
  103. {
  104. task_lock(current);
  105. current->mems_allowed = nodemask;
  106. task_unlock(current);
  107. }
  108. #else /* !CONFIG_CPUSETS */
  109. static inline int cpuset_init(void) { return 0; }
  110. static inline void cpuset_init_smp(void) {}
  111. static inline void cpuset_update_active_cpus(void)
  112. {
  113. partition_sched_domains(1, NULL, NULL);
  114. }
  115. static inline void cpuset_cpus_allowed(struct task_struct *p,
  116. struct cpumask *mask)
  117. {
  118. cpumask_copy(mask, cpu_possible_mask);
  119. }
  120. static inline int cpuset_cpus_allowed_fallback(struct task_struct *p)
  121. {
  122. do_set_cpus_allowed(p, cpu_possible_mask);
  123. return cpumask_any(cpu_active_mask);
  124. }
  125. static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  126. {
  127. return node_possible_map;
  128. }
  129. #define cpuset_current_mems_allowed (node_states[N_HIGH_MEMORY])
  130. static inline void cpuset_init_current_mems_allowed(void) {}
  131. static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  132. {
  133. return 1;
  134. }
  135. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  136. {
  137. return 1;
  138. }
  139. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  140. {
  141. return 1;
  142. }
  143. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  144. {
  145. return 1;
  146. }
  147. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  148. {
  149. return 1;
  150. }
  151. static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  152. const struct task_struct *tsk2)
  153. {
  154. return 1;
  155. }
  156. static inline void cpuset_memory_pressure_bump(void) {}
  157. static inline void cpuset_task_status_allowed(struct seq_file *m,
  158. struct task_struct *task)
  159. {
  160. }
  161. static inline int cpuset_mem_spread_node(void)
  162. {
  163. return 0;
  164. }
  165. static inline int cpuset_slab_spread_node(void)
  166. {
  167. return 0;
  168. }
  169. static inline int cpuset_do_page_mem_spread(void)
  170. {
  171. return 0;
  172. }
  173. static inline int cpuset_do_slab_mem_spread(void)
  174. {
  175. return 0;
  176. }
  177. static inline int current_cpuset_is_being_rebound(void)
  178. {
  179. return 0;
  180. }
  181. static inline void rebuild_sched_domains(void)
  182. {
  183. partition_sched_domains(1, NULL, NULL);
  184. }
  185. static inline void cpuset_print_task_mems_allowed(struct task_struct *p)
  186. {
  187. }
  188. static inline void set_mems_allowed(nodemask_t nodemask)
  189. {
  190. }
  191. static inline void get_mems_allowed(void)
  192. {
  193. }
  194. static inline void put_mems_allowed(void)
  195. {
  196. }
  197. #endif /* !CONFIG_CPUSETS */
  198. #endif /* _LINUX_CPUSET_H */