Patchwork [2/2] do proper cpu_self check

login
register
mail settings
Submitter Glauber Costa
Date Sept. 28, 2009, 6:27 p.m.
Message ID <1254162464-20089-3-git-send-email-glommer@redhat.com>
Download mbox | patch
Permalink /patch/34385/
State Superseded
Headers show

Comments

Glauber Costa - Sept. 28, 2009, 6:27 p.m.
From: Glauber Costa <glommer@mothafucka.localdomain>

Currently, our check for qemu_cpu_self only checks if there is a cpu
currently in execution (represented by cpu_single_env being set). While
this might be okay for tcg, it is certainly not okay for kvm, since multiple
cpus might be executing.

Instead, I propose we use pthread primitives to test if the caller thread is
the same as env->thread.

For tcg, it will have the same semantics as before, since all CPUStates will
point to the same thread, and we'll only have one in execution at a time.

Signed-off-by: Glauber Costa <glommer@mothafucka.localdomain>
---
 vl.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
malc - Sept. 28, 2009, 6:58 p.m.
On Mon, 28 Sep 2009, Glauber Costa wrote:

> From: Glauber Costa <glommer@mothafucka.localdomain>
> 
> Currently, our check for qemu_cpu_self only checks if there is a cpu
> currently in execution (represented by cpu_single_env being set). While
> this might be okay for tcg, it is certainly not okay for kvm, since multiple
> cpus might be executing.
> 
> Instead, I propose we use pthread primitives to test if the caller thread is
> the same as env->thread.
> 
> For tcg, it will have the same semantics as before, since all CPUStates will
> point to the same thread, and we'll only have one in execution at a time.
> 
> Signed-off-by: Glauber Costa <glommer@mothafucka.localdomain>

Nice signoff

[..snip..]

Patch

diff --git a/vl.c b/vl.c
index f24a260..9448190 100644
--- a/vl.c
+++ b/vl.c
@@ -3582,9 +3582,14 @@  void qemu_cpu_kick(void *_env)
         qemu_thread_signal(env->thread, SIGUSR1);
 }
 
-int qemu_cpu_self(void *env)
+int qemu_cpu_self(void *_env)
 {
-    return (cpu_single_env != NULL);
+    CPUState *env = _env;
+    QemuThread this;
+ 
+    qemu_thread_self(&this);
+ 
+    return qemu_thread_equal(&this, env->thread);
 }
 
 static void cpu_signal(int sig)