cpuset.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 void 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 void cpuset_cpus_allowed_fallback(struct task_struct *p)
  121. {
  122. }
  123. static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  124. {
  125. return node_possible_map;
  126. }
  127. #define cpuset_current_mems_allowed (node_states[N_HIGH_MEMORY])
  128. static inline void cpuset_init_current_mems_allowed(void) {}
  129. static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  130. {
  131. return 1;
  132. }
  133. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  134. {
  135. return 1;
  136. }
  137. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  138. {
  139. return 1;
  140. }
  141. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  142. {
  143. return 1;
  144. }
  145. static inline int cpuset_zone_allowed_hardwall(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_task_mems_allowed(struct task_struct *p)
  184. {
  185. }
  186. static inline void set_mems_allowed(nodemask_t nodemask)
  187. {
  188. }
  189. static inline void get_mems_allowed(void)
  190. {
  191. }
  192. static inline void put_mems_allowed(void)
  193. {
  194. }
  195. #endif /* !CONFIG_CPUSETS */
  196. #endif /* _LINUX_CPUSET_H */