target/ppc: Have gen_pause() actually pause vCPUs
cover target/ppc: Have gen_pause() actually pause vCPUs
Probably due to a type, gen_pause() keeps vCPUs running. Fix that.
Philippe Mathieu-Daudé (3):
hw/ppc: Do not open-code cpu_resume() in spin_kick() target/ppc: Have gen_pause() actually pause vCPUs target/ppc: Re-use gen_pause() in gen_wait()
hw/ppc/ppce500_spin.c | 3 +-- target/ppc/translate.c | 15 ++++++--------- 2 files changed, 7 insertions(+), 11 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 hw/ppc: Do not open-code cpu_resume() in spin_kick()
In order to make the code easier to follow / review, use the cpu_resume() helper instead of open-coding it.
--- hw/ppc/ppce500_spin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/ppce500_spin.c +1 -2
@@ -99,8 +99,7 @@ static void spin_kick(CPUState *cs, run_on_cpu_data data) cs->halted =0 ; cs->exception_index =-1 ; - cs->stopped = false; -qemu_cpu_kick (cs); +cpu_resume (cs); } static void spin_write(void *opaque, hwaddr addr, uint64_t value,
Signature · 1 line
2.51.0
Re: [PATCH 1/3] hw/ppc: Do not open-code cpu_resume() in spin_kick()
Quoted 13 lines · Philippe Mathieu-Daudé
In order to make the code easier to follow / review, use the
cpu_resume()helper instead of open-coding it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ppc/ppce500_spin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/ppc/ppce500_spin.c +0
-0
hw/ppc/ppce500_spin.c static void spin_kick(CPUState *cs, run_on_cpu_data data) · line 105
Quoted 9 lines
hw/ppc/ppce500_spin.c +1
-2@@ -99,8 +99,7 @@ static void spin_kick(CPUState *cs, run_on_cpu_data data) cs->halted =0 ; cs->exception_index =-1 ; - cs->stopped = false; -qemu_cpu_kick (cs); +cpu_resume (cs); } static void spin_write(void *opaque, hwaddr addr, uint64_t value,
r~
PATCH 2/3 target/ppc: Have gen_pause() actually pause vCPUs
In reply to Philippe Mathieu-Daudégen_pause() sets CPUState::halted = 0, effectively unhalting (a.k.a. "running") the cpu. Correct by setting the '1' value to really halt the cpu.
--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate.c +1 -1
@@ -1985,7 +1985,7 @@ static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )static void gen_pause (DisasContext *ctx) { -TCGv_i32 t0 =tcg_constant_i32 (0 ); +TCGv_i32 t0 =tcg_constant_i32 (1 );tcg_gen_st_i32 (t0, tcg_env, -offsetof(PowerPCCPU , env) + offsetof(CPUState , halted));
Signature · 1 line
2.51.0
Quoted 15 lines · Philippe Mathieu-Daudé
gen_pause()setsCPUState::halted= 0, effectively unhalting (a.k.a. "running") the cpu. Correct by setting the '1' value to really halt the cpu.Fixes b68e60e6f0d ("ppc: Get out of emulation on SMT "OR" ops")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/ppc/translate.c +0
-0
target/ppc/translate.c static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, · line 1991
Quoted 8 lines
target/ppc/translate.c +1
-1@@ -1985,7 +1985,7 @@ static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )static void gen_pause (DisasContext *ctx) { -TCGv_i32 t0 =tcg_constant_i32 (0 ); +TCGv_i32 t0 =tcg_constant_i32 (1 );tcg_gen_st_i32 (t0, tcg_env, -offsetof(PowerPCCPU , env) + offsetof(CPUState , halted));
r~
Quoted 3 lines · Philippe Mathieu-Daudé
gen_pause()setsCPUState::halted= 0, effectively unhalting (a.k.a. "running") the cpu. Correct by setting the '1' value to really halt the cpu.
What will resume it though ? The smt_low() case isn't meant to *halt* the CPUs permanently. smt_*() levels are about SMT thread priorities. Using a "pause" that just gets out of TCG (and back in), is a way to "yield" to another thread, thus enabling more forward progress when a thread is spinning on an smt_low() loop. This happens in firmware and in some spinlock cases.
This isn't about stopping until some external event resumes it.
Cheers,
Ben.
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 3 lines · Philippe Mathieu-Daudé
gen_pause()setsCPUState::halted= 0, effectively unhalting (a.k.a. "running") the cpu. Correct by setting the '1' value to really halt the cpu.What will resume it though ? The
smt_low()case isn't meant to *halt* the CPUs permanently. smt_*() levels are about SMT thread priorities. Using a "pause" that just gets out of TCG (and back in), is a way to "yield" to another thread, thus enabling more forward progress when a
What you describe can be achieved with a helper doing:
cs->exception_index = EXCP_YIELD; cpu_loop_exit(cs);
Is that what you wanted?
Quoted 8 lines
thread is spinning on an
smt_low()loop. This happens in firmware and in some spinlock cases.This isn't about stopping until some external event resumes it.
Cheers,
Ben.
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines
What will resume it though ? The
smt_low()case isn't meant to *halt*
the CPUs permanently. smt_*() levels are about SMT thread priorities.
Using a "pause" that just gets out of TCG (and back in), is a way to
"yield" to another thread, thus enabling more forward progress when a
Quoted 6 lines
What you describe can be achieved with a helper doing:
cs->exception_index=EXCP_YIELD;
cpu_loop_exit(cs);Is that what you wanted?
I suppose so... this was many years ago and I don't have much context anymore, so I don't know why I didn't do it that way back then.
Cheers,
Ben.
(Cc'ing Aaron for commit 9e196938aa1 "target-ppc: gen_pause for
instructions: yield, mdoio, mdoom, miso")
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 8 lines
What will resume it though ? The
smt_low()case isn't meant to *halt*
the CPUs permanently. smt_*() levels are about SMT thread priorities.
Using a "pause" that just gets out of TCG (and back in), is a way to
"yield" to another thread, thus enabling more forward progress when aWhat you describe can be achieved with a helper doing:
Quoted 7 lines
Quoted 4 lines
cs->exception_index=EXCP_YIELD;
cpu_loop_exit(cs);Is that what you wanted?
I suppose so... this was many years ago and I don't have much context anymore, so I don't know why I didn't do it that way back then.
I *think* Nick implemented something similar for sPAPR in commit e8ce0e40ee9 ("spapr: Implement H_CONFER"):
/*
* The targeted confer does not do anything special beyond yielding
* the current vCPU, but even this should be better than nothing.
* At least for single-threaded tcg, it gives the target a chance to
* run before we run again. Multi-threaded tcg does not really do
* anything with EXCP_YIELD yet.
*/
cs->exception_index = EXCP_YIELD;
cpu_exit(cs);
Nick, would that make sense to implement smt_low?
PATCH 3/3 target/ppc: Re-use gen_pause() in gen_wait()
In reply to Philippe Mathieu-DaudéAvoid open-coding gen_pause() in gen_wait().
--- target/ppc/translate.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
target/ppc/translate.c +5 -8
@@ -1982,17 +1982,18 @@ static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,/*** Integer logical ***/ -#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )static void gen_pause (DisasContext *ctx) {TCGv_i32 t0 =tcg_constant_i32 (1 );tcg_gen_st_i32 (t0, tcg_env, -offsetof(PowerPCCPU , env) + offsetof(CPUState , halted)); -/* Stop translation, this gives other CPUs a chance to run */ +/* +* Stop translation, as the CPU is supposed to sleep from now, +* giving other CPUs a chance to run +*/ gen_exception_nip (ctx,EXCP_HLT , ctx->base.pc_next); } -#endif /* defined(TARGET_PPC64) */ /*** Integer rotate ***/
@@ -3368,11 +3369,7 @@ static void gen_wait(DisasContext *ctx)* to occur. */ if (wc ==0 ) { -TCGv_i32 t0 =tcg_constant_i32 (1 ); -tcg_gen_st_i32 (t0, tcg_env, - -offsetof(PowerPCCPU , env) + offsetof(CPUState , halted)); -/* Stop translation, as the CPU is supposed to sleep from now */ -gen_exception_nip (ctx,EXCP_HLT , ctx->base.pc_next); +gen_pause (ctx); }/*
Signature · 1 line
2.51.0
Re: [PATCH 3/3] target/ppc: Re-use gen_pause() in gen_wait()
Quoted 6 lines · Philippe Mathieu-Daudé
Avoid open-coding
gen_pause()ingen_wait().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/translate.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
r~
Quoted 5 lines · Philippe Mathieu-Daudé
Probably due to a type,
gen_pause()keeps vCPUs running. Fix that.Philippe Mathieu-Daudé (3):
hw/ppc: Do not open-codecpu_resume()inspin_kick()
Patch #1 queued, thanks.