linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, mingo@kernel.org, linux-kernel@vger.kernel.org,
	steffen.klassert@secunet.com, peterz@infradead.org,
	bigeasy@linutronix.de, tglx@linutronix.de
Subject: [tip:smp/hotplug] padata: Convert to hotplug state machine
Date: Mon, 19 Sep 2016 12:57:23 -0700	[thread overview]
Message-ID: <tip-30e92153b4e6f1cd01e30c34d9ef6f0986f96b0e@git.kernel.org> (raw)
In-Reply-To: <20160906170457.32393-14-bigeasy@linutronix.de>

Commit-ID:  30e92153b4e6f1cd01e30c34d9ef6f0986f96b0e
Gitweb:     http://git.kernel.org/tip/30e92153b4e6f1cd01e30c34d9ef6f0986f96b0e
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Tue, 6 Sep 2016 19:04:49 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 19 Sep 2016 21:44:30 +0200

padata: Convert to hotplug state machine

Install the callbacks via the state machine. CPU-hotplug multinstance support
is used with the nocalls() version. Maybe parts of padata_alloc() could be
moved into the online callback so that we could invoke ->startup callback for
instance and drop get_online_cpus().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-crypto@vger.kernel.org
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20160906170457.32393-14-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 include/linux/padata.h |  2 +-
 kernel/padata.c        | 88 ++++++++++++++++++++++++++++----------------------
 2 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/include/linux/padata.h b/include/linux/padata.h
index 113ee62..0f9e567 100644
--- a/include/linux/padata.h
+++ b/include/linux/padata.h
@@ -151,7 +151,7 @@ struct parallel_data {
  * @flags: padata flags.
  */
 struct padata_instance {
-	struct notifier_block		 cpu_notifier;
+	struct hlist_node		 node;
 	struct workqueue_struct		*wq;
 	struct parallel_data		*pd;
 	struct padata_cpumask		cpumask;
diff --git a/kernel/padata.c b/kernel/padata.c
index 9932788..7848f05 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 #include <linux/rcupdate.h>
+#include <linux/module.h>
 
 #define MAX_OBJ_NUM 1000
 
@@ -769,52 +770,43 @@ static inline int pinst_has_cpu(struct padata_instance *pinst, int cpu)
 		cpumask_test_cpu(cpu, pinst->cpumask.cbcpu);
 }
 
-
-static int padata_cpu_callback(struct notifier_block *nfb,
-			       unsigned long action, void *hcpu)
+static int padata_cpu_online(unsigned int cpu, struct hlist_node *node)
 {
-	int err;
 	struct padata_instance *pinst;
-	int cpu = (unsigned long)hcpu;
+	int ret;
 
-	pinst = container_of(nfb, struct padata_instance, cpu_notifier);
+	pinst = hlist_entry_safe(node, struct padata_instance, node);
+	if (!pinst_has_cpu(pinst, cpu))
+		return 0;
 
-	switch (action) {
-	case CPU_ONLINE:
-	case CPU_ONLINE_FROZEN:
-	case CPU_DOWN_FAILED:
-	case CPU_DOWN_FAILED_FROZEN:
-		if (!pinst_has_cpu(pinst, cpu))
-			break;
-		mutex_lock(&pinst->lock);
-		err = __padata_add_cpu(pinst, cpu);
-		mutex_unlock(&pinst->lock);
-		if (err)
-			return notifier_from_errno(err);
-		break;
+	mutex_lock(&pinst->lock);
+	ret = __padata_add_cpu(pinst, cpu);
+	mutex_unlock(&pinst->lock);
+	return ret;
+}
 
-	case CPU_DOWN_PREPARE:
-	case CPU_DOWN_PREPARE_FROZEN:
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-		if (!pinst_has_cpu(pinst, cpu))
-			break;
-		mutex_lock(&pinst->lock);
-		err = __padata_remove_cpu(pinst, cpu);
-		mutex_unlock(&pinst->lock);
-		if (err)
-			return notifier_from_errno(err);
-		break;
-	}
+static int padata_cpu_prep_down(unsigned int cpu, struct hlist_node *node)
+{
+	struct padata_instance *pinst;
+	int ret;
+
+	pinst = hlist_entry_safe(node, struct padata_instance, node);
+	if (!pinst_has_cpu(pinst, cpu))
+		return 0;
 
-	return NOTIFY_OK;
+	mutex_lock(&pinst->lock);
+	ret = __padata_remove_cpu(pinst, cpu);
+	mutex_unlock(&pinst->lock);
+	return ret;
 }
+
+static enum cpuhp_state hp_online;
 #endif
 
 static void __padata_free(struct padata_instance *pinst)
 {
 #ifdef CONFIG_HOTPLUG_CPU
-	unregister_hotcpu_notifier(&pinst->cpu_notifier);
+	cpuhp_state_remove_instance_nocalls(hp_online, &pinst->node);
 #endif
 
 	padata_stop(pinst);
@@ -1012,11 +1004,8 @@ struct padata_instance *padata_alloc(struct workqueue_struct *wq,
 	mutex_init(&pinst->lock);
 
 #ifdef CONFIG_HOTPLUG_CPU
-	pinst->cpu_notifier.notifier_call = padata_cpu_callback;
-	pinst->cpu_notifier.priority = 0;
-	register_hotcpu_notifier(&pinst->cpu_notifier);
+	cpuhp_state_add_instance_nocalls(hp_online, &pinst->node);
 #endif
-
 	return pinst;
 
 err_free_masks:
@@ -1039,3 +1028,26 @@ void padata_free(struct padata_instance *pinst)
 	kobject_put(&pinst->kobj);
 }
 EXPORT_SYMBOL(padata_free);
+
+#ifdef CONFIG_HOTPLUG_CPU
+
+static __init int padata_driver_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "padata:online",
+				      padata_cpu_online,
+				      padata_cpu_prep_down);
+	if (ret < 0)
+		return ret;
+	hp_online = ret;
+	return 0;
+}
+module_init(padata_driver_init);
+
+static __exit void padata_driver_exit(void)
+{
+	cpuhp_remove_multi_state(hp_online);
+}
+module_exit(padata_driver_exit);
+#endif

  reply	other threads:[~2016-09-19 19:58 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06 17:04 cpu hotplug: convert more drivers (batch #3) Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 01/21] arm64: FP/SIMD: Convert to hotplug state machine Sebastian Andrzej Siewior
2016-09-06 18:14   ` Will Deacon
2016-09-19 19:51   ` [tip:smp/hotplug] arm64/FP/SIMD: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 02/21] ARM: shmobile: " Sebastian Andrzej Siewior
2016-09-06 18:05   ` Geert Uytterhoeven
2016-09-07 13:58     ` Sebastian Andrzej Siewior
2016-09-19 19:52   ` [tip:smp/hotplug] ARM/shmobile: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 03/21] ARM: OMAP: wakeupgen: " Sebastian Andrzej Siewior
2016-09-13 22:24   ` Tony Lindgren
2016-09-19 19:52   ` [tip:smp/hotplug] ARM/OMAP/wakeupgen: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 04/21] ia64: mca: " Sebastian Andrzej Siewior
2016-09-19 19:53   ` [tip:smp/hotplug] ia64/mca: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 05/21] sh: SH-X3 SMP: " Sebastian Andrzej Siewior
2016-09-19 19:53   ` [tip:smp/hotplug] sh/SH-X3 " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 06/21] x86: microcode: " Sebastian Andrzej Siewior
2016-09-07 11:36   ` Borislav Petkov
2016-09-07 14:51     ` Sebastian Andrzej Siewior
2016-09-07 16:02       ` Borislav Petkov
2016-09-07 16:45     ` [PATCH 06/21 v2] " Sebastian Andrzej Siewior
2016-09-19 19:54       ` [tip:smp/hotplug] x86/microcode: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 07/21] lib: irq_poll: " Sebastian Andrzej Siewior
2016-09-19 19:54   ` [tip:smp/hotplug] lib/irq_poll: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 08/21] block: softirq: " Sebastian Andrzej Siewior
2016-09-19 19:55   ` [tip:smp/hotplug] block/softirq: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 09/21] oprofile: timer: " Sebastian Andrzej Siewior
2016-09-19 19:55   ` [tip:smp/hotplug] oprofile/timer: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 10/21] virtio scsi: " Sebastian Andrzej Siewior
2016-09-19 19:56   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 11/21] ACPI: processor: " Sebastian Andrzej Siewior
2016-09-06 21:08   ` Rafael J. Wysocki
2016-09-07 14:01     ` Sebastian Andrzej Siewior
2016-09-07 15:59       ` Rafael J. Wysocki
2016-09-19 19:56   ` [tip:smp/hotplug] ACPI/processor: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 12/21] cpufreq: " Sebastian Andrzej Siewior
2016-09-06 21:27   ` Rafael J. Wysocki
2016-09-07 14:18     ` Sebastian Andrzej Siewior
2016-09-07 15:58       ` Rafael J. Wysocki
2016-09-19 19:56   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-09-20 14:56     ` [PATCH] cpufreq: fix up conversion " Sebastian Andrzej Siewior
2016-09-20 15:07       ` [tip:smp/hotplug] cpufreq: Fix " tip-bot for Sebastian Andrzej Siewior
2016-09-20 16:08         ` Borislav Petkov
2016-09-20 16:17       ` [PATCH] cpufreq: fix " Rafael J. Wysocki
2016-09-06 17:04 ` [PATCH 13/21] padata: Convert " Sebastian Andrzej Siewior
2016-09-19 19:57   ` tip-bot for Sebastian Andrzej Siewior [this message]
2016-09-06 17:04 ` [PATCH 14/21] fault-injection: cpu: " Sebastian Andrzej Siewior
2016-09-19 19:57   ` [tip:smp/hotplug] fault-injection/cpu: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 15/21] mips: octeon: smp: " Sebastian Andrzej Siewior
2016-09-07  8:24   ` Matt Redfearn
2016-09-07 14:27     ` Sebastian Andrzej Siewior
2016-09-08  8:34       ` Matt Redfearn
2016-09-19 15:10   ` Ralf Baechle
2016-09-19 19:58   ` [tip:smp/hotplug] mips/octeon/smp: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 16/21] mips: loongson: smp: " Sebastian Andrzej Siewior
2016-09-19 15:10   ` Ralf Baechle
2016-09-19 19:58   ` [tip:smp/hotplug] mips/loongson/smp: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 17/21] s390: mm: pfault: " Sebastian Andrzej Siewior
2016-09-19 19:59   ` [tip:smp/hotplug] s390/mm/pfault: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 18/21] x86: apic: uv: " Sebastian Andrzej Siewior
2016-09-19 19:59   ` [tip:smp/hotplug] x86/apic/uv: " tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 19/21] blk: mq: reserve hotplug ID states for block Sebastian Andrzej Siewior
2016-09-19 20:03   ` [tip:smp/hotplug] blk/mq: Reserve hotplug ID states for block multiqueue tip-bot for Sebastian Andrzej Siewior
2016-09-19 21:24   ` [tip:smp/hotplug] blk/mq: Reserve hotplug " tip-bot for Sebastian Andrzej Siewior
2016-09-21  7:45   ` tip-bot for Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 20/21] blk: mq: cpu-notif: Convert to hotplug state machine Sebastian Andrzej Siewior
2016-09-06 17:04 ` [PATCH 21/21] blk: mq: " Sebastian Andrzej Siewior

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=tip-30e92153b4e6f1cd01e30c34d9ef6f0986f96b0e@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bigeasy@linutronix.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=steffen.klassert@secunet.com \
    --cc=tglx@linutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).