| 1 |
|
| 2 | #ifndef _LINUX_CPUSET_H
|
| 3 | #define _LINUX_CPUSET_H
|
| 4 | |
| 5 | * cpuset interface
|
| 6 | *
|
| 7 | * Copyright (C) 2003 BULL SA
|
| 8 | * Copyright (C) 2004-2006 Silicon Graphics, Inc.
|
| 9 | *
|
| 10 |
|
| 11 |
|
| 12 | #include <linux/sched.h>
|
| 13 | #include <linux/sched/topology.h>
|
| 14 | #include <linux/sched/task.h>
|
| 15 | #include <linux/cpumask.h>
|
| 16 | #include <linux/nodemask.h>
|
| 17 | #include <linux/mm.h>
|
| 18 | #include <linux/mmu_context.h>
|
| 19 | #include <linux/jump_label.h>
|
| 20 |
|
| 21 | extern bool lockdep_is_cpuset_held(void);
|
| 22 |
|
| 23 | #ifdef CONFIG_CPUSETS
|
| 24 |
|
| 25 | |
| 26 | * Static branch rewrites can happen in an arbitrary order for a given
|
| 27 | * key. In code paths where we need to loop with read_mems_allowed_begin() and
|
| 28 | * read_mems_allowed_retry() to get a consistent view of mems_allowed, we need
|
| 29 | * to ensure that begin() always gets rewritten before retry() in the
|
| 30 | * disabled -> enabled transition. If not, then if local irqs are disabled
|
| 31 | * around the loop, we can deadlock since retry() would always be
|
| 32 | * comparing the latest value of the mems_allowed seqcount against 0 as
|
| 33 | * begin() still would see cpusets_enabled() as false. The enabled -> disabled
|
| 34 | * transition should happen in reverse order for the same reasons (want to stop
|
| 35 | * looking at real value of mems_allowed.sequence in retry() first).
|
| 36 |
|
| 37 | extern struct static_key_false cpusets_pre_enable_key;
|
| 38 | extern struct static_key_false cpusets_enabled_key;
|
| 39 | extern struct static_key_false cpusets_insane_config_key;
|
| 40 |
|
| 41 | static inline bool cpusets_enabled(void)
|
| 42 | {
|
| 43 | return static_branch_unlikely(&cpusets_enabled_key);
|
| 44 | }
|
| 45 |
|
| 46 | static inline void cpuset_inc(void)
|
| 47 | {
|
| 48 | static_branch_inc_cpuslocked(&cpusets_pre_enable_key);
|
| 49 | static_branch_inc_cpuslocked(&cpusets_enabled_key);
|
| 50 | }
|
| 51 |
|
| 52 | static inline void cpuset_dec(void)
|
| 53 | {
|
| 54 | static_branch_dec_cpuslocked(&cpusets_enabled_key);
|
| 55 | static_branch_dec_cpuslocked(&cpusets_pre_enable_key);
|
| 56 | }
|
| 57 |
|
| 58 | |
| 59 | * This will get enabled whenever a cpuset configuration is considered
|
| 60 | * unsupportable in general. E.g. movable only node which cannot satisfy
|
| 61 | * any non movable allocations (see update_nodemask). Page allocator
|
| 62 | * needs to make additional checks for those configurations and this
|
| 63 | * check is meant to guard those checks without any overhead for sane
|
| 64 | * configurations.
|
| 65 |
|
| 66 | static inline bool cpusets_insane_config(void)
|
| 67 | {
|
| 68 | return static_branch_unlikely(&cpusets_insane_config_key);
|
| 69 | }
|
| 70 |
|
| 71 | extern int cpuset_init(void);
|
| 72 | extern void cpuset_init_smp(void);
|
| 73 | extern void cpuset_force_rebuild(void);
|
| 74 | extern void cpuset_update_active_cpus(void);
|
| 75 | extern void inc_dl_tasks_cs(struct task_struct *task);
|
| 76 | extern void dec_dl_tasks_cs(struct task_struct *task);
|
| 77 | extern void cpuset_lock(void);
|
| 78 | extern void cpuset_unlock(void);
|
| 79 | extern void lockdep_assert_cpuset_lock_held(void);
|
| 80 | extern void cpuset_cpus_allowed_locked(struct task_struct *p, struct cpumask *mask);
|
| 81 | extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
|
| 82 | extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
|
| 83 | extern int cpuset_num_cpus(struct cgroup *cgroup);
|
| 84 | extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
|
| 85 | #define cpuset_current_mems_allowed (current->mems_allowed)
|
| 86 | void cpuset_init_current_mems_allowed(void);
|
| 87 | int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask);
|
| 88 |
|
| 89 | extern bool cpuset_current_node_allowed(int node, gfp_t gfp_mask);
|
| 90 |
|
| 91 | static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
| 92 | {
|
| 93 | return cpuset_current_node_allowed(zone_to_nid(z), gfp_mask);
|
| 94 | }
|
| 95 |
|
| 96 | static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
| 97 | {
|
| 98 | if (cpusets_enabled())
|
| 99 | return __cpuset_zone_allowed(z, gfp_mask);
|
| 100 | return true;
|
| 101 | }
|
| 102 |
|
| 103 | extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
|
| 104 | const struct task_struct *tsk2);
|
| 105 |
|
| 106 | #ifdef CONFIG_CPUSETS_V1
|
| 107 | #define cpuset_memory_pressure_bump() \
|
| 108 | do { \
|
| 109 | if (cpuset_memory_pressure_enabled) \
|
| 110 | __cpuset_memory_pressure_bump(); \
|
| 111 | } while (0)
|
| 112 | extern int cpuset_memory_pressure_enabled;
|
| 113 | extern void __cpuset_memory_pressure_bump(void);
|
| 114 | #else
|
| 115 | static inline void cpuset_memory_pressure_bump(void) { }
|
| 116 | #endif
|
| 117 |
|
| 118 | extern void cpuset_task_status_allowed(struct seq_file *m,
|
| 119 | struct task_struct *task);
|
| 120 | extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
|
| 121 | struct pid *pid, struct task_struct *tsk);
|
| 122 |
|
| 123 | extern int cpuset_mem_spread_node(void);
|
| 124 |
|
| 125 | static inline int cpuset_do_page_mem_spread(void)
|
| 126 | {
|
| 127 | return task_spread_page(current);
|
| 128 | }
|
| 129 |
|
| 130 | extern bool current_cpuset_is_being_rebound(void);
|
| 131 |
|
| 132 | extern void dl_rebuild_rd_accounting(void);
|
| 133 | extern void rebuild_sched_domains(void);
|
| 134 |
|
| 135 | extern void cpuset_print_current_mems_allowed(void);
|
| 136 | extern void cpuset_reset_sched_domains(void);
|
| 137 |
|
| 138 | |
| 139 | * read_mems_allowed_begin is required when making decisions involving
|
| 140 | * mems_allowed such as during page allocation. mems_allowed can be updated in
|
| 141 | * parallel and depending on the new value an operation can fail potentially
|
| 142 | * causing process failure. A retry loop with read_mems_allowed_begin and
|
| 143 | * read_mems_allowed_retry prevents these artificial failures.
|
| 144 |
|
| 145 | static inline unsigned int read_mems_allowed_begin(void)
|
| 146 | {
|
| 147 | if (!static_branch_unlikely(&cpusets_pre_enable_key))
|
| 148 | return 0;
|
| 149 |
|
| 150 | return read_seqcount_begin(¤t->mems_allowed_seq);
|
| 151 | }
|
| 152 |
|
| 153 | |
| 154 | * If this returns true, the operation that took place after
|
| 155 | * read_mems_allowed_begin may have failed artificially due to a concurrent
|
| 156 | * update of mems_allowed. It is up to the caller to retry the operation if
|
| 157 | * appropriate.
|
| 158 |
|
| 159 | static inline bool read_mems_allowed_retry(unsigned int seq)
|
| 160 | {
|
| 161 | if (!static_branch_unlikely(&cpusets_enabled_key))
|
| 162 | return false;
|
| 163 |
|
| 164 | return read_seqcount_retry(¤t->mems_allowed_seq, seq);
|
| 165 | }
|
| 166 |
|
| 167 | static inline void set_mems_allowed(nodemask_t nodemask)
|
| 168 | {
|
| 169 | unsigned long flags;
|
| 170 |
|
| 171 | task_lock(current);
|
| 172 | local_irq_save(flags);
|
| 173 | write_seqcount_begin(¤t->mems_allowed_seq);
|
| 174 | current->mems_allowed = nodemask;
|
| 175 | write_seqcount_end(¤t->mems_allowed_seq);
|
| 176 | local_irq_restore(flags);
|
| 177 | task_unlock(current);
|
| 178 | }
|
| 179 |
|
| 180 | extern void cpuset_nodes_allowed(struct cgroup *cgroup, nodemask_t *mask);
|
| 181 | #else
|
| 182 |
|
| 183 | static inline bool cpusets_enabled(void) { return false; }
|
| 184 |
|
| 185 | static inline bool cpusets_insane_config(void) { return false; }
|
| 186 |
|
| 187 | static inline int cpuset_init(void) { return 0; }
|
| 188 | static inline void cpuset_init_smp(void) {}
|
| 189 |
|
| 190 | static inline void cpuset_force_rebuild(void) { }
|
| 191 |
|
| 192 | static inline void cpuset_update_active_cpus(void)
|
| 193 | {
|
| 194 | partition_sched_domains(1, NULL, NULL);
|
| 195 | }
|
| 196 |
|
| 197 | static inline void inc_dl_tasks_cs(struct task_struct *task) { }
|
| 198 | static inline void dec_dl_tasks_cs(struct task_struct *task) { }
|
| 199 | static inline void cpuset_lock(void) { }
|
| 200 | static inline void cpuset_unlock(void) { }
|
| 201 | static inline void lockdep_assert_cpuset_lock_held(void) { }
|
| 202 |
|
| 203 | static inline void cpuset_cpus_allowed_locked(struct task_struct *p,
|
| 204 | struct cpumask *mask)
|
| 205 | {
|
| 206 | cpumask_copy(mask, task_cpu_possible_mask(p));
|
| 207 | }
|
| 208 |
|
| 209 | static inline void cpuset_cpus_allowed(struct task_struct *p,
|
| 210 | struct cpumask *mask)
|
| 211 | {
|
| 212 | cpuset_cpus_allowed_locked(p, mask);
|
| 213 | }
|
| 214 |
|
| 215 | static inline bool cpuset_cpus_allowed_fallback(struct task_struct *p)
|
| 216 | {
|
| 217 | return false;
|
| 218 | }
|
| 219 |
|
| 220 | static inline int cpuset_num_cpus(struct cgroup *cgroup)
|
| 221 | {
|
| 222 | return num_online_cpus();
|
| 223 | }
|
| 224 |
|
| 225 | static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
|
| 226 | {
|
| 227 | return node_possible_map;
|
| 228 | }
|
| 229 |
|
| 230 | #define cpuset_current_mems_allowed (node_states[N_MEMORY])
|
| 231 | static inline void cpuset_init_current_mems_allowed(void) {}
|
| 232 |
|
| 233 | static inline int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
|
| 234 | {
|
| 235 | return 1;
|
| 236 | }
|
| 237 |
|
| 238 | static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
| 239 | {
|
| 240 | return true;
|
| 241 | }
|
| 242 |
|
| 243 | static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
| 244 | {
|
| 245 | return true;
|
| 246 | }
|
| 247 |
|
| 248 | static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
|
| 249 | const struct task_struct *tsk2)
|
| 250 | {
|
| 251 | return 1;
|
| 252 | }
|
| 253 |
|
| 254 | static inline void cpuset_memory_pressure_bump(void) {}
|
| 255 |
|
| 256 | static inline void cpuset_task_status_allowed(struct seq_file *m,
|
| 257 | struct task_struct *task)
|
| 258 | {
|
| 259 | }
|
| 260 |
|
| 261 | static inline int cpuset_mem_spread_node(void)
|
| 262 | {
|
| 263 | return 0;
|
| 264 | }
|
| 265 |
|
| 266 | static inline int cpuset_do_page_mem_spread(void)
|
| 267 | {
|
| 268 | return 0;
|
| 269 | }
|
| 270 |
|
| 271 | static inline bool current_cpuset_is_being_rebound(void)
|
| 272 | {
|
| 273 | return false;
|
| 274 | }
|
| 275 |
|
| 276 | static inline void dl_rebuild_rd_accounting(void)
|
| 277 | {
|
| 278 | }
|
| 279 |
|
| 280 | static inline void rebuild_sched_domains(void)
|
| 281 | {
|
| 282 | guard(cpus_read_lock)();
|
| 283 | partition_sched_domains(1, NULL, NULL);
|
| 284 | }
|
| 285 |
|
| 286 | static inline void cpuset_reset_sched_domains(void)
|
| 287 | {
|
| 288 | partition_sched_domains(1, NULL, NULL);
|
| 289 | }
|
| 290 |
|
| 291 | static inline void cpuset_print_current_mems_allowed(void)
|
| 292 | {
|
| 293 | }
|
| 294 |
|
| 295 | static inline void set_mems_allowed(nodemask_t nodemask)
|
| 296 | {
|
| 297 | }
|
| 298 |
|
| 299 | static inline unsigned int read_mems_allowed_begin(void)
|
| 300 | {
|
| 301 | return 0;
|
| 302 | }
|
| 303 |
|
| 304 | static inline bool read_mems_allowed_retry(unsigned int seq)
|
| 305 | {
|
| 306 | return false;
|
| 307 | }
|
| 308 |
|
| 309 | static inline void cpuset_nodes_allowed(struct cgroup *cgroup, nodemask_t *mask)
|
| 310 | {
|
| 311 | nodes_copy(*mask, node_states[N_MEMORY]);
|
| 312 | }
|
| 313 | #endif
|
| 314 |
|
| 315 | #endif
|