All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 0/3] arm/arm64: introduce on_cpu[_async]
@ 2017-06-01 13:49 Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle Andrew Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Jones @ 2017-06-01 13:49 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar

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(-)

-- 
2.9.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle
  2017-06-01 13:49 [PATCH kvm-unit-tests 0/3] arm/arm64: introduce on_cpu[_async] Andrew Jones
@ 2017-06-01 13:50 ` Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 2/3] arm/arm64: smp: introduce on_cpu and on_cpu_async Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 3/3] arm/arm64: rename smp_run to on_cpus Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2017-06-01 13:50 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar

Also prepare the newly renamed function to come out of idle
and use sev/wfe rather than a busy wait in smp_run().

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 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(-)

diff --git a/arm/cstart.S b/arm/cstart.S
index b3176b274933..86d879ec7b35 100644
--- a/arm/cstart.S
+++ b/arm/cstart.S
@@ -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:
diff --git a/arm/cstart64.S b/arm/cstart64.S
index 30f732f1e99b..0445e133bb62 100644
--- a/arm/cstart64.S
+++ b/arm/cstart64.S
@@ -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:
diff --git a/lib/arm/asm/smp.h b/lib/arm/asm/smp.h
index a3551a40e4c5..a352d76e710d 100644
--- a/lib/arm/asm/smp.h
+++ b/lib/arm/asm/smp.h
@@ -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));
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index fe64ed410377..3f8457cbf3a1 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -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);
 }
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH kvm-unit-tests 2/3] arm/arm64: smp: introduce on_cpu and on_cpu_async
  2017-06-01 13:49 [PATCH kvm-unit-tests 0/3] arm/arm64: introduce on_cpu[_async] Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle Andrew Jones
@ 2017-06-01 13:50 ` Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 3/3] arm/arm64: rename smp_run to on_cpus Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2017-06-01 13:50 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar

x86 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.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/smp.h |  2 ++
 lib/arm/smp.c     | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/lib/arm/asm/smp.h b/lib/arm/asm/smp.h
index a352d76e710d..ca088d654516 100644
--- a/lib/arm/asm/smp.h
+++ b/lib/arm/asm/smp.h
@@ -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_ */
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index 3f8457cbf3a1..f3542b8bad99 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -48,14 +48,10 @@ secondary_entry_fn secondary_cinit(void)
 	return entry;
 }
 
-void smp_boot_secondary(int cpu, secondary_entry_fn entry)
+static void __smp_boot_secondary(int cpu, secondary_entry_fn entry)
 {
 	int ret;
 
-	spin_lock(&lock);
-
-	assert_msg(!cpu_online(cpu), "CPU%d already boot once", cpu);
-
 	secondary_data.stack = thread_stack_alloc();
 	secondary_data.entry = entry;
 	mmu_mark_disabled(cpu);
@@ -64,10 +60,23 @@ void smp_boot_secondary(int cpu, secondary_entry_fn entry)
 
 	while (!cpu_online(cpu))
 		wfe();
+}
 
+void smp_boot_secondary(int cpu, secondary_entry_fn entry)
+{
+	spin_lock(&lock);
+	assert_msg(!cpu_online(cpu), "CPU%d already boot once", cpu);
+	__smp_boot_secondary(cpu, entry);
 	spin_unlock(&lock);
 }
 
+typedef void (*on_cpu_func)(void *);
+struct on_cpu_info {
+	on_cpu_func func;
+	void *data;
+};
+static struct on_cpu_info on_cpu_info[NR_CPUS];
+
 void do_idle(void)
 {
 	int cpu = smp_processor_id();
@@ -78,11 +87,50 @@ void do_idle(void)
 	for (;;) {
 		while (cpu_idle(cpu))
 			wfe();
+		smp_rmb();
+		on_cpu_info[cpu].func(on_cpu_info[cpu].data);
+		on_cpu_info[cpu].func = NULL;
+		smp_wmb();
 		set_cpu_idle(cpu, true);
 		sev();
 	}
 }
 
+void on_cpu_async(int cpu, void (*func)(void *data), void *data)
+{
+	if (cpu == smp_processor_id()) {
+		func(data);
+		return;
+	}
+
+	spin_lock(&lock);
+	if (!cpu_online(cpu))
+		__smp_boot_secondary(cpu, do_idle);
+	spin_unlock(&lock);
+
+	for (;;) {
+		while (!cpu_idle(cpu))
+			wfe();
+		spin_lock(&lock);
+		if ((volatile void *)on_cpu_info[cpu].func == NULL)
+			break;
+		spin_unlock(&lock);
+	}
+	on_cpu_info[cpu].func = func;
+	on_cpu_info[cpu].data = data;
+	spin_unlock(&lock);
+	set_cpu_idle(cpu, false);
+	sev();
+}
+
+void on_cpu(int cpu, void (*func)(void *data), void *data)
+{
+	on_cpu_async(cpu, func, data);
+
+	while (!cpu_idle(cpu))
+		wfe();
+}
+
 void smp_run(void (*func)(void))
 {
 	int cpu;
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH kvm-unit-tests 3/3] arm/arm64: rename smp_run to on_cpus
  2017-06-01 13:49 [PATCH kvm-unit-tests 0/3] arm/arm64: introduce on_cpu[_async] Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle Andrew Jones
  2017-06-01 13:50 ` [PATCH kvm-unit-tests 2/3] arm/arm64: smp: introduce on_cpu and on_cpu_async Andrew Jones
@ 2017-06-01 13:50 ` Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2017-06-01 13:50 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar

Also base on on_cpu_async() to allow it to be called more than once.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 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(-)

diff --git a/arm/gic.c b/arm/gic.c
index 4cdb77b1fdda..2c5832100e0e 100644
--- a/arm/gic.c
+++ b/arm/gic.c
@@ -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 {
diff --git a/arm/selftest.c b/arm/selftest.c
index dd750c418644..1ad2e7120248 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -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");
diff --git a/arm/spinlock-test.c b/arm/spinlock-test.c
index d1e45d2d9b05..cd03f81c5fae 100644
--- a/arm/spinlock-test.c
+++ b/arm/spinlock-test.c
@@ -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();
 }
diff --git a/lib/arm/asm/smp.h b/lib/arm/asm/smp.h
index ca088d654516..4272e0fd9253 100644
--- a/lib/arm/asm/smp.h
+++ b/lib/arm/asm/smp.h
@@ -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_ */
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index f3542b8bad99..7e3c91ce3b48 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -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();
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-01 13:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-01 13:49 [PATCH kvm-unit-tests 0/3] arm/arm64: introduce on_cpu[_async] Andrew Jones
2017-06-01 13:50 ` [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle Andrew Jones
2017-06-01 13:50 ` [PATCH kvm-unit-tests 2/3] arm/arm64: smp: introduce on_cpu and on_cpu_async Andrew Jones
2017-06-01 13:50 ` [PATCH kvm-unit-tests 3/3] arm/arm64: rename smp_run to on_cpus Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.