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