[PATCH v3 29/29] user: Prefer fast cpu_env() over slower CPU QOM cast macro

Philippe Mathieu-Daudé posted 29 patches 10 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony Perard <anthony.perard@citrix.com>, Paul Durrant <paul@xen.org>, Peter Maydell <peter.maydell@linaro.org>, Song Gao <gaosong@loongson.cn>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Cédric Le Goater" <clg@kaod.org>, Nicholas Piggin <npiggin@gmail.com>, "Frédéric Barrat" <fbarrat@linux.ibm.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, "Alex Bennée" <alex.bennee@linaro.org>, Viresh Kumar <viresh.kumar@linaro.org>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Alexander Graf <agraf@csgraf.de>, Michael Rolnik <mrolnik@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Brian Cain <bcain@quicinc.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Marcelo Tosatti <mtosatti@redhat.com>, David Woodhouse <dwmw2@infradead.org>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Huacai Chen <chenhuacai@kernel.org>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Stafford Horne <shorne@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liwei1518@gmail.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
[PATCH v3 29/29] user: Prefer fast cpu_env() over slower CPU QOM cast macro
Posted by Philippe Mathieu-Daudé 10 months ago
Mechanical patch produced running the command documented
in scripts/coccinelle/cpu_env.cocci_template header.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 bsd-user/signal.c   | 3 +--
 linux-user/signal.c | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index ca31470772..c6f0b1be38 100644
--- a/bsd-user/signal.c
+++ b/bsd-user/signal.c
@@ -463,14 +463,13 @@ static int fatal_signal(int sig)
 void force_sig_fault(int sig, int code, abi_ulong addr)
 {
     CPUState *cpu = thread_cpu;
-    CPUArchState *env = cpu_env(cpu);
     target_siginfo_t info = {};
 
     info.si_signo = sig;
     info.si_errno = 0;
     info.si_code = code;
     info.si_addr = addr;
-    queue_signal(env, sig, QEMU_SI_FAULT, &info);
+    queue_signal(cpu_env(cpu), sig, QEMU_SI_FAULT, &info);
 }
 
 static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
diff --git a/linux-user/signal.c b/linux-user/signal.c
index c9527adfa3..f78f7fc476 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -623,7 +623,6 @@ void signal_init(void)
 void force_sig(int sig)
 {
     CPUState *cpu = thread_cpu;
-    CPUArchState *env = cpu_env(cpu);
     target_siginfo_t info = {};
 
     info.si_signo = sig;
@@ -631,7 +630,7 @@ void force_sig(int sig)
     info.si_code = TARGET_SI_KERNEL;
     info._sifields._kill._pid = 0;
     info._sifields._kill._uid = 0;
-    queue_signal(env, info.si_signo, QEMU_SI_KILL, &info);
+    queue_signal(cpu_env(cpu), info.si_signo, QEMU_SI_KILL, &info);
 }
 
 /*
@@ -641,14 +640,13 @@ void force_sig(int sig)
 void force_sig_fault(int sig, int code, abi_ulong addr)
 {
     CPUState *cpu = thread_cpu;
-    CPUArchState *env = cpu_env(cpu);
     target_siginfo_t info = {};
 
     info.si_signo = sig;
     info.si_errno = 0;
     info.si_code = code;
     info._sifields._sigfault._addr = addr;
-    queue_signal(env, sig, QEMU_SI_FAULT, &info);
+    queue_signal(cpu_env(cpu), sig, QEMU_SI_FAULT, &info);
 }
 
 /* Force a SIGSEGV if we couldn't write to memory trying to set
-- 
2.41.0


Re: [PATCH v3 29/29] user: Prefer fast cpu_env() over slower CPU QOM cast macro
Posted by Warner Losh 9 months, 3 weeks ago
[[ I dont know if it's too late ]]

On Mon, Jan 29, 2024 at 9:48 AM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Mechanical patch produced running the command documented
> in scripts/coccinelle/cpu_env.cocci_template header.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  bsd-user/signal.c   | 3 +--
>  linux-user/signal.c | 6 ++----
>  2 files changed, 3 insertions(+), 6 deletions(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>


> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index ca31470772..c6f0b1be38 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -463,14 +463,13 @@ static int fatal_signal(int sig)
>  void force_sig_fault(int sig, int code, abi_ulong addr)
>  {
>      CPUState *cpu = thread_cpu;
> -    CPUArchState *env = cpu_env(cpu);
>      target_siginfo_t info = {};
>
>      info.si_signo = sig;
>      info.si_errno = 0;
>      info.si_code = code;
>      info.si_addr = addr;
> -    queue_signal(env, sig, QEMU_SI_FAULT, &info);
> +    queue_signal(cpu_env(cpu), sig, QEMU_SI_FAULT, &info);
>  }
>
>  static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index c9527adfa3..f78f7fc476 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -623,7 +623,6 @@ void signal_init(void)
>  void force_sig(int sig)
>  {
>      CPUState *cpu = thread_cpu;
> -    CPUArchState *env = cpu_env(cpu);
>      target_siginfo_t info = {};
>
>      info.si_signo = sig;
> @@ -631,7 +630,7 @@ void force_sig(int sig)
>      info.si_code = TARGET_SI_KERNEL;
>      info._sifields._kill._pid = 0;
>      info._sifields._kill._uid = 0;
> -    queue_signal(env, info.si_signo, QEMU_SI_KILL, &info);
> +    queue_signal(cpu_env(cpu), info.si_signo, QEMU_SI_KILL, &info);
>  }
>
>  /*
> @@ -641,14 +640,13 @@ void force_sig(int sig)
>  void force_sig_fault(int sig, int code, abi_ulong addr)
>  {
>      CPUState *cpu = thread_cpu;
> -    CPUArchState *env = cpu_env(cpu);
>      target_siginfo_t info = {};
>
>      info.si_signo = sig;
>      info.si_errno = 0;
>      info.si_code = code;
>      info._sifields._sigfault._addr = addr;
> -    queue_signal(env, sig, QEMU_SI_FAULT, &info);
> +    queue_signal(cpu_env(cpu), sig, QEMU_SI_FAULT, &info);
>  }
>
>  /* Force a SIGSEGV if we couldn't write to memory trying to set
> --
> 2.41.0
>
>
Re: [PATCH v3 29/29] user: Prefer fast cpu_env() over slower CPU QOM cast macro
Posted by Richard Henderson 10 months ago
On 1/30/24 02:45, Philippe Mathieu-Daudé wrote:
> Mechanical patch produced running the command documented
> in scripts/coccinelle/cpu_env.cocci_template header.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   bsd-user/signal.c   | 3 +--
>   linux-user/signal.c | 6 ++----
>   2 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index ca31470772..c6f0b1be38 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -463,14 +463,13 @@ static int fatal_signal(int sig)
>   void force_sig_fault(int sig, int code, abi_ulong addr)
>   {
>       CPUState *cpu = thread_cpu;
> -    CPUArchState *env = cpu_env(cpu);
>       target_siginfo_t info = {};
>   
>       info.si_signo = sig;
>       info.si_errno = 0;
>       info.si_code = code;
>       info.si_addr = addr;
> -    queue_signal(env, sig, QEMU_SI_FAULT, &info);
> +    queue_signal(cpu_env(cpu), sig, QEMU_SI_FAULT, &info);

Might as well propagate thread_cpu here, and remove local cpu variable.

> @@ -631,7 +630,7 @@ void force_sig(int sig)
>       info.si_code = TARGET_SI_KERNEL;
>       info._sifields._kill._pid = 0;
>       info._sifields._kill._uid = 0;
> -    queue_signal(env, info.si_signo, QEMU_SI_KILL, &info);
> +    queue_signal(cpu_env(cpu), info.si_signo, QEMU_SI_KILL, &info);

More instances?

Either way,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~