arm/arm64: introduce on_cpu[_async]
cover arm/arm64: introduce on_cpu[_async]
and smp_run becomes on_cpus, which can be run more than once.
Andrew Jones (3):
arm/arm64: smp: rename secondary_halt to do_idle arm/arm64: smp: introduce on_cpu and on_cpu_async arm/arm64: rename smp_run to on_cpus
arm/cstart.S | 2 +- arm/cstart64.S | 2 +- arm/gic.c | 2 +- arm/selftest.c | 2 +- arm/spinlock-test.c | 2 +- lib/arm/asm/smp.h | 16 ++++++++-- lib/arm/smp.c | 87 +++++++++++++++++++++++++++++++++++++++++++---------- 7 files changed, 90 insertions(+), 23 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/3 arm/arm64: smp: rename secondary_halt to do_idle
Also prepare the newly renamed function to come out of idle and use sev/wfe rather than a busy wait in smp_run().
--- arm/cstart.S | 2 +- arm/cstart64.S | 2 +- lib/arm/asm/smp.h | 12 +++++++++++- lib/arm/smp.c | 25 ++++++++++++++++--------- 4 files changed, 29 insertions(+), 12 deletions(-)
arm/cstart.S +1 -1
@@ -119,7 +119,7 @@ secondary_entry: /* r0 is now the entry function, run it */ blx r0 - b secondary_halt + b do_idle .globl halt halt:
arm/cstart64.S +1 -1
@@ -80,7 +80,7 @@ secondary_entry: /* x0 is now the entry function, run it */ blr x0 - b secondary_halt + b do_idle .globl halt halt:
lib/arm/asm/smp.h +11 -1
@@ -11,12 +11,14 @@#define smp_processor_id () (current_thread_info()->cpu)extern void halt (void ); +extern void do_idle (void );extern cpumask_t cpu_present_mask;extern cpumask_t cpu_online_mask; -extern cpumask_t cpu_halted_mask; +extern cpumask_t cpu_idle_mask;#define cpu_present (cpu) cpumask_test_cpu(cpu, &cpu_present_mask)#define cpu_online (cpu) cpumask_test_cpu(cpu, &cpu_online_mask) +#define cpu_idle (cpu) cpumask_test_cpu(cpu, &cpu_idle_mask)#define for_each_present_cpu (cpu) for_each_cpu(cpu, &cpu_present_mask)#define for_each_online_cpu (cpu) for_each_cpu(cpu, &cpu_online_mask)
@@ -36,6 +38,14 @@ static inline void set_cpu_online(int cpu, bool online)cpumask_clear_cpu (cpu, &cpu_online_mask); } +static inline void set_cpu_idle (int cpu,bool idle) +{ +if (idle) +cpumask_set_cpu (cpu, &cpu_idle_mask); +else +cpumask_clear_cpu (cpu, &cpu_idle_mask); +} +typedef void (*secondary_entry_fn )(void );extern void smp_boot_secondary (int cpu,secondary_entry_fn entry);extern void smp_run (void (*func)(void ));
lib/arm/smp.c +16 -9
@@ -16,7 +16,7 @@cpumask_t cpu_present_mask;cpumask_t cpu_online_mask; -cpumask_t cpu_halted_mask; +cpumask_t cpu_idle_mask;struct secondary_data {void *stack;/* must be first member of struct */
@@ -68,12 +68,19 @@ void smp_boot_secondary(int cpu, secondary_entry_fn entry)spin_unlock (&lock); } -void secondary_halt (void ) +void do_idle (void ) { -struct thread_info *ti =current_thread_info (); +int cpu =smp_processor_id (); + +set_cpu_idle (cpu, true); +sev (); -cpumask_set_cpu (ti->cpu, &cpu_halted_mask); -halt (); +for (;;) { +while (cpu_idle (cpu)) +wfe (); +set_cpu_idle (cpu, true); +sev (); + } }void smp_run (void (*func)(void ))
@@ -87,8 +94,8 @@ void smp_run(void (*func)(void)) }func (); -cpumask_set_cpu (0 , &cpu_halted_mask); -while (!cpumask_full (&cpu_halted_mask)) -cpu_relax (); -cpumask_clear_cpu (0 , &cpu_halted_mask); +set_cpu_idle (0 , true); +while (!cpumask_full (&cpu_idle_mask)) +wfe (); +set_cpu_idle (0 , false); }
Signature · 1 line
2.9.4
PATCH 2/3 arm/arm64: smp: introduce on_cpu and on_cpu_async
In reply to Andrew Jonesx86 has two smp functions on_cpu() and on_cpu_async(). These are nice because we can run them more than once on cpus. This patch adds the same API to ARM, but the target cpu requirements are not the same. While on x86 the interrupt controller must be enabled enough to send/receive IPIs and the target cpu must have interrupts enabled (or be expected to enable them), on ARM we do not use IPIs, so the GIC does not need to be enabled and cpus do not need to register irq handlers nor enable interrupts. Instead, target cpus are expected to be powered off or idle. The advantage of the ARM approach is the lack of interrupt handling dependencies. The disadvantage is the lack of preemption - even on_cpu_async() must wait for the target cpu to be idle first.
--- lib/arm/asm/smp.h | 2 ++ lib/arm/smp.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)
lib/arm/asm/smp.h +2 -0
@@ -48,6 +48,8 @@ static inline void set_cpu_idle(int cpu, bool idle)typedef void (*secondary_entry_fn )(void );extern void smp_boot_secondary (int cpu,secondary_entry_fn entry); +extern void on_cpu_async (int cpu,void (*func)(void *data),void *data); +extern void on_cpu (int cpu,void (*func)(void *data),void *data);extern void smp_run (void (*func)(void ));#endif /* _ASMARM_SMP_H_ */
lib/arm/smp.c +53 -5
88 lines not on this page · raw message
Signature · 1 line
2.9.4
PATCH 3/3 arm/arm64: rename smp_run to on_cpus
In reply to Andrew JonesAlso base on on_cpu_async() to allow it to be called more than once.
--- arm/gic.c | 2 +- arm/selftest.c | 2 +- arm/spinlock-test.c | 2 +- lib/arm/asm/smp.h | 2 +- lib/arm/smp.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-)
arm/gic.c +1 -1
@@ -327,7 +327,7 @@ int main(int argc, char **argv)if (strcmp (argv[1 ],"ipi" ) ==0 ) {report_prefix_push (argv[1 ]);nr_cpu_check (2 ); -smp_run (ipi_test); +on_cpus (ipi_test); }else if (strcmp (argv[1 ],"active" ) ==0 ) {run_active_clear_test (); }else {
arm/selftest.c +1 -1
@@ -342,7 +342,7 @@ int main(int argc, char **argv) }else if (strcmp (argv[1 ],"smp" ) ==0 ) {report ("PSCI version" ,psci_check ()); -smp_run (cpu_report); +on_cpus (cpu_report); }else {printf ("Unknown subtest\n" );
arm/spinlock-test.c +1 -1
@@ -80,7 +80,7 @@ int main(int argc, char **argv) lock_ops.unlock = none_unlock; } -smp_run (test_spinlock); +on_cpus (test_spinlock);return report_summary (); }
lib/arm/asm/smp.h +1 -1
@@ -50,6 +50,6 @@ typedef void (*secondary_entry_fn)(void);extern void smp_boot_secondary (int cpu,secondary_entry_fn entry);extern void on_cpu_async (int cpu,void (*func)(void *data),void *data);extern void on_cpu (int cpu,void (*func)(void *data),void *data); -extern void smp_run (void (*func)(void )); +extern void on_cpus (void (*func)(void ));#endif /* _ASMARM_SMP_H_ */
lib/arm/smp.c +2 -2
@@ -131,14 +131,14 @@ void on_cpu(int cpu, void (*func)(void *data), void *data)wfe (); } -void smp_run (void (*func)(void )) +void on_cpus (void (*func)(void )) {int cpu;for_each_present_cpu (cpu) {if (cpu ==0 )continue ; -smp_boot_secondary (cpu, func); +on_cpu_async (cpu, (on_cpu_func )func,NULL ); }func ();
Signature · 1 line
2.9.4