Skip to content

Commit

Permalink
plugins: optimize cpu_index code generation
Browse files Browse the repository at this point in the history
When running with a single vcpu, we can return a constant instead of a
load when accessing cpu_index.
A side effect is that all tcg operations using it are optimized, most
notably scoreboard access.
When running a simple loop in user-mode, the speedup is around 20%.

Signed-off-by: Pierrick Bouvier <[email protected]>

---

v2:
- no need to do a flush, as user-mode already does it when spawning a
  second cpu (to honor CF_PARALLEL flags).
- change condition detection to use CF_PARALLEL instead

Signed-off-by: Pierrick Bouvier <[email protected]>
  • Loading branch information
pbo-linaro committed Nov 24, 2024
1 parent 53fe3cc commit d381592
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions accel/tcg/plugin-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ static void gen_disable_mem_helper(void)

static TCGv_i32 gen_cpu_index(void)
{
/*
* Optimize when we run with a single vcpu. All values using cpu_index,
* including scoreboard index, will be optimized out.
* User-mode calls tb_flush when setting this flag. In system-mode, all
* vcpus are created before generating code.
*/
if (!tcg_cflags_has(current_cpu, CF_PARALLEL)) {
return tcg_constant_i32(current_cpu->cpu_index);
}
TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
tcg_gen_ld_i32(cpu_index, tcg_env,
-offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
Expand Down

0 comments on commit d381592

Please sign in to comment.