kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com
Subject: [PATCH kvm-unit-tests 1/3] arm/arm64: smp: rename secondary_halt to do_idle
Date: Thu,  1 Jun 2017 15:50:00 +0200	[thread overview]
Message-ID: <20170601135002.26704-2-drjones@redhat.com> (raw)
In-Reply-To: <20170601135002.26704-1-drjones@redhat.com>

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

  reply	other threads:[~2017-06-01 13:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170601135002.26704-2-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).