Skip to contentSkip to conversation

target/riscv: Use env_archcpu for better performance

PATCH Superseded Richard W.M. Jones 4 participants 6 messages Oct 9, 2023 – Oct 11, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 target/riscv: Use env_archcpu for better performance

In v3:

- Use env_archcpu

- Rerun the benchmark to get new "after" figures

Rich.

#1 lore raw

PATCH v3 1/1 target/riscv: Use env_archcpu for better performance

RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled this adds about 5% total overhead when emulating RV64 on x86-64 host.

Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk disk. The guest has a copy of the qemu source tree. The test involves compiling the qemu source tree with 'make clean; time make -j16'.

Before making this change the compile step took 449 & 447 seconds over two consecutive runs.

After making this change: 428 & 421 seconds.

The saving is over 5%.

Thanks: Paolo Bonzini
Thanks: Philippe Mathieu-Daudé

---
 target/riscv/cpu_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/cpu_helper.c +1 -2
index 3a02079290..8c28241c18 100644
@@ -65,8 +65,7 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
                           uint64_t *cs_base, uint32_t *pflags)
 {
-    CPUState *cs = env_cpu(env);
-    RISCVCPU *cpu = RISCV_CPU(cs);
+    RISCVCPU *cpu = env_archcpu(env);
     RISCVExtStatus fs, vs;
     uint32_t flags = 0;
 
Signature · 1 line
2.41.0
Reviewed-by on v3 1/1
#2 lore raw
Quoted 12 lines · Richard W.M. Jones

RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled this adds about 5% total overhead when emulating RV64 on x86-64 host.

Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk disk. The guest has a copy of the qemu source tree. The test involves compiling the qemu source tree with 'make clean; time make -j16'.

Before making this change the compile step took 449 & 447 seconds over two consecutive runs.

After making this change: 428 & 421 seconds.

Quoted 8 lines

The saving is over 5%.

Thanks: Paolo Bonzini
Thanks: Philippe Mathieu-Daudé

---
  target/riscv/cpu_helper.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by on v3 1/1
#3 lore raw
In reply to Richard W.M. Jones
Quoted 12 lines · Richard W.M. Jones

RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled this adds about 5% total overhead when emulating RV64 on x86-64 host.

Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk disk. The guest has a copy of the qemu source tree. The test involves compiling the qemu source tree with 'make clean; time make -j16'.

Before making this change the compile step took 449 & 447 seconds over two consecutive runs.

After making this change: 428 & 421 seconds.

Quoted 8 lines

The saving is over 5%.

Thanks: Paolo Bonzini
Thanks: Philippe Mathieu-Daudé

---
  target/riscv/cpu_helper.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

r~

Reviewed-by on v3 1/1
#4 lore raw
In reply to Richard W.M. Jones
Quoted 11 lines · Richard W.M. Jones

RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled this adds about 5% total overhead when emulating RV64 on x86-64 host.

Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk disk. The guest has a copy of the qemu source tree. The test involves compiling the qemu source tree with 'make clean; time make -j16'.

Before making this change the compile step took 449 & 447 seconds over two consecutive runs.

Quoted 7 lines

After making this change: 428 & 421 seconds.

The saving is over 5%.

Thanks: Paolo Bonzini
Thanks: Philippe Mathieu-Daudé

Alistair

Quoted 22 lines
---
 target/riscv/cpu_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/cpu_helper.c +1 -3
index 3a02079290..8c28241c18 100644
@@ -65,8 +65,7 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
                           uint64_t *cs_base, uint32_t *pflags)
 {
-    CPUState *cs = env_cpu(env);
-    RISCVCPU *cpu = RISCV_CPU(cs);
+    RISCVCPU *cpu = env_archcpu(env);
     RISCVExtStatus fs, vs;
     uint32_t flags = 0;
 
--

2.41.0

#5 lore raw
In reply to Richard W.M. Jones
Quoted 11 lines · Richard W.M. Jones

RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled this adds about 5% total overhead when emulating RV64 on x86-64 host.

Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk disk. The guest has a copy of the qemu source tree. The test involves compiling the qemu source tree with 'make clean; time make -j16'.

Before making this change the compile step took 449 & 447 seconds over two consecutive runs.

Quoted 7 lines

After making this change: 428 & 421 seconds.

The saving is over 5%.

Thanks: Paolo Bonzini
Thanks: Philippe Mathieu-Daudé

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 22 lines
---
 target/riscv/cpu_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/cpu_helper.c +1 -3
index 3a02079290..8c28241c18 100644
@@ -65,8 +65,7 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
                           uint64_t *cs_base, uint32_t *pflags)
 {
-    CPUState *cs = env_cpu(env);
-    RISCVCPU *cpu = RISCV_CPU(cs);
+    RISCVCPU *cpu = env_archcpu(env);
     RISCVExtStatus fs, vs;
     uint32_t flags = 0;
 
--

2.41.0