Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_CPUSET_H |
2 | #define _LINUX_CPUSET_H | |
3 | /* | |
4 | * cpuset interface | |
5 | * | |
6 | * Copyright (C) 2003 BULL SA | |
825a46af | 7 | * Copyright (C) 2004-2006 Silicon Graphics, Inc. |
1da177e4 LT |
8 | * |
9 | */ | |
10 | ||
11 | #include <linux/sched.h> | |
12 | #include <linux/cpumask.h> | |
13 | #include <linux/nodemask.h> | |
a1bc5a4e | 14 | #include <linux/mm.h> |
664eedde | 15 | #include <linux/jump_label.h> |
1da177e4 LT |
16 | |
17 | #ifdef CONFIG_CPUSETS | |
18 | ||
002f2906 | 19 | extern struct static_key_false cpusets_enabled_key; |
664eedde MG |
20 | static inline bool cpusets_enabled(void) |
21 | { | |
002f2906 | 22 | return static_branch_unlikely(&cpusets_enabled_key); |
664eedde MG |
23 | } |
24 | ||
25 | static inline int nr_cpusets(void) | |
26 | { | |
27 | /* jump label reference count + the top-level cpuset */ | |
002f2906 | 28 | return static_key_count(&cpusets_enabled_key.key) + 1; |
664eedde MG |
29 | } |
30 | ||
31 | static inline void cpuset_inc(void) | |
32 | { | |
002f2906 | 33 | static_branch_inc(&cpusets_enabled_key); |
664eedde MG |
34 | } |
35 | ||
36 | static inline void cpuset_dec(void) | |
37 | { | |
002f2906 | 38 | static_branch_dec(&cpusets_enabled_key); |
664eedde | 39 | } |
202f72d5 | 40 | |
1da177e4 LT |
41 | extern int cpuset_init(void); |
42 | extern void cpuset_init_smp(void); | |
7ddf96b0 | 43 | extern void cpuset_update_active_cpus(bool cpu_online); |
6af866af | 44 | extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); |
2baab4e9 | 45 | extern void cpuset_cpus_allowed_fallback(struct task_struct *p); |
909d75a3 | 46 | extern nodemask_t cpuset_mems_allowed(struct task_struct *p); |
9276b1bc | 47 | #define cpuset_current_mems_allowed (current->mems_allowed) |
1da177e4 | 48 | void cpuset_init_current_mems_allowed(void); |
19770b32 | 49 | int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask); |
202f72d5 | 50 | |
002f2906 | 51 | extern bool __cpuset_node_allowed(int node, gfp_t gfp_mask); |
02a0e53d | 52 | |
002f2906 | 53 | static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask) |
02a0e53d | 54 | { |
002f2906 VB |
55 | if (cpusets_enabled()) |
56 | return __cpuset_node_allowed(node, gfp_mask); | |
57 | return true; | |
02a0e53d PJ |
58 | } |
59 | ||
002f2906 | 60 | static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) |
202f72d5 | 61 | { |
002f2906 VB |
62 | return __cpuset_node_allowed(zone_to_nid(z), gfp_mask); |
63 | } | |
64 | ||
65 | static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) | |
66 | { | |
67 | if (cpusets_enabled()) | |
68 | return __cpuset_zone_allowed(z, gfp_mask); | |
69 | return true; | |
202f72d5 PJ |
70 | } |
71 | ||
bbe373f2 DR |
72 | extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1, |
73 | const struct task_struct *tsk2); | |
3e0d98b9 PJ |
74 | |
75 | #define cpuset_memory_pressure_bump() \ | |
76 | do { \ | |
77 | if (cpuset_memory_pressure_enabled) \ | |
78 | __cpuset_memory_pressure_bump(); \ | |
79 | } while (0) | |
80 | extern int cpuset_memory_pressure_enabled; | |
81 | extern void __cpuset_memory_pressure_bump(void); | |
82 | ||
df5f8314 EB |
83 | extern void cpuset_task_status_allowed(struct seq_file *m, |
84 | struct task_struct *task); | |
52de4779 ZL |
85 | extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns, |
86 | struct pid *pid, struct task_struct *tsk); | |
1da177e4 | 87 | |
825a46af | 88 | extern int cpuset_mem_spread_node(void); |
6adef3eb | 89 | extern int cpuset_slab_spread_node(void); |
825a46af PJ |
90 | |
91 | static inline int cpuset_do_page_mem_spread(void) | |
92 | { | |
2ad654bc | 93 | return task_spread_page(current); |
825a46af PJ |
94 | } |
95 | ||
96 | static inline int cpuset_do_slab_mem_spread(void) | |
97 | { | |
2ad654bc | 98 | return task_spread_slab(current); |
825a46af PJ |
99 | } |
100 | ||
8793d854 PM |
101 | extern int current_cpuset_is_being_rebound(void); |
102 | ||
e761b772 MK |
103 | extern void rebuild_sched_domains(void); |
104 | ||
da39da3a | 105 | extern void cpuset_print_current_mems_allowed(void); |
75aa1994 | 106 | |
c0ff7453 | 107 | /* |
d26914d1 MG |
108 | * read_mems_allowed_begin is required when making decisions involving |
109 | * mems_allowed such as during page allocation. mems_allowed can be updated in | |
110 | * parallel and depending on the new value an operation can fail potentially | |
111 | * causing process failure. A retry loop with read_mems_allowed_begin and | |
112 | * read_mems_allowed_retry prevents these artificial failures. | |
c0ff7453 | 113 | */ |
d26914d1 | 114 | static inline unsigned int read_mems_allowed_begin(void) |
c0ff7453 | 115 | { |
46e700ab MG |
116 | if (!cpusets_enabled()) |
117 | return 0; | |
118 | ||
cc9a6c87 | 119 | return read_seqcount_begin(¤t->mems_allowed_seq); |
c0ff7453 MX |
120 | } |
121 | ||
cc9a6c87 | 122 | /* |
d26914d1 MG |
123 | * If this returns true, the operation that took place after |
124 | * read_mems_allowed_begin may have failed artificially due to a concurrent | |
125 | * update of mems_allowed. It is up to the caller to retry the operation if | |
cc9a6c87 MG |
126 | * appropriate. |
127 | */ | |
d26914d1 | 128 | static inline bool read_mems_allowed_retry(unsigned int seq) |
c0ff7453 | 129 | { |
46e700ab MG |
130 | if (!cpusets_enabled()) |
131 | return false; | |
132 | ||
d26914d1 | 133 | return read_seqcount_retry(¤t->mems_allowed_seq, seq); |
c0ff7453 MX |
134 | } |
135 | ||
58568d2a MX |
136 | static inline void set_mems_allowed(nodemask_t nodemask) |
137 | { | |
db751fe3 JS |
138 | unsigned long flags; |
139 | ||
c0ff7453 | 140 | task_lock(current); |
db751fe3 | 141 | local_irq_save(flags); |
cc9a6c87 | 142 | write_seqcount_begin(¤t->mems_allowed_seq); |
58568d2a | 143 | current->mems_allowed = nodemask; |
cc9a6c87 | 144 | write_seqcount_end(¤t->mems_allowed_seq); |
db751fe3 | 145 | local_irq_restore(flags); |
c0ff7453 | 146 | task_unlock(current); |
58568d2a MX |
147 | } |
148 | ||
1da177e4 LT |
149 | #else /* !CONFIG_CPUSETS */ |
150 | ||
664eedde MG |
151 | static inline bool cpusets_enabled(void) { return false; } |
152 | ||
1da177e4 LT |
153 | static inline int cpuset_init(void) { return 0; } |
154 | static inline void cpuset_init_smp(void) {} | |
1da177e4 | 155 | |
7ddf96b0 | 156 | static inline void cpuset_update_active_cpus(bool cpu_online) |
3a101d05 TH |
157 | { |
158 | partition_sched_domains(1, NULL, NULL); | |
159 | } | |
160 | ||
6af866af LZ |
161 | static inline void cpuset_cpus_allowed(struct task_struct *p, |
162 | struct cpumask *mask) | |
1da177e4 | 163 | { |
aa85ea5b | 164 | cpumask_copy(mask, cpu_possible_mask); |
1da177e4 LT |
165 | } |
166 | ||
2baab4e9 | 167 | static inline void cpuset_cpus_allowed_fallback(struct task_struct *p) |
9084bb82 | 168 | { |
9084bb82 ON |
169 | } |
170 | ||
909d75a3 PJ |
171 | static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) |
172 | { | |
173 | return node_possible_map; | |
174 | } | |
175 | ||
38d7bee9 | 176 | #define cpuset_current_mems_allowed (node_states[N_MEMORY]) |
1da177e4 | 177 | static inline void cpuset_init_current_mems_allowed(void) {} |
1da177e4 | 178 | |
19770b32 | 179 | static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask) |
1da177e4 LT |
180 | { |
181 | return 1; | |
182 | } | |
183 | ||
002f2906 | 184 | static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask) |
02a0e53d | 185 | { |
002f2906 | 186 | return true; |
02a0e53d PJ |
187 | } |
188 | ||
002f2906 | 189 | static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) |
1da177e4 | 190 | { |
002f2906 VB |
191 | return true; |
192 | } | |
193 | ||
194 | static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) | |
195 | { | |
196 | return true; | |
1da177e4 LT |
197 | } |
198 | ||
bbe373f2 DR |
199 | static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1, |
200 | const struct task_struct *tsk2) | |
ef08e3b4 PJ |
201 | { |
202 | return 1; | |
203 | } | |
204 | ||
3e0d98b9 PJ |
205 | static inline void cpuset_memory_pressure_bump(void) {} |
206 | ||
df5f8314 EB |
207 | static inline void cpuset_task_status_allowed(struct seq_file *m, |
208 | struct task_struct *task) | |
1da177e4 | 209 | { |
1da177e4 LT |
210 | } |
211 | ||
825a46af PJ |
212 | static inline int cpuset_mem_spread_node(void) |
213 | { | |
214 | return 0; | |
215 | } | |
216 | ||
6adef3eb JS |
217 | static inline int cpuset_slab_spread_node(void) |
218 | { | |
219 | return 0; | |
220 | } | |
221 | ||
825a46af PJ |
222 | static inline int cpuset_do_page_mem_spread(void) |
223 | { | |
224 | return 0; | |
225 | } | |
226 | ||
227 | static inline int cpuset_do_slab_mem_spread(void) | |
228 | { | |
229 | return 0; | |
230 | } | |
231 | ||
8793d854 PM |
232 | static inline int current_cpuset_is_being_rebound(void) |
233 | { | |
234 | return 0; | |
235 | } | |
236 | ||
e761b772 MK |
237 | static inline void rebuild_sched_domains(void) |
238 | { | |
dfb512ec | 239 | partition_sched_domains(1, NULL, NULL); |
e761b772 MK |
240 | } |
241 | ||
da39da3a | 242 | static inline void cpuset_print_current_mems_allowed(void) |
75aa1994 DR |
243 | { |
244 | } | |
245 | ||
58568d2a MX |
246 | static inline void set_mems_allowed(nodemask_t nodemask) |
247 | { | |
248 | } | |
249 | ||
d26914d1 | 250 | static inline unsigned int read_mems_allowed_begin(void) |
c0ff7453 | 251 | { |
cc9a6c87 | 252 | return 0; |
c0ff7453 MX |
253 | } |
254 | ||
d26914d1 | 255 | static inline bool read_mems_allowed_retry(unsigned int seq) |
c0ff7453 | 256 | { |
d26914d1 | 257 | return false; |
c0ff7453 MX |
258 | } |
259 | ||
1da177e4 LT |
260 | #endif /* !CONFIG_CPUSETS */ |
261 | ||
262 | #endif /* _LINUX_CPUSET_H */ |