Patchwork [v2,3/3] Make cpu_single_env thread-local

login
register
mail settings
Submitter Peter Maydell
Date Oct. 27, 2011, 11:37 a.m.
Message ID <1319715472-16286-4-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/122117/
State New
Headers show

Comments

Peter Maydell - Oct. 27, 2011, 11:37 a.m.
From: Paolo Bonzini <pbonzini@redhat.com>

Make cpu_single_env thread-local. This fixes a regression
in handling of multi-threaded programs in linux-user mode
(bug 823902).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[Peter Maydell: rename tls_cpu_single_env to cpu_single_env]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 cpu-all.h |    4 +++-
 exec.c    |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
Andreas Färber - Oct. 27, 2011, 3:10 p.m.
Am 27.10.2011 13:37, schrieb Peter Maydell:
> From: Paolo Bonzini <pbonzini@redhat.com>
> 
> Make cpu_single_env thread-local. This fixes a regression
> in handling of multi-threaded programs in linux-user mode
> (bug 823902).
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> [Peter Maydell: rename tls_cpu_single_env to cpu_single_env]
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  cpu-all.h |    4 +++-
>  exec.c    |    2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/cpu-all.h b/cpu-all.h
> index 42a5fa0..5f47ab8 100644
> --- a/cpu-all.h
> +++ b/cpu-all.h
> @@ -20,6 +20,7 @@
>  #define CPU_ALL_H
>  
>  #include "qemu-common.h"
> +#include "qemu-tls.h"
>  #include "cpu-common.h"
>  
>  /* some important defines:
[8<]

Is there a reason not to include this from qemu-common.h? To avoid
accidental use in unsuited cases? If so, add an explicit comment to
either qemu-common.h or Jan's comment in qemu-tls.h to avoid someone
doing such a cleanup/simplification patch?

Andreas
Paolo Bonzini - Oct. 27, 2011, 3:12 p.m.
On 10/27/2011 05:10 PM, Andreas Färber wrote:
> Am 27.10.2011 13:37, schrieb Peter Maydell:
>> From: Paolo Bonzini<pbonzini@redhat.com>
>>
>> Make cpu_single_env thread-local. This fixes a regression
>> in handling of multi-threaded programs in linux-user mode
>> (bug 823902).
>>
>> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
>> [Peter Maydell: rename tls_cpu_single_env to cpu_single_env]
>> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
>> ---
>>   cpu-all.h |    4 +++-
>>   exec.c    |    2 +-
>>   2 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/cpu-all.h b/cpu-all.h
>> index 42a5fa0..5f47ab8 100644
>> --- a/cpu-all.h
>> +++ b/cpu-all.h
>> @@ -20,6 +20,7 @@
>>   #define CPU_ALL_H
>>
>>   #include "qemu-common.h"
>> +#include "qemu-tls.h"
>>   #include "cpu-common.h"
>>
>>   /* some important defines:
> [8<]
>
> Is there a reason not to include this from qemu-common.h? To avoid
> accidental use in unsuited cases? If so, add an explicit comment to
> either qemu-common.h or Jan's comment in qemu-tls.h to avoid someone
> doing such a cleanup/simplification patch?

I think we're evolving towards having qemu-common.h as a common place 
for system header inclusions, but not really for QEMU-specific headers.

Paolo
Andreas Färber - Oct. 27, 2011, 4:20 p.m.
Am 27.10.2011 17:10, schrieb Andreas Färber:
> Am 27.10.2011 13:37, schrieb Peter Maydell:
>> From: Paolo Bonzini <pbonzini@redhat.com>
>>
>> Make cpu_single_env thread-local. This fixes a regression
>> in handling of multi-threaded programs in linux-user mode
>> (bug 823902).
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> [Peter Maydell: rename tls_cpu_single_env to cpu_single_env]
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Andreas Färber <afaerber@suse.de>

Patch

diff --git a/cpu-all.h b/cpu-all.h
index 42a5fa0..5f47ab8 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -20,6 +20,7 @@ 
 #define CPU_ALL_H
 
 #include "qemu-common.h"
+#include "qemu-tls.h"
 #include "cpu-common.h"
 
 /* some important defines:
@@ -334,7 +335,8 @@  void cpu_dump_statistics(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
 void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 extern CPUState *first_cpu;
-extern CPUState *cpu_single_env;
+DECLARE_TLS(CPUState *,cpu_single_env);
+#define cpu_single_env get_tls(cpu_single_env)
 
 /* Flags for use in ENV->INTERRUPT_PENDING.
 
diff --git a/exec.c b/exec.c
index 9dc4edb..18e26cb 100644
--- a/exec.c
+++ b/exec.c
@@ -120,7 +120,7 @@  static MemoryRegion *system_io;
 CPUState *first_cpu;
 /* current CPU in the current thread. It is only valid inside
    cpu_exec() */
-CPUState *cpu_single_env;
+DEFINE_TLS(CPUState *,cpu_single_env);
 /* 0 = Do not count executed instructions.
    1 = Precise instruction counting.
    2 = Adaptive rate instruction counting.  */