1 #ifndef _LINUX_CPUSET_H
2 #define _LINUX_CPUSET_H
6 * Copyright (C) 2003 BULL SA
7 * Copyright (C) 2004-2006 Silicon Graphics, Inc.
11 #include <linux/sched.h>
12 #include <linux/cpumask.h>
13 #include <linux/nodemask.h>
15 #include <linux/jump_label.h>
19 extern struct static_key cpusets_pre_enable_key;
20 extern struct static_key cpusets_enabled_key;
21 static inline bool cpusets_enabled(void)
23 return static_key_false(&cpusets_enabled_key);
26 static inline int nr_cpusets(void)
28 /* jump label reference count + the top-level cpuset */
29 return static_key_count(&cpusets_enabled_key) + 1;
32 static inline void cpuset_inc(void)
34 static_key_slow_inc(&cpusets_pre_enable_key);
35 static_key_slow_inc(&cpusets_enabled_key);
38 static inline void cpuset_dec(void)
40 static_key_slow_dec(&cpusets_enabled_key);
41 static_key_slow_dec(&cpusets_pre_enable_key);
44 extern int cpuset_init(void);
45 extern void cpuset_init_smp(void);
46 extern void cpuset_force_rebuild(void);
47 extern void cpuset_update_active_cpus(bool cpu_online);
48 extern void cpuset_wait_for_hotplug(void);
49 extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
50 extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
51 extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
52 #define cpuset_current_mems_allowed (current->mems_allowed)
53 void cpuset_init_current_mems_allowed(void);
54 int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
56 extern int __cpuset_node_allowed(int node, gfp_t gfp_mask);
58 static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
60 return nr_cpusets() <= 1 || __cpuset_node_allowed(node, gfp_mask);
63 static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
65 return cpuset_node_allowed(zone_to_nid(z), gfp_mask);
68 extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
69 const struct task_struct *tsk2);
71 #define cpuset_memory_pressure_bump() \
73 if (cpuset_memory_pressure_enabled) \
74 __cpuset_memory_pressure_bump(); \
76 extern int cpuset_memory_pressure_enabled;
77 extern void __cpuset_memory_pressure_bump(void);
79 extern void cpuset_task_status_allowed(struct seq_file *m,
80 struct task_struct *task);
81 extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
82 struct pid *pid, struct task_struct *tsk);
84 extern int cpuset_mem_spread_node(void);
85 extern int cpuset_slab_spread_node(void);
87 static inline int cpuset_do_page_mem_spread(void)
89 return task_spread_page(current);
92 static inline int cpuset_do_slab_mem_spread(void)
94 return task_spread_slab(current);
97 extern int current_cpuset_is_being_rebound(void);
99 extern void rebuild_sched_domains(void);
101 extern void cpuset_print_current_mems_allowed(void);
104 * read_mems_allowed_begin is required when making decisions involving
105 * mems_allowed such as during page allocation. mems_allowed can be updated in
106 * parallel and depending on the new value an operation can fail potentially
107 * causing process failure. A retry loop with read_mems_allowed_begin and
108 * read_mems_allowed_retry prevents these artificial failures.
110 static inline unsigned int read_mems_allowed_begin(void)
112 if (!static_key_false(&cpusets_pre_enable_key))
115 return read_seqcount_begin(¤t->mems_allowed_seq);
119 * If this returns true, the operation that took place after
120 * read_mems_allowed_begin may have failed artificially due to a concurrent
121 * update of mems_allowed. It is up to the caller to retry the operation if
124 static inline bool read_mems_allowed_retry(unsigned int seq)
126 if (!static_key_false(&cpusets_enabled_key))
129 return read_seqcount_retry(¤t->mems_allowed_seq, seq);
132 static inline void set_mems_allowed(nodemask_t nodemask)
137 local_irq_save(flags);
138 write_seqcount_begin(¤t->mems_allowed_seq);
139 current->mems_allowed = nodemask;
140 write_seqcount_end(¤t->mems_allowed_seq);
141 local_irq_restore(flags);
142 task_unlock(current);
145 #else /* !CONFIG_CPUSETS */
147 static inline bool cpusets_enabled(void) { return false; }
149 static inline int cpuset_init(void) { return 0; }
150 static inline void cpuset_init_smp(void) {}
152 static inline void cpuset_force_rebuild(void) { }
154 static inline void cpuset_update_active_cpus(bool cpu_online)
156 partition_sched_domains(1, NULL, NULL);
159 static inline void cpuset_wait_for_hotplug(void) { }
161 static inline void cpuset_cpus_allowed(struct task_struct *p,
162 struct cpumask *mask)
164 cpumask_copy(mask, cpu_possible_mask);
167 static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
171 static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
173 return node_possible_map;
176 #define cpuset_current_mems_allowed (node_states[N_MEMORY])
177 static inline void cpuset_init_current_mems_allowed(void) {}
179 static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
184 static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
189 static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
194 static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
195 const struct task_struct *tsk2)
200 static inline void cpuset_memory_pressure_bump(void) {}
202 static inline void cpuset_task_status_allowed(struct seq_file *m,
203 struct task_struct *task)
207 static inline int cpuset_mem_spread_node(void)
212 static inline int cpuset_slab_spread_node(void)
217 static inline int cpuset_do_page_mem_spread(void)
222 static inline int cpuset_do_slab_mem_spread(void)
227 static inline int current_cpuset_is_being_rebound(void)
232 static inline void rebuild_sched_domains(void)
234 partition_sched_domains(1, NULL, NULL);
237 static inline void cpuset_print_current_mems_allowed(void)
241 static inline void set_mems_allowed(nodemask_t nodemask)
245 static inline unsigned int read_mems_allowed_begin(void)
250 static inline bool read_mems_allowed_retry(unsigned int seq)
255 #endif /* !CONFIG_CPUSETS */
257 #endif /* _LINUX_CPUSET_H */