Skip to contentSkip to conversation

cpusets,isolcpus: resolve conflict between cpusets and isolcpus

PATCH Superseded [email protected] 6 participants 28 messages Feb 25, 2015 – Mar 3, 2015

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover cpusets,isolcpus: resolve conflict between cpusets and isolcpus

-v2 addresses the conflict David Rientjes spotted between my previous patches and commit e8e6d97c9b ("cpuset: use %*pb[l] to print bitmaps including cpumasks and nodemasks")

Ensure that cpus specified with the isolcpus= boot commandline option stay outside of the load balancing in the kernel scheduler.

Operations like load balancing can introduce unwanted latencies, which is exactly what the isolcpus= commandline is there to prevent.

Previously, simply creating a new cpuset, without even touching the cpuset.cpus field inside the new cpuset, would undo the effects of isolcpus=, by creating a scheduler domain spanning the whole system, and setting up load balancing inside that domain. The cpuset root cpuset.cpus file is read-only, so there was not even a way to undo that effect.

This does not impact the majority of cpusets users, since isolcpus= is a fairly specialized feature used for realtime purposes.

#1 lore raw

PATCH 1/2 cpusets,isolcpus: exclude isolcpus from load balancing in cpusets

From: Rik van Riel <[email protected]>

Ensure that cpus specified with the isolcpus= boot commandline option stay outside of the load balancing in the kernel scheduler.

Operations like load balancing can introduce unwanted latencies, which is exactly what the isolcpus= commandline is there to prevent.

Previously, simply creating a new cpuset, without even touching the cpuset.cpus field inside the new cpuset, would undo the effects of isolcpus=, by creating a scheduler domain spanning the whole system, and setting up load balancing inside that domain. The cpuset root cpuset.cpus file is read-only, so there was not even a way to undo that effect.

This does not impact the majority of cpusets users, since isolcpus= is a fairly specialized feature used for realtime purposes.

Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc Mike Galbraith <[email protected]>
---
 include/linux/sched.h |  2 ++
 kernel/cpuset.c       | 13 +++++++++++--
 kernel/sched/core.c   |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)
include/linux/sched.h +2 -0
index 6d77432e14ff..aeae02435717 100644
@@ -1038,6 +1038,8 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
 extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
 				    struct sched_domain_attr *dattr_new);
 
+extern cpumask_var_t cpu_isolated_map;
+
 /* Allocate an array of sched domains, for partition_sched_domains(). */
 cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
 void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
kernel/cpuset.c +11 -2
index 1d1fe9361d29..b544e5229d99 100644
@@ -625,6 +625,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
 	int csn;		/* how many cpuset ptrs in csa so far */
 	int i, j, k;		/* indices for partition finding loops */
 	cpumask_var_t *doms;	/* resulting partition; i.e. sched domains */
+	cpumask_var_t non_isolated_cpus;  /* load balanced CPUs */
 	struct sched_domain_attr *dattr;  /* attributes for custom domains */
 	int ndoms = 0;		/* number of sched domains in result */
 	int nslot;		/* next empty doms[] struct cpumask slot */
@@ -634,6 +635,10 @@ static int generate_sched_domains(cpumask_var_t **domains,
 	dattr = NULL;
 	csa = NULL;
 
+	if (!alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL))
+		goto done;
+	cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map);
+
 	/* Special case for the 99% of systems with one, full, sched domain */
 	if (is_sched_load_balance(&top_cpuset)) {
 		ndoms = 1;
@@ -646,7 +651,8 @@ static int generate_sched_domains(cpumask_var_t **domains,
 			*dattr = SD_ATTR_INIT;
 			update_domain_attr_tree(dattr, &top_cpuset);
 		}
-		cpumask_copy(doms[0], top_cpuset.effective_cpus);
+		cpumask_and(doms[0], top_cpuset.effective_cpus,
+				     non_isolated_cpus);
 
 		goto done;
 	}
@@ -669,7 +675,8 @@ static int generate_sched_domains(cpumask_var_t **domains,
 		 * the corresponding sched domain.
 		 */
 		if (!cpumask_empty(cp->cpus_allowed) &&
-		    !is_sched_load_balance(cp))
+		    !(is_sched_load_balance(cp) &&
+		      cpumask_intersects(cp->cpus_allowed, non_isolated_cpus)))
 			continue;
 
 		if (is_sched_load_balance(cp))
@@ -751,6 +758,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
 
 			if (apn == b->pn) {
 				cpumask_or(dp, dp, b->effective_cpus);
+				cpumask_and(dp, dp, non_isolated_cpus);
 				if (dattr)
 					update_domain_attr_tree(dattr + nslot, b);
 
@@ -763,6 +771,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
 	BUG_ON(nslot != ndoms);
 
 done:
+	free_cpumask_var(non_isolated_cpus);
 	kfree(csa);
 
 	/*
kernel/sched/core.c +1 -1
index f0f831e8a345..3db1beace19b 100644
@@ -5812,7 +5812,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
 }
 
 /* cpus with isolated domains */
-static cpumask_var_t cpu_isolated_map;
+cpumask_var_t cpu_isolated_map;
 
 /* Setup the mask of cpus configured for isolated domains */
 static int __init isolated_cpu_setup(char *str)
Signature · 1 line
2.1.0
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] cpusets,isolcpus: exclude isolcpus from load balancing in cpusets

Quoted 18 lines · On Wed, Feb 25, 2015 at 11:38:07AM -0500…

From: Rik van Riel <[email protected]>

Ensure that cpus specified with the isolcpus= boot commandline option stay outside of the load balancing in the kernel scheduler.

Operations like load balancing can introduce unwanted latencies, which is exactly what the isolcpus= commandline is there to prevent.

Previously, simply creating a new cpuset, without even touching the cpuset.cpus field inside the new cpuset, would undo the effects of isolcpus=, by creating a scheduler domain spanning the whole system, and setting up load balancing inside that domain. The cpuset root cpuset.cpus file is read-only, so there was not even a way to undo that effect.

This does not impact the majority of cpusets users, since isolcpus= is a fairly specialized feature used for realtime purposes.

Quoted 9 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc Mike Galbraith <[email protected]>

Might I asked you to update Documentation/cgroups/cpusets.txt with this knowledge? While it does mentions isolcpus it does not clarify the interaction between it and cpusets.

Other than that,

#3 lore raw

[PATCH 3/2] cpusets,isolcpus: document relationship between cpusets & isolcpus

Document the subtly changed relationship between cpusets and isolcpus. Turns out the old documentation did not quite match the code...

---
 Documentation/cgroups/cpusets.txt | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Documentation/cgroups/cpusets.txt +8 -2
index f2235a162529..fdf7dff3f607 100644
@@ -392,8 +392,10 @@ Put simply, it costs less to balance between two smaller sched domains
 than one big one, but doing so means that overloads in one of the
 two domains won't be load balanced to the other one.
 
-By default, there is one sched domain covering all CPUs, except those
-marked isolated using the kernel boot time "isolcpus=" argument.
+By default, there is one sched domain covering all CPUs, including those
+marked isolated using the kernel boot time "isolcpus=" argument. However,
+the isolated CPUs will not participate in load balancing, and will not
+have tasks running on them unless explicitly assigned.
 
 This default load balancing across all CPUs is not well suited for
 the following two situations:
@@ -465,6 +467,10 @@ such partially load balanced cpusets, as they may be artificially
 constrained to some subset of the CPUs allowed to them, for lack of
 load balancing to the other CPUs.
 
+CPUs in "cpuset.isolcpus" were excluded from load balancing by the
+isolcpus= kernel boot option, and will never be load balanced regardless
+of the value of "cpuset.sched_load_balance" in any cpuset.
+
 1.7.1 sched_load_balance implementation details.
 ------------------------------------------------
 
Acked-by on v1 1/2
#6 lore raw

Re: [PATCH 1/2] cpusets,isolcpus: exclude isolcpus from load balancing in cpusets

In reply to [email protected]
Quoted 18 lines · On 2015/2/26 0:38, [email protected] wrote:

From: Rik van Riel <[email protected]>

Ensure that cpus specified with the isolcpus= boot commandline option stay outside of the load balancing in the kernel scheduler.

Operations like load balancing can introduce unwanted latencies, which is exactly what the isolcpus= commandline is there to prevent.

Previously, simply creating a new cpuset, without even touching the cpuset.cpus field inside the new cpuset, would undo the effects of isolcpus=, by creating a scheduler domain spanning the whole system, and setting up load balancing inside that domain. The cpuset root cpuset.cpus file is read-only, so there was not even a way to undo that effect.

This does not impact the majority of cpusets users, since isolcpus= is a fairly specialized feature used for realtime purposes.

Quoted 9 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc Mike Galbraith <[email protected]>
#7 lore raw

PATCH 2/2 cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to [email protected]

From: Rik van Riel <[email protected]>

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>
---
 kernel/cpuset.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
kernel/cpuset.c +24 -0
index b544e5229d99..94bf59588e23 100644
@@ -1563,6 +1563,7 @@ typedef enum {
 	FILE_MEMORY_PRESSURE,
 	FILE_SPREAD_PAGE,
 	FILE_SPREAD_SLAB,
+	FILE_ISOLCPUS,
 } cpuset_filetype_t;
 
 static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -1704,6 +1705,20 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 	return retval ?: nbytes;
 }
 
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+
+	cpumask_and(my_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", nodemask_pr_args(my_isolated_cpus));
+
+	free_cpumask_var(my_isolated_cpus);
+}
+
 /*
  * These ascii lists should be read in a single call, by using a user
  * buffer large enough to hold the entire map.  If read in smaller
@@ -1733,6 +1748,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1893,6 +1911,12 @@ static struct cftype files[] = {
 		.private = FILE_MEMORY_PRESSURE_ENABLED,
 	},
 
+	{
+		.name = "isolcpus",
+		.seq_show = cpuset_common_seq_show,
+		.private = FILE_ISOLCPUS,
+	},
+
 	{ }	/* terminate */
 };
 
Signature · 1 line
2.1.0
Acked-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 16 lines · On Wed, 25 Feb 2015, [email protected] wrote:
kernel/cpuset.c +1 -0
index b544e5229d99..94bf59588e23 100644
@@ -1563,6 +1563,7 @@ typedef enum {
 	FILE_MEMORY_PRESSURE,
 	FILE_SPREAD_PAGE,
 	FILE_SPREAD_SLAB,
+	FILE_ISOLCPUS,
 } cpuset_filetype_t;
 
 static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -1704,6 +1705,20 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 	return retval ?: nbytes;
 }
 

kernel/cpuset.c static ssize_t cpuset_write_resmask(struct kernfs_open_file *of, · line 1717

Quoted 10 lines
kernel/cpuset.c +10 -0
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+
+	cpumask_and(my_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", nodemask_pr_args(my_isolated_cpus));

That unfortunately won't output anything, it needs to be cpumask_pr_args(). After that's fixed, feel free to add my

Quoted 30 lines
kernel/cpuset.c +13 -0
+
+	free_cpumask_var(my_isolated_cpus);
+}
+
 /*
  * These ascii lists should be read in a single call, by using a user
  * buffer large enough to hold the entire map.  If read in smaller
@@ -1733,6 +1748,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1893,6 +1911,12 @@ static struct cftype files[] = {
 		.private = FILE_MEMORY_PRESSURE_ENABLED,
 	},
 
+	{
+		.name = "isolcpus",
+		.seq_show = cpuset_common_seq_show,
+		.private = FILE_ISOLCPUS,
+	},
+
 	{ }	/* terminate */
 };
 
#9 lore raw

Re: [PATCH 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 32 lines · David Rientjes
Quoted 16 lines · On Wed, 25 Feb 2015, [email protected] wrote:
kernel/cpuset.c +1 -0
index b544e5229d99..94bf59588e23 100644
@@ -1563,6 +1563,7 @@ typedef enum {
 	FILE_MEMORY_PRESSURE,
 	FILE_SPREAD_PAGE,
 	FILE_SPREAD_SLAB,
+	FILE_ISOLCPUS,
 } cpuset_filetype_t;
 
 static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -1704,6 +1705,20 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 	return retval ?: nbytes;
 }
 

kernel/cpuset.c static ssize_t cpuset_write_resmask(struct kernfs_open_file *of, · line 1717

Quoted 10 lines
kernel/cpuset.c +10 -0
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+
+	cpumask_and(my_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", nodemask_pr_args(my_isolated_cpus));

That unfortunately won't output anything, it needs to be cpumask_pr_args(). After that's fixed, feel free to add my

Quoted 1 line

Gah. Too many things going on at once.

Let me resend a v3 of just patch 2/2 with your ack.

#10 lore raw

PATCH v3 2/2 cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to [email protected]

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>

---
OK, I suck. Thanks to David Rientjes for spotting the silly mistake.

 kernel/cpuset.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
kernel/cpuset.c +24 -0
index b544e5229d99..455df101ceec 100644
@@ -1563,6 +1563,7 @@ typedef enum {
 	FILE_MEMORY_PRESSURE,
 	FILE_SPREAD_PAGE,
 	FILE_SPREAD_SLAB,
+	FILE_ISOLCPUS,
 } cpuset_filetype_t;
 
 static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -1704,6 +1705,20 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 	return retval ?: nbytes;
 }
 
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+
+	cpumask_and(my_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", cpumask_pr_args(my_isolated_cpus));
+
+	free_cpumask_var(my_isolated_cpus);
+}
+
 /*
  * These ascii lists should be read in a single call, by using a user
  * buffer large enough to hold the entire map.  If read in smaller
@@ -1733,6 +1748,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1893,6 +1911,12 @@ static struct cftype files[] = {
 		.private = FILE_MEMORY_PRESSURE_ENABLED,
 	},
 
+	{
+		.name = "isolcpus",
+		.seq_show = cpuset_common_seq_show,
+		.private = FILE_ISOLCPUS,
+	},
+
 	{ }	/* terminate */
 };
 
#11 lore raw

Re: [PATCH 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to [email protected]

kernel/cpuset.c static ssize_t cpuset_write_resmask(struct kernfs_open_file *of, · line 1714

Quoted 7 lines
kernel/cpuset.c +7 -0
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+

Make it return -ENOMEM ? Or make it a global variable and allocate memory for it in cpuset_init().

Quoted 34 lines
kernel/cpuset.c +16 -0
+	cpumask_and(my_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", nodemask_pr_args(my_isolated_cpus));
+
+	free_cpumask_var(my_isolated_cpus);
+}
+
 /*
  * These ascii lists should be read in a single call, by using a user
  * buffer large enough to hold the entire map.  If read in smaller
@@ -1733,6 +1748,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1893,6 +1911,12 @@ static struct cftype files[] = {
 		.private = FILE_MEMORY_PRESSURE_ENABLED,
 	},
 
+	{
+		.name = "isolcpus",
+		.seq_show = cpuset_common_seq_show,
+		.private = FILE_ISOLCPUS,
+	},
+
 	{ }	/* terminate */
 };
 
#12 lore raw

Re: [PATCH 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 10 lines · Zefan Li

kernel/cpuset.c static ssize_t cpuset_write_resmask(struct kernfs_open_file *of, · line 1714

Quoted 7 lines
kernel/cpuset.c +7 -0
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_var_t my_isolated_cpus;
+
+	if (!alloc_cpumask_var(&my_isolated_cpus, GFP_KERNEL))
+		return;
+

Make it return -ENOMEM ? Or make it a global variable and allocate memory for it in cpuset_init().

OK, can do.

I see that cpuset_common_seq_show already takes a lock, so having one global variable for this should not introduce any additional contention.

I will send a v4.

Quoted 10 lines
Quoted 10 lines
kernel/cpuset.c +3 -0
@@ -1733,6 +1748,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
Signature · 1 line
All rights reversed
#13 lore raw

PATCH v4 2/2 cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to Zefan Li
Quoted 2 lines · On Thu, 26 Feb 2015 19:05:57 +0800 Zefan Li <[email protected]> wrote:

Make it return -ENOMEM ? Or make it a global variable and allocate memory for it in cpuset_init().

Here you are. This addresses your concern, as well as the issue David Rientjes found earlier.

---8<---

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>
---
 kernel/cpuset.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
kernel/cpuset.c +22 -0
index b544e5229d99..5462e1ca90bd 100644
@@ -1563,6 +1563,7 @@ typedef enum {
 	FILE_MEMORY_PRESSURE,
 	FILE_SPREAD_PAGE,
 	FILE_SPREAD_SLAB,
+	FILE_ISOLCPUS,
 } cpuset_filetype_t;
 
 static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -1704,6 +1705,16 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
 	return retval ?: nbytes;
 }
 
+/* protected by the lock in cpuset_common_seq_show */
+static cpumask_var_t print_isolated_cpus;
+
+static void cpuset_seq_print_isolcpus(struct seq_file *sf, struct cpuset *cs)
+{
+	cpumask_and(print_isolated_cpus, cs->cpus_allowed, cpu_isolated_map);
+
+	seq_printf(sf, "%*pbl\n", cpumask_pr_args(print_isolated_cpus));
+}
+
 /*
  * These ascii lists should be read in a single call, by using a user
  * buffer large enough to hold the entire map.  If read in smaller
@@ -1733,6 +1744,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
 	case FILE_EFFECTIVE_MEMLIST:
 		seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems));
 		break;
+	case FILE_ISOLCPUS:
+		cpuset_seq_print_isolcpus(sf, cs);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1893,6 +1907,12 @@ static struct cftype files[] = {
 		.private = FILE_MEMORY_PRESSURE_ENABLED,
 	},
 
+	{
+		.name = "isolcpus",
+		.seq_show = cpuset_common_seq_show,
+		.private = FILE_ISOLCPUS,
+	},
+
 	{ }	/* terminate */
 };
 
@@ -2070,6 +2090,8 @@ int __init cpuset_init(void)
 		BUG();
 	if (!alloc_cpumask_var(&top_cpuset.effective_cpus, GFP_KERNEL))
 		BUG();
+	if (!alloc_cpumask_var(&print_isolated_cpus, GFP_KERNEL))
+		BUG();
 
 	cpumask_setall(top_cpuset.cpus_allowed);
 	nodes_setall(top_cpuset.mems_allowed);
Acked-by on v4 2/2
#14 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 14 lines

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 10 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>
#15 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to Rik van Riel

Hi Rik,

Quoted 7 lines

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Quoted 7 lines

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

One Question, why not add a /sys/devices/system/cpu/isolated instead?

maintainer
#16 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 12 lines · Zefan Li

Hi Rik,

Quoted 10 lines

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

Quoted 6 lines
Quoted 4 lines

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

One Question, why not add a /sys/devices/system/cpu/isolated instead?

It would leave userspace to calculate the result for any one cpuset itself. Furthermore, is that /sys thing visible for all nested containers?

#17 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 18 lines · Peter Zijlstra
Quoted 17 lines · Zefan Li

Hi Rik,

Quoted 14 lines

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 4 lines
Quoted 1 line

One Question, why not add a /sys/devices/system/cpu/isolated instead?

It would leave userspace to calculate the result for any one cpuset itself.

It's trivial. Instead of reading cpuset.isolcpus, now we read cpuset.cpus and /sys/.../isolated.

Quoted 4 lines

Furthermore, is that /sys thing visible for all nested containers?
.

Never tried nested containers, but I think so.

maintainer
#18 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to Rik van Riel
Quoted 14 lines · Rik van Riel

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 10 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>

So let me start off by saying I hate isolcpus ;-)

Let me further state that I had hopes we could extend cpusets to natively provide the functionality isolcpus has, and kill isolcpus.

The 'normal' way would be to create 2 cgroups with disjoint cpus, disable sched_load_balance on root and one of the siblings, while moving everything into the other group.

The 'problem' is that we cannot move everything that is affected by isolcpus, workqueues have grown a horrible 'new' interface outside of the regular task interfaces and things like kthreadd are non-movable for mostly good reasons.

Furthermore it appears that software like system-disease and libvirt hard assume they're lord and master of the cgroup hierarchy and do not expect things like this.

So while I mostly hate all of this it might be the best we can do :-(

#19 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 26 lines · Peter Zijlstra
Quoted 14 lines · Rik van Riel

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 10 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>
Quoted 4 lines

So let me start off by saying I hate isolcpus ;-)

Let me further state that I had hopes we could extend cpusets to natively provide the functionality isolcpus has, and kill isolcpus.

+1

That's where nohz_full goop belongs too.

Quoted 3 lines

The 'normal' way would be to create 2 cgroups with disjoint cpus, disable sched_load_balance on root and one of the siblings, while moving everything into the other group.

That's what cset shield does, works fine.

Quoted 10 lines

The 'problem' is that we cannot move everything that is affected by isolcpus, workqueues have grown a horrible 'new' interface outside of the regular task interfaces and things like kthreadd are non-movable for mostly good reasons.

Furthermore it appears that software like system-disease and libvirt hard assume they're lord and master of the cgroup hierarchy and do not expect things like this.

So while I mostly hate all of this it might be the best we can do :-(

Hm, I'm now all system-disease-ified now (still hate the bloody thing), and have no problem isolating cpus via cpusets, modulo workqueues wanting a bat upside the head.

-Mike

#20 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 27 lines · Mike Galbraith
Quoted 26 lines · Peter Zijlstra
Quoted 24 lines · Rik van Riel

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>
Quoted 8 lines
Quoted 4 lines

So let me start off by saying I hate isolcpus ;-)

Let me further state that I had hopes we could extend cpusets to natively provide the functionality isolcpus has, and kill isolcpus.

+1

That's where nohz_full goop belongs too.

Except nohz_full and isolcpus are very much global attributes of each CPU, so I am not sure whether it would make sense to allow configuration of this attribute anywhere other than the root cpuset.

Signature · 1 line
All rights reversed
#21 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 33 lines · Rik van Riel
Quoted 32 lines · Mike Galbraith
Quoted 30 lines · Peter Zijlstra
Quoted 14 lines · Rik van Riel

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 10 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>

So let me start off by saying I hate isolcpus ;-)

Let me further state that I had hopes we could extend cpusets to natively provide the functionality isolcpus has, and kill isolcpus.

Quoted 8 lines
Quoted 3 lines

+1

That's where nohz_full goop belongs too.

Except nohz_full and isolcpus are very much global attributes of each CPU, so I am not sure whether it would make sense to allow configuration of this attribute anywhere other than the root cpuset.

They're attributes of exclusive sets, which excludes the root set. It'd be kinda hard to have the root set be both ticked and tickless :)

-Mike

maintainer
#22 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to Mike Galbraith
Quoted 3 lines · Mike Galbraith

Hm, I'm now all system-disease-ified now (still hate the bloody thing), and have no problem isolating cpus via cpusets, modulo workqueues wanting a bat upside the head.

It shouldn't be difficult to teach workqueue pools to follow the same rules. This matters only for the unbound ones anyway, right?

Thanks.

Signature · 1 line
tejun
#23 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 7 lines · Tejun Heo
Quoted 3 lines · Mike Galbraith

Hm, I'm now all system-disease-ified now (still hate the bloody thing), and have no problem isolating cpus via cpusets, modulo workqueues wanting a bat upside the head.

It shouldn't be difficult to teach workqueue pools to follow the same rules. This matters only for the unbound ones anyway, right?

Well, those are the only ones we can do anything about. Dirt simple diddling of the workqueue default mask as sched domains are added/removed should do it I think. Automatically moving any existing unbound worker away from isolated cores at the same time would be a bonus, most important is that no new threads sneak in.

-Mike

maintainer
#24 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 5 lines · Mike Galbraith

Well, those are the only ones we can do anything about. Dirt simple diddling of the workqueue default mask as sched domains are added/removed should do it I think. Automatically moving any existing unbound worker away from isolated cores at the same time would be a bonus, most important is that no new threads sneak in.

Worker pools are immutable once created and configuraiton changes are achieved by creating new pools and draining old ones but at any rate making it follow config changes is almost trivial. Figuring out configuration policy might take a bit of effort tho. Can you point me to what specific configuration it should be following?

Thanks.

Signature · 1 line
tejun
#25 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 7 lines · Tejun Heo
Quoted 5 lines · Mike Galbraith

Well, those are the only ones we can do anything about. Dirt simple diddling of the workqueue default mask as sched domains are added/removed should do it I think. Automatically moving any existing unbound worker away from isolated cores at the same time would be a bonus, most important is that no new threads sneak in.

Quoted 5 lines

Worker pools are immutable once created and configuraiton changes are achieved by creating new pools and draining old ones but at any rate making it follow config changes is almost trivial. Figuring out configuration policy might take a bit of effort tho. Can you point me to what specific configuration it should be following?

For cpusets, an exclusive set should become taboo to unbound workers when load balancing is turned off. The user making sched domains go away is a not so subtle hint that he wants no random interference, as he is trying to assume full responsibility for task placement therein.

In my trees, I let the user turn rt cpupri/push/pull off as well, as that further reduces jitter.

-Mike

maintainer
#26 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

In reply to Rik van Riel
Quoted 25 lines · Rik van Riel
Quoted 2 lines · On Thu, 26 Feb 2015 19:05:57 +0800 Zefan Li <[email protected]> wrote:

Make it return -ENOMEM ? Or make it a global variable and allocate memory for it in cpuset_init().

Here you are. This addresses your concern, as well as the issue David Rientjes found earlier.

---8<---

Subject: cpusets,isolcpus: add file to show isolated cpus in cpuset

The previous patch makes it so the code skips over isolcpus when building scheduler load balancing domains. This makes it hard to see for a user which of the CPUs in a cpuset are participating in load balancing, and which ones are isolated cpus.

Add a cpuset.isolcpus file with info on which cpus in a cpuset are isolated CPUs.

This file is read-only for now. In the future we could extend things so isolcpus can be changed at run time, for the root (system wide) cpuset only.

Quoted 10 lines
Cc Peter Zijlstra <[email protected]>
Cc Clark Williams <[email protected]>
Cc Li Zefan <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Luiz Capitulino <[email protected]>
Cc David Rientjes <[email protected]>
Cc Mike Galbraith <[email protected]>

Applied 1-2 to cgroup/for-4.1.

Thanks.

Signature · 1 line
tejun
maintainer
#27 lore raw

Re: [PATCH v4 2/2] cpusets,isolcpus: add file to show isolated cpus in cpuset

Quoted 1 line · Tejun Heo

Applied 1-2 to cgroup/for-4.1.

Reverted due to build failure. Looks like UP build is broken.

Thanks.

Signature · 1 line
tejun