* [PATCH v2] plugins: optimize cpu_index code generation
@ 2024-11-28 21:38 Pierrick Bouvier
2024-11-29 13:29 ` Richard Henderson
0 siblings, 1 reply; 3+ messages in thread
From: Pierrick Bouvier @ 2024-11-28 21:38 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Alex Bennée, Paolo Bonzini,
Alexandre Iooss, Mahmoud Mandour, Pierrick Bouvier
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 <pierrick.bouvier@linaro.org>
---
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
---
accel/tcg/plugin-gen.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index 0f47bfbb489..961d9305913 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -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));
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] plugins: optimize cpu_index code generation
2024-11-28 21:38 [PATCH v2] plugins: optimize cpu_index code generation Pierrick Bouvier
@ 2024-11-29 13:29 ` Richard Henderson
2024-12-16 17:54 ` Pierrick Bouvier
0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2024-11-29 13:29 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Alex Bennée, Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour
On 11/28/24 15:38, Pierrick Bouvier wrote:
> 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<pierrick.bouvier@linaro.org>
>
> ---
>
> 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
> ---
> accel/tcg/plugin-gen.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] plugins: optimize cpu_index code generation
2024-11-29 13:29 ` Richard Henderson
@ 2024-12-16 17:54 ` Pierrick Bouvier
0 siblings, 0 replies; 3+ messages in thread
From: Pierrick Bouvier @ 2024-12-16 17:54 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Alex Bennée, Paolo Bonzini, Alexandre Iooss, Mahmoud Mandour
Hi Richard,
On 11/29/24 05:29, Richard Henderson wrote:
> On 11/28/24 15:38, Pierrick Bouvier wrote:
>> 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<pierrick.bouvier@linaro.org>
>>
>> ---
>>
>> 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
>> ---
>> accel/tcg/plugin-gen.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> r~
any chance you could pull that as part of one of your series?
Thanks,
Pierrick
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-16 17:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28 21:38 [PATCH v2] plugins: optimize cpu_index code generation Pierrick Bouvier
2024-11-29 13:29 ` Richard Henderson
2024-12-16 17:54 ` Pierrick Bouvier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).