linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] add cpu physically hotplug driver
@ 2013-06-06  1:32 liguang
  2013-06-06  1:32 ` [PATCH RFC 1/3] drivers/platform/x86: " liguang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: liguang @ 2013-06-06  1:32 UTC (permalink / raw)
  To: Len Brown, Rafael J. Wysocki
  Cc: Matthew Garrett, linux-kernel, linux-acpi, platform-driver-x86, liguang

This patch-set try to support physically hot-plug/unplug
a cpu automatically, that is:
if you offline a cpu, it will automatically actually remove
a cpu, and if you hot-plug a cpu, then it will online this
cpu automatically.
so, offline is just like eject, but eject attribute seems not
available since recent kernel(can't figure out when), with
this driver, if allowed, it will trigger a eject cpu process.
and for automatically online, it was said there are objections,
don't know the reason, so, send this patch-set boldly.

of course, this approach is for QEMU 's hotplug cpu emulation 
only, but not limited, if someone like to explore ec space to
implment cpu hot-plug/unplug for real platform please
feel free to continue.

Li Guang (3)
	 drivers/platform/x86: add cpu physically hotplug driver
	 ec: add ec space notifier
	 cpu_physic_hotplug: register handler for ec space notifier

drivers/acpi/ec.c                         | 32 ++++++++++++++++++++++++++++++++
drivers/platform/x86/Kconfig              |  8 ++++
drivers/platform/x86/Makefile             |  1 +
drivers/platform/x86/cpu_physic_hotplug.c | 87 +++++++++++++++++++++++++++++
include/linux/acpi.h                      |  2 ++
5 files changed, 128 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/cpu_physic_hotplug.c


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH RFC 1/3] drivers/platform/x86: add cpu physically hotplug driver
  2013-06-06  1:32 [PATCH RFC 0/3] add cpu physically hotplug driver liguang
@ 2013-06-06  1:32 ` liguang
  2013-06-06  1:32 ` [PATCH RFC 2/3] ec: add ec space notifier liguang
  2013-06-06  1:32 ` [PATCH RFC 3/3] cpu_physic_hotplug: register handler for " liguang
  2 siblings, 0 replies; 4+ messages in thread
From: liguang @ 2013-06-06  1:32 UTC (permalink / raw)
  To: Len Brown, Rafael J. Wysocki
  Cc: Matthew Garrett, linux-kernel, linux-acpi, platform-driver-x86, liguang

this driver will support cpu phyical add/removal automatically
after online/offline. if cpu hotpluged, cpu will not
online automatically, and for cpu offline, we try to
do actually eject if allowed for cpu like
"echo 1 > /sys/bus/acpi/devices/LNXCPU\:0X/eject"
this "echo ..." is only present for recent kernel
(sorry, can't figure out since when), for a little
older kernel, there's not such approach AFAICS.

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 drivers/platform/x86/Kconfig              |    8 ++++
 drivers/platform/x86/Makefile             |    1 +
 drivers/platform/x86/cpu_physic_hotplug.c |   60 +++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)
 create mode 100644 drivers/platform/x86/cpu_physic_hotplug.c

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 8577261..39b2392 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -789,4 +789,12 @@ config PVPANIC
 	  a paravirtualized device provided by QEMU; it lets a virtual machine
 	  (guest) communicate panic events to the host.
 
+config QEMU_CPU_PHYSIC_HOTPLUG
+	tristate "physically add/remove cpu after cpu onlined/offlined"
+	depends on ACPI_HOTPLUG_CPU
+	---help---
+	  This driver will support physically remove a cpu after
+	  it offlined for QEMU automatically. someone may require this feature
+	  to do a physically removal for a cpu.
+
 endif # X86_PLATFORM_DEVICES
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index ef0ec74..2e669b0 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -53,3 +53,4 @@ obj-$(CONFIG_APPLE_GMUX)	+= apple-gmux.o
 obj-$(CONFIG_CHROMEOS_LAPTOP)	+= chromeos_laptop.o
 
 obj-$(CONFIG_PVPANIC)           += pvpanic.o
+obj-$(CONFIG_QEMU_CPU_PHYSIC_HOTPLUG)	+= cpu_physic_hotplug.o
diff --git a/drivers/platform/x86/cpu_physic_hotplug.c b/drivers/platform/x86/cpu_physic_hotplug.c
new file mode 100644
index 0000000..a52c042
--- /dev/null
+++ b/drivers/platform/x86/cpu_physic_hotplug.c
@@ -0,0 +1,60 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/cpu.h>
+#include <linux/notifier.h>
+#include <acpi/processor.h>
+
+MODULE_AUTHOR("Li Guang");
+MODULE_DESCRIPTION("CPU physically hot-plug/unplug Driver");
+MODULE_LICENSE("GPL");
+
+static int cpu_logic_hotplug_notify(struct notifier_block *nfb,
+				unsigned long action, void *hcpu)
+{
+	unsigned int cpu = (unsigned long)hcpu;
+	struct acpi_processor *pr = per_cpu(processors, cpu);
+
+	if (pr) {
+		switch (action) {
+		case CPU_ONLINE:
+			break;
+		case CPU_DEAD:
+			break;
+		default:
+			break;
+		}
+	}
+	return NOTIFY_OK;
+}
+
+static struct notifier_block cpu_logic_hotplug_notifier =
+{
+	.notifier_call = cpu_logic_hotplug_notify,
+};
+
+static int cpu_physic_hotplug_notify(struct notifier_block *nfb,
+				 unsigned char *s)
+{
+}
+
+static struct notifier_block cpu_physic_hotplug_notifier =
+{
+	.notifier_call = cpu_physic_hotplug_notify,
+};
+
+static int __init cpu_qemu_hotplug_init(void)
+{
+	register_hotcpu_notifier(&cpu_logic_hotplug_notifier);
+	register_ec_gpe_notifier(&cpu_physic_hotplug_notifier);
+	return 0;
+}
+
+static void __exit cpu_qemu_hotplug_exit(void)
+{
+	unregister_hotcpu_notifier(&cpu_logic_hotplug_notifier);
+	unregister_ec_gpe_notifier(&cpu_physic_hotplug_notifier);
+}
+
+module_init(cpu_qemu_hotplug_init);
+module_exit(cpu_qemu_hotplug_exit);
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH RFC 2/3] ec: add ec space notifier
  2013-06-06  1:32 [PATCH RFC 0/3] add cpu physically hotplug driver liguang
  2013-06-06  1:32 ` [PATCH RFC 1/3] drivers/platform/x86: " liguang
@ 2013-06-06  1:32 ` liguang
  2013-06-06  1:32 ` [PATCH RFC 3/3] cpu_physic_hotplug: register handler for " liguang
  2 siblings, 0 replies; 4+ messages in thread
From: liguang @ 2013-06-06  1:32 UTC (permalink / raw)
  To: Len Brown, Rafael J. Wysocki
  Cc: Matthew Garrett, linux-kernel, linux-acpi, platform-driver-x86, liguang

add a notifier for anyone who are instresting in
ec space changing.

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 drivers/acpi/ec.c    |   32 ++++++++++++++++++++++++++++++++
 include/linux/acpi.h |    2 ++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index edc0081..dee3417 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -124,6 +124,35 @@ static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
 static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */
 static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
 
+/* notifier chain for who are intresting in ec space changing */
+static RAW_NOTIFIER_HEAD(ec_space_chain);
+
+int __ref register_ec_space_notifier(struct notifier_block *nb)
+{
+        int ret;
+
+        ret = raw_notifier_chain_register(&ec_space_chain, nb);
+
+        return ret;
+}
+EXPORT_SYMBOL(register_ec_space_notifier);
+
+void __ref unregister_ec_space_notifier(struct notifier_block *nb)
+{
+
+        raw_notifier_chain_unregister(&ec_space_chain, nb);
+}
+EXPORT_SYMBOL(unregister_ec_space_notifier);
+
+static int ec_space_notify(void *data)
+{
+    int ret;
+
+    ret = __raw_notifier_call_chain(&ec_space_chain, 0, data, -1, NULL);
+
+     return notifier_to_errno(ret);
+}
+
 /* --------------------------------------------------------------------------
                              Transaction Management
    -------------------------------------------------------------------------- */
@@ -638,6 +667,9 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
 		wake_up(&ec->wait);
 		ec_check_sci(ec, acpi_ec_read_status(ec));
 	}
+
+	ec_space_notify(data);
+
 	return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE;
 }
 
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 17b5b59..4fe2247 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -158,6 +158,8 @@ extern int ec_transaction(u8 command,
                           const u8 *wdata, unsigned wdata_len,
                           u8 *rdata, unsigned rdata_len);
 extern acpi_handle ec_get_handle(void);
+extern int register_ec_space_notifier(struct notifier_block *nb);
+extern void unregister_ec_space_notifier(struct notifier_block *nb);
 
 #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
 
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH RFC 3/3] cpu_physic_hotplug: register handler for ec space notifier
  2013-06-06  1:32 [PATCH RFC 0/3] add cpu physically hotplug driver liguang
  2013-06-06  1:32 ` [PATCH RFC 1/3] drivers/platform/x86: " liguang
  2013-06-06  1:32 ` [PATCH RFC 2/3] ec: add ec space notifier liguang
@ 2013-06-06  1:32 ` liguang
  2 siblings, 0 replies; 4+ messages in thread
From: liguang @ 2013-06-06  1:32 UTC (permalink / raw)
  To: Len Brown, Rafael J. Wysocki
  Cc: Matthew Garrett, linux-kernel, linux-acpi, platform-driver-x86, liguang

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 drivers/platform/x86/cpu_physic_hotplug.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/cpu_physic_hotplug.c b/drivers/platform/x86/cpu_physic_hotplug.c
index a52c042..a84c999 100644
--- a/drivers/platform/x86/cpu_physic_hotplug.c
+++ b/drivers/platform/x86/cpu_physic_hotplug.c
@@ -9,6 +9,9 @@ MODULE_AUTHOR("Li Guang");
 MODULE_DESCRIPTION("CPU physically hot-plug/unplug Driver");
 MODULE_LICENSE("GPL");
 
+#define EC_SPACE_CPU_IDX       3
+#define EC_SPACE_CPU_OFFSET    4
+
 static int cpu_logic_hotplug_notify(struct notifier_block *nfb,
 				unsigned long action, void *hcpu)
 {
@@ -36,6 +39,26 @@ static struct notifier_block cpu_logic_hotplug_notifier =
 static int cpu_physic_hotplug_notify(struct notifier_block *nfb,
 				 unsigned char *s)
 {
+	u8 index = 0, val = 0;
+	bool cpu_state = false;
+	struct acpi_processor *pr;
+
+	ec_read(EC_SPACE_CPU_IDX, &index);
+	if (index == 0)
+		goto out;
+	pr = per_cpu(processors, index);
+
+	ec_read(EC_SPACE_CPU_OFFSET + index/8, &val);
+	if (val & 1 << index/8)
+		cpu_state = true;
+
+	if (pr->flags.need_hotplug_init & cpu_state)
+		cpu_up(pr->id);
+	else
+		cpu_down(pr->id);
+
+out:
+    return NOTIFY_OK;
 }
 
 static struct notifier_block cpu_physic_hotplug_notifier =
@@ -46,14 +69,14 @@ static struct notifier_block cpu_physic_hotplug_notifier =
 static int __init cpu_qemu_hotplug_init(void)
 {
 	register_hotcpu_notifier(&cpu_logic_hotplug_notifier);
-	register_ec_gpe_notifier(&cpu_physic_hotplug_notifier);
+	register_ec_space_notifier(&cpu_physic_hotplug_notifier);
 	return 0;
 }
 
 static void __exit cpu_qemu_hotplug_exit(void)
 {
 	unregister_hotcpu_notifier(&cpu_logic_hotplug_notifier);
-	unregister_ec_gpe_notifier(&cpu_physic_hotplug_notifier);
+	unregister_ec_space_notifier(&cpu_physic_hotplug_notifier);
 }
 
 module_init(cpu_qemu_hotplug_init);
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-06  1:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06  1:32 [PATCH RFC 0/3] add cpu physically hotplug driver liguang
2013-06-06  1:32 ` [PATCH RFC 1/3] drivers/platform/x86: " liguang
2013-06-06  1:32 ` [PATCH RFC 2/3] ec: add ec space notifier liguang
2013-06-06  1:32 ` [PATCH RFC 3/3] cpu_physic_hotplug: register handler for " liguang

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).