]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/cpuset.h
iommu/amd: Remove PD_DMA_OPS_MASK
[mirror_ubuntu-jammy-kernel.git] / include / linux / cpuset.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _LINUX_CPUSET_H
3#define _LINUX_CPUSET_H
4/*
5 * cpuset interface
6 *
7 * Copyright (C) 2003 BULL SA
825a46af 8 * Copyright (C) 2004-2006 Silicon Graphics, Inc.
1da177e4
LT
9 *
10 */
11
12#include <linux/sched.h>
105ab3d8 13#include <linux/sched/topology.h>
f719ff9b 14#include <linux/sched/task.h>
1da177e4
LT
15#include <linux/cpumask.h>
16#include <linux/nodemask.h>
a1bc5a4e 17#include <linux/mm.h>
664eedde 18#include <linux/jump_label.h>
1da177e4
LT
19
20#ifdef CONFIG_CPUSETS
21
89affbf5
DZ
22/*
23 * Static branch rewrites can happen in an arbitrary order for a given
24 * key. In code paths where we need to loop with read_mems_allowed_begin() and
25 * read_mems_allowed_retry() to get a consistent view of mems_allowed, we need
26 * to ensure that begin() always gets rewritten before retry() in the
27 * disabled -> enabled transition. If not, then if local irqs are disabled
28 * around the loop, we can deadlock since retry() would always be
29 * comparing the latest value of the mems_allowed seqcount against 0 as
30 * begin() still would see cpusets_enabled() as false. The enabled -> disabled
31 * transition should happen in reverse order for the same reasons (want to stop
32 * looking at real value of mems_allowed.sequence in retry() first).
33 */
34extern struct static_key_false cpusets_pre_enable_key;
002f2906 35extern struct static_key_false cpusets_enabled_key;
664eedde
MG
36static inline bool cpusets_enabled(void)
37{
002f2906 38 return static_branch_unlikely(&cpusets_enabled_key);
664eedde
MG
39}
40
664eedde
MG
41static inline void cpuset_inc(void)
42{
d74b27d6
JL
43 static_branch_inc_cpuslocked(&cpusets_pre_enable_key);
44 static_branch_inc_cpuslocked(&cpusets_enabled_key);
664eedde
MG
45}
46
47static inline void cpuset_dec(void)
48{
d74b27d6
JL
49 static_branch_dec_cpuslocked(&cpusets_enabled_key);
50 static_branch_dec_cpuslocked(&cpusets_pre_enable_key);
664eedde 51}
202f72d5 52
1da177e4
LT
53extern int cpuset_init(void);
54extern void cpuset_init_smp(void);
50e76632 55extern void cpuset_force_rebuild(void);
30e03acd 56extern void cpuset_update_active_cpus(void);
50e76632 57extern void cpuset_wait_for_hotplug(void);
710da3c8
JL
58extern void cpuset_read_lock(void);
59extern void cpuset_read_unlock(void);
6af866af 60extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
2baab4e9 61extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
909d75a3 62extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
9276b1bc 63#define cpuset_current_mems_allowed (current->mems_allowed)
1da177e4 64void cpuset_init_current_mems_allowed(void);
19770b32 65int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
202f72d5 66
002f2906 67extern bool __cpuset_node_allowed(int node, gfp_t gfp_mask);
02a0e53d 68
002f2906 69static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask)
02a0e53d 70{
002f2906
VB
71 if (cpusets_enabled())
72 return __cpuset_node_allowed(node, gfp_mask);
73 return true;
02a0e53d
PJ
74}
75
002f2906 76static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
202f72d5 77{
002f2906
VB
78 return __cpuset_node_allowed(zone_to_nid(z), gfp_mask);
79}
80
81static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
82{
83 if (cpusets_enabled())
84 return __cpuset_zone_allowed(z, gfp_mask);
85 return true;
202f72d5
PJ
86}
87
bbe373f2
DR
88extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
89 const struct task_struct *tsk2);
3e0d98b9
PJ
90
91#define cpuset_memory_pressure_bump() \
92 do { \
93 if (cpuset_memory_pressure_enabled) \
94 __cpuset_memory_pressure_bump(); \
95 } while (0)
96extern int cpuset_memory_pressure_enabled;
97extern void __cpuset_memory_pressure_bump(void);
98
df5f8314
EB
99extern void cpuset_task_status_allowed(struct seq_file *m,
100 struct task_struct *task);
52de4779
ZL
101extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
102 struct pid *pid, struct task_struct *tsk);
1da177e4 103
825a46af 104extern int cpuset_mem_spread_node(void);
6adef3eb 105extern int cpuset_slab_spread_node(void);
825a46af
PJ
106
107static inline int cpuset_do_page_mem_spread(void)
108{
2ad654bc 109 return task_spread_page(current);
825a46af
PJ
110}
111
112static inline int cpuset_do_slab_mem_spread(void)
113{
2ad654bc 114 return task_spread_slab(current);
825a46af
PJ
115}
116
77ef80c6 117extern bool current_cpuset_is_being_rebound(void);
8793d854 118
e761b772
MK
119extern void rebuild_sched_domains(void);
120
da39da3a 121extern void cpuset_print_current_mems_allowed(void);
75aa1994 122
c0ff7453 123/*
d26914d1
MG
124 * read_mems_allowed_begin is required when making decisions involving
125 * mems_allowed such as during page allocation. mems_allowed can be updated in
126 * parallel and depending on the new value an operation can fail potentially
127 * causing process failure. A retry loop with read_mems_allowed_begin and
128 * read_mems_allowed_retry prevents these artificial failures.
c0ff7453 129 */
d26914d1 130static inline unsigned int read_mems_allowed_begin(void)
c0ff7453 131{
89affbf5 132 if (!static_branch_unlikely(&cpusets_pre_enable_key))
46e700ab
MG
133 return 0;
134
cc9a6c87 135 return read_seqcount_begin(&current->mems_allowed_seq);
c0ff7453
MX
136}
137
cc9a6c87 138/*
d26914d1
MG
139 * If this returns true, the operation that took place after
140 * read_mems_allowed_begin may have failed artificially due to a concurrent
141 * update of mems_allowed. It is up to the caller to retry the operation if
cc9a6c87
MG
142 * appropriate.
143 */
d26914d1 144static inline bool read_mems_allowed_retry(unsigned int seq)
c0ff7453 145{
89affbf5 146 if (!static_branch_unlikely(&cpusets_enabled_key))
46e700ab
MG
147 return false;
148
d26914d1 149 return read_seqcount_retry(&current->mems_allowed_seq, seq);
c0ff7453
MX
150}
151
58568d2a
MX
152static inline void set_mems_allowed(nodemask_t nodemask)
153{
db751fe3
JS
154 unsigned long flags;
155
c0ff7453 156 task_lock(current);
db751fe3 157 local_irq_save(flags);
cc9a6c87 158 write_seqcount_begin(&current->mems_allowed_seq);
58568d2a 159 current->mems_allowed = nodemask;
cc9a6c87 160 write_seqcount_end(&current->mems_allowed_seq);
db751fe3 161 local_irq_restore(flags);
c0ff7453 162 task_unlock(current);
58568d2a
MX
163}
164
1da177e4
LT
165#else /* !CONFIG_CPUSETS */
166
664eedde
MG
167static inline bool cpusets_enabled(void) { return false; }
168
1da177e4
LT
169static inline int cpuset_init(void) { return 0; }
170static inline void cpuset_init_smp(void) {}
1da177e4 171
50e76632
PZ
172static inline void cpuset_force_rebuild(void) { }
173
30e03acd 174static inline void cpuset_update_active_cpus(void)
3a101d05
TH
175{
176 partition_sched_domains(1, NULL, NULL);
177}
178
50e76632
PZ
179static inline void cpuset_wait_for_hotplug(void) { }
180
710da3c8
JL
181static inline void cpuset_read_lock(void) { }
182static inline void cpuset_read_unlock(void) { }
183
6af866af
LZ
184static inline void cpuset_cpus_allowed(struct task_struct *p,
185 struct cpumask *mask)
1da177e4 186{
aa85ea5b 187 cpumask_copy(mask, cpu_possible_mask);
1da177e4
LT
188}
189
2baab4e9 190static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
9084bb82 191{
9084bb82
ON
192}
193
909d75a3
PJ
194static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
195{
196 return node_possible_map;
197}
198
38d7bee9 199#define cpuset_current_mems_allowed (node_states[N_MEMORY])
1da177e4 200static inline void cpuset_init_current_mems_allowed(void) {}
1da177e4 201
19770b32 202static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
1da177e4
LT
203{
204 return 1;
205}
206
002f2906 207static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask)
02a0e53d 208{
002f2906 209 return true;
02a0e53d
PJ
210}
211
002f2906 212static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
1da177e4 213{
002f2906
VB
214 return true;
215}
216
217static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
218{
219 return true;
1da177e4
LT
220}
221
bbe373f2
DR
222static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
223 const struct task_struct *tsk2)
ef08e3b4
PJ
224{
225 return 1;
226}
227
3e0d98b9
PJ
228static inline void cpuset_memory_pressure_bump(void) {}
229
df5f8314
EB
230static inline void cpuset_task_status_allowed(struct seq_file *m,
231 struct task_struct *task)
1da177e4 232{
1da177e4
LT
233}
234
825a46af
PJ
235static inline int cpuset_mem_spread_node(void)
236{
237 return 0;
238}
239
6adef3eb
JS
240static inline int cpuset_slab_spread_node(void)
241{
242 return 0;
243}
244
825a46af
PJ
245static inline int cpuset_do_page_mem_spread(void)
246{
247 return 0;
248}
249
250static inline int cpuset_do_slab_mem_spread(void)
251{
252 return 0;
253}
254
77ef80c6 255static inline bool current_cpuset_is_being_rebound(void)
8793d854 256{
77ef80c6 257 return false;
8793d854
PM
258}
259
e761b772
MK
260static inline void rebuild_sched_domains(void)
261{
dfb512ec 262 partition_sched_domains(1, NULL, NULL);
e761b772
MK
263}
264
da39da3a 265static inline void cpuset_print_current_mems_allowed(void)
75aa1994
DR
266{
267}
268
58568d2a
MX
269static inline void set_mems_allowed(nodemask_t nodemask)
270{
271}
272
d26914d1 273static inline unsigned int read_mems_allowed_begin(void)
c0ff7453 274{
cc9a6c87 275 return 0;
c0ff7453
MX
276}
277
d26914d1 278static inline bool read_mems_allowed_retry(unsigned int seq)
c0ff7453 279{
d26914d1 280 return false;
c0ff7453
MX
281}
282
1da177e4
LT
283#endif /* !CONFIG_CPUSETS */
284
285#endif /* _LINUX_CPUSET_H */