diff mbox series

[v1,3/8] hw/core/cpu-sysemu: used cached class in cpu_asidx_from_attrs

Message ID 20220811151413.3350684-4-alex.bennee@linaro.org
State Superseded
Headers show
Series memory leaks and speed tweaks | expand

Commit Message

Alex Bennée Aug. 11, 2022, 3:14 p.m. UTC
This is a heavily used function so lets avoid the cost of
CPU_GET_CLASS. On the romulus-bmc run it has a modest effect:

  Before: 36.812 s ±  0.506 s
  After:  35.912 s ±  0.168 s

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 hw/core/cpu-sysemu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Richard Henderson Aug. 11, 2022, 5:17 p.m. UTC | #1
On 8/11/22 08:14, Alex Bennée wrote:
> This is a heavily used function so lets avoid the cost of
> CPU_GET_CLASS. On the romulus-bmc run it has a modest effect:
> 
>    Before: 36.812 s ±  0.506 s
>    After:  35.912 s ±  0.168 s
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   hw/core/cpu-sysemu.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
> index 00253f8929..5eaf2e79e6 100644
> --- a/hw/core/cpu-sysemu.c
> +++ b/hw/core/cpu-sysemu.c
> @@ -69,11 +69,10 @@ hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
>   
>   int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
>   {
> -    CPUClass *cc = CPU_GET_CLASS(cpu);
>       int ret = 0;
>   
> -    if (cc->sysemu_ops->asidx_from_attrs) {
> -        ret = cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
> +    if (cpu->cc->sysemu_ops->asidx_from_attrs) {
> +        ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
>           assert(ret < cpu->num_ases && ret >= 0);
>       }
>       return ret;

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

r~
Philippe Mathieu-Daudé Aug. 11, 2022, 11:37 p.m. UTC | #2
On 11/8/22 17:14, Alex Bennée wrote:
> This is a heavily used function so lets avoid the cost of
> CPU_GET_CLASS. On the romulus-bmc run it has a modest effect:
> 
>    Before: 36.812 s ±  0.506 s
>    After:  35.912 s ±  0.168 s
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   hw/core/cpu-sysemu.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
index 00253f8929..5eaf2e79e6 100644
--- a/hw/core/cpu-sysemu.c
+++ b/hw/core/cpu-sysemu.c
@@ -69,11 +69,10 @@  hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 
 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
 {
-    CPUClass *cc = CPU_GET_CLASS(cpu);
     int ret = 0;
 
-    if (cc->sysemu_ops->asidx_from_attrs) {
-        ret = cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
+    if (cpu->cc->sysemu_ops->asidx_from_attrs) {
+        ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
         assert(ret < cpu->num_ases && ret >= 0);
     }
     return ret;