cpuset.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. #ifdef CONFIG_CPUSETS
  15. extern int number_of_cpusets; /* How many cpusets are defined in system? */
  16. extern int cpuset_init(void);
  17. extern void cpuset_init_smp(void);
  18. extern void cpuset_update_active_cpus(bool cpu_online);
  19. extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
  20. extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
  21. extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
  22. #define cpuset_current_mems_allowed (current->mems_allowed)
  23. void cpuset_init_current_mems_allowed(void);
  24. int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
  25. extern int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask);
  26. extern int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask);
  27. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  28. {
  29. return number_of_cpusets <= 1 ||
  30. __cpuset_node_allowed_softwall(node, gfp_mask);
  31. }
  32. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  33. {
  34. return number_of_cpusets <= 1 ||
  35. __cpuset_node_allowed_hardwall(node, gfp_mask);
  36. }
  37. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  38. {
  39. return cpuset_node_allowed_softwall(zone_to_nid(z), gfp_mask);
  40. }
  41. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  42. {
  43. return cpuset_node_allowed_hardwall(zone_to_nid(z), gfp_mask);
  44. }
  45. extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  46. const struct task_struct *tsk2);
  47. #define cpuset_memory_pressure_bump() \
  48. do { \
  49. if (cpuset_memory_pressure_enabled) \
  50. __cpuset_memory_pressure_bump(); \
  51. } while (0)
  52. extern int cpuset_memory_pressure_enabled;
  53. extern void __cpuset_memory_pressure_bump(void);
  54. extern void cpuset_task_status_allowed(struct seq_file *m,
  55. struct task_struct *task);
  56. extern int proc_cpuset_show(struct seq_file *, void *);
  57. extern int cpuset_mem_spread_node(void);
  58. extern int cpuset_slab_spread_node(void);
  59. static inline int cpuset_do_page_mem_spread(void)
  60. {
  61. return current->flags & PF_SPREAD_PAGE;
  62. }
  63. static inline int cpuset_do_slab_mem_spread(void)
  64. {
  65. return current->flags & PF_SPREAD_SLAB;
  66. }
  67. extern int current_cpuset_is_being_rebound(void);
  68. extern void rebuild_sched_domains(void);
  69. extern void cpuset_print_task_mems_allowed(struct task_struct *p);
  70. /*
  71. * get_mems_allowed is required when making decisions involving mems_allowed
  72. * such as during page allocation. mems_allowed can be updated in parallel
  73. * and depending on the new value an operation can fail potentially causing
  74. * process failure. A retry loop with get_mems_allowed and put_mems_allowed
  75. * prevents these artificial failures.
  76. */
  77. static inline unsigned int get_mems_allowed(void)
  78. {
  79. return read_seqcount_begin(&current->mems_allowed_seq);
  80. }
  81. /*
  82. * If this returns false, the operation that took place after get_mems_allowed
  83. * may have failed. It is up to the caller to retry the operation if
  84. * appropriate.
  85. */
  86. static inline bool put_mems_allowed(unsigned int seq)
  87. {
  88. return !read_seqcount_retry(&current->mems_allowed_seq, seq);
  89. }
  90. static inline void set_mems_allowed(nodemask_t nodemask)
  91. {
  92. unsigned long flags;
  93. task_lock(current);
  94. local_irq_save(flags);
  95. write_seqcount_begin(&current->mems_allowed_seq);
  96. current->mems_allowed = nodemask;
  97. write_seqcount_end(&current->mems_allowed_seq);
  98. local_irq_restore(flags);
  99. task_unlock(current);
  100. }
  101. #else /* !CONFIG_CPUSETS */
  102. static inline int cpuset_init(void) { return 0; }
  103. static inline void cpuset_init_smp(void) {}
  104. static inline void cpuset_update_active_cpus(bool cpu_online)
  105. {
  106. partition_sched_domains(1, NULL, NULL);
  107. }
  108. static inline void cpuset_cpus_allowed(struct task_struct *p,
  109. struct cpumask *mask)
  110. {
  111. cpumask_copy(mask, cpu_possible_mask);
  112. }
  113. static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
  114. {
  115. }
  116. static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  117. {
  118. return node_possible_map;
  119. }
  120. #define cpuset_current_mems_allowed (node_states[N_MEMORY])
  121. static inline void cpuset_init_current_mems_allowed(void) {}
  122. static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
  123. {
  124. return 1;
  125. }
  126. static inline int cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
  127. {
  128. return 1;
  129. }
  130. static inline int cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
  131. {
  132. return 1;
  133. }
  134. static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
  135. {
  136. return 1;
  137. }
  138. static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
  139. {
  140. return 1;
  141. }
  142. static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  143. const struct task_struct *tsk2)
  144. {
  145. return 1;
  146. }
  147. static inline void cpuset_memory_pressure_bump(void) {}
  148. static inline void cpuset_task_status_allowed(struct seq_file *m,
  149. struct task_struct *task)
  150. {
  151. }
  152. static inline int cpuset_mem_spread_node(void)
  153. {
  154. return 0;
  155. }
  156. static inline int cpuset_slab_spread_node(void)
  157. {
  158. return 0;
  159. }
  160. static inline int cpuset_do_page_mem_spread(void)
  161. {
  162. return 0;
  163. }
  164. static inline int cpuset_do_slab_mem_spread(void)
  165. {
  166. return 0;
  167. }
  168. static inline int current_cpuset_is_being_rebound(void)
  169. {
  170. return 0;
  171. }
  172. static inline void rebuild_sched_domains(void)
  173. {
  174. partition_sched_domains(1, NULL, NULL);
  175. }
  176. static inline void cpuset_print_task_mems_allowed(struct task_struct *p)
  177. {
  178. }
  179. static inline void set_mems_allowed(nodemask_t nodemask)
  180. {
  181. }
  182. static inline unsigned int get_mems_allowed(void)
  183. {
  184. return 0;
  185. }
  186. static inline bool put_mems_allowed(unsigned int seq)
  187. {
  188. return true;
  189. }
  190. #endif /* !CONFIG_CPUSETS */
  191. #endif /* _LINUX_CPUSET_H */