2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 15:20:36 -07:00
|
|
|
#ifndef _LINUX_CPUSET_H
|
|
|
|
|
#define _LINUX_CPUSET_H
|
|
|
|
|
/*
|
|
|
|
|
* cpuset interface
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 BULL SA
|
2006-03-24 03:16:03 -08:00
|
|
|
* Copyright (C) 2004-2006 Silicon Graphics, Inc.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
2017-02-01 16:36:40 +01:00
|
|
|
#include <linux/sched/topology.h>
|
2017-02-06 10:57:33 +01:00
|
|
|
#include <linux/sched/task.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/cpumask.h>
|
|
|
|
|
#include <linux/nodemask.h>
|
2009-04-02 16:57:54 -07:00
|
|
|
#include <linux/mm.h>
|
2021-07-30 12:24:29 +01:00
|
|
|
#include <linux/mmu_context.h>
|
2014-06-04 16:10:08 -07:00
|
|
|
#include <linux/jump_label.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPUSETS
|
|
|
|
|
|
2017-08-02 13:32:18 -07:00
|
|
|
/*
|
|
|
|
|
* Static branch rewrites can happen in an arbitrary order for a given
|
|
|
|
|
* key. In code paths where we need to loop with read_mems_allowed_begin() and
|
|
|
|
|
* read_mems_allowed_retry() to get a consistent view of mems_allowed, we need
|
|
|
|
|
* to ensure that begin() always gets rewritten before retry() in the
|
|
|
|
|
* disabled -> enabled transition. If not, then if local irqs are disabled
|
|
|
|
|
* around the loop, we can deadlock since retry() would always be
|
|
|
|
|
* comparing the latest value of the mems_allowed seqcount against 0 as
|
|
|
|
|
* begin() still would see cpusets_enabled() as false. The enabled -> disabled
|
|
|
|
|
* transition should happen in reverse order for the same reasons (want to stop
|
|
|
|
|
* looking at real value of mems_allowed.sequence in retry() first).
|
|
|
|
|
*/
|
|
|
|
|
extern struct static_key_false cpusets_pre_enable_key;
|
2016-05-19 17:14:30 -07:00
|
|
|
extern struct static_key_false cpusets_enabled_key;
|
2021-11-05 13:40:34 -07:00
|
|
|
extern struct static_key_false cpusets_insane_config_key;
|
|
|
|
|
|
2014-06-04 16:10:08 -07:00
|
|
|
static inline bool cpusets_enabled(void)
|
|
|
|
|
{
|
2016-05-19 17:14:30 -07:00
|
|
|
return static_branch_unlikely(&cpusets_enabled_key);
|
2014-06-04 16:10:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void cpuset_inc(void)
|
|
|
|
|
{
|
2019-07-19 15:59:58 +02:00
|
|
|
static_branch_inc_cpuslocked(&cpusets_pre_enable_key);
|
|
|
|
|
static_branch_inc_cpuslocked(&cpusets_enabled_key);
|
2014-06-04 16:10:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void cpuset_dec(void)
|
|
|
|
|
{
|
2019-07-19 15:59:58 +02:00
|
|
|
static_branch_dec_cpuslocked(&cpusets_enabled_key);
|
|
|
|
|
static_branch_dec_cpuslocked(&cpusets_pre_enable_key);
|
2014-06-04 16:10:08 -07:00
|
|
|
}
|
2006-01-08 01:01:57 -08:00
|
|
|
|
2021-11-05 13:40:34 -07:00
|
|
|
/*
|
|
|
|
|
* This will get enabled whenever a cpuset configuration is considered
|
|
|
|
|
* unsupportable in general. E.g. movable only node which cannot satisfy
|
|
|
|
|
* any non movable allocations (see update_nodemask). Page allocator
|
|
|
|
|
* needs to make additional checks for those configurations and this
|
|
|
|
|
* check is meant to guard those checks without any overhead for sane
|
|
|
|
|
* configurations.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool cpusets_insane_config(void)
|
|
|
|
|
{
|
|
|
|
|
return static_branch_unlikely(&cpusets_insane_config_key);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
extern int cpuset_init(void);
|
|
|
|
|
extern void cpuset_init_smp(void);
|
2017-09-07 11:13:38 +02:00
|
|
|
extern void cpuset_force_rebuild(void);
|
2017-04-09 07:36:14 +06:00
|
|
|
extern void cpuset_update_active_cpus(void);
|
2017-09-07 11:13:38 +02:00
|
|
|
extern void cpuset_wait_for_hotplug(void);
|
2019-07-19 16:00:00 +02:00
|
|
|
extern void cpuset_read_lock(void);
|
|
|
|
|
extern void cpuset_read_unlock(void);
|
2009-01-07 18:08:45 -08:00
|
|
|
extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
|
2021-07-30 12:24:31 +01:00
|
|
|
extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
|
2006-01-08 01:01:55 -08:00
|
|
|
extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
|
2006-12-06 20:31:48 -08:00
|
|
|
#define cpuset_current_mems_allowed (current->mems_allowed)
|
2005-04-16 15:20:36 -07:00
|
|
|
void cpuset_init_current_mems_allowed(void);
|
2008-04-28 02:12:18 -07:00
|
|
|
int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
|
2006-01-08 01:01:57 -08:00
|
|
|
|
2016-05-19 17:14:30 -07:00
|
|
|
extern bool __cpuset_node_allowed(int node, gfp_t gfp_mask);
|
2006-12-13 00:34:25 -08:00
|
|
|
|
2016-05-19 17:14:30 -07:00
|
|
|
static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask)
|
2006-01-08 01:01:57 -08:00
|
|
|
{
|
2016-05-19 17:14:30 -07:00
|
|
|
if (cpusets_enabled())
|
|
|
|
|
return __cpuset_node_allowed(node, gfp_mask);
|
|
|
|
|
return true;
|
2006-12-13 00:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
2016-05-19 17:14:30 -07:00
|
|
|
static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
2006-12-13 00:34:25 -08:00
|
|
|
{
|
2016-05-19 17:14:30 -07:00
|
|
|
return __cpuset_node_allowed(zone_to_nid(z), gfp_mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
|
|
|
|
{
|
|
|
|
|
if (cpusets_enabled())
|
|
|
|
|
return __cpuset_zone_allowed(z, gfp_mask);
|
|
|
|
|
return true;
|
2006-01-08 01:01:57 -08:00
|
|
|
}
|
|
|
|
|
|
2007-10-16 23:25:58 -07:00
|
|
|
extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
|
|
|
|
|
const struct task_struct *tsk2);
|
2006-01-08 01:01:49 -08:00
|
|
|
|
|
|
|
|
#define cpuset_memory_pressure_bump() \
|
|
|
|
|
do { \
|
|
|
|
|
if (cpuset_memory_pressure_enabled) \
|
|
|
|
|
__cpuset_memory_pressure_bump(); \
|
|
|
|
|
} while (0)
|
|
|
|
|
extern int cpuset_memory_pressure_enabled;
|
|
|
|
|
extern void __cpuset_memory_pressure_bump(void);
|
|
|
|
|
|
2008-02-08 04:18:33 -08:00
|
|
|
extern void cpuset_task_status_allowed(struct seq_file *m,
|
|
|
|
|
struct task_struct *task);
|
2014-09-18 16:03:36 +08:00
|
|
|
extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
|
|
|
|
|
struct pid *pid, struct task_struct *tsk);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-03-24 03:16:03 -08:00
|
|
|
extern int cpuset_mem_spread_node(void);
|
2010-05-26 14:42:49 -07:00
|
|
|
extern int cpuset_slab_spread_node(void);
|
2006-03-24 03:16:03 -08:00
|
|
|
|
|
|
|
|
static inline int cpuset_do_page_mem_spread(void)
|
|
|
|
|
{
|
2014-09-25 09:41:02 +08:00
|
|
|
return task_spread_page(current);
|
2006-03-24 03:16:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int cpuset_do_slab_mem_spread(void)
|
|
|
|
|
{
|
2014-09-25 09:41:02 +08:00
|
|
|
return task_spread_slab(current);
|
2006-03-24 03:16:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 15:41:24 -08:00
|
|
|
extern bool current_cpuset_is_being_rebound(void);
|
2007-10-18 23:39:39 -07:00
|
|
|
|
2008-07-15 04:43:49 -07:00
|
|
|
extern void rebuild_sched_domains(void);
|
|
|
|
|
|
2015-11-05 18:48:05 -08:00
|
|
|
extern void cpuset_print_current_mems_allowed(void);
|
2009-01-06 14:39:01 -08:00
|
|
|
|
2010-05-24 14:32:08 -07:00
|
|
|
/*
|
2014-04-03 14:47:24 -07:00
|
|
|
* read_mems_allowed_begin is required when making decisions involving
|
|
|
|
|
* mems_allowed such as during page allocation. mems_allowed can be updated in
|
|
|
|
|
* parallel and depending on the new value an operation can fail potentially
|
|
|
|
|
* causing process failure. A retry loop with read_mems_allowed_begin and
|
|
|
|
|
* read_mems_allowed_retry prevents these artificial failures.
|
2010-05-24 14:32:08 -07:00
|
|
|
*/
|
2014-04-03 14:47:24 -07:00
|
|
|
static inline unsigned int read_mems_allowed_begin(void)
|
2010-05-24 14:32:08 -07:00
|
|
|
{
|
2017-08-02 13:32:18 -07:00
|
|
|
if (!static_branch_unlikely(&cpusets_pre_enable_key))
|
2015-11-06 16:28:15 -08:00
|
|
|
return 0;
|
|
|
|
|
|
2012-03-21 16:34:11 -07:00
|
|
|
return read_seqcount_begin(¤t->mems_allowed_seq);
|
2010-05-24 14:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-21 16:34:11 -07:00
|
|
|
/*
|
2014-04-03 14:47:24 -07:00
|
|
|
* If this returns true, the operation that took place after
|
|
|
|
|
* read_mems_allowed_begin may have failed artificially due to a concurrent
|
|
|
|
|
* update of mems_allowed. It is up to the caller to retry the operation if
|
2012-03-21 16:34:11 -07:00
|
|
|
* appropriate.
|
|
|
|
|
*/
|
2014-04-03 14:47:24 -07:00
|
|
|
static inline bool read_mems_allowed_retry(unsigned int seq)
|
2010-05-24 14:32:08 -07:00
|
|
|
{
|
2017-08-02 13:32:18 -07:00
|
|
|
if (!static_branch_unlikely(&cpusets_enabled_key))
|
2015-11-06 16:28:15 -08:00
|
|
|
return false;
|
|
|
|
|
|
2014-04-03 14:47:24 -07:00
|
|
|
return read_seqcount_retry(¤t->mems_allowed_seq, seq);
|
2010-05-24 14:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
2009-06-16 15:31:49 -07:00
|
|
|
static inline void set_mems_allowed(nodemask_t nodemask)
|
|
|
|
|
{
|
2013-10-07 15:52:00 -07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
2010-05-24 14:32:08 -07:00
|
|
|
task_lock(current);
|
2013-10-07 15:52:00 -07:00
|
|
|
local_irq_save(flags);
|
2012-03-21 16:34:11 -07:00
|
|
|
write_seqcount_begin(¤t->mems_allowed_seq);
|
2009-06-16 15:31:49 -07:00
|
|
|
current->mems_allowed = nodemask;
|
2012-03-21 16:34:11 -07:00
|
|
|
write_seqcount_end(¤t->mems_allowed_seq);
|
2013-10-07 15:52:00 -07:00
|
|
|
local_irq_restore(flags);
|
2010-05-24 14:32:08 -07:00
|
|
|
task_unlock(current);
|
2009-06-16 15:31:49 -07:00
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#else /* !CONFIG_CPUSETS */
|
|
|
|
|
|
2014-06-04 16:10:08 -07:00
|
|
|
static inline bool cpusets_enabled(void) { return false; }
|
|
|
|
|
|
2021-11-05 13:40:34 -07:00
|
|
|
static inline bool cpusets_insane_config(void) { return false; }
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
static inline int cpuset_init(void) { return 0; }
|
|
|
|
|
static inline void cpuset_init_smp(void) {}
|
|
|
|
|
|
2017-09-07 11:13:38 +02:00
|
|
|
static inline void cpuset_force_rebuild(void) { }
|
|
|
|
|
|
2017-04-09 07:36:14 +06:00
|
|
|
static inline void cpuset_update_active_cpus(void)
|
2010-06-08 21:40:36 +02:00
|
|
|
{
|
|
|
|
|
partition_sched_domains(1, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 11:13:38 +02:00
|
|
|
static inline void cpuset_wait_for_hotplug(void) { }
|
|
|
|
|
|
2019-07-19 16:00:00 +02:00
|
|
|
static inline void cpuset_read_lock(void) { }
|
|
|
|
|
static inline void cpuset_read_unlock(void) { }
|
|
|
|
|
|
2009-01-07 18:08:45 -08:00
|
|
|
static inline void cpuset_cpus_allowed(struct task_struct *p,
|
|
|
|
|
struct cpumask *mask)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2021-07-30 12:24:30 +01:00
|
|
|
cpumask_copy(mask, task_cpu_possible_mask(p));
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-30 12:24:31 +01:00
|
|
|
static inline bool cpuset_cpus_allowed_fallback(struct task_struct *p)
|
2010-03-15 10:10:27 +01:00
|
|
|
{
|
2021-07-30 12:24:31 +01:00
|
|
|
return false;
|
2010-03-15 10:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
2006-01-08 01:01:55 -08:00
|
|
|
static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
|
|
|
|
|
{
|
|
|
|
|
return node_possible_map;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 13:51:24 -08:00
|
|
|
#define cpuset_current_mems_allowed (node_states[N_MEMORY])
|
2005-04-16 15:20:36 -07:00
|
|
|
static inline void cpuset_init_current_mems_allowed(void) {}
|
|
|
|
|
|
2008-04-28 02:12:18 -07:00
|
|
|
static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 17:14:30 -07:00
|
|
|
static inline bool cpuset_node_allowed(int node, gfp_t gfp_mask)
|
2009-04-02 16:57:54 -07:00
|
|
|
{
|
2016-05-19 17:14:30 -07:00
|
|
|
return true;
|
2009-04-02 16:57:54 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-19 17:14:30 -07:00
|
|
|
static inline bool __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2016-05-19 17:14:30 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2007-10-16 23:25:58 -07:00
|
|
|
static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
|
|
|
|
|
const struct task_struct *tsk2)
|
2005-09-06 15:18:13 -07:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-08 01:01:49 -08:00
|
|
|
static inline void cpuset_memory_pressure_bump(void) {}
|
|
|
|
|
|
2008-02-08 04:18:33 -08:00
|
|
|
static inline void cpuset_task_status_allowed(struct seq_file *m,
|
|
|
|
|
struct task_struct *task)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-24 03:16:03 -08:00
|
|
|
static inline int cpuset_mem_spread_node(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-26 14:42:49 -07:00
|
|
|
static inline int cpuset_slab_spread_node(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-24 03:16:03 -08:00
|
|
|
static inline int cpuset_do_page_mem_spread(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int cpuset_do_slab_mem_spread(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 15:41:24 -08:00
|
|
|
static inline bool current_cpuset_is_being_rebound(void)
|
2007-10-18 23:39:39 -07:00
|
|
|
{
|
2018-02-06 15:41:24 -08:00
|
|
|
return false;
|
2007-10-18 23:39:39 -07:00
|
|
|
}
|
|
|
|
|
|
2008-07-15 04:43:49 -07:00
|
|
|
static inline void rebuild_sched_domains(void)
|
|
|
|
|
{
|
2008-08-29 13:11:41 -07:00
|
|
|
partition_sched_domains(1, NULL, NULL);
|
2008-07-15 04:43:49 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-05 18:48:05 -08:00
|
|
|
static inline void cpuset_print_current_mems_allowed(void)
|
2009-01-06 14:39:01 -08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-16 15:31:49 -07:00
|
|
|
static inline void set_mems_allowed(nodemask_t nodemask)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 14:47:24 -07:00
|
|
|
static inline unsigned int read_mems_allowed_begin(void)
|
2010-05-24 14:32:08 -07:00
|
|
|
{
|
2012-03-21 16:34:11 -07:00
|
|
|
return 0;
|
2010-05-24 14:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
2014-04-03 14:47:24 -07:00
|
|
|
static inline bool read_mems_allowed_retry(unsigned int seq)
|
2010-05-24 14:32:08 -07:00
|
|
|
{
|
2014-04-03 14:47:24 -07:00
|
|
|
return false;
|
2010-05-24 14:32:08 -07:00
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif /* !CONFIG_CPUSETS */
|
|
|
|
|
|
|
|
|
|
#endif /* _LINUX_CPUSET_H */
|