cpus: kick all vCPUs when running thread=single
PATCH 1/1 cpus: kick all vCPUs when running thread=single
qemu_cpu_kick is used for a number of reasons including to indicate there is work to be done. However when thread=single the old qemu_cpu_kick_rr_cpu only advanced the vCPU to the next executing one which can lead to a hang in the case that:
a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread calling run_on_cpu)
To avoid this lets split qemu_cpu_kick_rr into two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.
--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
cpus.c +18 -6
@@ -949,8 +949,8 @@ static inline int64_t qemu_tcg_next_kick(void)return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +TCG_KICK_PERIOD ; } -/* Kick the currently round-robin scheduled vCPU */ -static void qemu_cpu_kick_rr_cpu (void ) +/* Kick the currently round-robin scheduled vCPU to next */ +static void qemu_cpu_kick_rr_next_cpu (void ) {CPUState *cpu; do {
@@ -961,6 +961,16 @@ static void qemu_cpu_kick_rr_cpu(void) }while (cpu !=atomic_mb_read (&tcg_current_rr_cpu)); } +/* Kick all RR vCPUs */ +static void qemu_cpu_kick_rr_cpus (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +cpu_exit (cpu); + }; +} +static void do_nothing (CPUState *cpu,run_on_cpu_data unused) { }
@@ -993,7 +1003,7 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type)static void kick_tcg_thread (void *opaque) {timer_mod (tcg_kick_vcpu_timer,qemu_tcg_next_kick ()); -qemu_cpu_kick_rr_cpu (); +qemu_cpu_kick_rr_next_cpu (); }static void start_tcg_kick_timer (void )
@@ -1828,9 +1838,11 @@ void qemu_cpu_kick(CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond);if (tcg_enabled ()) { -cpu_exit (cpu); -/* NOP unless doing single-thread RR */ -qemu_cpu_kick_rr_cpu (); +if (qemu_tcg_mttcg_enabled ()) { +cpu_exit (cpu); + }else { +qemu_cpu_kick_rr_cpus (); + } }else {if (hax_enabled ()) {/*
Signature · 1 line
2.20.1
Quoted 12 lines · Alex Bennée
qemu_cpu_kickis used for a number of reasons including to indicate there is work to be done. However when thread=single the oldqemu_cpu_kick_rr_cpuonly advanced the vCPU to the next executing one which can lead to a hang in the case that:a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread callingrun_on_cpu)To avoid this lets split
qemu_cpu_kick_rrinto two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.
Quoted 7 lines
Signed-off-by Alex Bennée <[email protected]>Cc Doug Gale <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
Looks good to me. Single-threaded TCG is not going to have high vCPU counts anyway.
Paolo
Quoted 57 lines
cpus.c +18
-6@@ -949,8 +949,8 @@ static inline int64_t qemu_tcg_next_kick(void)return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +TCG_KICK_PERIOD ; } -/* Kick the currently round-robin scheduled vCPU */ -static void qemu_cpu_kick_rr_cpu (void ) +/* Kick the currently round-robin scheduled vCPU to next */ +static void qemu_cpu_kick_rr_next_cpu (void ) {CPUState *cpu; do {@@ -961,6 +961,16 @@ static void qemu_cpu_kick_rr_cpu(void) }while (cpu !=atomic_mb_read (&tcg_current_rr_cpu)); } +/* Kick all RR vCPUs */ +static void qemu_cpu_kick_rr_cpus (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +cpu_exit (cpu); + }; +} +static void do_nothing (CPUState *cpu,run_on_cpu_data unused) { }@@ -993,7 +1003,7 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type)static void kick_tcg_thread (void *opaque) {timer_mod (tcg_kick_vcpu_timer,qemu_tcg_next_kick ()); -qemu_cpu_kick_rr_cpu (); +qemu_cpu_kick_rr_next_cpu (); }static void start_tcg_kick_timer (void )@@ -1828,9 +1838,11 @@ void qemu_cpu_kick(CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond);if (tcg_enabled ()) { -cpu_exit (cpu); -/* NOP unless doing single-thread RR */ -qemu_cpu_kick_rr_cpu (); +if (qemu_tcg_mttcg_enabled ()) { +cpu_exit (cpu); + }else { +qemu_cpu_kick_rr_cpus (); + } }else {if (hax_enabled ()) {/*
Quoted 21 lines · Paolo Bonzini
Quoted 12 lines · Alex Bennée
qemu_cpu_kickis used for a number of reasons including to indicate there is work to be done. However when thread=single the oldqemu_cpu_kick_rr_cpuonly advanced the vCPU to the next executing one which can lead to a hang in the case that:a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread callingrun_on_cpu)To avoid this lets split
qemu_cpu_kick_rrinto two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.Quoted 7 lines
Signed-off-by Alex Bennée <[email protected]>Cc Doug Gale <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
Quoted 2 lines
Looks good to me. Single-threaded TCG is not going to have high vCPU counts anyway.
Are you going to take this via your queue?
Quoted 52 lines
Paolo
Quoted 49 lines
cpus.c +14
-6@@ -949,8 +949,8 @@ static inline int64_t qemu_tcg_next_kick(void)return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +TCG_KICK_PERIOD ; } -/* Kick the currently round-robin scheduled vCPU */ -static void qemu_cpu_kick_rr_cpu (void ) +/* Kick the currently round-robin scheduled vCPU to next */ +static void qemu_cpu_kick_rr_next_cpu (void ) {CPUState *cpu; do {@@ -961,6 +961,16 @@ static void qemu_cpu_kick_rr_cpu(void) }while (cpu !=atomic_mb_read (&tcg_current_rr_cpu)); } +/* Kick all RR vCPUs */ +static void qemu_cpu_kick_rr_cpus (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +cpu_exit (cpu); + }; +} +static void do_nothing (CPUState *cpu,run_on_cpu_data unused) { }@@ -993,7 +1003,7 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type)static void kick_tcg_thread (void *opaque) {timer_mod (tcg_kick_vcpu_timer,qemu_tcg_next_kick ()); -qemu_cpu_kick_rr_cpu (); +qemu_cpu_kick_rr_next_cpu (); }static void start_tcg_kick_timer (void )@@ -1828,9 +1838,11 @@ void qemu_cpu_kick(CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond);if (tcg_enabled ()) { -cpu_exit (cpu); -/* NOP unless doing single-thread RR */ -qemu_cpu_kick_rr_cpu (); +if (qemu_tcg_mttcg_enabled ()) {
Quoted 8 lines
cpus.c void qemu_cpu_kick(CPUState *cpu) · line 1848
Quoted 8 lines
cpus.c +4
-0+cpu_exit (cpu); + }else { +qemu_cpu_kick_rr_cpus (); + } }else {if (hax_enabled ()) {/*
--
Alex Bennée
Quoted 24 lines · Alex Bennée
Quoted 21 lines · Paolo Bonzini
Quoted 19 lines · Alex Bennée
qemu_cpu_kickis used for a number of reasons including to indicate there is work to be done. However when thread=single the oldqemu_cpu_kick_rr_cpuonly advanced the vCPU to the next executing one which can lead to a hang in the case that:a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread callingrun_on_cpu)To avoid this lets split
qemu_cpu_kick_rrinto two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.Signed-off-by Alex Bennée <[email protected]>Cc Doug Gale <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
Quoted 4 lines
Quoted 2 lines
Looks good to me. Single-threaded TCG is not going to have high vCPU counts anyway.
Are you going to take this via your queue?
I wasn't, since we have had a proper TCG maintainer for a while. :)
Paolo
Quoted 66 lines
Quoted 53 lines
Paolo
Quoted 49 lines
cpus.c +14
-6@@ -949,8 +949,8 @@ static inline int64_t qemu_tcg_next_kick(void)return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +TCG_KICK_PERIOD ; } -/* Kick the currently round-robin scheduled vCPU */ -static void qemu_cpu_kick_rr_cpu (void ) +/* Kick the currently round-robin scheduled vCPU to next */ +static void qemu_cpu_kick_rr_next_cpu (void ) {CPUState *cpu; do {@@ -961,6 +961,16 @@ static void qemu_cpu_kick_rr_cpu(void) }while (cpu !=atomic_mb_read (&tcg_current_rr_cpu)); } +/* Kick all RR vCPUs */ +static void qemu_cpu_kick_rr_cpus (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +cpu_exit (cpu); + }; +} +static void do_nothing (CPUState *cpu,run_on_cpu_data unused) { }@@ -993,7 +1003,7 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type)static void kick_tcg_thread (void *opaque) {timer_mod (tcg_kick_vcpu_timer,qemu_tcg_next_kick ()); -qemu_cpu_kick_rr_cpu (); +qemu_cpu_kick_rr_next_cpu (); }static void start_tcg_kick_timer (void )@@ -1828,9 +1838,11 @@ void qemu_cpu_kick(CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond);if (tcg_enabled ()) { -cpu_exit (cpu); -/* NOP unless doing single-thread RR */ -qemu_cpu_kick_rr_cpu (); +if (qemu_tcg_mttcg_enabled ()) {Quoted 8 lines
cpus.c void qemu_cpu_kick(CPUState *cpu) · line 1848
Quoted 8 lines
cpus.c +4
-0+cpu_exit (cpu); + }else { +qemu_cpu_kick_rr_cpus (); + } }else {if (hax_enabled ()) {/* --
Alex Bennée
Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Alex Bennée
Quoted 21 lines · Paolo Bonzini
Quoted 19 lines · Alex Bennée
qemu_cpu_kickis used for a number of reasons including to indicate there is work to be done. However when thread=single the oldqemu_cpu_kick_rr_cpuonly advanced the vCPU to the next executing one which can lead to a hang in the case that:a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread callingrun_on_cpu)To avoid this lets split
qemu_cpu_kick_rrinto two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.Signed-off-by Alex Bennée <[email protected]>Cc Doug Gale <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Looks good to me. Single-threaded TCG is not going to have high vCPU counts anyway.
Are you going to take this via your queue?
I wasn't, since we have had a proper TCG maintainer for a while. :)
Hah. Point taken, and queued. Would you care to go on the record with something more than a LGTM?
r~
Paolo Bonzini
Reviewed-byQuoted 3 lines · Richard Henderson
Quoted 1 line
I wasn't, since we have had a proper TCG maintainer for a while. :)
Hah. Point taken, and queued. Would you care to go on the record with something more than a LGTM?
Sure,
Quoted 29 lines · Richard Henderson
Quoted 28 lines · Paolo Bonzini
Quoted 27 lines · Alex Bennée
Quoted 23 lines · Paolo Bonzini
Quoted 12 lines · Alex Bennée
qemu_cpu_kickis used for a number of reasons including to indicate there is work to be done. However when thread=single the oldqemu_cpu_kick_rr_cpuonly advanced the vCPU to the next executing one which can lead to a hang in the case that:a) the kick is from outside the vCPUs (e.g. iothread)
b) the timers are paused (i.e. iothread callingrun_on_cpu)To avoid this lets split
qemu_cpu_kick_rrinto two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks.Quoted 7 lines
Signed-off-by Alex Bennée <[email protected]>Cc Doug Gale <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>--- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)Looks good to me. Single-threaded TCG is not going to have high vCPU counts anyway.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Are you going to take this via your queue?
I wasn't, since we have had a proper TCG maintainer for a while. :)
Hah. Point taken, and queued. Would you care to go on the record with something more than a LGTM?
Heh, I was confused because cpus.c is shown twice in MAINTAINERS as Paolo is the main loop guy ;-)
Quoted 3 lines
r~
--
Alex Bennée