Skip to contentSkip to conversation

cpu bulk removal interface

PATCH In review Shaohua Li 2 participants 3 messages May 8, 2006

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 10/10 cpu bulk removal interface

Interface for bulk cpu removal. It's /sys/devices/system/cpu/cpu_bulk_remove

---

 linux-2.6.17-rc3-root/drivers/base/cpu.c  |   47 +++++++++++++++++++++++++++++-
 linux-2.6.17-rc3-root/include/linux/cpu.h |    3 +
 2 files changed, 49 insertions(+), 1 deletion(-)
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +46 -1
diff -puN drivers/base/cpu.c~bulk_cpu_remove_interface drivers/base/cpu.c
@@ -76,6 +76,46 @@ static inline void register_cpu_control(
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
+#ifdef CONFIG_BULK_CPU_REMOVE
+static ssize_t cpu_bulk_remove_show(struct sysdev_class *c, char *buf)
+{
+	int len;
+
+	len = cpulist_scnprintf(buf, PAGE_SIZE-1, cpu_online_map);
+	len += sprintf(buf + len, "\n");
+	return len;
+}
+
+static ssize_t cpu_bulk_remove_store(struct sysdev_class *c,
+	const char *buf, size_t count)
+{
+	int err;
+	cpumask_t removed_cpus;
+
+	if ((err = lock_cpu_hotplug_interruptible() != 0))
+		return err;
+	err = cpulist_parse(buf, removed_cpus);
+	if (err) {
+		unlock_cpu_hotplug();
+		return err;
+	}
+
+	unlock_cpu_hotplug();
+	cpu_down_mask(removed_cpus);
+	return count;
+}
+
+static SYSDEV_CLASS_ATTR(cpu_bulk_remove, 0600, cpu_bulk_remove_show,
+	cpu_bulk_remove_store);
+
+void __init cpu_bulk_remove_sysfs_init(void)
+{
+	sysdev_class_create_file(&cpu_sysdev_class, &attr_cpu_bulk_remove);
+}
+#else
+#define cpu_bulk_remove_sysfs_init()
+#endif
+
 #ifdef CONFIG_KEXEC
 #include <linux/kexec.h>
 
@@ -145,5 +185,10 @@ EXPORT_SYMBOL_GPL(get_cpu_sysdev);
 
 int __init cpu_dev_init(void)
 {
-	return sysdev_class_register(&cpu_sysdev_class);
+	int ret;
+
+	ret = sysdev_class_register(&cpu_sysdev_class);
+	if (!ret)
+		cpu_bulk_remove_sysfs_init();
+	return ret;
 }
include/linux/cpu.h renamed from include/linux/cpu.h~bulk_cpu_remove_interface +3 -0
diff -puN include/linux/cpu.h~bulk_cpu_remove_interface include/linux/cpu.h
@@ -74,6 +74,9 @@ extern int lock_cpu_hotplug_interruptibl
 	register_cpu_notifier(&fn##_nb);			\
 }
 int cpu_down(unsigned int cpu);
+#ifdef CONFIG_BULK_CPU_REMOVE
+int cpu_down_mask(cpumask_t remove_mask);
+#endif
 #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
 #else
 #define lock_cpu_hotplug()	do { } while (0)

_

#1 lore raw
Quoted 16 lines · Shaohua Li

Interface for bulk cpu removal. It's /sys/devices/system/cpu/cpu_bulk_remove

---

 linux-2.6.17-rc3-root/drivers/base/cpu.c  |   47 +++++++++++++++++++++++++++++-
 linux-2.6.17-rc3-root/include/linux/cpu.h |    3 +
 2 files changed, 49 insertions(+), 1 deletion(-)

diff -puN drivers/base/cpu.c~bulk_cpu_remove_interface drivers/base/cpu.c

drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +0 -0
@@ -76,6 +76,46 @@ static inline void register_cpu_control(
 }
 #endif /* CONFIG_HOTPLUG_CPU */

drivers/base/cpu.c static inline void register_cpu_control( · line 87

Quoted 10 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +9 -0
 
+#ifdef CONFIG_BULK_CPU_REMOVE
+static ssize_t cpu_bulk_remove_show(struct sysdev_class *c, char *buf)
+{
+	int len;
+
+	len = cpulist_scnprintf(buf, PAGE_SIZE-1, cpu_online_map);
+	len += sprintf(buf + len, "\n");
+	return len;
+}

This doesn't really seem meaningful. I'd say the attribute could do without a show method.

Quoted 8 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +8 -0
+static ssize_t cpu_bulk_remove_store(struct sysdev_class *c,
+	const char *buf, size_t count)
+{
+	int err;
+	cpumask_t removed_cpus;
+
+	if ((err = lock_cpu_hotplug_interruptible() != 0))
+		return err;

drivers/base/cpu.c static inline void register_cpu_control( · line 106

Quoted 10 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +10 -0
+	err = cpulist_parse(buf, removed_cpus);
+	if (err) {
+		unlock_cpu_hotplug();
+		return err;
+	}
+
+	unlock_cpu_hotplug();
+	cpu_down_mask(removed_cpus);
+	return count;
+}

Shouldn't this make sure that we don't offline all cpus?

Why are you using lock_cpu_hotplug_interruptible instead of lock_cpu_hotplug?

Why is only the parsing of the cpumask buffer protected by the cpu hotplug lock? Shouldn't cpu_down_mask be called with the lock held?

Can cpu_down_mask fail, and if so, shouldn't we be reporting the error?

author
#2 lore raw
Quoted 18 lines · Nathan Lynch
Quoted 17 lines · Shaohua Li

Interface for bulk cpu removal. It's /sys/devices/system/cpu/cpu_bulk_remove

---

 linux-2.6.17-rc3-root/drivers/base/cpu.c  |   47 +++++++++++++++++++++++++++++-
 linux-2.6.17-rc3-root/include/linux/cpu.h |    3 +
 2 files changed, 49 insertions(+), 1 deletion(-)

diff -puN drivers/base/cpu.c~bulk_cpu_remove_interface drivers/base/cpu.c

drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +0 -0
@@ -76,6 +76,46 @@ static inline void register_cpu_control(
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
Quoted 12 lines

drivers/base/cpu.c static inline void register_cpu_control( · line 87

Quoted 9 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +9 -0
+#ifdef CONFIG_BULK_CPU_REMOVE
+static ssize_t cpu_bulk_remove_show(struct sysdev_class *c, char *buf)
+{
+	int len;
+
+	len = cpulist_scnprintf(buf, PAGE_SIZE-1, cpu_online_map);
+	len += sprintf(buf + len, "\n");
+	return len;
+}

This doesn't really seem meaningful. I'd say the attribute could do without a show method.

Ok, I'll remove it.

Quoted 12 lines
Quoted 12 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +12 -0
+static ssize_t cpu_bulk_remove_store(struct sysdev_class *c,
+	const char *buf, size_t count)
+{
+	int err;
+	cpumask_t removed_cpus;
+
+	if ((err = lock_cpu_hotplug_interruptible() != 0))
+		return err;
+	err = cpulist_parse(buf, removed_cpus);
+	if (err) {
+		unlock_cpu_hotplug();
+		return err;
Quoted 8 lines

drivers/base/cpu.c static inline void register_cpu_control( · line 106

Quoted 6 lines
drivers/base/cpu.c renamed from drivers/base/cpu.c~bulk_cpu_remove_interface +6 -0
+	}
+
+	unlock_cpu_hotplug();
+	cpu_down_mask(removed_cpus);
+	return count;
+}

Shouldn't this make sure that we don't offline all cpus?

cpu_down_mask will check it.

Quoted 5 lines

Why are you using lock_cpu_hotplug_interruptible instead of lock_cpu_hotplug?

Why is only the parsing of the cpumask buffer protected by the cpu hotplug lock? Shouldn't cpu_down_mask be called with the lock held?

we actually don't need lock here. I'll remove it.

Quoted 2 lines

Can cpu_down_mask fail, and if so, shouldn't we be reporting the error?

Makes sense.

Thanks,
Shaohua