Skip to content

Commit 30e9215

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
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>
1 parent 27622b0 commit 30e9215

2 files changed

Lines changed: 51 additions & 39 deletions

File tree

‎include/linux/padata.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct parallel_data {
151151
* @flags: padata flags.
152152
*/
153153
struct padata_instance {
154-
struct notifier_block cpu_notifier;
154+
struct hlist_node node;
155155
struct workqueue_struct *wq;
156156
struct parallel_data *pd;
157157
struct padata_cpumask cpumask;

‎kernel/padata.c‎

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/slab.h>
3131
#include <linux/sysfs.h>
3232
#include <linux/rcupdate.h>
33+
#include <linux/module.h>
3334

3435
#define MAX_OBJ_NUM 1000
3536

@@ -769,52 +770,43 @@ static inline int pinst_has_cpu(struct padata_instance *pinst, int cpu)
769770
cpumask_test_cpu(cpu, pinst->cpumask.cbcpu);
770771
}
771772

772-
773-
static int padata_cpu_callback(struct notifier_block *nfb,
774-
unsigned long action, void *hcpu)
773+
static int padata_cpu_online(unsigned int cpu, struct hlist_node *node)
775774
{
776-
int err;
777775
struct padata_instance *pinst;
778-
int cpu = (unsigned long)hcpu;
776+
int ret;
779777

780-
pinst = container_of(nfb, struct padata_instance, cpu_notifier);
778+
pinst = hlist_entry_safe(node, struct padata_instance, node);
779+
if (!pinst_has_cpu(pinst, cpu))
780+
return 0;
781781

782-
switch (action) {
783-
case CPU_ONLINE:
784-
case CPU_ONLINE_FROZEN:
785-
case CPU_DOWN_FAILED:
786-
case CPU_DOWN_FAILED_FROZEN:
787-
if (!pinst_has_cpu(pinst, cpu))
788-
break;
789-
mutex_lock(&pinst->lock);
790-
err = __padata_add_cpu(pinst, cpu);
791-
mutex_unlock(&pinst->lock);
792-
if (err)
793-
return notifier_from_errno(err);
794-
break;
782+
mutex_lock(&pinst->lock);
783+
ret = __padata_add_cpu(pinst, cpu);
784+
mutex_unlock(&pinst->lock);
785+
return ret;
786+
}
795787

796-
case CPU_DOWN_PREPARE:
797-
case CPU_DOWN_PREPARE_FROZEN:
798-
case CPU_UP_CANCELED:
799-
case CPU_UP_CANCELED_FROZEN:
800-
if (!pinst_has_cpu(pinst, cpu))
801-
break;
802-
mutex_lock(&pinst->lock);
803-
err = __padata_remove_cpu(pinst, cpu);
804-
mutex_unlock(&pinst->lock);
805-
if (err)
806-
return notifier_from_errno(err);
807-
break;
808-
}
788+
static int padata_cpu_prep_down(unsigned int cpu, struct hlist_node *node)
789+
{
790+
struct padata_instance *pinst;
791+
int ret;
792+
793+
pinst = hlist_entry_safe(node, struct padata_instance, node);
794+
if (!pinst_has_cpu(pinst, cpu))
795+
return 0;
809796

810-
return NOTIFY_OK;
797+
mutex_lock(&pinst->lock);
798+
ret = __padata_remove_cpu(pinst, cpu);
799+
mutex_unlock(&pinst->lock);
800+
return ret;
811801
}
802+
803+
static enum cpuhp_state hp_online;
812804
#endif
813805

814806
static void __padata_free(struct padata_instance *pinst)
815807
{
816808
#ifdef CONFIG_HOTPLUG_CPU
817-
unregister_hotcpu_notifier(&pinst->cpu_notifier);
809+
cpuhp_state_remove_instance_nocalls(hp_online, &pinst->node);
818810
#endif
819811

820812
padata_stop(pinst);
@@ -1012,11 +1004,8 @@ struct padata_instance *padata_alloc(struct workqueue_struct *wq,
10121004
mutex_init(&pinst->lock);
10131005

10141006
#ifdef CONFIG_HOTPLUG_CPU
1015-
pinst->cpu_notifier.notifier_call = padata_cpu_callback;
1016-
pinst->cpu_notifier.priority = 0;
1017-
register_hotcpu_notifier(&pinst->cpu_notifier);
1007+
cpuhp_state_add_instance_nocalls(hp_online, &pinst->node);
10181008
#endif
1019-
10201009
return pinst;
10211010

10221011
err_free_masks:
@@ -1039,3 +1028,26 @@ void padata_free(struct padata_instance *pinst)
10391028
kobject_put(&pinst->kobj);
10401029
}
10411030
EXPORT_SYMBOL(padata_free);
1031+
1032+
#ifdef CONFIG_HOTPLUG_CPU
1033+
1034+
static __init int padata_driver_init(void)
1035+
{
1036+
int ret;
1037+
1038+
ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "padata:online",
1039+
padata_cpu_online,
1040+
padata_cpu_prep_down);
1041+
if (ret < 0)
1042+
return ret;
1043+
hp_online = ret;
1044+
return 0;
1045+
}
1046+
module_init(padata_driver_init);
1047+
1048+
static __exit void padata_driver_exit(void)
1049+
{
1050+
cpuhp_remove_multi_state(hp_online);
1051+
}
1052+
module_exit(padata_driver_exit);
1053+
#endif

0 commit comments

Comments
 (0)