Blame SOURCES/irqbalance-1.0.8-parse-isolcpus-from-proc-cmdline-to-set-up-banned_cp.patch

5f346f
From ca5a3f13bf247561e64ef2323b3dd28a2c3b880d Mon Sep 17 00:00:00 2001
5f346f
From: Rik van Riel <riel@redhat.com>
5f346f
Date: Thu, 12 Mar 2015 17:47:00 -0400
5f346f
Subject: [PATCH 3/3] parse isolcpus= from /proc/cmdline to set up banned_cpus
5f346f
5f346f
When the user specifies a range of CPUs to be isolated from system
5f346f
tasks with isolcpus= on the kernel command line, it would be nice
5f346f
if those CPUs could automatically be excluded from getting interrupts
5f346f
routed to them, as well.
5f346f
5f346f
This patch does that, by looking at /proc/cmdline
5f346f
5f346f
The environment variable IRQBALANCE_BANNED_CPUS will override the
5f346f
automatically detectable banned_cpus.
5f346f
5f346f
Signed-off-by: Rik van Riel <riel@redhat.com>
5f346f
---
5f346f
 cputree.c    | 44 ++++++++++++++++++++++++++++++++++++++++++++
5f346f
 irqbalance.c |  4 ----
5f346f
 2 files changed, 44 insertions(+), 4 deletions(-)
5f346f
5f346f
diff --git a/cputree.c b/cputree.c
5f346f
index 8b8cf5e..cfa70b6 100644
5f346f
--- a/cputree.c
5f346f
+++ b/cputree.c
5f346f
@@ -58,6 +58,48 @@ cpumask_t cpu_possible_map;
5f346f
 */
5f346f
 cpumask_t unbanned_cpus;
5f346f
 
5f346f
+/*
5f346f
+ * By default do not place IRQs on CPUs the kernel keeps isolated,
5f346f
+ * as specified through the isolcpus= boot commandline. Users can
5f346f
+ * override this with the IRQBALANCE_BANNED_CPUS environment variable.
5f346f
+ */
5f346f
+static void setup_banned_cpus(void)
5f346f
+{
5f346f
+	FILE *file;
5f346f
+	char *c, *line = NULL;
5f346f
+	size_t size = 0;
5f346f
+	const char *isolcpus = "isolcpus=";
5f346f
+	char buffer[4096];
5f346f
+
5f346f
+	/* A manually specified cpumask overrides auto-detection. */
5f346f
+	if (getenv("IRQBALANCE_BANNED_CPUS"))  {
5f346f
+		cpumask_parse_user(getenv("IRQBALANCE_BANNED_CPUS"), strlen(getenv("IRQBALANCE_BANNED_CPUS")), banned_cpus);
5f346f
+		goto out;
5f346f
+	}
5f346f
+
5f346f
+	file = fopen("/proc/cmdline", "r");
5f346f
+	if (!file)
5f346f
+		goto out;
5f346f
+
5f346f
+	if (getline(&line, &size, file) <= 0)
5f346f
+		goto out;
5f346f
+
5f346f
+	if ((c = strstr(line, isolcpus))) {
5f346f
+		char *end;
5f346f
+		int len;
5f346f
+
5f346f
+		c += strlen(isolcpus);
5f346f
+		for (end = c; *end != ' ' && *end != '\0' && *end != '\n'; end++);
5f346f
+		len = end - c;
5f346f
+
5f346f
+		cpulist_parse(c, len, banned_cpus);
5f346f
+	}
5f346f
+
5f346f
+ out:
5f346f
+	cpumask_scnprintf(buffer, 4096, banned_cpus);
5f346f
+	log(TO_CONSOLE, LOG_INFO, "Isolated CPUs: %s\n", buffer);
5f346f
+}
5f346f
+
5f346f
 static struct topo_obj* add_cache_domain_to_package(struct topo_obj *cache, 
5f346f
 						    int packageid, cpumask_t package_mask)
5f346f
 {
5f346f
@@ -372,6 +414,8 @@ void parse_cpu_tree(void)
5f346f
 	DIR *dir;
5f346f
 	struct dirent *entry;
5f346f
 
5f346f
+	setup_banned_cpus();
5f346f
+
5f346f
 	cpus_complement(unbanned_cpus, banned_cpus);
5f346f
 
5f346f
 	dir = opendir("/sys/devices/system/cpu");
5f346f
diff --git a/irqbalance.c b/irqbalance.c
5f346f
index a5079b9..e4f3b93 100644
5f346f
--- a/irqbalance.c
5f346f
+++ b/irqbalance.c
5f346f
@@ -276,10 +276,6 @@ int main(int argc, char** argv)
5f346f
  	 */
5f346f
 	openlog(argv[0], 0, LOG_DAEMON);
5f346f
 
5f346f
-	if (getenv("IRQBALANCE_BANNED_CPUS"))  {
5f346f
-		cpumask_parse_user(getenv("IRQBALANCE_BANNED_CPUS"), strlen(getenv("IRQBALANCE_BANNED_CPUS")), banned_cpus);
5f346f
-	}
5f346f
-
5f346f
 	if (getenv("IRQBALANCE_ONESHOT")) 
5f346f
 		one_shot_mode=1;
5f346f
 
5f346f
-- 
5f346f
2.1.0
5f346f