qemu-e2k/include/qemu
Paolo Bonzini 6b8f0187a4 icount: process QEMU_CLOCK_VIRTUAL timers in vCPU thread
icount has become much slower after tcg_cpu_exec has stopped
using the BQL.  There is also a latent bug that is masked by
the slowness.

The slowness happens because every occurrence of a QEMU_CLOCK_VIRTUAL
timer now has to wake up the I/O thread and wait for it.  The rendez-vous
is mediated by the BQL QemuMutex:

- handle_icount_deadline wakes up the I/O thread with BQL taken
- the I/O thread wakes up and waits on the BQL
- the VCPU thread releases the BQL a little later
- the I/O thread raises an interrupt, which calls qemu_cpu_kick
- the VCPU thread notices the interrupt, takes the BQL to
  process it and waits on it

All this back and forth is extremely expensive, causing a 6 to 8-fold
slowdown when icount is turned on.

One may think that the issue is that the VCPU thread is too dependent
on the BQL, but then the latent bug comes in.  I first tried removing
the BQL completely from the x86 cpu_exec, only to see everything break.
The only way to fix it (and make everything slow again) was to add a dummy
BQL lock/unlock pair.

This is because in -icount mode you really have to process the events
before the CPU restarts executing the next instruction.  Therefore, this
series moves the processing of QEMU_CLOCK_VIRTUAL timers straight in
the vCPU thread when running in icount mode.

The required changes include:

- make the timer notification callback wake up TCG's single vCPU thread
  when run from another thread.  By using async_run_on_cpu, the callback
  can override all_cpu_threads_idle() when the CPU is halted.

- move handle_icount_deadline after qemu_tcg_wait_io_event, so that
  the timer notification callback is invoked after the dummy work item
  wakes up the vCPU thread

- make handle_icount_deadline run the timers instead of just waking the
  I/O thread.

- stop processing the timers in the main loop

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-14 13:51:34 +01:00
..
acl.h
atomic.h atomics: Add __nocheck atomic operations 2016-10-26 08:28:57 -07:00
base64.h
bcd.h
bitmap.h bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK 2016-10-08 11:25:29 +03:00
bitops.h bitops: fix rol/ror when shift is zero 2016-11-15 10:05:50 +11:00
bswap.h
buffer.h
compiler.h compiler: expression version of QEMU_BUILD_BUG_ON 2017-02-01 03:37:17 +02:00
config-file.h arch_init: Remove unnecessary default_config_files table 2017-01-23 21:25:36 -02:00
coroutine_int.h aio: introduce aio_co_schedule and aio_co_wake 2017-02-21 11:14:07 +00:00
coroutine.h coroutine-lock: make CoRwlock thread-safe and fair 2017-02-21 11:39:40 +00:00
crc32c.h
cutils.h util/cutils: Change qemu_strtosz*() from int64_t to uint64_t 2017-02-23 20:35:36 +01:00
envlist.h
error-report.h qemu-error: remove dependency of stubs on monitor 2016-11-01 16:06:57 +01:00
event_notifier.h event_notifier: cleanups around event_notifier_set_handler 2017-01-16 17:52:35 +01:00
fifo8.h
fifo32.h
fprintf-fn.h
futex.h qemu-thread: optimize QemuLockCnt with futexes on Linux 2017-01-16 13:25:18 +00:00
hbitmap.h hbitmap: Add hbitmap_is_serializable() 2017-01-26 10:25:01 +08:00
help_option.h
host-utils.h host-utils: Implement unsigned quadword left/right shift and unit tests 2017-01-31 10:10:14 +11:00
id.h
int128.h tcg: Add atomic128 helpers 2016-10-26 08:29:01 -07:00
iov.h
jhash.h Jhash: add linux kernel jhashtable in qemu 2016-09-27 17:54:21 +08:00
log.h log: Add locking to large logging blocks 2016-11-01 10:29:03 -06:00
main-loop.h event_notifier: cleanups around event_notifier_set_handler 2017-01-16 17:52:35 +01:00
memfd.h
mmap-alloc.h exec, kvm, target-ppc: Move getrampagesize() to common code 2017-03-03 11:30:59 +11:00
module.h qmp: Dumb down how we run QMP command registration 2017-03-05 09:02:10 +01:00
notify.h
option_int.h
option.h keyval: New keyval_parse() 2017-03-07 16:07:46 +01:00
osdep.h mem-prealloc: reduce large guest start-up and migration time. 2017-03-14 13:26:36 +01:00
path.h
processor.h
qdist.h
qht.h include: Fix typos found by codespell 2017-01-24 23:26:52 +03:00
queue.h migration: migrate QTAILQ 2017-01-24 17:54:47 +00:00
range.h
ratelimit.h
rcu_queue.h
rcu.h
readline.h
seqlock.h seqlock: use atomic writes for the sequence 2016-10-04 10:00:26 +02:00
sockets.h io: introduce a DNS resolver API 2017-01-23 15:32:46 +00:00
thread-posix.h qemu-thread: introduce QemuRecMutex 2016-10-28 21:50:18 +08:00
thread-win32.h qemu-thread: introduce QemuRecMutex 2016-10-28 21:50:18 +08:00
thread.h qemu-thread: optimize QemuLockCnt with futexes on Linux 2017-01-16 13:25:18 +00:00
throttle-options.h throttle: factor out duplicate code 2017-02-28 10:31:46 +01:00
throttle.h
timed-average.h
timer.h icount: process QEMU_CLOCK_VIRTUAL timers in vCPU thread 2017-03-14 13:51:34 +01:00
typedefs.h char: rename CharDriverState Chardev 2017-01-27 18:07:59 +01:00
unicode.h
uri.h Remove unused function declarations 2016-09-15 15:32:22 +03:00
uuid.h vl: Switch qemu_uuid to QemuUUID 2016-09-23 11:42:52 +08:00
xattr.h include: Fix typos found by codespell 2017-01-24 23:26:52 +03:00