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
11 #include <linux/sched.h>
12 #include <linux/cpumask.h>
13 #include <linux/nodemask.h>
14 #include <linux/mm.h>
15 #include <linux/jump_label.h>
16
17 #ifdef CONFIG_CPUSETS
18
19 extern struct static_key cpusets_pre_enable_key;
20 extern struct static_key cpusets_enabled_key;
cpusets_enabled(void)21 static inline bool cpusets_enabled(void)
22 {
23 return static_key_false(&cpusets_enabled_key);
24 }
25
nr_cpusets(void)26 static inline int nr_cpusets(void)
27 {
28 /* jump label reference count + the top-level cpuset */
29 return static_key_count(&cpusets_enabled_key) + 1;
30 }
31
cpuset_inc(void)32 static inline void cpuset_inc(void)
33 {
34 static_key_slow_inc(&cpusets_pre_enable_key);
35 static_key_slow_inc(&cpusets_enabled_key);
36 }
37
cpuset_dec(void)38 static inline void cpuset_dec(void)
39 {
40 static_key_slow_dec(&cpusets_enabled_key);
41 static_key_slow_dec(&cpusets_pre_enable_key);
42 }
43
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);
55
56 extern int __cpuset_node_allowed(int node, gfp_t gfp_mask);
57
cpuset_node_allowed(int node,gfp_t gfp_mask)58 static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
59 {
60 return nr_cpusets() <= 1 || __cpuset_node_allowed(node, gfp_mask);
61 }
62
cpuset_zone_allowed(struct zone * z,gfp_t gfp_mask)63 static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
64 {
65 return cpuset_node_allowed(zone_to_nid(z), gfp_mask);
66 }
67
68 extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
69 const struct task_struct *tsk2);
70
71 #define cpuset_memory_pressure_bump() \
72 do { \
73 if (cpuset_memory_pressure_enabled) \
74 __cpuset_memory_pressure_bump(); \
75 } while (0)
76 extern int cpuset_memory_pressure_enabled;
77 extern void __cpuset_memory_pressure_bump(void);
78
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);
83
84 extern int cpuset_mem_spread_node(void);
85 extern int cpuset_slab_spread_node(void);
86
cpuset_do_page_mem_spread(void)87 static inline int cpuset_do_page_mem_spread(void)
88 {
89 return task_spread_page(current);
90 }
91
cpuset_do_slab_mem_spread(void)92 static inline int cpuset_do_slab_mem_spread(void)
93 {
94 return task_spread_slab(current);
95 }
96
97 extern int current_cpuset_is_being_rebound(void);
98
99 extern void rebuild_sched_domains(void);
100
101 extern void cpuset_print_current_mems_allowed(void);
102
103 /*
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.
109 */
read_mems_allowed_begin(void)110 static inline unsigned int read_mems_allowed_begin(void)
111 {
112 if (!static_key_false(&cpusets_pre_enable_key))
113 return 0;
114
115 return read_seqcount_begin(¤t->mems_allowed_seq);
116 }
117
118 /*
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
122 * appropriate.
123 */
read_mems_allowed_retry(unsigned int seq)124 static inline bool read_mems_allowed_retry(unsigned int seq)
125 {
126 if (!static_key_false(&cpusets_enabled_key))
127 return false;
128
129 return read_seqcount_retry(¤t->mems_allowed_seq, seq);
130 }
131
set_mems_allowed(nodemask_t nodemask)132 static inline void set_mems_allowed(nodemask_t nodemask)
133 {
134 unsigned long flags;
135
136 task_lock(current);
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);
143 }
144
145 #else /* !CONFIG_CPUSETS */
146
cpusets_enabled(void)147 static inline bool cpusets_enabled(void) { return false; }
148
cpuset_init(void)149 static inline int cpuset_init(void) { return 0; }
cpuset_init_smp(void)150 static inline void cpuset_init_smp(void) {}
151
cpuset_force_rebuild(void)152 static inline void cpuset_force_rebuild(void) { }
153
cpuset_update_active_cpus(bool cpu_online)154 static inline void cpuset_update_active_cpus(bool cpu_online)
155 {
156 partition_sched_domains(1, NULL, NULL);
157 }
158
cpuset_wait_for_hotplug(void)159 static inline void cpuset_wait_for_hotplug(void) { }
160
cpuset_cpus_allowed(struct task_struct * p,struct cpumask * mask)161 static inline void cpuset_cpus_allowed(struct task_struct *p,
162 struct cpumask *mask)
163 {
164 cpumask_copy(mask, cpu_possible_mask);
165 }
166
cpuset_cpus_allowed_fallback(struct task_struct * p)167 static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
168 {
169 }
170
cpuset_mems_allowed(struct task_struct * p)171 static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
172 {
173 return node_possible_map;
174 }
175
176 #define cpuset_current_mems_allowed (node_states[N_MEMORY])
cpuset_init_current_mems_allowed(void)177 static inline void cpuset_init_current_mems_allowed(void) {}
178
cpuset_nodemask_valid_mems_allowed(nodemask_t * nodemask)179 static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
180 {
181 return 1;
182 }
183
cpuset_node_allowed(int node,gfp_t gfp_mask)184 static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
185 {
186 return 1;
187 }
188
cpuset_zone_allowed(struct zone * z,gfp_t gfp_mask)189 static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
190 {
191 return 1;
192 }
193
cpuset_mems_allowed_intersects(const struct task_struct * tsk1,const struct task_struct * tsk2)194 static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
195 const struct task_struct *tsk2)
196 {
197 return 1;
198 }
199
cpuset_memory_pressure_bump(void)200 static inline void cpuset_memory_pressure_bump(void) {}
201
cpuset_task_status_allowed(struct seq_file * m,struct task_struct * task)202 static inline void cpuset_task_status_allowed(struct seq_file *m,
203 struct task_struct *task)
204 {
205 }
206
cpuset_mem_spread_node(void)207 static inline int cpuset_mem_spread_node(void)
208 {
209 return 0;
210 }
211
cpuset_slab_spread_node(void)212 static inline int cpuset_slab_spread_node(void)
213 {
214 return 0;
215 }
216
cpuset_do_page_mem_spread(void)217 static inline int cpuset_do_page_mem_spread(void)
218 {
219 return 0;
220 }
221
cpuset_do_slab_mem_spread(void)222 static inline int cpuset_do_slab_mem_spread(void)
223 {
224 return 0;
225 }
226
current_cpuset_is_being_rebound(void)227 static inline int current_cpuset_is_being_rebound(void)
228 {
229 return 0;
230 }
231
rebuild_sched_domains(void)232 static inline void rebuild_sched_domains(void)
233 {
234 partition_sched_domains(1, NULL, NULL);
235 }
236
cpuset_print_current_mems_allowed(void)237 static inline void cpuset_print_current_mems_allowed(void)
238 {
239 }
240
set_mems_allowed(nodemask_t nodemask)241 static inline void set_mems_allowed(nodemask_t nodemask)
242 {
243 }
244
read_mems_allowed_begin(void)245 static inline unsigned int read_mems_allowed_begin(void)
246 {
247 return 0;
248 }
249
read_mems_allowed_retry(unsigned int seq)250 static inline bool read_mems_allowed_retry(unsigned int seq)
251 {
252 return false;
253 }
254
255 #endif /* !CONFIG_CPUSETS */
256
257 #endif /* _LINUX_CPUSET_H */
258