LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: maxk@qualcomm.com
To: linux-kernel@vger.kernel.org
Cc: Max Krasnyansky <maxk@qualcomm.com>
Subject: [PATCH] [CPUISOL] Export CPU isolation bits
Date: Sun, 27 Jan 2008 20:09:39 -0800 [thread overview]
Message-ID: <1201493382-29804-3-git-send-email-maxk@qualcomm.com> (raw)
In-Reply-To: <1201493382-29804-2-git-send-email-maxk@qualcomm.com>
From: Max Krasnyansky <maxk@qualcomm.com>
Here we're just exporting CPU isolation bitmap so that it can
be used outside the scheduler code.
Helper functions like cpu_isolated() are provided for easy access.
This is very similar to cpu_online() and friends.
The patch also exports 'isolated' bit via sysfs in very much the
same way 'online' bit is exposed today.
CPUs can be isolated either via command line isolcpu= option or
by doing something like this:
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/isolated
echo 1 > /sys/devices/system/cpu/cpu1/online
Signed-off-by: Max Krasnyansky <maxk@qualcomm.com>
---
drivers/base/cpu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/cpumask.h | 3 +++
kernel/sched.c | 12 ++++++++----
3 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index c5885f5..f59c719 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -55,10 +55,57 @@ static ssize_t store_online(struct sys_device *dev, const char *buf,
}
static SYSDEV_ATTR(online, 0644, show_online, store_online);
+#ifdef CONFIG_CPUISOL
+/*
+ * This is under config hotplug is because in order to
+ * dynamically isolate a CPU it needs to be brought down.
+ * In other words the sequence should be
+ * echo 0 > /sys/device/system/cpuN/online
+ * echo 1 > /sys/device/system/cpuN/isolated
+ */
+static ssize_t show_isol(struct sys_device *dev, char *buf)
+{
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+
+ return sprintf(buf, "%u\n", !!cpu_isolated(cpu->sysdev.id));
+}
+
+static ssize_t store_isol(struct sys_device *dev, const char *buf,
+ size_t count)
+{
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+ ssize_t ret = 0;
+
+ if (cpu_online(cpu->sysdev.id))
+ return -EBUSY;
+
+ switch (buf[0]) {
+ case '0':
+ cpu_clear(cpu->sysdev.id, cpu_isolated_map);
+ break;
+ case '1':
+ cpu_set(cpu->sysdev.id, cpu_isolated_map);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ if (ret >= 0)
+ ret = count;
+ return ret;
+}
+static SYSDEV_ATTR(isolated, 0600, show_isol, store_isol);
+#endif /* CONFIG_CPUISOL */
+
static void __devinit register_cpu_control(struct cpu *cpu)
{
sysdev_create_file(&cpu->sysdev, &attr_online);
+
+#ifdef CONFIG_CPUISOL
+ sysdev_create_file(&cpu->sysdev, &attr_isolated);
+#endif
}
+
void unregister_cpu(struct cpu *cpu)
{
int logical_cpu = cpu->sysdev.id;
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 85bd790..84d1561 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -380,6 +380,7 @@ static inline void __cpus_remap(cpumask_t *dstp, const cpumask_t *srcp,
extern cpumask_t cpu_possible_map;
extern cpumask_t cpu_online_map;
extern cpumask_t cpu_present_map;
+extern cpumask_t cpu_isolated_map;
#if NR_CPUS > 1
#define num_online_cpus() cpus_weight(cpu_online_map)
@@ -388,6 +389,7 @@ extern cpumask_t cpu_present_map;
#define cpu_online(cpu) cpu_isset((cpu), cpu_online_map)
#define cpu_possible(cpu) cpu_isset((cpu), cpu_possible_map)
#define cpu_present(cpu) cpu_isset((cpu), cpu_present_map)
+#define cpu_isolated(cpu) cpu_isset((cpu), cpu_isolated_map)
#else
#define num_online_cpus() 1
#define num_possible_cpus() 1
@@ -395,6 +397,7 @@ extern cpumask_t cpu_present_map;
#define cpu_online(cpu) ((cpu) == 0)
#define cpu_possible(cpu) ((cpu) == 0)
#define cpu_present(cpu) ((cpu) == 0)
+#define cpu_isolated(cpu) (0)
#endif
#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
diff --git a/kernel/sched.c b/kernel/sched.c
index 524285e..2fc942e 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4815,10 +4815,17 @@ asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
* as new cpu's are detected in the system via any platform specific
* method, such as ACPI for e.g.
*/
-
cpumask_t cpu_present_map __read_mostly;
EXPORT_SYMBOL(cpu_present_map);
+/*
+ * Represents isolated cpu's.
+ * These cpu's have isolated scheduling domains. In general any
+ * kernel activity should be avoided as much as possible on them.
+ */
+cpumask_t cpu_isolated_map __read_mostly = CPU_MASK_NONE;
+EXPORT_SYMBOL(cpu_isolated_map);
+
#ifndef CONFIG_SMP
cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL;
EXPORT_SYMBOL(cpu_online_map);
@@ -6186,9 +6193,6 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
rcu_assign_pointer(rq->sd, sd);
}
-/* cpus with isolated domains */
-static cpumask_t cpu_isolated_map = CPU_MASK_NONE;
-
/* Setup the mask of cpus configured for isolated domains */
static int __init isolated_cpu_setup(char *str)
{
--
1.5.3.7
next prev parent reply other threads:[~2008-01-28 4:35 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-28 4:09 [CPUISOL] CPU isolation extensions maxk
2008-01-28 4:09 ` [PATCH] [CPUISOL] Add config options for CPU isolation maxk
2008-01-28 4:09 ` maxk [this message]
2008-01-28 4:09 ` [PATCH] [CPUISOL] Do not route IRQs to the CPUs isolated at boot maxk
2008-01-28 4:09 ` [PATCH] [CPUISOL] Support for workqueue isolation maxk
2008-01-28 4:09 ` [PATCH] [CPUISOL] Isolated CPUs should be ignored by the "stop machine" maxk
2008-01-28 9:08 ` [CPUISOL] CPU isolation extensions Peter Zijlstra
2008-01-28 14:59 ` Paul Jackson
2008-01-28 16:34 ` Steven Rostedt
2008-01-28 16:44 ` Peter Zijlstra
2008-01-28 18:54 ` Max Krasnyanskiy
2008-01-28 18:46 ` Max Krasnyanskiy
2008-01-28 19:00 ` Steven Rostedt
2008-01-28 20:22 ` Peter Zijlstra
2008-01-28 21:42 ` Max Krasnyanskiy
2008-02-05 0:32 ` CPU isolation and workqueues [was Re: [CPUISOL] CPU isolation extensions] Max Krasnyanskiy
2008-01-28 18:37 ` [CPUISOL] CPU isolation extensions Max Krasnyanskiy
2008-01-28 19:06 ` Paul Jackson
2008-01-28 21:47 ` Max Krasnyanskiy
2008-01-31 19:06 ` Integrating cpusets and cpu isolation [was Re: [CPUISOL] CPU isolation extensions] Max Krasnyanskiy
2008-02-02 6:16 ` Paul Jackson
2008-02-03 5:57 ` Max Krasnyansky
2008-02-03 7:53 ` Paul Jackson
2008-02-04 6:03 ` Max Krasnyansky
2008-02-04 10:54 ` Paul Jackson
2008-02-04 23:19 ` Max Krasnyanskiy
2008-02-05 2:46 ` Paul Jackson
2008-02-05 4:08 ` Max Krasnyansky
2008-01-28 18:32 ` [CPUISOL] CPU isolation extensions Max Krasnyanskiy
2008-01-28 19:10 ` Paul Jackson
2008-01-28 23:41 ` Daniel Walker
2008-01-29 0:12 ` Max Krasnyanskiy
2008-01-29 1:33 ` Daniel Walker
2008-02-04 6:53 ` Max Krasnyansky
2008-01-31 12:16 ` Mark Hounschell
2008-01-31 19:13 ` Max Krasnyanskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1201493382-29804-3-git-send-email-maxk@qualcomm.com \
--to=maxk@qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [PATCH] [CPUISOL] Export CPU isolation bits' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).