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