qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] accel/tcg/tcg-accel-ops-rr: ensure fairness with icount
@ 2023-04-27  2:09 Jamie Iles
  2023-04-27  2:09 ` [PATCH v3 1/2] cpu: expose qemu_cpu_list_lock for lock-guard use Jamie Iles
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jamie Iles @ 2023-04-27  2:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: richard.henderson, pbonzini, philmd, peter.maydell

From: Jamie Iles <jiles@qti.qualcomm.com>

The round-robin scheduler will iterate over the CPU list with an
assigned budget until the next timer expiry and may exit early because
of a TB exit.  This is fine under normal operation but with icount
enabled and SMP it is possible for a CPU to be starved of run time and
the system live-locks.

For example, booting a riscv64 platform with '-icount
shift=0,align=off,sleep=on -smp 2' we observe a livelock once the kernel
has timers enabled and starts performing TLB shootdowns.  In this case
we have CPU 0 in M-mode with interrupts disabled sending an IPI to CPU
1.  As we enter the TCG loop, we assign the icount budget to next timer
interrupt to CPU 0 and begin executing where the guest is sat in a busy
loop exhausting all of the budget before we try to execute CPU 1 which
is the target of the IPI but CPU 1 is left with no budget with which to
execute and the process repeats.

We try here to add some fairness by splitting the budget across all of
the CPUs on the thread fairly before entering each one.  The CPU count
is cached on CPU list generation ID to avoid iterating the list on each
loop iteration.  With this change it is possible to boot an SMP rv64
guest with icount enabled and no hangs.

New in v3 (address feedback from Richard Henderson):
 - Additional patch to use QEMU_LOCK_GUARD with qemu_cpu_list_lock where 
   appropriate
 - Move rr_cpu_count() call to be conditional on icount_enabled()
 - Initialize cpu_budget to 0

Jamie Iles (2):
  cpu: expose qemu_cpu_list_lock for lock-guard use
  accel/tcg/tcg-accel-ops-rr: ensure fairness with icount

 accel/tcg/tcg-accel-ops-icount.c | 17 +++++++++++++--
 accel/tcg/tcg-accel-ops-icount.h |  3 ++-
 accel/tcg/tcg-accel-ops-rr.c     | 37 +++++++++++++++++++++++++++++++-
 cpus-common.c                    |  2 +-
 include/exec/cpu-common.h        |  1 +
 linux-user/elfload.c             | 12 +++++------
 migration/dirtyrate.c            | 26 +++++++++++-----------
 trace/control-target.c           |  9 ++++----
 8 files changed, 78 insertions(+), 29 deletions(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-05-10 15:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-27  2:09 [PATCH v3 0/2] accel/tcg/tcg-accel-ops-rr: ensure fairness with icount Jamie Iles
2023-04-27  2:09 ` [PATCH v3 1/2] cpu: expose qemu_cpu_list_lock for lock-guard use Jamie Iles
2023-04-27  7:44   ` Richard Henderson
2023-04-28 23:05   ` Philippe Mathieu-Daudé
2023-04-27  2:09 ` [PATCH v3 2/2] accel/tcg/tcg-accel-ops-rr: ensure fairness with icount Jamie Iles
2023-04-27  7:46   ` Richard Henderson
2023-04-29  9:28 ` [PATCH v3 0/2] " Richard Henderson
2023-04-29 12:23   ` Philippe Mathieu-Daudé
2023-05-03  9:44   ` Jamie Iles
2023-05-10 15:01     ` Richard Henderson

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).