Skip to contentSkip to conversation

parisc: Switch from GENERIC_CPU_DEVICES to GENERIC_ARCH_TOPOLOGY

PATCH In review Helge Deller 2 participants 23 messages Mar 25, 2022 – Mar 26, 2022 PA-RISC architecture

lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

PATCH 1/12 parisc: Switch from GENERIC_CPU_DEVICES to GENERIC_ARCH_TOPOLOGY

Switch away from the own cpu topology code to common code which is used by ARM64 and RISCV. That allows us to enable hotplug later on too.

---
 arch/parisc/Kconfig                |  2 +-
 arch/parisc/include/asm/topology.h | 20 +--------
 arch/parisc/kernel/processor.c     |  2 +
 arch/parisc/kernel/topology.c      | 72 +++++++-----------------------
 4 files changed, 19 insertions(+), 77 deletions(-)
arch/parisc/Kconfig +1 -1
index 00cb889bd9a6..6bd42c82a019 100644
@@ -37,7 +37,7 @@ config PARISC
 	select GENERIC_PCI_IOMAP
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_SMP_IDLE_THREAD
-	select GENERIC_CPU_DEVICES
+	select GENERIC_ARCH_TOPOLOGY
 	select GENERIC_LIB_DEVMEM_IS_ALLOWED
 	select SYSCTL_ARCH_UNALIGN_ALLOW
 	select SYSCTL_EXCEPTION_TRACE
arch/parisc/include/asm/topology.h +1 -19
index 6f0750c74e47..734eddf096f7 100644
@@ -4,25 +4,7 @@
 #ifdef CONFIG_PARISC_CPU_TOPOLOGY
 
 #include <linux/cpumask.h>
-
-struct cputopo_parisc {
-	int thread_id;
-	int core_id;
-	int socket_id;
-	cpumask_t thread_sibling;
-	cpumask_t core_sibling;
-};
-
-extern struct cputopo_parisc cpu_topology[NR_CPUS];
-
-#define topology_physical_package_id(cpu)	(cpu_topology[cpu].socket_id)
-#define topology_core_id(cpu)		(cpu_topology[cpu].core_id)
-#define topology_core_cpumask(cpu)	(&cpu_topology[cpu].core_sibling)
-#define topology_sibling_cpumask(cpu)	(&cpu_topology[cpu].thread_sibling)
-
-void init_cpu_topology(void);
-void store_cpu_topology(unsigned int cpuid);
-const struct cpumask *cpu_coregroup_mask(int cpu);
+#include <linux/arch_topology.h>
 
 #else
 
arch/parisc/kernel/processor.c +2 -0
index ccaf075d0750..d0bfd61a4623 100644
@@ -19,6 +19,7 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/cpu.h>
+#include <asm/topology.h>
 #include <asm/param.h>
 #include <asm/cache.h>
 #include <asm/hardware.h>	/* for register_parisc_driver() stuff */
@@ -459,5 +460,6 @@ static struct parisc_driver cpu_driver __refdata = {
  */
 void __init processor_init(void)
 {
+	reset_cpu_topology();
 	register_parisc_driver(&cpu_driver);
 }
arch/parisc/kernel/topology.c +15 -57

118 lines not on this page · raw message

--
2.35.1

author maintainer
#1 lore raw

PATCH 2/12 parisc: Add __cpuinit section for HOTPLUG_CPU

Provide a __cpuinit section which needs to be used instead of __init when CPU hotplugging is enabled.

---
 arch/parisc/include/asm/sections.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/parisc/include/asm/sections.h +6 -0
index bb52aea0cb21..4c28c7adaf5f 100644
@@ -7,6 +7,12 @@
 
 extern char __alt_instructions[], __alt_instructions_end[];
 
+#ifdef CONFIG_HOTPLUG_CPU
+#define __cpuinit
+#else
+#define __cpuinit	__init
+#endif
+
 #ifdef CONFIG_64BIT
 
 #define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1

--
2.35.1

author maintainer
#2 lore raw

PATCH 3/12 parisc: Move store_cpu_topology() into __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/topology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/parisc/kernel/topology.c +3 -2
index 72d9aeb54fbe..dc766fb55491 100644
@@ -16,17 +16,18 @@
 #include <linux/cpu.h>
 
 #include <asm/topology.h>
+#include <asm/sections.h>
 
 static DEFINE_PER_CPU(struct cpu, cpu_devices);
 
-static int dualcores_found __initdata;
+static int dualcores_found;
 
 /*
  * store_cpu_topology is called at boot when only one cpu is running
  * and with the mutex cpu_hotplug.lock locked, when several cpus have booted,
  * which prevents simultaneous write access to cpu_topology array
  */
-void __init store_cpu_topology(unsigned int cpuid)
+void __cpuinit store_cpu_topology(unsigned int cpuid)
 {
 	struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
 	struct cpuinfo_parisc *p;

--
2.35.1

#3 lore raw

Re: [PATCH 03/12] parisc: Move store_cpu_topology() into __cpuinit section

Am Freitag, 25. März 2022, 15:38:24 CET schrieb Helge Deller:

Quoted 10 lines
---
 arch/parisc/kernel/topology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/parisc/kernel/topology.c +0 -0
index 72d9aeb54fbe..dc766fb55491 100644

arch/parisc/kernel/topology.c line 23

Quoted 9 lines
arch/parisc/kernel/topology.c +2 -1
@@ -16,17 +16,18 @@
 #include <linux/cpu.h>
 
 #include <asm/topology.h>
+#include <asm/sections.h>
 
 static DEFINE_PER_CPU(struct cpu, cpu_devices);
 
-static int dualcores_found __initdata;
+static int dualcores_found;

I wonder if that should not be something like __cpuinit_data.

author maintainer
#4 lore raw

Re: [PATCH 03/12] parisc: Move store_cpu_topology() into __cpuinit section

Quoted 16 lines · Rolf Eike Beer

Am Freitag, 25. März 2022, 15:38:24 CET schrieb Helge Deller:

Quoted 15 lines
---
 arch/parisc/kernel/topology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/parisc/kernel/topology.c +1 -0
index 72d9aeb54fbe..dc766fb55491 100644
@@ -16,17 +16,18 @@
 #include <linux/cpu.h>
 
 #include <asm/topology.h>
+#include <asm/sections.h>
 
Quoted 6 lines

arch/parisc/kernel/topology.c line 23

Quoted 4 lines
arch/parisc/kernel/topology.c +1 -1
 static DEFINE_PER_CPU(struct cpu, cpu_devices);
 
-static int dualcores_found __initdata;
+static int dualcores_found;

I wonder if that should not be something like __cpuinit_data.

Heh ... all other platforms got rid of __cpuinit and __cpuinit_data.
I just wanted to keep it on parisc in order to have small code in case of UP. That said, introducing a __cpuinit_data section for this single variable didn't made sense.

Helge

author maintainer
#5 lore raw

PATCH 4/12 parisc: Move start_cpu_itimer() into __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/time.c +1 -1
index 061119a56fbe..4101392bf74d 100644
@@ -150,7 +150,7 @@ static struct clocksource clocksource_cr16 = {
 	.flags			= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-void __init start_cpu_itimer(void)
+void __cpuinit start_cpu_itimer(void)
 {
 	unsigned int cpu = smp_processor_id();
 	unsigned long next_tick = mfctl(16) + clocktick;

--
2.35.1

#6 lore raw

Re: [PATCH 04/12] parisc: Move start_cpu_itimer() into __cpuinit section

Am Freitag, 25. März 2022, 15:38:25 CET schrieb Helge Deller:

Quoted 10 lines
---
 arch/parisc/kernel/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/time.c +0 -0
index 061119a56fbe..4101392bf74d 100644

arch/parisc/kernel/time.c static struct clocksource clocksource_cr16 = { · line 156

Quoted 8 lines
arch/parisc/kernel/time.c +1 -1
@@ -150,7 +150,7 @@ static struct clocksource clocksource_cr16 = {
 	.flags			= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-void __init start_cpu_itimer(void)
+void __cpuinit start_cpu_itimer(void)
 {
 	unsigned int cpu = smp_processor_id();
 	unsigned long next_tick = mfctl(16) + clocktick;

I would have squashed this and 5, 7, and 8 together. None of these patches adds any sensible description and all do the same.

author maintainer
#7 lore raw

Re: [PATCH 04/12] parisc: Move start_cpu_itimer() into __cpuinit section

Quoted 14 lines · Rolf Eike Beer

Am Freitag, 25. März 2022, 15:38:25 CET schrieb Helge Deller:

Quoted 13 lines
---
 arch/parisc/kernel/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/time.c +0 -0
index 061119a56fbe..4101392bf74d 100644
@@ -150,7 +150,7 @@ static struct clocksource clocksource_cr16 = {
 	.flags			= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
Quoted 8 lines

arch/parisc/kernel/time.c static struct clocksource clocksource_cr16 = { · line 156

Quoted 5 lines
arch/parisc/kernel/time.c +1 -1
-void __init start_cpu_itimer(void)
+void __cpuinit start_cpu_itimer(void)
 {
 	unsigned int cpu = smp_processor_id();
 	unsigned long next_tick = mfctl(16) + clocktick;

I would have squashed this and 5, 7, and 8 together. None of these patches adds any sensible description and all do the same.

Yes, maybe I'll do that. Keeping them seperate makes handling easier for me.

Helge

author maintainer
#8 lore raw

PATCH 5/12 parisc: Move init_per_cpu() init __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/processor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/parisc/kernel/processor.c +2 -1
index d0bfd61a4623..89284e79c159 100644
@@ -29,6 +29,7 @@
 #include <asm/pdcpat.h>
 #include <asm/irq.h>		/* for struct irq_region */
 #include <asm/parisc-device.h>
+#include <asm/sections.h>
 
 struct system_cpuinfo_parisc boot_cpu_data __ro_after_init;
 EXPORT_SYMBOL(boot_cpu_data);
@@ -317,7 +318,7 @@ void __init collect_boot_cpu_data(void)
  *
  * o Enable CPU profiling hooks.
  */
-int __init init_per_cpu(int cpunum)
+int __cpuinit init_per_cpu(int cpunum)
 {
 	int ret;
 	struct pdc_coproc_cfg coproc_cfg;

--
2.35.1

author maintainer
#9 lore raw

PATCH 6/12 parisc: Move disable_sr_hashing_asm() into __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/pacache.S | 4 ++++
 1 file changed, 4 insertions(+)
arch/parisc/kernel/pacache.S +4 -0
index b2ba6d633065..661b1834ac94 100644
@@ -1264,7 +1264,11 @@ ENTRY_CFI(flush_kernel_icache_range_asm)
 	nop
 ENDPROC_CFI(flush_kernel_icache_range_asm)
 
+#ifdef CONFIG_HOTPLUG_CPU
+	.text
+#else
 	__INIT
+#endif
 
 	/* align should cover use of rfi in disable_sr_hashing_asm and
 	 * srdis_done.

--
2.35.1

author maintainer
#10 lore raw

PATCH 7/12 parisc: Move disable_sr_hashing() into __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/cache.c +1 -1
index 456e879d34a8..6be03d3a2382 100644
@@ -273,7 +273,7 @@ parisc_cache_init(void)
 	}
 }
 
-void __init disable_sr_hashing(void)
+void __cpuinit disable_sr_hashing(void)
 {
 	int srhash_type, retval;
 	unsigned long space_bits;

--
2.35.1

author maintainer
#11 lore raw

PATCH 8/12 parisc: Move init_IRQ() into __cpuinit section

In reply to Helge Deller
---
 arch/parisc/kernel/irq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/irq.c +1 -1
index eb18e16362f6..a8372db32492 100644
@@ -582,7 +582,7 @@ static void claim_cpu_irqs(void)
 #endif
 }
 
-void __init init_IRQ(void)
+void __cpuinit init_IRQ(void)
 {
 	local_irq_disable();	/* PARANOID - should already be disabled */
 	mtctl(~0UL, 23);	/* EIRR : clear all pending external intr */

--
2.35.1

author maintainer
#12 lore raw

PATCH 9/12 parisc: Ensure set_firmware_width() is called only once

In reply to Helge Deller

Make sure, that set_firmware_width() is only called once at runtime. This prevents that if secondary CPUs are started later get stuck in spinlocks.

---
 arch/parisc/kernel/firmware.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/parisc/kernel/firmware.c +6 -1
index 3370e347dde3..c6b11bdb8602 100644
@@ -83,7 +83,7 @@ extern unsigned long pdc_result2[NUM_PDC_RESULT];
 
 /* Firmware needs to be initially set to narrow to determine the
  * actual firmware width. */
-int parisc_narrow_firmware __ro_after_init = 1;
+int parisc_narrow_firmware __ro_after_init = 2;
 #endif
 
 /* On most currently-supported platforms, IODC I/O calls are 32-bit calls
@@ -174,6 +174,11 @@ void set_firmware_width_unlocked(void)
 void set_firmware_width(void)
 {
 	unsigned long flags;
+
+	/* already initialized? */
+	if (parisc_narrow_firmware != 2)
+		return;
+
 	spin_lock_irqsave(&pdc_lock, flags);
 	set_firmware_width_unlocked();
 	spin_unlock_irqrestore(&pdc_lock, flags);

--
2.35.1

#13 lore raw

Re: [PATCH 09/12] parisc: Ensure set_firmware_width() is called only once

Am Freitag, 25. März 2022, 15:38:30 CET schrieb Helge Deller:

Quoted 3 lines

Make sure, that set_firmware_width() is only called once at runtime. This prevents that if secondary CPUs are started later get stuck in spinlocks.

The second sentence seems to be missing a word.

author maintainer
#14 lore raw

PATCH 10/12 parisc: Move common_stext into text section when CONFIG_HOTPLUG_CPU=y

In reply to Helge Deller

Move the common_stext function into the non-init text section if hotplug is enabled. This function is called from the firmware when secondary CPUS are brought up when CPU hotplug is enabled.

---
 arch/parisc/kernel/head.S | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/parisc/kernel/head.S +9 -2
index b24f77748c22..e0a9e9657622 100644
@@ -162,6 +162,15 @@ $pgt_fill_loop:
 	/* FALLTHROUGH */
 	.procend
 
+#ifdef CONFIG_HOTPLUG_CPU
+	/* common_stext is far away in another section... jump there */
+	load32		PA(common_stext), %rp
+	bv,n		(%rp)
+
+	/* common_stext and smp_slave_stext needs to be in text section */
+	.text
+#endif
+
 	/*
 	** Code Common to both Monarch and Slave processors.
 	** Entry:
@@ -371,8 +380,6 @@ smp_slave_stext:
 	.procend
 #endif /* CONFIG_SMP */
 
-ENDPROC(parisc_kernel_start)
-
 #ifndef CONFIG_64BIT
 	.section .data..ro_after_init
 

--
2.35.1

author maintainer
#15 lore raw

PATCH 11/12 parisc: Rewrite arch_cpu_idle_dead() for CPU hotplugging

In reply to Helge Deller

Let the PDC firmware put the CPU into firmware idle loop with pdc_cpu_rendezvous() function.

---
 arch/parisc/kernel/process.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
arch/parisc/kernel/process.c +30 -3
index ea3d83b6fb62..44fa89fbb280 100644
@@ -38,6 +38,7 @@
 #include <linux/rcupdate.h>
 #include <linux/random.h>
 #include <linux/nmi.h>
+#include <linux/sched/hotplug.h>
 
 #include <asm/io.h>
 #include <asm/asm-offsets.h>
@@ -46,6 +47,7 @@
 #include <asm/pdc_chassis.h>
 #include <asm/unwind.h>
 #include <asm/sections.h>
+#include <asm/cacheflush.h>
 
 #define COMMAND_GLOBAL  F_EXTEND(0xfffe0030)
 #define CMD_RESET       5       /* reset any module */
@@ -158,10 +160,35 @@ void release_thread(struct task_struct *dead_task)
 int running_on_qemu __ro_after_init;
 EXPORT_SYMBOL(running_on_qemu);
 
-void __cpuidle arch_cpu_idle_dead(void)
+/*
+ * Called from the idle thread for the CPU which has been shutdown.
+ */
+void arch_cpu_idle_dead(void)
 {
-	/* nop on real hardware, qemu will offline CPU. */
-	asm volatile("or %%r31,%%r31,%%r31\n":::);
+#ifdef CONFIG_HOTPLUG_CPU
+	idle_task_exit();
+
+	local_irq_disable();
+
+	/*
+	 * Tell __cpu_die() that this CPU is now safe to dispose of.
+	 */
+	(void)cpu_report_death();
+
+	/*
+	 * Ensure that the cache lines are written out.
+	 */
+	flush_cache_all_local();
+	flush_tlb_all_local(NULL);
+
+	/*
+	 * Let PDC firmware put CPU into firmware idle loop.
+	 */
+	__pdc_cpu_rendezvous();
+
+	pr_warn("PDC does not provide rendezvous function.\n");
+#endif
+	while (1);
 }
 
 void __cpuidle arch_cpu_idle(void)

--
2.35.1

#16 lore raw

Re: [PATCH 11/12] parisc: Rewrite arch_cpu_idle_dead() for CPU hotplugging

Am Freitag, 25. März 2022, 15:38:32 CET schrieb Helge Deller:

Quoted 50 lines

Let the PDC firmware put the CPU into firmware idle loop with pdc_cpu_rendezvous() function.

---
 arch/parisc/kernel/process.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
arch/parisc/kernel/process.c +16 -3
index ea3d83b6fb62..44fa89fbb280 100644
@@ -38,6 +38,7 @@
 #include <linux/rcupdate.h>
 #include <linux/random.h>
 #include <linux/nmi.h>
+#include <linux/sched/hotplug.h>
 
 #include <asm/io.h>
 #include <asm/asm-offsets.h>
@@ -46,6 +47,7 @@
 #include <asm/pdc_chassis.h>
 #include <asm/unwind.h>
 #include <asm/sections.h>
+#include <asm/cacheflush.h>
 
 #define COMMAND_GLOBAL  F_EXTEND(0xfffe0030)
 #define CMD_RESET       5       /* reset any module */
@@ -158,10 +160,35 @@ void release_thread(struct task_struct *dead_task)
 int running_on_qemu __ro_after_init;
 EXPORT_SYMBOL(running_on_qemu);
 
-void __cpuidle arch_cpu_idle_dead(void)
+/*
+ * Called from the idle thread for the CPU which has been shutdown.
+ */
+void arch_cpu_idle_dead(void)
 {
-	/* nop on real hardware, qemu will offline CPU. */
-	asm volatile("or %%r31,%%r31,%%r31\n":::);
+#ifdef CONFIG_HOTPLUG_CPU
+	idle_task_exit();
+
+	local_irq_disable();
+
+	/*
+	 * Tell __cpu_die() that this CPU is now safe to dispose of.
+	 */
+	(void)cpu_report_death();
+

arch/parisc/kernel/process.c void release_thread(struct task_struct *dead_task) · line 187

Quoted 10 lines
arch/parisc/kernel/process.c +10 -0
+	/*
+	 * Ensure that the cache lines are written out.
+	 */
+	flush_cache_all_local();
+	flush_tlb_all_local(NULL);
+
+	/*
+	 * Let PDC firmware put CPU into firmware idle loop.
+	 */
+	__pdc_cpu_rendezvous();

That could all be one-line comments for a higher code/line ratio ;)

author maintainer
#17 lore raw

Re: [PATCH 11/12] parisc: Rewrite arch_cpu_idle_dead() for CPU hotplugging

Quoted 55 lines · Rolf Eike Beer

Am Freitag, 25. März 2022, 15:38:32 CET schrieb Helge Deller:

Quoted 54 lines

Let the PDC firmware put the CPU into firmware idle loop with pdc_cpu_rendezvous() function.

---
 arch/parisc/kernel/process.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
arch/parisc/kernel/process.c +20 -3
index ea3d83b6fb62..44fa89fbb280 100644
@@ -38,6 +38,7 @@
 #include <linux/rcupdate.h>
 #include <linux/random.h>
 #include <linux/nmi.h>
+#include <linux/sched/hotplug.h>
 
 #include <asm/io.h>
 #include <asm/asm-offsets.h>
@@ -46,6 +47,7 @@
 #include <asm/pdc_chassis.h>
 #include <asm/unwind.h>
 #include <asm/sections.h>
+#include <asm/cacheflush.h>
 
 #define COMMAND_GLOBAL  F_EXTEND(0xfffe0030)
 #define CMD_RESET       5       /* reset any module */
@@ -158,10 +160,35 @@ void release_thread(struct task_struct *dead_task)
 int running_on_qemu __ro_after_init;
 EXPORT_SYMBOL(running_on_qemu);
 
-void __cpuidle arch_cpu_idle_dead(void)
+/*
+ * Called from the idle thread for the CPU which has been shutdown.
+ */
+void arch_cpu_idle_dead(void)
 {
-	/* nop on real hardware, qemu will offline CPU. */
-	asm volatile("or %%r31,%%r31,%%r31\n":::);
+#ifdef CONFIG_HOTPLUG_CPU
+	idle_task_exit();
+
+	local_irq_disable();
+
+	/*
+	 * Tell __cpu_die() that this CPU is now safe to dispose of.
+	 */
+	(void)cpu_report_death();
+
+	/*
+	 * Ensure that the cache lines are written out.
+	 */
+	flush_cache_all_local();
Quoted 8 lines

arch/parisc/kernel/process.c void release_thread(struct task_struct *dead_task) · line 187

Quoted 6 lines
arch/parisc/kernel/process.c +6 -0
+	flush_tlb_all_local(NULL);
+
+	/*
+	 * Let PDC firmware put CPU into firmware idle loop.
+	 */
+	__pdc_cpu_rendezvous();

That could all be one-line comments for a higher code/line ratio ;)

Yes. The syntax is mostly copied from other arches, where it's like this.

Helge

author maintainer
#18 lore raw

PATCH 12/12 parisc: Implement __cpu_die() and __cpu_disable() for CPU hotplugging

In reply to Helge Deller

Add relevant code to __cpu_die() and __cpu_disable() to finally enable the CPU hotplugging features. Reset the irq count values in smp_callin() to zero before bringing up the CPU.

Use "chcpu -d 1" to bring CPU1 down, and "chcpu -e 1" to bring it up.

---
 arch/parisc/Kconfig           |  1 +
 arch/parisc/include/asm/smp.h |  9 +---
 arch/parisc/kernel/smp.c      | 80 +++++++++++++++++++++++++++++++++--
 3 files changed, 79 insertions(+), 11 deletions(-)
arch/parisc/Kconfig +1 -0
index 6bd42c82a019..ec5bb9626d06 100644
@@ -56,6 +56,7 @@ config PARISC
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select GENERIC_SCHED_CLOCK
+	select GENERIC_IRQ_MIGRATION
 	select HAVE_UNSTABLE_SCHED_CLOCK if SMP
 	select LEGACY_TIMER_TICK
 	select CPU_NO_EFFICIENT_FFS
arch/parisc/include/asm/smp.h +2 -7
index 2279ebe5e2da..94d1f21ce99a 100644
@@ -44,12 +44,7 @@ static inline void smp_send_all_nop(void) { return; }
 
 #define NO_PROC_ID		0xFF		/* No processor magic marker */
 #define ANY_PROC_ID		0xFF		/* Any processor magic marker */
-static inline int __cpu_disable (void) {
-  return 0;
-}
-static inline void __cpu_die (unsigned int cpu) {
-  while(1)
-    ;
-}
+int __cpu_disable(void);
+void __cpu_die(unsigned int cpu);
 
 #endif /*  __ASM_SMP_H */
arch/parisc/kernel/smp.c +76 -4

105 lines not on this page · raw message

--
2.35.1

#19 lore raw

Re: [PATCH 12/12] parisc: Implement __cpu_die() and __cpu_disable() for CPU hotplugging

Am Freitag, 25. März 2022, 15:38:33 CET schrieb Helge Deller:

Quoted 18 lines

Add relevant code to __cpu_die() and __cpu_disable() to finally enable the CPU hotplugging features. Reset the irq count values in smp_callin() to zero before bringing up the CPU.

Use "chcpu -d 1" to bring CPU1 down, and "chcpu -e 1" to bring it up.

---
 arch/parisc/Kconfig           |  1 +
 arch/parisc/include/asm/smp.h |  9 +---
 arch/parisc/kernel/smp.c      | 80 +++++++++++++++++++++++++++++++++--
 3 files changed, 79 insertions(+), 11 deletions(-)
arch/parisc/kernel/smp.c +0 -0
index a32a882a2d58..60cc33fd345c 100644

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 433

Quoted 4 lines
arch/parisc/kernel/smp.c +0 -1
@@ -430,10 +444,68 @@ void smp_cpus_done(unsigned int cpu_max)
 
 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
 {
-	if (cpu != 0 && cpu < parisc_max_cpus && smp_boot_one_cpu(cpu, 

tidle))

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max)

Quoted 5 lines
arch/parisc/kernel/smp.c +4 -1
-		return -ENOSYS;
+	if (cpu_online(cpu))
+		return 0;
+
+	if (num_online_cpus() < parisc_max_cpus && smp_boot_one_cpu(cpu, 

tidle))

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 451

Quoted 1 line
arch/parisc/kernel/smp.c +1 -0
+		return -EIO;

I had to look up parisc_max_cpus, and found this:

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 452

Quoted 1 line
arch/parisc/kernel/smp.c +0 -0
 static int parisc_max_cpus = 1;

Hm, signed?

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 455

Quoted 3 lines
arch/parisc/kernel/smp.c +0 -0
 parisc_max_cpus = max_cpus;
       if (!max_cpus)
               printk(KERN_INFO "SMP mode deactivated.\n");

So parisc_max_cpus is now 0, which seems wrong. Shouldn't the check be before the assignment? This would have avoided the "cpu != 0" in the old code completely.

Quoted 19 lines
arch/parisc/kernel/smp.c +19 -0
+
+	return cpu_online(cpu) ? 0 : -EIO;
+}
+
+/*
+ * __cpu_disable runs on the processor to be shutdown.
+ */
+int __cpu_disable(void)
+{
+#ifdef CONFIG_HOTPLUG_CPU
+	unsigned int cpu = smp_processor_id();
+
+	remove_cpu_topology(cpu);
+
+	/*
+	 * Take this CPU offline.  Once we clear this, we can't return,
+	 * and we must not schedule until we're ready to give up the cpu.
+	 */
+	set_cpu_online(cpu, false);

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 480

Quoted 10 lines
arch/parisc/kernel/smp.c +10 -0
+
+	/*
+	 * disable IPI interrupt
+	 */
+	disable_percpu_irq(IPI_IRQ);
+
+	/*
+	 * migrate IRQs away from this CPU
+	 */
+	irq_migrate_all_off_this_cpu();

While I really enjoy good code comments the last 2 seem a t bit wasteful, given that the code is basically exactly the same as the text.

Quoted 33 lines
arch/parisc/kernel/smp.c +26 -2
+	/*
+	 * Flush user cache and TLB mappings, and then remove this CPU
+	 * from the vm mask set of all processes.
+	 *
+	 * Caches are flushed to the Level of Unification Inner Shareable
+	 * to write-back dirty lines to unified caches shared by all CPUs.
+	 */
+	flush_cache_all_local();
+	flush_tlb_all_local(NULL);
 
-	return cpu_online(cpu) ? 0 : -ENOSYS;
+	/* disable all irqs, including timer irq */
+	local_irq_disable();
+#endif
+	return 0;
+}
+
+/*
+ * called on the thread which is asking for a CPU to be shutdown -
+ * waits until shutdown has completed, or it is timed out.
+ */
+void __cpu_die(unsigned int cpu)
+{
+	if (!cpu_wait_death(cpu, 5)) {
+		pr_crit("CPU%u: cpu didn't die\n", cpu);
+		return;
+	}
+	pr_debug("CPU%u: shutdown\n", cpu);
 }
 
 #ifdef CONFIG_PROC_FS
--

2.35.1

author maintainer
#20 lore raw

Re: [PATCH 12/12] parisc: Implement __cpu_die() and __cpu_disable() for CPU hotplugging

Quoted 38 lines · Rolf Eike Beer

Am Freitag, 25. März 2022, 15:38:33 CET schrieb Helge Deller:

Quoted 18 lines

Add relevant code to __cpu_die() and __cpu_disable() to finally enable the CPU hotplugging features. Reset the irq count values in smp_callin() to zero before bringing up the CPU.

Use "chcpu -d 1" to bring CPU1 down, and "chcpu -e 1" to bring it up.

---
 arch/parisc/Kconfig           |  1 +
 arch/parisc/include/asm/smp.h |  9 +---
 arch/parisc/kernel/smp.c      | 80 +++++++++++++++++++++++++++++++++--
 3 files changed, 79 insertions(+), 11 deletions(-)
arch/parisc/kernel/smp.c +0 -0
index a32a882a2d58..60cc33fd345c 100644

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 433

Quoted 4 lines
arch/parisc/kernel/smp.c +0 -1
@@ -430,10 +444,68 @@ void smp_cpus_done(unsigned int cpu_max)
 
 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
 {
-	if (cpu != 0 && cpu < parisc_max_cpus && smp_boot_one_cpu(cpu,

tidle))

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max)

Quoted 5 lines
arch/parisc/kernel/smp.c +4 -1
-		return -ENOSYS;
+	if (cpu_online(cpu))
+		return 0;
+
+	if (num_online_cpus() < parisc_max_cpus && smp_boot_one_cpu(cpu,

tidle))

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 451

Quoted 1 line
arch/parisc/kernel/smp.c +1 -0
+		return -EIO;

I had to look up parisc_max_cpus, and found this:

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 452

Quoted 1 line
arch/parisc/kernel/smp.c +0 -0
 static int parisc_max_cpus = 1;

Hm, signed?

Quoted 7 lines

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 455

Quoted 3 lines
arch/parisc/kernel/smp.c +0 -0
 parisc_max_cpus = max_cpus;
       if (!max_cpus)
               printk(KERN_INFO "SMP mode deactivated.\n");

So parisc_max_cpus is now 0, which seems wrong. Shouldn't the check be before the assignment? This would have avoided the "cpu != 0" in the old code completely.

No, the old

	cpu != 0 && ....smp_boot_one_cpu(cpu, tidle))

was to avoid that smp_boot_one_cpu() gets called for the monarch cpu.

Anyway, you are right, the code could need cleanups.
But in my patch series I wanted to keep the changes minimal in the first place.

Quoted 25 lines
Quoted 25 lines
arch/parisc/kernel/smp.c +24 -0
+
+	return cpu_online(cpu) ? 0 : -EIO;
+}
+
+/*
+ * __cpu_disable runs on the processor to be shutdown.
+ */
+int __cpu_disable(void)
+{
+#ifdef CONFIG_HOTPLUG_CPU
+	unsigned int cpu = smp_processor_id();
+
+	remove_cpu_topology(cpu);
+
+	/*
+	 * Take this CPU offline.  Once we clear this, we can't return,
+	 * and we must not schedule until we're ready to give up the cpu.
+	 */
+	set_cpu_online(cpu, false);
+
+	/*
+	 * disable IPI interrupt
+	 */
+	disable_percpu_irq(IPI_IRQ);
Quoted 8 lines

arch/parisc/kernel/smp.c void smp_cpus_done(unsigned int cpu_max) · line 480

Quoted 5 lines
arch/parisc/kernel/smp.c +5 -0
+
+	/*
+	 * migrate IRQs away from this CPU
+	 */
+	irq_migrate_all_off_this_cpu();

While I really enjoy good code comments the last 2 seem a t bit wasteful, given that the code is basically exactly the same as the text.

Yep.

Helge

author maintainer
#21 lore raw
In reply to Helge Deller
Quoted 2 lines · Helge Deller

Switch away from the own cpu topology code to common code which is used by ARM64 and RISCV. That allows us to enable hotplug later on too.

With this series I was able to use CPU hotplugging on the PA-RISC machines. I sucessfully tested it on qemu (32bit kernel) and on a 2-way C8000 (64bit kernel).

For qemu the patch I committed today is required:
https://github.com/hdeller/seabios-hppa/commit/5cec13f11d3917cf3bceaf68ce23e9fa5f206a35

There is still some issue with the irq balancing on qemu with the emulated GSC, e.g. in this example with 3 CPUs you can only disable CPU0 or CPU2, which both don't use any IRQs. During shutdown of CPU1 the irqs 17-20 needs to be moved to another CPU which doesn't work reliable yet.

Example:

root@debian:~# cat /proc/interrupts
           CPU0       CPU1       CPU2
 17:          0          0          0        GSC-ASIC  parport0
 18:          0       1759          0         GSC-PCI  ttyS0
 19:          0       3572          0         GSC-PCI  sym53c8xx
 20:          0       2359          0         GSC-PCI  enp0s1
 64:        224     148358     128518             CPU  timer
 65:         16       4224        677             CPU  IPI
 66:          0          0          0             CPU  lasi
 67:          0       8758          0             CPU  Dino
STK:       2240       6080       3072   Kernel stack usage
root@debian:~# chcpu -d 2	# disables CPU2
CPU 2 disabled
root@debian:~# cat /proc/interrupts
           CPU0       CPU1
 17:          0          0        GSC-ASIC  parport0
 18:          0       1843         GSC-PCI  ttyS0
 19:          0       3662         GSC-PCI  sym53c8xx
 20:...
root@debian:~# chcpu -e 2	# enable CPU2
[    6.466714] Releasing cpu 2 now, hpa=fffb2000
CPU 2 enabled
root@debian:~# cat /proc/interrupts
           CPU0       CPU1       CPU2
 17:          0          0          0        GSC-ASIC  parport0
 18:          0       1915          0         GSC-PCI  ttyS0
 19:          0       3668          0         GSC-PCI  sym53c8xx
...

CPU hotplugging on the C8000 seems to work reliable.

Helge

#22 lore raw
In reply to Helge Deller

Am Freitag, 25. März 2022, 15:38:22 CET schrieb Helge Deller:

Quoted 8 lines

Switch away from the own cpu topology code to common code which is used by ARM64 and RISCV. That allows us to enable hotplug later on too.

arch/parisc/kernel/topology.c +0 -0
index e88a6ce7c96d..72d9aeb54fbe 100644

arch/parisc/kernel/topology.c void __init store_cpu_topology(unsigned int cpuid) · line 45

Quoted 9 lines
arch/parisc/kernel/topology.c +6 -0
@@ -71,6 +37,12 @@ void __init store_cpu_topology(unsigned int cpuid)
 	if (cpuid_topo->core_id != -1)
 		return;
 
+#ifdef CONFIG_HOTPLUG_CPU
+	per_cpu(cpu_devices, cpuid).hotpluggable = 1;
+#endif
+	if (register_cpu(&per_cpu(cpu_devices, cpuid), cpuid))
+		printk("Failed to register CPU device");
+

This seems to be missing a level, and I think also printing the id of the failing CPU wouldn't hurt either.