Skip to contentSkip to conversation

cgroup:cpuset:separate legacy cgroup v1 code and put under config option

PATCH Superseded Chen Ridong 3 participants 15 messages Aug 27, 2024 – Aug 30, 2024

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover cgroup:cpuset:separate legacy cgroup v1 code and put under config option

Cgroups v2 have been around for a while and many users have fully adopted them, so they never use cgroups v1 features and functionality. Yet they have to "pay" for the cgroup v1 support anyway:
1) the kernel binary contains an unused cgroup v1 code,
2) some code paths have additional checks which are not needed,
3) some common structures like task_struct and mem_cgroup contain unused cgroup v1-specific members.

Cgroup memory controller has already separated legacy code to memory-v1.c. So it is time to do the same thing for cpuset controller.

This patchset aims to do:
1) moving cgroup v1-specific cpuset code to the new cpuset-v1.c file,
2) putting definitions shared by cpuset.c and cpuset-v1.c into the cpuset-internal.h header,
3) introducing the CONFIG_CPUSETS_V1 config option, turned off by default,
4) making cpuset-v1.c to compile only if CONFIG_CPUSETS_V1 is set.

---
V3:
- Delete blank line at the end of file.
- Rename some generic functions name with cpuset_/cpuset1_ prefix.

V2:
- Update to base on the latest cgroup/for-6.12.
- Add CONFIG_CPUSETS_V1 for cpuset_memory_pressure_bump.

Chen Ridong (12):
cgroup/cpuset: introduce cpuset-v1.c cgroup/cpuset: move common code to cpuset-internal.h cgroup/cpuset: move memory_pressure to cpuset-v1.c cgroup/cpuset: move relax_domain_level to cpuset-v1.c cgroup/cpuset: move memory_spread to cpuset-v1.c cgroup/cpuset: add callback_lock helper cgroup/cpuset: move legacy hotplug update to cpuset-v1.c cgroup/cpuset: move validate_change_legacy to cpuset-v1.c cgroup/cpuset: move v1 interfaces to cpuset-v1.c cgroup/cpuset: rename functions shared between v1 and v2 cgroup/cpuset: guard cpuset-v1 code under CONFIG_CPUSETS_V1 cgroup/cpuset: add sefltest for cpuset v1

 MAINTAINERS                                   |   3 +
 include/linux/cpuset.h                        |   4 +
 init/Kconfig                                  |  13 +
 kernel/cgroup/Makefile                        |   1 +
 kernel/cgroup/cpuset-internal.h               | 304 ++++++
 kernel/cgroup/cpuset-v1.c                     | 562 +++++++++++
 kernel/cgroup/cpuset.c                        | 908 +-----------------
 .../selftests/cgroup/test_cpuset_v1_base.sh   |  77 ++
 8 files changed, 1013 insertions(+), 859 deletions(-)
 create mode 100644 kernel/cgroup/cpuset-internal.h
 create mode 100644 kernel/cgroup/cpuset-v1.c
 create mode 100755 tools/testing/selftests/cgroup/test_cpuset_v1_base.sh
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/12 cgroup/cpuset: introduce cpuset-v1.c

This patch introduces the cgroup/cpuset-v1.c source file which will be used for all legacy (cgroup v1) cpuset cgroup code. It also introduces cgroup/cpuset-internal.h to keep declarations shared between cgroup/cpuset.c and cpuset/cpuset-v1.c.

As of now, let's compile it if CONFIG_CPUSET is set. Later on it can be switched to use a separate config option, so that the legacy code won't be compiled if not required.

---
 MAINTAINERS                     | 2 ++
 kernel/cgroup/Makefile          | 2 +-
 kernel/cgroup/cpuset-internal.h | 6 ++++++
 kernel/cgroup/cpuset-v1.c       | 3 +++
 4 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 kernel/cgroup/cpuset-internal.h
 create mode 100644 kernel/cgroup/cpuset-v1.c
MAINTAINERS +2 -0
index 82e3924816d2..3b5ec1cafd95 100644
@@ -5698,6 +5698,8 @@ S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
 F:	Documentation/admin-guide/cgroup-v1/cpusets.rst
 F:	include/linux/cpuset.h
+F:	kernel/cgroup/cpuset-internal.h
+F:	kernel/cgroup/cpuset-v1.c
 F:	kernel/cgroup/cpuset.c
 F:	tools/testing/selftests/cgroup/test_cpuset.c
 F:	tools/testing/selftests/cgroup/test_cpuset_prs.sh
kernel/cgroup/Makefile +1 -1
index 12f8457ad1f9..005ac4c675cb 100644
@@ -4,6 +4,6 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o freezer.o
 obj-$(CONFIG_CGROUP_FREEZER) += legacy_freezer.o
 obj-$(CONFIG_CGROUP_PIDS) += pids.o
 obj-$(CONFIG_CGROUP_RDMA) += rdma.o
-obj-$(CONFIG_CPUSETS) += cpuset.o
+obj-$(CONFIG_CPUSETS) += cpuset.o cpuset-v1.o
 obj-$(CONFIG_CGROUP_MISC) += misc.o
 obj-$(CONFIG_CGROUP_DEBUG) += debug.o
kernel/cgroup/cpuset-internal.h new file +6 -0
new file mode 100644
index 000000000000..034de3cbf3ad
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __CPUSET_INTERNAL_H
+#define __CPUSET_INTERNAL_H
+
+#endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c new file +3 -0
new file mode 100644
index 000000000000..bdec4b196986
@@ -0,0 +1,3 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "cpuset-internal.h"
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/12 cgroup/cpuset: move common code to cpuset-internal.h

In reply to Chen Ridong

Move some declarations that will be used for cpuset v1 and v2, including 'cpuset struct', 'cpuset_flagbits_t', cpuset_filetype_t,etc. No logical change.

---
 kernel/cgroup/cpuset-internal.h | 235 +++++++++++++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 236 +-------------------------------
 2 files changed, 236 insertions(+), 235 deletions(-)
kernel/cgroup/cpuset-internal.h +235 -0
index 034de3cbf3ad..ffea3eefebdf 100644
@@ -3,4 +3,239 @@
 #ifndef __CPUSET_INTERNAL_H
 #define __CPUSET_INTERNAL_H
 
+#include <linux/union_find.h>
+#include <linux/cpumask.h>
+#include <linux/spinlock.h>
+#include <linux/cpuset.h>
+#include <linux/cgroup.h>
+
+/* See "Frequency meter" comments, below. */
+
+struct fmeter {
+	int cnt;		/* unprocessed events count */
+	int val;		/* most recent output value */
+	time64_t time;		/* clock (secs) when val computed */
+	spinlock_t lock;	/* guards read or write of above */
+};
+
+/*
+ * Invalid partition error code
+ */
+enum prs_errcode {
+	PERR_NONE = 0,
+	PERR_INVCPUS,
+	PERR_INVPARENT,
+	PERR_NOTPART,
+	PERR_NOTEXCL,
+	PERR_NOCPUS,
+	PERR_HOTPLUG,
+	PERR_CPUSEMPTY,
+	PERR_HKEEPING,
+	PERR_ACCESS,
+};
+
+/* bits in struct cpuset flags field */
+typedef enum {
+	CS_ONLINE,
+	CS_CPU_EXCLUSIVE,
+	CS_MEM_EXCLUSIVE,
+	CS_MEM_HARDWALL,
+	CS_MEMORY_MIGRATE,
+	CS_SCHED_LOAD_BALANCE,
+	CS_SPREAD_PAGE,
+	CS_SPREAD_SLAB,
+} cpuset_flagbits_t;
+
+/* The various types of files and directories in a cpuset file system */
+
+typedef enum {
+	FILE_MEMORY_MIGRATE,
+	FILE_CPULIST,
+	FILE_MEMLIST,
+	FILE_EFFECTIVE_CPULIST,
+	FILE_EFFECTIVE_MEMLIST,
+	FILE_SUBPARTS_CPULIST,
+	FILE_EXCLUSIVE_CPULIST,
+	FILE_EFFECTIVE_XCPULIST,
+	FILE_ISOLATED_CPULIST,
+	FILE_CPU_EXCLUSIVE,
+	FILE_MEM_EXCLUSIVE,
+	FILE_MEM_HARDWALL,
+	FILE_SCHED_LOAD_BALANCE,
+	FILE_PARTITION_ROOT,
+	FILE_SCHED_RELAX_DOMAIN_LEVEL,
+	FILE_MEMORY_PRESSURE_ENABLED,
+	FILE_MEMORY_PRESSURE,
+	FILE_SPREAD_PAGE,
+	FILE_SPREAD_SLAB,
+} cpuset_filetype_t;
+
+struct cpuset {
+	struct cgroup_subsys_state css;
+
+	unsigned long flags;		/* "unsigned long" so bitops work */
+
+	/*
+	 * On default hierarchy:
+	 *
+	 * The user-configured masks can only be changed by writing to
+	 * cpuset.cpus and cpuset.mems, and won't be limited by the
+	 * parent masks.
+	 *
+	 * The effective masks is the real masks that apply to the tasks
+	 * in the cpuset. They may be changed if the configured masks are
+	 * changed or hotplug happens.
+	 *
+	 * effective_mask == configured_mask & parent's effective_mask,
+	 * and if it ends up empty, it will inherit the parent's mask.
+	 *
+	 *
+	 * On legacy hierarchy:
+	 *
+	 * The user-configured masks are always the same with effective masks.
+	 */
+
+	/* user-configured CPUs and Memory Nodes allow to tasks */
+	cpumask_var_t cpus_allowed;
+	nodemask_t mems_allowed;
+
+	/* effective CPUs and Memory Nodes allow to tasks */
+	cpumask_var_t effective_cpus;
+	nodemask_t effective_mems;
+
+	/*
+	 * Exclusive CPUs dedicated to current cgroup (default hierarchy only)
+	 *
+	 * The effective_cpus of a valid partition root comes solely from its
+	 * effective_xcpus and some of the effective_xcpus may be distributed
+	 * to sub-partitions below & hence excluded from its effective_cpus.
+	 * For a valid partition root, its effective_cpus have no relationship
+	 * with cpus_allowed unless its exclusive_cpus isn't set.
+	 *
+	 * This value will only be set if either exclusive_cpus is set or
+	 * when this cpuset becomes a local partition root.
+	 */
+	cpumask_var_t effective_xcpus;
+
+	/*
+	 * Exclusive CPUs as requested by the user (default hierarchy only)
+	 *
+	 * Its value is independent of cpus_allowed and designates the set of
+	 * CPUs that can be granted to the current cpuset or its children when
+	 * it becomes a valid partition root. The effective set of exclusive
+	 * CPUs granted (effective_xcpus) depends on whether those exclusive
+	 * CPUs are passed down by its ancestors and not yet taken up by
+	 * another sibling partition root along the way.
+	 *
+	 * If its value isn't set, it defaults to cpus_allowed.
+	 */
+	cpumask_var_t exclusive_cpus;
+
+	/*
+	 * This is old Memory Nodes tasks took on.
+	 *
+	 * - top_cpuset.old_mems_allowed is initialized to mems_allowed.
+	 * - A new cpuset's old_mems_allowed is initialized when some
+	 *   task is moved into it.
+	 * - old_mems_allowed is used in cpuset_migrate_mm() when we change
+	 *   cpuset.mems_allowed and have tasks' nodemask updated, and
+	 *   then old_mems_allowed is updated to mems_allowed.
+	 */
+	nodemask_t old_mems_allowed;
+
+	struct fmeter fmeter;		/* memory_pressure filter */
+
+	/*
+	 * Tasks are being attached to this cpuset.  Used to prevent
+	 * zeroing cpus/mems_allowed between ->can_attach() and ->attach().
+	 */
+	int attach_in_progress;
+
+	/* for custom sched domain */
+	int relax_domain_level;
+
+	/* number of valid local child partitions */
+	int nr_subparts;
+
+	/* partition root state */
+	int partition_root_state;
+
+	/*
+	 * number of SCHED_DEADLINE tasks attached to this cpuset, so that we
+	 * know when to rebuild associated root domain bandwidth information.
+	 */
+	int nr_deadline_tasks;
+	int nr_migrate_dl_tasks;
+	u64 sum_migrate_dl_bw;
+
+	/* Invalid partition error code, not lock protected */
+	enum prs_errcode prs_err;
+
+	/* Handle for cpuset.cpus.partition */
+	struct cgroup_file partition_file;
+
+	/* Remote partition silbling list anchored at remote_children */
+	struct list_head remote_sibling;
+
+	/* Used to merge intersecting subsets for generate_sched_domains */
+	struct uf_node node;
+};
+
+static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)
+{
+	return css ? container_of(css, struct cpuset, css) : NULL;
+}
+
+/* Retrieve the cpuset for a task */
+static inline struct cpuset *task_cs(struct task_struct *task)
+{
+	return css_cs(task_css(task, cpuset_cgrp_id));
+}
+
+static inline struct cpuset *parent_cs(struct cpuset *cs)
+{
+	return css_cs(cs->css.parent);
+}
+
+/* convenient tests for these bits */
+static inline bool is_cpuset_online(struct cpuset *cs)
+{
+	return test_bit(CS_ONLINE, &cs->flags) && !css_is_dying(&cs->css);
+}
+
+static inline int is_cpu_exclusive(const struct cpuset *cs)
+{
+	return test_bit(CS_CPU_EXCLUSIVE, &cs->flags);
+}
+
+static inline int is_mem_exclusive(const struct cpuset *cs)
+{
+	return test_bit(CS_MEM_EXCLUSIVE, &cs->flags);
+}
+
+static inline int is_mem_hardwall(const struct cpuset *cs)
+{
+	return test_bit(CS_MEM_HARDWALL, &cs->flags);
+}
+
+static inline int is_sched_load_balance(const struct cpuset *cs)
+{
+	return test_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
+}
+
+static inline int is_memory_migrate(const struct cpuset *cs)
+{
+	return test_bit(CS_MEMORY_MIGRATE, &cs->flags);
+}
+
+static inline int is_spread_page(const struct cpuset *cs)
+{
+	return test_bit(CS_SPREAD_PAGE, &cs->flags);
+}
+
+static inline int is_spread_slab(const struct cpuset *cs)
+{
+	return test_bit(CS_SPREAD_SLAB, &cs->flags);
+}
+
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset.c +1 -235

284 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/12 cgroup/cpuset: move memory_pressure to cpuset-v1.c

In reply to Chen Ridong

Collection of memory_pressure can be enabled by writing 1 to the cpuset file 'memory_pressure_enabled', which is only for cpuset-v1. Therefore, move the corresponding code to cpuset-v1.c.

Currently, the 'fmeter_init' and 'fmeter_getrate' functions are called at cpuset.c, so expose them to cpuset.c.

---
 kernel/cgroup/cpuset-internal.h |   7 ++
 kernel/cgroup/cpuset-v1.c       | 134 ++++++++++++++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 134 --------------------------------
 3 files changed, 141 insertions(+), 134 deletions(-)
kernel/cgroup/cpuset-internal.h +7 -0
index ffea3eefebdf..7911c86bf012 100644
@@ -238,4 +238,11 @@ static inline int is_spread_slab(const struct cpuset *cs)
 	return test_bit(CS_SPREAD_SLAB, &cs->flags);
 }
 
+/*
+ * cpuset-v1.c
+ */
+
+void fmeter_init(struct fmeter *fmp);
+int fmeter_getrate(struct fmeter *fmp);
+
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +134 -0

137 lines not on this page · raw message

kernel/cgroup/cpuset.c +0 -134

146 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 4/12 cgroup/cpuset: move relax_domain_level to cpuset-v1.c

In reply to Chen Ridong

Setting domain level is not supported at cpuset v2, so move corresponding code into cpuset-v1.c.

The 'cpuset_write_s64' and 'cpuset_read_s64' are only used for setting domain level, move them to cpuset-v1.c. Currently, expose to cpuset.c. After cpuset legacy interface files are move to cpuset-v1.c, they can be static. The 'rebuild_sched_domains_locked' is exposed to cpuset-v1.c.

The change from original code is that using 'cpuset_lock' and 'cpuset_unlock' functions to lock or unlock cpuset_mutex.

---
 kernel/cgroup/cpuset-internal.h |  6 +++-
 kernel/cgroup/cpuset-v1.c       | 59 +++++++++++++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 62 ++-------------------------------
 3 files changed, 66 insertions(+), 61 deletions(-)
kernel/cgroup/cpuset-internal.h +5 -1
index 7911c86bf012..1058a45f05ec 100644
@@ -238,11 +238,15 @@ static inline int is_spread_slab(const struct cpuset *cs)
 	return test_bit(CS_SPREAD_SLAB, &cs->flags);
 }
 
+void rebuild_sched_domains_locked(void);
+
 /*
  * cpuset-v1.c
  */
-
 void fmeter_init(struct fmeter *fmp);
 int fmeter_getrate(struct fmeter *fmp);
+int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
+			    s64 val);
+s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft);
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +59 -0

62 lines not on this page · raw message

kernel/cgroup/cpuset.c +2 -60

92 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

PATCH v3 5/12 cgroup/cpuset: move memory_spread to cpuset-v1.c

In reply to Chen Ridong

'memory_spread' is only set in cpuset v1. move corresponding code into cpuset-v1.c.

Currently, 'cpuset_update_task_spread_flags' and 'update_tasks_flags' are exposed to cpuset.c.

---
 kernel/cgroup/cpuset-internal.h |  3 +++
 kernel/cgroup/cpuset-v1.c       | 42 +++++++++++++++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 42 ---------------------------------
 3 files changed, 45 insertions(+), 42 deletions(-)
kernel/cgroup/cpuset-internal.h +3 -0
index 1058a45f05ec..02c4b0c74fa9 100644
@@ -248,5 +248,8 @@ int fmeter_getrate(struct fmeter *fmp);
 int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
 			    s64 val);
 s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft);
+void cpuset_update_task_spread_flags(struct cpuset *cs,
+					struct task_struct *tsk);
+void update_tasks_flags(struct cpuset *cs);
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +42 -0

45 lines not on this page · raw message

kernel/cgroup/cpuset.c +0 -42

54 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

PATCH v3 6/12 cgroup/cpuset: add callback_lock helper

In reply to Chen Ridong

To modify cpuset, both cpuset_mutex and callback_lock are needed. Add helpers for cpuset-v1 to get callback_lock.

---
 kernel/cgroup/cpuset-internal.h |  2 ++
 kernel/cgroup/cpuset.c          | 10 ++++++++++
 2 files changed, 12 insertions(+)
kernel/cgroup/cpuset-internal.h +2 -0
index 02c4b0c74fa9..9a60dd6681e4 100644
@@ -239,6 +239,8 @@ static inline int is_spread_slab(const struct cpuset *cs)
 }
 
 void rebuild_sched_domains_locked(void);
+void callback_lock_irq(void);
+void callback_unlock_irq(void);
 
 /*
  * cpuset-v1.c
kernel/cgroup/cpuset.c +10 -0
index 0a3347e4dddc..2b2dc963299b 100644
@@ -269,6 +269,16 @@ void cpuset_unlock(void)
 
 static DEFINE_SPINLOCK(callback_lock);
 
+void callback_lock_irq(void)
+{
+	spin_lock_irq(&callback_lock);
+}
+
+void callback_unlock_irq(void)
+{
+	spin_unlock_irq(&callback_lock);
+}
+
 static struct workqueue_struct *cpuset_migrate_mm_wq;
 
 static DECLARE_WAIT_QUEUE_HEAD(cpuset_attach_wq);
Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 7/12 cgroup/cpuset: move legacy hotplug update to cpuset-v1.c

In reply to Chen Ridong

There are some differents about hotplug update between cpuset v1 and cpuset v2. Move the legacy code to cpuset-v1.c.

'update_tasks_cpumask' and 'update_tasks_nodemask' are both used in cpuset v1 and cpuset v2, declare them in cpuset-internal.h.

The change from original code is that use callback_lock helpers to get callback_lock lock/unlock.

---
 kernel/cgroup/cpuset-internal.h |  5 ++
 kernel/cgroup/cpuset-v1.c       | 91 +++++++++++++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 96 +--------------------------------
 3 files changed, 98 insertions(+), 94 deletions(-)
kernel/cgroup/cpuset-internal.h +5 -0
index 9a60dd6681e4..7cd30ad809d5 100644
@@ -241,6 +241,8 @@ static inline int is_spread_slab(const struct cpuset *cs)
 void rebuild_sched_domains_locked(void);
 void callback_lock_irq(void);
 void callback_unlock_irq(void);
+void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
+void update_tasks_nodemask(struct cpuset *cs);
 
 /*
  * cpuset-v1.c
@@ -253,5 +255,8 @@ s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft);
 void cpuset_update_task_spread_flags(struct cpuset *cs,
 					struct task_struct *tsk);
 void update_tasks_flags(struct cpuset *cs);
+void hotplug_update_tasks_legacy(struct cpuset *cs,
+			    struct cpumask *new_cpus, nodemask_t *new_mems,
+			    bool cpus_updated, bool mems_updated);
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +91 -0

100 lines not on this page · raw message

kernel/cgroup/cpuset.c +2 -94

120 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

PATCH v3 8/12 cgroup/cpuset: move validate_change_legacy to cpuset-v1.c

In reply to Chen Ridong

The validate_change_legacy functions is used for v1, move it to cpuset-v1.c. And two micro 'cpuset_for_each_child' and 'cpuset_for_each_descendant_pre' are common for v1 and v2, move them to cpuset-internal.h.

---
 kernel/cgroup/cpuset-internal.h | 29 +++++++++++++
 kernel/cgroup/cpuset-v1.c       | 45 ++++++++++++++++++++
 kernel/cgroup/cpuset.c          | 73 ---------------------------------
 3 files changed, 74 insertions(+), 73 deletions(-)
kernel/cgroup/cpuset-internal.h +29 -0
index 7cd30ad809d5..07551ff0812e 100644
@@ -238,6 +238,34 @@ static inline int is_spread_slab(const struct cpuset *cs)
 	return test_bit(CS_SPREAD_SLAB, &cs->flags);
 }
 
+/**
+ * cpuset_for_each_child - traverse online children of a cpuset
+ * @child_cs: loop cursor pointing to the current child
+ * @pos_css: used for iteration
+ * @parent_cs: target cpuset to walk children of
+ *
+ * Walk @child_cs through the online children of @parent_cs.  Must be used
+ * with RCU read locked.
+ */
+#define cpuset_for_each_child(child_cs, pos_css, parent_cs)		\
+	css_for_each_child((pos_css), &(parent_cs)->css)		\
+		if (is_cpuset_online(((child_cs) = css_cs((pos_css)))))
+
+/**
+ * cpuset_for_each_descendant_pre - pre-order walk of a cpuset's descendants
+ * @des_cs: loop cursor pointing to the current descendant
+ * @pos_css: used for iteration
+ * @root_cs: target cpuset to walk ancestor of
+ *
+ * Walk @des_cs through the online descendants of @root_cs.  Must be used
+ * with RCU read locked.  The caller may modify @pos_css by calling
+ * css_rightmost_descendant() to skip subtree.  @root_cs is included in the
+ * iteration and the first node to be visited.
+ */
+#define cpuset_for_each_descendant_pre(des_cs, pos_css, root_cs)	\
+	css_for_each_descendant_pre((pos_css), &(root_cs)->css)		\
+		if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
+
 void rebuild_sched_domains_locked(void);
 void callback_lock_irq(void);
 void callback_unlock_irq(void);
@@ -258,5 +286,6 @@ void update_tasks_flags(struct cpuset *cs);
 void hotplug_update_tasks_legacy(struct cpuset *cs,
 			    struct cpumask *new_cpus, nodemask_t *new_mems,
 			    bool cpus_updated, bool mems_updated);
+int validate_change_legacy(struct cpuset *cur, struct cpuset *trial);
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +45 -0

48 lines not on this page · raw message

kernel/cgroup/cpuset.c +0 -73

91 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

PATCH v3 9/12 cgroup/cpuset: move v1 interfaces to cpuset-v1.c

In reply to Chen Ridong

Move legacy cpuset controller interfaces files and corresponding code into cpuset-v1.c. 'update_flag', 'cpuset_write_resmask' and 'cpuset_common_seq_show' are also used for v1, so declare them in cpuset-internal.h.

'cpuset_write_s64', 'cpuset_read_s64' and 'fmeter_getrate' are only used cpuset-v1.c now, make it static.

---
 kernel/cgroup/cpuset-internal.h |   9 +-
 kernel/cgroup/cpuset-v1.c       | 194 ++++++++++++++++++++++++++++++-
 kernel/cgroup/cpuset.c          | 195 +-------------------------------
 3 files changed, 199 insertions(+), 199 deletions(-)
kernel/cgroup/cpuset-internal.h +5 -4
index 07551ff0812e..a6c71c86e58d 100644
@@ -271,15 +271,16 @@ void callback_lock_irq(void);
 void callback_unlock_irq(void);
 void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
 void update_tasks_nodemask(struct cpuset *cs);
+int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
+ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
+				    char *buf, size_t nbytes, loff_t off);
+int cpuset_common_seq_show(struct seq_file *sf, void *v);
 
 /*
  * cpuset-v1.c
  */
+extern struct cftype legacy_files[];
 void fmeter_init(struct fmeter *fmp);
-int fmeter_getrate(struct fmeter *fmp);
-int cpuset_write_s64(struct cgroup_subsys_state *css, struct cftype *cft,
-			    s64 val);
-s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft);
 void cpuset_update_task_spread_flags(struct cpuset *cs,
 					struct task_struct *tsk);
 void update_tasks_flags(struct cpuset *cs);
kernel/cgroup/cpuset-v1.c +191 -3

215 lines not on this page · raw message

kernel/cgroup/cpuset.c +3 -192

234 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw

PATCH v3 10/12 cgroup/cpuset: rename functions shared between v1 and v2

In reply to Chen Ridong

Some functions name declared in cpuset-internel.h are generic. To avoid confilicting with other variables for the same name, rename these functions with cpuset_/cpuset1_ prefix to make them unique to cpuset.

---
 kernel/cgroup/cpuset-internal.h | 22 +++++-----
 kernel/cgroup/cpuset-v1.c       | 44 ++++++++++----------
 kernel/cgroup/cpuset.c          | 72 ++++++++++++++++-----------------
 3 files changed, 69 insertions(+), 69 deletions(-)
kernel/cgroup/cpuset-internal.h +11 -11
index a6c71c86e58d..683fcf8bc743 100644
@@ -266,12 +266,12 @@ static inline int is_spread_slab(const struct cpuset *cs)
 	css_for_each_descendant_pre((pos_css), &(root_cs)->css)		\
 		if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
 
-void rebuild_sched_domains_locked(void);
-void callback_lock_irq(void);
-void callback_unlock_irq(void);
-void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
-void update_tasks_nodemask(struct cpuset *cs);
-int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
+void cpuset_rebuild_sched_domains_locked(void);
+void cpuset_callback_lock_irq(void);
+void cpuset_callback_unlock_irq(void);
+void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
+void cpuset_update_tasks_nodemask(struct cpuset *cs);
+int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
 ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 				    char *buf, size_t nbytes, loff_t off);
 int cpuset_common_seq_show(struct seq_file *sf, void *v);
@@ -280,13 +280,13 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v);
  * cpuset-v1.c
  */
 extern struct cftype legacy_files[];
-void fmeter_init(struct fmeter *fmp);
-void cpuset_update_task_spread_flags(struct cpuset *cs,
+void cpuset1_fmeter_init(struct fmeter *fmp);
+void cpuset1_update_task_spread_flags(struct cpuset *cs,
 					struct task_struct *tsk);
-void update_tasks_flags(struct cpuset *cs);
-void hotplug_update_tasks_legacy(struct cpuset *cs,
+void cpuset1_update_tasks_flags(struct cpuset *cs);
+void cpuset1_hotplug_update_tasks(struct cpuset *cs,
 			    struct cpumask *new_cpus, nodemask_t *new_mems,
 			    bool cpus_updated, bool mems_updated);
-int validate_change_legacy(struct cpuset *cur, struct cpuset *trial);
+int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +22 -22

136 lines not on this page · raw message

kernel/cgroup/cpuset.c +36 -36

274 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#11 lore raw

Re: [PATCH v3 -next 10/12] cgroup/cpuset: rename functions shared between v1 and v2

Quoted 16 lines · Chen Ridong

Some functions name declared in cpuset-internel.h are generic. To avoid confilicting with other variables for the same name, rename these functions with cpuset_/cpuset1_ prefix to make them unique to cpuset.

---
  kernel/cgroup/cpuset-internal.h | 22 +++++-----
  kernel/cgroup/cpuset-v1.c       | 44 ++++++++++----------
  kernel/cgroup/cpuset.c          | 72 ++++++++++++++++-----------------
  3 files changed, 69 insertions(+), 69 deletions(-)
kernel/cgroup/cpuset-internal.h +0 -0
index a6c71c86e58d..683fcf8bc743 100644

kernel/cgroup/cpuset-internal.h static inline int is_spread_slab(const struct cpuset *cs) · line 269

Quoted 10 lines
kernel/cgroup/cpuset-internal.h +1 -6
@@ -266,12 +266,12 @@ static inline int is_spread_slab(const struct cpuset *cs)
  	css_for_each_descendant_pre((pos_css), &(root_cs)->css)		\
  		if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
 
-void rebuild_sched_domains_locked(void);
-void callback_lock_irq(void);
-void callback_unlock_irq(void);
-void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
-void update_tasks_nodemask(struct cpuset *cs);
-int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
+void cpuset_rebuild_sched_domains_locked(void);

There is already a "rebuild_sched_domain()" function that is externally visible and the name is pretty unique. I don't think we need to add the "cpuset_" prefix for consistency.

Quoted 9 lines
kernel/cgroup/cpuset-internal.h +5 -0
+void cpuset_callback_lock_irq(void);
+void cpuset_callback_unlock_irq(void);
+void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
+void cpuset_update_tasks_nodemask(struct cpuset *cs);
+int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int turning_on);
  ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
  				    char *buf, size_t nbytes, loff_t off);
  int cpuset_common_seq_show(struct seq_file *sf, void *v);

kernel/cgroup/cpuset-internal.h int cpuset_common_seq_show(struct seq_file *sf, void *v); · line 283

Quoted 6 lines
kernel/cgroup/cpuset-internal.h +1 -2
@@ -280,13 +280,13 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v);
   * cpuset-v1.c
   */
  extern struct cftype legacy_files[];
-void fmeter_init(struct fmeter *fmp);
-void cpuset_update_task_spread_flags(struct cpuset *cs,
+void cpuset1_fmeter_init(struct fmeter *fmp);

Similarly, there are other fmeter_* functions available and fmeter is a unique prefix. The cpuset_ prefix shouldn't be needed.

OTOH, the legacy_files should be changed to cpuset1_files.

Other than that, the rest of the series looks good to me.

Cheers,
Longman

Quoted 469 lines
kernel/cgroup/cpuset-internal.h +4 -3
+void cpuset1_update_task_spread_flags(struct cpuset *cs,
  					struct task_struct *tsk);
-void update_tasks_flags(struct cpuset *cs);
-void hotplug_update_tasks_legacy(struct cpuset *cs,
+void cpuset1_update_tasks_flags(struct cpuset *cs);
+void cpuset1_hotplug_update_tasks(struct cpuset *cs,
  			    struct cpumask *new_cpus, nodemask_t *new_mems,
  			    bool cpus_updated, bool mems_updated);
-int validate_change_legacy(struct cpuset *cur, struct cpuset *trial);
+int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
 
  #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +22 -22
index 0ccc440c468a..ab10852b4a76 100644
@@ -15,7 +15,7 @@ struct cpuset_remove_tasks_struct {
   *
   * These routines manage a digitally filtered, constant time based,
   * event frequency meter.  There are four routines:
- *   fmeter_init() - initialize a frequency meter.
+ *   cpuset1_fmeter_init() - initialize a frequency meter.
   *   fmeter_markevent() - called each time the event happens.
   *   fmeter_getrate() - returns the recent rate of such events.
   *   fmeter_update() - internal routine used to update fmeter.
@@ -61,7 +61,7 @@ struct cpuset_remove_tasks_struct {
  #define FM_SCALE 1000		/* faux fixed point scale */
 
  /* Initialize a frequency meter */
-void fmeter_init(struct fmeter *fmp)
+void cpuset1_fmeter_init(struct fmeter *fmp)
  {
  	fmp->cnt = 0;
  	fmp->val = 0;
@@ -155,7 +155,7 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val)
  		cs->relax_domain_level = val;
  		if (!cpumask_empty(cs->cpus_allowed) &&
  		    is_sched_load_balance(cs))
-			rebuild_sched_domains_locked();
+			cpuset_rebuild_sched_domains_locked();
  	}
 
  	return 0;
@@ -209,7 +209,7 @@ static s64 cpuset_read_s64(struct cgroup_subsys_state *css, struct cftype *cft)
   * Call with callback_lock or cpuset_mutex held. The check can be skipped
   * if on default hierarchy.
   */
-void cpuset_update_task_spread_flags(struct cpuset *cs,
+void cpuset1_update_task_spread_flags(struct cpuset *cs,
  					struct task_struct *tsk)
  {
  	if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys))
@@ -227,21 +227,21 @@ void cpuset_update_task_spread_flags(struct cpuset *cs,
  }
 
  /**
- * update_tasks_flags - update the spread flags of tasks in the cpuset.
+ * cpuset1_update_tasks_flags - update the spread flags of tasks in the cpuset.
   * @cs: the cpuset in which each task's spread flags needs to be changed
   *
   * Iterate through each task of @cs updating its spread flags.  As this
   * function is called with cpuset_mutex held, cpuset membership stays
   * stable.
   */
-void update_tasks_flags(struct cpuset *cs)
+void cpuset1_update_tasks_flags(struct cpuset *cs)
  {
  	struct css_task_iter it;
  	struct task_struct *task;
 
  	css_task_iter_start(&cs->css, 0, &it);
  	while ((task = css_task_iter_next(&it)))
-		cpuset_update_task_spread_flags(cs, task);
+		cpuset1_update_task_spread_flags(cs, task);
  	css_task_iter_end(&it);
  }
 
@@ -282,27 +282,27 @@ static void cpuset_migrate_tasks_workfn(struct work_struct *work)
  	kfree(s);
  }
 
-void hotplug_update_tasks_legacy(struct cpuset *cs,
+void cpuset1_hotplug_update_tasks(struct cpuset *cs,
  			    struct cpumask *new_cpus, nodemask_t *new_mems,
  			    bool cpus_updated, bool mems_updated)
  {
  	bool is_empty;
 
-	callback_lock_irq();
+	cpuset_callback_lock_irq();
  	cpumask_copy(cs->cpus_allowed, new_cpus);
  	cpumask_copy(cs->effective_cpus, new_cpus);
  	cs->mems_allowed = *new_mems;
  	cs->effective_mems = *new_mems;
-	callback_unlock_irq();
+	cpuset_callback_unlock_irq();
 
  	/*
-	 * Don't call update_tasks_cpumask() if the cpuset becomes empty,
+	 * Don't call cpuset_update_tasks_cpumask() if the cpuset becomes empty,
  	 * as the tasks will be migrated to an ancestor.
  	 */
  	if (cpus_updated && !cpumask_empty(cs->cpus_allowed))
-		update_tasks_cpumask(cs, new_cpus);
+		cpuset_update_tasks_cpumask(cs, new_cpus);
  	if (mems_updated && !nodes_empty(cs->mems_allowed))
-		update_tasks_nodemask(cs);
+		cpuset_update_tasks_nodemask(cs);
 
  	is_empty = cpumask_empty(cs->cpus_allowed) ||
  		   nodes_empty(cs->mems_allowed);
@@ -345,10 +345,10 @@ static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
  }
 
  /*
- * validate_change_legacy() - Validate conditions specific to legacy (v1)
+ * cpuset1_validate_change() - Validate conditions specific to legacy (v1)
   *                            behavior.
   */
-int validate_change_legacy(struct cpuset *cur, struct cpuset *trial)
+int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial)
  {
  	struct cgroup_subsys_state *css;
  	struct cpuset *c, *par;
@@ -421,28 +421,28 @@ static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
 
  	switch (type) {
  	case FILE_CPU_EXCLUSIVE:
-		retval = update_flag(CS_CPU_EXCLUSIVE, cs, val);
+		retval = cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, val);
  		break;
  	case FILE_MEM_EXCLUSIVE:
-		retval = update_flag(CS_MEM_EXCLUSIVE, cs, val);
+		retval = cpuset_update_flag(CS_MEM_EXCLUSIVE, cs, val);
  		break;
  	case FILE_MEM_HARDWALL:
-		retval = update_flag(CS_MEM_HARDWALL, cs, val);
+		retval = cpuset_update_flag(CS_MEM_HARDWALL, cs, val);
  		break;
  	case FILE_SCHED_LOAD_BALANCE:
-		retval = update_flag(CS_SCHED_LOAD_BALANCE, cs, val);
+		retval = cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, val);
  		break;
  	case FILE_MEMORY_MIGRATE:
-		retval = update_flag(CS_MEMORY_MIGRATE, cs, val);
+		retval = cpuset_update_flag(CS_MEMORY_MIGRATE, cs, val);
  		break;
  	case FILE_MEMORY_PRESSURE_ENABLED:
  		cpuset_memory_pressure_enabled = !!val;
  		break;
  	case FILE_SPREAD_PAGE:
-		retval = update_flag(CS_SPREAD_PAGE, cs, val);
+		retval = cpuset_update_flag(CS_SPREAD_PAGE, cs, val);
  		break;
  	case FILE_SPREAD_SLAB:
-		retval = update_flag(CS_SPREAD_SLAB, cs, val);
+		retval = cpuset_update_flag(CS_SPREAD_SLAB, cs, val);
  		break;
  	default:
  		retval = -EINVAL;
kernel/cgroup/cpuset.c +36 -36
index 2f52fe488f3a..f215311eab62 100644
@@ -233,12 +233,12 @@ void cpuset_unlock(void)
 
  static DEFINE_SPINLOCK(callback_lock);
 
-void callback_lock_irq(void)
+void cpuset_callback_lock_irq(void)
  {
  	spin_lock_irq(&callback_lock);
  }
 
-void callback_unlock_irq(void)
+void cpuset_callback_unlock_irq(void)
  {
  	spin_unlock_irq(&callback_lock);
  }
@@ -534,7 +534,7 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
  	rcu_read_lock();
 
  	if (!is_in_v2_mode())
-		ret = validate_change_legacy(cur, trial);
+		ret = cpuset1_validate_change(cur, trial);
  	if (ret)
  		goto out;
 
@@ -975,7 +975,7 @@ partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
   *
   * Call with cpuset_mutex held.  Takes cpus_read_lock().
   */
-void rebuild_sched_domains_locked(void)
+void cpuset_rebuild_sched_domains_locked(void)
  {
  	struct cgroup_subsys_state *pos_css;
  	struct sched_domain_attr *attr;
@@ -1027,7 +1027,7 @@ void rebuild_sched_domains_locked(void)
  	partition_and_rebuild_sched_domains(ndoms, doms, attr);
  }
  #else /* !CONFIG_SMP */
-void rebuild_sched_domains_locked(void)
+void cpuset_rebuild_sched_domains_locked(void)
  {
  }
  #endif /* CONFIG_SMP */
@@ -1035,7 +1035,7 @@ void rebuild_sched_domains_locked(void)
  static void rebuild_sched_domains_cpuslocked(void)
  {
  	mutex_lock(&cpuset_mutex);
-	rebuild_sched_domains_locked();
+	cpuset_rebuild_sched_domains_locked();
  	mutex_unlock(&cpuset_mutex);
  }
 
@@ -1047,7 +1047,7 @@ void rebuild_sched_domains(void)
  }
 
  /**
- * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
+ * cpuset_update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
   * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
   * @new_cpus: the temp variable for the new effective_cpus mask
   *
@@ -1057,7 +1057,7 @@ void rebuild_sched_domains(void)
   * is used instead of effective_cpus to make sure all offline CPUs are also
   * included as hotplug code won't update cpumasks for tasks in top_cpuset.
   */
-void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus)
+void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus)
  {
  	struct css_task_iter it;
  	struct task_struct *task;
@@ -1120,11 +1120,11 @@ static int update_partition_exclusive(struct cpuset *cs, int new_prs)
  	bool exclusive = (new_prs > PRS_MEMBER);
 
  	if (exclusive && !is_cpu_exclusive(cs)) {
-		if (update_flag(CS_CPU_EXCLUSIVE, cs, 1))
+		if (cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, 1))
  			return PERR_NOTEXCL;
  	} else if (!exclusive && is_cpu_exclusive(cs)) {
  		/* Turning off CS_CPU_EXCLUSIVE will not return error */
-		update_flag(CS_CPU_EXCLUSIVE, cs, 0);
+		cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, 0);
  	}
  	return 0;
  }
@@ -1133,7 +1133,7 @@ static int update_partition_exclusive(struct cpuset *cs, int new_prs)
   * Update partition load balance flag and/or rebuild sched domain
   *
   * Changing load balance flag will automatically call
- * rebuild_sched_domains_locked().
+ * cpuset_rebuild_sched_domains_locked().
   * This function is for cgroup v2 only.
   */
  static void update_partition_sd_lb(struct cpuset *cs, int old_prs)
@@ -1160,7 +1160,7 @@ static void update_partition_sd_lb(struct cpuset *cs, int old_prs)
  	}
 
  	if (rebuild_domains && !force_sd_rebuild)
-		rebuild_sched_domains_locked();
+		cpuset_rebuild_sched_domains_locked();
  }
 
  /*
@@ -1374,7 +1374,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
  	/*
  	 * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
  	 */
-	update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+	cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
  	update_sibling_cpumasks(&top_cpuset, NULL, tmp);
  	return 0;
  }
@@ -1410,7 +1410,7 @@ static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *tmp)
  	/*
  	 * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
  	 */
-	update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+	cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
  	update_sibling_cpumasks(&top_cpuset, NULL, tmp);
  }
 
@@ -1462,7 +1462,7 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *newmask,
  	/*
  	 * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
  	 */
-	update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+	cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
  	update_sibling_cpumasks(&top_cpuset, NULL, tmp);
  	return;
 
@@ -1508,7 +1508,7 @@ static void remote_partition_check(struct cpuset *cs, struct cpumask *newmask,
  			disable_cnt++;
  		}
  	if (disable_cnt && !force_sd_rebuild)
-		rebuild_sched_domains_locked();
+		cpuset_rebuild_sched_domains_locked();
  }
 
  /*
@@ -1834,7 +1834,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
  		update_partition_exclusive(cs, new_prs);
 
  	if (adding || deleting) {
-		update_tasks_cpumask(parent, tmp->addmask);
+		cpuset_update_tasks_cpumask(parent, tmp->addmask);
  		update_sibling_cpumasks(parent, cs, tmp);
  	}
 
@@ -2017,7 +2017,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
  		/*
  		 * update_parent_effective_cpumask() should have been called
  		 * for cs already in update_cpumask(). We should also call
-		 * update_tasks_cpumask() again for tasks in the parent
+		 * cpuset_update_tasks_cpumask() again for tasks in the parent
  		 * cpuset if the parent's effective_cpus changes.
  		 */
  		if ((cp != cs) && old_prs) {
@@ -2074,7 +2074,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
  		WARN_ON(!is_in_v2_mode() &&
  			!cpumask_equal(cp->cpus_allowed, cp->effective_cpus));
 
-		update_tasks_cpumask(cp, cp->effective_cpus);
+		cpuset_update_tasks_cpumask(cp, cp->effective_cpus);
 
  		/*
  		 * On default hierarchy, inherit the CS_SCHED_LOAD_BALANCE
@@ -2109,7 +2109,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
 
  	if (need_rebuild_sched_domains && !(flags & HIER_NO_SD_REBUILD) &&
  	    !force_sd_rebuild)
-		rebuild_sched_domains_locked();
+		cpuset_rebuild_sched_domains_locked();
  }
 
  /**
@@ -2501,14 +2501,14 @@ static void cpuset_change_task_nodemask(struct task_struct *tsk,
  static void *cpuset_being_rebound;
 
  /**
- * update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
+ * cpuset_update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
   * @cs: the cpuset in which each task's mems_allowed mask needs to be changed
   *
   * Iterate through each task of @cs updating its mems_allowed to the
   * effective cpuset's.  As this function is called with cpuset_mutex held,
   * cpuset membership stays stable.
   */
-void update_tasks_nodemask(struct cpuset *cs)
+void cpuset_update_tasks_nodemask(struct cpuset *cs)
  {
  	static nodemask_t newmems;	/* protected by cpuset_mutex */
  	struct css_task_iter it;
@@ -2606,7 +2606,7 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
  		WARN_ON(!is_in_v2_mode() &&
  			!nodes_equal(cp->mems_allowed, cp->effective_mems));
 
-		update_tasks_nodemask(cp);
+		cpuset_update_tasks_nodemask(cp);
 
  		rcu_read_lock();
  		css_put(&cp->css);
@@ -2693,7 +2693,7 @@ bool current_cpuset_is_being_rebound(void)
  }
 
  /*
- * update_flag - read a 0 or a 1 in a file and update associated flag
+ * cpuset_update_flag - read a 0 or a 1 in a file and update associated flag
   * bit:		the bit to update (see cpuset_flagbits_t)
   * cs:		the cpuset to update
   * turning_on: 	whether the flag is being set or cleared
@@ -2701,7 +2701,7 @@ bool current_cpuset_is_being_rebound(void)
   * Call with cpuset_mutex held.
   */
 
-int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
+int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
  		       int turning_on)
  {
  	struct cpuset *trialcs;
@@ -2734,10 +2734,10 @@ int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
 
  	if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed &&
  	    !force_sd_rebuild)
-		rebuild_sched_domains_locked();
+		cpuset_rebuild_sched_domains_locked();
 
  	if (spread_flag_changed)
-		update_tasks_flags(cs);
+		cpuset1_update_tasks_flags(cs);
  out:
  	free_cpuset(trialcs);
  	return err;
@@ -3002,7 +3002,7 @@ static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task)
  	WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach));
 
  	cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
-	cpuset_update_task_spread_flags(cs, task);
+	cpuset1_update_task_spread_flags(cs, task);
  }
 
  static void cpuset_attach(struct cgroup_taskset *tset)
@@ -3373,7 +3373,7 @@ cpuset_css_alloc(struct cgroup_subsys_state *parent_css)
  	}
 
  	__set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
-	fmeter_init(&cs->fmeter);
+	cpuset1_fmeter_init(&cs->fmeter);
  	cs->relax_domain_level = -1;
  	INIT_LIST_HEAD(&cs->remote_sibling);
 
@@ -3458,7 +3458,7 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
  /*
   * If the cpuset being removed has its flag 'sched_load_balance'
   * enabled, then simulate turning sched_load_balance off, which
- * will call rebuild_sched_domains_locked(). That is not needed
+ * will call cpuset_rebuild_sched_domains_locked(). That is not needed
   * in the default hierarchy where only changes in partition
   * will cause repartitioning.
   *
@@ -3478,7 +3478,7 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
 
  	if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
  	    is_sched_load_balance(cs))
-		update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
+		cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
 
  	cpuset_dec();
  	clear_bit(CS_ONLINE, &cs->flags);
@@ -3645,7 +3645,7 @@ int __init cpuset_init(void)
  	cpumask_setall(top_cpuset.exclusive_cpus);
  	nodes_setall(top_cpuset.effective_mems);
 
-	fmeter_init(&top_cpuset.fmeter);
+	cpuset1_fmeter_init(&top_cpuset.fmeter);
  	INIT_LIST_HEAD(&remote_children);
 
  	BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL));
@@ -3670,9 +3670,9 @@ hotplug_update_tasks(struct cpuset *cs,
  	spin_unlock_irq(&callback_lock);
 
  	if (cpus_updated)
-		update_tasks_cpumask(cs, new_cpus);
+		cpuset_update_tasks_cpumask(cs, new_cpus);
  	if (mems_updated)
-		update_tasks_nodemask(cs);
+		cpuset_update_tasks_nodemask(cs);
  }
 
  void cpuset_force_rebuild(void)
@@ -3773,7 +3773,7 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp)
  		hotplug_update_tasks(cs, &new_cpus, &new_mems,
  				     cpus_updated, mems_updated);
  	else
-		hotplug_update_tasks_legacy(cs, &new_cpus, &new_mems,
+		cpuset1_hotplug_update_tasks(cs, &new_cpus, &new_mems,
  					    cpus_updated, mems_updated);
 
  unlock:
@@ -3858,7 +3858,7 @@ static void cpuset_handle_hotplug(void)
  			top_cpuset.mems_allowed = new_mems;
  		top_cpuset.effective_mems = new_mems;
  		spin_unlock_irq(&callback_lock);
-		update_tasks_nodemask(&top_cpuset);
+		cpuset_update_tasks_nodemask(&top_cpuset);
  	}
 
  	mutex_unlock(&cpuset_mutex);
#12 lore raw

Re: [PATCH v3 -next 10/12] cgroup/cpuset: rename functions shared between v1 and v2

Quoted 51 lines · Waiman Long
Quoted 17 lines · Chen Ridong

Some functions name declared in cpuset-internel.h are generic. To avoid confilicting with other variables for the same name, rename these functions with cpuset_/cpuset1_ prefix to make them unique to cpuset.

---
  kernel/cgroup/cpuset-internal.h | 22 +++++----- kernel/cgroup/cpuset-v1.c       | 44 ++++++++++---------- kernel/cgroup/cpuset.c          | 72 ++++++++++++++++-----------------

  3 files changed, 69 insertions(+), 69 deletions(-)
kernel/cgroup/cpuset-internal.h +0 -0
index a6c71c86e58d..683fcf8bc743 100644
@@ -266,12 +266,12 @@ static inline int is_spread_slab(const struct 
 cpuset *cs)

kernel/cgroup/cpuset-internal.h static inline int is_spread_slab(const struct · line 270

Quoted 10 lines
kernel/cgroup/cpuset-internal.h +1 -6
       css_for_each_descendant_pre((pos_css), &(root_cs)->css)        \
           if (is_cpuset_online(((des_cs) = css_cs((pos_css)))))
-void rebuild_sched_domains_locked(void);
-void callback_lock_irq(void);
-void callback_unlock_irq(void);
-void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus);
-void update_tasks_nodemask(struct cpuset *cs);
-int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int 
 turning_on);
+void cpuset_rebuild_sched_domains_locked(void);

There is already a "rebuild_sched_domain()" function that is externally visible and the name is pretty unique. I don't think we need to add the "cpuset_" prefix for consistency.

Quoted 11 lines
kernel/cgroup/cpuset-internal.h +5 -0
+void cpuset_callback_lock_irq(void);
+void cpuset_callback_unlock_irq(void);
+void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask 
 *new_cpus);
+void cpuset_update_tasks_nodemask(struct cpuset *cs);
+int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int 
 turning_on);

  ssize_t cpuset_write_resmask(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); int cpuset_common_seq_show(struct seq_file *sf, void *v);

kernel/cgroup/cpuset-internal.h int cpuset_common_seq_show(struct seq_file *sf, · line 284

Quoted 7 lines
kernel/cgroup/cpuset-internal.h +1 -2
@@ -280,13 +280,13 @@ int cpuset_common_seq_show(struct seq_file *sf, 
 void *v);
    * cpuset-v1.c
    */
   extern struct cftype legacy_files[];
-void fmeter_init(struct fmeter *fmp);
-void cpuset_update_task_spread_flags(struct cpuset *cs,
+void cpuset1_fmeter_init(struct fmeter *fmp);

Similarly, there are other fmeter_* functions available and fmeter is a unique prefix. The cpuset_ prefix shouldn't be needed.

Quoted 7 lines

OTOH, the legacy_files should be changed to cpuset1_files.

Other than that, the rest of the series looks good to me.

Cheers,
Longman

Thank you, I will update later.

Best regards,
Ridong

Quoted 455 lines
Quoted 454 lines
kernel/cgroup/cpuset-internal.h +4 -3
+void cpuset1_update_task_spread_flags(struct cpuset *cs,
                       struct task_struct *tsk);
-void update_tasks_flags(struct cpuset *cs);
-void hotplug_update_tasks_legacy(struct cpuset *cs,
+void cpuset1_update_tasks_flags(struct cpuset *cs);
+void cpuset1_hotplug_update_tasks(struct cpuset *cs,
                   struct cpumask *new_cpus, nodemask_t *new_mems,
                   bool cpus_updated, bool mems_updated);
-int validate_change_legacy(struct cpuset *cur, struct cpuset *trial);
+int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
   #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c +2 -2
index 0ccc440c468a..ab10852b4a76 100644
@@ -15,7 +15,7 @@ struct cpuset_remove_tasks_struct {
    *
    * These routines manage a digitally filtered, constant time based,
    * event frequency meter.  There are four routines:
- *   fmeter_init() - initialize a frequency meter.
+ *   cpuset1_fmeter_init() - initialize a frequency meter.
    *   fmeter_markevent() - called each time the event happens.
    *   fmeter_getrate() - returns the recent rate of such events.
    *   fmeter_update() - internal routine used to update fmeter.
@@ -61,7 +61,7 @@ struct cpuset_remove_tasks_struct {
   #define FM_SCALE 1000        /* faux fixed point scale */
   /* Initialize a frequency meter */
-void fmeter_init(struct fmeter *fmp)
+void cpuset1_fmeter_init(struct fmeter *fmp)
   {
       fmp->cnt = 0;
       fmp->val = 0;
@@ -155,7 +155,7 @@ static int update_relax_domain_level(struct cpuset 
 *cs, s64 val)
           cs->relax_domain_level = val;

          if (!cpumask_empty(cs->cpus_allowed) && is_sched_load_balance(cs))
-            rebuild_sched_domains_locked(); +            cpuset_rebuild_sched_domains_locked(); }
      return 0;

kernel/cgroup/cpuset-v1.c +1 -1
@@ -209,7 +209,7 @@ static s64 cpuset_read_s64(struct 
 cgroup_subsys_state *css, struct cftype *cft)
    * Call with callback_lock or cpuset_mutex held. The check can be skipped
    * if on default hierarchy.
    */
-void cpuset_update_task_spread_flags(struct cpuset *cs,
+void cpuset1_update_task_spread_flags(struct cpuset *cs,
                       struct task_struct *tsk)
   {

      if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys))

kernel/cgroup/cpuset-v1.c +1 -1
@@ -227,21 +227,21 @@ void cpuset_update_task_spread_flags(struct 
 cpuset *cs,
   }
   /**
- * update_tasks_flags - update the spread flags of tasks in the cpuset.
+ * cpuset1_update_tasks_flags - update the spread flags of tasks in 

the cpuset.
   * @cs: the cpuset in which each task's spread flags needs to be changed *
   * Iterate through each task of @cs updating its spread flags.  As this
   * function is called with cpuset_mutex held, cpuset membership stays
   * stable.
   */

kernel/cgroup/cpuset-v1.c +1 -1
-void update_tasks_flags(struct cpuset *cs)
+void cpuset1_update_tasks_flags(struct cpuset *cs)

  {
      struct css_task_iter it;
      struct task_struct *task; css_task_iter_start(&cs->css, 0, &it); while ((task = css_task_iter_next(&it))) -        cpuset_update_task_spread_flags(cs, task); +        cpuset1_update_task_spread_flags(cs, task); css_task_iter_end(&it);
  }

kernel/cgroup/cpuset-v1.c +6 -6
@@ -282,27 +282,27 @@ static void cpuset_migrate_tasks_workfn(struct 
 work_struct *work)
       kfree(s);
   }
-void hotplug_update_tasks_legacy(struct cpuset *cs,
+void cpuset1_hotplug_update_tasks(struct cpuset *cs,
                   struct cpumask *new_cpus, nodemask_t *new_mems,
                   bool cpus_updated, bool mems_updated)
   {
       bool is_empty;
-    callback_lock_irq();
+    cpuset_callback_lock_irq();
       cpumask_copy(cs->cpus_allowed, new_cpus);
       cpumask_copy(cs->effective_cpus, new_cpus);
       cs->mems_allowed = *new_mems;
       cs->effective_mems = *new_mems;
-    callback_unlock_irq();
+    cpuset_callback_unlock_irq();
       /*
-     * Don't call update_tasks_cpumask() if the cpuset becomes empty,
+     * Don't call cpuset_update_tasks_cpumask() if the cpuset becomes 
 empty,
        * as the tasks will be migrated to an ancestor.
        */
       if (cpus_updated && !cpumask_empty(cs->cpus_allowed))
-        update_tasks_cpumask(cs, new_cpus);
+        cpuset_update_tasks_cpumask(cs, new_cpus);
       if (mems_updated && !nodes_empty(cs->mems_allowed))
-        update_tasks_nodemask(cs);
+        cpuset_update_tasks_nodemask(cs);

      is_empty = cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed);

kernel/cgroup/cpuset-v1.c +2 -2
@@ -345,10 +345,10 @@ static int is_cpuset_subset(const struct cpuset 
 *p, const struct cpuset *q)
   }
   /*
- * validate_change_legacy() - Validate conditions specific to legacy 
 (v1)
+ * cpuset1_validate_change() - Validate conditions specific to legacy 
 (v1)
    *                            behavior.
    */
-int validate_change_legacy(struct cpuset *cur, struct cpuset *trial)
+int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial)
   {

      struct cgroup_subsys_state *css;
      struct cpuset *c, *par;

kernel/cgroup/cpuset-v1.c +0 -0
@@ -421,28 +421,28 @@ static int cpuset_write_u64(struct 
 cgroup_subsys_state *css, struct cftype *cft,
       switch (type) {

      case FILE_CPU_EXCLUSIVE:
-        retval = update_flag(CS_CPU_EXCLUSIVE, cs, val); +        retval = cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, val); break;
      case FILE_MEM_EXCLUSIVE:
-        retval = update_flag(CS_MEM_EXCLUSIVE, cs, val); +        retval = cpuset_update_flag(CS_MEM_EXCLUSIVE, cs, val); break;
      case FILE_MEM_HARDWALL:
-        retval = update_flag(CS_MEM_HARDWALL, cs, val);
+        retval = cpuset_update_flag(CS_MEM_HARDWALL, cs, val); break;
      case FILE_SCHED_LOAD_BALANCE:
-        retval = update_flag(CS_SCHED_LOAD_BALANCE, cs, val); +        retval = cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, val); break;
      case FILE_MEMORY_MIGRATE:
-        retval = update_flag(CS_MEMORY_MIGRATE, cs, val); +        retval = cpuset_update_flag(CS_MEMORY_MIGRATE, cs, val); break;
      case FILE_MEMORY_PRESSURE_ENABLED:
          cpuset_memory_pressure_enabled = !!val;
          break;
      case FILE_SPREAD_PAGE:
-        retval = update_flag(CS_SPREAD_PAGE, cs, val);
+        retval = cpuset_update_flag(CS_SPREAD_PAGE, cs, val); break;
      case FILE_SPREAD_SLAB:
-        retval = update_flag(CS_SPREAD_SLAB, cs, val);
+        retval = cpuset_update_flag(CS_SPREAD_SLAB, cs, val); break;
      default:
          retval = -EINVAL;

kernel/cgroup/cpuset.c +4 -4
index 2f52fe488f3a..f215311eab62 100644
@@ -233,12 +233,12 @@ void cpuset_unlock(void)
   static DEFINE_SPINLOCK(callback_lock);
-void callback_lock_irq(void)
+void cpuset_callback_lock_irq(void)
   {
       spin_lock_irq(&callback_lock);
   }
-void callback_unlock_irq(void)
+void cpuset_callback_unlock_irq(void)
   {
       spin_unlock_irq(&callback_lock);
   }
@@ -534,7 +534,7 @@ static int validate_change(struct cpuset *cur, 
 struct cpuset *trial)
       rcu_read_lock();
       if (!is_in_v2_mode())
-        ret = validate_change_legacy(cur, trial);
+        ret = cpuset1_validate_change(cur, trial);
       if (ret)
           goto out;
@@ -975,7 +975,7 @@ partition_and_rebuild_sched_domains(int ndoms_new, 
 cpumask_var_t doms_new[],
    *
    * Call with cpuset_mutex held.  Takes cpus_read_lock().
    */
-void rebuild_sched_domains_locked(void)
+void cpuset_rebuild_sched_domains_locked(void)
   {
       struct cgroup_subsys_state *pos_css;

      struct sched_domain_attr *attr;

kernel/cgroup/cpuset.c +3 -3
@@ -1027,7 +1027,7 @@ void rebuild_sched_domains_locked(void)
       partition_and_rebuild_sched_domains(ndoms, doms, attr);
   }
   #else /* !CONFIG_SMP */
-void rebuild_sched_domains_locked(void)
+void cpuset_rebuild_sched_domains_locked(void)
   {
   }
   #endif /* CONFIG_SMP */
@@ -1035,7 +1035,7 @@ void rebuild_sched_domains_locked(void)
   static void rebuild_sched_domains_cpuslocked(void)
   {
       mutex_lock(&cpuset_mutex);
-    rebuild_sched_domains_locked();
+    cpuset_rebuild_sched_domains_locked();
       mutex_unlock(&cpuset_mutex);
   }
@@ -1047,7 +1047,7 @@ void rebuild_sched_domains(void)
   }
   /**
- * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
+ * cpuset_update_tasks_cpumask - Update the cpumasks of tasks in the 

cpuset.
   * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
   * @new_cpus: the temp variable for the new effective_cpus mask *

kernel/cgroup/cpuset.c +1 -1
@@ -1057,7 +1057,7 @@ void rebuild_sched_domains(void)
    * is used instead of effective_cpus to make sure all offline CPUs are also
    * included as hotplug code won't update cpumasks for tasks in top_cpuset.
    */
-void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus)
+void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask 
 *new_cpus)
   {
       struct css_task_iter it;

      struct task_struct *task;

kernel/cgroup/cpuset.c +3 -3
@@ -1120,11 +1120,11 @@ static int update_partition_exclusive(struct 
 cpuset *cs, int new_prs)
       bool exclusive = (new_prs > PRS_MEMBER);
       if (exclusive && !is_cpu_exclusive(cs)) {
-        if (update_flag(CS_CPU_EXCLUSIVE, cs, 1))
+        if (cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, 1))
               return PERR_NOTEXCL;
       } else if (!exclusive && is_cpu_exclusive(cs)) {
           /* Turning off CS_CPU_EXCLUSIVE will not return error */
-        update_flag(CS_CPU_EXCLUSIVE, cs, 0);
+        cpuset_update_flag(CS_CPU_EXCLUSIVE, cs, 0);
       }
       return 0;
   }
@@ -1133,7 +1133,7 @@ static int update_partition_exclusive(struct 
 cpuset *cs, int new_prs)
    * Update partition load balance flag and/or rebuild sched domain
    *
    * Changing load balance flag will automatically call
- * rebuild_sched_domains_locked().
+ * cpuset_rebuild_sched_domains_locked().
    * This function is for cgroup v2 only.
    */

  static void update_partition_sd_lb(struct cpuset *cs, int old_prs)

kernel/cgroup/cpuset.c +2 -2
@@ -1160,7 +1160,7 @@ static void update_partition_sd_lb(struct cpuset 
 *cs, int old_prs)
       }
       if (rebuild_domains && !force_sd_rebuild)
-        rebuild_sched_domains_locked();
+        cpuset_rebuild_sched_domains_locked();
   }
   /*
@@ -1374,7 +1374,7 @@ static int remote_partition_enable(struct cpuset 
 *cs, int new_prs,
       /*
        * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
        */
-    update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+    cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
       update_sibling_cpumasks(&top_cpuset, NULL, tmp);
       return 0;

  }

kernel/cgroup/cpuset.c +5 -5
@@ -1410,7 +1410,7 @@ static void remote_partition_disable(struct 
 cpuset *cs, struct tmpmasks *tmp)
       /*
        * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
        */
-    update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+    cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
       update_sibling_cpumasks(&top_cpuset, NULL, tmp);
   }
@@ -1462,7 +1462,7 @@ static void remote_cpus_update(struct cpuset 
 *cs, struct cpumask *newmask,
       /*
        * Proprogate changes in top_cpuset's effective_cpus down the hierarchy.
        */
-    update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
+    cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
       update_sibling_cpumasks(&top_cpuset, NULL, tmp);
       return;
@@ -1508,7 +1508,7 @@ static void remote_partition_check(struct cpuset 
 *cs, struct cpumask *newmask,
               disable_cnt++;
           }
       if (disable_cnt && !force_sd_rebuild)
-        rebuild_sched_domains_locked();
+        cpuset_rebuild_sched_domains_locked();
   }
   /*
@@ -1834,7 +1834,7 @@ static int 
 update_parent_effective_cpumask(struct cpuset *cs, int cmd,
           update_partition_exclusive(cs, new_prs);
       if (adding || deleting) {
-        update_tasks_cpumask(parent, tmp->addmask);
+        cpuset_update_tasks_cpumask(parent, tmp->addmask);
           update_sibling_cpumasks(parent, cs, tmp);
       }
@@ -2017,7 +2017,7 @@ static void update_cpumasks_hier(struct cpuset 
 *cs, struct tmpmasks *tmp,
           /*
            * update_parent_effective_cpumask() should have been called
            * for cs already in update_cpumask(). We should also call
-         * update_tasks_cpumask() again for tasks in the parent
+         * cpuset_update_tasks_cpumask() again for tasks in the parent
            * cpuset if the parent's effective_cpus changes.
            */

          if ((cp != cs) && old_prs) {

kernel/cgroup/cpuset.c +0 -0
@@ -2074,7 +2074,7 @@ static void update_cpumasks_hier(struct cpuset 
 *cs, struct tmpmasks *tmp,

          WARN_ON(!is_in_v2_mode() && !cpumask_equal(cp->cpus_allowed, cp->effective_cpus)); -        update_tasks_cpumask(cp, cp->effective_cpus);
+        cpuset_update_tasks_cpumask(cp, cp->effective_cpus); /*
           * On default hierarchy, inherit the CS_SCHED_LOAD_BALANCE

kernel/cgroup/cpuset.c +0 -0
@@ -2109,7 +2109,7 @@ static void update_cpumasks_hier(struct cpuset 
 *cs, struct tmpmasks *tmp,

      if (need_rebuild_sched_domains && !(flags & HIER_NO_SD_REBUILD) && !force_sd_rebuild)
-        rebuild_sched_domains_locked();
+        cpuset_rebuild_sched_domains_locked();
  }
  /**

kernel/cgroup/cpuset.c +1 -1
@@ -2501,14 +2501,14 @@ static void cpuset_change_task_nodemask(struct 
 task_struct *tsk,
   static void *cpuset_being_rebound;
   /**
- * update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
+ * cpuset_update_tasks_nodemask - Update the nodemasks of tasks in 

the cpuset.
   * @cs: the cpuset in which each task's mems_allowed mask needs to be changed *
   * Iterate through each task of @cs updating its mems_allowed to the
   * effective cpuset's.  As this function is called with cpuset_mutex held,
   * cpuset membership stays stable.
   */

kernel/cgroup/cpuset.c +1 -1
-void update_tasks_nodemask(struct cpuset *cs)
+void cpuset_update_tasks_nodemask(struct cpuset *cs)

  {
      static nodemask_t newmems;    /* protected by cpuset_mutex */ struct css_task_iter it;

kernel/cgroup/cpuset.c +0 -0
@@ -2606,7 +2606,7 @@ static void update_nodemasks_hier(struct cpuset 
 *cs, nodemask_t *new_mems)

          WARN_ON(!is_in_v2_mode() && !nodes_equal(cp->mems_allowed, cp->effective_mems)); -        update_tasks_nodemask(cp);
+        cpuset_update_tasks_nodemask(cp); rcu_read_lock();
          css_put(&cp->css);

kernel/cgroup/cpuset.c +1 -1
@@ -2693,7 +2693,7 @@ bool current_cpuset_is_being_rebound(void)
   }
   /*
- * update_flag - read a 0 or a 1 in a file and update associated flag
+ * cpuset_update_flag - read a 0 or a 1 in a file and update 

associated flag
   * bit:        the bit to update (see cpuset_flagbits_t)
   * cs:        the cpuset to update
   * turning_on:     whether the flag is being set or cleared

kernel/cgroup/cpuset.c +1 -1
@@ -2701,7 +2701,7 @@ bool current_cpuset_is_being_rebound(void)
    * Call with cpuset_mutex held.
    */
-int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
+int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
                  int turning_on)
   {
       struct cpuset *trialcs;
@@ -2734,10 +2734,10 @@ int update_flag(cpuset_flagbits_t bit, struct 
 cpuset *cs,

      if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed && !force_sd_rebuild)
-        rebuild_sched_domains_locked();
+        cpuset_rebuild_sched_domains_locked();
      if (spread_flag_changed)
-        update_tasks_flags(cs);
+        cpuset1_update_tasks_flags(cs);
  out:
      free_cpuset(trialcs);
      return err;

kernel/cgroup/cpuset.c +3 -3
@@ -3002,7 +3002,7 @@ static void cpuset_attach_task(struct cpuset 
 *cs, struct task_struct *task)
       WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach));
       cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
-    cpuset_update_task_spread_flags(cs, task);
+    cpuset1_update_task_spread_flags(cs, task);
   }
   static void cpuset_attach(struct cgroup_taskset *tset)
@@ -3373,7 +3373,7 @@ cpuset_css_alloc(struct cgroup_subsys_state 
 *parent_css)
       }
       __set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
-    fmeter_init(&cs->fmeter);
+    cpuset1_fmeter_init(&cs->fmeter);
       cs->relax_domain_level = -1;
       INIT_LIST_HEAD(&cs->remote_sibling);
@@ -3458,7 +3458,7 @@ static int cpuset_css_online(struct 
 cgroup_subsys_state *css)
   /*
    * If the cpuset being removed has its flag 'sched_load_balance'
    * enabled, then simulate turning sched_load_balance off, which
- * will call rebuild_sched_domains_locked(). That is not needed
+ * will call cpuset_rebuild_sched_domains_locked(). That is not needed
    * in the default hierarchy where only changes in partition
    * will cause repartitioning.

   *

kernel/cgroup/cpuset.c +0 -0
@@ -3478,7 +3478,7 @@ static void cpuset_css_offline(struct 
 cgroup_subsys_state *css)

      if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) && is_sched_load_balance(cs))
-        update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); +        cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); cpuset_dec();
      clear_bit(CS_ONLINE, &cs->flags);

kernel/cgroup/cpuset.c +3 -3
@@ -3645,7 +3645,7 @@ int __init cpuset_init(void)
       cpumask_setall(top_cpuset.exclusive_cpus);
       nodes_setall(top_cpuset.effective_mems);
-    fmeter_init(&top_cpuset.fmeter);
+    cpuset1_fmeter_init(&top_cpuset.fmeter);
       INIT_LIST_HEAD(&remote_children);
       BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL));
@@ -3670,9 +3670,9 @@ hotplug_update_tasks(struct cpuset *cs,
       spin_unlock_irq(&callback_lock);
       if (cpus_updated)
-        update_tasks_cpumask(cs, new_cpus);
+        cpuset_update_tasks_cpumask(cs, new_cpus);
       if (mems_updated)
-        update_tasks_nodemask(cs);
+        cpuset_update_tasks_nodemask(cs);
   }
   void cpuset_force_rebuild(void)
@@ -3773,7 +3773,7 @@ static void cpuset_hotplug_update_tasks(struct 
 cpuset *cs, struct tmpmasks *tmp)
           hotplug_update_tasks(cs, &new_cpus, &new_mems,
                        cpus_updated, mems_updated);

      else
-        hotplug_update_tasks_legacy(cs, &new_cpus, &new_mems, +        cpuset1_hotplug_update_tasks(cs, &new_cpus, &new_mems, cpus_updated, mems_updated); unlock:

kernel/cgroup/cpuset.c +1 -1
@@ -3858,7 +3858,7 @@ static void cpuset_handle_hotplug(void)
               top_cpuset.mems_allowed = new_mems;
           top_cpuset.effective_mems = new_mems;
           spin_unlock_irq(&callback_lock);
-        update_tasks_nodemask(&top_cpuset);
+        cpuset_update_tasks_nodemask(&top_cpuset);
       }
       mutex_unlock(&cpuset_mutex);
#13 lore raw

PATCH v3 11/12 cgroup/cpuset: guard cpuset-v1 code under CONFIG_CPUSETS_V1

In reply to Chen Ridong

This patch introduces CONFIG_CPUSETS_V1 and guard cpuset-v1 code under CONFIG_CPUSETS_V1. The default value of CONFIG_CPUSETS_V1 is N, so that user who adopted v2 don't have 'pay' for cpuset v1.

---
 include/linux/cpuset.h          |  4 ++++
 init/Kconfig                    | 13 +++++++++++++
 kernel/cgroup/Makefile          |  3 ++-
 kernel/cgroup/cpuset-internal.h | 12 ++++++++++++
 kernel/cgroup/cpuset.c          |  2 ++
 5 files changed, 33 insertions(+), 1 deletion(-)
include/linux/cpuset.h +4 -0
index 2a6981eeebf8..835e7b793f6a 100644
@@ -99,6 +99,7 @@ static inline bool cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
 extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
 					  const struct task_struct *tsk2);
 
+#ifdef CONFIG_CPUSETS_V1
 #define cpuset_memory_pressure_bump() 				\
 	do {							\
 		if (cpuset_memory_pressure_enabled)		\
@@ -106,6 +107,9 @@ extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
 	} while (0)
 extern int cpuset_memory_pressure_enabled;
 extern void __cpuset_memory_pressure_bump(void);
+#else
+static inline void cpuset_memory_pressure_bump(void) { }
+#endif
 
 extern void cpuset_task_status_allowed(struct seq_file *m,
 					struct task_struct *task);
init/Kconfig +13 -0
index a465ea9525bd..8bf091354bea 100644
@@ -1143,6 +1143,19 @@ config CPUSETS
 
 	  Say N if unsure.
 
+config CPUSETS_V1
+	bool "Legacy cgroup v1 cpusets controller"
+	depends on CPUSETS
+	default n
+	help
+	  Legacy cgroup v1 cpusets controller which has been deprecated by
+	  cgroup v2 implementation. The v1 is there for legacy applications
+	  which haven't migrated to the new cgroup v2 interface yet. If you
+	  do not have any such application then you are completely fine leaving
+	  this option disabled.
+
+	  Say N if unsure.
+
 config PROC_PID_CPUSET
 	bool "Include legacy /proc/<pid>/cpuset file"
 	depends on CPUSETS
kernel/cgroup/Makefile +2 -1
index 005ac4c675cb..a5c9359d516f 100644
@@ -4,6 +4,7 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o freezer.o
 obj-$(CONFIG_CGROUP_FREEZER) += legacy_freezer.o
 obj-$(CONFIG_CGROUP_PIDS) += pids.o
 obj-$(CONFIG_CGROUP_RDMA) += rdma.o
-obj-$(CONFIG_CPUSETS) += cpuset.o cpuset-v1.o
+obj-$(CONFIG_CPUSETS) += cpuset.o
+obj-$(CONFIG_CPUSETS_V1) += cpuset-v1.o
 obj-$(CONFIG_CGROUP_MISC) += misc.o
 obj-$(CONFIG_CGROUP_DEBUG) += debug.o
kernel/cgroup/cpuset-internal.h +12 -0
index 683fcf8bc743..0474eeb13c34 100644
@@ -279,6 +279,7 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v);
 /*
  * cpuset-v1.c
  */
+#ifdef CONFIG_CPUSETS_V1
 extern struct cftype legacy_files[];
 void cpuset1_fmeter_init(struct fmeter *fmp);
 void cpuset1_update_task_spread_flags(struct cpuset *cs,
@@ -288,5 +289,16 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs,
 			    struct cpumask *new_cpus, nodemask_t *new_mems,
 			    bool cpus_updated, bool mems_updated);
 int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
+#else
+static inline void cpuset1_fmeter_init(struct fmeter *fmp) {}
+static inline void cpuset1_update_task_spread_flags(struct cpuset *cs,
+					struct task_struct *tsk) {}
+static inline void cpuset1_update_tasks_flags(struct cpuset *cs) {}
+static inline void cpuset1_hotplug_update_tasks(struct cpuset *cs,
+			    struct cpumask *new_cpus, nodemask_t *new_mems,
+			    bool cpus_updated, bool mems_updated) {}
+static inline int cpuset1_validate_change(struct cpuset *cur,
+				struct cpuset *trial) { return 0; }
+#endif /* CONFIG_CPUSETS_V1 */
 
 #endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset.c +2 -0
index f215311eab62..7f82b8ed8fb3 100644
@@ -3617,7 +3617,9 @@ struct cgroup_subsys cpuset_cgrp_subsys = {
 	.can_fork	= cpuset_can_fork,
 	.cancel_fork	= cpuset_cancel_fork,
 	.fork		= cpuset_fork,
+#ifdef CONFIG_CPUSETS_V1
 	.legacy_cftypes	= legacy_files,
+#endif
 	.dfl_cftypes	= dfl_files,
 	.early_init	= true,
 	.threaded	= true,
Signature · 1 line
2.34.1
#14 lore raw

PATCH v3 12/12 cgroup/cpuset: add sefltest for cpuset v1

In reply to Chen Ridong

There is only hotplug test for cpuset v1, just add base read/write test for cpuset v1.

---
 MAINTAINERS                                   |  1 +
 .../selftests/cgroup/test_cpuset_v1_base.sh   | 77 +++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100755 tools/testing/selftests/cgroup/test_cpuset_v1_base.sh
MAINTAINERS +1 -0
index 3b5ec1cafd95..b59f54e1e30d 100644
@@ -5703,6 +5703,7 @@ F:	kernel/cgroup/cpuset-v1.c
 F:	kernel/cgroup/cpuset.c
 F:	tools/testing/selftests/cgroup/test_cpuset.c
 F:	tools/testing/selftests/cgroup/test_cpuset_prs.sh
+F:	tools/testing/selftests/cgroup/test_cpuset_v1_base.sh
 
 CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
 M:	Johannes Weiner <[email protected]>
tools/testing/selftests/cgroup/test_cpuset_v1_base.sh new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.34.1