Skip to contentSkip to conversation

cpuhotplug: Convert all priority notifiers to the state machine

PATCH Superseded Anna-Maria Gleixner 14 participants 102 messages Jul 11, 2016 – Aug 19, 2016

Subsystems (43)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anna-Maria Gleixner

author maintainer
#0 lore raw

cover cpuhotplug: Convert all priority notifiers to the state machine

This series is the next step towards a state machine based hotplug machinery.

It converts all notifiers which have a priority assigned and gets rid of the CPU_STARTING/DYING notifiers.

Thanks,

Anna-Maria

---
 arch/arc/kernel/time.c                        |   32 ++--
 arch/arm/kernel/smp_twd.c                     |   31 +---
 arch/arm/mach-mvebu/coherency.c               |   19 --
 arch/arm/mm/cache-l2x0.c                      |   27 +--
 arch/arm/vfp/vfpmodule.c                      |   28 ++--
 arch/arm/xen/enlighten.c                      |   41 +----
 arch/arm64/kernel/armv8_deprecated.c          |   22 ---
 arch/blackfin/kernel/perf_event.c             |   26 ---
 arch/metag/kernel/perf/perf_event.c           |   26 +--
 arch/mips/oprofile/op_model_loongson3.c       |   35 ++---
 arch/powerpc/mm/numa.c                        |   46 ++----
 arch/powerpc/perf/core-book3s.c               |   30 +---
 arch/s390/kernel/perf_cpum_cf.c               |   44 ++----
 arch/s390/kernel/perf_cpum_sf.c               |   43 ++----
 arch/sh/kernel/perf_event.c                   |   23 ---
 arch/sparc/kernel/smp_32.c                    |    2 
 arch/x86/entry/vdso/vma.c                     |   20 --
 arch/x86/events/amd/ibs.c                     |   64 ++++-----
 arch/x86/events/amd/power.c                   |   60 +-------
 arch/x86/events/intel/cqm.c                   |   49 ++-----
 arch/x86/events/intel/cstate.c                |   51 ++-----
 arch/x86/events/intel/rapl.c                  |   84 +++---------
 arch/x86/events/intel/uncore.c                |  133 ++++++-------------
 arch/x86/kernel/apb_timer.c                   |   29 +---
 arch/x86/kernel/apic/x2apic_cluster.c         |   80 ++++-------
 arch/x86/kernel/hpet.c                        |   69 ++++-----
 arch/x86/kernel/tboot.c                       |   25 +--
 arch/x86/kvm/x86.c                            |   35 +----
 arch/xtensa/kernel/perf_event.c               |   26 +--
 b/arch/x86/events/amd/core.c                  |    6 
 b/arch/x86/events/amd/uncore.c                |  122 ++++-------------
 b/arch/x86/events/core.c                      |  103 +++++++++-----
 b/arch/x86/events/intel/core.c                |    4 
 drivers/acpi/processor_driver.c               |   11 -
 drivers/bus/arm-cci.c                         |   54 ++-----
 drivers/bus/arm-ccn.c                         |   47 +++---
 drivers/clocksource/arm_arch_timer.c          |   54 +++----
 drivers/clocksource/arm_global_timer.c        |   41 +----
 drivers/clocksource/dummy_timer.c             |   36 -----
 drivers/clocksource/exynos_mct.c              |   48 +-----
 drivers/clocksource/metag_generic.c           |   33 ----
 drivers/clocksource/mips-gic-timer.c          |   38 +----
 drivers/clocksource/qcom-timer.c              |   41 +----
 drivers/clocksource/time-armada-370-xp.c      |   44 ++----
 drivers/clocksource/timer-atlas7.c            |   41 +----
 drivers/hwtracing/coresight/coresight-etm3x.c |   90 +++++++-----
 drivers/hwtracing/coresight/coresight-etm4x.c |   93 +++++++------
 drivers/irqchip/irq-armada-370-xp.c           |   44 ++----
 drivers/irqchip/irq-bcm2836.c                 |   34 +---
 drivers/irqchip/irq-gic-v3.c                  |   22 +--
 drivers/irqchip/irq-gic.c                     |   23 ---
 drivers/irqchip/irq-hip04.c                   |   25 ---
 drivers/leds/trigger/ledtrig-cpu.c            |   32 ++--
 drivers/perf/arm_pmu.c                        |   36 ++---
 include/linux/cpu.h                           |   23 ---
 include/linux/cpuhotplug.h                    |   78 +++++++++++
 include/linux/hrtimer.h                       |    7 +
 include/linux/perf/arm_pmu.h                  |    1 
 include/linux/perf_event.h                    |   44 +-----
 include/linux/rcutree.h                       |   15 ++
 include/linux/smp.h                           |    5 
 include/linux/timer.h                         |    6 
 include/linux/workqueue.h                     |    6 
 kernel/cpu.c                                  |   83 ++++++++---
 kernel/events/core.c                          |   56 +-------
 kernel/profile.c                              |  181 +++++++++-----------------
 kernel/rcu/tree.c                             |  105 +++++++--------
 kernel/smp.c                                  |   79 ++++-------
 kernel/time/hrtimer.c                         |   40 -----
 kernel/time/timer.c                           |   25 ---
 kernel/workqueue.c                            |  108 ++++++---------
 tools/testing/radix-tree/linux/cpu.h          |   13 -
 virt/kvm/arm/arch_timer.c                     |   35 +----
 virt/kvm/arm/vgic.c                           |   39 +----
 virt/kvm/arm/vgic/vgic-init.c                 |   31 +---
 virt/kvm/kvm_main.c                           |   32 +---
 76 files changed, 1271 insertions(+), 2063 deletions(-)
author maintainer
#1 lore raw

PATCH 1/66 x86/vdso: Convert to hotplug state machine

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/entry/vdso/vma.c  |   20 ++++----------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/entry/vdso/vma.c +4 -16
@@ -294,15 +294,9 @@ static void vgetcpu_cpu_init(void *arg)
 	write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_PER_CPU, &d, DESCTYPE_S);
 }
 
-static int
-vgetcpu_cpu_notifier(struct notifier_block *n, unsigned long action, void *arg)
+static int vgetcpu_online(unsigned int cpu)
 {
-	long cpu = (long)arg;
-
-	if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN)
-		smp_call_function_single(cpu, vgetcpu_cpu_init, NULL, 1);
-
-	return NOTIFY_DONE;
+	return smp_call_function_single(cpu, vgetcpu_cpu_init, NULL, 1);
 }
 
 static int __init init_vdso(void)
@@ -313,15 +307,9 @@ static int __init init_vdso(void)
 	init_vdso_image(&vdso_image_x32);
 #endif
 
-	cpu_notifier_register_begin();
-
-	on_each_cpu(vgetcpu_cpu_init, NULL, 1);
 	/* notifier priority > KVM */
-	__hotcpu_notifier(vgetcpu_cpu_notifier, 30);
-
-	cpu_notifier_register_done();
-
-	return 0;
+	return cpuhp_setup_state(CPUHP_AP_X86_VDSO_VMA_ONLINE,
+				 "AP_X86_VDSO_VMA_ONLINE", vgetcpu_online, NULL);
 }
 subsys_initcall(init_vdso);
 #endif /* CONFIG_X86_64 */
include/linux/cpuhotplug.h +1 -0
@@ -14,6 +14,7 @@ enum cpuhp_state {
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
 	CPUHP_AP_SMPBOOT_THREADS,
+	CPUHP_AP_X86_VDSO_VMA_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#3 lore raw

PATCH 2/66 irqchip/gic: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

More or less straightforward, although this driver sports some very interesting SMP setup code. Regarding the callback ordering, this deleted comment is interesting:

... the GIC needs to be up before the ARM generic timers.

That comment is half baken as the same requirement is true for perf.

---
 drivers/irqchip/irq-gic.c  |   23 ++++++-----------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 7 insertions(+), 17 deletions(-)
drivers/irqchip/irq-gic.c +6 -17
@@ -984,25 +984,12 @@ static int gic_irq_domain_translate(stru
 	return -EINVAL;
 }
 
-#ifdef CONFIG_SMP
-static int gic_secondary_init(struct notifier_block *nfb, unsigned long action,
-			      void *hcpu)
+static int gic_starting_cpu(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		gic_cpu_init(&gic_data[0]);
-	return NOTIFY_OK;
+	gic_cpu_init(&gic_data[0]);
+	return 0;
 }
 
-/*
- * Notifier for enabling the GIC CPU interface. Set an arbitrarily high
- * priority because the GIC needs to be up before the ARM generic timers.
- */
-static struct notifier_block gic_cpu_notifier = {
-	.notifier_call = gic_secondary_init,
-	.priority = 100,
-};
-#endif
-
 static int gic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
 				unsigned int nr_irqs, void *arg)
 {
@@ -1148,8 +1135,10 @@ static int __init __gic_init_bases(struc
 			gic_cpu_map[i] = 0xff;
 #ifdef CONFIG_SMP
 		set_smp_cross_call(gic_raise_softirq);
-		register_cpu_notifier(&gic_cpu_notifier);
 #endif
+		cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_GIC_STARTING,
+					  "AP_IRQ_GIC_STARTING",
+					  gic_starting_cpu, NULL);
 		set_handle_irq(gic_handle_irq);
 		if (static_key_true(&supports_deactivate))
 			pr_info("GIC: Using split EOI/Deactivate mode\n");
include/linux/cpuhotplug.h +1 -0
@@ -9,6 +9,7 @@ enum cpuhp_state {
 	CPUHP_AP_IDLE_DEAD,
 	CPUHP_AP_OFFLINE,
 	CPUHP_AP_SCHED_STARTING,
+	CPUHP_AP_IRQ_GIC_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
Acked-by Richard Cochran on v1 2/66
#4 lore raw

Re: [patch 02/66] irqchip/gic: Convert to hotplug state machine

Quoted 6 lines · Anna-Maria Gleixner

More or less straightforward, although this driver sports some very interesting SMP setup code. Regarding the callback ordering, this deleted comment is interesting:

... the GIC needs to be up before the ARM generic timers.

Quoted 7 lines

That comment is half baken as the same requirement is true for perf.

The SOB sequence is unusal. Is this patch missing this line:

From: Richard Cochran <[email protected]>

... or should the SOB be:

?

Thanks,

Ingo

author maintainer
#5 lore raw

Re: [patch 02/66] irqchip/gic: Convert to hotplug state machine

Quoted 17 lines · Ingo Molnar
Quoted 6 lines · Anna-Maria Gleixner

More or less straightforward, although this driver sports some very interesting SMP setup code. Regarding the callback ordering, this deleted comment is interesting:

... the GIC needs to be up before the ARM generic timers.

Quoted 7 lines

That comment is half baken as the same requirement is true for perf.

Quoted 4 lines

The SOB sequence is unusal. Is this patch missing this line:

From: Richard Cochran <[email protected]>

This line is missing.

Thanks,
Anna-Maria

author maintainer
#6 lore raw

PATCH 3/66 irqchip/gicv3: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine.

---
 drivers/irqchip/irq-gic-v3.c |   22 +++++++---------------
 include/linux/cpuhotplug.h   |    1 +
 2 files changed, 8 insertions(+), 15 deletions(-)
drivers/irqchip/irq-gic-v3.c +7 -15
@@ -538,23 +538,13 @@ static void gic_cpu_init(void)
 }
 
 #ifdef CONFIG_SMP
-static int gic_secondary_init(struct notifier_block *nfb,
-			      unsigned long action, void *hcpu)
+
+static int gic_starting_cpu(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		gic_cpu_init();
-	return NOTIFY_OK;
+	gic_cpu_init();
+	return 0;
 }
 
-/*
- * Notifier for enabling the GIC CPU interface. Set an arbitrarily high
- * priority because the GIC needs to be up before the ARM generic timers.
- */
-static struct notifier_block gic_cpu_notifier = {
-	.notifier_call = gic_secondary_init,
-	.priority = 100,
-};
-
 static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
 				   unsigned long cluster_id)
 {
@@ -634,7 +624,9 @@ static void gic_raise_softirq(const stru
 static void gic_smp_init(void)
 {
 	set_smp_cross_call(gic_raise_softirq);
-	register_cpu_notifier(&gic_cpu_notifier);
+	cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_GICV3_STARTING,
+				  "AP_IRQ_GICV3_STARTING", gic_starting_cpu,
+				  NULL);
 }
 
 static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
include/linux/cpuhotplug.h +1 -0
@@ -10,6 +10,7 @@ enum cpuhp_state {
 	CPUHP_AP_OFFLINE,
 	CPUHP_AP_SCHED_STARTING,
 	CPUHP_AP_IRQ_GIC_STARTING,
+	CPUHP_AP_IRQ_GICV3_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#7 lore raw

PATCH 4/66 irqchip/hip04: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/irqchip/irq-hip04.c |   25 +++++--------------------
 include/linux/cpuhotplug.h  |    1 +
 2 files changed, 6 insertions(+), 20 deletions(-)
drivers/irqchip/irq-hip04.c +5 -20
@@ -342,26 +342,12 @@ static int hip04_irq_domain_xlate(struct
 	return ret;
 }
 
-#ifdef CONFIG_SMP
-static int hip04_irq_secondary_init(struct notifier_block *nfb,
-				    unsigned long action,
-				    void *hcpu)
+static int hip04_irq_starting_cpu(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		hip04_irq_cpu_init(&hip04_data);
-	return NOTIFY_OK;
+	hip04_irq_cpu_init(&hip04_data);
+	return 0;
 }
 
-/*
- * Notifier for enabling the INTC CPU interface. Set an arbitrarily high
- * priority because the GIC needs to be up before the ARM generic timers.
- */
-static struct notifier_block hip04_irq_cpu_notifier = {
-	.notifier_call	= hip04_irq_secondary_init,
-	.priority	= 100,
-};
-#endif
-
 static const struct irq_domain_ops hip04_irq_domain_ops = {
 	.map	= hip04_irq_domain_map,
 	.xlate	= hip04_irq_domain_xlate,
@@ -417,13 +403,12 @@ hip04_of_init(struct device_node *node,
 
 #ifdef CONFIG_SMP
 	set_smp_cross_call(hip04_raise_softirq);
-	register_cpu_notifier(&hip04_irq_cpu_notifier);
 #endif
 	set_handle_irq(hip04_handle_irq);
 
 	hip04_irq_dist_init(&hip04_data);
-	hip04_irq_cpu_init(&hip04_data);
-
+	cpuhp_setup_state(CPUHP_AP_IRQ_HIP04_STARTING, "AP_IRQ_HIP04_STARTING",
+			  hip04_irq_starting_cpu, NULL);
 	return 0;
 }
 IRQCHIP_DECLARE(hip04_intc, "hisilicon,hip04-intc", hip04_of_init);
include/linux/cpuhotplug.h +1 -0
@@ -11,6 +11,7 @@ enum cpuhp_state {
 	CPUHP_AP_SCHED_STARTING,
 	CPUHP_AP_IRQ_GIC_STARTING,
 	CPUHP_AP_IRQ_GICV3_STARTING,
+	CPUHP_AP_IRQ_HIP04_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#8 lore raw

PATCH 5/66 irqchip/armada-370-xp: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine.

---
 drivers/irqchip/irq-armada-370-xp.c |   44 ++++++++++++------------------------
 include/linux/cpuhotplug.h          |    2 +
 2 files changed, 17 insertions(+), 29 deletions(-)
drivers/irqchip/irq-armada-370-xp.c +15 -29
@@ -344,40 +344,22 @@ static void armada_mpic_send_doorbell(co
 	writel((map << 8) | irq, main_int_base +
 		ARMADA_370_XP_SW_TRIG_INT_OFFS);
 }
+#endif
 
-static int armada_xp_mpic_secondary_init(struct notifier_block *nfb,
-					 unsigned long action, void *hcpu)
+static int armada_xp_mpic_starting_cpu(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) {
-		armada_xp_mpic_perf_init();
-		armada_xp_mpic_smp_cpu_init();
-	}
-
-	return NOTIFY_OK;
+	armada_xp_mpic_perf_init();
+	armada_xp_mpic_smp_cpu_init();
+	return 0;
 }
 
-static struct notifier_block armada_370_xp_mpic_cpu_notifier = {
-	.notifier_call = armada_xp_mpic_secondary_init,
-	.priority = 100,
-};
-
-static int mpic_cascaded_secondary_init(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
+static int mpic_cascaded_starting_cpu(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) {
-		armada_xp_mpic_perf_init();
-		enable_percpu_irq(parent_irq, IRQ_TYPE_NONE);
-	}
-
-	return NOTIFY_OK;
+	armada_xp_mpic_perf_init();
+	enable_percpu_irq(parent_irq, IRQ_TYPE_NONE);
+	return 0;
 }
 
-static struct notifier_block mpic_cascaded_cpu_notifier = {
-	.notifier_call = mpic_cascaded_secondary_init,
-	.priority = 100,
-};
-#endif /* CONFIG_SMP */
-
 static const struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
 	.map = armada_370_xp_mpic_irq_map,
 	.xlate = irq_domain_xlate_onecell,
@@ -595,11 +577,15 @@ static int __init armada_370_xp_mpic_of_
 		set_handle_irq(armada_370_xp_handle_irq);
 #ifdef CONFIG_SMP
 		set_smp_cross_call(armada_mpic_send_doorbell);
-		register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier);
+		cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_ARMADA_XP_STARTING,
+					  "AP_IRQ_ARMADA_XP_STARTING",
+					  armada_xp_mpic_starting_cpu, NULL);
 #endif
 	} else {
 #ifdef CONFIG_SMP
-		register_cpu_notifier(&mpic_cascaded_cpu_notifier);
+		cpuhp_setup_state_nocalls(CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
+					  "AP_IRQ_ARMADA_CASC_STARTING",
+					  mpic_cascaded_starting_cpu, NULL);
 #endif
 		irq_set_chained_handler(parent_irq,
 					armada_370_xp_mpic_handle_cascade_irq);
include/linux/cpuhotplug.h +2 -0
@@ -12,6 +12,8 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_GIC_STARTING,
 	CPUHP_AP_IRQ_GICV3_STARTING,
 	CPUHP_AP_IRQ_HIP04_STARTING,
+	CPUHP_AP_IRQ_ARMADA_XP_STARTING,
+	CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#9 lore raw

PATCH 6/66 irqchip/bcm2836: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine.

---
 drivers/irqchip/irq-bcm2836.c |   34 +++++++++++++---------------------
 include/linux/cpuhotplug.h    |    1 +
 2 files changed, 14 insertions(+), 21 deletions(-)
drivers/irqchip/irq-bcm2836.c +13 -21
@@ -202,26 +202,19 @@ static void bcm2836_arm_irqchip_send_ipi
 	}
 }
 
-/* Unmasks the IPI on the CPU when it's online. */
-static int bcm2836_arm_irqchip_cpu_notify(struct notifier_block *nfb,
-					  unsigned long action, void *hcpu)
+static int bcm2836_cpu_starting(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned long)hcpu;
-	unsigned int int_reg = LOCAL_MAILBOX_INT_CONTROL0;
-	unsigned int mailbox = 0;
-
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		bcm2836_arm_irqchip_unmask_per_cpu_irq(int_reg, mailbox, cpu);
-	else if (action == CPU_DYING)
-		bcm2836_arm_irqchip_mask_per_cpu_irq(int_reg, mailbox, cpu);
-
-	return NOTIFY_OK;
+	bcm2836_arm_irqchip_unmask_per_cpu_irq(LOCAL_MAILBOX_INT_CONTROL0, 0,
+					       cpu);
+	return 0;
 }
 
-static struct notifier_block bcm2836_arm_irqchip_cpu_notifier = {
-	.notifier_call = bcm2836_arm_irqchip_cpu_notify,
-	.priority = 100,
-};
+static int bcm2836_cpu_dying(unsigned int cpu)
+{
+	bcm2836_arm_irqchip_mask_per_cpu_irq(LOCAL_MAILBOX_INT_CONTROL0, 0,
+					     cpu);
+	return 0;
+}
 
 #ifdef CONFIG_ARM
 int __init bcm2836_smp_boot_secondary(unsigned int cpu,
@@ -251,10 +244,9 @@ bcm2836_arm_irqchip_smp_init(void)
 {
 #ifdef CONFIG_SMP
 	/* Unmask IPIs to the boot CPU. */
-	bcm2836_arm_irqchip_cpu_notify(&bcm2836_arm_irqchip_cpu_notifier,
-				       CPU_STARTING,
-				       (void *)(uintptr_t)smp_processor_id());
-	register_cpu_notifier(&bcm2836_arm_irqchip_cpu_notifier);
+	cpuhp_setup_state(CPUHP_AP_IRQ_BCM2836_STARTING,
+			  "AP_IRQ_BCM2836_STARTING", bcm2836_cpu_starting,
+			  bcm2836_cpu_dying);
 
 	set_smp_cross_call(bcm2836_arm_irqchip_send_ipi);
 
include/linux/cpuhotplug.h +1 -0
@@ -14,6 +14,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_HIP04_STARTING,
 	CPUHP_AP_IRQ_ARMADA_XP_STARTING,
 	CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
+	CPUHP_AP_IRQ_BCM2836_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#10 lore raw

PATCH 7/66 ARM: mvebu: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine.

Cc Andrew Lunn <[email protected]>
Cc Gregory Clement <[email protected]>
Cc Sebastian Hesselbarth <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/mach-mvebu/coherency.c |   19 ++++++-------------
 include/linux/cpuhotplug.h      |    1 +
 2 files changed, 7 insertions(+), 13 deletions(-)
arch/arm/mach-mvebu/coherency.c +6 -13
@@ -111,20 +111,12 @@ static struct notifier_block mvebu_hwcc_
 	.notifier_call = mvebu_hwcc_notifier,
 };
 
-static int armada_xp_clear_shared_l2_notifier_func(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
+static int armada_xp_clear_l2_starting(unsigned int cpu)
 {
-	if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		armada_xp_clear_shared_l2();
-
-	return NOTIFY_OK;
+	armada_xp_clear_shared_l2();
+	return 0;
 }
 
-static struct notifier_block armada_xp_clear_shared_l2_notifier = {
-	.notifier_call = armada_xp_clear_shared_l2_notifier_func,
-	.priority = 100,
-};
-
 static void __init armada_370_coherency_init(struct device_node *np)
 {
 	struct resource res;
@@ -155,8 +147,9 @@ static void __init armada_370_coherency_
 
 	of_node_put(cpu_config_np);
 
-	register_cpu_notifier(&armada_xp_clear_shared_l2_notifier);
-
+	cpuhp_setup_state_nocalls(CPUHP_AP_ARM_MVEBU_COHERENCY,
+				  "AP_ARM_MVEBU_COHERENCY",
+				  armada_xp_clear_l2_starting, NULL);
 exit:
 	set_cpu_coherent();
 }
include/linux/cpuhotplug.h +1 -0
@@ -15,6 +15,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_ARMADA_XP_STARTING,
 	CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
 	CPUHP_AP_IRQ_BCM2836_STARTING,
+	CPUHP_AP_ARM_MVEBU_COHERENCY,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#11 lore raw

PATCH 8/66 perf: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Actually a nice symmetric startup/teardown pair which fits proper in the state machine concept. In the long run we should be able to invoke the startup callback for the boot CPU via the state machine and get rid of the init function which invokes it on the boot CPU.

Note: This comes actually before the perf hardware callbacks. In the notifier model the hardware callbacks have a higher priority than the core callback. But that's solely for cpu offline so that hardware migration of events happens before the core is notified about the outgoing cpu.

With the symetric state array model we have the ordering

UP: core -> hardware
DOWN: hardware -> core

---
 include/linux/cpuhotplug.h |    2 +
 include/linux/perf_event.h |    9 +++++++
 kernel/cpu.c               |   11 ++++++++
 kernel/events/core.c       |   56 ++++++++-------------------------------------
 4 files changed, 32 insertions(+), 46 deletions(-)
include/linux/cpuhotplug.h +2 -0
@@ -4,6 +4,7 @@
 enum cpuhp_state {
 	CPUHP_OFFLINE,
 	CPUHP_CREATE_THREADS,
+	CPUHP_PERF_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -22,6 +23,7 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE_IDLE,
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_X86_VDSO_VMA_ONLINE,
+	CPUHP_AP_PERF_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
include/linux/perf_event.h +9 -0
@@ -1354,4 +1354,13 @@ static ssize_t								\
 									\
 static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
 
+/* Performance counter hotplug functions */
+#ifdef CONFIG_PERF_EVENTS
+int perf_event_init_cpu(unsigned int cpu);
+int perf_event_exit_cpu(unsigned int cpu);
+#else
+#define perf_event_init_cpu	NULL
+#define perf_event_exit_cpu	NULL
+#endif
+
 #endif /* _LINUX_PERF_EVENT_H */
kernel/cpu.c +11 -0
@@ -1173,6 +1173,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.teardown		= NULL,
 		.cant_stop		= true,
 	},
+	[CPUHP_PERF_PREPARE] = {
+		.name = "perf prepare",
+		.startup = perf_event_init_cpu,
+		.teardown = perf_event_exit_cpu,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
@@ -1248,6 +1253,12 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup		= smpboot_unpark_threads,
 		.teardown		= NULL,
 	},
+	[CPUHP_AP_PERF_ONLINE] = {
+		.name = "perf online",
+		.startup = perf_event_init_cpu,
+		.teardown = perf_event_exit_cpu,
+	},
+
 	/*
 	 * Online/down_prepare notifiers. Will be removed once the notifiers
 	 * are converted to states.
kernel/events/core.c +10 -46

90 lines not on this page · raw message

author maintainer
#12 lore raw

PATCH 9/66 perf/x86: Convert the core to the hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Replace the perf_notifier() install mechanism, which invokes magically the callback on the current CPU. Convert the hardware specific callbacks which are invoked from the x86 perf core to return proper error codes instead of totally pointless NOTIFY_BAD return values.

---
 arch/x86/events/amd/core.c   |    6 +-
 arch/x86/events/core.c       |  103 +++++++++++++++++++++++++++----------------
 arch/x86/events/intel/core.c |    4 -
 include/linux/cpuhotplug.h   |    3 +
 4 files changed, 74 insertions(+), 42 deletions(-)
arch/x86/events/amd/core.c +3 -3
@@ -370,13 +370,13 @@ static int amd_pmu_cpu_prepare(int cpu)
 	WARN_ON_ONCE(cpuc->amd_nb);
 
 	if (!x86_pmu.amd_nb_constraints)
-		return NOTIFY_OK;
+		return 0;
 
 	cpuc->amd_nb = amd_alloc_nb(cpu);
 	if (!cpuc->amd_nb)
-		return NOTIFY_BAD;
+		return -ENOMEM;
 
-	return NOTIFY_OK;
+	return 0;
 }
 
 static void amd_pmu_cpu_starting(int cpu)
arch/x86/events/core.c +66 -37

125 lines not on this page · raw message

arch/x86/events/intel/core.c +2 -2
@@ -3050,7 +3050,7 @@ static int intel_pmu_cpu_prepare(int cpu
 		cpuc->excl_thread_id = 0;
 	}
 
-	return NOTIFY_OK;
+	return 0;
 
 err_constraint_list:
 	kfree(cpuc->constraint_list);
@@ -3061,7 +3061,7 @@ static int intel_pmu_cpu_prepare(int cpu
 	cpuc->shared_regs = NULL;
 
 err:
-	return NOTIFY_BAD;
+	return -ENOMEM;
 }
 
 static void intel_pmu_cpu_starting(int cpu)
include/linux/cpuhotplug.h +3 -0
@@ -5,6 +5,7 @@ enum cpuhp_state {
 	CPUHP_OFFLINE,
 	CPUHP_CREATE_THREADS,
 	CPUHP_PERF_PREPARE,
+	CPUHP_PERF_X86_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -17,6 +18,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
 	CPUHP_AP_IRQ_BCM2836_STARTING,
 	CPUHP_AP_ARM_MVEBU_COHERENCY,
+	CPUHP_AP_PERF_X86_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
@@ -24,6 +26,7 @@ enum cpuhp_state {
 	CPUHP_AP_SMPBOOT_THREADS,
 	CPUHP_AP_X86_VDSO_VMA_ONLINE,
 	CPUHP_AP_PERF_ONLINE,
+	CPUHP_AP_PERF_X86_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#13 lore raw

PATCH 10/66 perf/x86/intel/uncore: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Convert the notifiers to state machine states and let the core code do the setup for the already online CPUs. This notifier has a completely undocumented ordering requirement versus perf hardcoded in the notifier priority. This odering is only required for cpu down, so that hardware migration happens before the core is notified about the outgoing cpu.

---
 arch/x86/events/intel/uncore.c |  133 +++++++++++++----------------------------
 include/linux/cpuhotplug.h     |    3 
 2 files changed, 48 insertions(+), 88 deletions(-)
arch/x86/events/intel/uncore.c +45 -88
@@ -1034,7 +1034,7 @@ static void uncore_pci_exit(void)
 	}
 }
 
-static void uncore_cpu_dying(int cpu)
+static int uncore_cpu_dying(unsigned int cpu)
 {
 	struct intel_uncore_type *type, **types = uncore_msr_uncores;
 	struct intel_uncore_pmu *pmu;
@@ -1051,16 +1051,19 @@ static void uncore_cpu_dying(int cpu)
 				uncore_box_exit(box);
 		}
 	}
+	return 0;
 }
 
-static void uncore_cpu_starting(int cpu, bool init)
+static int first_init;
+
+static int uncore_cpu_starting(unsigned int cpu)
 {
 	struct intel_uncore_type *type, **types = uncore_msr_uncores;
 	struct intel_uncore_pmu *pmu;
 	struct intel_uncore_box *box;
 	int i, pkg, ncpus = 1;
 
-	if (init) {
+	if (first_init) {
 		/*
 		 * On init we get the number of online cpus in the package
 		 * and set refcount for all of them.
@@ -1081,9 +1084,11 @@ static void uncore_cpu_starting(int cpu,
 				uncore_box_init(box);
 		}
 	}
+
+	return 0;
 }
 
-static int uncore_cpu_prepare(int cpu)
+static int uncore_cpu_prepare(unsigned int cpu)
 {
 	struct intel_uncore_type *type, **types = uncore_msr_uncores;
 	struct intel_uncore_pmu *pmu;
@@ -1146,13 +1151,13 @@ static void uncore_change_context(struct
 		uncore_change_type_ctx(*uncores, old_cpu, new_cpu);
 }
 
-static void uncore_event_exit_cpu(int cpu)
+static int uncore_event_cpu_offline(unsigned int cpu)
 {
 	int target;
 
 	/* Check if exiting cpu is used for collecting uncore events */
 	if (!cpumask_test_and_clear_cpu(cpu, &uncore_cpu_mask))
-		return;
+		return 0;
 
 	/* Find a new cpu to collect uncore events */
 	target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
@@ -1165,9 +1170,10 @@ static void uncore_event_exit_cpu(int cp
 
 	uncore_change_context(uncore_msr_uncores, cpu, target);
 	uncore_change_context(uncore_pci_uncores, cpu, target);
+	return 0;
 }
 
-static void uncore_event_init_cpu(int cpu)
+static int uncore_event_cpu_online(unsigned int cpu)
 {
 	int target;
 
@@ -1177,50 +1183,15 @@ static void uncore_event_init_cpu(int cp
 	 */
 	target = cpumask_any_and(&uncore_cpu_mask, topology_core_cpumask(cpu));
 	if (target < nr_cpu_ids)
-		return;
+		return 0;
 
 	cpumask_set_cpu(cpu, &uncore_cpu_mask);
 
 	uncore_change_context(uncore_msr_uncores, -1, cpu);
 	uncore_change_context(uncore_pci_uncores, -1, cpu);
+	return 0;
 }
 
-static int uncore_cpu_notifier(struct notifier_block *self,
-			       unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		return notifier_from_errno(uncore_cpu_prepare(cpu));
-
-	case CPU_STARTING:
-		uncore_cpu_starting(cpu, false);
-	case CPU_DOWN_FAILED:
-		uncore_event_init_cpu(cpu);
-		break;
-
-	case CPU_UP_CANCELED:
-	case CPU_DYING:
-		uncore_cpu_dying(cpu);
-		break;
-
-	case CPU_DOWN_PREPARE:
-		uncore_event_exit_cpu(cpu);
-		break;
-	}
-	return NOTIFY_OK;
-}
-
-static struct notifier_block uncore_cpu_nb = {
-	.notifier_call	= uncore_cpu_notifier,
-	/*
-	 * to migrate uncore events, our notifier should be executed
-	 * before perf core's notifier.
-	 */
-	.priority	= CPU_PRI_PERF + 1,
-};
-
 static int __init type_pmu_register(struct intel_uncore_type *type)
 {
 	int i, ret;
@@ -1264,41 +1235,6 @@ static int __init uncore_cpu_init(void)
 	return ret;
 }
 
-static void __init uncore_cpu_setup(void *dummy)
-{
-	uncore_cpu_starting(smp_processor_id(), true);
-}
-
-/* Lazy to avoid allocation of a few bytes for the normal case */
-static __initdata DECLARE_BITMAP(packages, MAX_LOCAL_APIC);
-
-static int __init uncore_cpumask_init(bool msr)
-{
-	unsigned int cpu;
-
-	for_each_online_cpu(cpu) {
-		unsigned int pkg = topology_logical_package_id(cpu);
-		int ret;
-
-		if (test_and_set_bit(pkg, packages))
-			continue;
-		/*
-		 * The first online cpu of each package allocates and takes
-		 * the refcounts for all other online cpus in that package.
-		 * If msrs are not enabled no allocation is required.
-		 */
-		if (msr) {
-			ret = uncore_cpu_prepare(cpu);
-			if (ret)
-				return ret;
-		}
-		uncore_event_init_cpu(cpu);
-		smp_call_function_single(cpu, uncore_cpu_setup, NULL, 1);
-	}
-	__register_cpu_notifier(&uncore_cpu_nb);
-	return 0;
-}
-
 #define X86_UNCORE_MODEL_MATCH(model, init)	\
 	{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&init }
 
@@ -1420,11 +1356,33 @@ static int __init intel_uncore_init(void
 	if (cret && pret)
 		return -ENODEV;
 
-	cpu_notifier_register_begin();
-	ret = uncore_cpumask_init(!cret);
-	if (ret)
-		goto err;
-	cpu_notifier_register_done();
+	/*
+	 * Install callbacks. Core will call them for each online cpu.
+	 *
+	 * The first online cpu of each package allocates and takes
+	 * the refcounts for all other online cpus in that package.
+	 * If msrs are not enabled no allocation is required and
+	 * uncore_cpu_prepare() is not called for each online cpu.
+	 */
+	if (!cret) {
+	       ret = cpuhp_setup_state(CPUHP_PERF_X86_UNCORE_PREP,
+					"PERF_X86_UNCORE_PREP",
+					uncore_cpu_prepare, NULL);
+		if (ret)
+			goto err;
+	} else {
+		cpuhp_setup_state_nocalls(CPUHP_PERF_X86_UNCORE_PREP,
+					  "PERF_X86_UNCORE_PREP",
+					  uncore_cpu_prepare, NULL);
+	}
+	first_init = 1;
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_UNCORE_STARTING,
+			  "AP_PERF_X86_UNCORE_STARTING",
+			  uncore_cpu_starting, uncore_cpu_dying);
+	first_init = 0;
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_UNCORE_ONLINE,
+			  "AP_PERF_X86_UNCORE_ONLINE",
+			  uncore_event_cpu_online, uncore_event_cpu_offline);
 	return 0;
 
 err:
@@ -1432,17 +1390,16 @@ static int __init intel_uncore_init(void
 	on_each_cpu_mask(&uncore_cpu_mask, uncore_exit_boxes, NULL, 1);
 	uncore_types_exit(uncore_msr_uncores);
 	uncore_pci_exit();
-	cpu_notifier_register_done();
 	return ret;
 }
 module_init(intel_uncore_init);
 
 static void __exit intel_uncore_exit(void)
 {
-	cpu_notifier_register_begin();
-	__unregister_cpu_notifier(&uncore_cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_UNCORE_ONLINE);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_UNCORE_STARTING);
+	cpuhp_remove_state_nocalls(CPUHP_PERF_X86_UNCORE_PREP);
 	uncore_types_exit(uncore_msr_uncores);
 	uncore_pci_exit();
-	cpu_notifier_register_done();
 }
 module_exit(intel_uncore_exit);
include/linux/cpuhotplug.h +3 -0
@@ -6,6 +6,7 @@ enum cpuhp_state {
 	CPUHP_CREATE_THREADS,
 	CPUHP_PERF_PREPARE,
 	CPUHP_PERF_X86_PREPARE,
+	CPUHP_PERF_X86_UNCORE_PREP,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -18,6 +19,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_ARMADA_CASC_STARTING,
 	CPUHP_AP_IRQ_BCM2836_STARTING,
 	CPUHP_AP_ARM_MVEBU_COHERENCY,
+	CPUHP_AP_PERF_X86_UNCORE_STARTING,
 	CPUHP_AP_PERF_X86_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
@@ -27,6 +29,7 @@ enum cpuhp_state {
 	CPUHP_AP_X86_VDSO_VMA_ONLINE,
 	CPUHP_AP_PERF_ONLINE,
 	CPUHP_AP_PERF_X86_ONLINE,
+	CPUHP_AP_PERF_X86_UNCORE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#14 lore raw

PATCH 11/66 perf/x86/amd/uncore: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---

 arch/x86/events/amd/uncore.c |  122 +++++++++++--------------------------------
 include/linux/cpuhotplug.h   |    3 +
 2 files changed, 35 insertions(+), 90 deletions(-)
arch/x86/events/amd/uncore.c +32 -90
@@ -358,7 +358,7 @@ amd_uncore_find_online_sibling(struct am
 	return this;
 }
 
-static void amd_uncore_cpu_starting(unsigned int cpu)
+static int amd_uncore_cpu_starting(unsigned int cpu)
 {
 	unsigned int eax, ebx, ecx, edx;
 	struct amd_uncore *uncore;
@@ -384,6 +384,8 @@ static void amd_uncore_cpu_starting(unsi
 		uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_l2);
 		*per_cpu_ptr(amd_uncore_l2, cpu) = uncore;
 	}
+
+	return 0;
 }
 
 static void uncore_online(unsigned int cpu,
@@ -398,13 +400,15 @@ static void uncore_online(unsigned int c
 		cpumask_set_cpu(cpu, uncore->active_mask);
 }
 
-static void amd_uncore_cpu_online(unsigned int cpu)
+static int amd_uncore_cpu_online(unsigned int cpu)
 {
 	if (amd_uncore_nb)
 		uncore_online(cpu, amd_uncore_nb);
 
 	if (amd_uncore_l2)
 		uncore_online(cpu, amd_uncore_l2);
+
+	return 0;
 }
 
 static void uncore_down_prepare(unsigned int cpu,
@@ -433,13 +437,15 @@ static void uncore_down_prepare(unsigned
 	}
 }
 
-static void amd_uncore_cpu_down_prepare(unsigned int cpu)
+static int amd_uncore_cpu_down_prepare(unsigned int cpu)
 {
 	if (amd_uncore_nb)
 		uncore_down_prepare(cpu, amd_uncore_nb);
 
 	if (amd_uncore_l2)
 		uncore_down_prepare(cpu, amd_uncore_l2);
+
+	return 0;
 }
 
 static void uncore_dead(unsigned int cpu, struct amd_uncore * __percpu *uncores)
@@ -454,74 +460,19 @@ static void uncore_dead(unsigned int cpu
 	*per_cpu_ptr(uncores, cpu) = NULL;
 }
 
-static void amd_uncore_cpu_dead(unsigned int cpu)
+static int amd_uncore_cpu_dead(unsigned int cpu)
 {
 	if (amd_uncore_nb)
 		uncore_dead(cpu, amd_uncore_nb);
 
 	if (amd_uncore_l2)
 		uncore_dead(cpu, amd_uncore_l2);
-}
-
-static int
-amd_uncore_cpu_notifier(struct notifier_block *self, unsigned long action,
-			void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		if (amd_uncore_cpu_up_prepare(cpu))
-			return notifier_from_errno(-ENOMEM);
-		break;
-
-	case CPU_STARTING:
-		amd_uncore_cpu_starting(cpu);
-		break;
-
-	case CPU_ONLINE:
-		amd_uncore_cpu_online(cpu);
-		break;
-
-	case CPU_DOWN_PREPARE:
-		amd_uncore_cpu_down_prepare(cpu);
-		break;
-
-	case CPU_UP_CANCELED:
-	case CPU_DEAD:
-		amd_uncore_cpu_dead(cpu);
-		break;
-
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block amd_uncore_cpu_notifier_block = {
-	.notifier_call	= amd_uncore_cpu_notifier,
-	.priority	= CPU_PRI_PERF + 1,
-};
-
-static void __init init_cpu_already_online(void *dummy)
-{
-	unsigned int cpu = smp_processor_id();
-
-	amd_uncore_cpu_starting(cpu);
-	amd_uncore_cpu_online(cpu);
-}
-
-static void cleanup_cpu_online(void *dummy)
-{
-	unsigned int cpu = smp_processor_id();
 
-	amd_uncore_cpu_dead(cpu);
+	return 0;
 }
 
 static int __init amd_uncore_init(void)
 {
-	unsigned int cpu, cpu2;
 	int ret = -ENODEV;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
@@ -558,38 +509,29 @@ static int __init amd_uncore_init(void)
 		ret = 0;
 	}
 
-	if (ret)
-		goto fail_nodev;
-
-	cpu_notifier_register_begin();
-
-	/* init cpus already online before registering for hotplug notifier */
-	for_each_online_cpu(cpu) {
-		ret = amd_uncore_cpu_up_prepare(cpu);
-		if (ret)
-			goto fail_online;
-		smp_call_function_single(cpu, init_cpu_already_online, NULL, 1);
-	}
-
-	__register_cpu_notifier(&amd_uncore_cpu_notifier_block);
-	cpu_notifier_register_done();
-
+	/*
+	 * Install callbacks. Core will call them for each online cpu.
+	 */
+	if (cpuhp_setup_state(CPUHP_PERF_X86_AMD_UNCORE_PREP,
+			      "PERF_X86_AMD_UNCORE_PREP",
+			      amd_uncore_cpu_up_prepare, amd_uncore_cpu_dead))
+		goto fail_l2;
+
+	if (cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
+			      "AP_PERF_X86_AMD_UNCORE_STARTING",
+			      amd_uncore_cpu_starting, NULL))
+		goto fail_prep;
+	if (cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
+			      "AP_PERF_X86_AMD_UNCORE_ONLINE",
+			      amd_uncore_cpu_online,
+			      amd_uncore_cpu_down_prepare))
+		goto fail_start;
 	return 0;
 
-
-fail_online:
-	for_each_online_cpu(cpu2) {
-		if (cpu2 == cpu)
-			break;
-		smp_call_function_single(cpu, cleanup_cpu_online, NULL, 1);
-	}
-	cpu_notifier_register_done();
-
-	/* amd_uncore_nb/l2 should have been freed by cleanup_cpu_online */
-	amd_uncore_nb = amd_uncore_l2 = NULL;
-
-	if (boot_cpu_has(X86_FEATURE_PERFCTR_L2))
-		perf_pmu_unregister(&amd_l2_pmu);
+fail_start:
+	cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING);
+fail_prep:
+	cpuhp_remove_state(CPUHP_PERF_X86_AMD_UNCORE_PREP);
 fail_l2:
 	if (boot_cpu_has(X86_FEATURE_PERFCTR_NB))
 		perf_pmu_unregister(&amd_nb_pmu);
include/linux/cpuhotplug.h +3 -0
@@ -7,6 +7,7 @@ enum cpuhp_state {
 	CPUHP_PERF_PREPARE,
 	CPUHP_PERF_X86_PREPARE,
 	CPUHP_PERF_X86_UNCORE_PREP,
+	CPUHP_PERF_X86_AMD_UNCORE_PREP,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -20,6 +21,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_BCM2836_STARTING,
 	CPUHP_AP_ARM_MVEBU_COHERENCY,
 	CPUHP_AP_PERF_X86_UNCORE_STARTING,
+	CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
 	CPUHP_AP_PERF_X86_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
@@ -30,6 +32,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ONLINE,
 	CPUHP_AP_PERF_X86_ONLINE,
 	CPUHP_AP_PERF_X86_UNCORE_ONLINE,
+	CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#15 lore raw

PATCH 12/66 perf/x86/amd/ibs: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/events/amd/ibs.c  |   64 +++++++++++++++++++--------------------------
 include/linux/cpuhotplug.h |    1 
 2 files changed, 29 insertions(+), 36 deletions(-)
arch/x86/events/amd/ibs.c +28 -36
@@ -721,13 +721,10 @@ static __init int perf_ibs_pmu_init(stru
 	return ret;
 }
 
-static __init int perf_event_ibs_init(void)
+static __init void perf_event_ibs_init(void)
 {
 	struct attribute **attr = ibs_op_format_attrs;
 
-	if (!ibs_caps)
-		return -ENODEV;	/* ibs not supported by the cpu */
-
 	perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch");
 
 	if (ibs_caps & IBS_CAPS_OPCNT) {
@@ -738,13 +735,11 @@ static __init int perf_event_ibs_init(vo
 
 	register_nmi_handler(NMI_LOCAL, perf_ibs_nmi_handler, 0, "perf_ibs");
 	pr_info("perf: AMD IBS detected (0x%08x)\n", ibs_caps);
-
-	return 0;
 }
 
 #else /* defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_AMD) */
 
-static __init int perf_event_ibs_init(void) { return 0; }
+static __init void perf_event_ibs_init(void) { }
 
 #endif
 
@@ -921,7 +916,7 @@ static inline int get_ibs_lvt_offset(voi
 	return val & IBSCTL_LVT_OFFSET_MASK;
 }
 
-static void setup_APIC_ibs(void *dummy)
+static void setup_APIC_ibs(void)
 {
 	int offset;
 
@@ -936,7 +931,7 @@ static void setup_APIC_ibs(void *dummy)
 		smp_processor_id());
 }
 
-static void clear_APIC_ibs(void *dummy)
+static void clear_APIC_ibs(void)
 {
 	int offset;
 
@@ -945,18 +940,24 @@ static void clear_APIC_ibs(void *dummy)
 		setup_APIC_eilvt(offset, 0, APIC_EILVT_MSG_FIX, 1);
 }
 
+static int x86_pmu_amd_ibs_starting_cpu(unsigned int cpu)
+{
+	setup_APIC_ibs();
+	return 0;
+}
+
 #ifdef CONFIG_PM
 
 static int perf_ibs_suspend(void)
 {
-	clear_APIC_ibs(NULL);
+	clear_APIC_ibs();
 	return 0;
 }
 
 static void perf_ibs_resume(void)
 {
 	ibs_eilvt_setup();
-	setup_APIC_ibs(NULL);
+	setup_APIC_ibs();
 }
 
 static struct syscore_ops perf_ibs_syscore_ops = {
@@ -975,27 +976,15 @@ static inline void perf_ibs_pm_init(void
 
 #endif
 
-static int
-perf_ibs_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
+static int x86_pmu_amd_ibs_dying_cpu(unsigned int cpu)
 {
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		setup_APIC_ibs(NULL);
-		break;
-	case CPU_DYING:
-		clear_APIC_ibs(NULL);
-		break;
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	clear_APIC_ibs();
+	return 0;
 }
 
 static __init int amd_ibs_init(void)
 {
 	u32 caps;
-	int ret = -EINVAL;
 
 	caps = __get_ibs_caps();
 	if (!caps)
@@ -1004,22 +993,25 @@ static __init int amd_ibs_init(void)
 	ibs_eilvt_setup();
 
 	if (!ibs_eilvt_valid())
-		goto out;
+		return -EINVAL;
 
 	perf_ibs_pm_init();
-	cpu_notifier_register_begin();
+
 	ibs_caps = caps;
 	/* make ibs_caps visible to other cpus: */
 	smp_mb();
-	smp_call_function(setup_APIC_ibs, NULL, 1);
-	__perf_cpu_notifier(perf_ibs_cpu_notifier);
-	cpu_notifier_register_done();
+	/*
+	 * x86_pmu_amd_ibs_starting_cpu will be called from core on
+	 * all online cpus.
+	 */
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
+			  "AP_PERF_X86_AMD_IBS_STARTING",
+			  x86_pmu_amd_ibs_starting_cpu,
+			  x86_pmu_amd_ibs_dying_cpu);
 
-	ret = perf_event_ibs_init();
-out:
-	if (ret)
-		pr_err("Failed to setup IBS, %d\n", ret);
-	return ret;
+	perf_event_ibs_init();
+
+	return 0;
 }
 
 /* Since we need the pci subsystem to init ibs we can't do this earlier: */
include/linux/cpuhotplug.h +1 -0
@@ -23,6 +23,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_UNCORE_STARTING,
 	CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
 	CPUHP_AP_PERF_X86_STARTING,
+	CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#16 lore raw

PATCH 13/66 perf/x86/intel/rapl: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/events/intel/rapl.c |   84 ++++++++++++-------------------------------
 include/linux/cpuhotplug.h   |    2 +
 2 files changed, 27 insertions(+), 59 deletions(-)
arch/x86/events/intel/rapl.c +25 -59
@@ -555,14 +555,14 @@ const struct attribute_group *rapl_attr_
 	NULL,
 };
 
-static void rapl_cpu_exit(int cpu)
+static int rapl_cpu_offline(unsigned int cpu)
 {
 	struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
 	int target;
 
 	/* Check if exiting cpu is used for collecting rapl events */
 	if (!cpumask_test_and_clear_cpu(cpu, &rapl_cpu_mask))
-		return;
+		return 0;
 
 	pmu->cpu = -1;
 	/* Find a new cpu to collect rapl events */
@@ -574,9 +574,10 @@ static void rapl_cpu_exit(int cpu)
 		pmu->cpu = target;
 		perf_pmu_migrate_context(pmu->pmu, cpu, target);
 	}
+	return 0;
 }
 
-static void rapl_cpu_init(int cpu)
+static int rapl_cpu_online(unsigned int cpu)
 {
 	struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
 	int target;
@@ -587,13 +588,14 @@ static void rapl_cpu_init(int cpu)
 	 */
 	target = cpumask_any_and(&rapl_cpu_mask, topology_core_cpumask(cpu));
 	if (target < nr_cpu_ids)
-		return;
+		return 0;
 
 	cpumask_set_cpu(cpu, &rapl_cpu_mask);
 	pmu->cpu = cpu;
+	return 0;
 }
 
-static int rapl_cpu_prepare(int cpu)
+static int rapl_cpu_prepare(unsigned int cpu)
 {
 	struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
 
@@ -614,33 +616,6 @@ static int rapl_cpu_prepare(int cpu)
 	return 0;
 }
 
-static int rapl_cpu_notifier(struct notifier_block *self,
-			     unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		rapl_cpu_prepare(cpu);
-		break;
-
-	case CPU_DOWN_FAILED:
-	case CPU_ONLINE:
-		rapl_cpu_init(cpu);
-		break;
-
-	case CPU_DOWN_PREPARE:
-		rapl_cpu_exit(cpu);
-		break;
-	}
-	return NOTIFY_OK;
-}
-
-static struct notifier_block rapl_cpu_nb = {
-	.notifier_call	= rapl_cpu_notifier,
-	.priority       = CPU_PRI_PERF + 1,
-};
-
 static int rapl_check_hw_unit(bool apply_quirk)
 {
 	u64 msr_rapl_power_unit_bits;
@@ -691,24 +666,6 @@ static void __init rapl_advertise(void)
 	}
 }
 
-static int __init rapl_prepare_cpus(void)
-{
-	unsigned int cpu, pkg;
-	int ret;
-
-	for_each_online_cpu(cpu) {
-		pkg = topology_logical_package_id(cpu);
-		if (rapl_pmus->pmus[pkg])
-			continue;
-
-		ret = rapl_cpu_prepare(cpu);
-		if (ret)
-			return ret;
-		rapl_cpu_init(cpu);
-	}
-	return 0;
-}
-
 static void cleanup_rapl_pmus(void)
 {
 	int i;
@@ -835,35 +792,44 @@ static int __init rapl_pmu_init(void)
 	if (ret)
 		return ret;
 
-	cpu_notifier_register_begin();
+	/*
+	 * Install callbacks. Core will call them for each online cpu.
+	 */
 
-	ret = rapl_prepare_cpus();
+	ret = cpuhp_setup_state(CPUHP_PERF_X86_RAPL_PREP, "PERF_X86_RAPL_PREP",
+				rapl_cpu_prepare, NULL);
 	if (ret)
 		goto out;
 
+	ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_RAPL_ONLINE,
+				"AP_PERF_X86_RAPL_ONLINE",
+				rapl_cpu_online, rapl_cpu_offline);
+	if (ret)
+		goto out1;
+
 	ret = perf_pmu_register(&rapl_pmus->pmu, "power", -1);
 	if (ret)
-		goto out;
+		goto out2;
 
-	__register_cpu_notifier(&rapl_cpu_nb);
-	cpu_notifier_register_done();
 	rapl_advertise();
 	return 0;
 
+out2:
+	cpuhp_remove_state(CPUHP_AP_PERF_X86_RAPL_ONLINE);
+out1:
+	cpuhp_remove_state(CPUHP_PERF_X86_RAPL_PREP);
 out:
 	pr_warn("Initialization failed (%d), disabled\n", ret);
 	cleanup_rapl_pmus();
-	cpu_notifier_register_done();
 	return ret;
 }
 module_init(rapl_pmu_init);
 
 static void __exit intel_rapl_exit(void)
 {
-	cpu_notifier_register_begin();
-	__unregister_cpu_notifier(&rapl_cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE);
+	cpuhp_remove_state_nocalls(CPUHP_PERF_X86_RAPL_PREP);
 	perf_pmu_unregister(&rapl_pmus->pmu);
 	cleanup_rapl_pmus();
-	cpu_notifier_register_done();
 }
 module_exit(intel_rapl_exit);
include/linux/cpuhotplug.h +2 -0
@@ -8,6 +8,7 @@ enum cpuhp_state {
 	CPUHP_PERF_X86_PREPARE,
 	CPUHP_PERF_X86_UNCORE_PREP,
 	CPUHP_PERF_X86_AMD_UNCORE_PREP,
+	CPUHP_PERF_X86_RAPL_PREP,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -34,6 +35,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_ONLINE,
 	CPUHP_AP_PERF_X86_UNCORE_ONLINE,
 	CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
+	CPUHP_AP_PERF_X86_RAPL_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#17 lore raw

PATCH 14/66 perf/x86/intel/cqm: Convert Intel CQM to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/events/intel/cqm.c |   49 ++++++++++++++++----------------------------
 include/linux/cpuhotplug.h  |    2 +
 2 files changed, 20 insertions(+), 31 deletions(-)
arch/x86/events/intel/cqm.c +18 -31
@@ -1577,7 +1577,7 @@ static inline void cqm_pick_event_reader
 		cpumask_set_cpu(cpu, &cqm_cpumask);
 }
 
-static void intel_cqm_cpu_starting(unsigned int cpu)
+static int intel_cqm_cpu_starting(unsigned int cpu)
 {
 	struct intel_pqr_state *state = &per_cpu(pqr_state, cpu);
 	struct cpuinfo_x86 *c = &cpu_data(cpu);
@@ -1588,39 +1588,26 @@ static void intel_cqm_cpu_starting(unsig
 
 	WARN_ON(c->x86_cache_max_rmid != cqm_max_rmid);
 	WARN_ON(c->x86_cache_occ_scale != cqm_l3_scale);
+
+	cqm_pick_event_reader(cpu);
+	return 0;
 }
 
-static void intel_cqm_cpu_exit(unsigned int cpu)
+static int intel_cqm_cpu_exit(unsigned int cpu)
 {
 	int target;
 
 	/* Is @cpu the current cqm reader for this package ? */
 	if (!cpumask_test_and_clear_cpu(cpu, &cqm_cpumask))
-		return;
+		return 0;
 
 	/* Find another online reader in this package */
 	target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
 
 	if (target < nr_cpu_ids)
 		cpumask_set_cpu(target, &cqm_cpumask);
-}
-
-static int intel_cqm_cpu_notifier(struct notifier_block *nb,
-				  unsigned long action, void *hcpu)
-{
-	unsigned int cpu  = (unsigned long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DOWN_PREPARE:
-		intel_cqm_cpu_exit(cpu);
-		break;
-	case CPU_STARTING:
-		intel_cqm_cpu_starting(cpu);
-		cqm_pick_event_reader(cpu);
-		break;
-	}
 
-	return NOTIFY_OK;
+	return 0;
 }
 
 static const struct x86_cpu_id intel_cqm_match[] = {
@@ -1682,7 +1669,7 @@ static int intel_mbm_init(void)
 static int __init intel_cqm_init(void)
 {
 	char *str = NULL, scale[20];
-	int i, cpu, ret;
+	int cpu, ret;
 
 	if (x86_match_cpu(intel_cqm_match))
 		cqm_enabled = true;
@@ -1705,8 +1692,7 @@ static int __init intel_cqm_init(void)
 	 *
 	 * Also, check that the scales match on all cpus.
 	 */
-	cpu_notifier_register_begin();
-
+	get_online_cpus();
 	for_each_online_cpu(cpu) {
 		struct cpuinfo_x86 *c = &cpu_data(cpu);
 
@@ -1743,11 +1729,6 @@ static int __init intel_cqm_init(void)
 	if (ret)
 		goto out;
 
-	for_each_online_cpu(i) {
-		intel_cqm_cpu_starting(i);
-		cqm_pick_event_reader(i);
-	}
-
 	if (mbm_enabled)
 		ret = intel_mbm_init();
 	if (ret && !cqm_enabled)
@@ -1772,12 +1753,18 @@ static int __init intel_cqm_init(void)
 		pr_info("Intel MBM enabled\n");
 
 	/*
-	 * Register the hot cpu notifier once we are sure cqm
+	 * Setup the hot cpu notifier once we are sure cqm
 	 * is enabled to avoid notifier leak.
 	 */
-	__perf_cpu_notifier(intel_cqm_cpu_notifier);
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_STARTING,
+			  "AP_PERF_X86_CQM_STARTING",
+			  intel_cqm_cpu_starting, NULL);
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_ONLINE, "AP_PERF_X86_CQM_ONLINE",
+			  NULL, intel_cqm_cpu_exit);
+
 out:
-	cpu_notifier_register_done();
+	put_online_cpus();
+
 	if (ret) {
 		kfree(str);
 		cqm_cleanup();
include/linux/cpuhotplug.h +2 -0
@@ -25,6 +25,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
 	CPUHP_AP_PERF_X86_STARTING,
 	CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
+	CPUHP_AP_PERF_X86_CQM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
@@ -36,6 +37,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_UNCORE_ONLINE,
 	CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
 	CPUHP_AP_PERF_X86_RAPL_ONLINE,
+	CPUHP_AP_PERF_X86_CQM_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#18 lore raw

PATCH 15/66 perf/x86/intel/cstate: Convert Intel CSTATE to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/events/intel/cstate.c |   51 ++++++++++++-----------------------------
 include/linux/cpuhotplug.h     |    2 +
 2 files changed, 17 insertions(+), 36 deletions(-)
arch/x86/events/intel/cstate.c +15 -36
@@ -365,7 +365,7 @@ static int cstate_pmu_event_add(struct p
  * Check if exiting cpu is the designated reader. If so migrate the
  * events when there is a valid target available
  */
-static void cstate_cpu_exit(int cpu)
+static int cstate_cpu_exit(unsigned int cpu)
 {
 	unsigned int target;
 
@@ -390,9 +390,10 @@ static void cstate_cpu_exit(int cpu)
 			perf_pmu_migrate_context(&cstate_pkg_pmu, cpu, target);
 		}
 	}
+	return 0;
 }
 
-static void cstate_cpu_init(int cpu)
+static int cstate_cpu_init(unsigned int cpu)
 {
 	unsigned int target;
 
@@ -414,31 +415,10 @@ static void cstate_cpu_init(int cpu)
 				 topology_core_cpumask(cpu));
 	if (has_cstate_pkg && target >= nr_cpu_ids)
 		cpumask_set_cpu(cpu, &cstate_pkg_cpu_mask);
-}
-
-static int cstate_cpu_notifier(struct notifier_block *self,
-			       unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		cstate_cpu_init(cpu);
-		break;
-	case CPU_DOWN_PREPARE:
-		cstate_cpu_exit(cpu);
-		break;
-	default:
-		break;
-	}
-	return NOTIFY_OK;
+	return 0;
 }
 
-static struct notifier_block cstate_cpu_nb = {
-	.notifier_call	= cstate_cpu_notifier,
-	.priority       = CPU_PRI_PERF + 1,
-};
-
 static struct pmu cstate_core_pmu = {
 	.attr_groups	= core_attr_groups,
 	.name		= "cstate_core",
@@ -599,18 +579,20 @@ static inline void cstate_cleanup(void)
 
 static int __init cstate_init(void)
 {
-	int cpu, err;
+	int err;
 
-	cpu_notifier_register_begin();
-	for_each_online_cpu(cpu)
-		cstate_cpu_init(cpu);
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_STARTING,
+			  "AP_PERF_X86_CSTATE_STARTING", cstate_cpu_init,
+			  NULL);
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_ONLINE,
+			  "AP_PERF_X86_CSTATE_ONLINE", NULL, cstate_cpu_exit);
 
 	if (has_cstate_core) {
 		err = perf_pmu_register(&cstate_core_pmu, cstate_core_pmu.name, -1);
 		if (err) {
 			has_cstate_core = false;
 			pr_info("Failed to register cstate core pmu\n");
-			goto out;
+			return err;
 		}
 	}
 
@@ -620,12 +602,10 @@ static int __init cstate_init(void)
 			has_cstate_pkg = false;
 			pr_info("Failed to register cstate pkg pmu\n");
 			cstate_cleanup();
-			goto out;
+			return err;
 		}
 	}
-	__register_cpu_notifier(&cstate_cpu_nb);
-out:
-	cpu_notifier_register_done();
+
 	return err;
 }
 
@@ -651,9 +631,8 @@ module_init(cstate_pmu_init);
 
 static void __exit cstate_pmu_exit(void)
 {
-	cpu_notifier_register_begin();
-	__unregister_cpu_notifier(&cstate_cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_ONLINE);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_STARTING);
 	cstate_cleanup();
-	cpu_notifier_register_done();
 }
 module_exit(cstate_pmu_exit);
include/linux/cpuhotplug.h +2 -0
@@ -26,6 +26,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_STARTING,
 	CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
 	CPUHP_AP_PERF_X86_CQM_STARTING,
+	CPUHP_AP_PERF_X86_CSTATE_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
@@ -38,6 +39,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
 	CPUHP_AP_PERF_X86_RAPL_ONLINE,
 	CPUHP_AP_PERF_X86_CQM_ONLINE,
+	CPUHP_AP_PERF_X86_CSTATE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#19 lore raw

PATCH 16/66 blackfin: perf: Convert hotplug notifier to state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callback via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/blackfin/kernel/perf_event.c |   26 +++++---------------------
 include/linux/cpuhotplug.h        |    1 +
 2 files changed, 6 insertions(+), 21 deletions(-)
arch/blackfin/kernel/perf_event.c +5 -21
@@ -453,29 +453,13 @@ static struct pmu pmu = {
 	.read        = bfin_pmu_read,
 };
 
-static void bfin_pmu_setup(int cpu)
+static int bfin_pmu_prepare_cpu(unsigned int cpu)
 {
 	struct cpu_hw_events *cpuhw = &per_cpu(cpu_hw_events, cpu);
 
+	bfin_write_PFCTL(0);
 	memset(cpuhw, 0, sizeof(struct cpu_hw_events));
-}
-
-static int
-bfin_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		bfin_write_PFCTL(0);
-		bfin_pmu_setup(cpu);
-		break;
-
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	return 0;
 }
 
 static int __init bfin_pmu_init(void)
@@ -491,8 +475,8 @@ static int __init bfin_pmu_init(void)
 
 	ret = perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
 	if (!ret)
-		perf_cpu_notifier(bfin_pmu_notifier);
-
+		cpuhp_setup_state(CPUHP_PERF_BFIN, "PERF_BFIN",
+				  bfin_pmu_prepare_cpu, NULL);
 	return ret;
 }
 early_initcall(bfin_pmu_init);
include/linux/cpuhotplug.h +1 -0
@@ -9,6 +9,7 @@ enum cpuhp_state {
 	CPUHP_PERF_X86_UNCORE_PREP,
 	CPUHP_PERF_X86_AMD_UNCORE_PREP,
 	CPUHP_PERF_X86_RAPL_PREP,
+	CPUHP_PERF_BFIN,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
author maintainer
#20 lore raw

PATCH 17/66 powerpc: perf: Convert book3s notifier to state machine callbacks

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/powerpc/perf/core-book3s.c |   30 +++++++-----------------------
 include/linux/cpuhotplug.h      |    1 +
 2 files changed, 8 insertions(+), 23 deletions(-)
arch/powerpc/perf/core-book3s.c +7 -23
@@ -2158,31 +2158,15 @@ static void perf_event_interrupt(struct
 		irq_exit();
 }
 
-static void power_pmu_setup(int cpu)
+int power_pmu_prepare_cpu(unsigned int cpu)
 {
 	struct cpu_hw_events *cpuhw = &per_cpu(cpu_hw_events, cpu);
 
-	if (!ppmu)
-		return;
-	memset(cpuhw, 0, sizeof(*cpuhw));
-	cpuhw->mmcr[0] = MMCR0_FC;
-}
-
-static int
-power_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		power_pmu_setup(cpu);
-		break;
-
-	default:
-		break;
+	if (ppmu) {
+		memset(cpuhw, 0, sizeof(*cpuhw));
+		cpuhw->mmcr[0] = MMCR0_FC;
 	}
-
-	return NOTIFY_OK;
+	return 0;
 }
 
 int register_power_pmu(struct power_pmu *pmu)
@@ -2205,7 +2189,7 @@ int register_power_pmu(struct power_pmu
 #endif /* CONFIG_PPC64 */
 
 	perf_pmu_register(&power_pmu, "cpu", PERF_TYPE_RAW);
-	perf_cpu_notifier(power_pmu_notifier);
-
+	cpuhp_setup_state(CPUHP_PERF_POWER, "PERF_POWER",
+			  power_pmu_prepare_cpu, NULL);
 	return 0;
 }
include/linux/cpuhotplug.h +1 -0
@@ -10,6 +10,7 @@ enum cpuhp_state {
 	CPUHP_PERF_X86_AMD_UNCORE_PREP,
 	CPUHP_PERF_X86_RAPL_PREP,
 	CPUHP_PERF_BFIN,
+	CPUHP_PERF_POWER,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
author maintainer
#21 lore raw

PATCH 18/66 s390: perf: Convert the hotplug notifier to state machine callbacks (Counter)

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/s390/kernel/perf_cpum_cf.c |   44 ++++++++++++++++------------------------
 include/linux/cpuhotplug.h      |    1 
 2 files changed, 19 insertions(+), 26 deletions(-)
arch/s390/kernel/perf_cpum_cf.c +18 -26
@@ -664,30 +664,22 @@ static struct pmu cpumf_pmu = {
 	.cancel_txn   = cpumf_pmu_cancel_txn,
 };
 
-static int cpumf_pmu_notifier(struct notifier_block *self, unsigned long action,
-			      void *hcpu)
+static int cpumf_pmf_setup(unsigned int cpu, int flags)
 {
-	int flags;
+	local_irq_disable();
+	setup_pmc_cpu(&flags);
+	local_irq_enable();
+	return 0;
+}
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_ONLINE:
-	case CPU_DOWN_FAILED:
-		flags = PMC_INIT;
-		local_irq_disable();
-		setup_pmc_cpu(&flags);
-		local_irq_enable();
-		break;
-	case CPU_DOWN_PREPARE:
-		flags = PMC_RELEASE;
-		local_irq_disable();
-		setup_pmc_cpu(&flags);
-		local_irq_enable();
-		break;
-	default:
-		break;
-	}
+static int s390_pmu_online_cpu(unsigned int cpu)
+{
+	return cpumf_pmf_setup(cpu, PMC_INIT);
+}
 
-	return NOTIFY_OK;
+static int s390_pmu_offline_cpu(unsigned int cpu)
+{
+	return cpumf_pmf_setup(cpu, PMC_RELEASE);
 }
 
 static int __init cpumf_pmu_init(void)
@@ -707,7 +699,7 @@ static int __init cpumf_pmu_init(void)
 	if (rc) {
 		pr_err("Registering for CPU-measurement alerts "
 		       "failed with rc=%i\n", rc);
-		goto out;
+		return rc;
 	}
 
 	cpumf_pmu.attr_groups = cpumf_cf_event_group();
@@ -716,10 +708,10 @@ static int __init cpumf_pmu_init(void)
 		pr_err("Registering the cpum_cf PMU failed with rc=%i\n", rc);
 		unregister_external_irq(EXT_IRQ_MEASURE_ALERT,
 					cpumf_measurement_alert);
-		goto out;
+		return rc;
 	}
-	perf_cpu_notifier(cpumf_pmu_notifier);
-out:
-	return rc;
+	return cpuhp_setup_state(CPUHP_AP_PERF_S390_CF_ONLINE,
+				 "AP_PERF_S390_CF_ONLINE",
+				 s390_pmu_online_cpu, s390_pmu_offline_cpu);
 }
 early_initcall(cpumf_pmu_init);
include/linux/cpuhotplug.h +1 -0
@@ -42,6 +42,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_RAPL_ONLINE,
 	CPUHP_AP_PERF_X86_CQM_ONLINE,
 	CPUHP_AP_PERF_X86_CSTATE_ONLINE,
+	CPUHP_AP_PERF_S390_CF_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#22 lore raw

PATCH 19/66 s390: perf: Convert the hotplug notifier to state machine callbacks (Sampling)

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/s390/kernel/perf_cpum_sf.c |   43 ++++++++++++++++------------------------
 include/linux/cpuhotplug.h      |    1 
 2 files changed, 19 insertions(+), 25 deletions(-)
arch/s390/kernel/perf_cpum_sf.c +18 -25
@@ -1506,37 +1506,28 @@ static void cpumf_measurement_alert(stru
 		sf_disable();
 	}
 }
-
-static int cpumf_pmu_notifier(struct notifier_block *self,
-			      unsigned long action, void *hcpu)
+static int cpusf_pmu_setup(unsigned int cpu, int flags)
 {
-	int flags;
-
 	/* Ignore the notification if no events are scheduled on the PMU.
 	 * This might be racy...
 	 */
 	if (!atomic_read(&num_events))
-		return NOTIFY_OK;
+		return 0;
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_ONLINE:
-	case CPU_DOWN_FAILED:
-		flags = PMC_INIT;
-		local_irq_disable();
-		setup_pmc_cpu(&flags);
-		local_irq_enable();
-		break;
-	case CPU_DOWN_PREPARE:
-		flags = PMC_RELEASE;
-		local_irq_disable();
-		setup_pmc_cpu(&flags);
-		local_irq_enable();
-		break;
-	default:
-		break;
-	}
+	local_irq_disable();
+	setup_pmc_cpu(&flags);
+	local_irq_enable();
+	return 0;
+}
 
-	return NOTIFY_OK;
+static int s390_pmu_sf_online_cpu(unsigned int cpu)
+{
+	return cpusf_pmu_setup(cpu, PMC_INIT);
+}
+
+static int s390_pmu_sf_offline_cpu(unsigned int cpu)
+{
+	return cpusf_pmu_setup(cpu, PMC_RELEASE);
 }
 
 static int param_get_sfb_size(char *buffer, const struct kernel_param *kp)
@@ -1636,7 +1627,9 @@ static int __init init_cpum_sampling_pmu
 					cpumf_measurement_alert);
 		goto out;
 	}
-	perf_cpu_notifier(cpumf_pmu_notifier);
+
+	cpuhp_setup_state(CPUHP_AP_PERF_S390_SF_ONLINE, "AP_PERF_S390_SF_ONLINE",
+			  s390_pmu_sf_online_cpu, s390_pmu_sf_offline_cpu);
 out:
 	return err;
 }
include/linux/cpuhotplug.h +1 -0
@@ -43,6 +43,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CQM_ONLINE,
 	CPUHP_AP_PERF_X86_CSTATE_ONLINE,
 	CPUHP_AP_PERF_S390_CF_ONLINE,
+	CPUHP_AP_PERF_S390_SF_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#23 lore raw

PATCH 20/66 sh: perf: Convert the hotplug notifiers to state machine callbacks

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/sh/kernel/perf_event.c |   23 ++++-------------------
 include/linux/cpuhotplug.h  |    1 +
 2 files changed, 5 insertions(+), 19 deletions(-)
arch/sh/kernel/perf_event.c +4 -19
@@ -352,28 +352,12 @@ static struct pmu pmu = {
 	.read		= sh_pmu_read,
 };
 
-static void sh_pmu_setup(int cpu)
+static int sh_pmu_prepare_cpu(unsigned int cpu)
 {
 	struct cpu_hw_events *cpuhw = &per_cpu(cpu_hw_events, cpu);
 
 	memset(cpuhw, 0, sizeof(struct cpu_hw_events));
-}
-
-static int
-sh_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_UP_PREPARE:
-		sh_pmu_setup(cpu);
-		break;
-
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	return 0;
 }
 
 int register_sh_pmu(struct sh_pmu *_pmu)
@@ -394,6 +378,7 @@ int register_sh_pmu(struct sh_pmu *_pmu)
 	WARN_ON(_pmu->num_events > MAX_HWEVENTS);
 
 	perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
-	perf_cpu_notifier(sh_pmu_notifier);
+	cpuhp_setup_state(CPUHP_PERF_SUPERH, "PERF_SUPERH", sh_pmu_prepare_cpu,
+			  NULL);
 	return 0;
 }
include/linux/cpuhotplug.h +1 -0
@@ -11,6 +11,7 @@ enum cpuhp_state {
 	CPUHP_PERF_X86_RAPL_PREP,
 	CPUHP_PERF_BFIN,
 	CPUHP_PERF_POWER,
+	CPUHP_PERF_SUPERH,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
author maintainer
#24 lore raw

PATCH 21/66 bus: arm-cci: convert to hotplug statemachine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/bus/arm-cci.c      |   54 +++++++++++++++------------------------------
 include/linux/cpuhotplug.h |    1 
 2 files changed, 20 insertions(+), 35 deletions(-)
drivers/bus/arm-cci.c +19 -35
@@ -144,7 +144,6 @@ struct cci_pmu {
 	int num_cntrs;
 	atomic_t active_events;
 	struct mutex reserve_mutex;
-	struct notifier_block cpu_nb;
 	cpumask_t cpus;
 };
 
@@ -1503,31 +1502,22 @@ static int cci_pmu_init(struct cci_pmu *
 	return perf_pmu_register(&cci_pmu->pmu, name, -1);
 }
 
-static int cci_pmu_cpu_notifier(struct notifier_block *self,
-				unsigned long action, void *hcpu)
+static struct cci_pmu *cpuhp_cci_pmu;
+static int cci_pmu_offline_cpu(unsigned int cpu)
 {
-	struct cci_pmu *cci_pmu = container_of(self,
-					struct cci_pmu, cpu_nb);
-	unsigned int cpu = (long)hcpu;
 	unsigned int target;
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DOWN_PREPARE:
-		if (!cpumask_test_and_clear_cpu(cpu, &cci_pmu->cpus))
-			break;
-		target = cpumask_any_but(cpu_online_mask, cpu);
-		if (target >= nr_cpu_ids) // UP, last CPU
-			break;
-		/*
-		 * TODO: migrate context once core races on event->ctx have
-		 * been fixed.
-		 */
-		cpumask_set_cpu(target, &cci_pmu->cpus);
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	if (!cpumask_test_and_clear_cpu(cpu, &cpuhp_cci_pmu->cpus))
+		return 0;
+	target = cpumask_any_but(cpu_online_mask, cpu);
+	if (target >= nr_cpu_ids) // UP, last CPU
+		return 0;
+	/*
+	 * TODO: migrate context once core races on event->ctx have
+	 * been fixed.
+	 */
+	cpumask_set_cpu(target, &cpuhp_cci_pmu->cpus);
+	return 0;
 }
 
 static struct cci_pmu_model cci_pmu_models[] = {
@@ -1765,23 +1755,17 @@ static int cci_pmu_probe(struct platform
 	mutex_init(&cci_pmu->reserve_mutex);
 	atomic_set(&cci_pmu->active_events, 0);
 	cpumask_set_cpu(smp_processor_id(), &cci_pmu->cpus);
-
-	cci_pmu->cpu_nb = (struct notifier_block) {
-		.notifier_call	= cci_pmu_cpu_notifier,
-		/*
-		 * to migrate uncore events, our notifier should be executed
-		 * before perf core's notifier.
-		 */
-		.priority	= CPU_PRI_PERF + 1,
-	};
-
-	ret = register_cpu_notifier(&cci_pmu->cpu_nb);
+	cpuhp_cci_pmu = cci_pmu;
+	ret = cpuhp_setup_state(CPUHP_AP_PERF_ARM_CCI_ONLINE,
+				"AP_PERF_ARM_CCI_ONLINE", NULL,
+				cci_pmu_offline_cpu);
 	if (ret)
 		return ret;
 
 	ret = cci_pmu_init(cci_pmu, pdev);
 	if (ret) {
-		unregister_cpu_notifier(&cci_pmu->cpu_nb);
+		cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE);
+		cpuhp_cci_pmu = NULL;
 		return ret;
 	}
 
include/linux/cpuhotplug.h +1 -0
@@ -45,6 +45,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CSTATE_ONLINE,
 	CPUHP_AP_PERF_S390_CF_ONLINE,
 	CPUHP_AP_PERF_S390_SF_ONLINE,
+	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
author maintainer
#25 lore raw

PATCH 22/66 bus: arm-ccn: convert to hotplug statemachine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/bus/arm-ccn.c      |   47 ++++++++++++++++++++-------------------------
 include/linux/cpuhotplug.h |    2 +
 2 files changed, 23 insertions(+), 26 deletions(-)
drivers/bus/arm-ccn.c +21 -26
@@ -167,7 +167,6 @@ struct arm_ccn_dt {
 	struct hrtimer hrtimer;
 
 	cpumask_t cpu;
-	struct notifier_block cpu_nb;
 
 	struct pmu pmu;
 };
@@ -1171,30 +1170,23 @@ static enum hrtimer_restart arm_ccn_pmu_
 }
 
 
-static int arm_ccn_pmu_cpu_notifier(struct notifier_block *nb,
-		unsigned long action, void *hcpu)
+static struct arm_ccn_dt *cpuhp_armccn_dt;
+static int arm_ccn_pmu_offline_cpu(unsigned int cpu)
 {
-	struct arm_ccn_dt *dt = container_of(nb, struct arm_ccn_dt, cpu_nb);
+	struct arm_ccn_dt *dt = cpuhp_armccn_dt;
 	struct arm_ccn *ccn = container_of(dt, struct arm_ccn, dt);
-	unsigned int cpu = (long)hcpu; /* for (long) see kernel/cpu.c */
 	unsigned int target;
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DOWN_PREPARE:
-		if (!cpumask_test_and_clear_cpu(cpu, &dt->cpu))
-			break;
-		target = cpumask_any_but(cpu_online_mask, cpu);
-		if (target >= nr_cpu_ids)
-			break;
-		perf_pmu_migrate_context(&dt->pmu, cpu, target);
-		cpumask_set_cpu(target, &dt->cpu);
-		if (ccn->irq)
-			WARN_ON(irq_set_affinity_hint(ccn->irq, &dt->cpu) != 0);
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	if (!cpumask_test_and_clear_cpu(cpu, &dt->cpu))
+		return 0;
+	target = cpumask_any_but(cpu_online_mask, cpu);
+	if (target >= nr_cpu_ids)
+		return 0;
+	perf_pmu_migrate_context(&dt->pmu, cpu, target);
+	cpumask_set_cpu(target, &dt->cpu);
+	if (ccn->irq)
+		WARN_ON(irq_set_affinity_hint(ccn->irq, &dt->cpu) != 0);
+	return 0;
 }
 
 
@@ -1270,9 +1262,10 @@ static int arm_ccn_pmu_init(struct arm_c
 	 * ... and change the selection when it goes offline. Priority is
 	 * picked to have a chance to migrate events before perf is notified.
 	 */
-	ccn->dt.cpu_nb.notifier_call = arm_ccn_pmu_cpu_notifier;
-	ccn->dt.cpu_nb.priority = CPU_PRI_PERF + 1,
-	err = register_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_armccn_dt = &ccn->dt;
+	err = cpuhp_setup_state(CPUHP_AP_PERF_ARM_CCN_ONLINE,
+				"AP_PERF_ARM_CCN_ONLINE", NULL,
+				arm_ccn_pmu_offline_cpu);
 	if (err)
 		goto error_cpu_notifier;
 
@@ -1293,7 +1286,8 @@ static int arm_ccn_pmu_init(struct arm_c
 
 error_pmu_register:
 error_set_affinity:
-	unregister_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE);
+	cpuhp_armccn_dt = NULL;
 error_cpu_notifier:
 	ida_simple_remove(&arm_ccn_pmu_ida, ccn->dt.id);
 	for (i = 0; i < ccn->num_xps; i++)
@@ -1308,7 +1302,8 @@ static void arm_ccn_pmu_cleanup(struct a
 
 	if (ccn->irq)
 		irq_set_affinity_hint(ccn->irq, NULL);
-	unregister_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE);
+	cpuhp_armccn_dt = NULL;
 	for (i = 0; i < ccn->num_xps; i++)
 		writel(0, ccn->xp[i].base + CCN_XP_DT_CONTROL);
 	writel(0, ccn->dt.base + CCN_DT_PMCR);
include/linux/cpuhotplug.h +2 -0
@@ -30,6 +30,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
 	CPUHP_AP_PERF_X86_CQM_STARTING,
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
+	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
@@ -46,6 +47,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_S390_CF_ONLINE,
 	CPUHP_AP_PERF_S390_SF_ONLINE,
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
+	CPUHP_AP_PERF_ARM_CCN_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
#26 lore raw

Re: [patch 22/66] bus: arm-ccn: convert to hotplug statemachine

Quoted 8 lines · Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

Although I won't shed a tear over the notifiers going, there's a problem with this patch...

Quoted 9 lines
---
 drivers/bus/arm-ccn.c      |   47 ++++++++++++++++++++--------------
-----------
 include/linux/cpuhotplug.h |    2 +
 2 files changed, 23 insertions(+), 26 deletions(-)

drivers/bus/arm-ccn.c struct arm_ccn_dt { · line 172

Quoted 7 lines
drivers/bus/arm-ccn.c +0 -1
@@ -167,7 +167,6 @@ struct arm_ccn_dt {
 	struct hrtimer hrtimer;
 
 	cpumask_t cpu;
-	struct notifier_block cpu_nb;
 
 	struct pmu pmu;
 };

Notice that here each instance of CCN (unlikely as it is today, the code was written with the assumption that there's more than one interconnect ring in the system) get its own notifier block...

Quoted 4 lines
drivers/bus/arm-ccn.c +0 -0
@@ -1171,30 +1170,23 @@ static enum hrtimer_restart arm_ccn_pmu_
 }
 
 

drivers/bus/arm-ccn.c static enum hrtimer_restart arm_ccn_pmu_ · line 1180

Quoted 10 lines
drivers/bus/arm-ccn.c +3 -4
-static int arm_ccn_pmu_cpu_notifier(struct notifier_block *nb,
-		unsigned long action, void *hcpu)
+static struct arm_ccn_dt *cpuhp_armccn_dt;
+static int arm_ccn_pmu_offline_cpu(unsigned int cpu)
 {
-	struct arm_ccn_dt *dt = container_of(nb, struct arm_ccn_dt,
 cpu_nb);
+	struct arm_ccn_dt *dt = cpuhp_armccn_dt;
 	struct arm_ccn *ccn = container_of(dt, struct arm_ccn, dt);
-	unsigned int cpu = (long)hcpu; /* for (long) see

... but here (and in all the rest of this change) it's replaced by a static pointer to a single instance.

drivers/bus/arm-ccn.c static int arm_ccn_pmu_init(struct arm_c · line 1265

Quoted 10 lines
drivers/bus/arm-ccn.c +0 -0
@@ -1270,9 +1262,10 @@ static int arm_ccn_pmu_init(struct arm_c
 	 * ... and change the selection when it goes offline.

Priority is
* picked to have a chance to migrate events before perf is
notified.

drivers/bus/arm-ccn.c +1 -3
 	 */
-	ccn->dt.cpu_nb.notifier_call = arm_ccn_pmu_cpu_notifier;
-	ccn->dt.cpu_nb.priority = CPU_PRI_PERF + 1,
-	err = register_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_armccn_dt = &ccn->dt;

Even without checking if the pointer has been already set.

drivers/bus/arm-ccn.c static int arm_ccn_pmu_init(struct arm_c · line 1290

Quoted 13 lines
drivers/bus/arm-ccn.c +5 -1
+	err = cpuhp_setup_state(CPUHP_AP_PERF_ARM_CCN_ONLINE,
+				"AP_PERF_ARM_CCN_ONLINE", NULL,
+				arm_ccn_pmu_offline_cpu);
 	if (err)
 		goto error_cpu_notifier;
@@ -1293,7 +1286,8 @@ static int arm_ccn_pmu_init(struct arm_c
 
 error_pmu_register:
 error_set_affinity:
-	unregister_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE);
+	cpuhp_armccn_dt = NULL;

error_cpu_notifier:

drivers/bus/arm-ccn.c static void arm_ccn_pmu_cleanup(struct a · line 1306

Quoted 9 lines
drivers/bus/arm-ccn.c +2 -1
 	ida_simple_remove(&arm_ccn_pmu_ida, ccn->dt.id);
 	for (i = 0; i < ccn->num_xps; i++)
@@ -1308,7 +1302,8 @@ static void arm_ccn_pmu_cleanup(struct a
 
 	if (ccn->irq)
 		irq_set_affinity_hint(ccn->irq, NULL);
-	unregister_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE);
+	cpuhp_armccn_dt = NULL;

Same (only the other way round) here...

include/linux/cpuhotplug.h enum cpuhp_state { · line 36

Quoted 10 lines
include/linux/cpuhotplug.h +1 -0
@@ -30,6 +30,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
 	CPUHP_AP_PERF_X86_CQM_STARTING,
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
+	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,

That chunk does not belong here, does it?

Regards

Pawel

#27 lore raw

Re: [patch 22/66] bus: arm-ccn: convert to hotplug statemachine

In reply to Anna-Maria Gleixner
Quoted 5 lines · Anna-Maria Gleixner
(quoted diff) +0 -0
@@ -1270,9 +1262,10 @@ static int arm_ccn_pmu_init(struct arm_c
 	 * ... and change the selection when it goes offline.

Priority is
* picked to have a chance to migrate events before perf is
notified.

drivers/bus/arm-ccn.c static int arm_ccn_pmu_init(struct arm_c · line 1270

Quoted 10 lines
drivers/bus/arm-ccn.c +4 -3
 	 */
-	ccn->dt.cpu_nb.notifier_call = arm_ccn_pmu_cpu_notifier;
-	ccn->dt.cpu_nb.priority = CPU_PRI_PERF + 1,
-	err = register_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_armccn_dt = &ccn->dt;
+	err = cpuhp_setup_state(CPUHP_AP_PERF_ARM_CCN_ONLINE,
+				"AP_PERF_ARM_CCN_ONLINE", NULL,
+				arm_ccn_pmu_offline_cpu);
 	if (err)
 		goto error_cpu_notifier;

Also, unless I'm missing something obvious, it seems that the callback will be executed for CPUs going online? I'm definitely interested in my "current" CPU going down, in order to migrate my handlers somewhere else.

Help?

Pawel

#28 lore raw

Re: [patch 22/66] bus: arm-ccn: convert to hotplug statemachine

Quoted 22 lines · Pawel Moll
Quoted 5 lines · Anna-Maria Gleixner
(quoted diff) +0 -0
@@ -1270,9 +1262,10 @@ static int arm_ccn_pmu_init(struct arm_c
 	 * ... and change the selection when it goes offline.

Priority is
* picked to have a chance to migrate events before perf is
notified.

drivers/bus/arm-ccn.c static int arm_ccn_pmu_init(struct arm_c · line 1270

Quoted 10 lines
drivers/bus/arm-ccn.c +4 -3
 	 */
-	ccn->dt.cpu_nb.notifier_call = arm_ccn_pmu_cpu_notifier;
-	ccn->dt.cpu_nb.priority = CPU_PRI_PERF + 1,
-	err = register_cpu_notifier(&ccn->dt.cpu_nb);
+	cpuhp_armccn_dt = &ccn->dt;
+	err = cpuhp_setup_state(CPUHP_AP_PERF_ARM_CCN_ONLINE,
+				"AP_PERF_ARM_CCN_ONLINE", NULL,
+				arm_ccn_pmu_offline_cpu);
 	if (err)
 		goto error_cpu_notifier;

Also, unless I'm missing something obvious, it seems that the callback will be executed for CPUs going online? I'm definitely interested in my "current" CPU going down, in order to migrate my handlers somewhere else.

Quoted 1 line

Help?

cpuhp_setup_state() gets two callbacks, online followed by offline (argument three and four). The online callback is NULL so you have only one offline callback.

Quoted 1 line

Pawel

Sebastian

author maintainer
#29 lore raw

PATCH 23/66 xtensa: perf: Convert the hotplug notifier to state machine callbacks

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/xtensa/kernel/perf_event.c |   26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
arch/xtensa/kernel/perf_event.c +9 -17
@@ -404,7 +404,7 @@ static struct pmu xtensa_pmu = {
 	.read = xtensa_pmu_read,
 };
 
-static void xtensa_pmu_setup(void)
+static int xtensa_pmu_setup(int cpu)
 {
 	unsigned i;
 
@@ -413,21 +413,7 @@ static void xtensa_pmu_setup(void)
 		set_er(0, XTENSA_PMU_PMCTRL(i));
 		set_er(get_er(XTENSA_PMU_PMSTAT(i)), XTENSA_PMU_PMSTAT(i));
 	}
-}
-
-static int xtensa_pmu_notifier(struct notifier_block *self,
-			       unsigned long action, void *data)
-{
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		xtensa_pmu_setup();
-		break;
-
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
+	return 0;
 }
 
 static int __init xtensa_pmu_init(void)
@@ -435,7 +421,13 @@ static int __init xtensa_pmu_init(void)
 	int ret;
 	int irq = irq_create_mapping(NULL, XCHAL_PROFILING_INTERRUPT);
 
-	perf_cpu_notifier(xtensa_pmu_notifier);
+	ret = cpuhp_setup_state(CPUHP_AP_PERF_XTENSA_STARTING,
+				"AP_PERF_XTENSA_STARTING", xtensa_pmu_setup,
+				NULL);
+	if (ret) {
+		pr_err("xtensa_pmu: failed to register CPU-hotplug.\n");
+		return ret;
+	}
 #if XTENSA_FAKE_NMI
 	enable_irq(irq);
 #else
author maintainer
#30 lore raw

PATCH 24/66 perf/x86/amd/power: Change hotplug notifier to a symmetric structure

In reply to Anna-Maria Gleixner

From: Anna-Maria Gleixner <[email protected]>

To simplify the hotplug mechanism move the starting callback to online. There is no functional requirement that the cpumask bit has to be set in the starting callback.

---
 arch/x86/events/amd/power.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/events/amd/power.c +2 -2
@@ -255,7 +255,7 @@ static void power_cpu_init(int cpu)
 	 * 1) If any CPU is set at cpu_mask in the same compute unit, do
 	 * nothing.
 	 * 2) If no CPU is set at cpu_mask in the same compute unit,
-	 * set current STARTING CPU.
+	 * set current ONLINE CPU.
 	 *
 	 * Note: if there is a CPU aside of the new one already in the
 	 * sibling mask, then it is also in cpu_mask.
@@ -272,7 +272,7 @@ power_cpu_notifier(struct notifier_block
 
 	switch (action & ~CPU_TASKS_FROZEN) {
 	case CPU_DOWN_FAILED:
-	case CPU_STARTING:
+	case CPU_ONLINE:
 		power_cpu_init(cpu);
 		break;
 	case CPU_DOWN_PREPARE:
author maintainer
#31 lore raw

PATCH 25/66 perf/x86/amd/power: Convert the hotplug notifier to state machine

In reply to Anna-Maria Gleixner

From: Anna-Maria Gleixner <[email protected]>

Install the callbacks via the state machine.

---
 arch/x86/events/amd/power.c |   58 ++++++++------------------------------------
 include/linux/cpuhotplug.h  |    1 
 2 files changed, 12 insertions(+), 47 deletions(-)
arch/x86/events/amd/power.c +11 -47
@@ -228,12 +228,12 @@ static struct pmu pmu_class = {
 	.read		= pmu_event_read,
 };
 
-static void power_cpu_exit(int cpu)
+static int power_cpu_exit(unsigned int cpu)
 {
 	int target;
 
 	if (!cpumask_test_and_clear_cpu(cpu, &cpu_mask))
-		return;
+		return 0;
 
 	/*
 	 * Find a new CPU on the same compute unit, if was set in cpumask
@@ -245,9 +245,10 @@ static void power_cpu_exit(int cpu)
 		cpumask_set_cpu(target, &cpu_mask);
 		perf_pmu_migrate_context(&pmu_class, cpu, target);
 	}
+	return 0;
 }
 
-static void power_cpu_init(int cpu)
+static int power_cpu_init(unsigned int cpu)
 {
 	int target;
 
@@ -263,33 +264,9 @@ static void power_cpu_init(int cpu)
 	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
 	if (target >= nr_cpumask_bits)
 		cpumask_set_cpu(cpu, &cpu_mask);
+	return 0;
 }
 
-static int
-power_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
-{
-	unsigned int cpu = (long)hcpu;
-
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DOWN_FAILED:
-	case CPU_ONLINE:
-		power_cpu_init(cpu);
-		break;
-	case CPU_DOWN_PREPARE:
-		power_cpu_exit(cpu);
-		break;
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block power_cpu_notifier_nb = {
-	.notifier_call = power_cpu_notifier,
-	.priority = CPU_PRI_PERF,
-};
-
 static const struct x86_cpu_id cpu_match[] = {
 	{ .vendor = X86_VENDOR_AMD, .family = 0x15 },
 	{},
@@ -297,7 +274,7 @@ static const struct x86_cpu_id cpu_match
 
 static int __init amd_power_pmu_init(void)
 {
-	int cpu, target, ret;
+	int ret;
 
 	if (!x86_match_cpu(cpu_match))
 		return 0;
@@ -312,38 +289,25 @@ static int __init amd_power_pmu_init(voi
 		return -ENODEV;
 	}
 
-	cpu_notifier_register_begin();
 
-	/* Choose one online core of each compute unit. */
-	for_each_online_cpu(cpu) {
-		target = cpumask_first(topology_sibling_cpumask(cpu));
-		if (!cpumask_test_cpu(target, &cpu_mask))
-			cpumask_set_cpu(target, &cpu_mask);
-	}
+	cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
+			  "AP_PERF_X86_AMD_POWER_ONLINE",
+			  power_cpu_init, power_cpu_exit);
 
 	ret = perf_pmu_register(&pmu_class, "power", -1);
 	if (WARN_ON(ret)) {
 		pr_warn("AMD Power PMU registration failed\n");
-		goto out;
+		return ret;
 	}
 
-	__register_cpu_notifier(&power_cpu_notifier_nb);
-
 	pr_info("AMD Power PMU detected\n");
-
-out:
-	cpu_notifier_register_done();
-
 	return ret;
 }
 module_init(amd_power_pmu_init);
 
 static void __exit amd_power_pmu_exit(void)
 {
-	cpu_notifier_register_begin();
-	__unregister_cpu_notifier(&power_cpu_notifier_nb);
-	cpu_notifier_register_done();
-
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE);
 	perf_pmu_unregister(&pmu_class);
 }
 module_exit(amd_power_pmu_exit);
include/linux/cpuhotplug.h +1 -0
@@ -41,6 +41,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_ONLINE,
 	CPUHP_AP_PERF_X86_UNCORE_ONLINE,
 	CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
+	CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
 	CPUHP_AP_PERF_X86_RAPL_ONLINE,
 	CPUHP_AP_PERF_X86_CQM_ONLINE,
 	CPUHP_AP_PERF_X86_CSTATE_ONLINE,
author maintainer
#32 lore raw

PATCH 26/66 perf: Remove perf cpu notifier code

In reply to Anna-Maria Gleixner

All users converted to state machine callbacks.

---
 include/linux/cpu.h        |    2 --
 include/linux/perf_event.h |   35 -----------------------------------
 2 files changed, 37 deletions(-)
include/linux/cpu.h +0 -2
@@ -59,8 +59,6 @@ struct notifier_block;
  * CPU notifier priorities.
  */
 enum {
-	CPU_PRI_PERF		= 20,
-
 	/* bring up workqueues before normal notifiers and down after */
 	CPU_PRI_WORKQUEUE_UP	= 5,
 	CPU_PRI_WORKQUEUE_DOWN	= -5,
include/linux/perf_event.h +0 -35
@@ -1285,41 +1285,6 @@ static inline void perf_restore_debug_st
 
 #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
 
-/*
- * This has to have a higher priority than migration_notifier in sched/core.c.
- */
-#define perf_cpu_notifier(fn)						\
-do {									\
-	static struct notifier_block fn##_nb =				\
-		{ .notifier_call = fn, .priority = CPU_PRI_PERF };	\
-	unsigned long cpu = smp_processor_id();				\
-	unsigned long flags;						\
-									\
-	cpu_notifier_register_begin();					\
-	fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE,			\
-		(void *)(unsigned long)cpu);				\
-	local_irq_save(flags);						\
-	fn(&fn##_nb, (unsigned long)CPU_STARTING,			\
-		(void *)(unsigned long)cpu);				\
-	local_irq_restore(flags);					\
-	fn(&fn##_nb, (unsigned long)CPU_ONLINE,				\
-		(void *)(unsigned long)cpu);				\
-	__register_cpu_notifier(&fn##_nb);				\
-	cpu_notifier_register_done();					\
-} while (0)
-
-/*
- * Bare-bones version of perf_cpu_notifier(), which doesn't invoke the
- * callback for already online CPUs.
- */
-#define __perf_cpu_notifier(fn)						\
-do {									\
-	static struct notifier_block fn##_nb =				\
-		{ .notifier_call = fn, .priority = CPU_PRI_PERF };	\
-									\
-	__register_cpu_notifier(&fn##_nb);				\
-} while (0)
-
 struct perf_pmu_events_attr {
 	struct device_attribute attr;
 	u64 id;
author maintainer
#35 lore raw

PATCH 27/66 workqueue: Convert to state machine callbacks

In reply to Anna-Maria Gleixner

Get rid of the prio ordering of the separate notifiers and use a proper state callback pair.

---
 include/linux/cpu.h        |    9 ---
 include/linux/cpuhotplug.h |    2 
 include/linux/workqueue.h  |    6 ++
 kernel/cpu.c               |   10 ++++
 kernel/workqueue.c         |  108 +++++++++++++++++----------------------------
 5 files changed, 61 insertions(+), 74 deletions(-)
include/linux/cpu.h +0 -9
@@ -55,15 +55,6 @@ extern ssize_t arch_cpu_release(const ch
 #endif
 struct notifier_block;
 
-/*
- * CPU notifier priorities.
- */
-enum {
-	/* bring up workqueues before normal notifiers and down after */
-	CPU_PRI_WORKQUEUE_UP	= 5,
-	CPU_PRI_WORKQUEUE_DOWN	= -5,
-};
-
 #define CPU_ONLINE		0x0002 /* CPU (unsigned)v is up */
 #define CPU_UP_PREPARE		0x0003 /* CPU (unsigned)v coming up */
 #define CPU_UP_CANCELED		0x0004 /* CPU (unsigned)v NOT coming up */
include/linux/cpuhotplug.h +2 -0
@@ -12,6 +12,7 @@ enum cpuhp_state {
 	CPUHP_PERF_BFIN,
 	CPUHP_PERF_POWER,
 	CPUHP_PERF_SUPERH,
+	CPUHP_WORKQUEUE_PREP,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
@@ -48,6 +49,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_S390_SF_ONLINE,
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
+	CPUHP_AP_WORKQUEUE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
include/linux/workqueue.h +6 -0
@@ -625,4 +625,10 @@ void wq_watchdog_touch(int cpu);
 static inline void wq_watchdog_touch(int cpu) { }
 #endif	/* CONFIG_WQ_WATCHDOG */
 
+#ifdef CONFIG_SMP
+int workqueue_prepare_cpu(unsigned int cpu);
+int workqueue_online_cpu(unsigned int cpu);
+int workqueue_offline_cpu(unsigned int cpu);
+#endif
+
 #endif
kernel/cpu.c +10 -0
@@ -1178,6 +1178,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = perf_event_init_cpu,
 		.teardown = perf_event_exit_cpu,
 	},
+	[CPUHP_WORKQUEUE_PREP] = {
+		.name = "workqueue prepare",
+		.startup = workqueue_prepare_cpu,
+		.teardown = NULL,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
@@ -1258,6 +1263,11 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup = perf_event_init_cpu,
 		.teardown = perf_event_exit_cpu,
 	},
+	[CPUHP_AP_WORKQUEUE_ONLINE] = {
+		.name = "workqueue online",
+		.startup = workqueue_online_cpu,
+		.teardown = workqueue_offline_cpu,
+	},
 
 	/*
 	 * Online/down_prepare notifiers. Will be removed once the notifiers
kernel/workqueue.c +43 -65

136 lines not on this page · raw message

Acked-by Thomas Gleixner on v1 27/66
#36 lore raw

Re: [patch 27/66] workqueue: Convert to state machine callbacks

Quoted 8 lines · Anna-Maria Gleixner

Get rid of the prio ordering of the separate notifiers and use a proper state callback pair.

Same question - should I add:

From: Thomas Gleixner <[email protected]>

or:

?

Thanks,

Ingo

author maintainer
#37 lore raw

Re: [patch 27/66] workqueue: Convert to state machine callbacks

Quoted 12 lines · Ingo Molnar
Quoted 8 lines · Anna-Maria Gleixner

Get rid of the prio ordering of the separate notifiers and use a proper state callback pair.

Quoted 4 lines

Same question - should I add:

From: Thomas Gleixner <[email protected]>

This is the right one. I'm sorry, the script failed...

Thanks,
Anna-Maria

maintainer Acked-by on v1 27/66
#38 lore raw

Re: [patch 27/66] workqueue: Convert to state machine callbacks

In reply to Anna-Maria Gleixner

Hello,

Quoted 8 lines · Anna-Maria Gleixner

Get rid of the prio ordering of the separate notifiers and use a proper state callback pair.

Thanks.

Signature · 1 line
tejun
author maintainer
#39 lore raw

PATCH 28/66 x86/hpet: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/kernel/hpet.c     |   69 ++++++++++++++++++++++-----------------------
 include/linux/cpuhotplug.h |    2 +
 2 files changed, 36 insertions(+), 35 deletions(-)
arch/x86/kernel/hpet.c +34 -35
@@ -710,31 +710,29 @@ static void hpet_work(struct work_struct
 	complete(&hpet_work->complete);
 }
 
-static int hpet_cpuhp_notify(struct notifier_block *n,
-		unsigned long action, void *hcpu)
+static int hpet_cpuhp_online(unsigned int cpu)
 {
-	unsigned long cpu = (unsigned long)hcpu;
 	struct hpet_work_struct work;
+
+	INIT_DELAYED_WORK_ONSTACK(&work.work, hpet_work);
+	init_completion(&work.complete);
+	/* FIXME: add schedule_work_on() */
+	schedule_delayed_work_on(cpu, &work.work, 0);
+	wait_for_completion(&work.complete);
+	destroy_delayed_work_on_stack(&work.work);
+	return 0;
+}
+
+static int hpet_cpuhp_dead(unsigned int cpu)
+{
 	struct hpet_dev *hdev = per_cpu(cpu_hpet_dev, cpu);
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_ONLINE:
-		INIT_DELAYED_WORK_ONSTACK(&work.work, hpet_work);
-		init_completion(&work.complete);
-		/* FIXME: add schedule_work_on() */
-		schedule_delayed_work_on(cpu, &work.work, 0);
-		wait_for_completion(&work.complete);
-		destroy_delayed_work_on_stack(&work.work);
-		break;
-	case CPU_DEAD:
-		if (hdev) {
-			free_irq(hdev->irq, hdev);
-			hdev->flags &= ~HPET_DEV_USED;
-			per_cpu(cpu_hpet_dev, cpu) = NULL;
-		}
-		break;
-	}
-	return NOTIFY_OK;
+	if (!hdev)
+		return 0;
+	free_irq(hdev->irq, hdev);
+	hdev->flags &= ~HPET_DEV_USED;
+	per_cpu(cpu_hpet_dev, cpu) = NULL;
+	return 0;
 }
 #else
 
@@ -750,11 +748,8 @@ static void hpet_reserve_msi_timers(stru
 }
 #endif
 
-static int hpet_cpuhp_notify(struct notifier_block *n,
-		unsigned long action, void *hcpu)
-{
-	return NOTIFY_OK;
-}
+#define hpet_cpuhp_online	NULL
+#define hpet_cpuhp_dead		NULL
 
 #endif
 
@@ -931,7 +926,7 @@ int __init hpet_enable(void)
  */
 static __init int hpet_late_init(void)
 {
-	int cpu;
+	int ret;
 
 	if (boot_hpet_disable)
 		return -ENODEV;
@@ -961,16 +956,20 @@ static __init int hpet_late_init(void)
 	if (boot_cpu_has(X86_FEATURE_ARAT))
 		return 0;
 
-	cpu_notifier_register_begin();
-	for_each_online_cpu(cpu) {
-		hpet_cpuhp_notify(NULL, CPU_ONLINE, (void *)(long)cpu);
-	}
-
 	/* This notifier should be called after workqueue is ready */
-	__hotcpu_notifier(hpet_cpuhp_notify, -20);
-	cpu_notifier_register_done();
-
+	ret = cpuhp_setup_state(CPUHP_AP_X86_HPET_ONLINE, "AP_X86_HPET_ONLINE",
+				hpet_cpuhp_online, NULL);
+	if (ret)
+		return ret;
+	ret = cpuhp_setup_state(CPUHP_X86_HPET_DEAD, "X86_HPET_DEAD", NULL,
+				hpet_cpuhp_dead);
+	if (ret)
+		goto err_cpuhp;
 	return 0;
+
+err_cpuhp:
+	cpuhp_remove_state(CPUHP_AP_X86_HPET_ONLINE);
+	return ret;
 }
 fs_initcall(hpet_late_init);
 
include/linux/cpuhotplug.h +2 -0
@@ -12,6 +12,7 @@ enum cpuhp_state {
 	CPUHP_PERF_BFIN,
 	CPUHP_PERF_POWER,
 	CPUHP_PERF_SUPERH,
+	CPUHP_X86_HPET_DEAD,
 	CPUHP_WORKQUEUE_PREP,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
@@ -53,6 +54,7 @@ enum cpuhp_state {
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
+	CPUHP_AP_X86_HPET_ONLINE,
 	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };
author maintainer
#40 lore raw

PATCH 29/66 powerpc: numa: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/powerpc/mm/numa.c     |   46 +++++++++++++++------------------------------
 include/linux/cpuhotplug.h |    1 
 2 files changed, 17 insertions(+), 30 deletions(-)
arch/powerpc/mm/numa.c +16 -30
@@ -581,30 +581,22 @@ static void verify_cpu_node_mapping(int
 	}
 }
 
-static int cpu_numa_callback(struct notifier_block *nfb, unsigned long action,
-			     void *hcpu)
+/* Must run before sched domains notifier. */
+static int ppc_numa_cpu_prepare(unsigned int cpu)
 {
-	unsigned long lcpu = (unsigned long)hcpu;
-	int ret = NOTIFY_DONE, nid;
+	int nid;
+
+	nid = numa_setup_cpu(cpu);
+	verify_cpu_node_mapping(cpu, nid);
+	return 0;
+}
 
-	switch (action) {
-	case CPU_UP_PREPARE:
-	case CPU_UP_PREPARE_FROZEN:
-		nid = numa_setup_cpu(lcpu);
-		verify_cpu_node_mapping((int)lcpu, nid);
-		ret = NOTIFY_OK;
-		break;
+static int ppc_numa_cpu_dead(unsigned int cpu)
+{
 #ifdef CONFIG_HOTPLUG_CPU
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-		unmap_cpu_from_node(lcpu);
-		ret = NOTIFY_OK;
-		break;
+	unmap_cpu_from_node(cpu);
 #endif
-	}
-	return ret;
+	return 0;
 }
 
 /*
@@ -913,11 +905,6 @@ static void __init dump_numa_memory_topo
 	}
 }
 
-static struct notifier_block ppc64_numa_nb = {
-	.notifier_call = cpu_numa_callback,
-	.priority = 1 /* Must run before sched domains notifier. */
-};
-
 /* Initialize NODE_DATA for a node on the local memory */
 static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
 {
@@ -953,7 +940,7 @@ static void __init setup_node_data(int n
 
 void __init initmem_init(void)
 {
-	int nid, cpu;
+	int nid;
 
 	max_low_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT;
 	max_pfn = max_low_pfn;
@@ -985,15 +972,14 @@ void __init initmem_init(void)
 	setup_node_to_cpumask_map();
 
 	reset_numa_cpu_lookup_table();
-	register_cpu_notifier(&ppc64_numa_nb);
+
 	/*
 	 * We need the numa_cpu_lookup_table to be accurate for all CPUs,
 	 * even before we online them, so that we can use cpu_to_{node,mem}
 	 * early in boot, cf. smp_prepare_cpus().
 	 */
-	for_each_present_cpu(cpu) {
-		numa_setup_cpu((unsigned long)cpu);
-	}
+	cpuhp_setup_state(CPUHP_POWER_NUMA_PREPARE, "POWER_NUMA_PREPARE",
+			  ppc_numa_cpu_prepare, ppc_numa_cpu_dead);
 }
 
 static int __init early_numa(char *p)
include/linux/cpuhotplug.h +1 -0
@@ -14,6 +14,7 @@ enum cpuhp_state {
 	CPUHP_PERF_SUPERH,
 	CPUHP_X86_HPET_DEAD,
 	CPUHP_WORKQUEUE_PREP,
+	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
author maintainer
#41 lore raw

PATCH 30/66 KVM: x86: Remove superfluous SMP function call

In reply to Anna-Maria Gleixner

From: Anna-Maria Gleixner <[email protected]>

Since commit 1cf4f629d9d2 ("cpu/hotplug: Move online calls to hotplugged cpu") the CPU_ONLINE and CPU_DOWN_PREPARE notifiers are always run on the hot plugged CPU, and as of commit 3b9d6da67e11 ("cpu/hotplug: Fix rollback during error-out in __cpu_disable()") the CPU_DOWN_FAILED notifier also runs on the hot plugged CPU. This patch converts the SMP functional calls into direct calls.

smp_function_call_single() executes the function with interrupts disabled. This calling convention is not preserved because there is no reason to do so.

---
 arch/x86/kvm/x86.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +2 -2
@@ -5667,10 +5667,10 @@ static int kvmclock_cpu_notifier(struct
 	switch (action) {
 		case CPU_ONLINE:
 		case CPU_DOWN_FAILED:
-			smp_call_function_single(cpu, tsc_khz_changed, NULL, 1);
+			tsc_khz_changed(NULL);
 			break;
 		case CPU_DOWN_PREPARE:
-			smp_call_function_single(cpu, tsc_bad, NULL, 1);
+			tsc_bad(NULL);
 			break;
 	}
 	return NOTIFY_OK;
author maintainer
#42 lore raw

PATCH 31/66 x86/kvm/kvmclock: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

We assumed that the priority ordering was ment to invoke the online callback as the last step. In the original code this also invoked the down prepare callback as the last step. With the symmetric state machine the down prepare callback is now the first step.

---
 arch/x86/kvm/x86.c         |   35 ++++++++---------------------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 9 insertions(+), 27 deletions(-)
arch/x86/kvm/x86.c +8 -27
@@ -5552,9 +5552,10 @@ int kvm_fast_pio_out(struct kvm_vcpu *vc
 }
 EXPORT_SYMBOL_GPL(kvm_fast_pio_out);
 
-static void tsc_bad(void *info)
+static int kvmclock_cpu_down_prep(unsigned int cpu)
 {
 	__this_cpu_write(cpu_tsc_khz, 0);
+	return 0;
 }
 
 static void tsc_khz_changed(void *data)
@@ -5659,35 +5660,18 @@ static struct notifier_block kvmclock_cp
 	.notifier_call  = kvmclock_cpufreq_notifier
 };
 
-static int kvmclock_cpu_notifier(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
+static int kvmclock_cpu_online(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned long)hcpu;
-
-	switch (action) {
-		case CPU_ONLINE:
-		case CPU_DOWN_FAILED:
-			tsc_khz_changed(NULL);
-			break;
-		case CPU_DOWN_PREPARE:
-			tsc_bad(NULL);
-			break;
-	}
-	return NOTIFY_OK;
+	tsc_khz_changed(NULL);
+	return 0;
 }
 
-static struct notifier_block kvmclock_cpu_notifier_block = {
-	.notifier_call  = kvmclock_cpu_notifier,
-	.priority = -INT_MAX
-};
-
 static void kvm_timer_init(void)
 {
 	int cpu;
 
 	max_tsc_khz = tsc_khz;
 
-	cpu_notifier_register_begin();
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
 #ifdef CONFIG_CPU_FREQ
 		struct cpufreq_policy policy;
@@ -5702,12 +5686,9 @@ static void kvm_timer_init(void)
 					  CPUFREQ_TRANSITION_NOTIFIER);
 	}
 	pr_debug("kvm: max_tsc_khz = %ld\n", max_tsc_khz);
-	for_each_online_cpu(cpu)
-		smp_call_function_single(cpu, tsc_khz_changed, NULL, 1);
-
-	__register_hotcpu_notifier(&kvmclock_cpu_notifier_block);
-	cpu_notifier_register_done();
 
+	cpuhp_setup_state(CPUHP_AP_X86_KVM_CLK_ONLINE, "AP_X86_KVM_CLK_ONLINE",
+			  kvmclock_cpu_online, kvmclock_cpu_down_prep);
 }
 
 static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu);
@@ -5896,7 +5877,7 @@ void kvm_arch_exit(void)
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
-	unregister_hotcpu_notifier(&kvmclock_cpu_notifier_block);
+	cpuhp_remove_state_nocalls(CPUHP_X86_KVM_CLK_ONLINE);
 #ifdef CONFIG_X86_64
 	pvclock_gtod_unregister_notifier(&pvclock_gtod_notifier);
 #endif
include/linux/cpuhotplug.h +1 -0
@@ -56,6 +56,7 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
 	CPUHP_AP_X86_HPET_ONLINE,
+	CPUHP_AP_X86_KVM_CLK_ONLINE,
 	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };
author maintainer
#43 lore raw

Re: [patch 31/66] x86/kvm/kvmclock: Convert to hotplug state machine

Review void kvm_arch_exit(void) · line 5880

Quoted 6 lines · Anna-Maria Gleixner
(quoted diff) +1 -1
@@ -5896,7 +5877,7 @@ void kvm_arch_exit(void)
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
-	unregister_hotcpu_notifier(&kvmclock_cpu_notifier_block);
+	cpuhp_remove_state_nocalls(CPUHP_X86_KVM_CLK_ONLINE);

I'm sorry, this is buggy and wants to be:

    cpuhp_remove_state_nocalls(CPUHP_AP_X86_KVM_CLK_ONLINE);

See delta patch below.

Anna-Maria

8<-----------------

arch/x86/kvm/x86.c +1 -1
@@ -5877,7 +5877,7 @@ void kvm_arch_exit(void)
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
-	cpuhp_remove_state_nocalls(CPUHP_X86_KVM_CLK_ONLINE);
+	cpuhp_remove_state_nocalls(CPUHP_AP_X86_KVM_CLK_ONLINE);
 #ifdef CONFIG_X86_64
 	pvclock_gtod_unregister_notifier(&pvclock_gtod_notifier);
 #endif
maintainer Acked-by on v1 31/66
#44 lore raw

Re: [patch 31/66] x86/kvm/kvmclock: Convert to hotplug state machine

In reply to Anna-Maria Gleixner
Quoted 103 lines · Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

We assumed that the priority ordering was ment to invoke the online callback as the last step. In the original code this also invoked the down prepare callback as the last step. With the symmetric state machine the down prepare callback is now the first step.

---
 arch/x86/kvm/x86.c         |   35 ++++++++---------------------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 9 insertions(+), 27 deletions(-)
arch/x86/kvm/x86.c +8 -27
@@ -5552,9 +5552,10 @@ int kvm_fast_pio_out(struct kvm_vcpu *vc
 }
 EXPORT_SYMBOL_GPL(kvm_fast_pio_out);
 
-static void tsc_bad(void *info)
+static int kvmclock_cpu_down_prep(unsigned int cpu)
 {
 	__this_cpu_write(cpu_tsc_khz, 0);
+	return 0;
 }
 
 static void tsc_khz_changed(void *data)
@@ -5659,35 +5660,18 @@ static struct notifier_block kvmclock_cp
 	.notifier_call  = kvmclock_cpufreq_notifier
 };
 
-static int kvmclock_cpu_notifier(struct notifier_block *nfb,
-					unsigned long action, void *hcpu)
+static int kvmclock_cpu_online(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned long)hcpu;
-
-	switch (action) {
-		case CPU_ONLINE:
-		case CPU_DOWN_FAILED:
-			tsc_khz_changed(NULL);
-			break;
-		case CPU_DOWN_PREPARE:
-			tsc_bad(NULL);
-			break;
-	}
-	return NOTIFY_OK;
+	tsc_khz_changed(NULL);
+	return 0;
 }
 
-static struct notifier_block kvmclock_cpu_notifier_block = {
-	.notifier_call  = kvmclock_cpu_notifier,
-	.priority = -INT_MAX
-};
-
 static void kvm_timer_init(void)
 {
 	int cpu;
 
 	max_tsc_khz = tsc_khz;
 
-	cpu_notifier_register_begin();
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
 #ifdef CONFIG_CPU_FREQ
 		struct cpufreq_policy policy;
@@ -5702,12 +5686,9 @@ static void kvm_timer_init(void)
 					  CPUFREQ_TRANSITION_NOTIFIER);
 	}
 	pr_debug("kvm: max_tsc_khz = %ld\n", max_tsc_khz);
-	for_each_online_cpu(cpu)
-		smp_call_function_single(cpu, tsc_khz_changed, NULL, 1);
-
-	__register_hotcpu_notifier(&kvmclock_cpu_notifier_block);
-	cpu_notifier_register_done();
 
+	cpuhp_setup_state(CPUHP_AP_X86_KVM_CLK_ONLINE, "AP_X86_KVM_CLK_ONLINE",
+			  kvmclock_cpu_online, kvmclock_cpu_down_prep);
 }
 
 static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu);
@@ -5896,7 +5877,7 @@ void kvm_arch_exit(void)
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
-	unregister_hotcpu_notifier(&kvmclock_cpu_notifier_block);
+	cpuhp_remove_state_nocalls(CPUHP_X86_KVM_CLK_ONLINE);
 #ifdef CONFIG_X86_64
 	pvclock_gtod_unregister_notifier(&pvclock_gtod_notifier);
 #endif

include/linux/cpuhotplug.h enum cpuhp_state { · line 62

Quoted 7 lines
include/linux/cpuhotplug.h +1 -0
@@ -56,6 +56,7 @@ enum cpuhp_state {
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
 	CPUHP_AP_X86_HPET_ONLINE,
+	CPUHP_AP_X86_KVM_CLK_ONLINE,
 	CPUHP_AP_ACTIVE,
 	CPUHP_ONLINE,
 };

(I don't have problems with patches sent as attachments, but others might).

author maintainer
#45 lore raw

PATCH 32/66 x86/apb_timer: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine. There is no setup just one teardown callback. Remove the silly comment about the workqueue up dependency.

---
 arch/x86/kernel/apb_timer.c |   29 ++++++++++-------------------
 include/linux/cpuhotplug.h  |    1 +
 2 files changed, 11 insertions(+), 19 deletions(-)
arch/x86/kernel/apb_timer.c +10 -19
@@ -215,26 +215,18 @@ void apbt_setup_secondary_clock(void)
  * cpu timers during the offline process due to the ordering of notification.
  * the extra interrupt is harmless.
  */
-static int apbt_cpuhp_notify(struct notifier_block *n,
-			     unsigned long action, void *hcpu)
+static int apbt_cpu_dead(unsigned int cpu)
 {
-	unsigned long cpu = (unsigned long)hcpu;
 	struct apbt_dev *adev = &per_cpu(cpu_apbt_dev, cpu);
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_DEAD:
-		dw_apb_clockevent_pause(adev->timer);
-		if (system_state == SYSTEM_RUNNING) {
-			pr_debug("skipping APBT CPU %lu offline\n", cpu);
-		} else {
-			pr_debug("APBT clockevent for cpu %lu offline\n", cpu);
-			dw_apb_clockevent_stop(adev->timer);
-		}
-		break;
-	default:
-		pr_debug("APBT notified %lu, no action\n", action);
+	dw_apb_clockevent_pause(adev->timer);
+	if (system_state == SYSTEM_RUNNING) {
+		pr_debug("skipping APBT CPU %u offline\n", cpu);
+	} else {
+		pr_debug("APBT clockevent for cpu %u offline\n", cpu);
+		dw_apb_clockevent_stop(adev->timer);
 	}
-	return NOTIFY_OK;
+	return 0;
 }
 
 static __init int apbt_late_init(void)
@@ -242,9 +234,8 @@ static __init int apbt_late_init(void)
 	if (intel_mid_timer_options == INTEL_MID_TIMER_LAPIC_APBT ||
 		!apb_timer_block_enabled)
 		return 0;
-	/* This notifier should be called after workqueue is ready */
-	hotcpu_notifier(apbt_cpuhp_notify, -20);
-	return 0;
+	return cpuhp_setup_state(CPUHP_X86_APB_DEAD, "X86_APB_DEAD", NULL,
+				 apbt_cpu_dead);
 }
 fs_initcall(apbt_late_init);
 #else
include/linux/cpuhotplug.h +1 -0
@@ -13,6 +13,7 @@ enum cpuhp_state {
 	CPUHP_PERF_POWER,
 	CPUHP_PERF_SUPERH,
 	CPUHP_X86_HPET_DEAD,
+	CPUHP_X86_APB_DEAD,
 	CPUHP_WORKQUEUE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
author maintainer
#46 lore raw

PATCH 33/66 arm: Convert VFP hotplug notifiers to state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion plus commentary why code which is executed in hotplug callbacks needs to be invoked before installing them.

Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/vfp/vfpmodule.c   |   28 +++++++++++++++++-----------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 18 insertions(+), 11 deletions(-)
arch/arm/vfp/vfpmodule.c +17 -11
@@ -643,19 +643,19 @@ int vfp_restore_user_hwstate(struct user
  * hardware state at every thread switch.  We clear our held state when
  * a CPU has been killed, indicating that the VFP hardware doesn't contain
  * a threads VFP state.  When a CPU starts up, we re-enable access to the
- * VFP hardware.
- *
- * Both CPU_DYING and CPU_STARTING are called on the CPU which
+ * VFP hardware. The callbacks below are called on the CPU which
  * is being offlined/onlined.
  */
-static int vfp_hotplug(struct notifier_block *b, unsigned long action,
-	void *hcpu)
+static int vfp_dying_cpu(unsigned int cpu)
 {
-	if (action == CPU_DYING || action == CPU_DYING_FROZEN)
-		vfp_current_hw_state[(long)hcpu] = NULL;
-	else if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
-		vfp_enable(NULL);
-	return NOTIFY_OK;
+	vfp_force_reload(cpu, current_thread_info());
+	return 0;
+}
+
+static int vfp_starting_cpu(unsigned int unused)
+{
+	vfp_enable(NULL);
+	return 0;
 }
 
 void vfp_kmode_exception(void)
@@ -732,6 +732,10 @@ static int __init vfp_init(void)
 	unsigned int vfpsid;
 	unsigned int cpu_arch = cpu_architecture();
 
+	/*
+	 * Enable the access to the VFP on all online CPUs so the
+	 * following test on FPSID will succeed.
+	 */
 	if (cpu_arch >= CPU_ARCH_ARMv6)
 		on_each_cpu(vfp_enable, NULL, 1);
 
@@ -794,7 +798,9 @@ static int __init vfp_init(void)
 		VFP_arch = (vfpsid & FPSID_ARCH_MASK) >> FPSID_ARCH_BIT;
 	}
 
-	hotcpu_notifier(vfp_hotplug, 0);
+	cpuhp_setup_state_nocalls(CPUHP_AP_ARM_VFP_STARTING,
+				  "AP_ARM_VFP_STARTING", vfp_starting_cpu,
+				  vfp_dying_cpu);
 
 	vfp_vector = vfp_support_entry;
 
include/linux/cpuhotplug.h +1 -0
@@ -35,6 +35,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CQM_STARTING,
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
 	CPUHP_AP_PERF_XTENSA_STARTING,
+	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#47 lore raw

PATCH 34/66 arm: perf: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion w/o bells and whistles.

---
 drivers/perf/arm_pmu.c       |   36 +++++++++++++++---------------------
 include/linux/cpuhotplug.h   |    1 +
 include/linux/perf/arm_pmu.h |    1 -
 3 files changed, 16 insertions(+), 22 deletions(-)
drivers/perf/arm_pmu.c +15 -21
@@ -691,24 +691,15 @@ static int cpu_pmu_request_irq(struct ar
  * UNKNOWN at reset, the PMU must be explicitly reset to avoid reading
  * junk values out of them.
  */
-static int cpu_pmu_notify(struct notifier_block *b, unsigned long action,
-			  void *hcpu)
+static int arm_perf_starting_cpu(unsigned int cpu)
 {
-	int cpu = (unsigned long)hcpu;
-	struct arm_pmu *pmu = container_of(b, struct arm_pmu, hotplug_nb);
-
-	if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING)
-		return NOTIFY_DONE;
-
-	if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
-		return NOTIFY_DONE;
-
-	if (pmu->reset)
-		pmu->reset(pmu);
-	else
-		return NOTIFY_DONE;
-
-	return NOTIFY_OK;
+	if (!__oprofile_cpu_pmu)
+		return 0;
+	if (!cpumask_test_cpu(cpu, &__oprofile_cpu_pmu->supported_cpus))
+		return 0;
+	if (__oprofile_cpu_pmu->reset)
+		__oprofile_cpu_pmu->reset(__oprofile_cpu_pmu);
+	return 0;
 }
 
 #ifdef CONFIG_CPU_PM
@@ -819,8 +810,9 @@ static int cpu_pmu_init(struct arm_pmu *
 	if (!cpu_hw_events)
 		return -ENOMEM;
 
-	cpu_pmu->hotplug_nb.notifier_call = cpu_pmu_notify;
-	err = register_cpu_notifier(&cpu_pmu->hotplug_nb);
+	err = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING,
+					"AP_PERF_ARM_STARTING",
+					arm_perf_starting_cpu, NULL);
 	if (err)
 		goto out_hw_events;
 
@@ -858,7 +850,7 @@ static int cpu_pmu_init(struct arm_pmu *
 	return 0;
 
 out_unregister:
-	unregister_cpu_notifier(&cpu_pmu->hotplug_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING);
 out_hw_events:
 	free_percpu(cpu_hw_events);
 	return err;
@@ -867,7 +859,7 @@ static int cpu_pmu_init(struct arm_pmu *
 static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
 {
 	cpu_pm_pmu_unregister(cpu_pmu);
-	unregister_cpu_notifier(&cpu_pmu->hotplug_nb);
+	cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_STARTING);
 	free_percpu(cpu_pmu->hw_events);
 }
 
@@ -1027,6 +1019,8 @@ int arm_pmu_device_probe(struct platform
 	if (ret)
 		goto out_destroy;
 
+	WARN(__oprofile_cpu_pmu, "%s(): missing PMU strucure for CPU-hotplug\n",
+	     __func__);
 	if (!__oprofile_cpu_pmu)
 		__oprofile_cpu_pmu = pmu;
 
include/linux/cpuhotplug.h +1 -0
@@ -36,6 +36,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
 	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
+	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
include/linux/perf/arm_pmu.h +0 -1
@@ -109,7 +109,6 @@ struct arm_pmu {
 	DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
 	struct platform_device	*plat_device;
 	struct pmu_hw_events	__percpu *hw_events;
-	struct notifier_block	hotplug_nb;
 	struct notifier_block	cpu_pm_nb;
 };
 
author maintainer
#48 lore raw

PATCH 35/66 virt: Convert kvm hotplug to state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine. The core won't invoke the callbacks on already online CPUs.

---
 include/linux/cpuhotplug.h |    1 +
 virt/kvm/kvm_main.c        |   32 ++++++++------------------------
 2 files changed, 9 insertions(+), 24 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -37,6 +37,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
+	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
virt/kvm/kvm_main.c +8 -24
@@ -3144,12 +3144,13 @@ static void hardware_enable_nolock(void
 	}
 }
 
-static void hardware_enable(void)
+static int kvm_starting_cpu(unsigned int cpu)
 {
 	raw_spin_lock(&kvm_count_lock);
 	if (kvm_usage_count)
 		hardware_enable_nolock(NULL);
 	raw_spin_unlock(&kvm_count_lock);
+	return 0;
 }
 
 static void hardware_disable_nolock(void *junk)
@@ -3162,12 +3163,13 @@ static void hardware_disable_nolock(void
 	kvm_arch_hardware_disable();
 }
 
-static void hardware_disable(void)
+static int kvm_dying_cpu(unsigned int cpu)
 {
 	raw_spin_lock(&kvm_count_lock);
 	if (kvm_usage_count)
 		hardware_disable_nolock(NULL);
 	raw_spin_unlock(&kvm_count_lock);
+	return 0;
 }
 
 static void hardware_disable_all_nolock(void)
@@ -3208,21 +3210,6 @@ static int hardware_enable_all(void)
 	return r;
 }
 
-static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
-			   void *v)
-{
-	val &= ~CPU_TASKS_FROZEN;
-	switch (val) {
-	case CPU_DYING:
-		hardware_disable();
-		break;
-	case CPU_STARTING:
-		hardware_enable();
-		break;
-	}
-	return NOTIFY_OK;
-}
-
 static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
 		      void *v)
 {
@@ -3489,10 +3476,6 @@ int kvm_io_bus_unregister_dev(struct kvm
 	return r;
 }
 
-static struct notifier_block kvm_cpu_notifier = {
-	.notifier_call = kvm_cpu_hotplug,
-};
-
 static int kvm_debugfs_open(struct inode *inode, struct file *file,
 			   int (*get)(void *, u64 *), int (*set)(void *, u64),
 			   const char *fmt)
@@ -3743,7 +3726,8 @@ int kvm_init(void *opaque, unsigned vcpu
 			goto out_free_1;
 	}
 
-	r = register_cpu_notifier(&kvm_cpu_notifier);
+	r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_STARTING, "AP_KVM_STARTING",
+				      kvm_starting_cpu, kvm_dying_cpu);
 	if (r)
 		goto out_free_2;
 	register_reboot_notifier(&kvm_reboot_notifier);
@@ -3797,7 +3781,7 @@ int kvm_init(void *opaque, unsigned vcpu
 	kmem_cache_destroy(kvm_vcpu_cache);
 out_free_3:
 	unregister_reboot_notifier(&kvm_reboot_notifier);
-	unregister_cpu_notifier(&kvm_cpu_notifier);
+	cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
 out_free_2:
 out_free_1:
 	kvm_arch_hardware_unsetup();
@@ -3820,7 +3804,7 @@ void kvm_exit(void)
 	kvm_async_pf_deinit();
 	unregister_syscore_ops(&kvm_syscore_ops);
 	unregister_reboot_notifier(&kvm_reboot_notifier);
-	unregister_cpu_notifier(&kvm_cpu_notifier);
+	cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
 	on_each_cpu(hardware_disable_nolock, NULL, 1);
 	kvm_arch_hardware_unsetup();
 	kvm_arch_exit();
maintainer Acked-by on v1 35/66
#49 lore raw

Re: [patch 35/66] virt: Convert kvm hotplug to state machine

Quoted 123 lines · Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Install the callbacks via the state machine. The core won't invoke the callbacks on already online CPUs.

---
 include/linux/cpuhotplug.h |    1 +
 virt/kvm/kvm_main.c        |   32 ++++++++------------------------
 2 files changed, 9 insertions(+), 24 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -37,6 +37,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
+	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
virt/kvm/kvm_main.c +8 -25
@@ -3144,12 +3144,13 @@ static void hardware_enable_nolock(void
 	}
 }
 
-static void hardware_enable(void)
+static int kvm_starting_cpu(unsigned int cpu)
 {
 	raw_spin_lock(&kvm_count_lock);
 	if (kvm_usage_count)
 		hardware_enable_nolock(NULL);
 	raw_spin_unlock(&kvm_count_lock);
+	return 0;
 }
 
 static void hardware_disable_nolock(void *junk)
@@ -3162,12 +3163,13 @@ static void hardware_disable_nolock(void
 	kvm_arch_hardware_disable();
 }
 
-static void hardware_disable(void)
+static int kvm_dying_cpu(unsigned int cpu)
 {
 	raw_spin_lock(&kvm_count_lock);
 	if (kvm_usage_count)
 		hardware_disable_nolock(NULL);
 	raw_spin_unlock(&kvm_count_lock);
+	return 0;
 }
 
 static void hardware_disable_all_nolock(void)
@@ -3208,21 +3210,6 @@ static int hardware_enable_all(void)
 	return r;
 }
 
-static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
-			   void *v)
-{
-	val &= ~CPU_TASKS_FROZEN;
-	switch (val) {
-	case CPU_DYING:
-		hardware_disable();
-		break;
-	case CPU_STARTING:
-		hardware_enable();
-		break;
-	}
-	return NOTIFY_OK;
-}
-
 static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
 		      void *v)
 {
@@ -3489,10 +3476,6 @@ int kvm_io_bus_unregister_dev(struct kvm
 	return r;
 }
 
-static struct notifier_block kvm_cpu_notifier = {
-	.notifier_call = kvm_cpu_hotplug,
-};
-
 static int kvm_debugfs_open(struct inode *inode, struct file *file,
 			   int (*get)(void *, u64 *), int (*set)(void *, u64),
 			   const char *fmt)
@@ -3743,7 +3726,8 @@ int kvm_init(void *opaque, unsigned vcpu
 			goto out_free_1;
 	}
 
-	r = register_cpu_notifier(&kvm_cpu_notifier);
+	r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_STARTING, "AP_KVM_STARTING",
+				      kvm_starting_cpu, kvm_dying_cpu);
 	if (r)
 		goto out_free_2;
 	register_reboot_notifier(&kvm_reboot_notifier);
@@ -3797,7 +3781,7 @@ int kvm_init(void *opaque, unsigned vcpu
 	kmem_cache_destroy(kvm_vcpu_cache);
 out_free_3:
 	unregister_reboot_notifier(&kvm_reboot_notifier);
-	unregister_cpu_notifier(&kvm_cpu_notifier);
+	cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
 out_free_2:
 out_free_1:
 	kvm_arch_hardware_unsetup();
@@ -3820,7 +3804,7 @@ void kvm_exit(void)
 	kvm_async_pf_deinit();
 	unregister_syscore_ops(&kvm_syscore_ops);
 	unregister_reboot_notifier(&kvm_reboot_notifier);
-	unregister_cpu_notifier(&kvm_cpu_notifier);
+	cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
 	on_each_cpu(hardware_disable_nolock, NULL, 1);
 	kvm_arch_hardware_unsetup();
 	kvm_arch_exit();
 
 
--
Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#50 lore raw

PATCH 36/66 ACPI/processor: avoid STARTING/DYING actions in a more logical way

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

As part of the hotplug cleanup, the CPU_STARTING/DYING actions are going away soon. This driver needlessly uses those two macro, and so this patch replaces that code with something more sensible.

Commit 8da8373447d6a57a5a9f55233d35beb15d92d0d2 ("ACPI / processor: Fix STARTING/DYING action in acpi_cpu_soft_notify()") added checks for those two actions, because the notification callback can sleep, causing a hung CPU. This patch instead checks for the ONLINE/DEAD actions, which are the ones that are handled by the driver in the first place.

---
 drivers/acpi/processor_driver.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/acpi/processor_driver.c +6 -5
@@ -118,12 +118,13 @@ static int acpi_cpu_soft_notify(struct n
 	struct acpi_device *device;
 	action &= ~CPU_TASKS_FROZEN;
 
-	/*
-	 * CPU_STARTING and CPU_DYING must not sleep. Return here since
-	 * acpi_bus_get_device() may sleep.
-	 */
-	if (action == CPU_STARTING || action == CPU_DYING)
+	switch (action) {
+	case CPU_ONLINE:
+	case CPU_DEAD:
+		break;
+	default:
 		return NOTIFY_DONE;
+	}
 
 	if (!pr || acpi_bus_get_device(pr->handle, &device))
 		return NOTIFY_DONE;
author maintainer
#51 lore raw

PATCH 37/66 clocksource/arm_arch_timer: Convert to hotplug state machine.

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/arm_arch_timer.c |   54 ++++++++++++++++-------------------
 include/linux/cpuhotplug.h           |    1 
 2 files changed, 27 insertions(+), 28 deletions(-)
drivers/clocksource/arm_arch_timer.c +26 -28
@@ -362,8 +362,10 @@ static bool arch_timer_has_nonsecure_ppi
 		arch_timer_ppi[PHYS_NONSECURE_PPI]);
 }
 
-static int arch_timer_setup(struct clock_event_device *clk)
+static int arch_timer_starting_cpu(unsigned int cpu)
 {
+	struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
+
 	__arch_timer_setup(ARCH_CP15_TIMER, clk);
 
 	enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], 0);
@@ -519,29 +521,14 @@ static void arch_timer_stop(struct clock
 	clk->set_state_shutdown(clk);
 }
 
-static int arch_timer_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
+static int arch_timer_dying_cpu(unsigned int cpu)
 {
-	/*
-	 * Grab cpu pointer in each case to avoid spurious
-	 * preemptible warnings
-	 */
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		arch_timer_setup(this_cpu_ptr(arch_timer_evt));
-		break;
-	case CPU_DYING:
-		arch_timer_stop(this_cpu_ptr(arch_timer_evt));
-		break;
-	}
+	struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
 
-	return NOTIFY_OK;
+	arch_timer_stop(clk);
+	return 0;
 }
 
-static struct notifier_block arch_timer_cpu_nb = {
-	.notifier_call = arch_timer_cpu_notify,
-};
-
 #ifdef CONFIG_CPU_PM
 static unsigned int saved_cntkctl;
 static int arch_timer_cpu_pm_notify(struct notifier_block *self,
@@ -562,11 +549,21 @@ static int __init arch_timer_cpu_pm_init
 {
 	return cpu_pm_register_notifier(&arch_timer_cpu_pm_notifier);
 }
+
+static void __init arch_timer_cpu_pm_deinit(void)
+{
+	WARN_ON(cpu_pm_unregister_notifier(&arch_timer_cpu_pm_notifier));
+}
+
 #else
 static int __init arch_timer_cpu_pm_init(void)
 {
 	return 0;
 }
+
+static void __init arch_timer_cpu_pm_deinit(void)
+{
+}
 #endif
 
 static int __init arch_timer_register(void)
@@ -613,22 +610,23 @@ static int __init arch_timer_register(vo
 		goto out_free;
 	}
 
-	err = register_cpu_notifier(&arch_timer_cpu_nb);
-	if (err)
-		goto out_free_irq;
-
 	err = arch_timer_cpu_pm_init();
 	if (err)
 		goto out_unreg_notify;
 
-	/* Immediately configure the timer on the boot CPU */
-	arch_timer_setup(this_cpu_ptr(arch_timer_evt));
 
+	/* Register and immediately configure the timer on the boot CPU */
+	err = cpuhp_setup_state(CPUHP_AP_ARM_ARCH_TIMER_STARTING,
+				"AP_ARM_ARCH_TIMER_STARTING",
+				arch_timer_starting_cpu, arch_timer_dying_cpu);
+	if (err)
+		goto out_unreg_cpupm;
 	return 0;
 
+out_unreg_cpupm:
+	arch_timer_cpu_pm_deinit();
+
 out_unreg_notify:
-	unregister_cpu_notifier(&arch_timer_cpu_nb);
-out_free_irq:
 	free_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], arch_timer_evt);
 	if (arch_timer_has_nonsecure_ppi())
 		free_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI],
include/linux/cpuhotplug.h +1 -0
@@ -37,6 +37,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
+	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#52 lore raw

PATCH 38/66 clocksource/arm_global_timer: Convert to hotplug state machine.

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

Cc Srinivas Kandagatla <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc kernel at stlinux.com
---
 drivers/clocksource/arm_global_timer.c |   41 ++++++++-------------------------
 include/linux/cpuhotplug.h             |    1 
 2 files changed, 11 insertions(+), 31 deletions(-)
drivers/clocksource/arm_global_timer.c +10 -31
@@ -165,9 +165,9 @@ static irqreturn_t gt_clockevent_interru
 	return IRQ_HANDLED;
 }
 
-static int gt_clockevents_init(struct clock_event_device *clk)
+static int gt_starting_cpu(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
+	struct clock_event_device *clk = this_cpu_ptr(gt_evt);
 
 	clk->name = "arm_global_timer";
 	clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
@@ -186,10 +186,13 @@ static int gt_clockevents_init(struct cl
 	return 0;
 }
 
-static void gt_clockevents_stop(struct clock_event_device *clk)
+static int gt_dying_cpu(unsigned int cpu)
 {
+	struct clock_event_device *clk = this_cpu_ptr(gt_evt);
+
 	gt_clockevent_shutdown(clk);
 	disable_percpu_irq(clk->irq);
+	return 0;
 }
 
 static cycle_t gt_clocksource_read(struct clocksource *cs)
@@ -252,24 +255,6 @@ static void __init gt_clocksource_init(v
 	clocksource_register_hz(&gt_clocksource, gt_clk_rate);
 }
 
-static int gt_cpu_notify(struct notifier_block *self, unsigned long action,
-			 void *hcpu)
-{
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		gt_clockevents_init(this_cpu_ptr(gt_evt));
-		break;
-	case CPU_DYING:
-		gt_clockevents_stop(this_cpu_ptr(gt_evt));
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-static struct notifier_block gt_cpu_nb = {
-	.notifier_call = gt_cpu_notify,
-};
-
 static void __init global_timer_of_register(struct device_node *np)
 {
 	struct clk *gt_clk;
@@ -325,21 +310,15 @@ static void __init global_timer_of_regis
 		goto out_free;
 	}
 
-	err = register_cpu_notifier(&gt_cpu_nb);
-	if (err) {
-		pr_warn("global-timer: unable to register cpu notifier.\n");
-		goto out_irq;
-	}
-
-	/* Immediately configure the timer on the boot CPU */
+	/* Register and immediately configure the timer on the boot CPU */
 	gt_clocksource_init();
-	gt_clockevents_init(this_cpu_ptr(gt_evt));
+	cpuhp_setup_state(CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
+			  "AP_ARM_GLOBAL_TIMER_STARTING", gt_starting_cpu,
+			  gt_dying_cpu);
 	gt_delay_timer_init();
 
 	return;
 
-out_irq:
-	free_percpu_irq(gt_ppi, gt_evt);
 out_free:
 	free_percpu(gt_evt);
 out_clk:
include/linux/cpuhotplug.h +1 -0
@@ -38,6 +38,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
+	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#53 lore raw

PATCH 39/66 clocksource/dummy_timer: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/dummy_timer.c |   36 ++++++------------------------------
 include/linux/cpuhotplug.h        |    1 +
 2 files changed, 7 insertions(+), 30 deletions(-)
drivers/clocksource/dummy_timer.c +6 -30
@@ -16,10 +16,9 @@
 
 static DEFINE_PER_CPU(struct clock_event_device, dummy_timer_evt);
 
-static void dummy_timer_setup(void)
+static int dummy_timer_starting_cpu(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
-	struct clock_event_device *evt = raw_cpu_ptr(&dummy_timer_evt);
+	struct clock_event_device *evt = per_cpu_ptr(&dummy_timer_evt, cpu);
 
 	evt->name	= "dummy_timer";
 	evt->features	= CLOCK_EVT_FEAT_PERIODIC |
@@ -29,36 +28,13 @@ static void dummy_timer_setup(void)
 	evt->cpumask	= cpumask_of(cpu);
 
 	clockevents_register_device(evt);
+	return 0;
 }
 
-static int dummy_timer_cpu_notify(struct notifier_block *self,
-				      unsigned long action, void *hcpu)
-{
-	if ((action & ~CPU_TASKS_FROZEN) == CPU_STARTING)
-		dummy_timer_setup();
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block dummy_timer_cpu_nb = {
-	.notifier_call = dummy_timer_cpu_notify,
-};
-
 static int __init dummy_timer_register(void)
 {
-	int err = 0;
-
-	cpu_notifier_register_begin();
-	err = __register_cpu_notifier(&dummy_timer_cpu_nb);
-	if (err)
-		goto out;
-
-	/* We won't get a call on the boot CPU, so register immediately */
-	if (num_possible_cpus() > 1)
-		dummy_timer_setup();
-
-out:
-	cpu_notifier_register_done();
-	return err;
+	return cpuhp_setup_state(CPUHP_AP_DUMMY_TIMER_STARTING,
+				 "AP_DUMMY_TIMER_STARTING",
+				 dummy_timer_starting_cpu, NULL);
 }
 early_initcall(dummy_timer_register);
include/linux/cpuhotplug.h +1 -0
@@ -39,6 +39,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
 	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
+	CPUHP_AP_DUMMY_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#54 lore raw

PATCH 40/66 clocksource/exynos_mct: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/exynos_mct.c |   48 +++++++++------------------------------
 include/linux/cpuhotplug.h       |    1 
 2 files changed, 13 insertions(+), 36 deletions(-)
drivers/clocksource/exynos_mct.c +12 -36
@@ -439,10 +439,11 @@ static irqreturn_t exynos4_mct_tick_isr(
 	return IRQ_HANDLED;
 }
 
-static int exynos4_local_timer_setup(struct mct_clock_event_device *mevt)
+static int exynos4_mct_starting_cpu(unsigned int cpu)
 {
+	struct mct_clock_event_device *mevt =
+		per_cpu_ptr(&percpu_mct_tick, cpu);
 	struct clock_event_device *evt = &mevt->evt;
-	unsigned int cpu = smp_processor_id();
 
 	mevt->base = EXYNOS4_MCT_L_BASE(cpu);
 	snprintf(mevt->name, sizeof(mevt->name), "mct_tick%d", cpu);
@@ -489,37 +490,18 @@ static void exynos4_local_timer_stop(str
 	}
 }
 
-static int exynos4_mct_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
+static int exynos4_mct_dying_cpu(unsigned int cpu)
 {
-	struct mct_clock_event_device *mevt;
+	struct mct_clock_event_device *mevt =
+		per_cpu_ptr(&percpu_mct_tick, cpu);
 
-	/*
-	 * Grab cpu pointer in each case to avoid spurious
-	 * preemptible warnings
-	 */
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		mevt = this_cpu_ptr(&percpu_mct_tick);
-		exynos4_local_timer_setup(mevt);
-		break;
-	case CPU_DYING:
-		mevt = this_cpu_ptr(&percpu_mct_tick);
-		exynos4_local_timer_stop(mevt);
-		break;
-	}
-
-	return NOTIFY_OK;
+	exynos4_local_timer_stop(mevt);
+	return 0;
 }
 
-static struct notifier_block exynos4_mct_cpu_nb = {
-	.notifier_call = exynos4_mct_cpu_notify,
-};
-
 static void __init exynos4_timer_resources(struct device_node *np, void __iomem *base)
 {
 	int err, cpu;
-	struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
 	struct clk *mct_clk, *tick_clk;
 
 	tick_clk = np ? of_clk_get_by_name(np, "fin_pll") :
@@ -566,16 +548,10 @@ static void __init exynos4_timer_resourc
 		}
 	}
 
-	err = register_cpu_notifier(&exynos4_mct_cpu_nb);
-	if (err)
-		goto out_irq;
-
-	/* Immediately configure the timer on the boot CPU */
-	exynos4_local_timer_setup(mevt);
-	return;
-
-out_irq:
-	free_percpu_irq(mct_irqs[MCT_L0_IRQ], &percpu_mct_tick);
+	/* Install hotplug callbacks which configure the timer on this cpu */
+	cpuhp_setup_state(CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
+			  "AP_EXYNOS4_MCT_TIMER_STARTING",
+			  exynos4_mct_starting_cpu, exynos4_mct_dying_cpu);
 }
 
 static void __init mct_init_dt(struct device_node *np, unsigned int int_type)
include/linux/cpuhotplug.h +1 -0
@@ -40,6 +40,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
 	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
 	CPUHP_AP_DUMMY_TIMER_STARTING,
+	CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#55 lore raw

PATCH 41/66 clocksource/metag: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/metag_generic.c |   33 ++++++---------------------------
 include/linux/cpuhotplug.h          |    1 +
 2 files changed, 7 insertions(+), 27 deletions(-)
drivers/clocksource/metag_generic.c +6 -27
@@ -90,7 +90,7 @@ unsigned long long sched_clock(void)
 	return ticks << HARDWARE_TO_NS_SHIFT;
 }
 
-static void arch_timer_setup(unsigned int cpu)
+static int arch_timer_starting_cpu(unsigned int cpu)
 {
 	unsigned int txdivtime;
 	struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
@@ -132,27 +132,9 @@ static void arch_timer_setup(unsigned in
 		val = core_reg_read(TXUCT_ID, TXTIMER_REGNUM, thread0);
 		__core_reg_set(TXTIMER, val);
 	}
+	return 0;
 }
 
-static int arch_timer_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
-{
-	int cpu = (long)hcpu;
-
-	switch (action) {
-	case CPU_STARTING:
-	case CPU_STARTING_FROZEN:
-		arch_timer_setup(cpu);
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block arch_timer_cpu_nb = {
-	.notifier_call = arch_timer_cpu_notify,
-};
-
 int __init metag_generic_timer_init(void)
 {
 	/*
@@ -170,11 +152,8 @@ int __init metag_generic_timer_init(void
 
 	setup_irq(tbisig_map(TBID_SIGNUM_TRT), &metag_timer_irq);
 
-	/* Configure timer on boot CPU */
-	arch_timer_setup(smp_processor_id());
-
-	/* Hook cpu boot to configure other CPU's timers */
-	register_cpu_notifier(&arch_timer_cpu_nb);
-
-	return 0;
+	/* Hook cpu boot to configure the CPU's timers */
+	return cpuhp_setup_state(CPUHP_AP_METAG_TIMER_STARTING,
+				 "AP_METAG_TIMER_STARTING",
+				 arch_timer_starting_cpu, NULL);
 }
include/linux/cpuhotplug.h +1 -0
@@ -41,6 +41,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
 	CPUHP_AP_DUMMY_TIMER_STARTING,
 	CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
+	CPUHP_AP_METAG_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#56 lore raw

PATCH 42/66 clocksource/qcom-timer: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/qcom-timer.c |   41 ++++++++++-----------------------------
 include/linux/cpuhotplug.h       |    1 
 2 files changed, 12 insertions(+), 30 deletions(-)
drivers/clocksource/qcom-timer.c +11 -30
@@ -105,9 +105,9 @@ static struct clocksource msm_clocksourc
 static int msm_timer_irq;
 static int msm_timer_has_ppi;
 
-static int msm_local_timer_setup(struct clock_event_device *evt)
+static int msm_local_timer_starting_cpu(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
+	struct clock_event_device *evt = per_cpu_ptr(msm_evt, cpu);
 	int err;
 
 	evt->irq = msm_timer_irq;
@@ -135,35 +135,15 @@ static int msm_local_timer_setup(struct
 	return 0;
 }
 
-static void msm_local_timer_stop(struct clock_event_device *evt)
+static int msm_local_timer_dying_cpu(unsigned int cpu)
 {
+	struct clock_event_device *evt = per_cpu_ptr(msm_evt, cpu);
+
 	evt->set_state_shutdown(evt);
 	disable_percpu_irq(evt->irq);
+	return 0;
 }
 
-static int msm_timer_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
-{
-	/*
-	 * Grab cpu pointer in each case to avoid spurious
-	 * preemptible warnings
-	 */
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		msm_local_timer_setup(this_cpu_ptr(msm_evt));
-		break;
-	case CPU_DYING:
-		msm_local_timer_stop(this_cpu_ptr(msm_evt));
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block msm_timer_cpu_nb = {
-	.notifier_call = msm_timer_cpu_notify,
-};
-
 static u64 notrace msm_sched_clock_read(void)
 {
 	return msm_clocksource.read(&msm_clocksource);
@@ -200,14 +180,15 @@ static void __init msm_timer_init(u32 dg
 	if (res) {
 		pr_err("request_percpu_irq failed\n");
 	} else {
-		res = register_cpu_notifier(&msm_timer_cpu_nb);
+		/* Install and invoke hotplug callbacks */
+		res = cpuhp_setup_state(CPUHP_AP_QCOM_TIMER_STARTING,
+					"AP_QCOM_TIMER_STARTING",
+					msm_local_timer_starting_cpu,
+					msm_local_timer_dying_cpu);
 		if (res) {
 			free_percpu_irq(irq, msm_evt);
 			goto err;
 		}
-
-		/* Immediately configure the timer on the boot CPU */
-		msm_local_timer_setup(raw_cpu_ptr(msm_evt));
 	}
 
 err:
include/linux/cpuhotplug.h +1 -0
@@ -42,6 +42,7 @@ enum cpuhp_state {
 	CPUHP_AP_DUMMY_TIMER_STARTING,
 	CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
 	CPUHP_AP_METAG_TIMER_STARTING,
+	CPUHP_AP_QCOM_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#57 lore raw

PATCH 43/66 clocksource/armada-370-xp: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/time-armada-370-xp.c |   44 +++++++++----------------------
 include/linux/cpuhotplug.h               |    1 
 2 files changed, 15 insertions(+), 30 deletions(-)
drivers/clocksource/time-armada-370-xp.c +14 -30
@@ -170,10 +170,10 @@ static irqreturn_t armada_370_xp_timer_i
 /*
  * Setup the local clock events for a CPU.
  */
-static int armada_370_xp_timer_setup(struct clock_event_device *evt)
+static int armada_370_xp_timer_starting_cpu(unsigned int cpu)
 {
+	struct clock_event_device *evt = per_cpu_ptr(armada_370_xp_evt, cpu);
 	u32 clr = 0, set = 0;
-	int cpu = smp_processor_id();
 
 	if (timer25Mhz)
 		set = TIMER0_25MHZ;
@@ -200,35 +200,15 @@ static int armada_370_xp_timer_setup(str
 	return 0;
 }
 
-static void armada_370_xp_timer_stop(struct clock_event_device *evt)
+static int armada_370_xp_timer_dying_cpu(unsigned int cpu)
 {
+	struct clock_event_device *evt = per_cpu_ptr(armada_370_xp_evt, cpu);
+
 	evt->set_state_shutdown(evt);
 	disable_percpu_irq(evt->irq);
+	return 0;
 }
 
-static int armada_370_xp_timer_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
-{
-	/*
-	 * Grab cpu pointer in each case to avoid spurious
-	 * preemptible warnings
-	 */
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		armada_370_xp_timer_setup(this_cpu_ptr(armada_370_xp_evt));
-		break;
-	case CPU_DYING:
-		armada_370_xp_timer_stop(this_cpu_ptr(armada_370_xp_evt));
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block armada_370_xp_timer_cpu_nb = {
-	.notifier_call = armada_370_xp_timer_cpu_notify,
-};
-
 static u32 timer0_ctrl_reg, timer0_local_ctrl_reg;
 
 static int armada_370_xp_timer_suspend(void)
@@ -310,8 +290,6 @@ static void __init armada_370_xp_timer_c
 			      "armada_370_xp_clocksource",
 			      timer_clk, 300, 32, clocksource_mmio_readl_down);
 
-	register_cpu_notifier(&armada_370_xp_timer_cpu_nb);
-
 	armada_370_xp_evt = alloc_percpu(struct clock_event_device);
 
 
@@ -323,8 +301,14 @@ static void __init armada_370_xp_timer_c
 				"armada_370_xp_per_cpu_tick",
 				armada_370_xp_evt);
 	/* Immediately configure the timer on the boot CPU */
-	if (!res)
-		armada_370_xp_timer_setup(this_cpu_ptr(armada_370_xp_evt));
+	if (res) {
+		pr_err("armada_370_xp_timer: failed to register per-cpu IRQ\n");
+	} else {
+		cpuhp_setup_state(CPUHP_AP_ARMADA_TIMER_STARTING,
+				  "AP_ARMADA_TIMER_STARTING",
+				  armada_370_xp_timer_starting_cpu,
+				  armada_370_xp_timer_dying_cpu);
+	}
 
 	register_syscore_ops(&armada_370_xp_timer_syscore_ops);
 }
include/linux/cpuhotplug.h +1 -0
@@ -43,6 +43,7 @@ enum cpuhp_state {
 	CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
 	CPUHP_AP_METAG_TIMER_STARTING,
 	CPUHP_AP_QCOM_TIMER_STARTING,
+	CPUHP_AP_ARMADA_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#58 lore raw

PATCH 44/66 clocksource/atlas7: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/timer-atlas7.c |   41 ++++++++-----------------------------
 include/linux/cpuhotplug.h         |    1 
 2 files changed, 10 insertions(+), 32 deletions(-)
drivers/clocksource/timer-atlas7.c +9 -32
@@ -172,9 +172,9 @@ static struct irqaction sirfsoc_timer1_i
 	.handler = sirfsoc_timer_interrupt,
 };
 
-static int sirfsoc_local_timer_setup(struct clock_event_device *ce)
+static int sirfsoc_local_timer_starting_cpu(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
+	struct clock_event_device *ce = per_cpu_ptr(sirfsoc_clockevent, cpu);
 	struct irqaction *action;
 
 	if (cpu == 0)
@@ -203,50 +203,27 @@ static int sirfsoc_local_timer_setup(str
 	return 0;
 }
 
-static void sirfsoc_local_timer_stop(struct clock_event_device *ce)
+static int sirfsoc_local_timer_dying_cpu(unsigned int cpu)
 {
-	int cpu = smp_processor_id();
-
 	sirfsoc_timer_count_disable(1);
 
 	if (cpu == 0)
 		remove_irq(sirfsoc_timer_irq.irq, &sirfsoc_timer_irq);
 	else
 		remove_irq(sirfsoc_timer1_irq.irq, &sirfsoc_timer1_irq);
+	return 0;
 }
 
-static int sirfsoc_cpu_notify(struct notifier_block *self,
-			      unsigned long action, void *hcpu)
-{
-	/*
-	 * Grab cpu pointer in each case to avoid spurious
-	 * preemptible warnings
-	 */
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		sirfsoc_local_timer_setup(this_cpu_ptr(sirfsoc_clockevent));
-		break;
-	case CPU_DYING:
-		sirfsoc_local_timer_stop(this_cpu_ptr(sirfsoc_clockevent));
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block sirfsoc_cpu_nb = {
-	.notifier_call = sirfsoc_cpu_notify,
-};
-
 static void __init sirfsoc_clockevent_init(void)
 {
 	sirfsoc_clockevent = alloc_percpu(struct clock_event_device);
 	BUG_ON(!sirfsoc_clockevent);
 
-	BUG_ON(register_cpu_notifier(&sirfsoc_cpu_nb));
-
-	/* Immediately configure the timer on the boot CPU */
-	sirfsoc_local_timer_setup(this_cpu_ptr(sirfsoc_clockevent));
+	/* Install and invoke hotplug callbacks */
+	cpuhp_setup_state(CPUHP_AP_MARCO_TIMER_STARTING,
+			  "AP_MARCO_TIMER_STARTING",
+			  sirfsoc_local_timer_starting_cpu,
+			  sirfsoc_local_timer_dying_cpu);
 }
 
 /* initialize the kernel jiffy timer source */
include/linux/cpuhotplug.h +1 -0
@@ -44,6 +44,7 @@ enum cpuhp_state {
 	CPUHP_AP_METAG_TIMER_STARTING,
 	CPUHP_AP_QCOM_TIMER_STARTING,
 	CPUHP_AP_ARMADA_TIMER_STARTING,
+	CPUHP_AP_MARCO_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#59 lore raw

PATCH 45/66 clocksource/mips-gic: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 drivers/clocksource/mips-gic-timer.c |   38 +++++++++++------------------------
 include/linux/cpuhotplug.h           |    1 
 2 files changed, 14 insertions(+), 25 deletions(-)
drivers/clocksource/mips-gic-timer.c +13 -25
@@ -49,10 +49,9 @@ struct irqaction gic_compare_irqaction =
 	.name = "timer",
 };
 
-static void gic_clockevent_cpu_init(struct clock_event_device *cd)
+static void gic_clockevent_cpu_init(unsigned int cpu,
+				    struct clock_event_device *cd)
 {
-	unsigned int cpu = smp_processor_id();
-
 	cd->name		= "MIPS GIC";
 	cd->features		= CLOCK_EVT_FEAT_ONESHOT |
 				  CLOCK_EVT_FEAT_C3STOP;
@@ -79,19 +78,10 @@ static void gic_update_frequency(void *d
 	clockevents_update_freq(this_cpu_ptr(&gic_clockevent_device), rate);
 }
 
-static int gic_cpu_notifier(struct notifier_block *nb, unsigned long action,
-				void *data)
+static int gic_starting_cpu(unsigned int cpu)
 {
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		gic_clockevent_cpu_init(this_cpu_ptr(&gic_clockevent_device));
-		break;
-	case CPU_DYING:
-		gic_clockevent_cpu_exit(this_cpu_ptr(&gic_clockevent_device));
-		break;
-	}
-
-	return NOTIFY_OK;
+	gic_clockevent_cpu_init(cpu, this_cpu_ptr(&gic_clockevent_device));
+	return 0;
 }
 
 static int gic_clk_notifier(struct notifier_block *nb, unsigned long action,
@@ -105,10 +95,11 @@ static int gic_clk_notifier(struct notif
 	return NOTIFY_OK;
 }
 
-
-static struct notifier_block gic_cpu_nb = {
-	.notifier_call = gic_cpu_notifier,
-};
+static int gic_dying_cpu(unsigned int cpu)
+{
+	gic_clockevent_cpu_exit(this_cpu_ptr(&gic_clockevent_device));
+	return 0;
+}
 
 static struct notifier_block gic_clk_nb = {
 	.notifier_call = gic_clk_notifier,
@@ -125,12 +116,9 @@ static int gic_clockevent_init(void)
 	if (ret < 0)
 		return ret;
 
-	ret = register_cpu_notifier(&gic_cpu_nb);
-	if (ret < 0)
-		pr_warn("GIC: Unable to register CPU notifier\n");
-
-	gic_clockevent_cpu_init(this_cpu_ptr(&gic_clockevent_device));
-
+	cpuhp_setup_state(CPUHP_AP_MIPS_GIC_TIMER_STARTING,
+			  "AP_MIPS_GIC_TIMER_STARTING", gic_starting_cpu,
+			  gic_dying_cpu);
 	return 0;
 }
 
include/linux/cpuhotplug.h +1 -0
@@ -45,6 +45,7 @@ enum cpuhp_state {
 	CPUHP_AP_QCOM_TIMER_STARTING,
 	CPUHP_AP_ARMADA_TIMER_STARTING,
 	CPUHP_AP_MARCO_TIMER_STARTING,
+	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#60 lore raw

PATCH 46/66 leds: trigger: cpu: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

This is a straightforward conversion. We place this callback last in the list so that the LED illuminates only after a successful bring up sequence.

---
 drivers/leds/trigger/ledtrig-cpu.c |   32 +++++++++++++++-----------------
 include/linux/cpuhotplug.h         |    1 +
 2 files changed, 16 insertions(+), 17 deletions(-)
drivers/leds/trigger/ledtrig-cpu.c +15 -17
@@ -92,25 +92,17 @@ static struct syscore_ops ledtrig_cpu_sy
 	.resume		= ledtrig_cpu_syscore_resume,
 };
 
-static int ledtrig_cpu_notify(struct notifier_block *self,
-					   unsigned long action, void *hcpu)
+static int ledtrig_starting_cpu(unsigned int cpu)
 {
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		ledtrig_cpu(CPU_LED_START);
-		break;
-	case CPU_DYING:
-		ledtrig_cpu(CPU_LED_STOP);
-		break;
-	}
-
-	return NOTIFY_OK;
+	ledtrig_cpu(CPU_LED_START);
+	return 0;
 }
 
-
-static struct notifier_block ledtrig_cpu_nb = {
-	.notifier_call = ledtrig_cpu_notify,
-};
+static int ledtrig_dying_cpu(unsigned int cpu)
+{
+	ledtrig_cpu(CPU_LED_STOP);
+	return 0;
+}
 
 static int __init ledtrig_cpu_init(void)
 {
@@ -133,7 +125,13 @@ static int __init ledtrig_cpu_init(void)
 	}
 
 	register_syscore_ops(&ledtrig_cpu_syscore_ops);
-	register_cpu_notifier(&ledtrig_cpu_nb);
+
+	/*
+	 * FIXME: Why needs this to happen in the interrupt disabled
+	 * low level bringup phase of a cpu?
+	 */
+	cpuhp_setup_state(CPUHP_AP_LEDTRIG_STARTING, "AP_LEDTRIG_STARTING",
+			  ledtrig_starting_cpu, ledtrig_dying_cpu);
 
 	pr_info("ledtrig-cpu: registered to indicate activity on CPUs\n");
 
include/linux/cpuhotplug.h +1 -0
@@ -47,6 +47,7 @@ enum cpuhp_state {
 	CPUHP_AP_MARCO_TIMER_STARTING,
 	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
+	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#61 lore raw

PATCH 47/66 arm: kvm: vgic: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.
The VGIC callback is run after KVM's main callback since it reflects the makefile order.

---
 include/linux/cpuhotplug.h |    1 +
 virt/kvm/arm/vgic.c        |   39 ++++++++-------------------------------
 2 files changed, 9 insertions(+), 31 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -47,6 +47,7 @@ enum cpuhp_state {
 	CPUHP_AP_MARCO_TIMER_STARTING,
 	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
+	CPUHP_AP_KVM_ARM_VGIC_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
virt/kvm/arm/vgic.c +8 -31
@@ -2326,32 +2326,18 @@ int vgic_has_attr_regs(const struct vgic
 		return -ENXIO;
 }
 
-static void vgic_init_maintenance_interrupt(void *info)
+static int vgic_starting_cpu(unsigned int cpu)
 {
 	enable_percpu_irq(vgic->maint_irq, 0);
+	return 0;
 }
 
-static int vgic_cpu_notify(struct notifier_block *self,
-			   unsigned long action, void *cpu)
+static int vgic_dying_cpu(unsigned int cpu)
 {
-	switch (action) {
-	case CPU_STARTING:
-	case CPU_STARTING_FROZEN:
-		vgic_init_maintenance_interrupt(NULL);
-		break;
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		disable_percpu_irq(vgic->maint_irq);
-		break;
-	}
-
-	return NOTIFY_OK;
+	disable_percpu_irq(vgic->maint_irq);
+	return 0;
 }
 
-static struct notifier_block vgic_cpu_nb = {
-	.notifier_call = vgic_cpu_notify,
-};
-
 static int kvm_vgic_probe(void)
 {
 	const struct gic_kvm_info *gic_kvm_info;
@@ -2392,19 +2378,10 @@ int kvm_vgic_hyp_init(void)
 		return ret;
 	}
 
-	ret = __register_cpu_notifier(&vgic_cpu_nb);
-	if (ret) {
-		kvm_err("Cannot register vgic CPU notifier\n");
-		goto out_free_irq;
-	}
-
-	on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1);
-
+	cpuhp_setup_state(CPUHP_AP_KVM_ARM_VGIC_STARTING,
+			  "AP_KVM_ARM_VGIC_STARTING", vgic_starting_cpu,
+			  vgic_dying_cpu);
 	return 0;
-
-out_free_irq:
-	free_percpu_irq(vgic->maint_irq, kvm_get_running_vcpus());
-	return ret;
 }
 
 int kvm_irq_map_gsi(struct kvm *kvm,
author maintainer
#62 lore raw

PATCH 48/66 arm: kvm: arch_timer: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 include/linux/cpuhotplug.h |    1 +
 virt/kvm/arm/arch_timer.c  |   35 +++++++++++------------------------
 2 files changed, 12 insertions(+), 24 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -48,6 +48,7 @@ enum cpuhp_state {
 	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_KVM_ARM_VGIC_STARTING,
+	CPUHP_AP_KVM_ARM_TIMER_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
virt/kvm/arm/arch_timer.c +11 -24
@@ -405,26 +405,17 @@ u64 kvm_arm_timer_get_reg(struct kvm_vcp
 	return (u64)-1;
 }
 
-static int kvm_timer_cpu_notify(struct notifier_block *self,
-				unsigned long action, void *cpu)
+static int kvm_timer_starting_cpu(unsigned int cpu)
 {
-	switch (action) {
-	case CPU_STARTING:
-	case CPU_STARTING_FROZEN:
-		kvm_timer_init_interrupt(NULL);
-		break;
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		disable_percpu_irq(host_vtimer_irq);
-		break;
-	}
-
-	return NOTIFY_OK;
+	kvm_timer_init_interrupt(NULL);
+	return 0;
 }
 
-static struct notifier_block kvm_timer_cpu_nb = {
-	.notifier_call = kvm_timer_cpu_notify,
-};
+static int kvm_timer_dying_cpu(unsigned int cpu)
+{
+	disable_percpu_irq(host_vtimer_irq);
+	return 0;
+}
 
 int kvm_timer_hyp_init(void)
 {
@@ -449,12 +440,6 @@ int kvm_timer_hyp_init(void)
 		goto out;
 	}
 
-	err = __register_cpu_notifier(&kvm_timer_cpu_nb);
-	if (err) {
-		kvm_err("Cannot register timer CPU notifier\n");
-		goto out_free;
-	}
-
 	wqueue = create_singlethread_workqueue("kvm_arch_timer");
 	if (!wqueue) {
 		err = -ENOMEM;
@@ -462,8 +447,10 @@ int kvm_timer_hyp_init(void)
 	}
 
 	kvm_info("virtual timer IRQ%d\n", host_vtimer_irq);
-	on_each_cpu(kvm_timer_init_interrupt, NULL, 1);
 
+	cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING,
+			  "AP_KVM_ARM_TIMER_STARTING", kvm_timer_starting_cpu,
+			  kvm_timer_dying_cpu);
 	goto out;
 out_free:
 	free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus());
author maintainer
#63 lore raw

PATCH 49/66 metag: perf: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/metag/kernel/perf/perf_event.c |   26 +++++++-------------------
 include/linux/cpuhotplug.h          |    1 +
 2 files changed, 8 insertions(+), 19 deletions(-)
arch/metag/kernel/perf/perf_event.c +7 -19
@@ -806,25 +806,16 @@ static struct metag_pmu _metag_pmu = {
 };
 
 /* PMU CPU hotplug notifier */
-static int metag_pmu_cpu_notify(struct notifier_block *b, unsigned long action,
-				void *hcpu)
+static int metag_pmu_starting_cpu(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned int)hcpu;
 	struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
 
-	if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING)
-		return NOTIFY_DONE;
-
 	memset(cpuc, 0, sizeof(struct cpu_hw_events));
 	raw_spin_lock_init(&cpuc->pmu_lock);
 
-	return NOTIFY_OK;
+	return 0;
 }
 
-static struct notifier_block metag_pmu_notifier = {
-	.notifier_call = metag_pmu_cpu_notify,
-};
-
 /* PMU Initialisation */
 static int __init init_hw_perf_events(void)
 {
@@ -876,16 +867,13 @@ static int __init init_hw_perf_events(vo
 	metag_out32(0, PERF_COUNT(0));
 	metag_out32(0, PERF_COUNT(1));
 
-	for_each_possible_cpu(cpu) {
-		struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
-
-		memset(cpuc, 0, sizeof(struct cpu_hw_events));
-		raw_spin_lock_init(&cpuc->pmu_lock);
-	}
+	cpuhp_setup_state(CPUHP_AP_PERF_METAG_STARTING,
+			  "AP_PERF_METAG_STARTING", metag_pmu_starting_cpu,
+			  NULL);
 
-	register_cpu_notifier(&metag_pmu_notifier);
 	ret = perf_pmu_register(&pmu, metag_pmu->name, PERF_TYPE_RAW);
-out:
+	if (ret)
+		cpuhp_remove_state_nocalls(CPUHP_AP_PERF_METAG_STARTING);
 	return ret;
 }
 early_initcall(init_hw_perf_events);
include/linux/cpuhotplug.h +1 -0
@@ -35,6 +35,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CQM_STARTING,
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
 	CPUHP_AP_PERF_XTENSA_STARTING,
+	CPUHP_AP_PERF_METAG_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
author maintainer
#64 lore raw

PATCH 50/66 arm: l2c: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

Cc Russell King <[email protected]>
Cc Marek Szyprowski <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/mm/cache-l2x0.c   |   27 +++++++++++++--------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 14 insertions(+), 14 deletions(-)
arch/arm/mm/cache-l2x0.c +13 -14
@@ -597,17 +597,16 @@ static void l2c310_configure(void __iome
 			      L310_POWER_CTRL);
 }
 
-static int l2c310_cpu_enable_flz(struct notifier_block *nb, unsigned long act, void *data)
+static int l2c310_starting_cpu(unsigned int cpu)
 {
-	switch (act & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
-		break;
-	case CPU_DYING:
-		set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
-		break;
-	}
-	return NOTIFY_OK;
+	set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
+	return 0;
+}
+
+static int l2c310_dying_cpu(unsigned int cpu)
+{
+	set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
+	return 0;
 }
 
 static void __init l2c310_enable(void __iomem *base, unsigned num_lock)
@@ -678,10 +677,10 @@ static void __init l2c310_enable(void __
 			power_ctrl & L310_STNDBY_MODE_EN ? "en" : "dis");
 	}
 
-	if (aux & L310_AUX_CTRL_FULL_LINE_ZERO) {
-		set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
-		cpu_notifier(l2c310_cpu_enable_flz, 0);
-	}
+	if (aux & L310_AUX_CTRL_FULL_LINE_ZERO)
+		cpuhp_setup_state(CPUHP_AP_ARM_L2X0_STARTING,
+				  "AP_ARM_L2X0_STARTING", l2c310_starting_cpu,
+				  l2c310_dying_cpu);
 }
 
 static void __init l2c310_fixup(void __iomem *base, u32 cache_id,
include/linux/cpuhotplug.h +1 -0
@@ -38,6 +38,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_METAG_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
+	CPUHP_AP_ARM_L2X0_STARTING,
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
 	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
 	CPUHP_AP_DUMMY_TIMER_STARTING,
author maintainer
#65 lore raw

PATCH 51/66 arm: twd: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine. The callbacks won't be invoked on already online CPUs.

Cc Russell King <[email protected]>
Cc Viresh Kumar <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/kernel/smp_twd.c  |   31 +++++++++++--------------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 12 insertions(+), 20 deletions(-)
arch/arm/kernel/smp_twd.c +11 -20
@@ -310,24 +310,17 @@ static void twd_timer_setup(void)
 	enable_percpu_irq(clk->irq, 0);
 }
 
-static int twd_timer_cpu_notify(struct notifier_block *self,
-				unsigned long action, void *hcpu)
+static int twd_timer_starting_cpu(unsigned int cpu)
 {
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		twd_timer_setup();
-		break;
-	case CPU_DYING:
-		twd_timer_stop();
-		break;
-	}
-
-	return NOTIFY_OK;
+	twd_timer_setup();
+	return 0;
 }
 
-static struct notifier_block twd_timer_cpu_nb = {
-	.notifier_call = twd_timer_cpu_notify,
-};
+static int twd_timer_dying_cpu(unsigned int cpu)
+{
+	twd_timer_stop();
+	return 0;
+}
 
 static int __init twd_local_timer_common_register(struct device_node *np)
 {
@@ -345,9 +338,9 @@ static int __init twd_local_timer_common
 		goto out_free;
 	}
 
-	err = register_cpu_notifier(&twd_timer_cpu_nb);
-	if (err)
-		goto out_irq;
+	cpuhp_setup_state_nocalls(CPUHP_AP_ARM_TWD_STARTING,
+				  "AP_ARM_TWD_STARTING",
+				  twd_timer_starting_cpu, twd_timer_dying_cpu);
 
 	twd_get_clock(np);
 	if (!of_property_read_bool(np, "always-on"))
@@ -365,8 +358,6 @@ static int __init twd_local_timer_common
 
 	return 0;
 
-out_irq:
-	free_percpu_irq(twd_ppi, twd_evt);
 out_free:
 	iounmap(twd_base);
 	twd_base = NULL;
include/linux/cpuhotplug.h +1 -0
@@ -42,6 +42,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_ARCH_TIMER_STARTING,
 	CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
 	CPUHP_AP_DUMMY_TIMER_STARTING,
+	CPUHP_AP_ARM_TWD_STARTING,
 	CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
 	CPUHP_AP_METAG_TIMER_STARTING,
 	CPUHP_AP_QCOM_TIMER_STARTING,
author maintainer
#66 lore raw

PATCH 52/66 arm: xen: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.
The get_cpu() in xen_starting_cpu() boils down to preempt_disable() since we already know the CPU we run on. Disabling preemption shouldn't be required here from what I see since it we don't switch CPUs while invoking the function.

---
 arch/arm/xen/enlighten.c   |   41 +++++++++++------------------------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 12 insertions(+), 30 deletions(-)
arch/arm/xen/enlighten.c +11 -30
@@ -161,12 +161,11 @@ static struct notifier_block xen_pvclock
 	.notifier_call = xen_pvclock_gtod_notify,
 };
 
-static void xen_percpu_init(void)
+static int xen_starting_cpu(unsigned int cpu)
 {
 	struct vcpu_register_vcpu_info info;
 	struct vcpu_info *vcpup;
 	int err;
-	int cpu = get_cpu();
 
 	/* 
 	 * VCPUOP_register_vcpu_info cannot be called twice for the same
@@ -190,7 +189,13 @@ static void xen_percpu_init(void)
 
 after_register_vcpu_info:
 	enable_percpu_irq(xen_events_irq, 0);
-	put_cpu();
+	return 0;
+}
+
+static int xen_dying_cpu(unsigned int cpu)
+{
+	disable_percpu_irq(xen_events_irq);
+	return 0;
 }
 
 static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
@@ -209,28 +214,6 @@ static void xen_power_off(void)
 	BUG_ON(rc);
 }
 
-static int xen_cpu_notification(struct notifier_block *self,
-				unsigned long action,
-				void *hcpu)
-{
-	switch (action) {
-	case CPU_STARTING:
-		xen_percpu_init();
-		break;
-	case CPU_DYING:
-		disable_percpu_irq(xen_events_irq);
-		break;
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block xen_cpu_notifier = {
-	.notifier_call = xen_cpu_notification,
-};
-
 static irqreturn_t xen_arm_callback(int irq, void *arg)
 {
 	xen_hvm_evtchn_do_upcall();
@@ -351,16 +334,14 @@ static int __init xen_guest_init(void)
 		return -EINVAL;
 	}
 
-	xen_percpu_init();
-
-	register_cpu_notifier(&xen_cpu_notifier);
-
 	pv_time_ops.steal_clock = xen_stolen_accounting;
 	static_key_slow_inc(&paravirt_steal_enabled);
 	if (xen_initial_domain())
 		pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier);
 
-	return 0;
+	return cpuhp_setup_state(CPUHP_AP_ARM_XEN_STARTING,
+				 "AP_ARM_XEN_STARTING", xen_starting_cpu,
+				 xen_dying_cpu);
 }
 early_initcall(xen_guest_init);
 
include/linux/cpuhotplug.h +1 -0
@@ -52,6 +52,7 @@ enum cpuhp_state {
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_KVM_ARM_VGIC_STARTING,
 	CPUHP_AP_KVM_ARM_TIMER_STARTING,
+	CPUHP_AP_ARM_XEN_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author maintainer
#67 lore raw

PATCH 53/66 MIPS: Loongson-3: Convert oprofile to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/mips/oprofile/op_model_loongson3.c |   35 ++++++++++++--------------------
 include/linux/cpuhotplug.h              |    1 
 2 files changed, 15 insertions(+), 21 deletions(-)
arch/mips/oprofile/op_model_loongson3.c +14 -21
@@ -168,33 +168,26 @@ static int loongson3_perfcount_handler(v
 	return handled;
 }
 
-static int loongson3_cpu_callback(struct notifier_block *nfb,
-	unsigned long action, void *hcpu)
+static int loongson3_starting_cpu(unsigned int cpu)
 {
-	switch (action) {
-	case CPU_STARTING:
-	case CPU_STARTING_FROZEN:
-		write_c0_perflo1(reg.control1);
-		write_c0_perflo2(reg.control2);
-		break;
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		write_c0_perflo1(0xc0000000);
-		write_c0_perflo2(0x40000000);
-		break;
-	}
-
-	return NOTIFY_OK;
+	write_c0_perflo1(reg.control1);
+	write_c0_perflo2(reg.control2);
+	return 0;
 }
 
-static struct notifier_block loongson3_notifier_block = {
-	.notifier_call = loongson3_cpu_callback
-};
+static int loongson3_dying_cpu(unsigned int cpu)
+{
+	write_c0_perflo1(0xc0000000);
+	write_c0_perflo2(0x40000000);
+	return 0;
+}
 
 static int __init loongson3_init(void)
 {
 	on_each_cpu(reset_counters, NULL, 1);
-	register_hotcpu_notifier(&loongson3_notifier_block);
+	cpuhp_setup_state_nocalls(CPUHP_AP_MIPS_OP_LOONGSON3_STARTING,
+				  "AP_MIPS_OP_LOONGSON3_STARTING",
+				  loongson3_starting_cpu, loongson3_dying_cpu);
 	save_perf_irq = perf_irq;
 	perf_irq = loongson3_perfcount_handler;
 
@@ -204,7 +197,7 @@ static int __init loongson3_init(void)
 static void loongson3_exit(void)
 {
 	on_each_cpu(reset_counters, NULL, 1);
-	unregister_hotcpu_notifier(&loongson3_notifier_block);
+	cpuhp_remove_state_nocalls(CPUHP_AP_MIPS_OP_LOONGSON3_STARTING);
 	perf_irq = save_perf_irq;
 }
 
include/linux/cpuhotplug.h +1 -0
@@ -36,6 +36,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_X86_CSTATE_STARTING,
 	CPUHP_AP_PERF_XTENSA_STARTING,
 	CPUHP_AP_PERF_METAG_STARTING,
+	CPUHP_AP_MIPS_OP_LOONGSON3_STARTING,
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_ARM_L2X0_STARTING,
Acked-by on v1 53/66
#68 lore raw

Re: [patch 53/66] MIPS: Loongson-3: Convert oprofile to hotplug state machine

Thank, looks ok. I assume you want to merge this with the remainder of of the series, so:

Ralf

author maintainer
#69 lore raw

PATCH 54/66 hwtracing: coresight-etm3x: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

This driver has an asymmetry of ONLINE code without any corresponding tear down code. Otherwise, this is a straightforward conversion.

Cc Mathieu Poirier <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/hwtracing/coresight/coresight-etm3x.c |   90 ++++++++++++++------------
 include/linux/cpuhotplug.h                    |    1 
 2 files changed, 50 insertions(+), 41 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x.c +49 -41
@@ -481,8 +481,7 @@ static int etm_enable_sysfs(struct cores
 
 	/*
 	 * Configure the ETM only if the CPU is online.  If it isn't online
-	 * hw configuration will take place when 'CPU_STARTING' is received
-	 * in @etm_cpu_callback.
+	 * hw configuration will take place on the local CPU during bring up.
 	 */
 	if (cpu_online(drvdata->cpu)) {
 		ret = smp_call_function_single(drvdata->cpu,
@@ -641,47 +640,44 @@ static const struct coresight_ops etm_cs
 	.source_ops	= &etm_source_ops,
 };
 
-static int etm_cpu_callback(struct notifier_block *nfb, unsigned long action,
-			    void *hcpu)
+static int etm_online_cpu(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned long)hcpu;
-
 	if (!etmdrvdata[cpu])
-		goto out;
+		return 0;
 
-	switch (action & (~CPU_TASKS_FROZEN)) {
-	case CPU_STARTING:
-		spin_lock(&etmdrvdata[cpu]->spinlock);
-		if (!etmdrvdata[cpu]->os_unlock) {
-			etm_os_unlock(etmdrvdata[cpu]);
-			etmdrvdata[cpu]->os_unlock = true;
-		}
-
-		if (local_read(&etmdrvdata[cpu]->mode))
-			etm_enable_hw(etmdrvdata[cpu]);
-		spin_unlock(&etmdrvdata[cpu]->spinlock);
-		break;
+	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
+		coresight_enable(etmdrvdata[cpu]->csdev);
+	return 0;
+}
 
-	case CPU_ONLINE:
-		if (etmdrvdata[cpu]->boot_enable &&
-		    !etmdrvdata[cpu]->sticky_enable)
-			coresight_enable(etmdrvdata[cpu]->csdev);
-		break;
+static int etm_starting_cpu(unsigned int cpu)
+{
+	if (!etmdrvdata[cpu])
+		return 0;
 
-	case CPU_DYING:
-		spin_lock(&etmdrvdata[cpu]->spinlock);
-		if (local_read(&etmdrvdata[cpu]->mode))
-			etm_disable_hw(etmdrvdata[cpu]);
-		spin_unlock(&etmdrvdata[cpu]->spinlock);
-		break;
+	spin_lock(&etmdrvdata[cpu]->spinlock);
+	if (!etmdrvdata[cpu]->os_unlock) {
+		etm_os_unlock(etmdrvdata[cpu]);
+		etmdrvdata[cpu]->os_unlock = true;
 	}
-out:
-	return NOTIFY_OK;
+
+	if (local_read(&etmdrvdata[cpu]->mode))
+		etm_enable_hw(etmdrvdata[cpu]);
+	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	return 0;
 }
 
-static struct notifier_block etm_cpu_notifier = {
-	.notifier_call = etm_cpu_callback,
-};
+static int etm_dying_cpu(unsigned int cpu)
+{
+	if (!etmdrvdata[cpu])
+		return 0;
+
+	spin_lock(&etmdrvdata[cpu]->spinlock);
+	if (local_read(&etmdrvdata[cpu]->mode))
+		etm_disable_hw(etmdrvdata[cpu]);
+	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	return 0;
+}
 
 static bool etm_arch_supported(u8 arch)
 {
@@ -750,6 +746,8 @@ static void etm_init_trace_id(struct etm
 	drvdata->traceid = coresight_get_trace_id(drvdata->cpu);
 }
 
+static enum cpuhp_state hp_online;
+
 static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 {
 	int ret;
@@ -806,9 +804,17 @@ static int etm_probe(struct amba_device
 				     etm_init_arch_data,  drvdata, 1))
 		dev_err(dev, "ETM arch init failed\n");
 
-	if (!etm_count++)
-		register_hotcpu_notifier(&etm_cpu_notifier);
-
+	if (!etm_count++) {
+		cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
+					  "AP_ARM_CORESIGHT_STARTING",
+					  etm_starting_cpu, etm_dying_cpu);
+		ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+						"AP_ARM_CORESIGHT_ONLINE",
+						etm_online_cpu, NULL);
+		if (ret < 0)
+			goto err_arch_supported;
+		hp_online = ret;
+	}
 	put_online_cpus();
 
 	if (etm_arch_supported(drvdata->arch) == false) {
@@ -839,7 +845,6 @@ static int etm_probe(struct amba_device
 
 	pm_runtime_put(&adev->dev);
 	dev_info(dev, "%s initialized\n", (char *)id->data);
-
 	if (boot_enable) {
 		coresight_enable(drvdata->csdev);
 		drvdata->boot_enable = true;
@@ -848,8 +853,11 @@ static int etm_probe(struct amba_device
 	return 0;
 
 err_arch_supported:
-	if (--etm_count == 0)
-		unregister_hotcpu_notifier(&etm_cpu_notifier);
+	if (--etm_count == 0) {
+		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+		if (hp_online)
+			cpuhp_remove_state_nocalls(hp_online);
+	}
 	return ret;
 }
 
include/linux/cpuhotplug.h +1 -0
@@ -54,6 +54,7 @@ enum cpuhp_state {
 	CPUHP_AP_KVM_ARM_VGIC_STARTING,
 	CPUHP_AP_KVM_ARM_TIMER_STARTING,
 	CPUHP_AP_ARM_XEN_STARTING,
+	CPUHP_AP_ARM_CORESIGHT_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
Acked-by on v1 54/66
#70 lore raw

Re: [patch 54/66] hwtracing: coresight-etm3x: Convert to hotplug state machine

Quoted 107 lines · Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

This driver has an asymmetry of ONLINE code without any corresponding tear down code. Otherwise, this is a straightforward conversion.

Cc Mathieu Poirier <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/hwtracing/coresight/coresight-etm3x.c |   90 ++++++++++++++------------
 include/linux/cpuhotplug.h                    |    1
 2 files changed, 50 insertions(+), 41 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x.c +31 -35
@@ -481,8 +481,7 @@ static int etm_enable_sysfs(struct cores
 
        /*
         * Configure the ETM only if the CPU is online.  If it isn't online
-        * hw configuration will take place when 'CPU_STARTING' is received
-        * in @etm_cpu_callback.
+        * hw configuration will take place on the local CPU during bring up.
         */
        if (cpu_online(drvdata->cpu)) {
                ret = smp_call_function_single(drvdata->cpu,
@@ -641,47 +640,44 @@ static const struct coresight_ops etm_cs
        .source_ops     = &etm_source_ops,
 };
 
-static int etm_cpu_callback(struct notifier_block *nfb, unsigned long action,
-                           void *hcpu)
+static int etm_online_cpu(unsigned int cpu)
 {
-       unsigned int cpu = (unsigned long)hcpu;
-
        if (!etmdrvdata[cpu])
-               goto out;
+               return 0;
 
-       switch (action & (~CPU_TASKS_FROZEN)) {
-       case CPU_STARTING:
-               spin_lock(&etmdrvdata[cpu]->spinlock);
-               if (!etmdrvdata[cpu]->os_unlock) {
-                       etm_os_unlock(etmdrvdata[cpu]);
-                       etmdrvdata[cpu]->os_unlock = true;
-               }
-
-               if (local_read(&etmdrvdata[cpu]->mode))
-                       etm_enable_hw(etmdrvdata[cpu]);
-               spin_unlock(&etmdrvdata[cpu]->spinlock);
-               break;
+       if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
+               coresight_enable(etmdrvdata[cpu]->csdev);
+       return 0;
+}
 
-       case CPU_ONLINE:
-               if (etmdrvdata[cpu]->boot_enable &&
-                   !etmdrvdata[cpu]->sticky_enable)
-                       coresight_enable(etmdrvdata[cpu]->csdev);
-               break;
+static int etm_starting_cpu(unsigned int cpu)
+{
+       if (!etmdrvdata[cpu])
+               return 0;
 
-       case CPU_DYING:
-               spin_lock(&etmdrvdata[cpu]->spinlock);
-               if (local_read(&etmdrvdata[cpu]->mode))
-                       etm_disable_hw(etmdrvdata[cpu]);
-               spin_unlock(&etmdrvdata[cpu]->spinlock);
-               break;
+       spin_lock(&etmdrvdata[cpu]->spinlock);
+       if (!etmdrvdata[cpu]->os_unlock) {
+               etm_os_unlock(etmdrvdata[cpu]);
+               etmdrvdata[cpu]->os_unlock = true;
        }
-out:
-       return NOTIFY_OK;
+
+       if (local_read(&etmdrvdata[cpu]->mode))
+               etm_enable_hw(etmdrvdata[cpu]);
+       spin_unlock(&etmdrvdata[cpu]->spinlock);
+       return 0;
 }
 
-static struct notifier_block etm_cpu_notifier = {
-       .notifier_call = etm_cpu_callback,
-};
+static int etm_dying_cpu(unsigned int cpu)
+{
+       if (!etmdrvdata[cpu])
+               return 0;
+
+       spin_lock(&etmdrvdata[cpu]->spinlock);
+       if (local_read(&etmdrvdata[cpu]->mode))
+               etm_disable_hw(etmdrvdata[cpu]);
+       spin_unlock(&etmdrvdata[cpu]->spinlock);
+       return 0;
+}
 
 static bool etm_arch_supported(u8 arch)
 {

drivers/hwtracing/coresight/coresight-etm3x.c static void etm_init_trace_id(struct etm · line 750

Quoted 5 lines
drivers/hwtracing/coresight/coresight-etm3x.c +2 -0
@@ -750,6 +746,8 @@ static void etm_init_trace_id(struct etm
        drvdata->traceid = coresight_get_trace_id(drvdata->cpu);
 }
 
+static enum cpuhp_state hp_online;
+

Can we put this at the top of the file with the other global declaration?

Quoted 51 lines
drivers/hwtracing/coresight/coresight-etm3x.c +16 -6
 static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 {
        int ret;
@@ -806,9 +804,17 @@ static int etm_probe(struct amba_device
                                     etm_init_arch_data,  drvdata, 1))
                dev_err(dev, "ETM arch init failed\n");
 
-       if (!etm_count++)
-               register_hotcpu_notifier(&etm_cpu_notifier);
-
+       if (!etm_count++) {
+               cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
+                                         "AP_ARM_CORESIGHT_STARTING",
+                                         etm_starting_cpu, etm_dying_cpu);
+               ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+                                               "AP_ARM_CORESIGHT_ONLINE",
+                                               etm_online_cpu, NULL);
+               if (ret < 0)
+                       goto err_arch_supported;
+               hp_online = ret;
+       }
        put_online_cpus();
 
        if (etm_arch_supported(drvdata->arch) == false) {
@@ -839,7 +845,6 @@ static int etm_probe(struct amba_device
 
        pm_runtime_put(&adev->dev);
        dev_info(dev, "%s initialized\n", (char *)id->data);
-
        if (boot_enable) {
                coresight_enable(drvdata->csdev);
                drvdata->boot_enable = true;
@@ -848,8 +853,11 @@ static int etm_probe(struct amba_device
        return 0;
 
 err_arch_supported:
-       if (--etm_count == 0)
-               unregister_hotcpu_notifier(&etm_cpu_notifier);
+       if (--etm_count == 0) {
+               cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+               if (hp_online)
+                       cpuhp_remove_state_nocalls(hp_online);
+       }
        return ret;
 }
 

include/linux/cpuhotplug.h enum cpuhp_state { · line 60

Quoted 7 lines
include/linux/cpuhotplug.h +1 -0
@@ -54,6 +54,7 @@ enum cpuhp_state {
        CPUHP_AP_KVM_ARM_VGIC_STARTING,
        CPUHP_AP_KVM_ARM_TIMER_STARTING,
        CPUHP_AP_ARM_XEN_STARTING,
+       CPUHP_AP_ARM_CORESIGHT_STARTING,
        CPUHP_AP_LEDTRIG_STARTING,
        CPUHP_AP_NOTIFY_STARTING,
        CPUHP_AP_ONLINE,

This looks good to me - thanks for contribution. With the above change,

author maintainer
#71 lore raw

PATCH 55/66 hwtracing: coresight-etm4x: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

This driver has an asymmetry of ONLINE code without any corresponding tear down code. Otherwise, this is a straightforward conversion.

Cc Mathieu Poirier <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/hwtracing/coresight/coresight-etm4x.c |   93 ++++++++++++++------------
 include/linux/cpuhotplug.h                    |    1 
 2 files changed, 53 insertions(+), 41 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +52 -41
@@ -673,53 +673,52 @@ void etm4_config_trace_mode(struct etmv4
 	config->addr_acc[ETM_DEFAULT_ADDR_COMP + 1] = addr_acc;
 }
 
-static int etm4_cpu_callback(struct notifier_block *nfb, unsigned long action,
-			    void *hcpu)
+static int etm4_online_cpu(unsigned int cpu)
 {
-	unsigned int cpu = (unsigned long)hcpu;
+	if (!etmdrvdata[cpu])
+		return 0;
+
+	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
+		coresight_enable(etmdrvdata[cpu]->csdev);
+	return 0;
+}
+
+static int etm4_starting_cpu(unsigned int cpu)
+{
+	if (!etmdrvdata[cpu])
+		return 0;
+
+	spin_lock(&etmdrvdata[cpu]->spinlock);
+	if (!etmdrvdata[cpu]->os_unlock) {
+		etm4_os_unlock(etmdrvdata[cpu]);
+		etmdrvdata[cpu]->os_unlock = true;
+	}
 
+	if (local_read(&etmdrvdata[cpu]->mode))
+		etm4_enable_hw(etmdrvdata[cpu]);
+	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	return 0;
+}
+
+static int etm4_dying_cpu(unsigned int cpu)
+{
 	if (!etmdrvdata[cpu])
-		goto out;
+		return 0;
 
-	switch (action & (~CPU_TASKS_FROZEN)) {
-	case CPU_STARTING:
-		spin_lock(&etmdrvdata[cpu]->spinlock);
-		if (!etmdrvdata[cpu]->os_unlock) {
-			etm4_os_unlock(etmdrvdata[cpu]);
-			etmdrvdata[cpu]->os_unlock = true;
-		}
-
-		if (local_read(&etmdrvdata[cpu]->mode))
-			etm4_enable_hw(etmdrvdata[cpu]);
-		spin_unlock(&etmdrvdata[cpu]->spinlock);
-		break;
-
-	case CPU_ONLINE:
-		if (etmdrvdata[cpu]->boot_enable &&
-			!etmdrvdata[cpu]->sticky_enable)
-			coresight_enable(etmdrvdata[cpu]->csdev);
-		break;
-
-	case CPU_DYING:
-		spin_lock(&etmdrvdata[cpu]->spinlock);
-		if (local_read(&etmdrvdata[cpu]->mode))
-			etm4_disable_hw(etmdrvdata[cpu]);
-		spin_unlock(&etmdrvdata[cpu]->spinlock);
-		break;
-	}
-out:
-	return NOTIFY_OK;
-}
-
-static struct notifier_block etm4_cpu_notifier = {
-	.notifier_call = etm4_cpu_callback,
-};
+	spin_lock(&etmdrvdata[cpu]->spinlock);
+	if (local_read(&etmdrvdata[cpu]->mode))
+		etm4_disable_hw(etmdrvdata[cpu]);
+	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	return 0;
+}
 
 static void etm4_init_trace_id(struct etmv4_drvdata *drvdata)
 {
 	drvdata->trcid = coresight_get_trace_id(drvdata->cpu);
 }
 
+static enum cpuhp_state hp_online;
+
 static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 {
 	int ret;
@@ -767,8 +766,17 @@ static int etm4_probe(struct amba_device
 				etm4_init_arch_data,  drvdata, 1))
 		dev_err(dev, "ETM arch init failed\n");
 
-	if (!etm4_count++)
-		register_hotcpu_notifier(&etm4_cpu_notifier);
+	if (!etm4_count++) {
+		cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT4_STARTING,
+					  "AP_ARM_CORESIGHT4_STARTING",
+					  etm4_starting_cpu, etm4_dying_cpu);
+		ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+						"AP_ARM_CORESIGHT4_ONLINE",
+						etm4_online_cpu, NULL);
+		if (ret < 0)
+			goto err_arch_supported;
+		hp_online = ret;
+	}
 
 	put_online_cpus();
 
@@ -809,8 +817,11 @@ static int etm4_probe(struct amba_device
 	return 0;
 
 err_arch_supported:
-	if (--etm4_count == 0)
-		unregister_hotcpu_notifier(&etm4_cpu_notifier);
+	if (--etm4_count == 0) {
+		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT4_STARTING);
+		if (hp_online)
+			cpuhp_remove_state_nocalls(hp_online);
+	}
 	return ret;
 }
 
include/linux/cpuhotplug.h +1 -0
@@ -55,6 +55,7 @@ enum cpuhp_state {
 	CPUHP_AP_KVM_ARM_TIMER_STARTING,
 	CPUHP_AP_ARM_XEN_STARTING,
 	CPUHP_AP_ARM_CORESIGHT_STARTING,
+	CPUHP_AP_ARM_CORESIGHT4_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
Acked-by on v1 55/66
#72 lore raw

Re: [patch 55/66] hwtracing: coresight-etm4x: Convert to hotplug state machine

Quoted 93 lines · Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

This driver has an asymmetry of ONLINE code without any corresponding tear down code. Otherwise, this is a straightforward conversion.

Cc Mathieu Poirier <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/hwtracing/coresight/coresight-etm4x.c |   93 ++++++++++++++------------
 include/linux/cpuhotplug.h                    |    1
 2 files changed, 53 insertions(+), 41 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +32 -37
@@ -673,53 +673,52 @@ void etm4_config_trace_mode(struct etmv4
        config->addr_acc[ETM_DEFAULT_ADDR_COMP + 1] = addr_acc;
 }
 
-static int etm4_cpu_callback(struct notifier_block *nfb, unsigned long action,
-                           void *hcpu)
+static int etm4_online_cpu(unsigned int cpu)
 {
-       unsigned int cpu = (unsigned long)hcpu;
+       if (!etmdrvdata[cpu])
+               return 0;
+
+       if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
+               coresight_enable(etmdrvdata[cpu]->csdev);
+       return 0;
+}
+
+static int etm4_starting_cpu(unsigned int cpu)
+{
+       if (!etmdrvdata[cpu])
+               return 0;
+
+       spin_lock(&etmdrvdata[cpu]->spinlock);
+       if (!etmdrvdata[cpu]->os_unlock) {
+               etm4_os_unlock(etmdrvdata[cpu]);
+               etmdrvdata[cpu]->os_unlock = true;
+       }
 
+       if (local_read(&etmdrvdata[cpu]->mode))
+               etm4_enable_hw(etmdrvdata[cpu]);
+       spin_unlock(&etmdrvdata[cpu]->spinlock);
+       return 0;
+}
+
+static int etm4_dying_cpu(unsigned int cpu)
+{
        if (!etmdrvdata[cpu])
-               goto out;
+               return 0;
 
-       switch (action & (~CPU_TASKS_FROZEN)) {
-       case CPU_STARTING:
-               spin_lock(&etmdrvdata[cpu]->spinlock);
-               if (!etmdrvdata[cpu]->os_unlock) {
-                       etm4_os_unlock(etmdrvdata[cpu]);
-                       etmdrvdata[cpu]->os_unlock = true;
-               }
-
-               if (local_read(&etmdrvdata[cpu]->mode))
-                       etm4_enable_hw(etmdrvdata[cpu]);
-               spin_unlock(&etmdrvdata[cpu]->spinlock);
-               break;
-
-       case CPU_ONLINE:
-               if (etmdrvdata[cpu]->boot_enable &&
-                       !etmdrvdata[cpu]->sticky_enable)
-                       coresight_enable(etmdrvdata[cpu]->csdev);
-               break;
-
-       case CPU_DYING:
-               spin_lock(&etmdrvdata[cpu]->spinlock);
-               if (local_read(&etmdrvdata[cpu]->mode))
-                       etm4_disable_hw(etmdrvdata[cpu]);
-               spin_unlock(&etmdrvdata[cpu]->spinlock);
-               break;
-       }
-out:
-       return NOTIFY_OK;
-}
-
-static struct notifier_block etm4_cpu_notifier = {
-       .notifier_call = etm4_cpu_callback,
-};
+       spin_lock(&etmdrvdata[cpu]->spinlock);
+       if (local_read(&etmdrvdata[cpu]->mode))
+               etm4_disable_hw(etmdrvdata[cpu]);
+       spin_unlock(&etmdrvdata[cpu]->spinlock);

drivers/hwtracing/coresight/coresight-etm4x.c void etm4_config_trace_mode(struct etmv4 · line 721

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +4 -0
+       return 0;
+}
 
 static void etm4_init_trace_id(struct etmv4_drvdata *drvdata)
 {
        drvdata->trcid = coresight_get_trace_id(drvdata->cpu);
 }
 
+static enum cpuhp_state hp_online;
+

Same comment as with ETMv3 - I'd like to see this at the top of the file with the rest of the global declaration.

Quoted 42 lines
drivers/hwtracing/coresight/coresight-etm4x.c +16 -4
 static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 {
        int ret;
@@ -767,8 +766,17 @@ static int etm4_probe(struct amba_device
                                etm4_init_arch_data,  drvdata, 1))
                dev_err(dev, "ETM arch init failed\n");
 
-       if (!etm4_count++)
-               register_hotcpu_notifier(&etm4_cpu_notifier);
+       if (!etm4_count++) {
+               cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT4_STARTING,
+                                         "AP_ARM_CORESIGHT4_STARTING",
+                                         etm4_starting_cpu, etm4_dying_cpu);
+               ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+                                               "AP_ARM_CORESIGHT4_ONLINE",
+                                               etm4_online_cpu, NULL);
+               if (ret < 0)
+                       goto err_arch_supported;
+               hp_online = ret;
+       }
 
        put_online_cpus();
 
@@ -809,8 +817,11 @@ static int etm4_probe(struct amba_device
        return 0;
 
 err_arch_supported:
-       if (--etm4_count == 0)
-               unregister_hotcpu_notifier(&etm4_cpu_notifier);
+       if (--etm4_count == 0) {
+               cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT4_STARTING);
+               if (hp_online)
+                       cpuhp_remove_state_nocalls(hp_online);
+       }
        return ret;
 }
 

include/linux/cpuhotplug.h enum cpuhp_state { · line 61

Quoted 7 lines
include/linux/cpuhotplug.h +1 -0
@@ -55,6 +55,7 @@ enum cpuhp_state {
        CPUHP_AP_KVM_ARM_TIMER_STARTING,
        CPUHP_AP_ARM_XEN_STARTING,
        CPUHP_AP_ARM_CORESIGHT_STARTING,
+       CPUHP_AP_ARM_CORESIGHT4_STARTING,
        CPUHP_AP_LEDTRIG_STARTING,
        CPUHP_AP_NOTIFY_STARTING,
        CPUHP_AP_ONLINE,

With the above change,

author maintainer
#73 lore raw

PATCH 56/66 arm64: armv8 deprecated: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm64/kernel/armv8_deprecated.c |   22 +++++-----------------
 include/linux/cpuhotplug.h           |    1 +
 2 files changed, 6 insertions(+), 17 deletions(-)
arch/arm64/kernel/armv8_deprecated.c +5 -17
@@ -121,7 +121,7 @@ static int run_all_cpu_set_hw_mode(struc
  *  0 		- If all the hooks ran successfully.
  * -EINVAL	- At least one hook is not supported by the CPU.
  */
-static int run_all_insn_set_hw_mode(unsigned long cpu)
+static int run_all_insn_set_hw_mode(unsigned int cpu)
 {
 	int rc = 0;
 	unsigned long flags;
@@ -131,7 +131,7 @@ static int run_all_insn_set_hw_mode(unsi
 	list_for_each_entry(insn, &insn_emulation, node) {
 		bool enable = (insn->current_mode == INSN_HW);
 		if (insn->ops->set_hw_mode && insn->ops->set_hw_mode(enable)) {
-			pr_warn("CPU[%ld] cannot support the emulation of %s",
+			pr_warn("CPU[%u] cannot support the emulation of %s",
 				cpu, insn->ops->name);
 			rc = -EINVAL;
 		}
@@ -617,20 +617,6 @@ static struct insn_emulation_ops setend_
 	.set_hw_mode = setend_set_hw_mode,
 };
 
-static int insn_cpu_hotplug_notify(struct notifier_block *b,
-			      unsigned long action, void *hcpu)
-{
-	int rc = 0;
-	if ((action & ~CPU_TASKS_FROZEN) == CPU_STARTING)
-		rc = run_all_insn_set_hw_mode((unsigned long)hcpu);
-
-	return notifier_from_errno(rc);
-}
-
-static struct notifier_block insn_cpu_hotplug_notifier = {
-	.notifier_call = insn_cpu_hotplug_notify,
-};
-
 /*
  * Invoked as late_initcall, since not needed before init spawned.
  */
@@ -649,7 +635,9 @@ static int __init armv8_deprecated_init(
 			pr_info("setend instruction emulation is not supported on the system");
 	}
 
-	register_cpu_notifier(&insn_cpu_hotplug_notifier);
+	cpuhp_setup_state_nocalls(CPUHP_AP_ARM64_ISNDEP_STARTING,
+				  "AP_ARM64_ISNDEP_STARTING",
+				  run_all_insn_set_hw_mode, NULL);
 	register_insn_emulation_sysctl(ctl_abi);
 
 	return 0;
include/linux/cpuhotplug.h +1 -0
@@ -56,6 +56,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_XEN_STARTING,
 	CPUHP_AP_ARM_CORESIGHT_STARTING,
 	CPUHP_AP_ARM_CORESIGHT4_STARTING,
+	CPUHP_AP_ARM64_ISNDEP_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
author maintainer
#74 lore raw

PATCH 57/66 ARC/time: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Anna-Maria Gleixner <[email protected]>

Install the callbacks via the state machine.

---
 arch/arc/kernel/time.c     |   32 ++++++++++++++------------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 15 insertions(+), 18 deletions(-)
arch/arc/kernel/time.c +14 -18
@@ -296,30 +296,23 @@ static irqreturn_t timer_irq_handler(int
 	return IRQ_HANDLED;
 }
 
-static int arc_timer_cpu_notify(struct notifier_block *self,
-				unsigned long action, void *hcpu)
+
+static int arc_timer_starting_cpu(unsigned int cpu)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 
 	evt->cpumask = cpumask_of(smp_processor_id());
 
-	switch (action & ~CPU_TASKS_FROZEN) {
-	case CPU_STARTING:
-		clockevents_config_and_register(evt, arc_timer_freq,
-						0, ULONG_MAX);
-		enable_percpu_irq(arc_timer_irq, 0);
-		break;
-	case CPU_DYING:
-		disable_percpu_irq(arc_timer_irq);
-		break;
-	}
-
-	return NOTIFY_OK;
+	clockevents_config_and_register(evt, arc_timer_freq, 0, ULONG_MAX);
+	enable_percpu_irq(arc_timer_irq, 0);
+	return 0;
 }
 
-static struct notifier_block arc_timer_cpu_nb = {
-	.notifier_call = arc_timer_cpu_notify,
-};
+static int arc_timer_dying_cpu(unsigned int cpu)
+{
+	disable_percpu_irq(arc_timer_irq);
+	return 0;
+}
 
 /*
  * clockevent setup for boot CPU
@@ -329,7 +322,10 @@ static void __init arc_clockevent_setup(
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
-	register_cpu_notifier(&arc_timer_cpu_nb);
+	cpuhp_setup_state_nocalls(CPUHP_AP_ARC_TIMER_STARTING,
+				  "AP_ARC_TIMER_STARTING",
+				  arc_timer_starting_cpu,
+				  arc_timer_dying_cpu);
 
 	arc_timer_irq = irq_of_parse_and_map(node, 0);
 	if (arc_timer_irq <= 0)
include/linux/cpuhotplug.h +1 -0
@@ -50,6 +50,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARMADA_TIMER_STARTING,
 	CPUHP_AP_MARCO_TIMER_STARTING,
 	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
+	CPUHP_AP_ARC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
 	CPUHP_AP_KVM_ARM_VGIC_STARTING,
 	CPUHP_AP_KVM_ARM_TIMER_STARTING,
author maintainer
#75 lore raw

PATCH 58/66 x86/tboot: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/kernel/tboot.c    |   25 ++++++++-----------------
 include/linux/cpuhotplug.h |    1 +
 2 files changed, 9 insertions(+), 17 deletions(-)
arch/x86/kernel/tboot.c +8 -17
@@ -323,25 +323,16 @@ static int tboot_wait_for_aps(int num_ap
 	return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps);
 }
 
-static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
-			      void *hcpu)
+static int tboot_dying_cpu(unsigned int cpu)
 {
-	switch (action) {
-	case CPU_DYING:
-		atomic_inc(&ap_wfs_count);
-		if (num_online_cpus() == 1)
-			if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
-				return NOTIFY_BAD;
-		break;
+	atomic_inc(&ap_wfs_count);
+	if (num_online_cpus() == 1) {
+		if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
+			return -EBUSY;
 	}
-	return NOTIFY_OK;
+	return 0;
 }
 
-static struct notifier_block tboot_cpu_notifier =
-{
-	.notifier_call = tboot_cpu_callback,
-};
-
 #ifdef CONFIG_DEBUG_FS
 
 #define TBOOT_LOG_UUID	{ 0x26, 0x25, 0x19, 0xc0, 0x30, 0x6b, 0xb4, 0x4d, \
@@ -417,8 +408,8 @@ static __init int tboot_late_init(void)
 	tboot_create_trampoline();
 
 	atomic_set(&ap_wfs_count, 0);
-	register_hotcpu_notifier(&tboot_cpu_notifier);
-
+	cpuhp_setup_state(CPUHP_AP_X86_TBOOT_DYING, "AP_X86_TBOOT_DYING", NULL,
+			  tboot_dying_cpu);
 #ifdef CONFIG_DEBUG_FS
 	debugfs_create_file("tboot_log", S_IRUSR,
 			arch_debugfs_dir, NULL, &tboot_log_fops);
include/linux/cpuhotplug.h +1 -0
@@ -59,6 +59,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_CORESIGHT4_STARTING,
 	CPUHP_AP_ARM64_ISNDEP_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
+	CPUHP_AP_X86_TBOOT_DYING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
author maintainer
#76 lore raw

PATCH 59/66 rcu: Convert rcutree to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion to the state machine. Though the question arises whether this needs really all these state transitions to work.

---
 include/linux/cpuhotplug.h |    3 +
 include/linux/rcutree.h    |   15 ++++++
 kernel/cpu.c               |   15 ++++++
 kernel/rcu/tree.c          |  105 ++++++++++++++++++++++-----------------------
 4 files changed, 85 insertions(+), 53 deletions(-)
include/linux/cpuhotplug.h +3 -0
@@ -15,12 +15,14 @@ enum cpuhp_state {
 	CPUHP_X86_HPET_DEAD,
 	CPUHP_X86_APB_DEAD,
 	CPUHP_WORKQUEUE_PREP,
+	CPUHP_RCUTREE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
 	CPUHP_AP_OFFLINE,
 	CPUHP_AP_SCHED_STARTING,
+	CPUHP_AP_RCUTREE_DYING,
 	CPUHP_AP_IRQ_GIC_STARTING,
 	CPUHP_AP_IRQ_GICV3_STARTING,
 	CPUHP_AP_IRQ_HIP04_STARTING,
@@ -78,6 +80,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
+	CPUHP_AP_RCUTREE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,
include/linux/rcutree.h +15 -0
@@ -111,4 +111,19 @@ bool rcu_is_watching(void);
 
 void rcu_all_qs(void);
 
+/* RCUtree hotplug events */
+#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
+int rcutree_prepare_cpu(unsigned int cpu);
+int rcutree_online_cpu(unsigned int cpu);
+int rcutree_offline_cpu(unsigned int cpu);
+int rcutree_dead_cpu(unsigned int cpu);
+int rcutree_dying_cpu(unsigned int cpu);
+#else
+#define rcutree_prepare_cpu	NULL
+#define rcutree_online_cpu	NULL
+#define rcutree_offline_cpu	NULL
+#define rcutree_dead_cpu	NULL
+#define rcutree_dying_cpu	NULL
+#endif
+
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +15 -0
@@ -23,6 +23,7 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
+#include <linux/rcutree.h>
 
 #include <trace/events/power.h>
 #define CREATE_TRACE_POINTS
@@ -1183,6 +1184,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = workqueue_prepare_cpu,
 		.teardown = NULL,
 	},
+	[CPUHP_RCUTREE_PREP] = {
+		.name = "RCU-tree prepare",
+		.startup = rcutree_prepare_cpu,
+		.teardown = rcutree_dead_cpu,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
@@ -1235,6 +1241,10 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup		= sched_cpu_starting,
 		.teardown		= sched_cpu_dying,
 	},
+	[CPUHP_AP_RCUTREE_DYING] = {
+		.startup = NULL,
+		.teardown = rcutree_dying_cpu,
+	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
 	 * disabled. Will be removed once the notifiers are converted to
@@ -1268,6 +1278,11 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup = workqueue_online_cpu,
 		.teardown = workqueue_offline_cpu,
 	},
+	[CPUHP_AP_RCUTREE_ONLINE] = {
+		.name = "RCU-tree online",
+		.startup = rcutree_online_cpu,
+		.teardown = rcutree_offline_cpu,
+	},
 
 	/*
 	 * Online/down_prepare notifiers. Will be removed once the notifiers
kernel/rcu/tree.c +52 -53

137 lines not on this page · raw message

#77 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

Quoted 9 lines · Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion to the state machine. Though the question arises whether this needs really all these state transitions to work.

I believe that this patch breaks !SMP builds, as it has the side effect of pulling a Tree RCU include file into Tiny RCU builds.

Some questions below, and a related patch at the end. The related patch provides exact detection of CPUs coming online, and passes light rcutorture testing.

Thanx, Paul

Quoted 25 lines
---
 include/linux/cpuhotplug.h |    3 +
 include/linux/rcutree.h    |   15 ++++++
 kernel/cpu.c               |   15 ++++++
 kernel/rcu/tree.c          |  105 ++++++++++++++++++++++-----------------------
 4 files changed, 85 insertions(+), 53 deletions(-)
include/linux/cpuhotplug.h +2 -0
@@ -15,12 +15,14 @@ enum cpuhp_state {
 	CPUHP_X86_HPET_DEAD,
 	CPUHP_X86_APB_DEAD,
 	CPUHP_WORKQUEUE_PREP,
+	CPUHP_RCUTREE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
 	CPUHP_AP_OFFLINE,
 	CPUHP_AP_SCHED_STARTING,
+	CPUHP_AP_RCUTREE_DYING,
 	CPUHP_AP_IRQ_GIC_STARTING,
 	CPUHP_AP_IRQ_GICV3_STARTING,
 	CPUHP_AP_IRQ_HIP04_STARTING,

include/linux/cpuhotplug.h enum cpuhp_state { · line 86

Quoted 7 lines
include/linux/cpuhotplug.h +1 -0
@@ -78,6 +80,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
+	CPUHP_AP_RCUTREE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
 	CPUHP_AP_ONLINE_DYN_END		= CPUHP_AP_ONLINE_DYN + 30,

The dying-idle state is still covered by direct function call, correct? (The call to rcu_report_dead() from cpuhp_report_idle_dead().)

Quoted 10 lines
include/linux/rcutree.h +4 -0
@@ -111,4 +111,19 @@ bool rcu_is_watching(void);
 
 void rcu_all_qs(void);
 
+/* RCUtree hotplug events */
+#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
+int rcutree_prepare_cpu(unsigned int cpu);
+int rcutree_online_cpu(unsigned int cpu);

include/linux/rcutree.h bool rcu_is_watching(void); · line 127

Quoted 10 lines
include/linux/rcutree.h +10 -0
+int rcutree_offline_cpu(unsigned int cpu);
+int rcutree_dead_cpu(unsigned int cpu);
+int rcutree_dying_cpu(unsigned int cpu);
+#else
+#define rcutree_prepare_cpu	NULL
+#define rcutree_online_cpu	NULL
+#define rcutree_offline_cpu	NULL
+#define rcutree_dead_cpu	NULL
+#define rcutree_dying_cpu	NULL
+#endif

This file is included only in CONFIG_TREE_RCU or CONFIG_PREEMPT_RCU builds, so you should not need this ifdef.

The only other option is CONFIG_TINY_RCU, for which CONFIG_HOTPLUG_CPU cannot possibly be set.

kernel/cpu.c line 26

Quoted 9 lines
include/linux/rcutree.h +1 -0
+
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +1 -0
@@ -23,6 +23,7 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
+#include <linux/rcutree.h>

Ah, I see... ;-)

I am going to guess that this code was never built for CONFIG_SMP=n... I would expect a few build errors.

I suggest moving the #ifdef from include/linux/rcutree.h to include/linux/cpu.h. That way, you avoid including code intended only for Tree RCU into Tiny RCU builds.

Quoted 170 lines
kernel/cpu.c +14 -0
 #include <trace/events/power.h>
 #define CREATE_TRACE_POINTS
@@ -1183,6 +1184,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = workqueue_prepare_cpu,
 		.teardown = NULL,
 	},
+	[CPUHP_RCUTREE_PREP] = {
+		.name = "RCU-tree prepare",
+		.startup = rcutree_prepare_cpu,
+		.teardown = rcutree_dead_cpu,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
@@ -1235,6 +1241,10 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup		= sched_cpu_starting,
 		.teardown		= sched_cpu_dying,
 	},
+	[CPUHP_AP_RCUTREE_DYING] = {
+		.startup = NULL,
+		.teardown = rcutree_dying_cpu,
+	},
 	/*
 	 * Low level startup/teardown notifiers. Run with interrupts
 	 * disabled. Will be removed once the notifiers are converted to
@@ -1268,6 +1278,11 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup = workqueue_online_cpu,
 		.teardown = workqueue_offline_cpu,
 	},
+	[CPUHP_AP_RCUTREE_ONLINE] = {
+		.name = "RCU-tree online",
+		.startup = rcutree_online_cpu,
+		.teardown = rcutree_offline_cpu,
+	},
 
 	/*
 	 * Online/down_prepare notifiers. Will be removed once the notifiers
kernel/rcu/tree.c +51 -51
@@ -1070,11 +1070,11 @@ EXPORT_SYMBOL_GPL(rcu_is_watching);
  * offline to continue to use RCU for one jiffy after marking itself
  * offline in the cpu_online_mask.  This leniency is necessary given the
  * non-atomic nature of the online and offline processing, for example,
- * the fact that a CPU enters the scheduler after completing the CPU_DYING
- * notifiers.
+ * the fact that a CPU enters the scheduler after completing the teardown
+ * of the CPU.
  *
- * This is also why RCU internally marks CPUs online during the
- * CPU_UP_PREPARE phase and offline during the CPU_DEAD phase.
+ * This is also why RCU internally marks CPUs online during in the
+ * preparation phase and offline after the CPU has been taken down.
  *
  * Disable checking if in an NMI handler because we cannot safely report
  * errors from NMI handlers anyway.
@@ -4340,12 +4340,58 @@ rcu_init_percpu_data(int cpu, struct rcu
 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 }
 
-static void rcu_prepare_cpu(int cpu)
+int rcutree_prepare_cpu(unsigned int cpu)
 {
 	struct rcu_state *rsp;
 
 	for_each_rcu_flavor(rsp)
 		rcu_init_percpu_data(cpu, rsp);
+
+	rcu_prepare_kthreads(cpu);
+	rcu_spawn_all_nocb_kthreads(cpu);
+
+	return 0;
+}
+
+static void rcutree_affinity_setting(unsigned int cpu, int outgoing)
+{
+	struct rcu_data *rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
+
+	rcu_boost_kthread_setaffinity(rdp->mynode, outgoing);
+}
+
+int rcutree_online_cpu(unsigned int cpu)
+{
+	sync_sched_exp_online_cleanup(cpu);
+	rcutree_affinity_setting(cpu, -1);
+	return 0;
+}
+
+int rcutree_offline_cpu(unsigned int cpu)
+{
+	rcutree_affinity_setting(cpu, cpu);
+	return 0;
+}
+
+
+int rcutree_dying_cpu(unsigned int cpu)
+{
+	struct rcu_state *rsp;
+
+	for_each_rcu_flavor(rsp)
+		rcu_cleanup_dying_cpu(rsp);
+	return 0;
+}
+
+int rcutree_dead_cpu(unsigned int cpu)
+{
+	struct rcu_state *rsp;
+
+	for_each_rcu_flavor(rsp) {
+		rcu_cleanup_dead_cpu(cpu, rsp);
+		do_nocb_deferred_wakeup(per_cpu_ptr(rsp->rda, cpu));
+	}
+	return 0;
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -4388,52 +4434,6 @@ void rcu_report_dead(unsigned int cpu)
 }
 #endif
 
-/*
- * Handle CPU online/offline notification events.
- */
-int rcu_cpu_notify(struct notifier_block *self,
-		   unsigned long action, void *hcpu)
-{
-	long cpu = (long)hcpu;
-	struct rcu_data *rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
-	struct rcu_node *rnp = rdp->mynode;
-	struct rcu_state *rsp;
-
-	switch (action) {
-	case CPU_UP_PREPARE:
-	case CPU_UP_PREPARE_FROZEN:
-		rcu_prepare_cpu(cpu);
-		rcu_prepare_kthreads(cpu);
-		rcu_spawn_all_nocb_kthreads(cpu);
-		break;
-	case CPU_ONLINE:
-	case CPU_DOWN_FAILED:
-		sync_sched_exp_online_cleanup(cpu);
-		rcu_boost_kthread_setaffinity(rnp, -1);
-		break;
-	case CPU_DOWN_PREPARE:
-		rcu_boost_kthread_setaffinity(rnp, cpu);
-		break;
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		for_each_rcu_flavor(rsp)
-			rcu_cleanup_dying_cpu(rsp);
-		break;
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-		for_each_rcu_flavor(rsp) {
-			rcu_cleanup_dead_cpu(cpu, rsp);
-			do_nocb_deferred_wakeup(per_cpu_ptr(rsp->rda, cpu));
-		}
-		break;
-	default:
-		break;
-	}
-	return NOTIFY_OK;
-}
-
 static int rcu_pm_notify(struct notifier_block *self,
 			 unsigned long action, void *hcpu)
 {
@@ -4745,10 +4745,9 @@ void __init rcu_init(void)
 	 * this is called early in boot, before either interrupts

kernel/rcu/tree.c void __init rcu_init(void) · line 4753

Quoted 10 lines
kernel/rcu/tree.c +1 -2
 	 * or the scheduler are operational.
 	 */
-	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
 	for_each_online_cpu(cpu)
-		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcutree_prepare_cpu(cpu);
 }
 
 #include "tree_plugin.h"

------------------------------------------------------------------------

commit da7095f39456dd0f28fa21697f2f976a61bc6d0a

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jun 30 13:58:26 2016 -0700

rcu: Exact CPU-online tracking for RCU

Up to now, RCU has assumed that the CPU-online process makes it from CPU_UP_PREPARE to set_cpu_online() within one jiffy. Given the recent rise of virtualized environments, this assumption is very clearly obsolete.

This commit therefore updates RCU's internal CPU state-tracking information at notify_cpu_starting() time, thus providing exact tracking of the CPU state from an RCU perspective.

Note that this means that incoming CPUs must not use RCU read-side critical section (other than those of SRCU) until notify_cpu_starting() time. Note that the CPU_STARTING notifiers -are- allowed to use RCU read-side critical sections.

If a given architecture or CPU family needs to use RCU read-side critical sections earlier, the call to rcu_cpu_starting() from notify_cpu_starting() will need to be architecture-specific, with architectures that opt out being required to hand-place the call to rcu_cpu_starting() at some point preceding the call to notify_cpu_starting().

include/linux/rcupdate.h +1 -0
index 3bc5de08c0b7..0f2d86d1ca6e 100644
@@ -334,6 +334,7 @@ void rcu_sched_qs(void);
 void rcu_bh_qs(void);
 void rcu_check_callbacks(int user);
 void rcu_report_dead(unsigned int cpu);
+void rcu_cpu_starting(unsigned int cpu);
 
 #ifndef CONFIG_TINY_RCU
 void rcu_end_inkernel_boot(void);
kernel/cpu.c +1 -0
index d948e44c471e..703453233530 100644
@@ -882,6 +882,7 @@ void notify_cpu_starting(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
 
+	rcu_cpu_starting(cpu);  /* All CPU_STARTING notifiers can use RCU. */
 	while (st->state < target) {
 		struct cpuhp_step *step;
 
kernel/rcu/tree.c +29 -3
index 3121242b8579..5e7c1d6a6108 100644
@@ -3793,8 +3793,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
 	rnp = rdp->mynode;
 	mask = rdp->grpmask;
 	raw_spin_lock_rcu_node(rnp);		/* irqs already disabled. */
-	rnp->qsmaskinitnext |= mask;
-	rnp->expmaskinitnext |= mask;
 	if (!rdp->beenonline)
 		WRITE_ONCE(rsp->ncpus, READ_ONCE(rsp->ncpus) + 1);
 	rdp->beenonline = true;	 /* We have now been online. */
@@ -3815,6 +3813,32 @@ static void rcu_prepare_cpu(int cpu)
 		rcu_init_percpu_data(cpu, rsp);
 }
 
+/*
+ * Mark the specified CPU as being online so that subsequent grace periods
+ * (both expedited and normal) will wait on it.  Note that this means that
+ * incoming CPUs are not allowed to use RCU read-side critical sections
+ * until this function is called.  Failing to observe this restriction
+ * will result in lockdep splats.
+ */
+void rcu_cpu_starting(unsigned int cpu)
+{
+	unsigned long flags;
+	unsigned long mask;
+	struct rcu_data *rdp;
+	struct rcu_node *rnp;
+	struct rcu_state *rsp;
+
+	for_each_rcu_flavor(rsp) {
+		rdp = this_cpu_ptr(rsp->rda);
+		rnp = rdp->mynode;
+		mask = rdp->grpmask;
+		raw_spin_lock_irqsave_rcu_node(rnp, flags);
+		rnp->qsmaskinitnext |= mask;
+		rnp->expmaskinitnext |= mask;
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+	}
+}
+
 #ifdef CONFIG_HOTPLUG_CPU
 /*
  * The CPU is exiting the idle loop into the arch_cpu_idle_dead()
@@ -4211,8 +4235,10 @@ void __init rcu_init(void)
 	 */
 	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu)
+	for_each_online_cpu(cpu) {
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcu_cpu_starting(cpu);
+	}
 }
 
 #include "tree_exp.h"
author maintainer
#78 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

(edit cc: add tglx)

Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion to the state machine. Though the question arises whether this needs really all these state transitions to work.

Quoted 6 lines

I believe that this patch breaks !SMP builds, as it has the side effect of pulling a Tree RCU include file into Tiny RCU builds.

Some questions below, and a related patch at the end. The related patch provides exact detection of CPUs coming online, and passes light rcutorture testing.

We will take it into account before this change.

Quoted 2 lines

The dying-idle state is still covered by direct function call, correct? (The call to rcu_report_dead() from cpuhp_report_idle_dead().)

Yes.

Quoted 39 lines
Quoted 10 lines
include/linux/rcutree.h +4 -0
@@ -111,4 +111,19 @@ bool rcu_is_watching(void);
 
 void rcu_all_qs(void);
 
+/* RCUtree hotplug events */
+#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
+int rcutree_prepare_cpu(unsigned int cpu);
+int rcutree_online_cpu(unsigned int cpu);

include/linux/rcutree.h bool rcu_is_watching(void); · line 127

Quoted 10 lines
include/linux/rcutree.h +10 -0
+int rcutree_offline_cpu(unsigned int cpu);
+int rcutree_dead_cpu(unsigned int cpu);
+int rcutree_dying_cpu(unsigned int cpu);
+#else
+#define rcutree_prepare_cpu	NULL
+#define rcutree_online_cpu	NULL
+#define rcutree_offline_cpu	NULL
+#define rcutree_dead_cpu	NULL
+#define rcutree_dying_cpu	NULL
+#endif

This file is included only in CONFIG_TREE_RCU or CONFIG_PREEMPT_RCU builds, so you should not need this ifdef.

The only other option is CONFIG_TINY_RCU, for which CONFIG_HOTPLUG_CPU cannot possibly be set.

kernel/cpu.c line 26

Quoted 9 lines
include/linux/rcutree.h +1 -0
+
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +1 -0
@@ -23,6 +23,7 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
+#include <linux/rcutree.h>

Ah, I see... ;-)

Quoted 7 lines

I am going to guess that this code was never built for CONFIG_SMP=n... I would expect a few build errors.

I suggest moving the #ifdef from include/linux/rcutree.h to include/linux/cpu.h. That way, you avoid including code intended only for Tree RCU into Tiny RCU builds.

Is it ok, to leave the defines without ifdef in include/linux/rcutree.h and remove the include rcutree.h in kernel/cpu.c ? Because only if CONFIG_TREE_RCU or CONFIG_PREEMPT_RCU is defined, rcupdate.h includes rcutree.h . See delta patch below.

8<----------------

include/linux/rcutree.h +0 -8
@@ -112,18 +112,10 @@ bool rcu_is_watching(void);
 void rcu_all_qs(void);
 
 /* RCUtree hotplug events */
-#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
 int rcutree_prepare_cpu(unsigned int cpu);
 int rcutree_online_cpu(unsigned int cpu);
 int rcutree_offline_cpu(unsigned int cpu);
 int rcutree_dead_cpu(unsigned int cpu);
 int rcutree_dying_cpu(unsigned int cpu);
-#else
-#define rcutree_prepare_cpu	NULL
-#define rcutree_online_cpu	NULL
-#define rcutree_offline_cpu	NULL
-#define rcutree_dead_cpu	NULL
-#define rcutree_dying_cpu	NULL
-#endif
 
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +0 -1
@@ -23,7 +23,6 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
-#include <linux/rcutree.h>
 
 #include <trace/events/power.h>
 #define CREATE_TRACE_POINTS
#79 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

Quoted 15 lines · Anna-Maria Gleixner

(edit cc: add tglx)

Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Straight forward conversion to the state machine. Though the question arises whether this needs really all these state transitions to work.

Quoted 8 lines
Quoted 6 lines

I believe that this patch breaks !SMP builds, as it has the side effect of pulling a Tree RCU include file into Tiny RCU builds.

Some questions below, and a related patch at the end. The related patch provides exact detection of CPUs coming online, and passes light rcutorture testing.

We will take it into account before this change.

Very good, thank you!

My current plan is to submit this patch to the v4.9 merge window, that is, not the one in a few weeks, but the one after that. Please let me know if you need me to take a different approach.

Quoted 4 lines
Quoted 2 lines

The dying-idle state is still covered by direct function call, correct? (The call to rcu_report_dead() from cpuhp_report_idle_dead().)

Yes.

Whew! ;-)

Quoted 47 lines
Quoted 39 lines
Quoted 10 lines
include/linux/rcutree.h +4 -0
@@ -111,4 +111,19 @@ bool rcu_is_watching(void);
 
 void rcu_all_qs(void);
 
+/* RCUtree hotplug events */
+#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
+int rcutree_prepare_cpu(unsigned int cpu);
+int rcutree_online_cpu(unsigned int cpu);

include/linux/rcutree.h bool rcu_is_watching(void); · line 127

Quoted 10 lines
include/linux/rcutree.h +10 -0
+int rcutree_offline_cpu(unsigned int cpu);
+int rcutree_dead_cpu(unsigned int cpu);
+int rcutree_dying_cpu(unsigned int cpu);
+#else
+#define rcutree_prepare_cpu	NULL
+#define rcutree_online_cpu	NULL
+#define rcutree_offline_cpu	NULL
+#define rcutree_dead_cpu	NULL
+#define rcutree_dying_cpu	NULL
+#endif

This file is included only in CONFIG_TREE_RCU or CONFIG_PREEMPT_RCU builds, so you should not need this ifdef.

The only other option is CONFIG_TINY_RCU, for which CONFIG_HOTPLUG_CPU cannot possibly be set.

kernel/cpu.c line 26

Quoted 9 lines
include/linux/rcutree.h +1 -0
+
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +1 -0
@@ -23,6 +23,7 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
+#include <linux/rcutree.h>

Ah, I see... ;-)

Quoted 7 lines

I am going to guess that this code was never built for CONFIG_SMP=n... I would expect a few build errors.

I suggest moving the #ifdef from include/linux/rcutree.h to include/linux/cpu.h. That way, you avoid including code intended only for Tree RCU into Tiny RCU builds.

Quoted 4 lines

Is it ok, to leave the defines without ifdef in include/linux/rcutree.h and remove the include rcutree.h in kernel/cpu.c ? Because only if CONFIG_TREE_RCU or CONFIG_PREEMPT_RCU is defined, rcupdate.h includes rcutree.h . See delta patch below.

Yes, that would be much better!

Also, you need to put the other leg of the #ifdef (the #defines with all the NULLs) into include/linux/rcutiny. That way, kernel/cpu.c will get the correct set of #defines automatically, given that include/linux/rcupdate.h #includes one or the other of rcutree.h and rcutiny.h.

Thanx, Paul

Quoted 34 lines

8<----------------

include/linux/rcutree.h +0 -8
@@ -112,18 +112,10 @@ bool rcu_is_watching(void);
 void rcu_all_qs(void);
 
 /* RCUtree hotplug events */
-#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
 int rcutree_prepare_cpu(unsigned int cpu);
 int rcutree_online_cpu(unsigned int cpu);
 int rcutree_offline_cpu(unsigned int cpu);
 int rcutree_dead_cpu(unsigned int cpu);
 int rcutree_dying_cpu(unsigned int cpu);
-#else
-#define rcutree_prepare_cpu	NULL
-#define rcutree_online_cpu	NULL
-#define rcutree_offline_cpu	NULL
-#define rcutree_dead_cpu	NULL
-#define rcutree_dying_cpu	NULL
-#endif
 
 #endif /* __LINUX_RCUTREE_H */
kernel/cpu.c +0 -1
@@ -23,7 +23,6 @@
 #include <linux/tick.h>
 #include <linux/irq.h>
 #include <linux/smpboot.h>
-#include <linux/rcutree.h>
 
 #include <trace/events/power.h>
 #define CREATE_TRACE_POINTS
#80 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

In reply to Paul E. McKenney
Quoted 5 lines · Paul E. McKenney

commit da7095f39456dd0f28fa21697f2f976a61bc6d0a

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jun 30 13:58:26 2016 -0700

rcu: Exact CPU-online tracking for RCU

…

I don't pretend that I know what I going on here. I have just one simple question :)

kernel/cpu.c void notify_cpu_starting(unsigned int cpu) · line 887

Quoted 12 lines
kernel/cpu.c +1 -0
@@ -882,6 +882,7 @@ void notify_cpu_starting(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
 
+	rcu_cpu_starting(cpu);  /* All CPU_STARTING notifiers can use RCU. */
 	while (st->state < target) {
 		struct cpuhp_step *step;

What happens if something post CPUHP_AP_ONLINE fails and we do a rollback to 0? Do we need to revert / undo rcu_cpu_starting() doing?

Quoted 14 lines
kernel/rcu/tree.c +0 -2
index 3121242b8579..5e7c1d6a6108 100644
@@ -3793,8 +3793,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
 	rnp = rdp->mynode;
 	mask = rdp->grpmask;
 	raw_spin_lock_rcu_node(rnp);		/* irqs already disabled. */
-	rnp->qsmaskinitnext |= mask;
-	rnp->expmaskinitnext |= mask;
 	if (!rdp->beenonline)
 		WRITE_ONCE(rsp->ncpus, READ_ONCE(rsp->ncpus) + 1);
 	rdp->beenonline = true;	 /* We have now been online. */

kernel/rcu/tree.c void __init rcu_init(void) · line 4241

Quoted 8 lines
kernel/rcu/tree.c +3 -1
@@ -4211,8 +4235,10 @@ void __init rcu_init(void)
 	 */
 	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu)
+	for_each_online_cpu(cpu) {
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcu_cpu_starting(cpu);
+	}

and looking at this from x86-64 then at this point I have CPU0 online and all other are down (or not yet up). So this is invoked for one CPU only. And later via hotplug callbacks for the other CPUs.

kernel/rcu/tree.c void __init rcu_init(void) · line 4244

Quoted 3 lines
kernel/rcu/tree.c +0 -0
 }
 
 #include "tree_exp.h"

Sebastian

#81 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

Quoted 10 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Paul E. McKenney

commit da7095f39456dd0f28fa21697f2f976a61bc6d0a

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jun 30 13:58:26 2016 -0700

rcu: Exact CPU-online tracking for RCU

…

I don't pretend that I know what I going on here. I have just one simple question :)

That is what they all say! ;-)

Quoted 8 lines
Quoted 8 lines
kernel/cpu.c +0 -0
@@ -882,6 +882,7 @@ void notify_cpu_starting(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
 
Quoted 6 lines

kernel/cpu.c void notify_cpu_starting(unsigned int cpu) · line 887

Quoted 3 lines
kernel/cpu.c +1 -0
+	rcu_cpu_starting(cpu);  /* All CPU_STARTING notifiers can use RCU. */
 	while (st->state < target) {
 		struct cpuhp_step *step;

What happens if something post CPUHP_AP_ONLINE fails and we do a rollback to 0? Do we need to revert / undo rcu_cpu_starting() doing?

Yes, by calling rcu_cleanup_dying_idle_cpu().

But please note that rcu_cpu_starting() is invoked from the CPU itself during the onlining process. Is it really possible to fail beyond that point?

Quoted 18 lines
Quoted 18 lines
kernel/rcu/tree.c +0 -3
index 3121242b8579..5e7c1d6a6108 100644
@@ -3793,8 +3793,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
 	rnp = rdp->mynode;
 	mask = rdp->grpmask;
 	raw_spin_lock_rcu_node(rnp);		/* irqs already disabled. */
-	rnp->qsmaskinitnext |= mask;
-	rnp->expmaskinitnext |= mask;
 	if (!rdp->beenonline)
 		WRITE_ONCE(rsp->ncpus, READ_ONCE(rsp->ncpus) + 1);
 	rdp->beenonline = true;	 /* We have now been online. */
@@ -4211,8 +4235,10 @@ void __init rcu_init(void)
 	 */
 	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu)
Quoted 8 lines

kernel/rcu/tree.c void __init rcu_init(void) · line 4241

Quoted 4 lines
kernel/rcu/tree.c +3 -0
+	for_each_online_cpu(cpu) {
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcu_cpu_starting(cpu);
+	}

and looking at this from x86-64 then at this point I have CPU0 online and all other are down (or not yet up). So this is invoked for one CPU only. And later via hotplug callbacks for the other CPUs.

Yes, that is the current situation. The reason for the loop is in case someone clever decides to online other CPUs before RCU initializes itself. No idea how anyone would make that sort of thing work, but I have learned not to underestimate the creativity of the fast-boot guys.

And please do not invoke rcu_cpu_starting() before rcu_init(), at least not without some careful inspection and likely reworking of rcu_init() and the things that it calls.

Thanx, Paul

Quoted 6 lines

kernel/rcu/tree.c void __init rcu_init(void) · line 4244

Quoted 3 lines
kernel/rcu/tree.c +0 -0
 }
 
 #include "tree_exp.h"

Sebastian

#82 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

Quoted 6 lines · Paul E. McKenney
Quoted 6 lines
Quoted 6 lines
kernel/cpu.c +0 -0
@@ -882,6 +882,7 @@ void notify_cpu_starting(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
 
Quoted 8 lines
Quoted 6 lines

kernel/cpu.c void notify_cpu_starting(unsigned int cpu) · line 887

Quoted 3 lines
kernel/cpu.c +1 -0
+	rcu_cpu_starting(cpu);  /* All CPU_STARTING notifiers can use RCU. */
 	while (st->state < target) {
 		struct cpuhp_step *step;

What happens if something post CPUHP_AP_ONLINE fails and we do a rollback to 0? Do we need to revert / undo rcu_cpu_starting() doing?

Yes, by calling rcu_cleanup_dying_idle_cpu().

Thank you for that :)

Quoted 3 lines

But please note that rcu_cpu_starting() is invoked from the CPU itself during the onlining process. Is it really possible to fail beyond that point?

"sure". We enter here at CPUHP_BRINGUP_CPU. The next states until (approx) CPUHP_AP_ONLINE are currently defined as "can't fail". As you see in notify_cpu_starting() the return code of cpuhp_invoke_callback() isn't checked and there is no rollback.
Later, CPUHP_AP_SMPBOOT_THREADS could fail (not in current but from here on we no longer the return code). At this point we would return to where we started (CPUHP_OFFLINE is most cases). During the rollback we get to rcu_cleanup_dying_idle_cpu() via rcu_report_dead() so that is fine.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
kernel/rcu/tree.c +0 -3
index 3121242b8579..5e7c1d6a6108 100644
@@ -3793,8 +3793,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
 	rnp = rdp->mynode;
 	mask = rdp->grpmask;
 	raw_spin_lock_rcu_node(rnp);		/* irqs already disabled. */
-	rnp->qsmaskinitnext |= mask;
-	rnp->expmaskinitnext |= mask;
 	if (!rdp->beenonline)
 		WRITE_ONCE(rsp->ncpus, READ_ONCE(rsp->ncpus) + 1);
 	rdp->beenonline = true;	 /* We have now been online. */
@@ -4211,8 +4235,10 @@ void __init rcu_init(void)
 	 */
 	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu)
Quoted 8 lines

kernel/rcu/tree.c void __init rcu_init(void) · line 4241

Quoted 4 lines
kernel/rcu/tree.c +3 -0
+	for_each_online_cpu(cpu) {
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcu_cpu_starting(cpu);
+	}

and looking at this from x86-64 then at this point I have CPU0 online and all other are down (or not yet up). So this is invoked for one CPU only. And later via hotplug callbacks for the other CPUs.

Quoted 4 lines

Yes, that is the current situation. The reason for the loop is in case someone clever decides to online other CPUs before RCU initializes itself. No idea how anyone would make that sort of thing work, but I have learned not to underestimate the creativity of the fast-boot guys.

doubt this would work. start_kernel() is invoked from the boot CPU. Other CPUs are usually down because the scheduler wasn't up yet (so they can't idle in their idle thread nor could they be marked "online" in the CPU mask). Later (rest_init() -> kernel_init() -> kernel_init_freeable()) there is smp_init() which boots the additional CPUs.

Quoted 3 lines

And please do not invoke rcu_cpu_starting() before rcu_init(), at least not without some careful inspection and likely reworking of rcu_init() and the things that it calls.

I did not intend to. I was thinking about moving it to CPUHP_AP_RCUTREE_DYING but since the teardown method does not match it makes no sense.
Thank you for clarifying the counterpart of rcu_cpu_starting().

Quoted 1 line

Thanx, Paul

Sebastian

#83 lore raw

Re: [patch 59/66] rcu: Convert rcutree to hotplug state machine

Quoted 14 lines · Sebastian Andrzej Siewior
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines

kernel/cpu.c void notify_cpu_starting(unsigned int cpu) · line 887

Quoted 9 lines
kernel/cpu.c +1 -0
@@ -882,6 +882,7 @@ void notify_cpu_starting(unsigned int cpu)
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
 	enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
 
+	rcu_cpu_starting(cpu);  /* All CPU_STARTING notifiers can use RCU. */
 	while (st->state < target) {
 		struct cpuhp_step *step;

What happens if something post CPUHP_AP_ONLINE fails and we do a rollback to 0? Do we need to revert / undo rcu_cpu_starting() doing?

Quoted 3 lines
Quoted 1 line

Yes, by calling rcu_cleanup_dying_idle_cpu().

Thank you for that :)

No problem! ;-)

Quoted 4 lines
Quoted 3 lines

But please note that rcu_cpu_starting() is invoked from the CPU itself during the onlining process. Is it really possible to fail beyond that point?

Quoted 8 lines

"sure". We enter here at CPUHP_BRINGUP_CPU. The next states until (approx) CPUHP_AP_ONLINE are currently defined as "can't fail". As you see in notify_cpu_starting() the return code of cpuhp_invoke_callback() isn't checked and there is no rollback.
Later, CPUHP_AP_SMPBOOT_THREADS could fail (not in current but from here on we no longer the return code). At this point we would return to where we started (CPUHP_OFFLINE is most cases). During the rollback we get to rcu_cleanup_dying_idle_cpu() via rcu_report_dead() so that is fine.

OK, so any later failure looks to RCU like the CPU came online, then immediately went offline. Works for me!

Quoted 32 lines
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
kernel/rcu/tree.c +0 -3
index 3121242b8579..5e7c1d6a6108 100644
@@ -3793,8 +3793,6 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
 	rnp = rdp->mynode;
 	mask = rdp->grpmask;
 	raw_spin_lock_rcu_node(rnp);		/* irqs already disabled. */
-	rnp->qsmaskinitnext |= mask;
-	rnp->expmaskinitnext |= mask;
 	if (!rdp->beenonline)
 		WRITE_ONCE(rsp->ncpus, READ_ONCE(rsp->ncpus) + 1);
 	rdp->beenonline = true;	 /* We have now been online. */
@@ -4211,8 +4235,10 @@ void __init rcu_init(void)
 	 */
 	cpu_notifier(rcu_cpu_notify, 0);
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu)
Quoted 8 lines

kernel/rcu/tree.c void __init rcu_init(void) · line 4241

Quoted 4 lines
kernel/rcu/tree.c +3 -0
+	for_each_online_cpu(cpu) {
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+		rcu_cpu_starting(cpu);
+	}

and looking at this from x86-64 then at this point I have CPU0 online and all other are down (or not yet up). So this is invoked for one CPU only. And later via hotplug callbacks for the other CPUs.

Quoted 4 lines

Yes, that is the current situation. The reason for the loop is in case someone clever decides to online other CPUs before RCU initializes itself. No idea how anyone would make that sort of thing work, but I have learned not to underestimate the creativity of the fast-boot guys.

Quoted 6 lines

doubt this would work. start_kernel() is invoked from the boot CPU. Other CPUs are usually down because the scheduler wasn't up yet (so they can't idle in their idle thread nor could they be marked "online" in the CPU mask). Later (rest_init() -> kernel_init() -> kernel_init_freeable()) there is smp_init() which boots the additional CPUs.

Just as there is currently an early boot implementation of printk(), some crazy person might well create an early boot implementation of the scheduler that had fixed per-CPU tasks for which blocking is forbidden. I understand that this is crazy, but much else has been considered crazy not long before inclusion. PREEMPT_RT, for but one example. ;-)

Quoted 7 lines
Quoted 3 lines

And please do not invoke rcu_cpu_starting() before rcu_init(), at least not without some careful inspection and likely reworking of rcu_init() and the things that it calls.

I did not intend to. I was thinking about moving it to CPUHP_AP_RCUTREE_DYING but since the teardown method does not match it makes no sense.

Whew!!! ;-)

Quoted 1 line

Thank you for clarifying the counterpart of rcu_cpu_starting().

Again, no problem!

Thanx, Paul

author maintainer
#84 lore raw

PATCH 60/66 hrtimer: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Thomas Gleixner <[email protected]>

Split out the clockevents callbacks instead of piggy packing them on hrtimers.

This gets rid of a POST_DEAD user. See commit 54e88fad. We just move the callback state to the proper place in the state machine.

---
 include/linux/cpuhotplug.h |    1 +
 include/linux/hrtimer.h    |    7 +++++++
 kernel/cpu.c               |    5 +++++
 kernel/time/hrtimer.c      |   40 +++++-----------------------------------
 4 files changed, 18 insertions(+), 35 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -17,6 +17,7 @@ enum cpuhp_state {
 	CPUHP_WORKQUEUE_PREP,
 	CPUHP_RCUTREE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
+	CPUHP_HRTIMERS_PREPARE,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
include/linux/hrtimer.h +7 -0
@@ -494,4 +494,11 @@ extern void __init hrtimers_init(void);
 /* Show pending timers: */
 extern void sysrq_timer_list_show(void);
 
+int hrtimers_prepare_cpu(unsigned int cpu);
+#ifdef CONFIG_HOTPLUG_CPU
+int hrtimers_dead_cpu(unsigned int cpu);
+#else
+#define hrtimers_dead_cpu	NULL
+#endif
+
 #endif
kernel/cpu.c +5 -0
@@ -1189,6 +1189,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = rcutree_prepare_cpu,
 		.teardown = rcutree_dead_cpu,
 	},
+	[CPUHP_HRTIMERS_PREPARE] = {
+		.name = "hrtimers prepare",
+		.startup = hrtimers_prepare_cpu,
+		.teardown = hrtimers_dead_cpu,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
kernel/time/hrtimer.c +5 -35
@@ -1590,7 +1590,7 @@ SYSCALL_DEFINE2(nanosleep, struct timesp
 /*
  * Functions related to boot-time initialization:
  */
-static void init_hrtimers_cpu(int cpu)
+int hrtimers_prepare_cpu(unsigned int cpu)
 {
 	struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
 	int i;
@@ -1602,6 +1602,7 @@ static void init_hrtimers_cpu(int cpu)
 
 	cpu_base->cpu = cpu;
 	hrtimer_init_hres(cpu_base);
+	return 0;
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -1636,7 +1637,7 @@ static void migrate_hrtimer_list(struct
 	}
 }
 
-static void migrate_hrtimers(int scpu)
+int hrtimers_dead_cpu(unsigned int scpu)
 {
 	struct hrtimer_cpu_base *old_base, *new_base;
 	int i;
@@ -1665,45 +1666,14 @@ static void migrate_hrtimers(int scpu)
 	/* Check, if we got expired work to do */
 	__hrtimer_peek_ahead_timers();
 	local_irq_enable();
+	return 0;
 }
 
 #endif /* CONFIG_HOTPLUG_CPU */
 
-static int hrtimer_cpu_notify(struct notifier_block *self,
-					unsigned long action, void *hcpu)
-{
-	int scpu = (long)hcpu;
-
-	switch (action) {
-
-	case CPU_UP_PREPARE:
-	case CPU_UP_PREPARE_FROZEN:
-		init_hrtimers_cpu(scpu);
-		break;
-
-#ifdef CONFIG_HOTPLUG_CPU
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		migrate_hrtimers(scpu);
-		break;
-#endif
-
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static struct notifier_block hrtimers_nb = {
-	.notifier_call = hrtimer_cpu_notify,
-};
-
 void __init hrtimers_init(void)
 {
-	hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
-			  (void *)(long)smp_processor_id());
-	register_cpu_notifier(&hrtimers_nb);
+	hrtimers_prepare_cpu(smp_processor_id());
 }
 
 /**
author maintainer
#85 lore raw

PATCH 61/66 timers: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

When tearing down, call timers_dead_cpu before notify_dead. There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

---
 include/linux/cpuhotplug.h |    1 +
 include/linux/timer.h      |    6 ++++++
 kernel/cpu.c               |    5 +++++
 kernel/time/timer.c        |   25 ++-----------------------
 4 files changed, 14 insertions(+), 23 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -18,6 +18,7 @@ enum cpuhp_state {
 	CPUHP_RCUTREE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_HRTIMERS_PREPARE,
+	CPUHP_TIMERS_DEAD,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
include/linux/timer.h +6 -0
@@ -259,4 +259,10 @@ unsigned long __round_jiffies_up_relativ
 unsigned long round_jiffies_up(unsigned long j);
 unsigned long round_jiffies_up_relative(unsigned long j);
 
+#ifdef CONFIG_HOTPLUG_CPU
+int timers_dead_cpu(unsigned int cpu);
+#else
+#define timers_dead_cpu NULL
+#endif
+
 #endif
kernel/cpu.c +5 -0
@@ -1194,6 +1194,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = hrtimers_prepare_cpu,
 		.teardown = hrtimers_dead_cpu,
 	},
+	[CPUHP_TIMERS_DEAD] = {
+		.name = "timers dead",
+		.startup = NULL,
+		.teardown = timers_dead_cpu,
+	},
 	/*
 	 * Preparatory and dead notifiers. Will be replaced once the notifiers
 	 * are converted to states.
kernel/time/timer.c +2 -23
@@ -1577,7 +1577,7 @@ static void migrate_timer_list(struct tv
 	}
 }
 
-static void migrate_timers(int cpu)
+int timers_dead_cpu(unsigned int cpu)
 {
 	struct tvec_base *old_base;
 	struct tvec_base *new_base;
@@ -1610,29 +1610,9 @@ static void migrate_timers(int cpu)
 	spin_unlock(&old_base->lock);
 	spin_unlock_irq(&new_base->lock);
 	put_cpu_ptr(&tvec_bases);
+	return 0;
 }
 
-static int timer_cpu_notify(struct notifier_block *self,
-				unsigned long action, void *hcpu)
-{
-	switch (action) {
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		migrate_timers((long)hcpu);
-		break;
-	default:
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static inline void timer_register_cpu_notifier(void)
-{
-	cpu_notifier(timer_cpu_notify, 0);
-}
-#else
-static inline void timer_register_cpu_notifier(void) { }
 #endif /* CONFIG_HOTPLUG_CPU */
 
 static void __init init_timer_cpu(int cpu)
@@ -1658,7 +1638,6 @@ void __init init_timers(void)
 {
 	init_timer_cpus();
 	init_timer_stats();
-	timer_register_cpu_notifier();
 	open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
 }
 
maintainer
#86 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Hi Richard,

Quoted 11 lines · Anna-Maria Gleixner

From: Richard Cochran <[email protected]>

When tearing down, call timers_dead_cpu before notify_dead. There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

After this change is applied I am seeing RCU stalls during suspend on Tegra. I guess I am hitting the case mentioned above? How should this be avoided?

[    5.321824] PM: Syncing filesystems ... done.
[    5.349746] Freezing user space processes ... (elapsed 0.001 seconds) done.
[    5.358122] Double checking all user space processes after OOM killer disable... (elapsed 0.000 seconds) 
[    5.367817] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[    5.376746] Suspending console(s) (use no_console_suspend to debug)
[    5.427213] PM: suspend of devices complete after 42.812 msecs
[    5.429909] PM: late suspend of devices complete after 2.680 msecs
[    5.431968] PM: noirq suspend of devices complete after 2.049 msecs
[    5.431973] Disabling non-boot CPUs ...
[    5.432861] CPU1: shutdown
[    5.467806] CPU2: shutdown
[    5.506925] IRQ17 no longer affine to CPU3
[    5.507294] CPU3: shutdown
[   26.509992] INFO: rcu_sched detected stalls on CPUs/tasks:
[   26.510005]  3-O.N: (0 ticks this GP) idle=e13/140000000000000/0 softirq=86/86 fqs=0 
[   26.510016]  (detected by 0, t=4202 jiffies, g=-225, c=-226, q=23)
[   26.510020] Task dump for CPU 3:
[   26.510033] swapper/3       R running      0     0      1 0x00000000
[   26.510063] [<c0b79fac>] (__schedule) from [<c033b808>] (tegra_cpu_die+0x30/0x48)
[   26.510080] [<c033b808>] (tegra_cpu_die) from [<c030dd4c>] (arch_cpu_idle_dead+0x44/0x88)
[   26.510094] [<c030dd4c>] (arch_cpu_idle_dead) from [<c03794bc>] (cpu_startup_entry+0x1c0/0x220)
[   26.510106] [<c03794bc>] (cpu_startup_entry) from [<80301c2c>] (0x80301c2c)
[   26.510116] rcu_sched kthread starved for 4202 jiffies! g4294967071 c4294967070 f0x0 RCU_GP_WAIT_FQS(3) ->state=0x1
[   26.510128] rcu_sched       S c0b79fac     0     7      2 0x00000000
[   26.510139] [<c0b79fac>] (__schedule) from [<c0b7a434>] (schedule+0x38/0x9c)
[   26.510152] [<c0b7a434>] (schedule) from [<c0b7cf3c>] (schedule_timeout+0x158/0x21c)
[   26.510166] [<c0b7cf3c>] (schedule_timeout) from [<c03922e0>] (rcu_gp_kthread+0x414/0x99c)
[   26.510179] [<c03922e0>] (rcu_gp_kthread) from [<c035cdb8>] (kthread+0xd8/0xf4)
[   26.510191] [<c035cdb8>] (kthread) from [<c0307fb8>] (ret_from_fork+0x14/0x3c)
[   26.531238] Enabling non-boot CPUs ...
[   26.546568] CPU1 is up
[   26.566858] CPU2 is up
[   26.587169] CPU3 is up
[   26.588470] PM: noirq resume of devices complete after 1.290 msecs
[   26.591329] PM: early resume of devices complete after 2.574 msecs
[   26.696785] PM: resume of devices complete after 105.439 msecs
[   26.876814] Restarting tasks ... done.

Interestingly I am only seeing the above when using the ARM multi_v7_defconfig kernel configuration and not with the tegra_defconfig. One key difference between these is that the multi_v7_defconfig does not have CONFIG_PREEMPT enabled. Initial testing shows enabling CONFIG_PREEMPT for multi_v7_defconfig makes the problem go away.

Cheers
Jon

#87 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Quoted 6 lines · Jon Hunter
Quoted 6 lines

There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

Quoted 6 lines
Quoted 2 lines

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

After this change is applied I am seeing RCU stalls during suspend on Tegra. I guess I am hitting the case mentioned above? How should this be avoided?

The problem that I had found was a hidden dependency. When I initially placed the timers callback into the new HP state list, that caused a stall because the dependency was broken. The old code worked by luck, based on the order of the notifier registrations. The new code makes the old implicit ordering explicit, so it should work just as well as before (famous last words).

Quoted 5 lines

Interestingly I am only seeing the above when using the ARM multi_v7_defconfig kernel configuration and not with the tegra_defconfig. One key difference between these is that the multi_v7_defconfig does not have CONFIG_PREEMPT enabled. Initial testing shows enabling CONFIG_PREEMPT for multi_v7_defconfig makes the problem go away.

Just to be sure, this problem didn't exist before the HP rework, that is, suspend worked fine with and without CONFIG_PREEMPT, right?

I see if I can find a tegra system to test with...

Thanks,
Richard

#88 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Quoted 1 line · On Mon, Jul 25, 2016 at 05:35:43PM +0200…

I see if I can find a tegra system to test with...

I tried the tip:smp/hotplug branch under kvm x86_64, and I didn't see any problems with suspend or hibernate, even with CONFIG_PREEMPT_NONE. I'll see if I can get my hands on a tegra system tomorrow. Until then, two questions:

1. The issue appears with suspend (echo mem > /sys/power/state), as opposed to hibernate, right?

2. CONFIG_PREEMPT_NONE is good, but CONFIG_PREEMPT is bad, right?

Thanks,
Richard

maintainer
#89 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Quoted 10 lines · On 25/07/16 21:46, [email protected] wrote:
Quoted 1 line · On Mon, Jul 25, 2016 at 05:35:43PM +0200…

I see if I can find a tegra system to test with...

I tried the tip:smp/hotplug branch under kvm x86_64, and I didn't see any problems with suspend or hibernate, even with CONFIG_PREEMPT_NONE. I'll see if I can get my hands on a tegra system tomorrow. Until then, two questions:

1. The issue appears with suspend (echo mem > /sys/power/state), as opposed to hibernate, right?

Yes. I have been using rtcwake to test suspend with the following arguments ...

# rtcwake -d rtc1 -m mem -s 3
Quoted 1 line

2. CONFIG_PREEMPT_NONE is good, but CONFIG_PREEMPT is bad, right?

The other way around.

Cheers
Jon

Signature · 1 line
nvpublic
maintainer
#90 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

In reply to [email protected]
Quoted 14 lines · On 25/07/16 16:35, [email protected] wrote:
Quoted 6 lines · Jon Hunter
Quoted 6 lines

There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

Quoted 6 lines
Quoted 2 lines

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

After this change is applied I am seeing RCU stalls during suspend on Tegra. I guess I am hitting the case mentioned above? How should this be avoided?

Quoted 6 lines

The problem that I had found was a hidden dependency. When I initially placed the timers callback into the new HP state list, that caused a stall because the dependency was broken. The old code worked by luck, based on the order of the notifier registrations. The new code makes the old implicit ordering explicit, so it should work just as well as before (famous last words).

I see.

Quoted 8 lines
Quoted 5 lines

Interestingly I am only seeing the above when using the ARM multi_v7_defconfig kernel configuration and not with the tegra_defconfig. One key difference between these is that the multi_v7_defconfig does not have CONFIG_PREEMPT enabled. Initial testing shows enabling CONFIG_PREEMPT for multi_v7_defconfig makes the problem go away.

Just to be sure, this problem didn't exist before the HP rework, that is, suspend worked fine with and without CONFIG_PREEMPT, right?

Correct. I test suspend on Tegra with both multi_v7_defconfig (CONFIG_PREEMPT disabled) and tegra_defconfig (CONFIG_PREEMPT enabled). Looking at the git history for these configs I don't see any changes in this regard since they were added (unless some underlying Kconfig files have changed).

Quoted 1 line

I see if I can find a tegra system to test with...

Thanks. I have not tried another ARM based device, but I would be curious if another ARM device sees this or not.

Cheers
Jon

Signature · 1 line
nvpublic
#91 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Jon,

Quoted 9 lines · Jon Hunter
Quoted 2 lines · On 25/07/16 16:35, [email protected] wrote:

Just to be sure, this problem didn't exist before the HP rework, that is, suspend worked fine with and without CONFIG_PREEMPT, right?

Correct. I test suspend on Tegra with both multi_v7_defconfig (CONFIG_PREEMPT disabled) and tegra_defconfig (CONFIG_PREEMPT enabled). Looking at the git history for these configs I don't see any changes in this regard since they were added (unless some underlying Kconfig files have changed).

Is that fully reproducible, i.e on every suspend?

Can you please check whether this issue happens with just cpu offline as well? I.e. set a cpu (or all non-boot cpus) offline, wait long enough that the stall detector can trigger, set the cpu(s) online again and repeat.

Thanks

tglx

maintainer
#92 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Hi Thomas,

Quoted 7 lines · Thomas Gleixner

Jon,

Quoted 4 lines · Jon Hunter
Quoted 2 lines · On 25/07/16 16:35, [email protected] wrote:

Just to be sure, this problem didn't exist before the HP rework, that is, suspend worked fine with and without CONFIG_PREEMPT, right?

Quoted 7 lines
Quoted 5 lines

Correct. I test suspend on Tegra with both multi_v7_defconfig (CONFIG_PREEMPT disabled) and tegra_defconfig (CONFIG_PREEMPT enabled). Looking at the git history for these configs I don't see any changes in this regard since they were added (unless some underlying Kconfig files have changed).

Is that fully reproducible, i.e on every suspend?

No not every suspend. I run 10 suspend cycles on each Tegra board (5 boards total) and typically between 3 and 5 boards would see the stall in the 10 suspend cycles. So it does appear to be timing sensitive.

Quoted 3 lines

Can you please check whether this issue happens with just cpu offline as well? I.e. set a cpu (or all non-boot cpus) offline, wait long enough that the stall detector can trigger, set the cpu(s) online again and repeat.

I can, but it appears like Richard's patch has fixed this. I am happy to do more testing if necessary.

Cheers
Jon

Signature · 1 line
nvpublic
#93 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

In reply to Jon Hunter

Jon,

Quoted 2 lines · Jon Hunter

Thanks. I have not tried another ARM based device, but I would be curious if another ARM device sees this or not.

I do see this stall on socfpga and on zynq, but in both cases the suspend mechanism is flakey in other ways, too. At least I can reproduce the stall sometimes.

In your other mail you wrote that you test it like this:

rtcwake -d rtc1 -m mem -s 3

But the stall appears only after 20 seconds. So the resume event after three seconds (-s 3) is getting lost, right?

Thanks,
Richard

maintainer
#94 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Hi Richard,

Quoted 10 lines · On 26/07/16 15:40, [email protected] wrote:

Jon,

Quoted 2 lines · Jon Hunter

Thanks. I have not tried another ARM based device, but I would be curious if another ARM device sees this or not.

I do see this stall on socfpga and on zynq, but in both cases the suspend mechanism is flakey in other ways, too. At least I can reproduce the stall sometimes.

Quoted 6 lines

In your other mail you wrote that you test it like this:

rtcwake -d rtc1 -m mem -s 3

But the stall appears only after 20 seconds. So the resume event after three seconds (-s 3) is getting lost, right?

I don't think so. I noticed that when the stall occurs, I don't see the board attempt to transition to the Tegra LP1 power state in suspend and appears to wake up straight away. So I think the wake-up is seen, but the stall prevents it from transitioning all the way to LP1.

Cheers
Jon

Signature · 1 line
nvpublic
#95 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

In reply to Jon Hunter

Jon,

Quoted 7 lines · Jon Hunter
Quoted 7 lines

When tearing down, call timers_dead_cpu before notify_dead. There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

Quoted 6 lines
Quoted 2 lines

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

After this change is applied I am seeing RCU stalls during suspend on Tegra. I guess I am hitting the case mentioned above? How should this be avoided?

Contrary to the commit message, this callback ended up in the wrong place within the sequence. (It was correct in an earlier version, but the series has been through many changes.)

Can you try this patch to see if it avoids the stall, please?

Thanks,
Richard
---

include/linux/cpuhotplug.h +1 -1
index 6d405db..242bf53 100644
@@ -20,9 +20,9 @@ enum cpuhp_state {
 	CPUHP_PROFILE_PREPARE,
 	CPUHP_X2APIC_PREPARE,
 	CPUHP_SMPCFD_PREPARE,
-	CPUHP_TIMERS_DEAD,
 	CPUHP_RCUTREE_PREP,
 	CPUHP_NOTIFY_PREPARE,
+	CPUHP_TIMERS_DEAD,
 	CPUHP_BRINGUP_CPU,
 	CPUHP_AP_IDLE_DEAD,
 	CPUHP_AP_OFFLINE,
kernel/cpu.c +5 -5
index 67f4943..8d65510 100644
@@ -1208,11 +1208,6 @@ static struct cpuhp_step cpuhp_bp_states[] = {
 		.startup = smpcfd_prepare_cpu,
 		.teardown = smpcfd_dead_cpu,
 	},
-	[CPUHP_TIMERS_DEAD] = {
-		.name = "timers dead",
-		.startup = NULL,
-		.teardown = timers_dead_cpu,
-	},
 	[CPUHP_RCUTREE_PREP] = {
 		.name = "RCU-tree prepare",
 		.startup = rcutree_prepare_cpu,
@@ -1229,6 +1224,11 @@ static struct cpuhp_step cpuhp_bp_states[] = {
 		.skip_onerr		= true,
 		.cant_stop		= true,
 	},
+	[CPUHP_TIMERS_DEAD] = {
+		.name = "timers dead",
+		.startup = NULL,
+		.teardown = timers_dead_cpu,
+	},
 	/* Kicks the plugged cpu into life */
 	[CPUHP_BRINGUP_CPU] = {
 		.name			= "cpu:bringup",
maintainer
#96 lore raw

Re: [patch 61/66] timers: Convert to hotplug state machine

Hi Richard,

Quoted 17 lines · On 26/07/16 16:42, [email protected] wrote:

Jon,

Quoted 7 lines · Jon Hunter
Quoted 7 lines

When tearing down, call timers_dead_cpu before notify_dead. There is a hidden dependency between:

- timers
- Block multiqueue
- rcutree

Quoted 6 lines
Quoted 2 lines

If timers_dead_cpu() comes later than blk_mq_queue_reinit_notify() that latter function causes a RCU stall.

After this change is applied I am seeing RCU stalls during suspend on Tegra. I guess I am hitting the case mentioned above? How should this be avoided?

Quoted 5 lines

Contrary to the commit message, this callback ended up in the wrong place within the sequence. (It was correct in an earlier version, but the series has been through many changes.)

Can you try this patch to see if it avoids the stall, please?

I have included the patch and I am no longer seeing any RCU stalls and so this does look like it fixed it.

Thanks!
Jon

Signature · 1 line
nvpublic
author maintainer
#97 lore raw

PATCH 62/66 profile: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs. A lot of code is removed because the for-loop is used and create_hash_tables() is removed since its purpose is covered by the startup / teardown hooks.

---
 include/linux/cpuhotplug.h |    1 
 kernel/profile.c           |  181 ++++++++++++++++-----------------------------
 2 files changed, 66 insertions(+), 116 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -18,6 +18,7 @@ enum cpuhp_state {
 	CPUHP_RCUTREE_PREP,
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_HRTIMERS_PREPARE,
+	CPUHP_PROFILE_PREPARE,
 	CPUHP_TIMERS_DEAD,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
kernel/profile.c +65 -116

216 lines not on this page · raw message

author maintainer
#98 lore raw

PATCH 63/66 x86/x2apic: Convert to CPU hotplug state machine

In reply to Anna-Maria Gleixner

From: Sebastian Andrzej Siewior <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 arch/x86/kernel/apic/x2apic_cluster.c |   80 ++++++++++++----------------------
 include/linux/cpuhotplug.h            |    1 
 2 files changed, 31 insertions(+), 50 deletions(-)
arch/x86/kernel/apic/x2apic_cluster.c +30 -50
@@ -152,68 +152,48 @@ static void init_x2apic_ldr(void)
 	}
 }
 
- /*
-  * At CPU state changes, update the x2apic cluster sibling info.
-  */
-static int
-update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
+/*
+ * At CPU state changes, update the x2apic cluster sibling info.
+ */
+int x2apic_prepare_cpu(unsigned int cpu)
 {
-	unsigned int this_cpu = (unsigned long)hcpu;
-	unsigned int cpu;
-	int err = 0;
-
-	switch (action) {
-	case CPU_UP_PREPARE:
-		if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, this_cpu),
-					GFP_KERNEL)) {
-			err = -ENOMEM;
-		} else if (!zalloc_cpumask_var(&per_cpu(ipi_mask, this_cpu),
-					       GFP_KERNEL)) {
-			free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
-			err = -ENOMEM;
-		}
-		break;
-	case CPU_UP_CANCELED:
-	case CPU_UP_CANCELED_FROZEN:
-	case CPU_DEAD:
-		for_each_online_cpu(cpu) {
-			if (x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
-				continue;
-			cpumask_clear_cpu(this_cpu, per_cpu(cpus_in_cluster, cpu));
-			cpumask_clear_cpu(cpu, per_cpu(cpus_in_cluster, this_cpu));
-		}
-		free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
-		free_cpumask_var(per_cpu(ipi_mask, this_cpu));
-		break;
+	if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL))
+		return -ENOMEM;
+
+	if (!zalloc_cpumask_var(&per_cpu(ipi_mask, cpu), GFP_KERNEL)) {
+		free_cpumask_var(per_cpu(cpus_in_cluster, cpu));
+		return -ENOMEM;
 	}
 
-	return notifier_from_errno(err);
+	return 0;
 }
 
-static struct notifier_block x2apic_cpu_notifier = {
-	.notifier_call = update_clusterinfo,
-};
-
-static int x2apic_init_cpu_notifier(void)
+int x2apic_dead_cpu(unsigned int this_cpu)
 {
-	int cpu = smp_processor_id();
-
-	zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL);
-	zalloc_cpumask_var(&per_cpu(ipi_mask, cpu), GFP_KERNEL);
+	int cpu;
 
-	BUG_ON(!per_cpu(cpus_in_cluster, cpu) || !per_cpu(ipi_mask, cpu));
-
-	cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu));
-	register_hotcpu_notifier(&x2apic_cpu_notifier);
-	return 1;
+	for_each_online_cpu(cpu) {
+		if (x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
+			continue;
+		cpumask_clear_cpu(this_cpu, per_cpu(cpus_in_cluster, cpu));
+		cpumask_clear_cpu(cpu, per_cpu(cpus_in_cluster, this_cpu));
+	}
+	free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
+	free_cpumask_var(per_cpu(ipi_mask, this_cpu));
+	return 0;
 }
 
 static int x2apic_cluster_probe(void)
 {
-	if (x2apic_mode)
-		return x2apic_init_cpu_notifier();
-	else
+	int cpu = smp_processor_id();
+
+	if (!x2apic_mode)
 		return 0;
+
+	cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu));
+	cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE",
+			  x2apic_prepare_cpu, x2apic_dead_cpu);
+	return 1;
 }
 
 static const struct cpumask *x2apic_cluster_target_cpus(void)
include/linux/cpuhotplug.h +1 -0
@@ -19,6 +19,7 @@ enum cpuhp_state {
 	CPUHP_POWER_NUMA_PREPARE,
 	CPUHP_HRTIMERS_PREPARE,
 	CPUHP_PROFILE_PREPARE,
+	CPUHP_X2APIC_PREPARE,
 	CPUHP_TIMERS_DEAD,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
author maintainer
#99 lore raw

PATCH 64/66 smp: Convert core to hotplug state machine

In reply to Anna-Maria Gleixner

From: Richard Weinberger <[email protected]>

Install the callbacks via the state machine. They are installed at runtime so smpcfd_prepare_cpu() needs to be invoked by the boot-CPU.

[ RC: added the dropped "cpu dying" case back in. ]

---
 include/linux/cpuhotplug.h |    2 +
 include/linux/smp.h        |    5 ++
 kernel/cpu.c               |    9 +++++
 kernel/smp.c               |   79 ++++++++++++++++++---------------------------
 4 files changed, 48 insertions(+), 47 deletions(-)
include/linux/cpuhotplug.h +2 -0
@@ -20,6 +20,7 @@ enum cpuhp_state {
 	CPUHP_HRTIMERS_PREPARE,
 	CPUHP_PROFILE_PREPARE,
 	CPUHP_X2APIC_PREPARE,
+	CPUHP_SMPCFD_PREPARE,
 	CPUHP_TIMERS_DEAD,
 	CPUHP_NOTIFY_PREPARE,
 	CPUHP_BRINGUP_CPU,
@@ -65,6 +66,7 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_CORESIGHT4_STARTING,
 	CPUHP_AP_ARM64_ISNDEP_STARTING,
 	CPUHP_AP_LEDTRIG_STARTING,
+	CPUHP_AP_SMPCFD_DYING,
 	CPUHP_AP_X86_TBOOT_DYING,
 	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
include/linux/smp.h +5 -0
@@ -196,4 +196,9 @@ extern void arch_enable_nonboot_cpus_end
 
 void smp_setup_processor_id(void);
 
+/* SMP core functions */
+int smpcfd_prepare_cpu(unsigned int cpu);
+int smpcfd_dead_cpu(unsigned int cpu);
+int smpcfd_dying_cpu(unsigned int cpu);
+
 #endif /* __LINUX_SMP_H */
kernel/cpu.c +9 -0
@@ -1194,6 +1194,11 @@ static struct cpuhp_step cpuhp_bp_states
 		.startup = hrtimers_prepare_cpu,
 		.teardown = hrtimers_dead_cpu,
 	},
+	[CPUHP_SMPCFD_PREPARE] = {
+		.name = "SMPCFD prepare",
+		.startup = smpcfd_prepare_cpu,
+		.teardown = smpcfd_dead_cpu,
+	},
 	[CPUHP_TIMERS_DEAD] = {
 		.name = "timers dead",
 		.startup = NULL,
@@ -1217,6 +1222,10 @@ static struct cpuhp_step cpuhp_bp_states
 		.teardown		= NULL,
 		.cant_stop		= true,
 	},
+	[CPUHP_AP_SMPCFD_DYING] = {
+		.startup = NULL,
+		.teardown = smpcfd_dying_cpu,
+	},
 	/*
 	 * Handled on controll processor until the plugged processor manages
 	 * this itself.
kernel/smp.c +32 -47

101 lines not on this page · raw message

author maintainer
#100 lore raw

PATCH 65/66 KVM: arm/arm64: vgic-new: Convert to hotplug state machine

In reply to Anna-Maria Gleixner

From: Anna-Maria Gleixner <[email protected]>

Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs.

---
 include/linux/cpuhotplug.h    |    1 +
 virt/kvm/arm/vgic/vgic-init.c |   31 +++++++++----------------------
 2 files changed, 10 insertions(+), 22 deletions(-)
include/linux/cpuhotplug.h +1 -0
@@ -59,6 +59,7 @@ enum cpuhp_state {
 	CPUHP_AP_MIPS_GIC_TIMER_STARTING,
 	CPUHP_AP_ARC_TIMER_STARTING,
 	CPUHP_AP_KVM_STARTING,
+	CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING,
 	CPUHP_AP_KVM_ARM_VGIC_STARTING,
 	CPUHP_AP_KVM_ARM_TIMER_STARTING,
 	CPUHP_AP_ARM_XEN_STARTING,
virt/kvm/arm/vgic/vgic-init.c +9 -22
@@ -353,32 +353,19 @@ int kvm_vgic_map_resources(struct kvm *k
 
 /* GENERIC PROBE */
 
-static void vgic_init_maintenance_interrupt(void *info)
+static int vgic_init_cpu_starting(unsigned int cpu)
 {
 	enable_percpu_irq(kvm_vgic_global_state.maint_irq, 0);
+	return 0;
 }
 
-static int vgic_cpu_notify(struct notifier_block *self,
-			   unsigned long action, void *cpu)
-{
-	switch (action) {
-	case CPU_STARTING:
-	case CPU_STARTING_FROZEN:
-		vgic_init_maintenance_interrupt(NULL);
-		break;
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		disable_percpu_irq(kvm_vgic_global_state.maint_irq);
-		break;
-	}
 
-	return NOTIFY_OK;
+static int vgic_init_cpu_dying(unsigned int cpu)
+{
+	disable_percpu_irq(kvm_vgic_global_state.maint_irq);
+	return 0;
 }
 
-static struct notifier_block vgic_cpu_nb = {
-	.notifier_call = vgic_cpu_notify,
-};
-
 static irqreturn_t vgic_maintenance_handler(int irq, void *data)
 {
 	/*
@@ -434,14 +421,14 @@ int kvm_vgic_hyp_init(void)
 		return ret;
 	}
 
-	ret = __register_cpu_notifier(&vgic_cpu_nb);
+	ret = cpuhp_setup_state(CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING,
+				"AP_KVM_ARM_VGIC_INIT_STARTING",
+				vgic_init_cpu_starting, vgic_init_cpu_dying);
 	if (ret) {
 		kvm_err("Cannot register vgic CPU notifier\n");
 		goto out_free_irq;
 	}
 
-	on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1);
-
 	kvm_info("vgic interrupt IRQ%d\n", kvm_vgic_global_state.maint_irq);
 	return 0;
 
author maintainer
#101 lore raw

PATCH 66/66 cpuhotplug: Remove CPU_STARTING and CPU_DYING notifier

In reply to Anna-Maria Gleixner

All users are converted to the new state machine, remove CPU_STARTING and the corresponding CPU_DYING.

---
 arch/sparc/kernel/smp_32.c           |    2 --
 include/linux/cpu.h                  |   12 ------------
 include/linux/cpuhotplug.h           |    1 -
 kernel/cpu.c                         |   30 ++----------------------------
 tools/testing/radix-tree/linux/cpu.h |   13 -------------
 5 files changed, 2 insertions(+), 56 deletions(-)
arch/sparc/kernel/smp_32.c +0 -2
@@ -352,9 +352,7 @@ static void sparc_start_secondary(void *
 	preempt_disable();
 	cpu = smp_processor_id();
 
-	/* Invoke the CPU_STARTING notifier callbacks */
 	notify_cpu_starting(cpu);
-
 	arch_cpu_pre_online(arg);
 
 	/* Set the CPU in the cpu_online_mask */
include/linux/cpu.h +0 -12
@@ -61,17 +61,8 @@ struct notifier_block;
 #define CPU_DOWN_PREPARE	0x0005 /* CPU (unsigned)v going down */
 #define CPU_DOWN_FAILED		0x0006 /* CPU (unsigned)v NOT going down */
 #define CPU_DEAD		0x0007 /* CPU (unsigned)v dead */
-#define CPU_DYING		0x0008 /* CPU (unsigned)v not running any task,
-					* not handling interrupts, soon dead.
-					* Called on the dying cpu, interrupts
-					* are already disabled. Must not
-					* sleep, must not fail */
 #define CPU_POST_DEAD		0x0009 /* CPU (unsigned)v dead, cpu_hotplug
 					* lock is dropped */
-#define CPU_STARTING		0x000A /* CPU (unsigned)v soon running.
-					* Called on the new cpu, just before
-					* enabling interrupts. Must not sleep,
-					* must not fail */
 #define CPU_BROKEN		0x000B /* CPU (unsigned)v did not die properly,
 					* perhaps due to preemption. */
 
@@ -86,9 +77,6 @@ struct notifier_block;
 #define CPU_DOWN_PREPARE_FROZEN	(CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
 #define CPU_DOWN_FAILED_FROZEN	(CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
 #define CPU_DEAD_FROZEN		(CPU_DEAD | CPU_TASKS_FROZEN)
-#define CPU_DYING_FROZEN	(CPU_DYING | CPU_TASKS_FROZEN)
-#define CPU_STARTING_FROZEN	(CPU_STARTING | CPU_TASKS_FROZEN)
-
 
 #ifdef CONFIG_SMP
 extern bool cpuhp_tasks_frozen;
include/linux/cpuhotplug.h +0 -1
@@ -69,7 +69,6 @@ enum cpuhp_state {
 	CPUHP_AP_LEDTRIG_STARTING,
 	CPUHP_AP_SMPCFD_DYING,
 	CPUHP_AP_X86_TBOOT_DYING,
-	CPUHP_AP_NOTIFY_STARTING,
 	CPUHP_AP_ONLINE,
 	CPUHP_TEARDOWN_CPU,
 	CPUHP_AP_ONLINE_IDLE,
kernel/cpu.c +2 -28
@@ -331,12 +331,6 @@ static int notify_online(unsigned int cp
 	return 0;
 }
 
-static int notify_starting(unsigned int cpu)
-{
-	cpu_notify(CPU_STARTING, cpu);
-	return 0;
-}
-
 static int bringup_wait_for_ap(unsigned int cpu)
 {
 	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
@@ -668,12 +662,6 @@ static int notify_down_prepare(unsigned
 	return err;
 }
 
-static int notify_dying(unsigned int cpu)
-{
-	cpu_notify(CPU_DYING, cpu);
-	return 0;
-}
-
 /* Take this CPU down. */
 static int take_cpu_down(void *_param)
 {
@@ -728,7 +716,7 @@ static int takedown_cpu(unsigned int cpu
 	BUG_ON(cpu_online(cpu));
 
 	/*
-	 * The migration_call() CPU_DYING callback will have removed all
+	 * The CPUHP_AP_SCHED_MIGRATE_DYING callback will have removed all
 	 * runnable tasks from the cpu, there's only the idle task left now
 	 * that the migration thread is done doing the stop_machine thing.
 	 *
@@ -781,7 +769,6 @@ void cpuhp_report_idle_dead(void)
 #define notify_down_prepare	NULL
 #define takedown_cpu		NULL
 #define notify_dead		NULL
-#define notify_dying		NULL
 #endif
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -871,10 +858,9 @@ EXPORT_SYMBOL(cpu_down);
 #endif /*CONFIG_HOTPLUG_CPU*/
 
 /**
- * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers
+ * notify_cpu_starting(cpu) - Invoke the callbacks on the starting CPU
  * @cpu: cpu that just started
  *
- * This function calls the cpu_chain notifiers with CPU_STARTING.
  * It must be called by the arch code on the new cpu, before the new cpu
  * enables interrupts and before the "boot" cpu returns from __cpu_up().
  */
@@ -1264,18 +1250,6 @@ static struct cpuhp_step cpuhp_ap_states
 		.startup = NULL,
 		.teardown = rcutree_dying_cpu,
 	},
-	/*
-	 * Low level startup/teardown notifiers. Run with interrupts
-	 * disabled. Will be removed once the notifiers are converted to
-	 * states.
-	 */
-	[CPUHP_AP_NOTIFY_STARTING] = {
-		.name			= "notify:starting",
-		.startup		= notify_starting,
-		.teardown		= notify_dying,
-		.skip_onerr		= true,
-		.cant_stop		= true,
-	},
 	/* Entry state on starting. Interrupts enabled from here on. Transient
 	 * state for synchronsization */
 	[CPUHP_AP_ONLINE] = {
tools/testing/radix-tree/linux/cpu.h +0 -13
@@ -7,19 +7,8 @@
 #define CPU_DOWN_PREPARE	0x0005 /* CPU (unsigned)v going down */
 #define CPU_DOWN_FAILED		0x0006 /* CPU (unsigned)v NOT going down */
 #define CPU_DEAD		0x0007 /* CPU (unsigned)v dead */
-#define CPU_DYING		0x0008 /* CPU (unsigned)v not running any task,
-					* not handling interrupts, soon dead.
-					* Called on the dying cpu, interrupts
-					* are already disabled. Must not
-					* sleep, must not fail */
 #define CPU_POST_DEAD		0x0009 /* CPU (unsigned)v dead, cpu_hotplug
 					* lock is dropped */
-#define CPU_STARTING		0x000A /* CPU (unsigned)v soon running.
-					* Called on the new cpu, just before
-					* enabling interrupts. Must not sleep,
-					* must not fail */
-#define CPU_DYING_IDLE		0x000B /* CPU (unsigned)v dying, reached
-					* idle loop. */
 #define CPU_BROKEN		0x000C /* CPU (unsigned)v did not die properly,
 					* perhaps due to preemption. */
 #define CPU_TASKS_FROZEN	0x0010
@@ -30,5 +19,3 @@
 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
 #define CPU_DOWN_FAILED_FROZEN  (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
 #define CPU_DEAD_FROZEN		(CPU_DEAD | CPU_TASKS_FROZEN)
-#define CPU_DYING_FROZEN	(CPU_DYING | CPU_TASKS_FROZEN)
-#define CPU_STARTING_FROZEN	(CPU_STARTING | CPU_TASKS_FROZEN)