aio / timers: Add AioContext timers and use ppoll
Subsystems (6)
v10 cover aio / timers: Add AioContext timers and use ppoll
[ This patch set is available from git at:
https://github.com/abligh/qemu/tree/aio-timers10
As autogenerated patch 30 of the series is too large for the mailing list. ]
This patch series adds support for timers attached to an AioContext clock which get called within aio_poll.
In doing so it removes alarm timers and moves to use ppoll where possible.
This patch set 'sort of' passes make check (see below for caveat) including a new test harness for the aio timers, but has not been tested much beyond that. In particular, the win32 changes have not even been compile tested. Equally, alterations to use_icount are untested.
Caveat: I have had to alter tests/test-aio.c so the following error no longer occurs.
ERROR:tests/test-aio.c:346:test_wait_event_notifier_noflush: assertion failed: (aio_poll(ctx, false))
As gar as I can tell, this check was incorrect, in that it checking aio_poll makes progress when in fact it should not make progress. I fixed an issue where aio_poll was (as far as I can tell) wrongly returning true on a timeout, and that generated this error.
Note also the comment on patch 19 in relation to a possible bug in cpus.c.
The penultimate patch is patch which is created in an automated manner using scripts/switch-timer-api, added in this patch set. It violates some coding standards (e.g. line length >= 80 characters), but this is preferable in terms of giving a provably correct conversion. This patch is too large for the mailing list, so
EITHER: get it from git at the URL at the top of this message.
OR: Do the following:
1. Apply patches 0000-0029 inclusive
2. Run scripts/switch-timer-api
3. git commit -a (+ suitable commit message)
4. Apply patch 0031
If there is demand I can split it one commit per file.
This patch set has been compile tested & make check tested on a 'christmas-tree' configuration, meaning a configuration with every --enable-* value tested that can be easily configured on Ubuntu Precise, after application of each patch.
Changes done since v9:
* Rebase to master 2e985fe
* Wrap QEMUTimerListGroup in a struct as we're keeping it for the time being
Changes since v8:
* PR_SET_TIMERSLACK commit should have relevant configure patch within
* Delete timerlist_set_notify_cb, put into timerlist_new
* Add missing QLIST_INIT of clock->timerlists
* Fix documentation for timerlist_get_clock
* Rename qemu_timer_xxx to timer_xxx
* Remove unintentional change to pc-bios/slof.bin
* Introduce timer_init and aio_timer_init
Changes since v7:
* Rebase to master 6fdf98f281f85ae6e2883bed2f691bcfe33b1f9f
* Add qemu_clock_get_ms and qemu_clock_get_ms
* Rename qemu_get_clock to qemu_clock_ptr
* Reorder qemu-timer.h to utilise the legacy API
* Hide qemu_clock_new & qemu_clock_free
* Rename default_timerlist to main_loop_timerlist
* Remove main_loop_timerlist once main_loop_tlg is in
* Add script to convert to new API
* Make rtc_clock use new API
* Convert tests/test-aio to use new API
* Run script on entire source code
* Remove legacy API functions
Changes since v6:
* Fix build failure in vnc-auth-sasl.c
* Split first patch into 3
* Add assert on timerlist_free
* Fix ==/= error on qemu_clock_use_for_deadline
* Remove unnecessary cast in aio_timerlist_notify
* Fix bad deadline comparison in aio_ctx_check
* Add assert to timerlist_new_from_clock to check init_clocks
* Use timer_list not tl
* Change default_timerlistgroup to main_loop_timerlistgroup
* Add comment on commit for qemu_clock_use_for_deadline
* Fixed various include file issues
* Convert *_has_timers and *_has_expired to return bool
* Make loop variable consistent when looping through clock types
* Add documentation to existing qemu_timer calls
* Remove qemu_clock_deadline and move to qemu_clock_deadline_ns
Changes since v5:
* Rebase onto master (b9ac5d9)
* Fix spacing in typedef QEMUTimerList
* Rename 'QEMUClocks' extern to 'qemu_clocks'
Changes since v4:
* Rename qemu_timerlist_ functions to timer_list (per Paolo Bonzini)
* Rename qemu_timer_.*timerlist.* to timer_ (per Paolo Bonzini)
* Use enum for QEMUClockType
* Put clocks into an array; remove global variables
* Introduce QEMUTimerListGroup - a timeliest of each type
* Add a QEMUTimerListGroup to AioContext
* Use a callback on timer modification, rather than binding in AioContext into the timeliest
* Make cpus.c iterate over all timerlists when it does a notify
* Make cpus.c icount timeout use soonest timeout
across all timerlists
Changes since v3:
* Split up QEMUClock and QEMUClock list
* Improve commenting
* Fix comment in vl.c
* Change test/test-aio.c to reflect correct behaviour in aio_poll.
Changes since v2:
* Reordered to remove alarm timers last
* Added prctl(PR_SET_TIMERSLACK, 1, ...)
* Renamed qemu_g_poll_ns to qemu_poll_ns
* Moved declaration of above & drop glib types
* Do not use a global list of qemu clocks
* Add AioContext * to QEMUClock
* Split up conversion to use ppoll and timers
* Indentation fix
* Fix aio_win32.c aio_poll to return progress
* aio_notify / qemu_notify when timers are modified
* change comment in deprecation of clock options
Alex Bligh (31):
aio / timers: Rename qemu_timer_* functions
aio / timers: Rename qemu_new_clock and expose clock types aio / timers: add qemu-timer.c utility functions
aio / timers: Consistent treatment of disabled clocks for deadlines aio / timers: add ppoll support with qemu_poll_ns
aio / timers: Add prctl(PR_SET_TIMERSLACK, 1, ...) to reduce timer
slack
aio / timers: Make qemu_run_timers and qemu_run_all_timers return
progress
aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList aio / timers: Untangle include files
aio / timers: Add QEMUTimerListGroup and helper functions aio / timers: Add QEMUTimerListGroup to AioContext
aio / timers: Add a notify callback to QEMUTimerList
aio / timers: aio_ctx_prepare sets timeout from AioContext timers aio / timers: Add aio_timer_init & aio_timer_new wrappers aio / timers: Convert aio_poll to use AioContext timers' deadline aio / timers: Convert mainloop to use timeout
aio / timers: On timer modification, qemu_notify or aio_notify aio / timers: Introduce new API timer_new and friends aio / timers: Use all timerlists in icount warp calculations aio / timers: Add documentation and new format calls
aio / timers: Remove alarm timers
aio / timers: Remove legacy qemu_clock_deadline &
qemu_timerlist_deadline
aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms aio / timers: Rearrange timer.h & make legacy functions call
non-legacy
aio / timers: Remove main_loop_timerlist
aio / timers: Convert rtc_clock to be a QEMUClockType aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API aio / timers: Add test harness for AioContext timers
aio / timers: Add scripts/switch-timer-api
aio / timers: Switch entire codebase to the new timer API aio / timers: Remove legacy interface
aio-posix.c | 20 +- aio-win32.c | 22 +- arch_init.c | 12 +- async.c | 20 +- audio/audio.c | 6 +- audio/noaudio.c | 4 +- audio/spiceaudio.c | 4 +- audio/wavaudio.c | 2 +- backends/baum.c | 16 +- block.c | 14 +- block/backup.c | 4 +- block/commit.c | 2 +- block/iscsi.c | 14 +- block/mirror.c | 10 +- block/qed.c | 10 +- block/stream.c | 2 +- blockdev.c | 2 +- blockjob.c | 4 +- configure | 37 ++ cpus.c | 138 ++++--- dma-helpers.c | 1 + hmp.c | 8 +- hw/acpi/core.c | 8 +- hw/acpi/piix4.c | 2 +- hw/alpha/typhoon.c | 2 +- hw/arm/omap1.c | 52 +-- hw/arm/pxa2xx.c | 61 ++-- hw/arm/spitz.c | 6 +- hw/arm/stellaris.c | 10 +- hw/arm/strongarm.c | 34 +- hw/audio/adlib.c | 2 +- hw/audio/intel-hda.c | 4 +- hw/audio/sb16.c | 6 +- hw/block/fdc.c | 6 +- hw/block/nvme.c | 20 +- hw/block/pflash_cfi01.c | 2 +- hw/block/pflash_cfi02.c | 10 +- hw/bt/hci-csr.c | 4 +- hw/bt/hci.c | 38 +- hw/bt/l2cap.c | 8 +- hw/char/cadence_uart.c | 12 +- hw/char/serial.c | 22 +- hw/char/virtio-serial-bus.c | 10 +- hw/core/ptimer.c | 18 +- hw/display/qxl-logger.c | 2 +- hw/display/qxl.c | 2 +- hw/display/vga.c | 6 +- hw/dma/pl330.c | 6 +- hw/dma/rc4030.c | 4 +- hw/dma/soc_dma.c | 8 +- hw/dma/xilinx_axidma.c | 1 + hw/i386/kvm/apic.c | 2 +- hw/i386/kvm/i8254.c | 6 +- hw/i386/xen_domainbuild.c | 6 +- hw/ide/core.c | 6 +- hw/input/hid.c | 10 +- hw/input/lm832x.c | 8 +- hw/input/tsc2005.c | 16 +- hw/input/tsc210x.c | 32 +- hw/intc/apic.c | 16 +- hw/intc/apic_common.c | 2 +- hw/intc/armv7m_nvic.c | 16 +- hw/intc/i8259.c | 4 +- hw/mips/cputimer.c | 16 +- hw/misc/arm_sysctl.c | 2 +- hw/misc/macio/cuda.c | 34 +- hw/misc/macio/macio.c | 4 +- hw/misc/vfio.c | 14 +- hw/net/dp8393x.c | 20 +- hw/net/e1000.c | 12 +- hw/net/lan9118.c | 4 +- hw/net/pcnet-pci.c | 4 +- hw/net/pcnet.c | 10 +- hw/net/rtl8139.c | 28 +- hw/net/virtio-net.c | 20 +- hw/openrisc/cputimer.c | 10 +- hw/ppc/ppc.c | 64 ++-- hw/ppc/ppc405_uc.c | 8 +- hw/ppc/ppc_booke.c | 10 +- hw/ppc/spapr.c | 8 +- hw/sd/sdhci.c | 28 +- hw/sparc64/sun4u.c | 24 +- hw/timer/arm_mptimer.c | 12 +- hw/timer/arm_timer.c | 1 + hw/timer/cadence_ttc.c | 6 +- hw/timer/etraxfs_timer.c | 2 +- hw/timer/exynos4210_mct.c | 3 +- hw/timer/exynos4210_pwm.c | 1 + hw/timer/grlib_gptimer.c | 2 + hw/timer/hpet.c | 20 +- hw/timer/i8254.c | 26 +- hw/timer/i8254_common.c | 4 +- hw/timer/imx_epit.c | 1 + hw/timer/imx_gpt.c | 1 + hw/timer/lm32_timer.c | 1 + hw/timer/m48t59.c | 18 +- hw/timer/mc146818rtc.c | 50 +-- hw/timer/omap_gptimer.c | 24 +- hw/timer/omap_synctimer.c | 2 +- hw/timer/pl031.c | 19 +- hw/timer/puv3_ost.c | 1 + hw/timer/pxa2xx_timer.c | 34 +- hw/timer/sh_timer.c | 1 + hw/timer/slavio_timer.c | 1 + hw/timer/tusb6010.c | 12 +- hw/timer/twl92230.c | 14 +- hw/timer/xilinx_timer.c | 1 + hw/tpm/tpm_tis.c | 1 + hw/usb/hcd-ehci.c | 10 +- hw/usb/hcd-musb.c | 6 +- hw/usb/hcd-ohci.c | 12 +- hw/usb/hcd-uhci.c | 15 +- hw/usb/hcd-xhci.c | 26 +- hw/usb/host-libusb.c | 6 +- hw/usb/host-linux.c | 6 +- hw/usb/redirect.c | 16 +- hw/virtio/virtio-balloon.c | 8 +- hw/virtio/virtio-rng.c | 14 +- hw/watchdog/wdt_i6300esb.c | 6 +- hw/watchdog/wdt_ib700.c | 10 +- hw/xtensa/pic_cpu.c | 10 +- include/block/aio.h | 47 +++ include/block/block_int.h | 1 + include/block/blockjob.h | 2 +- include/block/coroutine.h | 4 +- include/hw/acpi/acpi.h | 2 +- include/qemu/ratelimit.h | 2 +- include/qemu/timer.h | 671 +++++++++++++++++++++++++++++++--- include/sysemu/sysemu.h | 2 +- main-loop.c | 51 ++- migration-exec.c | 1 + migration-fd.c | 1 + migration-tcp.c | 1 + migration-unix.c | 1 + migration.c | 17 +- monitor.c | 8 +- nbd.c | 1 + net/dump.c | 2 +- net/net.c | 1 + net/socket.c | 1 + qemu-char.c | 2 +- qemu-coroutine-io.c | 1 + qemu-coroutine-sleep.c | 10 +- qemu-io-cmds.c | 1 + qemu-nbd.c | 1 + qemu-timer.c | 833 +++++++++++++++---------------------------- qtest.c | 10 +- savevm.c | 24 +- scripts/switch-timer-api | 178 +++++++++ slirp/if.c | 2 +- slirp/misc.c | 1 + slirp/slirp.c | 4 +- stubs/clock-warp.c | 2 +- target-alpha/sys_helper.c | 12 +- target-ppc/kvm.c | 8 +- target-ppc/kvm_ppc.c | 6 +- target-s390x/cpu.c | 4 +- target-s390x/misc_helper.c | 6 +- target-xtensa/op_helper.c | 2 +- tests/libqtest.h | 24 +- tests/test-aio.c | 143 +++++++- tests/test-thread-pool.c | 3 + thread-pool.c | 1 + ui/console.c | 30 +- ui/input.c | 6 +- ui/spice-core.c | 10 +- ui/vnc-auth-sasl.h | 1 + ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 1 + vl.c | 14 +- xen-all.c | 12 +- 171 files changed, 2278 insertions(+), 1457 deletions(-) create mode 100755 scripts/switch-timer-api
Signature · 217 lines
1.7.9.5
*** BLURB END ***
Alex Bligh (31):
aio / timers: Rename qemu_timer_* functions
aio / timers: Rename qemu_new_clock and expose clock types
aio / timers: add qemu-timer.c utility functions
aio / timers: Consistent treatment of disabled clocks for deadlines
aio / timers: add ppoll support with qemu_poll_ns
aio / timers: Add prctl(PR_SET_TIMERSLACK, 1, ...) to reduce timer
slack
aio / timers: Make qemu_run_timers and qemu_run_all_timers return
progress
aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
aio / timers: Untangle include files
aio / timers: Add QEMUTimerListGroup and helper functions
aio / timers: Add QEMUTimerListGroup to AioContext
aio / timers: Add a notify callback to QEMUTimerList
aio / timers: aio_ctx_prepare sets timeout from AioContext timers
aio / timers: Add aio_timer_init & aio_timer_new wrappers
aio / timers: Convert aio_poll to use AioContext timers' deadline
aio / timers: Convert mainloop to use timeout
aio / timers: On timer modification, qemu_notify or aio_notify
aio / timers: Introduce new API timer_new and friends
aio / timers: Use all timerlists in icount warp calculations
aio / timers: Add documentation and new format calls
aio / timers: Remove alarm timers
aio / timers: Remove legacy qemu_clock_deadline &
qemu_timerlist_deadline
aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms
aio / timers: Rearrange timer.h & make legacy functions call
non-legacy
aio / timers: Remove main_loop_timerlist
aio / timers: Convert rtc_clock to be a QEMUClockType
aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API
aio / timers: Add test harness for AioContext timers
aio / timers: Add scripts/switch-timer-api
aio / timers: Switch entire codebase to the new timer API
aio / timers: Remove legacy interface
aio-posix.c | 20 +-
aio-win32.c | 22 +-
arch_init.c | 12 +-
async.c | 20 +-
audio/audio.c | 6 +-
audio/noaudio.c | 4 +-
audio/spiceaudio.c | 4 +-
audio/wavaudio.c | 2 +-
backends/baum.c | 16 +-
block.c | 14 +-
block/backup.c | 4 +-
block/commit.c | 2 +-
block/iscsi.c | 14 +-
block/mirror.c | 10 +-
block/qed.c | 10 +-
block/stream.c | 2 +-
blockdev.c | 2 +-
blockjob.c | 4 +-
configure | 37 ++
cpus.c | 138 ++++---
dma-helpers.c | 1 +
hmp.c | 8 +-
hw/acpi/core.c | 8 +-
hw/acpi/piix4.c | 2 +-
hw/alpha/typhoon.c | 2 +-
hw/arm/omap1.c | 52 +--
hw/arm/pxa2xx.c | 61 ++--
hw/arm/spitz.c | 6 +-
hw/arm/stellaris.c | 10 +-
hw/arm/strongarm.c | 34 +-
hw/audio/adlib.c | 2 +-
hw/audio/intel-hda.c | 4 +-
hw/audio/sb16.c | 6 +-
hw/block/fdc.c | 6 +-
hw/block/nvme.c | 20 +-
hw/block/pflash_cfi01.c | 2 +-
hw/block/pflash_cfi02.c | 10 +-
hw/bt/hci-csr.c | 4 +-
hw/bt/hci.c | 38 +-
hw/bt/l2cap.c | 8 +-
hw/char/cadence_uart.c | 12 +-
hw/char/serial.c | 22 +-
hw/char/virtio-serial-bus.c | 10 +-
hw/core/ptimer.c | 18 +-
hw/display/qxl-logger.c | 2 +-
hw/display/qxl.c | 2 +-
hw/display/vga.c | 6 +-
hw/dma/pl330.c | 6 +-
hw/dma/rc4030.c | 4 +-
hw/dma/soc_dma.c | 8 +-
hw/dma/xilinx_axidma.c | 1 +
hw/i386/kvm/apic.c | 2 +-
hw/i386/kvm/i8254.c | 6 +-
hw/i386/xen_domainbuild.c | 6 +-
hw/ide/core.c | 6 +-
hw/input/hid.c | 10 +-
hw/input/lm832x.c | 8 +-
hw/input/tsc2005.c | 16 +-
hw/input/tsc210x.c | 32 +-
hw/intc/apic.c | 16 +-
hw/intc/apic_common.c | 2 +-
hw/intc/armv7m_nvic.c | 16 +-
hw/intc/i8259.c | 4 +-
hw/mips/cputimer.c | 16 +-
hw/misc/arm_sysctl.c | 2 +-
hw/misc/macio/cuda.c | 34 +-
hw/misc/macio/macio.c | 4 +-
hw/misc/vfio.c | 14 +-
hw/net/dp8393x.c | 20 +-
hw/net/e1000.c | 12 +-
hw/net/lan9118.c | 4 +-
hw/net/pcnet-pci.c | 4 +-
hw/net/pcnet.c | 10 +-
hw/net/rtl8139.c | 28 +-
hw/net/virtio-net.c | 20 +-
hw/openrisc/cputimer.c | 10 +-
hw/ppc/ppc.c | 64 ++--
hw/ppc/ppc405_uc.c | 8 +-
hw/ppc/ppc_booke.c | 10 +-
hw/ppc/spapr.c | 8 +-
hw/sd/sdhci.c | 28 +-
hw/sparc64/sun4u.c | 24 +-
hw/timer/arm_mptimer.c | 12 +-
hw/timer/arm_timer.c | 1 +
hw/timer/cadence_ttc.c | 6 +-
hw/timer/etraxfs_timer.c | 2 +-
hw/timer/exynos4210_mct.c | 3 +-
hw/timer/exynos4210_pwm.c | 1 +
hw/timer/grlib_gptimer.c | 2 +
hw/timer/hpet.c | 20 +-
hw/timer/i8254.c | 26 +-
hw/timer/i8254_common.c | 4 +-
hw/timer/imx_epit.c | 1 +
hw/timer/imx_gpt.c | 1 +
hw/timer/lm32_timer.c | 1 +
hw/timer/m48t59.c | 18 +-
hw/timer/mc146818rtc.c | 50 +--
hw/timer/omap_gptimer.c | 24 +-
hw/timer/omap_synctimer.c | 2 +-
hw/timer/pl031.c | 19 +-
hw/timer/puv3_ost.c | 1 +
hw/timer/pxa2xx_timer.c | 34 +-
hw/timer/sh_timer.c | 1 +
hw/timer/slavio_timer.c | 1 +
hw/timer/tusb6010.c | 12 +-
hw/timer/twl92230.c | 14 +-
hw/timer/xilinx_timer.c | 1 +
hw/tpm/tpm_tis.c | 1 +
hw/usb/hcd-ehci.c | 10 +-
hw/usb/hcd-musb.c | 6 +-
hw/usb/hcd-ohci.c | 12 +-
hw/usb/hcd-uhci.c | 15 +-
hw/usb/hcd-xhci.c | 26 +-
hw/usb/host-libusb.c | 6 +-
hw/usb/host-linux.c | 6 +-
hw/usb/redirect.c | 16 +-
hw/virtio/virtio-balloon.c | 8 +-
hw/virtio/virtio-rng.c | 14 +-
hw/watchdog/wdt_i6300esb.c | 6 +-
hw/watchdog/wdt_ib700.c | 10 +-
hw/xtensa/pic_cpu.c | 10 +-
include/block/aio.h | 47 +++
include/block/block_int.h | 1 +
include/block/blockjob.h | 2 +-
include/block/coroutine.h | 4 +-
include/hw/acpi/acpi.h | 2 +-
include/qemu/ratelimit.h | 2 +-
include/qemu/timer.h | 675 +++++++++++++++++++++++++++++++---
include/sysemu/sysemu.h | 2 +-
main-loop.c | 51 ++-
migration-exec.c | 1 +
migration-fd.c | 1 +
migration-tcp.c | 1 +
migration-unix.c | 1 +
migration.c | 17 +-
monitor.c | 8 +-
nbd.c | 1 +
net/dump.c | 2 +-
net/net.c | 1 +
net/socket.c | 1 +
qemu-char.c | 2 +-
qemu-coroutine-io.c | 1 +
qemu-coroutine-sleep.c | 10 +-
qemu-io-cmds.c | 1 +
qemu-nbd.c | 1 +
qemu-timer.c | 834 +++++++++++++++----------------------------
qtest.c | 10 +-
savevm.c | 24 +-
scripts/switch-timer-api | 178 +++++++++
slirp/if.c | 2 +-
slirp/misc.c | 1 +
slirp/slirp.c | 4 +-
stubs/clock-warp.c | 2 +-
target-alpha/sys_helper.c | 12 +-
target-ppc/kvm.c | 8 +-
target-ppc/kvm_ppc.c | 6 +-
target-s390x/cpu.c | 4 +-
target-s390x/misc_helper.c | 6 +-
target-xtensa/op_helper.c | 2 +-
tests/libqtest.h | 24 +-
tests/test-aio.c | 143 +++++++-
tests/test-thread-pool.c | 3 +
thread-pool.c | 1 +
ui/console.c | 30 +-
ui/input.c | 6 +-
ui/spice-core.c | 10 +-
ui/vnc-auth-sasl.h | 1 +
ui/vnc-auth-vencrypt.c | 2 +-
ui/vnc-ws.c | 1 +
vl.c | 14 +-
xen-all.c | 12 +-
171 files changed, 2283 insertions(+), 1457 deletions(-)
create mode 100755 scripts/switch-timer-api
--
1.7.9.5RFC PATCH v10 1/31 aio / timers: Rename qemu_timer_* functions
Rename four functions in preparation for new API.
Rename qemu_timer_expired to timer_expired Rename qemu_timer_expire_time_ns to timer_expire_time_ns Rename qemu_timer_pending to timer_pending Rename qemu_timer_expired_ns to timer_expired_ns
--- backends/baum.c | 6 +++--- hw/input/tsc2005.c | 2 +- hw/input/tsc210x.c | 2 +- hw/mips/cputimer.c | 4 ++-- hw/openrisc/cputimer.c | 2 +- hw/timer/mc146818rtc.c | 6 +++--- hw/usb/redirect.c | 4 ++-- include/qemu/timer.h | 6 +++--- qemu-timer.c | 20 ++++++++++---------- savevm.c | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-)
backends/baum.c +3 -3
@@ -314,9 +314,9 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)return 0 ; \if (*cur++ !=ESC ) { \DPRINTF ("Broken packet %#2x, tossing\n" , req); \ -if (qemu_timer_pending (baum->cellCount_timer)) { \ -qemu_del_timer (baum->cellCount_timer); \ -baum_cellCount_timer_cb (baum); \ +if (timer_pending (baum->cellCount_timer)) { \ +qemu_del_timer (baum->cellCount_timer); \ +baum_cellCount_timer_cb (baum); \ } \return (cur -2 - buf); \ } \
hw/input/tsc2005.c +1 -1
@@ -513,7 +513,7 @@ static int tsc2005_load(QEMUFile *f, void *opaque, int version_id)for (i =0 ; i <8 ; i ++) s->tr[i] =qemu_get_be32 (f); - s->busy =qemu_timer_pending (s->timer); + s->busy =timer_pending (s->timer);tsc2005_pin_update (s);return 0 ;
hw/input/tsc210x.c +1 -1
@@ -1093,7 +1093,7 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id)for (i =0 ; i <0x14 ; i ++)qemu_get_be16s (f, &s->filter_data[i]); - s->busy =qemu_timer_pending (s->timer); + s->busy =timer_pending (s->timer);qemu_set_irq (s->pint, !s->irq);qemu_set_irq (s->davint, !s->dav);
hw/mips/cputimer.c +2 -2
@@ -72,8 +72,8 @@ uint32_t cpu_mips_get_count (CPUMIPSState *env)uint64_t now; now =qemu_get_clock_ns (vm_clock); -if (qemu_timer_pending (env->timer) - &&qemu_timer_expired (env->timer, now)) { +if (timer_pending (env->timer) + &&timer_expired (env->timer, now)) {/* The timer has already expired. */ cpu_mips_timer_expire (env); }
hw/openrisc/cputimer.c +1 -1
@@ -72,7 +72,7 @@ static void openrisc_timer_cb(void *opaque)OpenRISCCPU *cpu = opaque;if ((cpu->env.ttmr &TTMR_IE ) && -qemu_timer_expired (cpu->env.timer,qemu_get_clock_ns (vm_clock))) { +timer_expired (cpu->env.timer,qemu_get_clock_ns (vm_clock))) {CPUState *cs =CPU (cpu); cpu->env.ttmr |=TTMR_IP ;
hw/timer/mc146818rtc.c +3 -3
@@ -252,7 +252,7 @@ static void check_update_timer(RTCState *s)* the alarm time. */ next_update_time = s->next_alarm_time; } -if (next_update_time !=qemu_timer_expire_time_ns (s->update_timer)) { +if (next_update_time !=timer_expire_time_ns (s->update_timer)) {qemu_mod_timer (s->update_timer, next_update_time); } }
@@ -587,8 +587,8 @@ static int update_in_progress(RTCState *s)if (!rtc_running (s)) {return 0 ; } -if (qemu_timer_pending (s->update_timer)) { -int64_t next_update_time =qemu_timer_expire_time_ns (s->update_timer); +if (timer_pending (s->update_timer)) { +int64_t next_update_time =timer_expire_time_ns (s->update_timer);/* Latch UIP until the timer expires. */ if (qemu_get_clock_ns (rtc_clock) >= (next_update_time -UIP_HOLD_LENGTH )) { s->cmos_data[RTC_REG_A ] |=REG_A_UIP ;
hw/usb/redirect.c +2 -2
@@ -1493,7 +1493,7 @@ static void usbredir_device_connect(void *priv,USBRedirDevice *dev = priv;const char *speed; -if (qemu_timer_pending (dev->attach_timer) || dev->dev.attached) { +if (timer_pending (dev->attach_timer) || dev->dev.attached) {ERROR ("Received device connect while already connected\n" );return ; }
@@ -1588,7 +1588,7 @@ static void usbredir_interface_info(void *priv,* If we receive interface info after the device has already been * connected (ie on a set_config), re-check interface dependent things. */ -if (qemu_timer_pending (dev->attach_timer) || dev->dev.attached) { +if (timer_pending (dev->attach_timer) || dev->dev.attached) {usbredir_check_bulk_receiving (dev);if (usbredir_check_filter (dev)) { ERROR("Device no longer matches filter after interface info "
include/qemu/timer.h +3 -3
@@ -49,9 +49,9 @@ void qemu_free_timer(QEMUTimer *ts);void qemu_del_timer (QEMUTimer *ts);void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time);void qemu_mod_timer (QEMUTimer *ts,int64_t expire_time); -bool qemu_timer_pending (QEMUTimer *ts); -bool qemu_timer_expired (QEMUTimer *timer_head,int64_t current_time); -uint64_t qemu_timer_expire_time_ns (QEMUTimer *ts); +bool timer_pending (QEMUTimer *ts); +bool timer_expired (QEMUTimer *timer_head,int64_t current_time); +uint64_t timer_expire_time_ns (QEMUTimer *ts);void qemu_run_timers (QEMUClock *clock);void qemu_run_all_timers (void );
qemu-timer.c +10 -10
@@ -80,7 +80,7 @@ struct qemu_alarm_timer {static struct qemu_alarm_timer *alarm_timer; -static bool qemu_timer_expired_ns (QEMUTimer *timer_head,int64_t current_time) +static bool timer_expired_ns (QEMUTimer *timer_head,int64_t current_time) {return timer_head && (timer_head->expire_time <= current_time); }
@@ -301,7 +301,7 @@ void qemu_del_timer(QEMUTimer *ts)QEMUTimer **pt, *t;/* NOTE: this code must be signal safe because -qemu_timer_expired() can be called from a signal. */ +timer_expired() can be called from a signal. */ pt = &ts->clock->active_timers;for (;;) { t = *pt;
@@ -325,11 +325,11 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)/* add the timer in the sorted list */ /* NOTE: this code must be signal safe because -qemu_timer_expired() can be called from a signal. */ +timer_expired() can be called from a signal. */ pt = &ts->clock->active_timers;for (;;) { t = *pt; -if (!qemu_timer_expired_ns (t, expire_time)) { +if (!timer_expired_ns (t, expire_time)) {break ; } pt = &t->next;
@@ -356,7 +356,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)qemu_mod_timer_ns (ts, expire_time * ts->scale); } -bool qemu_timer_pending (QEMUTimer *ts) +bool timer_pending (QEMUTimer *ts) {QEMUTimer *t;for (t = ts->clock->active_timers; t !=NULL ; t = t->next) {
@@ -367,9 +367,9 @@ bool qemu_timer_pending(QEMUTimer *ts)return false; } -bool qemu_timer_expired (QEMUTimer *timer_head,int64_t current_time) +bool timer_expired (QEMUTimer *timer_head,int64_t current_time) { -return qemu_timer_expired_ns (timer_head, current_time * timer_head->scale); +return timer_expired_ns (timer_head, current_time * timer_head->scale); }void qemu_run_timers (QEMUClock *clock)
@@ -383,7 +383,7 @@ void qemu_run_timers(QEMUClock *clock) current_time =qemu_get_clock_ns (clock);for (;;) { ts = clock->active_timers; -if (!qemu_timer_expired_ns (ts, current_time)) { +if (!timer_expired_ns (ts, current_time)) {break ; }/* remove timer from the list before calling the callback */
@@ -439,9 +439,9 @@ void init_clocks(void) } } -uint64_t qemu_timer_expire_time_ns (QEMUTimer *ts) +uint64_t timer_expire_time_ns (QEMUTimer *ts) { -return qemu_timer_pending (ts) ? ts->expire_time :-1 ; +return timer_pending (ts) ? ts->expire_time :-1 ; }void qemu_run_all_timers (void )
savevm.c +1 -1
@@ -983,7 +983,7 @@ void qemu_put_timer(QEMUFile *f, QEMUTimer *ts) {uint64_t expire_time; - expire_time =qemu_timer_expire_time_ns (ts); + expire_time =timer_expire_time_ns (ts);qemu_put_be64 (f, expire_time); }
Signature · 1 line
1.7.9.5
RFC PATCH v10 2/31 aio / timers: Rename qemu_new_clock and expose clock types
In reply to Alex BlighRename qemu_new_clock to qemu_clock_new.
Expose clock types.
--- include/qemu/timer.h | 4 ++++ qemu-timer.c | 12 ++++-------- 2 files changed, 8 insertions(+), 8 deletions(-)
include/qemu/timer.h +4 -0
@@ -11,6 +11,10 @@#define SCALE_US 1000#define SCALE_NS 1 +#define QEMU_CLOCK_REALTIME 0 +#define QEMU_CLOCK_VIRTUAL 1 +#define QEMU_CLOCK_HOST 2 +typedef struct QEMUClock QEMUClock ;typedef void QEMUTimerCB (void *opaque);
qemu-timer.c +4 -8
@@ -40,10 +40,6 @@/***********************************************************/ /* timers */ -#define QEMU_CLOCK_REALTIME 0 -#define QEMU_CLOCK_VIRTUAL 1 -#define QEMU_CLOCK_HOST 2 -struct QEMUClock {QEMUTimer *active_timers;
@@ -231,7 +227,7 @@ QEMUClock *rt_clock;QEMUClock *vm_clock;QEMUClock *host_clock; -static QEMUClock *qemu_new_clock (int type) +static QEMUClock *qemu_clock_new (int type) {QEMUClock *clock;
@@ -433,9 +429,9 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier)void init_clocks (void ) {if (!rt_clock) { - rt_clock =qemu_new_clock (QEMU_CLOCK_REALTIME ); - vm_clock =qemu_new_clock (QEMU_CLOCK_VIRTUAL ); - host_clock =qemu_new_clock (QEMU_CLOCK_HOST ); + rt_clock =qemu_clock_new (QEMU_CLOCK_REALTIME ); + vm_clock =qemu_clock_new (QEMU_CLOCK_VIRTUAL ); + host_clock =qemu_clock_new (QEMU_CLOCK_HOST ); } }
Signature · 1 line
1.7.9.5
RFC PATCH v10 3/31 aio / timers: add qemu-timer.c utility functions
In reply to Alex BlighAdd utility functions to qemu-timer.c for nanosecond timing.
Add qemu_clock_deadline_ns to calculate deadlines to nanosecond accuracy.
Add utility function qemu_soonest_timeout to calculate soonest deadline.
Add qemu_timeout_ns_to_ms to convert a timeout in nanoseconds back to milliseconds for when ppoll is not used.
--- include/qemu/timer.h | 42 ++++++++++++++++++++++++++++++++++++++++++ qemu-timer.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+)
include/qemu/timer.h +42 -0
@@ -40,6 +40,29 @@ int64_t qemu_get_clock_ns(QEMUClock *clock);int64_t qemu_clock_has_timers (QEMUClock *clock);int64_t qemu_clock_expired (QEMUClock *clock);int64_t qemu_clock_deadline (QEMUClock *clock); + +/** +* qemu_clock_deadline_ns: +* @clock: the clock to operate on +* +* Calculate the timeout of the earliest expiring timer +* in nanoseconds, or -1 if no timer is set to expire. +* +* Returns: time until expiry in nanoseconds or -1 +*/ +int64_t qemu_clock_deadline_ns (QEMUClock *clock); + +/** +* qemu_timeout_ns_to_ms: +* @ns: nanosecond timeout value +* +* Convert a nanosecond timeout value (or -1) to +* a millisecond value (or -1), always rounding up. +* +* Returns: millisecond timeout value +*/ +int qemu_timeout_ns_to_ms (int64_t ns); +void qemu_clock_enable (QEMUClock *clock,bool enabled);void qemu_clock_warp (QEMUClock *clock);
@@ -67,6 +90,25 @@ int64_t cpu_get_ticks(void);void cpu_enable_ticks (void );void cpu_disable_ticks (void ); +/** +* qemu_soonest_timeout: +* @timeout1: first timeout in nanoseconds (or -1 for infinite) +* @timeout2: second timeout in nanoseconds (or -1 for infinite) +* +* Calculates the soonest of two timeout values. -1 means infinite, which +* is later than any other value. +* +* Returns: soonest timeout value in nanoseconds (or -1 for infinite) +*/ +static inline int64_t qemu_soonest_timeout (int64_t timeout1,int64_t timeout2) +{ +/* we can abuse the fact that -1 (which means infinite) is a maximal +* value when cast to unsigned. As this is disgusting, it's kept in +* one inline function. +*/ +return ((uint64_t ) timeout1 < (uint64_t ) timeout2) ? timeout1 : timeout2; +} +static inline QEMUTimer *qemu_new_timer_ns (QEMUClock *clock,QEMUTimerCB *cb,void *opaque) {
qemu-timer.c +50 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH v10 4/31 aio / timers: Consistent treatment of disabled clocks for deadlines
In reply to Alex BlighMake treatment of disabled clocks consistent in deadline calculation
--- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-timer.c +1 -1
@@ -264,7 +264,7 @@ int64_t qemu_clock_deadline(QEMUClock *clock)/* To avoid problems with overflow limit this to 2^32. */ int64_t delta =INT32_MAX ; -if (clock->active_timers) { +if (clock->enabled && clock->active_timers) { delta = clock->active_timers->expire_time -qemu_get_clock_ns (clock); }if (delta <0 ) {
Signature · 1 line
1.7.9.5
RFC PATCH v10 5/31 aio / timers: add ppoll support with qemu_poll_ns
In reply to Alex BlighAdd qemu_poll_ns which works like g_poll but takes a nanosecond timeout.
--- configure | 19 +++++++++++++++++++ include/qemu/timer.h | 12 ++++++++++++ qemu-timer.c | 24 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+)
configure +19 -0
@@ -2818,6 +2818,22 @@ if compile_prog "" "" ; then dup3=yes fi +# check for ppoll support +ppoll=no +cat > $TMPC << EOF +#include <poll.h> + +int main(void) +{ + struct pollfd pfd = { .fd = 0, .events = 0, .revents = 0 }; + ppoll(&pfd, 1, 0, 0); + return 0; +} +EOF +if compile_prog "" "" ; then + ppoll=yes +fi + # check for epoll support epoll=no cat > $TMPC << EOF
@@ -3814,6 +3830,9 @@ fi if test "$dup3" = "yes" ; then echo "CONFIG_DUP3=y" >> $config_host_mak fi +if test "$ppoll" = "yes" ; then + echo "CONFIG_PPOLL=y" >> $config_host_mak +fi if test "$epoll" = "yes" ; then echo "CONFIG_EPOLL=y" >> $config_host_mak fi
include/qemu/timer.h +12 -0
@@ -63,6 +63,18 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock);*/ int qemu_timeout_ns_to_ms (int64_t ns); +/** +* qemu_poll_ns: +* @fds: Array of file descriptors +* @nfds: number of file descriptors +* @timeout: timeout in nanoseconds +* +* Perform a poll like g_poll but with a timeout in nanoseconds. +* See g_poll documentation for further details. +* +* Returns: number of fds ready +*/ +int qemu_poll_ns (GPollFD *fds,uint nfds,int64_t timeout);void qemu_clock_enable (QEMUClock *clock,bool enabled);void qemu_clock_warp (QEMUClock *clock);
qemu-timer.c +24 -0
@@ -37,6 +37,10 @@#include <mmsystem.h> #endif +#ifdef CONFIG_PPOLL +#include <poll.h> +#endif +/***********************************************************/ /* timers */
@@ -323,6 +327,26 @@ int qemu_timeout_ns_to_ms(int64_t ns) } +/* qemu implementation of g_poll which uses a nanosecond timeout but is +* otherwise identical to g_poll +*/ +int qemu_poll_ns (GPollFD *fds,uint nfds,int64_t timeout) +{ +#ifdef CONFIG_PPOLL +if (timeout <0 ) { +return ppoll ((struct pollfd *)fds, nfds,NULL ,NULL ); + }else { +struct timespec ts; + ts.tv_sec = timeout /1000000000LL ; + ts.tv_nsec = timeout %1000000000LL ; +return ppoll ((struct pollfd *)fds, nfds, &ts,NULL ); + } +#else +return g_poll (fds, nfds,qemu_timeout_ns_to_ms (timeout)); +#endif +} + +QEMUTimer *qemu_new_timer (QEMUClock *clock,int scale,QEMUTimerCB *cb,void *opaque) {
Signature · 1 line
1.7.9.5
RFC PATCH v10 6/31 aio / timers: Add prctl(PR_SET_TIMERSLACK, 1, ...) to reduce timer slack
In reply to Alex BlighWhere supported, called prctl(PR_SET_TIMERSLACK, 1, ...) to set one nanosecond timer slack to increase precision of timer calls.
--- configure | 18 ++++++++++++++++++ qemu-timer.c | 7 +++++++ 2 files changed, 25 insertions(+)
configure +18 -0
@@ -2834,6 +2834,21 @@ if compile_prog "" "" ; then ppoll=yes fi +# check for prctl(PR_SET_TIMERSLACK , ... ) support +prctl_pr_set_timerslack=no +cat > $TMPC << EOF +#include <sys/prctl.h> + +int main(void) +{ + prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0); + return 0; +} +EOF +if compile_prog "" "" ; then + prctl_pr_set_timerslack=yes +fi + # check for epoll support epoll=no cat > $TMPC << EOF
@@ -3833,6 +3848,9 @@ fi if test "$ppoll" = "yes" ; then echo "CONFIG_PPOLL=y" >> $config_host_mak fi +if test "$prctl_pr_set_timerslack" = "yes" ; then + echo "CONFIG_PRCTL_PR_SET_TIMERSLACK=y" >> $config_host_mak +fi if test "$epoll" = "yes" ; then echo "CONFIG_EPOLL=y" >> $config_host_mak fi
qemu-timer.c +7 -0
@@ -41,6 +41,10 @@#include <poll.h> #endif +#ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK +#include <sys/prctl.h> +#endif +/***********************************************************/ /* timers */
@@ -507,6 +511,9 @@ void init_clocks(void) vm_clock =qemu_clock_new (QEMU_CLOCK_VIRTUAL ); host_clock =qemu_clock_new (QEMU_CLOCK_HOST ); } +#ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK +prctl (PR_SET_TIMERSLACK ,1 ,0 ,0 ,0 ); +#endif }uint64_t timer_expire_time_ns (QEMUTimer *ts)
Signature · 1 line
1.7.9.5
RFC PATCH v10 7/31 aio / timers: Make qemu_run_timers and qemu_run_all_timers return progress
In reply to Alex BlighMake qemu_run_timers and qemu_run_all_timers return progress so that aio_poll etc. can determine whether a timer has been run.
--- include/qemu/timer.h | 21 +++++++++++++++++++-- qemu-timer.c | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-)
include/qemu/timer.h +19 -2
@@ -92,8 +92,25 @@ bool timer_pending(QEMUTimer *ts);bool timer_expired (QEMUTimer *timer_head,int64_t current_time);uint64_t timer_expire_time_ns (QEMUTimer *ts); -void qemu_run_timers (QEMUClock *clock); -void qemu_run_all_timers (void ); +/** +* qemu_run_timers: +* @clock: clock on which to operate +* +* Run all the timers associated with a clock. +* +* Returns: true if any timer ran. +*/ +bool qemu_run_timers (QEMUClock *clock); + +/** +* qemu_run_all_timers: +* +* Run all the timers associated with every clock. +* +* Returns: true if any timer ran. +*/ +bool qemu_run_all_timers (void ); +void configure_alarms (char const *opt);void init_clocks (void );int init_timer_alarm (void );
qemu-timer.c +12 -6
@@ -446,13 +446,14 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time)return timer_expired_ns (timer_head, current_time * timer_head->scale); } -void qemu_run_timers (QEMUClock *clock) +bool qemu_run_timers (QEMUClock *clock) {QEMUTimer *ts;int64_t current_time; +bool progress = false;if (!clock->enabled) -return ; +return progress; current_time =qemu_get_clock_ns (clock);for (;;) {
@@ -466,7 +467,9 @@ void qemu_run_timers(QEMUClock *clock)/* run the callback (the timer list can be modified) */ ts->cb (ts->opaque); + progress = true; } +return progress; }int64_t qemu_get_clock_ns (QEMUClock *clock)
@@ -521,20 +524,23 @@ uint64_t timer_expire_time_ns(QEMUTimer *ts)return timer_pending (ts) ? ts->expire_time :-1 ; } -void qemu_run_all_timers (void ) +bool qemu_run_all_timers (void ) { +bool progress = false; alarm_timer->pending = false;/* vm time timers */ -qemu_run_timers (vm_clock); -qemu_run_timers (rt_clock); -qemu_run_timers (host_clock); + progress |=qemu_run_timers (vm_clock); + progress |=qemu_run_timers (rt_clock); + progress |=qemu_run_timers (host_clock);/* rearm timer, if not periodic */ if (alarm_timer->expired) { alarm_timer->expired = false;qemu_rearm_alarm_timer (alarm_timer); } + +return progress; }#ifdef _WIN32
Signature · 1 line
1.7.9.5
RFC PATCH v10 8/31 aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
In reply to Alex BlighSplit QEMUClock into QEMUClock and QEMUTimerList so that we can have more than one QEMUTimerList associated with the same clock.
Introduce a main_loop_timerlist concept and make existing qemu_clock_* calls that actually should operate on a QEMUTimerList call the relevant QEMUTimerList implementations, using the clock's default timerlist. This vastly reduces the invasiveness of this change and means the API stays constant for existing users.
Introduce a list of QEMUTimerLists associated with each clock so that reenabling the clock can cause all the notifiers to be called. Note the code to do the notifications is added in a later patch.
Switch QEMUClockType to an enum. Remove global variables vm_clock, host_clock and rt_clock and add compatibility defines. Do not fix qemu_next_alarm_deadline as it's going to be deleted.
Add qemu_clock_use_for_deadline to indicate whether a particular clock should be used for deadline calculations. When use_icount is true, vm_clock should not be used for deadline calculations as it does not contain a nanosecond count. Instead, icount timeouts come from the execution thread doing aio_notify or qemu_notify as appropriate. This function is used in the next patch.
--- include/qemu/timer.h | 347 ++++++++++++++++++++++++++++++++++++++++++++++---- qemu-timer.c | 207 ++++++++++++++++++++++-------- 2 files changed, 475 insertions(+), 79 deletions(-)
include/qemu/timer.h +324 -23
@@ -11,34 +11,84 @@#define SCALE_US 1000#define SCALE_NS 1 -#define QEMU_CLOCK_REALTIME 0 -#define QEMU_CLOCK_VIRTUAL 1 -#define QEMU_CLOCK_HOST 2 +/** +* QEMUClockType: +* +* The following clock types are available: +* +* @QEMU_CLOCK_REALTIME: Real time clock +* +* The real time clock should be used only for stuff which does not +* change the virtual machine state, as it is run even if the virtual +* machine is stopped. The real time clock has a frequency of 1000 +* Hz. +* +* Formerly rt_clock +* +* @QEMU_CLOCK_VIRTUAL: virtual clock +* +* The virtual clock is only run during the emulation. It is stopped +* when the virtual machine is stopped. Virtual timers use a high +* precision clock, usually cpu cycles (use ticks_per_sec). +* +* Formerly vm_clock +* +* @QEMU_CLOCK_HOST: host clock +* +* The host clock should be use for device models that emulate accurate +* real time sources. It will continue to run when the virtual machine +* is suspended, and it will reflect system time changes the host may +* undergo (e.g. due to NTP). The host clock has the same precision as +* the virtual clock. +* +* Formerly host_clock +*/ + +typedef enum { +QEMU_CLOCK_REALTIME =0 , +QEMU_CLOCK_VIRTUAL =1 , +QEMU_CLOCK_HOST =2 , +QEMU_CLOCK_MAX +}QEMUClockType ;typedef struct QEMUClock QEMUClock ; +typedef struct QEMUTimerList QEMUTimerList ;typedef void QEMUTimerCB (void *opaque); -/* The real time clock should be used only for stuff which does not -change the virtual machine state, as it is run even if the virtual -machine is stopped. The real time clock has a frequency of 1000 -Hz. */ -extern QEMUClock *rt_clock; +typedef struct QEMUTimer { +int64_t expire_time;/* in nanoseconds */ +QEMUTimerList *timer_list; +QEMUTimerCB *cb; +void *opaque; +QEMUTimer *next; +int scale; +}QEMUTimer ; + +extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX ]; -/* The virtual clock is only run during the emulation. It is stopped -when the virtual machine is stopped. Virtual timers use a high -precision clock, usually cpu cycles (use ticks_per_sec). */ -extern QEMUClock *vm_clock; +/** +* qemu_clock_ptr: +* @type: type of clock +* +* Translate a clock type into a pointer to QEMUClock object. +* +* Returns: a pointer to the QEMUClock object +*/ +static inline QEMUClock *qemu_clock_ptr (QEMUClockType type) +{ +return qemu_clocks[type]; +} -/* The host clock should be use for device models that emulate accurate -real time sources. It will continue to run when the virtual machine -is suspended, and it will reflect system time changes the host may -undergo (e.g. due to NTP). The host clock has the same precision as -the virtual clock. */ -extern QEMUClock *host_clock; +/* These three clocks are maintained here with separate variable +* names for compatibility only. +*/ +#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) +#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) +#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST))int64_t qemu_get_clock_ns (QEMUClock *clock); -int64_t qemu_clock_has_timers (QEMUClock *clock); -int64_t qemu_clock_expired (QEMUClock *clock); +bool qemu_clock_has_timers (QEMUClock *clock); +bool qemu_clock_expired (QEMUClock *clock);int64_t qemu_clock_deadline (QEMUClock *clock);/**
@@ -53,6 +103,121 @@ int64_t qemu_clock_deadline(QEMUClock *clock);int64_t qemu_clock_deadline_ns (QEMUClock *clock);/** +* qemu_clock_use_for_deadline: +* @clock: the clock to operate on +* +* Determine whether a clock should be used for deadline +* calculations. Some clocks, for instance vm_clock with +* use_icount set, do not count in nanoseconds. Such clocks +* are not used for deadline calculations, and are presumed +* to interrupt any poll using qemu_notify/aio_notify +* etc. +* +* Returns: true if the clock runs in nanoseconds and +* should be used for a deadline. +*/ +bool qemu_clock_use_for_deadline (QEMUClock *clock); + +/** +* qemu_clock_get_main_loop_timerlist: +* @clock: the clock to operate on +* +* Return the default timer list assocatiated with a clock. +* +* Returns: the default timer list +*/ +QEMUTimerList *qemu_clock_get_main_loop_timerlist (QEMUClock *clock); + +/** +* timerlist_new: +* @type: the clock type to associate with the timerlist +* +* Create a new timerlist associated with the clock of +* type @type. +* +* Returns: a pointer to the QEMUTimerList created +*/ +QEMUTimerList *timerlist_new (QEMUClockType type); + +/** +* timerlist_free: +* @timer_list: the timer list to free +* +* Frees a timer_list. It must have no active timers. +*/ +void timerlist_free (QEMUTimerList *timer_list); + +/** +* timerlist_has_timers: +* @timer_list: the timer list to operate on +* +* Determine whether a timer list has active timers +* +* Returns: true if the timer list has timers. +*/ +bool timerlist_has_timers (QEMUTimerList *timer_list); + +/** +* timerlist_expired: +* @timer_list: the timer list to operate on +* +* Determine whether a timer list has any timers which +* are expired. +* +* Returns: true if the timer list has timers which +* have expired. +*/ +bool timerlist_expired (QEMUTimerList *timer_list); + +/** +* timerlist_deadline: +* @timer_list: the timer list to operate on +* +* Determine the deadline for a timer_list. This is +* a legacy function which returns INT32_MAX if the +* timer list has no timers or if the earliest timer +* expires later than INT32_MAX nanoseconds away. +* +* Returns: the number of nanoseconds until the earliest +* timer expires or INT32_MAX in the situations listed +* above +*/ +int64_t timerlist_deadline (QEMUTimerList *timer_list); + +/** +* timerlist_deadline_ns: +* @timer_list: the timer list to operate on +* +* Determine the deadline for a timer_list, i.e. +* the number of nanoseconds until the first timer +* expires. Return -1 if there are no timers. +* +* Returns: the number of nanoseconds until the earliest +* timer expires -1 if none +*/ +int64_t timerlist_deadline_ns (QEMUTimerList *timer_list); + +/** +* timerlist_getclock: +* @timer_list: the timer list to operate on +* +* Determine the clock associated with a timer list. +* +* Returns: the clock associated with the timer list. +*/ +QEMUClock *timerlist_get_clock (QEMUTimerList *timer_list); + +/** +* timerlist_run_timers: +* @timer_list: the timer list to use +* +* Call all expired timers associated with the timer list. +* +* Returns: true if any timer expired +*/ +bool timerlist_run_timers (QEMUTimerList *timer_list); + +/** * qemu_timeout_ns_to_ms: * @ns: nanosecond timeout value *
@@ -84,6 +249,50 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock,QEMUTimer *qemu_new_timer (QEMUClock *clock,int scale,QEMUTimerCB *cb,void *opaque); + +/** +* timer_init: +* @ts: the timer to be initialised +* @timer_list: the timer list to attach the timer to +* @scale: the scale value for the tiemr +* @cb: the callback to be called when the timer expires +* @opaque: the opaque pointer to be passed to the callback +* +* Initialise a new timer and associate it with @timer_list. +* The caller is responsible for allocating the memory. +* +* You need not call an explicit deinit call. Simply make +* sure it is not on a list with timer_del. +*/ +void timer_init (QEMUTimer *ts, +QEMUTimerList *timer_list,int scale, +QEMUTimerCB *cb,void *opaque); + +/** +* timer_new_tl: +* @timer_list: the timer list to attach the timer to +* @scale: the scale value for the tiemr +* @cb: the callback to be called when the timer expires +* @opaque: the opaque pointer to be passed to the callback +* +* Creeate a new timer and associate it with @timer_list. +* The memory is allocated by the function. +* +* This is not the preferred interface unless you know you +* are going to call timer_free. Use timer_init instead. +* +* Returns: a pointer to the timer +*/ +static inline QEMUTimer *timer_new_tl (QEMUTimerList *timer_list, +int scale, +QEMUTimerCB *cb, +void *opaque) +{ +QEMUTimer *ts =g_malloc0 (sizeof (QEMUTimer)); +timer_init (ts, timer_list, scale, cb, opaque); +return ts; +} +void qemu_free_timer (QEMUTimer *ts);void qemu_del_timer (QEMUTimer *ts);void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time);
@@ -92,11 +301,61 @@ bool timer_pending(QEMUTimer *ts);bool timer_expired (QEMUTimer *timer_head,int64_t current_time);uint64_t timer_expire_time_ns (QEMUTimer *ts); +/* New format calling conventions for timers */ + +/** +* timer_free: +* @ts: the timer +* +* Free a timer (it must not be on the active list) +*/ +static inline void timer_free (QEMUTimer *ts) +{ +qemu_free_timer (ts); +} + +/** +* timer_del: +* @ts: the timer +* +* Delete a timer from the active list. +*/ +static inline void timer_del (QEMUTimer *ts) +{ +qemu_del_timer (ts); +} + +/** +* timer_mod_ns: +* @ts: the timer +* @expire_time: the expiry time in nanoseconds +* +* Modify a timer to expire at @expire_time +*/ +static inline void timer_mod_ns (QEMUTimer *ts,int64_t expire_time) +{ +qemu_mod_timer_ns (ts, expire_time); +} + +/** +* timer_mod: +* @ts: the timer +* @expire_time: the expire time in the units associated with the timer +* +* Modify a timer to expiry at @expire_time, taking into +* account the scale associated with the timer. +*/ +static inline void timer_mod (QEMUTimer *ts,int64_t expire_timer) +{ +qemu_mod_timer (ts, expire_timer); +} +/** * qemu_run_timers: * @clock: clock on which to operate * -* Run all the timers associated with a clock. +* Run all the timers associated with the default timer list +* of a clock. * * Returns: true if any timer ran. */
@@ -105,7 +364,8 @@ bool qemu_run_timers(QEMUClock *clock);/** * qemu_run_all_timers: * -* Run all the timers associated with every clock. +* Run all the timers associated with the default timer list +* of every clock. * * Returns: true if any timer ran. */
@@ -138,13 +398,54 @@ static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2)return ((uint64_t ) timeout1 < (uint64_t ) timeout2) ? timeout1 : timeout2; } +/** +* qemu_new_timer_ns: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with nanosecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ static inline QEMUTimer *qemu_new_timer_ns (QEMUClock *clock,QEMUTimerCB *cb,void *opaque) {return qemu_new_timer (clock,SCALE_NS , cb, opaque); } -static inline QEMUTimer *qemu_new_timer_ms (QEMUClock *clock,QEMUTimerCB *cb, +/** +* qemu_new_timer_us: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with microsecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ +static inline QEMUTimer *qemu_new_timer_us (QEMUClock *clock, +QEMUTimerCB *cb, +void *opaque) +{ +return qemu_new_timer (clock,SCALE_US , cb, opaque); +} + +/** +* qemu_new_timer_ms: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with millisecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ +static inline QEMUTimer *qemu_new_timer_ms (QEMUClock *clock, +QEMUTimerCB *cb,void *opaque) {return qemu_new_timer (clock,SCALE_MS , cb, opaque);
qemu-timer.c +151 -56
364 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [RFC] [PATCHv10 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
Quoted 90 lines · Alex Bligh
Split QEMUClock into QEMUClock and QEMUTimerList so that we can have more than one QEMUTimerList associated with the same clock.
Introduce a
main_loop_timerlistconcept and make existing qemu_clock_* calls that actually should operate on a QEMUTimerList call the relevant QEMUTimerList implementations, using the clock's default timerlist. This vastly reduces the invasiveness of this change and means the API stays constant for existing users.Introduce a list of QEMUTimerLists associated with each clock so that reenabling the clock can cause all the notifiers to be called. Note the code to do the notifications is added in a later patch.
Switch QEMUClockType to an enum. Remove global variables
vm_clock,host_clockandrt_clockand add compatibility defines. Do not fixqemu_next_alarm_deadlineas it's going to be deleted.Add
qemu_clock_use_for_deadlineto indicate whether a particular clock should be used for deadline calculations. Whenuse_icountis true,vm_clockshould not be used for deadline calculations as it does not contain a nanosecond count. Instead, icount timeouts come from the execution thread doingaio_notifyorqemu_notifyas appropriate. This function is used in the next patch.Signed-off-by Alex Bligh <[email protected]>--- include/qemu/timer.h | 347 ++++++++++++++++++++++++++++++++++++++++++++++---- qemu-timer.c | 207 ++++++++++++++++++++++-------- 2 files changed, 475 insertions(+), 79 deletions(-)include/qemu/timer.h +40
-6@@ -11,34 +11,84 @@#define SCALE_US 1000#define SCALE_NS 1 -#define QEMU_CLOCK_REALTIME 0 -#define QEMU_CLOCK_VIRTUAL 1 -#define QEMU_CLOCK_HOST 2 +/** +* QEMUClockType: +* +* The following clock types are available: +* +* @QEMU_CLOCK_REALTIME: Real time clock +* +* The real time clock should be used only for stuff which does not +* change the virtual machine state, as it is run even if the virtual +* machine is stopped. The real time clock has a frequency of 1000 +* Hz. +* +* Formerly rt_clock +* +* @QEMU_CLOCK_VIRTUAL: virtual clock +* +* The virtual clock is only run during the emulation. It is stopped +* when the virtual machine is stopped. Virtual timers use a high +* precision clock, usually cpu cycles (use ticks_per_sec). +* +* Formerly vm_clock +* +* @QEMU_CLOCK_HOST: host clock +* +* The host clock should be use for device models that emulate accurate +* real time sources. It will continue to run when the virtual machine +* is suspended, and it will reflect system time changes the host may +* undergo (e.g. due to NTP). The host clock has the same precision as +* the virtual clock. +* +* Formerly host_clock +*/ + +typedef enum { +QEMU_CLOCK_REALTIME =0 , +QEMU_CLOCK_VIRTUAL =1 , +QEMU_CLOCK_HOST =2 , +QEMU_CLOCK_MAX +}QEMUClockType ;typedef struct QEMUClock QEMUClock ; +typedef struct QEMUTimerList QEMUTimerList ;typedef void QEMUTimerCB (void *opaque); -/* The real time clock should be used only for stuff which does not -change the virtual machine state, as it is run even if the virtual -machine is stopped. The real time clock has a frequency of 1000
include/qemu/timer.h line 65
Quoted 10 lines
include/qemu/timer.h +8
-2-Hz. */ -extern QEMUClock *rt_clock; +typedef struct QEMUTimer { +int64_t expire_time;/* in nanoseconds */ +QEMUTimerList *timer_list; +QEMUTimerCB *cb; +void *opaque; +QEMUTimer *next; +int scale; +}QEMUTimer ;
The typedef part is a duplication of what we already have in qemu/typedefs.h and breaks the build for me. Just declare the struct here.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [RFC] [PATCHv10 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
Quoted 2 lines · Jan Kiszka
The typedef part is a duplication of what we already have in
qemu/typedefs.hand breaks the build for me. Just declare the struct here.
You mean one can't do
typedef struct foo foo;
...
typedef struct foo {
...
} foo;
?
I don't even get a warning for that. Learn a new thing every day. OK will fix. I guess that means timer.h needs to explicitly include typedefs.h in case whatever is including timer.h does not first include typedefs.h.
Signature · 1 line
Alex Bligh
Re: [Qemu-devel] [RFC] [PATCHv10 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
Quoted 8 lines · Alex Bligh
Quoted 2 lines · Jan Kiszka
The typedef part is a duplication of what we already have in
qemu/typedefs.hand breaks the build for me. Just declare the struct here.You mean one can't do
Quoted 7 lines
typedef struct foo foo;
...
typedef struct foo {
...
} foo;?
Yes, at least according to the standard. Older gcc seem to reject it, newer may have relaxed this by default.
Quoted 5 lines
I don't even get a warning for that. Learn a new thing every day. OK will fix. I guess that means
timer.hneeds to explicitly includetypedefs.hin case whatever is includingtimer.hdoes not first includetypedefs.h.
It works without explicit including as most users pull in qemu-common.h as well, but it's cleaner of course.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [RFC] [PATCHv10 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
In reply to Alex BlighQuoted 9 lines · Alex Bligh
You mean one can't do
typedef struct foo foo;
...
typedef struct foo {
...
} foo;?
No, but you can do
typedef struct foo foo;
...
struct foo {
};
It's the double typedef that's the problem.
r~
Re: [Qemu-devel] [RFC] [PATCHv10 08/31] aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList
Quoted 11 lines · Richard Henderson
Quoted 9 lines · Alex Bligh
You mean one can't do
typedef struct foo foo;
...
typedef struct foo {
...
} foo;?
Quoted 8 lines
No, but you can do
typedef struct foo foo;
...
struct foo {
};It's the double typedef that's the problem.
Yup I realise that - I just didn't know that was an error.
The problem is that include file A which has the struct definition in doesn't know whether include file B which has the definition in has been included or not.
So if file B has
typedef struct foo foo;
and file A defines struct foo, then
a) if A uses typedef, this will fail if bar.c includes B then A
b) if A does not use typedef, this will fail if baz.c does not include B then A.
The only reasonable solution would appear to be to move all the typedefs to typedefs.h and ensure that is included by .h file. Yuck. And only ever typedef in one include file.
Signature · 1 line
Alex Bligh
RFC PATCH v10 9/31 aio / timers: Untangle include files
In reply to Alex Blighinclude/qemu/timer.h has no need to include main-loop.h and doing so causes an issue for the next patch. Unfortunately various files assume including timers.h will pull in main-loop.h. Untangle this mess.
--- dma-helpers.c | 1 + hw/dma/xilinx_axidma.c | 1 + hw/timer/arm_timer.c | 1 + hw/timer/exynos4210_mct.c | 1 + hw/timer/exynos4210_pwm.c | 1 + hw/timer/grlib_gptimer.c | 2 ++ hw/timer/imx_epit.c | 1 + hw/timer/imx_gpt.c | 1 + hw/timer/lm32_timer.c | 1 + hw/timer/puv3_ost.c | 1 + hw/timer/sh_timer.c | 1 + hw/timer/slavio_timer.c | 1 + hw/timer/xilinx_timer.c | 1 + hw/tpm/tpm_tis.c | 1 + hw/usb/hcd-uhci.c | 1 + include/block/block_int.h | 1 + include/block/coroutine.h | 2 ++ include/qemu/timer.h | 1 - migration-exec.c | 1 + migration-fd.c | 1 + migration-tcp.c | 1 + migration-unix.c | 1 + migration.c | 1 + nbd.c | 1 + net/net.c | 1 + net/socket.c | 1 + qemu-coroutine-io.c | 1 + qemu-io-cmds.c | 1 + qemu-nbd.c | 1 + slirp/misc.c | 1 + thread-pool.c | 1 + ui/vnc-auth-sasl.h | 1 + ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 1 + 34 files changed, 35 insertions(+), 2 deletions(-)
dma-helpers.c +1 -0
@@ -11,6 +11,7 @@#include "trace.h" #include "qemu/range.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" /* #define DEBUG_IOMMU */
hw/dma/xilinx_axidma.c +1 -0
@@ -27,6 +27,7 @@#include "hw/ptimer.h" #include "qemu/log.h" #include "qapi/qmp/qerror.h" +#include "qemu/main-loop.h" #include "hw/stream.h"
hw/timer/arm_timer.c +1 -0
@@ -12,6 +12,7 @@#include "qemu-common.h" #include "hw/qdev.h" #include "hw/ptimer.h" +#include "qemu/main-loop.h" /* Common timer implementation. */
hw/timer/exynos4210_mct.c +1 -0
@@ -54,6 +54,7 @@#include "hw/sysbus.h" #include "qemu/timer.h" +#include "qemu/main-loop.h" #include "qemu-common.h" #include "hw/ptimer.h"
hw/timer/exynos4210_pwm.c +1 -0
@@ -23,6 +23,7 @@#include "hw/sysbus.h" #include "qemu/timer.h" #include "qemu-common.h" +#include "qemu/main-loop.h" #include "hw/ptimer.h" #include "hw/arm/exynos4210.h"
hw/timer/grlib_gptimer.c +2 -0
@@ -25,6 +25,8 @@#include "hw/sysbus.h" #include "qemu/timer.h" #include "hw/ptimer.h" +#include "qemu/timer.h" +#include "qemu/main-loop.h" #include "trace.h"
hw/timer/imx_epit.c +1 -0
@@ -18,6 +18,7 @@#include "hw/ptimer.h" #include "hw/sysbus.h" #include "hw/arm/imx.h" +#include "qemu/main-loop.h" #define TYPE_IMX_EPIT "imx.epit"
hw/timer/imx_gpt.c +1 -0
@@ -18,6 +18,7 @@#include "hw/ptimer.h" #include "hw/sysbus.h" #include "hw/arm/imx.h" +#include "qemu/main-loop.h" #define TYPE_IMX_GPT "imx.gpt"
hw/timer/lm32_timer.c +1 -0
@@ -27,6 +27,7 @@#include "qemu/timer.h" #include "hw/ptimer.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #define DEFAULT_FREQUENCY (50*1000000)
hw/timer/puv3_ost.c +1 -0
@@ -10,6 +10,7 @@*/ #include "hw/sysbus.h" #include "hw/ptimer.h" +#include "qemu/main-loop.h" #undef DEBUG_PUV3#include "hw/unicore32/puv3.h"
hw/timer/sh_timer.c +1 -0
@@ -11,6 +11,7 @@#include "hw/hw.h" #include "hw/sh4/sh.h" #include "qemu/timer.h" +#include "qemu/main-loop.h" #include "exec/address-spaces.h" #include "hw/ptimer.h"
hw/timer/slavio_timer.c +1 -0
@@ -27,6 +27,7 @@#include "hw/ptimer.h" #include "hw/sysbus.h" #include "trace.h" +#include "qemu/main-loop.h" /* * Registers of hardware timer in sun4m.
hw/timer/xilinx_timer.c +1 -0
@@ -25,6 +25,7 @@#include "hw/sysbus.h" #include "hw/ptimer.h" #include "qemu/log.h" +#include "qemu/main-loop.h" #define D (x)
hw/tpm/tpm_tis.c +1 -0
@@ -28,6 +28,7 @@#include "hw/pci/pci_ids.h" #include "tpm_tis.h" #include "qemu-common.h" +#include "qemu/main-loop.h" /*#define DEBUG_TIS */
hw/usb/hcd-uhci.c +1 -0
@@ -32,6 +32,7 @@#include "qemu/iov.h" #include "sysemu/dma.h" #include "trace.h" +#include "qemu/main-loop.h" //#define DEBUG //#define DEBUG_DUMP_DATA
include/block/block_int.h +1 -0
@@ -34,6 +34,7 @@#include "monitor/monitor.h" #include "qemu/hbitmap.h" #include "block/snapshot.h" +#include "qemu/main-loop.h" #define BLOCK_FLAG_ENCRYPT 1#define BLOCK_FLAG_COMPAT6 4
include/block/coroutine.h +2 -0
@@ -19,6 +19,8 @@#include "qemu/queue.h" #include "qemu/timer.h" +typedef struct AioContext AioContext ; +/** * Coroutines are a mechanism for stack switching and can be used for * cooperative userspace threading. These functions provide a simple but
include/qemu/timer.h +0 -1
@@ -2,7 +2,6 @@#define QEMU_TIMER_H #include "qemu-common.h" -#include "qemu/main-loop.h" #include "qemu/notify.h" /* timers */
migration-exec.c +1 -0
@@ -17,6 +17,7 @@#include "qemu-common.h" #include "qemu/sockets.h" +#include "qemu/main-loop.h" #include "migration/migration.h" #include "migration/qemu-file.h" #include "block/block.h"
migration-fd.c +1 -0
@@ -14,6 +14,7 @@*/ #include "qemu-common.h" +#include "qemu/main-loop.h" #include "qemu/sockets.h" #include "migration/migration.h" #include "monitor/monitor.h"
migration-tcp.c +1 -0
@@ -18,6 +18,7 @@#include "migration/migration.h" #include "migration/qemu-file.h" #include "block/block.h" +#include "qemu/main-loop.h" //#define DEBUG_MIGRATION_TCP
migration-unix.c +1 -0
@@ -15,6 +15,7 @@#include "qemu-common.h" #include "qemu/sockets.h" +#include "qemu/main-loop.h" #include "migration/migration.h" #include "migration/qemu-file.h" #include "block/block.h"
migration.c +1 -0
@@ -14,6 +14,7 @@*/ #include "qemu-common.h" +#include "qemu/main-loop.h" #include "migration/migration.h" #include "monitor/monitor.h" #include "migration/qemu-file.h"
nbd.c +1 -0
@@ -38,6 +38,7 @@#include "qemu/sockets.h" #include "qemu/queue.h" +#include "qemu/main-loop.h" //#define DEBUG_NBD
net/net.c +1 -0
@@ -36,6 +36,7 @@#include "qmp-commands.h" #include "hw/qdev.h" #include "qemu/iov.h" +#include "qemu/main-loop.h" #include "qapi-visit.h" #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h"
net/socket.c +1 -0
@@ -31,6 +31,7 @@#include "qemu/option.h" #include "qemu/sockets.h" #include "qemu/iov.h" +#include "qemu/main-loop.h" typedef struct NetSocketState { NetClientState nc;
qemu-coroutine-io.c +1 -0
@@ -26,6 +26,7 @@#include "qemu/sockets.h" #include "block/coroutine.h" #include "qemu/iov.h" +#include "qemu/main-loop.h" ssize_t coroutine_fn qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
qemu-io-cmds.c +1 -0
@@ -10,6 +10,7 @@#include "qemu-io.h" #include "block/block_int.h" +#include "qemu/main-loop.h" #define CMD_NOFILE_OK 0x01
qemu-nbd.c +1 -0
@@ -19,6 +19,7 @@#include "qemu-common.h" #include "block/block.h" #include "block/nbd.h" +#include "qemu/main-loop.h" #include <stdarg.h> #include <stdio.h>
slirp/misc.c +1 -0
@@ -9,6 +9,7 @@#include <libslirp.h> #include "monitor/monitor.h" +#include "qemu/main-loop.h" #ifdef DEBUG int slirp_debug =DBG_CALL |DBG_MISC |DBG_ERROR ;
thread-pool.c +1 -0
@@ -23,6 +23,7 @@#include "block/block_int.h" #include "qemu/event_notifier.h" #include "block/thread-pool.h" +#include "qemu/main-loop.h" static void do_spawn_thread (ThreadPool *pool);
ui/vnc-auth-sasl.h +1 -0
@@ -33,6 +33,7 @@ typedef struct VncStateSASL VncStateSASL;typedef struct VncDisplaySASL VncDisplaySASL ;#include "qemu/acl.h" +#include "qemu/main-loop.h" struct VncStateSASL {sasl_conn_t *conn;
ui/vnc-auth-vencrypt.c +1 -1
@@ -25,7 +25,7 @@*/ #include "vnc.h" - +#include "qemu/main-loop.h" static void start_auth_vencrypt_subauth (VncState *vs) {
ui/vnc-ws.c +1 -0
@@ -19,6 +19,7 @@*/ #include "vnc.h" +#include "qemu/main-loop.h" #ifdef CONFIG_VNC_TLS #include "qemu/sockets.h"
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [RFC] [PATCHv10 09/31] aio / timers: Untangle include files
Quoted 5 lines · Alex Bligh
include/qemu/timer.hhas no need to includemain-loop.hand doing so causes an issue for the next patch. Unfortunately various files assume includingtimers.hwill pull inmain-loop.h. Untangle this mess.
Hmm, this triggers a double typedef of AioContext for me. I've resolved it like the QEMUTimer issue: moved the typedef to typedefs.h.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [RFC] [PATCHv10 09/31] aio / timers: Untangle include files
Jan,
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Alex Bligh
include/qemu/timer.hhas no need to includemain-loop.hand doing so causes an issue for the next patch. Unfortunately various files assume includingtimers.hwill pull inmain-loop.h. Untangle this mess.Hmm, this triggers a double typedef of AioContext for me. I've resolved it like the QEMUTimer issue: moved the typedef to
typedefs.h.
For clarity, you mean in include/block/aio.h:
typedef struct AioContext {
becomes
include/block/aio.h:struct AioContext {
and then in include/qemu/typedefs.h add:
typedef struct AioContext AioContext;
(just so I can get it right in v11 as I don't see your error here)
Signature · 1 line
Alex Bligh
Re: [Qemu-devel] [RFC] [PATCHv10 09/31] aio / timers: Untangle include files
Quoted 14 lines · Alex Bligh
Jan,
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Alex Bligh
include/qemu/timer.hhas no need to includemain-loop.hand doing so causes an issue for the next patch. Unfortunately various files assume includingtimers.hwill pull inmain-loop.h. Untangle this mess.Hmm, this triggers a double typedef of AioContext for me. I've resolved it like the QEMUTimer issue: moved the typedef to
typedefs.h.
Quoted 7 lines
For clarity, you mean in
include/block/aio.h:
typedef struct AioContext {
becomes
include/block/aio.h:struct AioContext {and then in
include/qemu/typedefs.hadd:
typedef struct AioContext AioContext;
Yes, and remove the typedef from coroutine.h (that's the duplication).
Quoted 3 lines
(just so I can get it right in v11 as I don't see your error here)
This can be an independent patch, in fact. You don't introduce the issue, just expose it this way.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
RFC PATCH v10 10/31 aio / timers: Add QEMUTimerListGroup and helper functions
In reply to Alex BlighAdd QEMUTimerListGroup and helper functions, to represent a QEMUTimerList associated with each clock. Add a default QEMUTimerListGroup representing the default timer lists which are not associated with any other object (e.g. an AioContext as added by future patches).
--- include/qemu/timer.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ qemu-timer.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+)
include/qemu/timer.h +49 -0
@@ -52,6 +52,11 @@ typedef enum {typedef struct QEMUClock QEMUClock ;typedef struct QEMUTimerList QEMUTimerList ; + +typedef struct QEMUTimerListGroup { +QEMUTimerList *tl[QEMU_CLOCK_MAX ]; +}QEMUTimerListGroup ; +typedef void QEMUTimerCB (void *opaque); typedef struct QEMUTimer {
@@ -63,6 +68,7 @@ typedef struct QEMUTimer {int scale; } QEMUTimer; +extern QEMUTimerListGroup main_loop_tlg;extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX ];/**
@@ -217,6 +223,49 @@ QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list);bool timerlist_run_timers (QEMUTimerList *timer_list);/** +* timerlistgroup_init: +* @tlg: the timer list group +* +* Initialise a timer list group. This must already be +* allocated in memory and zeroed. +*/ +void timerlistgroup_init (QEMUTimerListGroup *tlg); + +/** +* timerlistgroup_deinit: +* @tlg: the timer list group +* +* Deinitialise a timer list group. This must already be +* initialised. Note the memory is not freed. +*/ +void timerlistgroup_deinit (QEMUTimerListGroup *tlg); + +/** +* timerlistgroup_run_timers: +* @tlg: the timer list group +* +* Run the timers associated with a timer list group. +* This will run timers on multiple clocks. +* +* Returns: true if any timer callback ran +*/ +bool timerlistgroup_run_timers (QEMUTimerListGroup *tlg); + +/** +* timerlistgroup_deadline_ns +* @tlg: the timer list group +* +* Determine the deadline of the soonest timer to +* expire associated with any timer list linked to +* the timer list group. Only clocks suitable for +* deadline calculation are included. +* +* Returns: the deadline in nanoseconds or -1 if no +* timers are to expire. +*/ +int64_t timerlistgroup_deadline_ns (QEMUTimerListGroup *tlg); + +/** * qemu_timeout_ns_to_ms: * @ns: nanosecond timeout value *
qemu-timer.c +42 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH v10 11/31 aio / timers: Add QEMUTimerListGroup to AioContext
In reply to Alex BlighAdd a QEMUTimerListGroup each AioContext (meaning a QEMUTimerList associated with each clock is added) and delete it when the AioContext is freed.
--- async.c | 2 ++ include/block/aio.h | 4 ++++ tests/test-aio.c | 3 +++ tests/test-thread-pool.c | 3 +++ 4 files changed, 12 insertions(+)
async.c +2 -0
@@ -205,6 +205,7 @@ aio_ctx_finalize(GSource *source)event_notifier_cleanup (&ctx->notifier);qemu_mutex_destroy (&ctx->bh_lock);g_array_free (ctx->pollfds, TRUE); +timerlistgroup_deinit (&ctx->tlg); }static GSourceFuncs aio_source_funcs = {
@@ -244,6 +245,7 @@ AioContext *aio_context_new(void)aio_set_event_notifier (ctx, &ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear,NULL ); +timerlistgroup_init (&ctx->tlg);return ctx; }
include/block/aio.h +4 -0
@@ -18,6 +18,7 @@#include "qemu/queue.h" #include "qemu/event_notifier.h" #include "qemu/thread.h" +#include "qemu/timer.h" typedef struct BlockDriverAIOCB BlockDriverAIOCB ;typedef void BlockDriverCompletionFunc (void *opaque,int ret);
@@ -72,6 +73,9 @@ typedef struct AioContext {/* Thread pool for performing work and receiving completion callbacks */ struct ThreadPool *thread_pool; + +/* TimerLists for calling timers - one per clock type */ +QEMUTimerListGroup tlg; } AioContext;/* Returns 1 if there are still outstanding AIO requests; 0 otherwise */
tests/test-aio.c +3 -0
@@ -12,6 +12,7 @@#include <glib.h> #include "block/aio.h" +#include "qemu/timer.h" AioContext *ctx;
@@ -628,6 +629,8 @@ int main(int argc, char **argv) {GSource *src; +init_clocks (); + ctx =aio_context_new (); src =aio_get_g_source (ctx);g_source_attach (src,NULL );
tests/test-thread-pool.c +3 -0
@@ -3,6 +3,7 @@#include "block/aio.h" #include "block/thread-pool.h" #include "block/block.h" +#include "qemu/timer.h" static AioContext *ctx;static ThreadPool *pool;
@@ -205,6 +206,8 @@ int main(int argc, char **argv) {int ret; +init_clocks (); + ctx =aio_context_new (); pool =aio_get_thread_pool (ctx);
Signature · 1 line
1.7.9.5
RFC PATCH v10 12/31 aio / timers: Add a notify callback to QEMUTimerList
In reply to Alex BlighAdd a notify pointer to QEMUTimerList so it knows what to notify on a timer change.
--- async.c | 7 ++++++- include/qemu/timer.h | 27 +++++++++++++++++++++++---- qemu-timer.c | 31 ++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 12 deletions(-)
async.c +6 -1
@@ -234,6 +234,11 @@ void aio_notify(AioContext *ctx)event_notifier_set (&ctx->notifier); } +static void aio_timerlist_notify (void *opaque) +{ +aio_notify (opaque); +} +AioContext *aio_context_new (void ) {AioContext *ctx;
@@ -245,7 +250,7 @@ AioContext *aio_context_new(void)aio_set_event_notifier (ctx, &ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear,NULL ); -timerlistgroup_init (&ctx->tlg); +timerlistgroup_init (&ctx->tlg, aio_timerlist_notify, ctx);return ctx; }
include/qemu/timer.h +23 -4
@@ -58,6 +58,7 @@ typedef struct QEMUTimerListGroup { } QEMUTimerListGroup;typedef void QEMUTimerCB (void *opaque); +typedef void QEMUTimerListNotifyCB (void *opaque); typedef struct QEMUTimer { int64_t expire_time; /* in nanoseconds */
@@ -136,13 +137,16 @@ QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock);/** * timerlist_new: * @type: the clock type to associate with the timerlist +* @cb: the callback to call on notification +* @opaque: the opaque pointer to pass to the callback * * Create a new timerlist associated with the clock of * type @type. * * Returns: a pointer to the QEMUTimerList created */ -QEMUTimerList *timerlist_new (QEMUClockType type); +QEMUTimerList *timerlist_new (QEMUClockType type, +QEMUTimerListNotifyCB *cb,void *opaque);/** * timerlist_free:
@@ -223,13 +227,28 @@ QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list);bool timerlist_run_timers (QEMUTimerList *timer_list);/** +* timerlist_notify: +* @timer_list: the timer list to use +* +* call the notifier callback associated with the timer list. +*/ +void timerlist_notify (QEMUTimerList *timer_list); + +/** * timerlistgroup_init: * @tlg: the timer list group +* @cb: the callback to call when a notify is required +* @opaque: the opaque pointer to be passed to the callback. * * Initialise a timer list group. This must already be -* allocated in memory and zeroed. -*/ -void timerlistgroup_init (QEMUTimerListGroup *tlg); +* allocated in memory and zeroed. The notifier callback is +* called whenever a clock in the timer list group is +* reenabled or whenever a timer associated with any timer +* list is modified. If @cb is specified as null, qemu_notify() +* is used instead. +*/ +void timerlistgroup_init (QEMUTimerListGroup *tlg, +QEMUTimerListNotifyCB *cb,void *opaque);/** * timerlistgroup_deinit:
qemu-timer.c +24 -7
@@ -73,6 +73,8 @@ struct QEMUTimerList {QEMUClock *clock;QEMUTimer *active_timers;QLIST_ENTRY (QEMUTimerList) list; +QEMUTimerListNotifyCB *notify_cb; +void *notify_opaque; };struct qemu_alarm_timer {
@@ -243,7 +245,9 @@ next: } } -static QEMUTimerList *timerlist_new_from_clock (QEMUClock *clock) +static QEMUTimerList *timerlist_new_from_clock (QEMUClock *clock, +QEMUTimerListNotifyCB *cb, +void *opaque) {QEMUTimerList *timer_list;
@@ -257,13 +261,16 @@ static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) timer_list =g_malloc0 (sizeof (QEMUTimerList)); timer_list->clock = clock; + timer_list->notify_cb = cb; + timer_list->notify_opaque = opaque;QLIST_INSERT_HEAD (&clock->timerlists, timer_list, list);return timer_list; } -QEMUTimerList *timerlist_new (QEMUClockType type) +QEMUTimerList *timerlist_new (QEMUClockType type, +QEMUTimerListNotifyCB *cb,void *opaque) { -return timerlist_new_from_clock (qemu_clock_ptr (type)); +return timerlist_new_from_clock (qemu_clock_ptr (type), cb, opaque); }void timerlist_free (QEMUTimerList *timer_list)
@@ -288,7 +295,7 @@ static QEMUClock *qemu_clock_new(QEMUClockType type) clock->last =INT64_MIN ;QLIST_INIT (&clock->timerlists);notifier_list_init (&clock->reset_notifiers); - clock->main_loop_timerlist =timerlist_new_from_clock (clock); + clock->main_loop_timerlist =timerlist_new_from_clock (clock,NULL ,NULL );return clock; }
@@ -386,6 +393,15 @@ QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock)return clock->main_loop_timerlist; } +void timerlist_notify (QEMUTimerList *timer_list) +{ +if (timer_list->notify_cb) { + timer_list->notify_cb (timer_list->notify_opaque); + }else { +qemu_notify_event (); + } +} +/* Transition function to convert a nanosecond timeout to ms * This is used where a system does not support ppoll */
@@ -507,7 +523,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)/* Interrupt execution to force deadline recalculation. */ qemu_clock_warp (ts->timer_list->clock);if (use_icount) { -qemu_notify_event (); +timerlist_notify (ts->timer_list); } } }
@@ -565,11 +581,12 @@ bool qemu_run_timers(QEMUClock *clock)return timerlist_run_timers (clock->main_loop_timerlist); } -void timerlistgroup_init (QEMUTimerListGroup *tlg) +void timerlistgroup_init (QEMUTimerListGroup *tlg, +QEMUTimerListNotifyCB *cb,void *opaque) {QEMUClockType type;for (type =0 ; type <QEMU_CLOCK_MAX ; type++) { - tlg->tl[type] =timerlist_new (type); + tlg->tl[type] =timerlist_new (type, cb, opaque); } }
Signature · 1 line
1.7.9.5
RFC PATCH v10 13/31 aio / timers: aio_ctx_prepare sets timeout from AioContext timers
In reply to Alex BlighCalculate the timeout in aio_ctx_prepare taking into account the timers attached to the AioContext.
Alter aio_ctx_check similarly.
--- async.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
async.c +11 -2
@@ -150,13 +150,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) {AioContext *ctx = (AioContext *) source;QEMUBH *bh; +int deadline;for (bh = ctx->first_bh; bh; bh = bh->next) {if (!bh->deleted && bh->scheduled) {if (bh->idle) {/* idle bottom halves will be polled at least * every 10ms */ - *timeout =10 ; + *timeout =qemu_soonest_timeout (*timeout,10 ); }else {/* non-idle bottom halves will be executed * immediately */
@@ -166,6 +167,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) } } + deadline =qemu_timeout_ns_to_ms (timerlistgroup_deadline_ns (&ctx->tlg)); +if (deadline ==0 ) { + *timeout =0 ; +return true; + }else { + *timeout =qemu_soonest_timeout (*timeout, deadline); + } +return false; }
@@ -180,7 +189,7 @@ aio_ctx_check(GSource *source)return true; } } -return aio_pending (ctx); +return aio_pending (ctx) || (timerlistgroup_deadline_ns (&ctx->tlg) ==0 ); } static gboolean
Signature · 1 line
1.7.9.5
RFC PATCH v10 14/31 aio / timers: Add aio_timer_init & aio_timer_new wrappers
In reply to Alex BlighAdd aio_timer_init and aio_timer_new wrapper functions.
--- include/block/aio.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
include/block/aio.h +43 -0
@@ -255,4 +255,47 @@ void qemu_aio_set_fd_handler(int fd, void *opaque);#endif +/** +* aio_timer_new: +* @ctx: the aio context +* @type: the clock type +* @scale: the scale +* @cb: the callback to call on timer expiry +* @opaque: the opaque pointer to pass to the callback +* +* Allocate a new timer attached to the context @ctx. +* The function is responsible for memory allocation. +* +* The preferred interface is aio_timer_init. Use that +* unless you really need dynamic memory allocation. +* +* Returns: a pointer to the new timer +*/ +static inline QEMUTimer *aio_timer_new (AioContext *ctx,QEMUClockType type, +int scale, +QEMUTimerCB *cb,void *opaque) +{ +return timer_new_tl (ctx->tlg.tl[type], scale, cb, opaque); +} + +/** +* aio_timer_init: +* @ctx: the aio context +* @ts: the timer +* @type: the clock type +* @scale: the scale +* @cb: the callback to call on timer expiry +* @opaque: the opaque pointer to pass to the callback +* +* Initialise a new timer attached to the context @ctx. +* The caller is responsible for memory allocation. +*/ +static inline void aio_timer_init (AioContext *ctx, +QEMUTimer *ts,QEMUClockType type, +int scale, +QEMUTimerCB *cb,void *opaque) +{ +timer_init (ts, ctx->tlg.tl[type], scale, cb, opaque); +} +#endif
Signature · 1 line
1.7.9.5
RFC PATCH v10 15/31 aio / timers: Convert aio_poll to use AioContext timers' deadline
In reply to Alex BlighConvert aio_poll to use deadline based on AioContext's timers.
aio_poll has been changed to return accurately whether progress has occurred. Prior to this commit, aio_poll always returned true if g_poll was entered, whether or not any progress was made. This required a change to tests/test-aio.c where an assert was backwards.
--- aio-posix.c | 20 +++++++++++++------- aio-win32.c | 22 +++++++++++++++++++--- tests/test-aio.c | 4 ++-- 3 files changed, 34 insertions(+), 12 deletions(-)
aio-posix.c +13 -7
@@ -166,6 +166,10 @@ static bool aio_dispatch(AioContext *ctx)g_free (tmp); } } + +/* Run our timers */ + progress |=timerlistgroup_run_timers (&ctx->tlg); +return progress; }
@@ -232,9 +236,9 @@ bool aio_poll(AioContext *ctx, bool blocking) }/* wait until next event */ - ret =g_poll ((GPollFD *)ctx->pollfds->data, - ctx->pollfds->len, - blocking ?-1 :0 ); + ret =qemu_poll_ns ((GPollFD *)ctx->pollfds->data, + ctx->pollfds->len, + blocking ?timerlistgroup_deadline_ns (&ctx->tlg) :0 );/* if we have any readable fds, dispatch event */ if (ret >0 ) {
@@ -245,11 +249,13 @@ bool aio_poll(AioContext *ctx, bool blocking) node->pfd.revents = pfd->revents; } } -if (aio_dispatch (ctx)) { - progress = true; - } + } + +/* Run dispatch even if there were no readable fds to run timers */ +if (aio_dispatch (ctx)) { + progress = true; }assert (progress || busy); -return true; +return progress; }
aio-win32.c +19 -3
@@ -98,6 +98,7 @@ bool aio_poll(AioContext *ctx, bool blocking)HANDLE events[MAXIMUM_WAIT_OBJECTS +1 ];bool busy, progress;int count; +int timeout; progress = false;
@@ -111,6 +112,9 @@ bool aio_poll(AioContext *ctx, bool blocking) progress = true; } +/* Run timers */ + progress |=timerlistgroup_run_timers (&ctx->tlg); +/* * Then dispatch any pending callbacks from the GSource. *
@@ -174,8 +178,11 @@ bool aio_poll(AioContext *ctx, bool blocking)/* wait until next event */ while (count >0 ) { -int timeout = blocking ?INFINITE :0 ; -int ret =WaitForMultipleObjects (count, events, FALSE, timeout); +int ret; + + timeout = blocking ? +qemu_timeout_ns_to_ms (timerlistgroup_deadline_ns (&ctx->tlg)) :0 ; + ret =WaitForMultipleObjects (count, events, FALSE, timeout);/* if we have any signaled events, dispatch event */ if ((DWORD ) (ret -WAIT_OBJECT_0 ) >= count) {
@@ -214,6 +221,15 @@ bool aio_poll(AioContext *ctx, bool blocking) events[ret -WAIT_OBJECT_0 ] = events[--count]; } +if (blocking) { +/* Run the timers a second time. We do this because otherwise aio_wait +* will not note progress - and will stop a drain early - if we have +* a timer that was not ready to run entering g_poll but is ready +* after g_poll. This will only do anything if a timer has expired. +*/ + progress |=timerlistgroup_run_timers (ctx->timer_list); + } +assert (progress || busy); -return true; +return progress; }
tests/test-aio.c +2 -2
@@ -316,13 +316,13 @@ static void test_wait_event_notifier_noflush(void)event_notifier_set (&data.e);g_assert (aio_poll (ctx, false)); g_assert_cmpint(data.n, ==, 1); -g_assert (aio_poll (ctx, false)); +g_assert (!aio_poll (ctx, false)); g_assert_cmpint(data.n, ==, 1);event_notifier_set (&data.e);g_assert (aio_poll (ctx, false)); g_assert_cmpint(data.n, ==, 2); -g_assert (aio_poll (ctx, false)); +g_assert (!aio_poll (ctx, false)); g_assert_cmpint(data.n, ==, 2);event_notifier_set (&dummy.e);
Signature · 1 line
1.7.9.5
RFC PATCH v10 16/31 aio / timers: Convert mainloop to use timeout
In reply to Alex BlighConvert mainloop to use timeout from default timerlist group (i.e. the current 3 static timers)
--- main-loop.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-)
main-loop.c +34 -11
@@ -155,10 +155,11 @@ static int max_priority;static int glib_pollfds_idx;static int glib_n_poll_fds; -static void glib_pollfds_fill (uint32_t *cur_timeout) +static void glib_pollfds_fill (int64_t *cur_timeout) {GMainContext *context =g_main_context_default ();int timeout =0 ; +int64_t timeout_ns;int n;g_main_context_prepare (context, &max_priority);
@@ -174,9 +175,13 @@ static void glib_pollfds_fill(uint32_t *cur_timeout) glib_n_poll_fds); }while (n != glib_n_poll_fds); -if (timeout >=0 && timeout < *cur_timeout) { - *cur_timeout = timeout; +if (timeout <0 ) { + timeout_ns =-1 ; + }else { + timeout_ns = (int64_t )timeout * (int64_t )SCALE_MS ; } + + *cur_timeout =qemu_soonest_timeout (timeout_ns, *cur_timeout); }static void glib_pollfds_poll (void )
@@ -191,7 +196,7 @@ static void glib_pollfds_poll(void)#define MAX_MAIN_LOOP_SPIN (1000) -static int os_host_main_loop_wait (uint32_t timeout) +static int os_host_main_loop_wait (int64_t timeout) {int ret;static int spin_counter;
@@ -214,7 +219,7 @@ static int os_host_main_loop_wait(uint32_t timeout) notified = true; } - timeout =1 ; + timeout =SCALE_MS ; }if (timeout >0 ) {
@@ -224,7 +229,7 @@ static int os_host_main_loop_wait(uint32_t timeout) spin_counter++; } - ret =g_poll ((GPollFD *)gpollfds->data, gpollfds->len, timeout); + ret =qemu_poll_ns ((GPollFD *)gpollfds->data, gpollfds->len, timeout);if (timeout >0 ) {qemu_mutex_lock_iothread ();
@@ -373,7 +378,7 @@ static void pollfds_poll(GArray *pollfds, int nfds, fd_set *rfds, } } -static int os_host_main_loop_wait (uint32_t timeout) +static int os_host_main_loop_wait (int64_t timeout) {GMainContext *context =g_main_context_default ();GPollFD poll_fds[1024 *2 ];/* this is probably overkill */
@@ -382,6 +387,7 @@ static int os_host_main_loop_wait(uint32_t timeout)PollingEntry *pe;WaitObjects *w = &wait_objects;gint poll_timeout; +int64_t poll_timeout_ns;static struct timeval tv0;fd_set rfds, wfds, xfds;int nfds;
@@ -419,12 +425,17 @@ static int os_host_main_loop_wait(uint32_t timeout) poll_fds[n_poll_fds + i].events =G_IO_IN ; } -if (poll_timeout <0 || timeout < poll_timeout) { - poll_timeout = timeout; +if (poll_timeout <0 ) { + poll_timeout_ns =-1 ; + }else { + poll_timeout_ns = (int64_t )poll_timeout * (int64_t )SCALE_MS ; } + poll_timeout_ns =qemu_soonest_timeout (poll_timeout_ns, timeout); +qemu_mutex_unlock_iothread (); - g_poll_ret =g_poll (poll_fds, n_poll_fds + w->num, poll_timeout); + g_poll_ret =qemu_poll_ns (poll_fds, n_poll_fds + w->num, poll_timeout_ns); +qemu_mutex_lock_iothread ();if (g_poll_ret >0 ) {for (i =0 ; i < w->num; i++) {
@@ -449,6 +460,7 @@ int main_loop_wait(int nonblocking) {int ret;uint32_t timeout =UINT32_MAX ; +int64_t timeout_ns;if (nonblocking) { timeout =0 ;
@@ -462,7 +474,18 @@ int main_loop_wait(int nonblocking)slirp_pollfds_fill (gpollfds);#endif qemu_iohandler_fill (gpollfds); - ret =os_host_main_loop_wait (timeout); + +if (timeout ==UINT32_MAX ) { + timeout_ns =-1 ; + }else { + timeout_ns = (uint64_t )timeout * (int64_t )(SCALE_MS ); + } + + timeout_ns =qemu_soonest_timeout (timeout_ns, +timerlistgroup_deadline_ns ( + &main_loop_tlg)); + + ret =os_host_main_loop_wait (timeout_ns);qemu_iohandler_poll (gpollfds, ret);#ifdef CONFIG_SLIRP slirp_pollfds_poll (gpollfds, (ret <0 ));
Signature · 1 line
1.7.9.5
RFC PATCH v10 17/31 aio / timers: On timer modification, qemu_notify or aio_notify
In reply to Alex BlighOn qemu_mod_timer_ns, ensure qemu_notify or aio_notify is called to end the appropriate poll(), irrespective of use_icount value.
On qemu_clock_enable, ensure qemu_notify or aio_notify is called for all QEMUTimerLists attached to the QEMUClock.
--- include/qemu/timer.h | 9 +++++++++ qemu-timer.c | 13 ++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-)
include/qemu/timer.h +9 -0
@@ -135,6 +135,15 @@ bool qemu_clock_use_for_deadline(QEMUClock *clock);QEMUTimerList *qemu_clock_get_main_loop_timerlist (QEMUClock *clock);/** +* qemu_clock_nofify: +* @clock: the clock to operate on +* +* Call the notifier callback connected with the default timer +* list linked to the clock, or qemu_notify() if none. +*/ +void qemu_clock_notify (QEMUClock *clock); + +/** * timerlist_new: * @type: the clock type to associate with the timerlist * @cb: the callback to call on notification
qemu-timer.c +10 -3
@@ -304,11 +304,20 @@ bool qemu_clock_use_for_deadline(QEMUClock *clock)return !(use_icount && (clock->type ==QEMU_CLOCK_VIRTUAL )); } +void qemu_clock_notify (QEMUClock *clock) +{ +QEMUTimerList *timer_list; + QLIST_FOREACH(timer_list, &clock->timerlists, list) { +timerlist_notify (timer_list); + } +} +void qemu_clock_enable (QEMUClock *clock,bool enabled) {bool old = clock->enabled; clock->enabled = enabled;if (enabled && !old) { +qemu_clock_notify (clock);qemu_rearm_alarm_timer (alarm_timer); } }
@@ -522,9 +531,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) }/* Interrupt execution to force deadline recalculation. */ qemu_clock_warp (ts->timer_list->clock); -if (use_icount) { -timerlist_notify (ts->timer_list); - } +timerlist_notify (ts->timer_list); } }
Signature · 1 line
1.7.9.5
RFC PATCH v10 18/31 aio / timers: Introduce new API timer_new and friends
In reply to Alex BlighIntroduce new API for creating timers - timer_new and _ns, _ms, _us derivatives.
--- include/qemu/timer.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
include/qemu/timer.h +69 -0
@@ -369,6 +369,24 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list,return ts; } +/** +* timer_new: +* @type: the clock type to use +* @scale: the scale value for the tiemr +* @cb: the callback to be called when the timer expires +* @opaque: the opaque pointer to be passed to the callback +* +* Creeate a new timer and associate it with the default +* timer list for the clock type @type. +* +* Returns: a pointer to the timer +*/ +static inline QEMUTimer *timer_new (QEMUClockType type,int scale, +QEMUTimerCB *cb,void *opaque) +{ +return timer_new_tl (main_loop_tlg.tl[type], scale, cb, opaque); +} +void qemu_free_timer (QEMUTimer *ts);void qemu_del_timer (QEMUTimer *ts);void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time);
@@ -492,6 +510,23 @@ static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, }/** +* timer_new_ns: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with nanosecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ +static inline QEMUTimer *timer_new_ns (QEMUClockType type,QEMUTimerCB *cb, +void *opaque) +{ +return timer_new (type,SCALE_NS , cb, opaque); +} + +/** * qemu_new_timer_us: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires
@@ -510,6 +545,23 @@ static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, }/** +* timer_new_us: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with microsecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ +static inline QEMUTimer *timer_new_us (QEMUClockType type,QEMUTimerCB *cb, +void *opaque) +{ +return timer_new (type,SCALE_US , cb, opaque); +} + +/** * qemu_new_timer_ms: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires
@@ -527,6 +579,23 @@ static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock,return qemu_new_timer (clock,SCALE_MS , cb, opaque); } +/** +* timer_new_ms: +* @clock: the clock to associate with the timer +* @callback: the callback to call when the timer expires +* @opaque: the opaque pointer to pass to the callback +* +* Create a new timer with millisecond scale on the default timer list +* associated with the clock. +* +* Returns: a pointer to the newly created timer +*/ +static inline QEMUTimer *timer_new_ms (QEMUClockType type,QEMUTimerCB *cb, +void *opaque) +{ +return timer_new (type,SCALE_MS , cb, opaque); +} +static inline int64_t qemu_get_clock_ms (QEMUClock *clock) {return qemu_get_clock_ns (clock) /SCALE_MS ;
Signature · 1 line
1.7.9.5
RFC PATCH v10 19/31 aio / timers: Use all timerlists in icount warp calculations
In reply to Alex BlighNotify all timerlists derived from vm_clock in icount warp calculations.
When calculating timer delay based on vm_clock deadline, use all timerlists.
For compatibility, maintain an apparent bug where when using icount, if no vm_clock timer was set, qemu_clock_deadline would return INT32_MAX and always set an icount clock expiry about 2 seconds ahead.
NB: thread safety - when different timerlists sit on different threads, this will need some locking.
--- cpus.c | 46 +++++++++++++++++++++++++++++++++++++--------- include/qemu/timer.h | 13 +++++++++++++ qemu-timer.c | 16 ++++++++++++++++ qtest.c | 2 +- 4 files changed, 67 insertions(+), 10 deletions(-)
cpus.c +37 -9
@@ -262,7 +262,7 @@ static void icount_warp_rt(void *opaque) qemu_icount_bias +=MIN (warp_delta, delta); }if (qemu_clock_expired (vm_clock)) { -qemu_notify_event (); +qemu_clock_notify (vm_clock); } } vm_clock_warp_start =-1 ;
@@ -273,13 +273,13 @@ void qtest_clock_warp(int64_t dest)int64_t clock =qemu_get_clock_ns (vm_clock);assert (qtest_enabled ());while (clock < dest) { -int64_t deadline =qemu_clock_deadline (vm_clock); +int64_t deadline =qemu_clock_deadline_ns_all (vm_clock);int64_t warp =MIN (dest - clock, deadline); qemu_icount_bias += warp;qemu_run_timers (vm_clock); clock =qemu_get_clock_ns (vm_clock); } -qemu_notify_event (); +qemu_clock_notify (vm_clock); }void qemu_clock_warp (QEMUClock *clock)
@@ -314,7 +314,18 @@ void qemu_clock_warp(QEMUClock *clock) } vm_clock_warp_start =qemu_get_clock_ns (rt_clock); - deadline =qemu_clock_deadline (vm_clock); +/* We want to use the earliest deadline from ALL vm_clocks */ + deadline =qemu_clock_deadline_ns_all (vm_clock); + +/* Maintain prior (possibly buggy) behaviour where if no deadline +* was set (as there is no vm_clock timer) or it is more than +* INT32_MAX nanoseconds ahead, we still use INT32_MAX +* nanoseconds. +*/ +if ((deadline <0 ) || (deadline >INT32_MAX )) { + deadline =INT32_MAX ; + } +if (deadline >0 ) {/* * Ensure the vm_clock proceeds even when the virtual CPU goes to
@@ -333,8 +344,8 @@ void qemu_clock_warp(QEMUClock *clock)* packets continuously instead of every 100ms. */ qemu_mod_timer (icount_warp_timer, vm_clock_warp_start + deadline); - }else { -qemu_notify_event (); + }else if (deadline ==0 ) { +qemu_clock_notify (vm_clock); } }
@@ -866,8 +877,13 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)while (1 ) {tcg_exec_all (); -if (use_icount &&qemu_clock_deadline (vm_clock) <=0 ) { -qemu_notify_event (); + +if (use_icount) { +int64_t deadline =qemu_clock_deadline_ns_all (vm_clock); + +if (deadline ==0 ) { +qemu_clock_notify (vm_clock); + } }qemu_tcg_wait_io_event (); }
@@ -1145,11 +1161,23 @@ static int tcg_cpu_exec(CPUArchState *env)#endif if (use_icount) {int64_t count; +int64_t deadline;int decr; qemu_icount -= (env->icount_decr.u16.low + env->icount_extra); env->icount_decr.u16.low =0 ; env->icount_extra =0 ; - count =qemu_icount_round (qemu_clock_deadline (vm_clock)); + deadline =qemu_clock_deadline_ns_all (vm_clock); + +/* Maintain prior (possibly buggy) behaviour where if no deadline +* was set (as there is no vm_clock timer) or it is more than +* INT32_MAX nanoseconds ahead, we still use INT32_MAX +* nanoseconds. +*/ +if ((deadline <0 ) || (deadline >INT32_MAX )) { + deadline =INT32_MAX ; + } + + count =qemu_icount_round (deadline); qemu_icount += count; decr = (count >0xffff ) ?0xffff : count; count -= decr;
include/qemu/timer.h +13 -0
@@ -102,6 +102,7 @@ int64_t qemu_clock_deadline(QEMUClock *clock);* @clock: the clock to operate on * * Calculate the timeout of the earliest expiring timer +* on the default timer list associated with the clock * in nanoseconds, or -1 if no timer is set to expire. * * Returns: time until expiry in nanoseconds or -1
@@ -125,6 +126,18 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock);bool qemu_clock_use_for_deadline (QEMUClock *clock);/** +* qemu_clock_use_for_deadline: +* @clock: the clock to operate on +* +* Calculate the deadline across all timer lists associated +* with a clock (as opposed to just the default one) +* in nanoseconds, or -1 if no timer is set to expire. +* +* Returns: time until expiry in nanoseconds or -1 +*/ +int64_t qemu_clock_deadline_ns_all (QEMUClock *clock); + +/** * qemu_clock_get_main_loop_timerlist: * @clock: the clock to operate on *
qemu-timer.c +16 -0
@@ -392,6 +392,22 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock)return timerlist_deadline_ns (clock->main_loop_timerlist); } +/* Calculate the soonest deadline across all timerlists attached +* to the clock. This is used for the icount timeout so we +* ignore whether or not the clock should be used in deadline +* calculations. +*/ +int64_t qemu_clock_deadline_ns_all (QEMUClock *clock) +{ +int64_t deadline =-1 ; +QEMUTimerList *timer_list; + QLIST_FOREACH(timer_list, &clock->timerlists, list) { + deadline =qemu_soonest_timeout (deadline, +timerlist_deadline_ns (timer_list)); + } +return deadline; +} +QEMUClock *timerlist_get_clock (QEMUTimerList *timer_list) {return timer_list->clock;
qtest.c +1 -1
@@ -412,7 +412,7 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)if (words[1 ]) { ns =strtoll (words[1 ],NULL ,0 ); }else { - ns =qemu_clock_deadline (vm_clock); + ns =qemu_clock_deadline_ns_all (vm_clock); }qtest_clock_warp (qemu_get_clock_ns (vm_clock) + ns);qtest_send_prefix (chr);
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [RFC] [PATCHv10 19/31] aio / timers: Use all timerlists in icount warp calculations
Quoted 7 lines · Alex Bligh
cpus.c +2
-1@@ -314,7 +314,18 @@ void qemu_clock_warp(QEMUClock *clock) } vm_clock_warp_start =qemu_get_clock_ns (rt_clock); - deadline =qemu_clock_deadline (vm_clock); +/* We want to use the earliest deadline from ALL vm_clocks */ + deadline =qemu_clock_deadline_ns_all (vm_clock);
cpus.c void qemu_clock_warp(QEMUClock *clock) · line 328
Quoted 10 lines
cpus.c +10
-0+ +/* Maintain prior (possibly buggy) behaviour where if no deadline +* was set (as there is no vm_clock timer) or it is more than +* INT32_MAX nanoseconds ahead, we still use INT32_MAX +* nanoseconds. +*/ +if ((deadline <0 ) || (deadline >INT32_MAX )) { + deadline =INT32_MAX ; + } +
I see no value in a spurious wakeup if no deadline was set, but it's harmless.
As for overflow, I don't really understand how INT32_MAX prevents overflow. If the base timer value we're adding to is already huge then INT32_MAX could still overflow it.
cpus.c void qemu_clock_warp(QEMUClock *clock) · line 348
Quoted 11 lines
cpus.c +2
-2if (deadline >0 ) {/* * Ensure the vm_clock proceeds even when the virtual CPU goes to @@ -333,8 +344,8 @@ void qemu_clock_warp(QEMUClock *clock)* packets continuously instead of every 100ms. */ qemu_mod_timer (icount_warp_timer, vm_clock_warp_start + deadline); - }else { -qemu_notify_event (); + }else if (deadline ==0 ) { +qemu_clock_notify (vm_clock);
It seems this change is just for clarity: deadline can either be >0 or 0? I think a plain else statement is clearer and doesn't leave you wondering in what case this qemu_clock_notify() isn't taken.
Re: [Qemu-devel] [RFC] [PATCHv10 19/31] aio / timers: Use all timerlists in icount warp calculations
Quoted 22 lines · Stefan Hajnoczi
Quoted 7 lines · Alex Bligh
cpus.c +2
-1@@ -314,7 +314,18 @@ void qemu_clock_warp(QEMUClock *clock) } vm_clock_warp_start =qemu_get_clock_ns (rt_clock); - deadline =qemu_clock_deadline (vm_clock); +/* We want to use the earliest deadline from ALL vm_clocks */ + deadline =qemu_clock_deadline_ns_all (vm_clock);cpus.c void qemu_clock_warp(QEMUClock *clock) · line 328
Quoted 10 lines
cpus.c +10
-0+ +/* Maintain prior (possibly buggy) behaviour where if no deadline +* was set (as there is no vm_clock timer) or it is more than +* INT32_MAX nanoseconds ahead, we still use INT32_MAX +* nanoseconds. +*/ +if ((deadline <0 ) || (deadline >INT32_MAX )) { + deadline =INT32_MAX ; + } +I see no value in a spurious wakeup if no deadline was set, but it's harmless.
Quoted 3 lines
As for overflow, I don't really understand how
INT32_MAXprevents overflow. If the base timer value we're adding to is already huge thenINT32_MAXcould still overflow it.
This is my understanding. I don't think we need to worry about overflowing int64_t.
Quoted 7 lines
Quoted 7 lines
cpus.c +0
-0if (deadline >0 ) {/* * Ensure the vm_clock proceeds even when the virtual CPU goes to @@ -333,8 +344,8 @@ void qemu_clock_warp(QEMUClock *clock)* packets continuously instead of every 100ms. */ qemu_mod_timer (icount_warp_timer, vm_clock_warp_start + deadline);
Quoted 8 lines
cpus.c void qemu_clock_warp(QEMUClock *clock) · line 348
Quoted 4 lines
cpus.c +2
-2- }else { -qemu_notify_event (); + }else if (deadline ==0 ) { +qemu_clock_notify (vm_clock);It seems this change is just for clarity: deadline can either be >0 or 0? I think a plain else statement is clearer and doesn't leave you wondering in what case this
qemu_clock_notify()isn't taken.
The change from qemu_notify_event() to qemu_clock_notify(vm_clock) is needed anyway.
The change to "... else if (deadline == 0)" is in case the spurious wakeup stuff above gets excised (which I think it ought to be), in which case deadline could be smaller than zero and no wakeup is necessary.
Signature · 1 line
Alex Bligh
Re: [Qemu-devel] [RFC] [PATCHv10 19/31] aio / timers: Use all timerlists in icount warp calculations
Quoted 9 lines · Alex Bligh
Quoted 6 lines
I see no value in a spurious wakeup if no deadline was set, but it's harmless.
As for overflow, I don't really understand how
INT32_MAXprevents overflow. If the base timer value we're adding to is already huge thenINT32_MAXcould still overflow it.This is my understanding. I don't think we need to worry about overflowing
int64_t.
I think this /might/ refer to the similar bit of nastiness in tcg_cpu_exec, where the parameter gets sent off to qemu_icount_round. It isn't evident this has been built with signed integers in mind. I'm hesitant to fix one without the other.
Given no one has been jumping up and down saying "I know how icount works and you should just delete these", I think I'll leave them in for v11, as the result is every two and a half seconds there's an extra wake up when using icount, as far as I can tell.
If the jumping up and down person appears, he/she can delete a few lines.
So v11 is currently planned just to fix Jan's include file issue.
Signature · 1 line
Alex Bligh
RFC PATCH v10 20/31 aio / timers: Add documentation and new format calls
In reply to Alex BlighAdd documentation for existing qemu timer calls. Add new format calls of the format timer_XXX rather than qemu_XXX_timer for consistency.
--- include/qemu/timer.h | 206 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 184 insertions(+), 22 deletions(-)
include/qemu/timer.h +184 -22
@@ -92,8 +92,52 @@ static inline QEMUClock *qemu_clock_ptr(QEMUClockType type)#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL))#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) +/** +* qemu_get_clock_ns: +* @clock: the clock to operate on +* +* Get the nanosecond value of a clock +* +* Returns: the clock value in nanoseconds +*/ int64_t qemu_get_clock_ns (QEMUClock *clock); + +/** +* qemu_clock_get_ns; +* @type: the clock type +* +* Get the nanosecond value of a clock with +* type @type +* +* Returns: the clock value in nanoseconds +*/ +static inline int64_t qemu_clock_get_ns (QEMUClockType type) +{ +return qemu_get_clock_ns (qemu_clock_ptr (type)); +} + +/** +* qemu_clock_has_timers: +* @clock: the clock to operate on +* +* Determines whether a clock's default timer list +* has timers attached +* +* Returns: true if the clock's default timer list +* has timers attached +*/ bool qemu_clock_has_timers (QEMUClock *clock); + +/** +* qemu_clock_expired: +* @clock: the clock to operate on +* +* Determines whether a clock's default timer list +* has an expired clock. +* +* Returns: true if the clock's default timer list has +* an expired timer +*/ bool qemu_clock_expired (QEMUClock *clock);int64_t qemu_clock_deadline (QEMUClock *clock);
@@ -293,7 +337,7 @@ void timerlistgroup_deinit(QEMUTimerListGroup *tlg);bool timerlistgroup_run_timers (QEMUTimerListGroup *tlg);/** -* timerlistgroup_deadline_ns +* timerlistgroup_deadline_ns: * @tlg: the timer list group * * Determine the deadline of the soonest timer to
@@ -329,13 +373,57 @@ int qemu_timeout_ns_to_ms(int64_t ns);* Returns: number of fds ready */ int qemu_poll_ns (GPollFD *fds,uint nfds,int64_t timeout); + +/** +* qemu_clock_enable: +* @clock: the clock to operate on +* @enabled: true to enable, false to disable +* +* Enable or disable a clock +*/ void qemu_clock_enable (QEMUClock *clock,bool enabled); + +/** +* qemu_clock_warp: +* @clock: the clock to operate on +* +* Warp a clock to a new value +*/ void qemu_clock_warp (QEMUClock *clock); +/** +* qemu_register_clock_reset_notifier: +* @clock: the clock to operate on +* @notifier: the notifier function +* +* Register a notifier function to call when the clock +* concerned is reset. +*/ void qemu_register_clock_reset_notifier (QEMUClock *clock,Notifier *notifier); + +/** +* qemu_unregister_clock_reset_notifier: +* @clock: the clock to operate on +* @notifier: the notifier function +* +* Unregister a notifier function to call when the clock +* concerned is reset. +*/ void qemu_unregister_clock_reset_notifier (QEMUClock *clock,Notifier *notifier); +/** +* qemu_new_timer: +* @clock: the clock to operate on +* @scale: the scale of the clock +* @cb: the callback function to call when the timer expires +* @opaque: an opaque pointer to pass to the callback +* +* Produce a new timer attached to clock @clock. This is a legacy +* function. Use timer_new instead. +* +* Returns: a pointer to the new timer allocated. +*/ QEMUTimer *qemu_new_timer (QEMUClock *clock,int scale,QEMUTimerCB *cb,void *opaque);
@@ -400,21 +488,21 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale,return timer_new_tl (main_loop_tlg.tl[type], scale, cb, opaque); } +/** +* qemu_free_timer: +* @ts: the timer to operate on +* +* free the timer @ts. @ts must not be active. +* +* This is a legacy function. Use timer_free instead. +*/ void qemu_free_timer (QEMUTimer *ts); -void qemu_del_timer (QEMUTimer *ts); -void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time); -void qemu_mod_timer (QEMUTimer *ts,int64_t expire_time); -bool timer_pending (QEMUTimer *ts); -bool timer_expired (QEMUTimer *timer_head,int64_t current_time); -uint64_t timer_expire_time_ns (QEMUTimer *ts); - -/* New format calling conventions for timers */ /** * timer_free: -* @ts: the timer +* @ts: the timer to operate on * -* Free a timer (it must not be on the active list) +* free the timer @ts. @ts must not be active. */ static inline void timer_free (QEMUTimer *ts) {
@@ -422,10 +510,22 @@ static inline void timer_free(QEMUTimer *ts) }/** +* qemu_del_timer: +* @ts: the timer to operate on +* +* Delete a timer. This makes it inactive. It does not free +* memory. +* +* This is a legacy function. Use timer_del instead. +*/ +void qemu_del_timer (QEMUTimer *ts); + +/** * timer_del: -* @ts: the timer +* @ts: the timer to operate on * -* Delete a timer from the active list. +* Delete a timer. This makes it inactive. It does not free +* memory. */ static inline void timer_del (QEMUTimer *ts) {
@@ -433,11 +533,24 @@ static inline void timer_del(QEMUTimer *ts) }/** +* qemu_mod_timer_ns: +* @ts: the timer to operate on +* @expire_time: the expiry time in nanoseconds +* +* Modify a timer such that the expiry time is @expire_time +* as measured in nanoseconds +* +* This is a legacy function. Use timer_mod_ns. +*/ +void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time); + +/** * timer_mod_ns: -* @ts: the timer +* @ts: the timer to operate on * @expire_time: the expiry time in nanoseconds * -* Modify a timer to expire at @expire_time +* Modify a timer such that the expiry time is @expire_time +* as measured in nanoseconds */ static inline void timer_mod_ns (QEMUTimer *ts,int64_t expire_time) {
@@ -445,19 +558,62 @@ static inline void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) }/** +* qemu_mod_timer: +* @ts: the timer to operate on +* @expire_time: the expiry time +* +* Modify a timer such that the expiry time is @expire_time +* as measured in the timer's scale +* +* This is a legacy function. Use timer_mod. +*/ +void qemu_mod_timer (QEMUTimer *ts,int64_t expire_time); + +/** * timer_mod: -* @ts: the timer -* @expire_time: the expire time in the units associated with the timer +* @ts: the timer to operate on +* @expire_time: the expiry time in nanoseconds * -* Modify a timer to expiry at @expire_time, taking into -* account the scale associated with the timer. +* Modify a timer such that the expiry time is @expire_time +* as measured in the timer's scale */ -static inline void timer_mod (QEMUTimer *ts,int64_t expire_timer) +static inline void timer_mod (QEMUTimer *ts,int64_t expire_time) { -qemu_mod_timer (ts, expire_timer); +qemu_mod_timer (ts, expire_time); }/** +* timer_pending: +* @ts: the timer to operate on +* +* Determines whether a timer is pending (i.e. is on the +* active list of timers, whether or not it has not yet expired). +* +* Returns: true if the timer is pending +*/ +bool timer_pending (QEMUTimer *ts); + +/** +* timer_expired: +* @ts: the timer to operate on +* +* Determines whether a timer has expired. +* +* Returns: true if the timer has expired +*/ +bool timer_expired (QEMUTimer *timer_head,int64_t current_time); + +/** +* timer_expire_time_ns: +* @ts: the timer to operate on +* +* Determines the time until a timer expires +* +* Returns: the time (in nanoseonds) until a timer expires +*/ +uint64_t timer_expire_time_ns (QEMUTimer *ts); + +/** * qemu_run_timers: * @clock: clock on which to operate *
@@ -479,9 +635,15 @@ bool qemu_run_timers(QEMUClock *clock);bool qemu_run_all_timers (void );void configure_alarms (char const *opt); -void init_clocks (void );int init_timer_alarm (void ); +/** +* initclocks: +* +* Initialise the clock & timer infrastructure +*/ +void init_clocks (void ); +int64_t cpu_get_ticks (void );void cpu_enable_ticks (void );void cpu_disable_ticks (void );
Signature · 1 line
1.7.9.5
RFC PATCH v10 21/31 aio / timers: Remove alarm timers
In reply to Alex BlighRemove alarm timers from qemu-timers.c now we use g_poll / ppoll instead.
--- include/qemu/timer.h | 3 - main-loop.c | 4 - qemu-timer.c | 500 +------------------------------------------------- vl.c | 4 +- 4 files changed, 4 insertions(+), 507 deletions(-)
include/qemu/timer.h +0 -3
@@ -634,9 +634,6 @@ bool qemu_run_timers(QEMUClock *clock);*/ bool qemu_run_all_timers (void ); -void configure_alarms (char const *opt); -int init_timer_alarm (void ); -/** * initclocks: *
main-loop.c +0 -4
@@ -131,10 +131,6 @@ int qemu_init_main_loop(void)GSource *src;init_clocks (); -if (init_timer_alarm () <0 ) { -fprintf (stderr,"could not initialize alarm timer\n" ); -exit (1 ); - } ret =qemu_signal_init ();if (ret) {
qemu-timer.c +1 -499
539 lines not on this page · raw message
vl.c +3 -1
@@ -3714,7 +3714,9 @@ int main(int argc, char **argv, char **envp) old_param =1 ;break ;case QEMU_OPTION_clock: -configure_alarms (optarg); +/* Clock options no longer exist. Keep this option for +* backward compatibility. +*/ break ;case QEMU_OPTION_startdate:configure_rtc_date_offset (optarg,1 );
Signature · 1 line
1.7.9.5
RFC PATCH v10 22/31 aio / timers: Remove legacy qemu_clock_deadline & qemu_timerlist_deadline
In reply to Alex BlighRemove qemu_clock_deadline and qemu_timerlist_deadline now we are using the ns functions throughout.
--- include/qemu/timer.h | 16 ---------------- qemu-timer.c | 20 -------------------- 2 files changed, 36 deletions(-)
include/qemu/timer.h +0 -16
@@ -139,7 +139,6 @@ bool qemu_clock_has_timers(QEMUClock *clock);* an expired timer */ bool qemu_clock_expired (QEMUClock *clock); -int64_t qemu_clock_deadline (QEMUClock *clock);/** * qemu_clock_deadline_ns:
@@ -245,21 +244,6 @@ bool timerlist_has_timers(QEMUTimerList *timer_list);bool timerlist_expired (QEMUTimerList *timer_list);/** -* timerlist_deadline: -* @timer_list: the timer list to operate on -* -* Determine the deadline for a timer_list. This is -* a legacy function which returns INT32_MAX if the -* timer list has no timers or if the earliest timer -* expires later than INT32_MAX nanoseconds away. -* -* Returns: the number of nanoseconds until the earliest -* timer expires or INT32_MAX in the situations listed -* above -*/ -int64_t timerlist_deadline (QEMUTimerList *timer_list); - -/** * timerlist_deadline_ns: * @timer_list: the timer list to operate on *
qemu-timer.c +0 -20
@@ -176,26 +176,6 @@ bool qemu_clock_expired(QEMUClock *clock)return timerlist_expired (clock->main_loop_timerlist); } -int64_t timerlist_deadline (QEMUTimerList *timer_list) -{ -/* To avoid problems with overflow limit this to 2^32. */ -int64_t delta =INT32_MAX ; - -if (timer_list->clock->enabled && timer_list->active_timers) { - delta = timer_list->active_timers->expire_time - -qemu_get_clock_ns (timer_list->clock); - } -if (delta <0 ) { - delta =0 ; - } -return delta; -} - -int64_t qemu_clock_deadline (QEMUClock *clock) -{ -return timerlist_deadline (clock->main_loop_timerlist); -} -/* * As above, but return -1 for no deadline, and do not cap to 2^32 * as we know the result is always positive.
Signature · 1 line
1.7.9.5
RFC PATCH v10 23/31 aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms
In reply to Alex BlighAdd utility functions qemu_clock_get_ms and qemu_clock_get_us
--- include/qemu/timer.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
include/qemu/timer.h +28 -0
@@ -117,6 +117,34 @@ static inline int64_t qemu_clock_get_ns(QEMUClockType type) }/** +* qemu_clock_get_ms; +* @type: the clock type +* +* Get the millisecond value of a clock with +* type @type +* +* Returns: the clock value in milliseconds +*/ +static inline int64_t qemu_clock_get_ms (QEMUClockType type) +{ +return qemu_clock_get_ns (type) /SCALE_MS ; +} + +/** +* qemu_clock_get_us; +* @type: the clock type +* +* Get the microsecond value of a clock with +* type @type +* +* Returns: the clock value in microseconds +*/ +static inline int64_t qemu_clock_get_us (QEMUClockType type) +{ +return qemu_clock_get_ns (type) /SCALE_US ; +} + +/** * qemu_clock_has_timers: * @clock: the clock to operate on *
Signature · 1 line
1.7.9.5
RFC PATCH v10 24/31 aio / timers: Rearrange timer.h & make legacy functions call non-legacy
In reply to Alex BlighRearrange timer.h so it is in order by function type.
Make legacy functions call non-legacy functions rather than vice-versa.
Convert cpus.c to use new API.
--- cpus.c | 112 ++++----- hw/acpi/piix4.c | 2 +- hw/input/tsc2005.c | 4 +- hw/input/tsc210x.c | 4 +- hw/sparc64/sun4u.c | 4 +- include/qemu/timer.h | 614 ++++++++++++++++++++++++++++---------------------- main-loop.c | 2 +- qemu-timer.c | 100 +++++--- qtest.c | 2 +- savevm.c | 8 +- stubs/clock-warp.c | 2 +- 11 files changed, 477 insertions(+), 377 deletions(-)
cpus.c +59 -53
@@ -202,7 +202,7 @@ static void icount_adjust(void)return ; } cur_time =cpu_get_clock (); - cur_icount =qemu_get_clock_ns (vm_clock); + cur_icount =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); delta = cur_icount - cur_time;/* FIXME: This is a very crude algorithm, somewhat prone to oscillation. */ if (delta > 0
@@ -223,15 +223,16 @@ static void icount_adjust(void)static void icount_adjust_rt (void *opaque) { -qemu_mod_timer (icount_rt_timer, -qemu_get_clock_ms (rt_clock) +1000 ); +timer_mod (icount_rt_timer, +qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +1000 );icount_adjust (); }static void icount_adjust_vm (void *opaque) { -qemu_mod_timer (icount_vm_timer, -qemu_get_clock_ns (vm_clock) +get_ticks_per_sec () /10 ); +timer_mod (icount_vm_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + +get_ticks_per_sec () /10 );icount_adjust (); }
@@ -247,22 +248,22 @@ static void icount_warp_rt(void *opaque) }if (runstate_is_running ()) { -int64_t clock =qemu_get_clock_ns (rt_clock); +int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );int64_t warp_delta = clock - vm_clock_warp_start;if (use_icount ==1 ) { qemu_icount_bias += warp_delta; }else {/* -* In adaptive mode, do not let the vm_clock run too +* In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too * far ahead of real time. */ int64_t cur_time =cpu_get_clock (); -int64_t cur_icount =qemu_get_clock_ns (vm_clock); +int64_t cur_icount =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int64_t delta = cur_time - cur_icount; qemu_icount_bias +=MIN (warp_delta, delta); } -if (qemu_clock_expired (vm_clock)) { -qemu_clock_notify (vm_clock); +if (qemu_clock_expired (QEMU_CLOCK_VIRTUAL )) { +qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); } } vm_clock_warp_start =-1 ;
@@ -270,19 +271,19 @@ static void icount_warp_rt(void *opaque)void qtest_clock_warp (int64_t dest) { -int64_t clock =qemu_get_clock_ns (vm_clock); +int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );assert (qtest_enabled ());while (clock < dest) { -int64_t deadline =qemu_clock_deadline_ns_all (vm_clock); +int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );int64_t warp =MIN (dest - clock, deadline); qemu_icount_bias += warp; -qemu_run_timers (vm_clock); - clock =qemu_get_clock_ns (vm_clock); +qemu_clock_run_timers (QEMU_CLOCK_VIRTUAL ); + clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); } -qemu_clock_notify (vm_clock); +qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); } -void qemu_clock_warp (QEMUClock *clock) +void qemu_clock_warp (QEMUClockType type) {int64_t deadline;
@@ -291,20 +292,20 @@ void qemu_clock_warp(QEMUClock *clock)* applicable to other clocks. But a clock argument removes the * need for if statements all over the place. */ -if (clock != vm_clock || !use_icount) { +if (type !=QEMU_CLOCK_VIRTUAL || !use_icount) {return ; }/* -* If the CPUs have been sleeping, advance the vm_clock timer now. This -* ensures that the deadline for the timer is computed correctly below. +* If the CPUs have been sleeping, advance QEMU_CLOCK_VIRTUAL timer now. +* This ensures that the deadline for the timer is computed correctly below. * This also makes sure that the insn counter is synchronized before the * CPU starts running, in case the CPU is woken by an event other than -* the earliest vm_clock timer. +* the earliest QEMU_CLOCK_VIRTUAL timer. */ icount_warp_rt (NULL ); -if (!all_cpu_threads_idle () || !qemu_clock_has_timers (vm_clock)) { -qemu_del_timer (icount_warp_timer); +if (!all_cpu_threads_idle () || !qemu_clock_has_timers (QEMU_CLOCK_VIRTUAL )) { +timer_del (icount_warp_timer);return ; }
@@ -313,12 +314,12 @@ void qemu_clock_warp(QEMUClock *clock)return ; } - vm_clock_warp_start =qemu_get_clock_ns (rt_clock); + vm_clock_warp_start =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );/* We want to use the earliest deadline from ALL vm_clocks */ - deadline =qemu_clock_deadline_ns_all (vm_clock); + deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );/* Maintain prior (possibly buggy) behaviour where if no deadline -* was set (as there is no vm_clock timer) or it is more than +* was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than * INT32_MAX nanoseconds ahead, we still use INT32_MAX * nanoseconds. */
@@ -328,24 +329,25 @@ void qemu_clock_warp(QEMUClock *clock)if (deadline >0 ) {/* -* Ensure the vm_clock proceeds even when the virtual CPU goes to +* Ensure QEMU_CLOCK_VIRTUAL proceeds even when the virtual CPU goes to * sleep. Otherwise, the CPU might be waiting for a future timer * interrupt to wake it up, but the interrupt never comes because * the vCPU isn't running any insns and thus doesn't advance the -* vm_clock. +* QEMU_CLOCK_VIRTUAL. * * An extreme solution for this problem would be to never let VCPUs -* sleep in icount mode if there is a pending vm_clock timer; rather -* time could just advance to the next vm_clock event. Instead, we -* do stop VCPUs and only advance vm_clock after some "real" time, -* (related to the time left until the next event) has passed. This -* rt_clock timer will do this. This avoids that the warps are too -* visible externally---for example, you will not be sending network -* packets continuously instead of every 100ms. +* sleep in icount mode if there is a pending QEMU_CLOCK_VIRTUAL +* timer; rather time could just advance to the next QEMU_CLOCK_VIRTUAL +* event. Instead, we do stop VCPUs and only advance QEMU_CLOCK_VIRTUAL +* after some e"real" time, (related to the time left until the next +* event) has passed. The QEMU_CLOCK_REALTIME timer will do this. +* This avoids that the warps are visible externally; for example, +* you will not be sending network packets continuously instead of +* every 100ms. */ -qemu_mod_timer (icount_warp_timer, vm_clock_warp_start + deadline); +timer_mod (icount_warp_timer, vm_clock_warp_start + deadline); }else if (deadline ==0 ) { -qemu_clock_notify (vm_clock); +qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); } }
@@ -369,7 +371,8 @@ void configure_icount(const char *option)return ; } - icount_warp_timer =qemu_new_timer_ns (rt_clock, icount_warp_rt,NULL ); + icount_warp_timer =timer_new_ns (QEMU_CLOCK_REALTIME , + icount_warp_rt,NULL );if (strcmp (option,"auto" ) !=0 ) { icount_time_shift =strtol (option,NULL ,0 ); use_icount =1 ;
@@ -387,12 +390,15 @@ void configure_icount(const char *option)the virtual time trigger catches emulated time passing too fast. Realtime triggers occur even when idle, so use them less frequently than VM triggers. */ - icount_rt_timer =qemu_new_timer_ms (rt_clock, icount_adjust_rt,NULL ); -qemu_mod_timer (icount_rt_timer, -qemu_get_clock_ms (rt_clock) +1000 ); - icount_vm_timer =qemu_new_timer_ns (vm_clock, icount_adjust_vm,NULL ); -qemu_mod_timer (icount_vm_timer, -qemu_get_clock_ns (vm_clock) +get_ticks_per_sec () /10 ); + icount_rt_timer =timer_new_ms (QEMU_CLOCK_REALTIME , + icount_adjust_rt,NULL ); +timer_mod (icount_rt_timer, +qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +1000 ); + icount_vm_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , + icount_adjust_vm,NULL ); +timer_mod (icount_vm_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + +get_ticks_per_sec () /10 ); }/***********************************************************/
@@ -746,7 +752,7 @@ static void qemu_tcg_wait_io_event(void)while (all_cpu_threads_idle ()) {/* Start accounting real time to the virtual clock if the CPUs are idle. */ -qemu_clock_warp (vm_clock); +qemu_clock_warp (QEMU_CLOCK_VIRTUAL );qemu_cond_wait (tcg_halt_cond, &qemu_global_mutex); }
@@ -879,10 +885,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)tcg_exec_all ();if (use_icount) { -int64_t deadline =qemu_clock_deadline_ns_all (vm_clock); +int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );if (deadline ==0 ) { -qemu_clock_notify (vm_clock); +qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); } }qemu_tcg_wait_io_event ();
@@ -1001,7 +1007,7 @@ void pause_all_vcpus(void) {CPUState *cpu = first_cpu; -qemu_clock_enable (vm_clock, false); +qemu_clock_enable (QEMU_CLOCK_VIRTUAL , false);while (cpu) { cpu->stop = true;qemu_cpu_kick (cpu);
@@ -1042,7 +1048,7 @@ void resume_all_vcpus(void) {CPUState *cpu = first_cpu; -qemu_clock_enable (vm_clock, true); +qemu_clock_enable (QEMU_CLOCK_VIRTUAL , true);while (cpu) {cpu_resume (cpu); cpu = cpu->next_cpu;
@@ -1166,10 +1172,10 @@ static int tcg_cpu_exec(CPUArchState *env) qemu_icount -= (env->icount_decr.u16.low + env->icount_extra); env->icount_decr.u16.low =0 ; env->icount_extra =0 ; - deadline =qemu_clock_deadline_ns_all (vm_clock); + deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );/* Maintain prior (possibly buggy) behaviour where if no deadline -* was set (as there is no vm_clock timer) or it is more than +* was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than * INT32_MAX nanoseconds ahead, we still use INT32_MAX * nanoseconds. */
@@ -1203,8 +1209,8 @@ static void tcg_exec_all(void) {int r; -/* Account partial waits to the vm_clock. */ -qemu_clock_warp (vm_clock); +/* Account partial waits to QEMU_CLOCK_VIRTUAL. */ +qemu_clock_warp (QEMU_CLOCK_VIRTUAL );if (next_cpu ==NULL ) { next_cpu = first_cpu;
@@ -1213,7 +1219,7 @@ static void tcg_exec_all(void)CPUState *cpu = next_cpu;CPUArchState *env = cpu->env_ptr; -qemu_clock_enable (vm_clock, +qemu_clock_enable (QEMU_CLOCK_VIRTUAL , (cpu->singlestep_enabled &SSTEP_NOTIMER ) ==0 );if (cpu_can_run (cpu)) {
hw/acpi/piix4.c +1 -1
@@ -263,7 +263,7 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)return ret; } -qemu_get_timer (f, s->ar.tmr.timer); +timer_get (f, s->ar.tmr.timer);qemu_get_sbe64s (f, &s->ar.tmr.overflow_time);qemu_get_be16s (f, (uint16_t *)s->ar.gpe.sts);
hw/input/tsc2005.c +2 -2
@@ -449,7 +449,7 @@ static void tsc2005_save(QEMUFile *f, void *opaque)qemu_put_be16s (f, &s->dav);qemu_put_be16s (f, &s->data); -qemu_put_timer (f, s->timer); +timer_put (f, s->timer);qemu_put_byte (f, s->enabled);qemu_put_byte (f, s->host_mode);qemu_put_byte (f, s->function);
@@ -490,7 +490,7 @@ static int tsc2005_load(QEMUFile *f, void *opaque, int version_id)qemu_get_be16s (f, &s->dav);qemu_get_be16s (f, &s->data); -qemu_get_timer (f, s->timer); +timer_get (f, s->timer); s->enabled =qemu_get_byte (f); s->host_mode =qemu_get_byte (f); s->function =qemu_get_byte (f);
hw/input/tsc210x.c +2 -2
@@ -1020,7 +1020,7 @@ static void tsc210x_save(QEMUFile *f, void *opaque)qemu_put_byte (f, s->irq);qemu_put_be16s (f, &s->dav); -qemu_put_timer (f, s->timer); +timer_put (f, s->timer);qemu_put_byte (f, s->enabled);qemu_put_byte (f, s->host_mode);qemu_put_byte (f, s->function);
@@ -1066,7 +1066,7 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) s->irq =qemu_get_byte (f);qemu_get_be16s (f, &s->dav); -qemu_get_timer (f, s->timer); +timer_get (f, s->timer); s->enabled =qemu_get_byte (f); s->host_mode =qemu_get_byte (f); s->function =qemu_get_byte (f);
hw/sparc64/sun4u.c +2 -2
@@ -363,7 +363,7 @@ void cpu_put_timer(QEMUFile *f, CPUTimer *s)qemu_put_be64s (f, &s->disabled_mask);qemu_put_sbe64s (f, &s->clock_offset); -qemu_put_timer (f, s->qtimer); +timer_put (f, s->qtimer); }void cpu_get_timer (QEMUFile *f,CPUTimer *s)
@@ -373,7 +373,7 @@ void cpu_get_timer(QEMUFile *f, CPUTimer *s)qemu_get_be64s (f, &s->disabled_mask);qemu_get_sbe64s (f, &s->clock_offset); -qemu_get_timer (f, s->qtimer); +timer_get (f, s->qtimer); } static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu,
include/qemu/timer.h +341 -273
851 lines not on this page · raw message
main-loop.c +1 -1
@@ -487,7 +487,7 @@ int main_loop_wait(int nonblocking)slirp_pollfds_poll (gpollfds, (ret <0 ));#endif -qemu_run_all_timers (); +qemu_clock_run_all_timers ();return ret; }
qemu-timer.c +63 -37
251 lines not on this page · raw message
qtest.c +1 -1
@@ -412,7 +412,7 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)if (words[1 ]) { ns =strtoll (words[1 ],NULL ,0 ); }else { - ns =qemu_clock_deadline_ns_all (vm_clock); + ns =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); }qtest_clock_warp (qemu_get_clock_ns (vm_clock) + ns);qtest_send_prefix (chr);
savevm.c +4 -4
@@ -979,7 +979,7 @@ uint64_t qemu_get_be64(QEMUFile *f)/* timer */ -void qemu_put_timer (QEMUFile *f,QEMUTimer *ts) +void timer_put (QEMUFile *f,QEMUTimer *ts) {uint64_t expire_time;
@@ -987,7 +987,7 @@ void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)qemu_put_be64 (f, expire_time); } -void qemu_get_timer (QEMUFile *f,QEMUTimer *ts) +void timer_get (QEMUFile *f,QEMUTimer *ts) {uint64_t expire_time;
@@ -1339,14 +1339,14 @@ const VMStateInfo vmstate_info_float64 = {static int get_timer (QEMUFile *f,void *pv,size_t size) {QEMUTimer *v = pv; -qemu_get_timer (f, v); +timer_get (f, v);return 0 ; }static void put_timer (QEMUFile *f,void *pv,size_t size) {QEMUTimer *v = pv; -qemu_put_timer (f, v); +timer_put (f, v); }const VMStateInfo vmstate_info_timer = {
stubs/clock-warp.c +1 -1
@@ -1,7 +1,7 @@#include "qemu-common.h" #include "qemu/timer.h" -void qemu_clock_warp (QEMUClock *clock) +void qemu_clock_warp (QEMUClockType type) { }
Signature · 1 line
1.7.9.5
RFC PATCH v10 25/31 aio / timers: Remove main_loop_timerlist
In reply to Alex BlighNow we have timerlistgroups implemented and main_loop_tlg, we no longer need the concept of a default timer list associated with each clock. Remove it and simplify initialisation of clocks and timer lists.
--- include/qemu/timer.h | 6 +---- qemu-timer.c | 63 ++++++++++++++++++++++---------------------------- 2 files changed, 28 insertions(+), 41 deletions(-)
include/qemu/timer.h +1 -5
@@ -64,7 +64,6 @@ typedef struct QEMUTimer { } QEMUTimer;extern QEMUTimerListGroup main_loop_tlg; -extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX ];/* * QEMUClock & QEMUClockType
@@ -78,10 +77,7 @@ extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX];* * Returns: a pointer to the QEMUClock object */ -static inline QEMUClock *qemu_clock_ptr (QEMUClockType type) -{ -return qemu_clocks[type]; -} +QEMUClock *qemu_clock_ptr (QEMUClockType type);/** * qemu_clock_get_ns;
qemu-timer.c +27 -36
146 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH v10 26/31 aio / timers: Convert rtc_clock to be a QEMUClockType
In reply to Alex BlighConvert rtc_clock to be a QEMUClockType
Move rtc_clock users to use the new API
--- hw/arm/omap1.c | 4 ++-- hw/arm/pxa2xx.c | 35 +++++++++++++++++++---------------- hw/arm/strongarm.c | 10 +++++----- hw/timer/m48t59.c | 4 ++-- hw/timer/mc146818rtc.c | 28 +++++++++++++++------------- hw/timer/pl031.c | 13 +++++++------ hw/timer/twl92230.c | 8 ++++---- include/sysemu/sysemu.h | 2 +- target-alpha/sys_helper.c | 2 +- vl.c | 10 +++++----- 10 files changed, 61 insertions(+), 55 deletions(-)
hw/arm/omap1.c +2 -2
@@ -2894,7 +2894,7 @@ static void omap_rtc_reset(struct omap_rtc_s *s) s->pm_am =0 ; s->auto_comp =0 ; s->round =0 ; - s->tick =qemu_get_clock_ms (rtc_clock); + s->tick =qemu_clock_get_ms (rtc_clock);memset (&s->alarm_tm,0 ,sizeof (s->alarm_tm)); s->alarm_tm.tm_mday =0x01 ; s->status =1 <<7 ;
@@ -2915,7 +2915,7 @@ static struct omap_rtc_s *omap_rtc_init(MemoryRegion *system_memory, s->irq = timerirq; s->alarm = alarmirq; - s->clk =qemu_new_timer_ms (rtc_clock, omap_rtc_tick, s); + s->clk =timer_new_ms (rtc_clock, omap_rtc_tick, s);omap_rtc_reset (s);
hw/arm/pxa2xx.c +19 -16
@@ -842,7 +842,7 @@ static inline void pxa2xx_rtc_int_update(PXA2xxRTCState *s)static void pxa2xx_rtc_hzupdate (PXA2xxRTCState *s) { -int64_t rt =qemu_get_clock_ms (rtc_clock); +int64_t rt =qemu_clock_get_ms (rtc_clock); s->last_rcnr += ((rt - s->last_hz) <<15 ) / (1000 * ((s->rttr &0xffff ) +1 )); s->last_rdcr += ((rt - s->last_hz) << 15) /
@@ -852,7 +852,7 @@ static void pxa2xx_rtc_hzupdate(PXA2xxRTCState *s)static void pxa2xx_rtc_swupdate (PXA2xxRTCState *s) { -int64_t rt =qemu_get_clock_ms (rtc_clock); +int64_t rt =qemu_clock_get_ms (rtc_clock);if (s->rtsr & (1 <<12 )) s->last_swcr += (rt - s->last_sw) /10 ; s->last_sw = rt;
@@ -860,7 +860,7 @@ static void pxa2xx_rtc_swupdate(PXA2xxRTCState *s)static void pxa2xx_rtc_piupdate (PXA2xxRTCState *s) { -int64_t rt =qemu_get_clock_ms (rtc_clock); +int64_t rt =qemu_clock_get_ms (rtc_clock);if (s->rtsr & (1 <<15 )) s->last_swcr += rt - s->last_pi; s->last_pi = rt;
@@ -986,16 +986,19 @@ static uint64_t pxa2xx_rtc_read(void *opaque, hwaddr addr,case PIAR :return s->piar;case RCNR : -return s->last_rcnr + ((qemu_get_clock_ms (rtc_clock) - s->last_hz) <<15 ) / - (1000 * ((s->rttr &0xffff ) +1 )); +return s->last_rcnr + + ((qemu_clock_get_ms (rtc_clock) - s->last_hz) <<15 ) / + (1000 * ((s->rttr &0xffff ) +1 ));case RDCR : -return s->last_rdcr + ((qemu_get_clock_ms (rtc_clock) - s->last_hz) <<15 ) / - (1000 * ((s->rttr &0xffff ) +1 )); +return s->last_rdcr + + ((qemu_clock_get_ms (rtc_clock) - s->last_hz) <<15 ) / + (1000 * ((s->rttr &0xffff ) +1 ));case RYCR :return s->last_rycr;case SWCR :if (s->rtsr & (1 <<12 )) -return s->last_swcr + (qemu_get_clock_ms (rtc_clock) - s->last_sw) /10 ; +return s->last_swcr + + (qemu_clock_get_ms (rtc_clock) - s->last_sw) /10 ;else return s->last_swcr;default :
@@ -1135,14 +1138,14 @@ static int pxa2xx_rtc_init(SysBusDevice *dev) s->last_swcr = (tm.tm_hour <<19 ) | (tm.tm_min <<13 ) | (tm.tm_sec <<7 ); s->last_rtcpicr =0 ; - s->last_hz = s->last_sw = s->last_pi =qemu_get_clock_ms (rtc_clock); - - s->rtc_hz =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_hz_tick, s); - s->rtc_rdal1 =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_rdal1_tick, s); - s->rtc_rdal2 =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_rdal2_tick, s); - s->rtc_swal1 =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_swal1_tick, s); - s->rtc_swal2 =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_swal2_tick, s); - s->rtc_pi =qemu_new_timer_ms (rtc_clock, pxa2xx_rtc_pi_tick, s); + s->last_hz = s->last_sw = s->last_pi =qemu_clock_get_ms (rtc_clock); + + s->rtc_hz =timer_new_ms (rtc_clock, pxa2xx_rtc_hz_tick, s); + s->rtc_rdal1 =timer_new_ms (rtc_clock, pxa2xx_rtc_rdal1_tick, s); + s->rtc_rdal2 =timer_new_ms (rtc_clock, pxa2xx_rtc_rdal2_tick, s); + s->rtc_swal1 =timer_new_ms (rtc_clock, pxa2xx_rtc_swal1_tick, s); + s->rtc_swal2 =timer_new_ms (rtc_clock, pxa2xx_rtc_swal2_tick, s); + s->rtc_pi =timer_new_ms (rtc_clock, pxa2xx_rtc_pi_tick, s);sysbus_init_irq (dev, &s->rtc_irq);
hw/arm/strongarm.c +5 -5
@@ -269,7 +269,7 @@ static inline void strongarm_rtc_int_update(StrongARMRTCState *s)static void strongarm_rtc_hzupdate (StrongARMRTCState *s) { -int64_t rt =qemu_get_clock_ms (rtc_clock); +int64_t rt =qemu_clock_get_ms (rtc_clock); s->last_rcnr += ((rt - s->last_hz) <<15 ) / (1000 * ((s->rttr &0xffff ) +1 )); s->last_hz = rt;
@@ -322,7 +322,7 @@ static uint64_t strongarm_rtc_read(void *opaque, hwaddr addr,return s->rtar;case RCNR :return s->last_rcnr + - ((qemu_get_clock_ms (rtc_clock) - s->last_hz) <<15 ) / + ((qemu_clock_get_ms (rtc_clock) - s->last_hz) <<15 ) / (1000 * ((s->rttr &0xffff ) +1 ));default :printf ("%s: Bad register 0x" TARGET_FMT_plx"\n" , __func__, addr);
@@ -388,10 +388,10 @@ static int strongarm_rtc_init(SysBusDevice *dev)qemu_get_timedate (&tm,0 ); s->last_rcnr = (uint32_t )mktimegm (&tm); - s->last_hz =qemu_get_clock_ms (rtc_clock); + s->last_hz =qemu_clock_get_ms (rtc_clock); - s->rtc_alarm =qemu_new_timer_ms (rtc_clock, strongarm_rtc_alarm_tick, s); - s->rtc_hz =qemu_new_timer_ms (rtc_clock, strongarm_rtc_hz_tick, s); + s->rtc_alarm =timer_new_ms (rtc_clock, strongarm_rtc_alarm_tick, s); + s->rtc_hz =timer_new_ms (rtc_clock, strongarm_rtc_hz_tick, s);sysbus_init_irq (dev, &s->rtc_irq);sysbus_init_irq (dev, &s->rtc_hz_irq);
hw/timer/m48t59.c +2 -2
@@ -137,7 +137,7 @@ static void alarm_cb (void *opaque)/* Repeat once a second */ next_time =1 ; } -qemu_mod_timer (NVRAM ->alrm_timer,qemu_get_clock_ns (rtc_clock) + +qemu_mod_timer (NVRAM ->alrm_timer,qemu_clock_get_ns (rtc_clock) + next_time *1000 );qemu_set_irq (NVRAM ->IRQ,0 ); }
@@ -700,7 +700,7 @@ static void m48t59_realize_common(M48t59State *s, Error **errp) { s->buffer =g_malloc0 (s->size);if (s->model ==59 ) { - s->alrm_timer =qemu_new_timer_ns (rtc_clock, &alarm_cb, s); + s->alrm_timer =timer_new_ns (rtc_clock, &alarm_cb, s); s->wd_timer =qemu_new_timer_ns (vm_clock, &watchdog_cb, s); }qemu_get_timedate (&s->alarm,0 );
hw/timer/mc146818rtc.c +15 -13
@@ -102,7 +102,7 @@ static inline bool rtc_running(RTCState *s)static uint64_t get_guest_rtc_ns (RTCState *s) {uint64_t guest_rtc; -uint64_t guest_clock =qemu_get_clock_ns (rtc_clock); +uint64_t guest_clock =qemu_clock_get_ns (rtc_clock); guest_rtc = s->base_rtc *NSEC_PER_SEC + guest_clock - s->last_update + s->offset;
@@ -117,7 +117,7 @@ static void rtc_coalesced_timer_update(RTCState *s) }else {/* divide each RTC interval to 2 - 8 smaller intervals */ int c =MIN (s->irq_coalesced,7 ) +1 ; -int64_t next_clock =qemu_get_clock_ns (rtc_clock) + +int64_t next_clock =qemu_clock_get_ns (rtc_clock) +muldiv64 (s->period / c,get_ticks_per_sec (),RTC_CLOCK_RATE );qemu_mod_timer (s->coalesced_timer, next_clock); }
@@ -238,7 +238,7 @@ static void check_update_timer(RTCState *s) guest_nsec =get_guest_rtc_ns (s) %NSEC_PER_SEC ;/* if UF is clear, reprogram to next second */ - next_update_time =qemu_get_clock_ns (rtc_clock) + next_update_time =qemu_clock_get_ns (rtc_clock) +NSEC_PER_SEC - guest_nsec;/* Compute time of next alarm. One second is already accounted
@@ -371,7 +371,7 @@ static void rtc_update_timer(void *opaque)rtc_update_time (s); s->cmos_data[RTC_REG_A ] &= ~REG_A_UIP ; -if (qemu_get_clock_ns (rtc_clock) >= s->next_alarm_time) { +if (qemu_clock_get_ns (rtc_clock) >= s->next_alarm_time) { irqs |=REG_C_AF ;if (s->cmos_data[RTC_REG_B ] ®_B_AIE ) {qemu_system_wakeup_request (QEMU_WAKEUP_REASON_RTC );
@@ -445,7 +445,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,/* UIP bit is read only */ s->cmos_data[RTC_REG_A ] = (data & ~REG_A_UIP ) | (s->cmos_data[RTC_REG_A ] ®_A_UIP ); -periodic_timer_update (s,qemu_get_clock_ns (rtc_clock)); +periodic_timer_update (s,qemu_clock_get_ns (rtc_clock));check_update_timer (s);break ;case RTC_REG_B :
@@ -475,7 +475,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,qemu_irq_lower (s->irq); } s->cmos_data[RTC_REG_B ] = data; -periodic_timer_update (s,qemu_get_clock_ns (rtc_clock)); +periodic_timer_update (s,qemu_clock_get_ns (rtc_clock));check_update_timer (s);break ;case RTC_REG_C :
@@ -535,7 +535,7 @@ static void rtc_set_time(RTCState *s)rtc_get_time (s, &tm); s->base_rtc =mktimegm (&tm); - s->last_update =qemu_get_clock_ns (rtc_clock); + s->last_update =qemu_clock_get_ns (rtc_clock);rtc_change_mon_event (&tm); }
@@ -590,7 +590,8 @@ static int update_in_progress(RTCState *s)if (timer_pending (s->update_timer)) {int64_t next_update_time =timer_expire_time_ns (s->update_timer);/* Latch UIP until the timer expires. */ -if (qemu_get_clock_ns (rtc_clock) >= (next_update_time -UIP_HOLD_LENGTH )) { +if (qemu_clock_get_ns (rtc_clock) >= + (next_update_time -UIP_HOLD_LENGTH )) { s->cmos_data[RTC_REG_A ] |=REG_A_UIP ;return 1 ; }
@@ -695,7 +696,7 @@ static void rtc_set_date_from_host(ISADevice *dev)qemu_get_timedate (&tm,0 ); s->base_rtc =mktimegm (&tm); - s->last_update =qemu_get_clock_ns (rtc_clock); + s->last_update =qemu_clock_get_ns (rtc_clock); s->offset =0 ;/* set the CMOS date */
@@ -843,7 +844,7 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)switch (s->lost_tick_policy) {case LOST_TICK_SLEW : s->coalesced_timer = -qemu_new_timer_ns (rtc_clock, rtc_coalesced_timer, s); +timer_new_ns (rtc_clock, rtc_coalesced_timer, s);break ;case LOST_TICK_DISCARD :break ;
@@ -853,12 +854,13 @@ static void rtc_realizefn(DeviceState *dev, Error **errp) }#endif - s->periodic_timer =qemu_new_timer_ns (rtc_clock, rtc_periodic_timer, s); - s->update_timer =qemu_new_timer_ns (rtc_clock, rtc_update_timer, s); + s->periodic_timer =timer_new_ns (rtc_clock, rtc_periodic_timer, s); + s->update_timer =timer_new_ns (rtc_clock, rtc_update_timer, s);check_update_timer (s); s->clock_reset_notifier.notify = rtc_notify_clock_reset; -qemu_register_clock_reset_notifier (rtc_clock, &s->clock_reset_notifier); +qemu_clock_register_reset_notifier (QEMU_CLOCK_REALTIME , + &s->clock_reset_notifier); s->suspend_notifier.notify = rtc_notify_suspend;qemu_register_suspend_notifier (&s->suspend_notifier);
hw/timer/pl031.c +7 -6
@@ -78,7 +78,7 @@ static void pl031_interrupt(void * opaque)static uint32_t pl031_get_count (PL031State *s) { -int64_t now =qemu_get_clock_ns (rtc_clock); +int64_t now =qemu_clock_get_ns (rtc_clock);return s->tick_offset + now /get_ticks_per_sec (); }
@@ -94,7 +94,7 @@ static void pl031_set_alarm(PL031State *s)qemu_del_timer (s->timer);pl031_interrupt (s); }else { -int64_t now =qemu_get_clock_ns (rtc_clock); +int64_t now =qemu_clock_get_ns (rtc_clock);qemu_mod_timer (s->timer, now + (int64_t )ticks *get_ticks_per_sec ()); } }
@@ -201,9 +201,10 @@ static int pl031_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq);qemu_get_timedate (&tm,0 ); - s->tick_offset =mktimegm (&tm) -qemu_get_clock_ns (rtc_clock) /get_ticks_per_sec (); + s->tick_offset =mktimegm (&tm) - +qemu_clock_get_ns (rtc_clock) /get_ticks_per_sec (); - s->timer =qemu_new_timer_ns (rtc_clock, pl031_interrupt, s); + s->timer =timer_new_ns (rtc_clock, pl031_interrupt, s);return 0 ; }
@@ -213,7 +214,7 @@ static void pl031_pre_save(void *opaque)/* tick_offset is base_time - rtc_clock base time. Instead, we want to * store the base time relative to the vm_clock for backwards-compatibility. */ -int64_t delta =qemu_get_clock_ns (rtc_clock) -qemu_get_clock_ns (vm_clock); +int64_t delta =qemu_clock_get_ns (rtc_clock) -qemu_get_clock_ns (vm_clock); s->tick_offset_vmstate = s->tick_offset + delta /get_ticks_per_sec (); }
@@ -221,7 +222,7 @@ static int pl031_post_load(void *opaque, int version_id) {PL031State *s = opaque; -int64_t delta =qemu_get_clock_ns (rtc_clock) -qemu_get_clock_ns (vm_clock); +int64_t delta =qemu_clock_get_ns (rtc_clock) -qemu_get_clock_ns (vm_clock); s->tick_offset = s->tick_offset_vmstate - delta /get_ticks_per_sec ();pl031_set_alarm (s);return 0 ;
hw/timer/twl92230.c +4 -4
@@ -72,14 +72,14 @@ static inline void menelaus_update(MenelausState *s)static inline void menelaus_rtc_start (MenelausState *s) { - s->rtc.next +=qemu_get_clock_ms (rtc_clock); + s->rtc.next +=qemu_clock_get_ms (rtc_clock);qemu_mod_timer (s->rtc.hz_tm, s->rtc.next); }static inline void menelaus_rtc_stop (MenelausState *s) {qemu_del_timer (s->rtc.hz_tm); - s->rtc.next -=qemu_get_clock_ms (rtc_clock); + s->rtc.next -=qemu_clock_get_ms (rtc_clock);if (s->rtc.next <1 ) s->rtc.next =1 ; }
@@ -782,7 +782,7 @@ static void menelaus_pre_save(void *opaque) {MenelausState *s = opaque;/* Should be <= 1000 */ - s->rtc_next_vmstate = s->rtc.next -qemu_get_clock_ms (rtc_clock); + s->rtc_next_vmstate = s->rtc.next -qemu_clock_get_ms (rtc_clock); }static int menelaus_post_load (void *opaque,int version_id)
@@ -843,7 +843,7 @@ static int twl92230_init(I2CSlave *i2c) {MenelausState *s =FROM_I2C_SLAVE (MenelausState, i2c); - s->rtc.hz_tm =qemu_new_timer_ms (rtc_clock, menelaus_rtc_hz, s); + s->rtc.hz_tm =timer_new_ms (rtc_clock, menelaus_rtc_hz, s);/* Three output pins plus one interrupt pin. */ qdev_init_gpio_out (&i2c->qdev, s->out,4 );
include/sysemu/sysemu.h +1 -1
@@ -124,7 +124,7 @@ extern int boot_menu;extern uint8_t *boot_splash_filedata;extern size_t boot_splash_filedata_size;extern uint8_t qemu_extra_params_fw[2 ]; -extern QEMUClock *rtc_clock; +extern QEMUClockType rtc_clock;#define MAX_NODES 64#define MAX_CPUMASK_BITS 255
target-alpha/sys_helper.c +1 -1
@@ -77,7 +77,7 @@ uint64_t helper_get_vmtime(void)uint64_t helper_get_walltime (void ) { -return qemu_get_clock_ns (rtc_clock); +return qemu_clock_get_ns (rtc_clock); }void helper_set_alarm (CPUAlphaState *env,uint64_t expire)
vl.c +5 -5
@@ -196,7 +196,7 @@ NICInfo nd_table[MAX_NICS];int autostart;static int rtc_utc =1 ;static int rtc_date_offset =-1 ;/* -1 means no change */ -QEMUClock *rtc_clock; +QEMUClockType rtc_clock;int vga_interface_type =VGA_NONE ;static int full_screen =0 ;static int no_frame =0 ;
@@ -805,11 +805,11 @@ static void configure_rtc(QemuOpts *opts) value =qemu_opt_get (opts,"clock" );if (value) {if (!strcmp (value,"host" )) { - rtc_clock = host_clock; + rtc_clock =QEMU_CLOCK_HOST ; }else if (!strcmp (value,"rt" )) { - rtc_clock = rt_clock; + rtc_clock =QEMU_CLOCK_REALTIME ; }else if (!strcmp (value,"vm" )) { - rtc_clock = vm_clock; + rtc_clock =QEMU_CLOCK_VIRTUAL ; }else {fprintf (stderr,"qemu: invalid option value '%s'\n" , value);exit (1 );
@@ -2965,7 +2965,7 @@ int main(int argc, char **argv, char **envp)runstate_init ();init_clocks (); - rtc_clock = host_clock; + rtc_clock =QEMU_CLOCK_HOST ;qemu_cache_utils_init (envp);
Signature · 1 line
1.7.9.5
RFC PATCH v10 27/31 aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API
In reply to Alex BlighConvert block_job_sleep_ns and co_sleep_ns to use the new timer API.
--- block/backup.c | 4 ++-- block/commit.c | 2 +- block/mirror.c | 4 ++-- block/stream.c | 2 +- blockjob.c | 4 ++-- include/block/blockjob.h | 2 +- include/block/coroutine.h | 2 +- qemu-coroutine-sleep.c | 10 +++++----- 8 files changed, 15 insertions(+), 15 deletions(-)
block/backup.c +2 -2
@@ -272,9 +272,9 @@ static void coroutine_fn backup_run(void *opaque)uint64_t delay_ns =ratelimit_calculate_delay ( &job->limit, job->sectors_read); job->sectors_read =0 ; -block_job_sleep_ns (&job->common, rt_clock, delay_ns); +block_job_sleep_ns (&job->common,QEMU_CLOCK_REALTIME , delay_ns); }else { -block_job_sleep_ns (&job->common, rt_clock,0 ); +block_job_sleep_ns (&job->common,QEMU_CLOCK_REALTIME ,0 ); }if (block_job_is_cancelled (&job->common)) {
block/commit.c +1 -1
@@ -103,7 +103,7 @@ wait:/* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ -block_job_sleep_ns (&s->common, rt_clock, delay_ns); +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME , delay_ns);if (block_job_is_cancelled (&s->common)) {break ; }
block/mirror.c +2 -2
@@ -439,13 +439,13 @@ static void coroutine_fn mirror_run(void *opaque) delay_ns =0 ; } -block_job_sleep_ns (&s->common, rt_clock, delay_ns); +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME , delay_ns);if (block_job_is_cancelled (&s->common)) {break ; } }else if (!should_complete) { delay_ns = (s->in_flight ==0 && cnt ==0 ?SLICE_TIME :0 ); -block_job_sleep_ns (&s->common, rt_clock, delay_ns); +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME , delay_ns); }else if (cnt ==0 ) {/* The two disks are in sync. Exit and report successful * completion.
block/stream.c +1 -1
@@ -110,7 +110,7 @@ wait:/* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ -block_job_sleep_ns (&s->common, rt_clock, delay_ns); +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME , delay_ns);if (block_job_is_cancelled (&s->common)) {break ; }
blockjob.c +2 -2
@@ -187,7 +187,7 @@ int block_job_cancel_sync(BlockJob *job)return (data.cancelled && data.ret ==0 ) ? -ECANCELED : data.ret; } -void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns) +void block_job_sleep_ns (BlockJob *job,QEMUClockType type,int64_t ns) {assert (job->busy);
@@ -200,7 +200,7 @@ void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns)if (block_job_is_paused (job)) {qemu_coroutine_yield (); }else { -co_sleep_ns (clock, ns); +co_sleep_ns (type, ns); } job->busy = true; }
include/block/blockjob.h +1 -1
@@ -141,7 +141,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,* Put the job to sleep (assuming that it wasn't canceled) for @ns * nanoseconds. Canceling the job will interrupt the wait immediately. */ -void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns); +void block_job_sleep_ns (BlockJob *job,QEMUClockType type,int64_t ns);/** * block_job_completed:
include/block/coroutine.h +1 -1
@@ -214,7 +214,7 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);* Note this function uses timers and hence only works when a main loop is in * use. See main-loop.h and do not use from qemu-tool programs. */ -void coroutine_fn co_sleep_ns(QEMUClock *clock, int64_t ns); +void coroutine_fn co_sleep_ns(QEMUClockType type, int64_t ns);/** * Yield until a file descriptor becomes readable
qemu-coroutine-sleep.c +5 -5
@@ -26,14 +26,14 @@ static void co_sleep_cb(void *opaque)qemu_coroutine_enter (sleep_cb->co,NULL ); } -void coroutine_fn co_sleep_ns(QEMUClock *clock, int64_t ns) +void coroutine_fn co_sleep_ns(QEMUClockType type, int64_t ns) {CoSleepCB sleep_cb = { .co =qemu_coroutine_self (), }; - sleep_cb.ts =qemu_new_timer (clock,SCALE_NS , co_sleep_cb, &sleep_cb); -qemu_mod_timer (sleep_cb.ts,qemu_get_clock_ns (clock) + ns); + sleep_cb.ts =timer_new (type,SCALE_NS , co_sleep_cb, &sleep_cb); +timer_mod (sleep_cb.ts,qemu_clock_get_ns (type) + ns);qemu_coroutine_yield (); -qemu_del_timer (sleep_cb.ts); -qemu_free_timer (sleep_cb.ts); +timer_del (sleep_cb.ts); +timer_free (sleep_cb.ts); }
Signature · 1 line
1.7.9.5
RFC PATCH v10 28/31 aio / timers: Add test harness for AioContext timers
In reply to Alex BlighAdd a test harness for AioContext timers. The g_source equivalent is unsatisfactory as it suffers from false wakeups.
--- tests/test-aio.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+)
tests/test-aio.c +136 -0
@@ -32,6 +32,15 @@ typedef struct {int max; } BHTestData; +typedef struct { +QEMUTimer timer; +QEMUClockType clock_type; +int n; +int max; +int64_t ns; +AioContext *ctx; +}TimerTestData ; +static void bh_test_cb (void *opaque) {BHTestData *data = opaque;
@@ -40,6 +49,24 @@ static void bh_test_cb(void *opaque) } } +static void timer_test_cb (void *opaque) +{ +TimerTestData *data = opaque; +if (++data->n < data->max) { +timer_mod (&data->timer, +qemu_clock_get_ns (data->clock_type) + data->ns); + } +} + +static void dummy_io_handler_read (void *opaque) +{ +} + +static int dummy_io_handler_flush (void *opaque) +{ +return 1 ; +} +static void bh_delete_cb (void *opaque) {BHTestData *data = opaque;
@@ -341,6 +368,65 @@ static void test_wait_event_notifier_noflush(void)event_notifier_cleanup (&data.e); } +static void test_timer_schedule (void ) +{ +TimerTestData data = { .n =0 , .ctx = ctx, .ns =SCALE_MS *750LL , + .max =2 , + .clock_type =QEMU_CLOCK_VIRTUAL }; +int pipefd[2 ]; + +/* aio_poll will not block to wait for timers to complete unless it has +* an fd to wait on. Fixing this breaks other tests. So create a dummy one. +*/ +g_assert (!pipe2 (pipefd,O_NONBLOCK )); +aio_set_fd_handler (ctx, pipefd[0 ], + dummy_io_handler_read,NULL , dummy_io_handler_flush, +NULL ); +aio_poll (ctx, false); + +aio_timer_init (ctx, &data.timer, data.clock_type, +SCALE_NS , timer_test_cb, &data); +timer_mod (&data.timer, +qemu_clock_get_ns (data.clock_type) + + data.ns); + + g_assert_cmpint(data.n, ==, 0); + +/* timer_mod may well cause an event notifer to have gone off, +* so clear that +*/ +do {}while (aio_poll (ctx, false)); + +g_assert (!aio_poll (ctx, false)); + g_assert_cmpint(data.n, ==, 0); + +sleep (1 ); + g_assert_cmpint(data.n, ==, 0); + +g_assert (aio_poll (ctx, false)); + g_assert_cmpint(data.n, ==, 1); + +/* timer_mod called by our callback */ +do {}while (aio_poll (ctx, false)); + +g_assert (!aio_poll (ctx, false)); + g_assert_cmpint(data.n, ==, 1); + +g_assert (aio_poll (ctx, true)); + g_assert_cmpint(data.n, ==, 2); + +/* As max is now 2, an event notifier should not have gone off */ + +g_assert (!aio_poll (ctx, false)); + g_assert_cmpint(data.n, ==, 2); + +aio_set_fd_handler (ctx, pipefd[0 ],NULL ,NULL ,NULL ,NULL ); +close (pipefd[0 ]); +close (pipefd[1 ]); + +timer_del (&data.timer); +} +/* Now the same tests, using the context as a GSource. They are * very similar to the ones above, with g_main_context_iteration * replacing aio_poll. However:
@@ -623,6 +709,54 @@ static void test_source_wait_event_notifier_noflush(void)event_notifier_cleanup (&data.e); } +static void test_source_timer_schedule (void ) +{ +TimerTestData data = { .n =0 , .ctx = ctx, .ns =SCALE_MS *750LL , + .max =2 , + .clock_type =QEMU_CLOCK_VIRTUAL }; +int pipefd[2 ]; +int64_t expiry; + +/* aio_poll will not block to wait for timers to complete unless it has +* an fd to wait on. Fixing this breaks other tests. So create a dummy one. +*/ +g_assert (!pipe2 (pipefd,O_NONBLOCK )); +aio_set_fd_handler (ctx, pipefd[0 ], + dummy_io_handler_read,NULL , dummy_io_handler_flush, +NULL ); +do {}while (g_main_context_iteration (NULL , false)); + +aio_timer_init (ctx, &data.timer, data.clock_type, +SCALE_NS , timer_test_cb, &data); + expiry =qemu_clock_get_ns (data.clock_type) + + data.ns; +timer_mod (&data.timer, expiry); + + g_assert_cmpint(data.n, ==, 0); + +sleep (1 ); + g_assert_cmpint(data.n, ==, 0); + +g_assert (g_main_context_iteration (NULL , false)); + g_assert_cmpint(data.n, ==, 1); + +/* The comment above was not kidding when it said this wakes up itself */ +do { +g_assert (g_main_context_iteration (NULL , true)); + }while (qemu_clock_get_ns (data.clock_type) <= expiry); +sleep (1 ); +g_main_context_iteration (NULL , false); + + g_assert_cmpint(data.n, ==, 2); + +aio_set_fd_handler (ctx, pipefd[0 ],NULL ,NULL ,NULL ,NULL ); +close (pipefd[0 ]); +close (pipefd[1 ]); + +timer_del (&data.timer); +} + +/* End of tests. */ int main (int argc,char **argv)
@@ -651,6 +785,7 @@ int main(int argc, char **argv)g_test_add_func ("/aio/event/wait" , test_wait_event_notifier);g_test_add_func ("/aio/event/wait/no-flush-cb" , test_wait_event_notifier_noflush);g_test_add_func ("/aio/event/flush" , test_flush_event_notifier); +g_test_add_func ("/aio/timer/schedule" , test_timer_schedule);g_test_add_func ("/aio-gsource/notify" , test_source_notify);g_test_add_func ("/aio-gsource/flush" , test_source_flush);
@@ -665,5 +800,6 @@ int main(int argc, char **argv)g_test_add_func ("/aio-gsource/event/wait" , test_source_wait_event_notifier);g_test_add_func ("/aio-gsource/event/wait/no-flush-cb" , test_source_wait_event_notifier_noflush);g_test_add_func ("/aio-gsource/event/flush" , test_source_flush_event_notifier); +g_test_add_func ("/aio-gsource/timer/schedule" , test_source_timer_schedule);return g_test_run (); }
Signature · 1 line
1.7.9.5
RFC PATCH v10 29/31 aio / timers: Add scripts/switch-timer-api
In reply to Alex BlighAdd scripts/switch-timer-api to programatically rewrite source files to use the new timer system.
--- scripts/switch-timer-api | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+)
scripts/switch-timer-api new file +178 -0
@@ -0,0 +1,178 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Getopt::Long; +use FindBin; + +my @legacy = qw(qemu_clock_ptr qemu_get_clock_ns qemu_get_clock_ms qemu_register_clock_reset_notifier qemu_unregister_clock_reset_notifier qemu_new_timer qemu_free_timer qemu_del_timer qemu_mod_timer_ns qemu_mod_timer qemu_run_timers qemu_new_timer_ns qemu_new_timer_us qemu_new_timer_ms); +my $legacyre = '\b('.join('|', @legacy).')\b'; +my $option_git; +my $option_dryrun; +my $option_quiet; +my $option_rtc; +my $suffix=".tmp.$$"; +my @files; +my $getfiles = 'git grep -l -E \'\b((host|rt|vm|rtc)_clock\b|qemu_\w*timer)\' | egrep \'\.[ch]$\' | egrep -v \'qemu-timer\.c$|include/qemu/timer\.h$\''; + +sub Syntax +{ + print STDERR <<STOP; +Usage: $FindBin::Script [options] FILE ... + +Translate each FILE to the new Qemu timer API. If no files +are passed, a reasonable guess is taken. + +Options: + -q, --quiet Do not show warnings etc + -d, --dry-run Do a dry run + -g, --git Generate a git commit for each change + -r, --rtc Only fix up rtc usage + -h, --help Print this message + +STOP +return; +} + +sub ParseOptions +{ + if (!GetOptions ( + "dry-run|d" => \$option_dryrun, + "git|g" => \$option_git, + "quiet|q" => \$option_quiet, + "rtc|r" => \$option_rtc, + "help|h" => sub { Syntax(); exit(0); } + )) + { + Syntax(); + die "Bad options"; + } + + if ($#ARGV >=0) + { + @files = @ARGV; + } + else + { + @files = split(/\s+/, `$getfiles`); + } + + foreach my $file (@files) + { + die "Cannot find $file" unless (-f $file && -r $file); + } +} + +sub DoWarn +{ + my $text = shift @_; + my $line = shift @_; + return if ($option_quiet); + chomp ($line); + print STDERR "$text\n"; + print STDERR "$line\n\n"; +} + +sub Process +{ + my $ifn = shift @_; + my $ofn = $ifn.$suffix; + + my $intext; + my $outtext; + my $linenum = 0; + + open my $input, "<", $ifn || die "Cannot open $ifn for read: $!"; + + while (<$input>) + { + my $line = $_; + $intext .= $line; + $linenum++; + + # fix the specific uses + unless ($option_rtc) + { + $line =~ s/\bqemu_new_timer(_[num]s)\s*\((vm_|rt_|host_)clock\b/timer_new$1(XXX_$2clock/g; + $line =~ s/\bqemu_new_timer\s*\((vm_|rt_|host_)clock\b/timer_new(XXX_$1clock/g; + $line =~ s/\bqemu_get_clock(_[num]s)\s*\((vm_|rt_|host_)clock\b/qemu_clock_get$1(XXX_$2clock/g; + } + + # rtc is different + $line =~ s/\bqemu_new_timer(_[num]s)\s*\(rtc_clock\b/timer_new$1(rtc_clock/g; + $line =~ s/\bqemu_new_timer\s*\(rtc_clock\b/timer_new(rtc_clock/g; + $line =~ s/\bqemu_get_clock(_[num]s)\s*\(rtc_clock\b/qemu_clock_get$1(rtc_clock/g; + $line =~ s/\bqemu_register_clock_reset_notifier\s*\(rtc_clock\b/qemu_register_clock_reset_notifier(qemu_clock_ptr(rtc_clock)/g; + + unless ($option_rtc) + { + # fix up comments + $line =~ s/\b(vm_|rt_|host_)clock\b/XXX_$1clock/g if ($line =~ m,^[/ ]+\*,); + + # spurious fprintf error reporting + $line =~ s/: qemu_new_timer_ns failed/: timer_new_ns failed/g; + + # these have just changed name + $line =~ s/\bqemu_mod_timer\b/timer_mod/g; + $line =~ s/\bqemu_mod_timer_(ns|us|ms)\b/timer_mod_$1/g; + $line =~ s/\bqemu_free_timer\b/timer_free/g; + $line =~ s/\bqemu_del_timer\b/timer_del/g; + } + + # fix up rtc_clock + $line =~ s/QEMUClock \*rtc_clock;/QEMUClockType rtc_clock;/g; + $line =~ s/\brtc_clock = (vm_|rt_|host_)clock\b/rtc_clock = XXX_$1clock/g; + + unless ($option_rtc) + { + # replace any more general uses + $line =~ s/\b(vm_|rt_|host_)clock\b/qemu_clock_ptr(XXX_$1clock)/g; + } + + # fix up the place holders + $line =~ s/\bXXX_vm_clock\b/QEMU_CLOCK_VIRTUAL/g; + $line =~ s/\bXXX_rt_clock\b/QEMU_CLOCK_REALTIME/g; + $line =~ s/\bXXX_host_clock\b/QEMU_CLOCK_HOST/g; + + unless ($option_rtc) + { + DoWarn("$ifn:$linenum WARNING: timer $1 not fixed up", $line) if ($line =~ /\b((vm_|rt_|host_)clock)\b/); + DoWarn("$ifn:$linenum WARNING: function $1 not fixed up", $line) if ($line =~ /\b(qemu_new_timer\w+)\b/); + DoWarn("$ifn:$linenum WARNING: legacy function $1 remains", $line) if ($line =~ /$legacyre/o); + } + + $outtext .= $line; + } + + close $input; + + if ($intext ne $outtext) + { + print STDERR "Patching $ifn\n" unless ($option_quiet); + unless ($option_dryrun) + { + open my $output, ">", $ofn || die "Cannot open $ofn for write: $!"; + print $output $outtext; + close $output; + rename ($ofn, $ifn) || die "Cannot rename temp file to $ifn: $!"; + return 1; + } + } + return 0; +} + +sub DoCommit +{ + my $file = shift @_; + open (my $git, "| git commit -F - $file") || die "Cannot run git commit on $file: $!"; + print $git "timers api: use new timer api in $file\n\nConvert $file to use new timer API.\nThis is an automated commit made by scripts/switch-timer-api\n"; + close ($git); +} + +ParseOptions; + +foreach my $file (@files) +{ + my $changed = Process ($file); + DoCommit($file) if ($changed && $option_git); +}
Signature · 1 line
1.7.9.5
RFC PATCH v10 30/31 aio / timers: Switch entire codebase to the new timer API
In reply to Alex BlighThis is an autogenerated patch using scripts/switch-timer-api.
Switch the entire code base to using the new timer API.
Note this patch may introduce some line length issues.
--- arch_init.c | 12 ++++---- audio/audio.c | 6 ++-- audio/noaudio.c | 4 +-- audio/spiceaudio.c | 4 +-- audio/wavaudio.c | 2 +- backends/baum.c | 12 ++++---- block.c | 14 +++++----- block/iscsi.c | 14 +++++----- block/mirror.c | 6 ++-- block/qed.c | 10 +++---- blockdev.c | 2 +- hmp.c | 8 +++--- hw/acpi/core.c | 8 +++--- hw/alpha/typhoon.c | 2 +- hw/arm/omap1.c | 48 ++++++++++++++++---------------- hw/arm/pxa2xx.c | 26 +++++++++--------- hw/arm/spitz.c | 6 ++-- hw/arm/stellaris.c | 10 +++---- hw/arm/strongarm.c | 24 ++++++++-------- hw/audio/adlib.c | 2 +- hw/audio/intel-hda.c | 4 +-- hw/audio/sb16.c | 6 ++-- hw/block/fdc.c | 6 ++-- hw/block/nvme.c | 20 +++++++------- hw/block/pflash_cfi01.c | 2 +- hw/block/pflash_cfi02.c | 10 +++---- hw/bt/hci-csr.c | 4 +-- hw/bt/hci.c | 38 ++++++++++++------------- hw/bt/l2cap.c | 8 +++--- hw/char/cadence_uart.c | 12 ++++---- hw/char/serial.c | 22 +++++++-------- hw/char/virtio-serial-bus.c | 10 +++---- hw/core/ptimer.c | 18 ++++++------ hw/display/qxl-logger.c | 2 +- hw/display/qxl.c | 2 +- hw/display/vga.c | 6 ++-- hw/dma/pl330.c | 6 ++-- hw/dma/rc4030.c | 4 +-- hw/dma/soc_dma.c | 8 +++--- hw/i386/kvm/apic.c | 2 +- hw/i386/kvm/i8254.c | 6 ++-- hw/i386/xen_domainbuild.c | 6 ++-- hw/ide/core.c | 6 ++-- hw/input/hid.c | 10 +++---- hw/input/lm832x.c | 8 +++--- hw/input/tsc2005.c | 10 +++---- hw/input/tsc210x.c | 26 +++++++++--------- hw/intc/apic.c | 16 +++++------ hw/intc/apic_common.c | 2 +- hw/intc/armv7m_nvic.c | 16 +++++------ hw/intc/i8259.c | 4 +-- hw/mips/cputimer.c | 12 ++++---- hw/misc/arm_sysctl.c | 2 +- hw/misc/macio/cuda.c | 34 +++++++++++------------ hw/misc/macio/macio.c | 4 +-- hw/misc/vfio.c | 14 +++++----- hw/net/dp8393x.c | 20 +++++++------- hw/net/e1000.c | 12 ++++---- hw/net/lan9118.c | 4 +-- hw/net/pcnet-pci.c | 4 +-- hw/net/pcnet.c | 10 +++---- hw/net/rtl8139.c | 28 +++++++++---------- hw/net/virtio-net.c | 20 +++++++------- hw/openrisc/cputimer.c | 10 +++---- hw/ppc/ppc.c | 64 +++++++++++++++++++++---------------------- hw/ppc/ppc405_uc.c | 8 +++--- hw/ppc/ppc_booke.c | 10 +++---- hw/ppc/spapr.c | 8 +++--- hw/sd/sdhci.c | 28 +++++++++---------- hw/sparc64/sun4u.c | 20 +++++++------- hw/timer/arm_mptimer.c | 12 ++++---- hw/timer/cadence_ttc.c | 6 ++-- hw/timer/etraxfs_timer.c | 2 +- hw/timer/exynos4210_mct.c | 2 +- hw/timer/hpet.c | 20 +++++++------- hw/timer/i8254.c | 26 +++++++++--------- hw/timer/i8254_common.c | 4 +-- hw/timer/m48t59.c | 16 +++++------ hw/timer/mc146818rtc.c | 16 +++++------ hw/timer/omap_gptimer.c | 24 ++++++++-------- hw/timer/omap_synctimer.c | 2 +- hw/timer/pl031.c | 10 +++---- hw/timer/pxa2xx_timer.c | 34 +++++++++++------------ hw/timer/tusb6010.c | 12 ++++---- hw/timer/twl92230.c | 6 ++-- hw/usb/hcd-ehci.c | 10 +++---- hw/usb/hcd-musb.c | 6 ++-- hw/usb/hcd-ohci.c | 12 ++++---- hw/usb/hcd-uhci.c | 14 +++++----- hw/usb/hcd-xhci.c | 26 +++++++++--------- hw/usb/host-libusb.c | 6 ++-- hw/usb/host-linux.c | 6 ++-- hw/usb/redirect.c | 12 ++++---- hw/virtio/virtio-balloon.c | 8 +++--- hw/virtio/virtio-rng.c | 14 +++++----- hw/watchdog/wdt_i6300esb.c | 6 ++-- hw/watchdog/wdt_ib700.c | 10 +++---- hw/xtensa/pic_cpu.c | 10 +++---- include/hw/acpi/acpi.h | 2 +- include/qemu/ratelimit.h | 2 +- migration.c | 16 +++++------ monitor.c | 8 +++--- net/dump.c | 2 +- qemu-char.c | 2 +- qtest.c | 8 +++--- savevm.c | 14 +++++----- slirp/if.c | 2 +- slirp/slirp.c | 4 +-- target-alpha/sys_helper.c | 10 +++---- target-ppc/kvm.c | 8 +++--- target-ppc/kvm_ppc.c | 6 ++-- target-s390x/cpu.c | 4 +-- target-s390x/misc_helper.c | 6 ++-- target-xtensa/op_helper.c | 2 +- tests/libqtest.h | 24 ++++++++-------- ui/console.c | 30 ++++++++++---------- ui/input.c | 6 ++-- ui/spice-core.c | 10 +++---- xen-all.c | 12 ++++---- 119 files changed, 671 insertions(+), 671 deletions(-)
arch_init.c +6 -6
@@ -392,7 +392,7 @@ static void migration_bitmap_sync(void) }if (!start_time) { - start_time =qemu_get_clock_ms (rt_clock); + start_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ); }trace_migration_bitmap_sync_start ();
@@ -410,7 +410,7 @@ static void migration_bitmap_sync(void)trace_migration_bitmap_sync_end (migration_dirty_pages - num_dirty_pages_init); num_dirty_pages_period += migration_dirty_pages - num_dirty_pages_init; - end_time =qemu_get_clock_ms (rt_clock); + end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );/* more than 1 second = 1000 millisecons */ if (end_time > start_time +1000 ) {
@@ -672,7 +672,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)ram_control_before_iterate (f,RAM_CONTROL_ROUND ); - t0 =qemu_get_clock_ns (rt_clock); + t0 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); i =0 ;while ((ret =qemu_file_rate_limit (f)) ==0 ) {int bytes_sent;
@@ -691,7 +691,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)iterations */ if ((i &63 ) ==0 ) { -uint64_t t1 = (qemu_get_clock_ns (rt_clock) - t0) /1000000 ; +uint64_t t1 = (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - t0) /1000000 ;if (t1 >MAX_WAIT ) {DPRINTF ("big wait: %" PRIu64" milliseconds, %d iterations\n" , t1, i);
@@ -1217,11 +1217,11 @@ static void check_guest_throttling(void) }if (!t0) { - t0 =qemu_get_clock_ns (rt_clock); + t0 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );return ; } - t1 =qemu_get_clock_ns (rt_clock); + t1 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );/* If it has been more than 40 ms since the last time the guest * was throttled then do it again.
audio/audio.c +3 -3
@@ -1124,10 +1124,10 @@ static int audio_is_timer_needed (void)static void audio_reset_timer (AudioState *s) {if (audio_is_timer_needed ()) { -qemu_mod_timer (s->ts,qemu_get_clock_ns (vm_clock) +1 ); +timer_mod (s->ts,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +1 ); }else { -qemu_del_timer (s->ts); +timer_del (s->ts); } }
@@ -1834,7 +1834,7 @@ static void audio_init (void)QLIST_INIT (&s->cap_head);atexit (audio_atexit); - s->ts =qemu_new_timer_ns (vm_clock, audio_timer, s); + s->ts =timer_new_ns (QEMU_CLOCK_VIRTUAL , audio_timer, s);if (!s->ts) {hw_error ("Could not create audio timer\n" ); }
audio/noaudio.c +2 -2
@@ -46,7 +46,7 @@ static int no_run_out (HWVoiceOut *hw, int live)int64_t ticks;int64_t bytes; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ticks = now - no->old_ticks; bytes =muldiv64 (ticks, hw->info.bytes_per_second,get_ticks_per_sec ()); bytes =audio_MIN (bytes,INT_MAX );
@@ -102,7 +102,7 @@ static int no_run_in (HWVoiceIn *hw)int samples =0 ;if (dead) { -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int64_t ticks = now - no->old_ticks;int64_t bytes =muldiv64 (ticks, hw->info.bytes_per_second,get_ticks_per_sec ());
audio/spiceaudio.c +2 -2
@@ -81,7 +81,7 @@ static void spice_audio_fini (void *opaque)static void rate_start (SpiceRateCtl *rate) {memset (rate,0 ,sizeof (*rate)); - rate->start_ticks =qemu_get_clock_ns (vm_clock); + rate->start_ticks =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }static int rate_get_samples (struct audio_pcm_info *info,SpiceRateCtl *rate)
@@ -91,7 +91,7 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)int64_t bytes;int64_t samples; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ticks = now - rate->start_ticks; bytes =muldiv64 (ticks, info->bytes_per_second,get_ticks_per_sec ()); samples = (bytes - rate->bytes_sent) >> info->shift;
audio/wavaudio.c +1 -1
@@ -52,7 +52,7 @@ static int wav_run_out (HWVoiceOut *hw, int live)int rpos, decr, samples;uint8_t *dst;struct st_sample *src; -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int64_t ticks = now - wav->old_ticks;int64_t bytes =muldiv64 (ticks, hw->info.bytes_per_second,get_ticks_per_sec ());
backends/baum.c +6 -6
@@ -315,7 +315,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)if (*cur++ !=ESC ) { \DPRINTF ("Broken packet %#2x, tossing\n" , req); \if (timer_pending (baum->cellCount_timer)) { \ -qemu_del_timer (baum->cellCount_timer); \ +timer_del (baum->cellCount_timer); \baum_cellCount_timer_cb (baum); \ } \return (cur -2 - buf); \
@@ -334,7 +334,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)int i;/* Allow 100ms to complete the DisplayData packet */ -qemu_mod_timer (baum->cellCount_timer,qemu_get_clock_ns (vm_clock) + +timer_mod (baum->cellCount_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () /10 );for (i =0 ; i < baum->x * baum->y ; i++) {EAT (c);
@@ -348,7 +348,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len) c ='?' ; text[i] = c; } -qemu_del_timer (baum->cellCount_timer); +timer_del (baum->cellCount_timer);memset (zero,0 ,sizeof (zero));
@@ -553,7 +553,7 @@ static void baum_close(struct CharDriverState *chr) {BaumDriverState *baum = chr->opaque; -qemu_free_timer (baum->cellCount_timer); +timer_free (baum->cellCount_timer);if (baum->brlapi) {brlapi__closeConnection (baum->brlapi);g_free (baum->brlapi);
@@ -588,7 +588,7 @@ CharDriverState *chr_baum_init(void) goto fail_handle; } - baum->cellCount_timer =qemu_new_timer_ns (vm_clock, baum_cellCount_timer_cb, baum); + baum->cellCount_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , baum_cellCount_timer_cb, baum);if (brlapi__getDisplaySize (handle, &baum->x, &baum->y) ==-1 ) {brlapi_perror ("baum_init: brlapi_getDisplaySize" );
@@ -614,7 +614,7 @@ CharDriverState *chr_baum_init(void)return chr; fail: -qemu_free_timer (baum->cellCount_timer); +timer_free (baum->cellCount_timer);brlapi__closeConnection (handle); fail_handle:g_free (handle);
block.c +7 -7
@@ -130,8 +130,8 @@ void bdrv_io_limits_disable(BlockDriverState *bs)do {}while (qemu_co_enter_next (&bs->throttled_reqs));if (bs->block_timer) { -qemu_del_timer (bs->block_timer); -qemu_free_timer (bs->block_timer); +timer_del (bs->block_timer); +timer_free (bs->block_timer); bs->block_timer =NULL ; }
@@ -149,7 +149,7 @@ static void bdrv_block_timer(void *opaque)void bdrv_io_limits_enable (BlockDriverState *bs) {qemu_co_queue_init (&bs->throttled_reqs); - bs->block_timer =qemu_new_timer_ns (vm_clock, bdrv_block_timer, bs); + bs->block_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , bdrv_block_timer, bs); bs->io_limits_enabled = true; }
@@ -181,8 +181,8 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,*/ while (bdrv_exceed_io_limits (bs, nb_sectors, is_write, &wait_time)) { -qemu_mod_timer (bs->block_timer, - wait_time +qemu_get_clock_ns (vm_clock)); +timer_mod (bs->block_timer, + wait_time +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));qemu_co_queue_wait_insert_head (&bs->throttled_reqs); }
@@ -3692,7 +3692,7 @@ static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,double elapsed_time;int bps_ret, iops_ret; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (now > bs->slice_end) { bs->slice_start = now; bs->slice_end = now +BLOCK_IO_SLICE_TIME ;
@@ -3712,7 +3712,7 @@ static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors, *wait = max_wait; } - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (bs->slice_end < now + max_wait) { bs->slice_end = now + max_wait; }
block/iscsi.c +7 -7
@@ -968,7 +968,7 @@ static void iscsi_nop_timed_event(void *opaque) return; } -qemu_mod_timer (iscsilun->nop_timer,qemu_get_clock_ms (rt_clock) +NOP_INTERVAL ); +timer_mod (iscsilun->nop_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +NOP_INTERVAL );iscsi_set_events (iscsilun); }#endif
@@ -1181,8 +1181,8 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags)#if defined(LIBISCSI_FEATURE_NOP_COUNTER )/* Set up a timer for sending out iSCSI NOPs */ - iscsilun->nop_timer =qemu_new_timer_ms (rt_clock, iscsi_nop_timed_event, iscsilun); -qemu_mod_timer (iscsilun->nop_timer,qemu_get_clock_ms (rt_clock) +NOP_INTERVAL ); + iscsilun->nop_timer =timer_new_ms (QEMU_CLOCK_REALTIME , iscsi_nop_timed_event, iscsilun); +timer_mod (iscsilun->nop_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +NOP_INTERVAL );#endif out:
@@ -1212,8 +1212,8 @@ static void iscsi_close(BlockDriverState *bs)struct iscsi_context *iscsi = iscsilun->iscsi;if (iscsilun->nop_timer) { -qemu_del_timer (iscsilun->nop_timer); -qemu_free_timer (iscsilun->nop_timer); +timer_del (iscsilun->nop_timer); +timer_free (iscsilun->nop_timer); }qemu_aio_set_fd_handler (iscsi_get_fd (iscsi),NULL ,NULL ,NULL ,NULL );iscsi_destroy_context (iscsi);
@@ -1275,8 +1275,8 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options) goto out; }if (iscsilun->nop_timer) { -qemu_del_timer (iscsilun->nop_timer); -qemu_free_timer (iscsilun->nop_timer); +timer_del (iscsilun->nop_timer); +timer_free (iscsilun->nop_timer); }if (iscsilun->type !=TYPE_DISK ) { ret = -ENODEV ;
block/mirror.c +3 -3
@@ -356,7 +356,7 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (bs, &s->hbi); - last_pause_ns =qemu_get_clock_ns (rt_clock); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns;int64_t cnt;
@@ -374,7 +374,7 @@ static void coroutine_fn mirror_run(void *opaque)* We do so every SLICE_TIME nanoseconds, or when there is an error, * or when the source is clean, whichever comes first. */ -if (qemu_get_clock_ns (rt_clock) - last_pause_ns <SLICE_TIME && +if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) {if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {
@@ -454,7 +454,7 @@ static void coroutine_fn mirror_run(void *opaque) s->common.cancelled = false;break ; } - last_pause_ns =qemu_get_clock_ns (rt_clock); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); } immediate_exit:
block/qed.c +5 -5
@@ -353,10 +353,10 @@ static void qed_start_need_check_timer(BDRVQEDState *s) {trace_qed_start_need_check_timer (s); -/* Use vm_clock so we don't alter the image file while suspended for +/* Use QEMU_CLOCK_VIRTUAL so we don't alter the image file while suspended for * migration. */ -qemu_mod_timer (s->need_check_timer,qemu_get_clock_ns (vm_clock) + +timer_mod (s->need_check_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () *QED_NEED_CHECK_TIMEOUT ); }
@@ -364,7 +364,7 @@ static void qed_start_need_check_timer(BDRVQEDState *s)static void qed_cancel_need_check_timer (BDRVQEDState *s) {trace_qed_cancel_need_check_timer (s); -qemu_del_timer (s->need_check_timer); +timer_del (s->need_check_timer); }static void bdrv_qed_rebind (BlockDriverState *bs)
@@ -494,7 +494,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags) } } - s->need_check_timer =qemu_new_timer_ns (vm_clock, + s->need_check_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , qed_need_check_timer_cb, s); out:
@@ -518,7 +518,7 @@ static void bdrv_qed_close(BlockDriverState *bs)BDRVQEDState *s = bs->opaque;qed_cancel_need_check_timer (s); -qemu_free_timer (s->need_check_timer); +timer_free (s->need_check_timer);/* Ensure writes reach stable storage */ bdrv_flush (bs->file);
blockdev.c +1 -1
@@ -1290,7 +1290,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,bdrv_io_limits_disable (bs); }else {if (bs->block_timer) { -qemu_mod_timer (bs->block_timer,qemu_get_clock_ns (vm_clock)); +timer_mod (bs->block_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); } } }
hmp.c +4 -4
@@ -1195,13 +1195,13 @@ static void hmp_migrate_status_cb(void *opaque)monitor_flush (status->mon); } -qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock) +1000 ); +timer_mod (status->timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +1000 ); }else {if (status->is_block_migration) {monitor_printf (status->mon,"\n" ); }monitor_resume (status->mon); -qemu_del_timer (status->timer); +timer_del (status->timer);g_free (status); }
@@ -1235,9 +1235,9 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) status =g_malloc0 (sizeof (*status)); status->mon = mon; status->is_block_migration = blk || inc; - status->timer =qemu_new_timer_ms (rt_clock, hmp_migrate_status_cb, + status->timer =timer_new_ms (QEMU_CLOCK_REALTIME , hmp_migrate_status_cb, status); -qemu_mod_timer (status->timer,qemu_get_clock_ms (rt_clock)); +timer_mod (status->timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME )); } }
hw/acpi/core.c +4 -4
@@ -433,9 +433,9 @@ void acpi_pm_tmr_update(ACPIREGS *ar, bool enable)if (enable) { expire_time =muldiv64 (ar->tmr.overflow_time,get_ticks_per_sec (),PM_TIMER_FREQUENCY ); -qemu_mod_timer (ar->tmr.timer, expire_time); +timer_mod (ar->tmr.timer, expire_time); }else { -qemu_del_timer (ar->tmr.timer); +timer_del (ar->tmr.timer); } }
@@ -481,7 +481,7 @@ void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci, MemoryRegion *parent) { ar->tmr.update_sci = update_sci; - ar->tmr.timer =qemu_new_timer_ns (vm_clock, acpi_pm_tmr_timer, ar); + ar->tmr.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , acpi_pm_tmr_timer, ar);memory_region_init_io (&ar->tmr.io,memory_region_owner (parent), &acpi_pm_tmr_ops, ar,"acpi-tmr" ,4 );memory_region_add_subregion (parent,8 , &ar->tmr.io);
@@ -490,7 +490,7 @@ void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,void acpi_pm_tmr_reset (ACPIREGS *ar) { ar->tmr.overflow_time =0 ; -qemu_del_timer (ar->tmr.timer); +timer_del (ar->tmr.timer); }/* ACPI PM1aCNT */
hw/alpha/typhoon.c +1 -1
@@ -693,7 +693,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,AlphaCPU *cpu = cpus[i]; s->cchip.cpu[i] = cpu;if (cpu !=NULL ) { - cpu->alarm_timer =qemu_new_timer_ns (vm_clock, + cpu->alarm_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , typhoon_alarm_timer, (void *)((uintptr_t )s + i)); }
hw/arm/omap1.c +24 -24
172 lines not on this page · raw message
hw/arm/pxa2xx.c +13 -13
@@ -335,7 +335,7 @@ static int pxa2xx_cpccnt_read(CPUARMState *env, const ARMCPRegInfo *ri, {PXA2xxState *s = (PXA2xxState *)ri->opaque;if (s->pmnc &1 ) { - *value =qemu_get_clock_ns (vm_clock); + *value =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }else { *value =0 ; }
@@ -870,43 +870,43 @@ static inline void pxa2xx_rtc_alarm_update(PXA2xxRTCState *s, uint32_t rtsr) {if ((rtsr & (1 <<2 )) && !(rtsr & (1 <<0 ))) -qemu_mod_timer (s->rtc_hz, s->last_hz + +timer_mod (s->rtc_hz, s->last_hz + (((s->rtar - s->last_rcnr) *1000 * ((s->rttr &0xffff ) +1 )) >>15 ));else -qemu_del_timer (s->rtc_hz); +timer_del (s->rtc_hz);if ((rtsr & (1 <<5 )) && !(rtsr & (1 <<4 ))) -qemu_mod_timer (s->rtc_rdal1, s->last_hz + +timer_mod (s->rtc_rdal1, s->last_hz + (((s->rdar1 - s->last_rdcr) *1000 * ((s->rttr &0xffff ) +1 )) >>15 ));/* TODO: fixup */ else -qemu_del_timer (s->rtc_rdal1); +timer_del (s->rtc_rdal1);if ((rtsr & (1 <<7 )) && !(rtsr & (1 <<6 ))) -qemu_mod_timer (s->rtc_rdal2, s->last_hz + +timer_mod (s->rtc_rdal2, s->last_hz + (((s->rdar2 - s->last_rdcr) *1000 * ((s->rttr &0xffff ) +1 )) >>15 ));/* TODO: fixup */ else -qemu_del_timer (s->rtc_rdal2); +timer_del (s->rtc_rdal2);if ((rtsr &0x1200 ) ==0x1200 && !(rtsr & (1 <<8 ))) -qemu_mod_timer (s->rtc_swal1, s->last_sw + +timer_mod (s->rtc_swal1, s->last_sw + (s->swar1 - s->last_swcr) *10 );/* TODO: fixup */ else -qemu_del_timer (s->rtc_swal1); +timer_del (s->rtc_swal1);if ((rtsr &0x1800 ) ==0x1800 && !(rtsr & (1 <<10 ))) -qemu_mod_timer (s->rtc_swal2, s->last_sw + +timer_mod (s->rtc_swal2, s->last_sw + (s->swar2 - s->last_swcr) *10 );/* TODO: fixup */ else -qemu_del_timer (s->rtc_swal2); +timer_del (s->rtc_swal2);if ((rtsr &0xc000 ) ==0xc000 && !(rtsr & (1 <<13 ))) -qemu_mod_timer (s->rtc_pi, s->last_pi + +timer_mod (s->rtc_pi, s->last_pi + (s->piar &0xffff ) - s->last_rtcpicr);else -qemu_del_timer (s->rtc_pi); +timer_del (s->rtc_pi); }static inline void pxa2xx_rtc_hz_tick (void *opaque)
hw/arm/spitz.c +3 -3
@@ -393,7 +393,7 @@ static void spitz_keyboard_tick(void *opaque) s->fifopos =0 ; } -qemu_mod_timer (s->kbdtimer,qemu_get_clock_ns (vm_clock) + +timer_mod (s->kbdtimer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () /32 ); }
@@ -485,7 +485,7 @@ static void spitz_keyboard_register(PXA2xxState *cpu)qdev_connect_gpio_out (cpu->gpio, spitz_gpio_key_strobe[i],qdev_get_gpio_in (dev, i)); -qemu_mod_timer (s->kbdtimer,qemu_get_clock_ns (vm_clock)); +timer_mod (s->kbdtimer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));qemu_add_kbd_event_handler (spitz_keyboard_handler, s); }
@@ -505,7 +505,7 @@ static int spitz_keyboard_init(SysBusDevice *sbd)spitz_keyboard_pre_map (s); - s->kbdtimer =qemu_new_timer_ns (vm_clock, spitz_keyboard_tick, s); + s->kbdtimer =timer_new_ns (QEMU_CLOCK_VIRTUAL , spitz_keyboard_tick, s);qdev_init_gpio_in (dev, spitz_keyboard_strobe,SPITZ_KEY_STROBE_NUM );qdev_init_gpio_out (dev, s->sense,SPITZ_KEY_SENSE_NUM );
hw/arm/stellaris.c +5 -5
@@ -78,14 +78,14 @@ static void gptm_update_irq(gptm_state *s)static void gptm_stop (gptm_state *s,int n) { -qemu_del_timer (s->timer[n]); +timer_del (s->timer[n]); }static void gptm_reload (gptm_state *s,int n,int reset) {int64_t tick;if (reset) - tick =qemu_get_clock_ns (vm_clock); + tick =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );else tick = s->tick[n];
@@ -103,7 +103,7 @@ static void gptm_reload(gptm_state *s, int n, int reset)hw_error ("TODO: 16-bit timer mode 0x%x\n" , s->mode[n]); } s->tick[n] = tick; -qemu_mod_timer (s->timer[n], tick); +timer_mod (s->timer[n], tick); }static void gptm_tick (void *opaque)
@@ -318,8 +318,8 @@ static int stellaris_gptm_init(SysBusDevice *sbd)sysbus_init_mmio (sbd, &s->iomem); s->opaque[0 ] = s->opaque[1 ] = s; - s->timer[0 ] =qemu_new_timer_ns (vm_clock, gptm_tick, &s->opaque[0 ]); - s->timer[1 ] =qemu_new_timer_ns (vm_clock, gptm_tick, &s->opaque[1 ]); + s->timer[0 ] =timer_new_ns (QEMU_CLOCK_VIRTUAL , gptm_tick, &s->opaque[0 ]); + s->timer[1 ] =timer_new_ns (QEMU_CLOCK_VIRTUAL , gptm_tick, &s->opaque[1 ]);vmstate_register (dev,-1 , &vmstate_stellaris_gptm, s);return 0 ; }
hw/arm/strongarm.c +12 -12
@@ -278,17 +278,17 @@ static void strongarm_rtc_hzupdate(StrongARMRTCState *s)static inline void strongarm_rtc_timer_update (StrongARMRTCState *s) {if ((s->rtsr &RTSR_HZE ) && !(s->rtsr &RTSR_HZ )) { -qemu_mod_timer (s->rtc_hz, s->last_hz +1000 ); +timer_mod (s->rtc_hz, s->last_hz +1000 ); }else { -qemu_del_timer (s->rtc_hz); +timer_del (s->rtc_hz); }if ((s->rtsr &RTSR_ALE ) && !(s->rtsr &RTSR_AL )) { -qemu_mod_timer (s->rtc_alarm, s->last_hz + +timer_mod (s->rtc_alarm, s->last_hz + (((s->rtar - s->last_rcnr) *1000 * ((s->rttr &0xffff ) +1 )) >>15 )); }else { -qemu_del_timer (s->rtc_alarm); +timer_del (s->rtc_alarm); } }
@@ -1085,8 +1085,8 @@ static void strongarm_uart_receive(void *opaque, const uint8_t *buf, int size) }/* call the timeout receive callback in 3 char transmit time */ -qemu_mod_timer (s->rx_timeout_timer, -qemu_get_clock_ns (vm_clock) + s->char_transmit_time *3 ); +timer_mod (s->rx_timeout_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->char_transmit_time *3 );strongarm_uart_update_status (s);strongarm_uart_update_int_status (s);
@@ -1107,7 +1107,7 @@ static void strongarm_uart_event(void *opaque, int event)static void strongarm_uart_tx (void *opaque) {StrongARMUARTState *s = opaque; -uint64_t new_xmit_ts =qemu_get_clock_ns (vm_clock); +uint64_t new_xmit_ts =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (s->utcr3 &UTCR3_LBM )/* loopback */ {strongarm_uart_receive (s, &s->tx_fifo[s->tx_start],1 );
@@ -1118,7 +1118,7 @@ static void strongarm_uart_tx(void *opaque) s->tx_start = (s->tx_start +1 ) %8 ; s->tx_len--;if (s->tx_len) { -qemu_mod_timer (s->tx_timer, new_xmit_ts + s->char_transmit_time); +timer_mod (s->tx_timer, new_xmit_ts + s->char_transmit_time); }strongarm_uart_update_status (s);strongarm_uart_update_int_status (s);
@@ -1237,8 +1237,8 @@ static int strongarm_uart_init(SysBusDevice *dev)sysbus_init_mmio (dev, &s->iomem);sysbus_init_irq (dev, &s->irq); - s->rx_timeout_timer =qemu_new_timer_ns (vm_clock, strongarm_uart_rx_to, s); - s->tx_timer =qemu_new_timer_ns (vm_clock, strongarm_uart_tx, s); + s->rx_timeout_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , strongarm_uart_rx_to, s); + s->tx_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , strongarm_uart_tx, s);if (s->chr) { qemu_chr_add_handlers(s->chr,
@@ -1282,8 +1282,8 @@ static int strongarm_uart_post_load(void *opaque, int version_id)/* restart rx timeout timer */ if (s->rx_len) { -qemu_mod_timer (s->rx_timeout_timer, -qemu_get_clock_ns (vm_clock) + s->char_transmit_time *3 ); +timer_mod (s->rx_timeout_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->char_transmit_time *3 ); }return 0 ;
hw/audio/adlib.c +1 -1
@@ -173,7 +173,7 @@ static void timer_handler (int c, double interval_Sec) s->ticking[n] =1 ;#ifdef DEBUG interval =get_ticks_per_sec () * interval_Sec; - exp =qemu_get_clock_ns (vm_clock) + interval; + exp =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + interval; s->exp[n] = exp;#endif
hw/audio/intel-hda.c +2 -2
@@ -526,7 +526,7 @@ static void intel_hda_get_wall_clk(IntelHDAState *d, const IntelHDAReg *reg) {int64_t ns; - ns =qemu_get_clock_ns (vm_clock) - d->wall_base_ns; + ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - d->wall_base_ns; d->wall_clk = (uint32_t )(ns *24 /1000 );/* 24 MHz */ }
@@ -1111,7 +1111,7 @@ static void intel_hda_reset(DeviceState *dev)HDACodecDevice *cdev;intel_hda_regs_reset (d); - d->wall_base_ns =qemu_get_clock_ns (vm_clock); + d->wall_base_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );/* reset codecs */ QTAILQ_FOREACH(kid, &d->codecs.qbus.children, sibling) {
hw/audio/sb16.c +3 -3
@@ -768,9 +768,9 @@ static void complete (SB16State *s) }else {if (s->aux_ts) { -qemu_mod_timer ( +timer_mod ( s->aux_ts, -qemu_get_clock_ns (vm_clock) + ticks +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + ticks ); } }
@@ -1378,7 +1378,7 @@ static void sb16_realizefn (DeviceState *dev, Error **errp) s->csp_regs[9 ] =0xf8 ;reset_mixer (s); - s->aux_ts =qemu_new_timer_ns (vm_clock, aux_timer, s); + s->aux_ts =timer_new_ns (QEMU_CLOCK_VIRTUAL , aux_timer, s);if (!s->aux_ts) {dolog ("warning: Could not create auxiliary timer\n" ); }
hw/block/fdc.c +3 -3
@@ -1647,8 +1647,8 @@ static void fdctrl_handle_readid(FDCtrl *fdctrl, int direction)FDrive *cur_drv =get_cur_drv (fdctrl); cur_drv->head = (fdctrl->fifo[1 ] >>2 ) &1 ; -qemu_mod_timer (fdctrl->result_timer, -qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () /50 )); +timer_mod (fdctrl->result_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () /50 )); }static void fdctrl_handle_format_track (FDCtrl *fdctrl,int direction)
@@ -2108,7 +2108,7 @@ static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp)FLOPPY_DPRINTF ("init controller\n" ); fdctrl->fifo =qemu_memalign (512 ,FD_SECTOR_LEN ); fdctrl->fifo_size =512 ; - fdctrl->result_timer =qemu_new_timer_ns (vm_clock, + fdctrl->result_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , fdctrl_result_timer, fdctrl); fdctrl->version =0x90 ;/* Intel 82078 controller */
hw/block/nvme.c +10 -10
@@ -187,7 +187,7 @@ static void nvme_enqueue_req_completion(NvmeCQueue *cq, NvmeRequest *req)assert (cq->cqid == req->sq->cqid);QTAILQ_REMOVE (&req->sq->out_req_list, req, entry);QTAILQ_INSERT_TAIL (&cq->req_list, req, entry); -qemu_mod_timer (cq->timer,qemu_get_clock_ns (vm_clock) +500 ); +timer_mod (cq->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +500 ); }static void nvme_rw_cb (void *opaque,int ret)
@@ -264,8 +264,8 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)static void nvme_free_sq (NvmeSQueue *sq,NvmeCtrl *n) { n->sq[sq->sqid] =NULL ; -qemu_del_timer (sq->timer); -qemu_free_timer (sq->timer); +timer_del (sq->timer); +timer_free (sq->timer);g_free (sq->io_req);if (sq->sqid) {g_free (sq);
@@ -327,7 +327,7 @@ static void nvme_init_sq(NvmeSQueue *sq, NvmeCtrl *n, uint64_t dma_addr, sq->io_req[i].sq = sq;QTAILQ_INSERT_TAIL (&(sq->req_list), &sq->io_req[i], entry); } - sq->timer =qemu_new_timer_ns (vm_clock, nvme_process_sq, sq); + sq->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , nvme_process_sq, sq);assert (n->cq[cqid]); cq = n->cq[cqid];
@@ -369,8 +369,8 @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd)static void nvme_free_cq (NvmeCQueue *cq,NvmeCtrl *n) { n->cq[cq->cqid] =NULL ; -qemu_del_timer (cq->timer); -qemu_free_timer (cq->timer); +timer_del (cq->timer); +timer_free (cq->timer);msix_vector_unuse (&n->parent_obj, cq->vector);if (cq->cqid) {g_free (cq);
@@ -410,7 +410,7 @@ static void nvme_init_cq(NvmeCQueue *cq, NvmeCtrl *n, uint64_t dma_addr,QTAILQ_INIT (&cq->sq_list);msix_vector_use (&n->parent_obj, cq->vector); n->cq[cqid] = cq; - cq->timer =qemu_new_timer_ns (vm_clock, nvme_post_cqes, cq); + cq->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , nvme_post_cqes, cq); }static uint16_t nvme_create_cq (NvmeCtrl *n,NvmeCmd *cmd)
@@ -691,9 +691,9 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)if (start_sqs) {NvmeSQueue *sq; QTAILQ_FOREACH(sq, &cq->sq_list, entry) { -qemu_mod_timer (sq->timer,qemu_get_clock_ns (vm_clock) +500 ); +timer_mod (sq->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +500 ); } -qemu_mod_timer (cq->timer,qemu_get_clock_ns (vm_clock) +500 ); +timer_mod (cq->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +500 ); }if (cq->tail != cq->head) {
@@ -714,7 +714,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) } sq->tail = new_tail; -qemu_mod_timer (sq->timer,qemu_get_clock_ns (vm_clock) +500 ); +timer_mod (sq->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +500 ); } }
hw/block/pflash_cfi01.c +1 -1
@@ -613,7 +613,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->ro =0 ; } - pfl->timer =qemu_new_timer_ns (vm_clock, pflash_timer, pfl); + pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;
hw/block/pflash_cfi02.c +5 -5
@@ -430,8 +430,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset, } pfl->status =0x00 ;/* Let's wait 5 seconds before chip erase is done */ -qemu_mod_timer (pfl->timer, -qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () *5 )); +timer_mod (pfl->timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () *5 ));break ;case 0x30 :/* Sector erase */
@@ -445,8 +445,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset, } pfl->status =0x00 ;/* Let's wait 1/2 second before sector erase is done */ -qemu_mod_timer (pfl->timer, -qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () /2 )); +timer_mod (pfl->timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () /2 ));break ;default :DPRINTF ("%s: invalid command %02x (wc 5)\n" , __func__, cmd);
@@ -633,7 +633,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) pfl->ro =0 ; } - pfl->timer =qemu_new_timer_ns (vm_clock, pflash_timer, pfl); + pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;
hw/bt/hci-csr.c +2 -2
@@ -87,7 +87,7 @@ static inline void csrhci_fifo_wake(struct csrhci_s *s) }if (s->out_len) -qemu_mod_timer (s->out_tm,qemu_get_clock_ns (vm_clock) + s->baud_delay); +timer_mod (s->out_tm,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->baud_delay); }#define csrhci_out_packetz (s, len) memset(csrhci_out_packet(s, len), 0, len)
@@ -446,7 +446,7 @@ CharDriverState *uart_hci_init(qemu_irq wakeup) s->hci->evt_recv = csrhci_out_hci_packet_event; s->hci->acl_recv = csrhci_out_hci_packet_acl; - s->out_tm =qemu_new_timer_ns (vm_clock, csrhci_out_tick, s); + s->out_tm =timer_new_ns (QEMU_CLOCK_VIRTUAL , csrhci_out_tick, s); s->pins =qemu_allocate_irqs (csrhci_pins, s, __csrhci_pins);csrhci_reset (s);
hw/bt/hci.c +19 -19
@@ -576,7 +576,7 @@ static void bt_hci_inquiry_result(struct bt_hci_s *hci,static void bt_hci_mod_timer_1280ms (QEMUTimer *timer,int period) { -qemu_mod_timer (timer,qemu_get_clock_ns (vm_clock) + +timer_mod (timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +muldiv64 (period <<7 ,get_ticks_per_sec (),100 )); }
@@ -657,7 +657,7 @@ static void bt_hci_lmp_link_establish(struct bt_hci_s *hci,if (master) { link->acl_mode = acl_active; hci->lm.handle[hci->lm.last_handle].acl_mode_timer = -qemu_new_timer_ns (vm_clock, bt_hci_mode_tick, link); +timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_mode_tick, link); } }
@@ -667,8 +667,8 @@ static void bt_hci_lmp_link_teardown(struct bt_hci_s *hci, uint16_t handle) hci->lm.handle[handle].link =NULL ;if (bt_hci_role_master (hci, handle)) { -qemu_del_timer (hci->lm.handle[handle].acl_mode_timer); -qemu_free_timer (hci->lm.handle[handle].acl_mode_timer); +timer_del (hci->lm.handle[handle].acl_mode_timer); +timer_free (hci->lm.handle[handle].acl_mode_timer); } }
@@ -1080,7 +1080,7 @@ static int bt_hci_mode_change(struct bt_hci_s *hci, uint16_t handle,bt_hci_event_status (hci,HCI_SUCCESS ); -qemu_mod_timer (link->acl_mode_timer,qemu_get_clock_ns (vm_clock) + +timer_mod (link->acl_mode_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +muldiv64 (interval *625 ,get_ticks_per_sec (),1000000 ));bt_hci_lmp_mode_change_master (hci, link->link, mode, interval);
@@ -1103,7 +1103,7 @@ static int bt_hci_mode_cancel(struct bt_hci_s *hci, uint16_t handle, int mode)bt_hci_event_status (hci,HCI_SUCCESS ); -qemu_del_timer (link->acl_mode_timer); +timer_del (link->acl_mode_timer);bt_hci_lmp_mode_change_master (hci, link->link, acl_active,0 );return 0 ;
@@ -1146,10 +1146,10 @@ static void bt_hci_reset(struct bt_hci_s *hci) hci->psb_handle =0x000 ; hci->asb_handle =0x000 ; -/* XXX: qemu_del_timer(sl->acl_mode_timer); for all links */ -qemu_del_timer (hci->lm.inquiry_done); -qemu_del_timer (hci->lm.inquiry_next); -qemu_del_timer (hci->conn_accept_timer); +/* XXX: timer_del(sl->acl_mode_timer); for all links */ +timer_del (hci->lm.inquiry_done); +timer_del (hci->lm.inquiry_next); +timer_del (hci->conn_accept_timer); }static void bt_hci_read_local_version_rp (struct bt_hci_s *hci)
@@ -1514,7 +1514,7 @@ static void bt_submit_hci(struct HCIInfo *info, } hci->lm.inquire =0 ; -qemu_del_timer (hci->lm.inquiry_done); +timer_del (hci->lm.inquiry_done);bt_hci_event_complete_status (hci,HCI_SUCCESS );break ;
@@ -1552,8 +1552,8 @@ static void bt_submit_hci(struct HCIInfo *info,break ; } hci->lm.inquire =0 ; -qemu_del_timer (hci->lm.inquiry_done); -qemu_del_timer (hci->lm.inquiry_next); +timer_del (hci->lm.inquiry_done); +timer_del (hci->lm.inquiry_next);bt_hci_event_complete_status (hci,HCI_SUCCESS );break ;
@@ -2141,10 +2141,10 @@ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net) {struct bt_hci_s *s =g_malloc0 (sizeof (struct bt_hci_s )); - s->lm.inquiry_done =qemu_new_timer_ns (vm_clock, bt_hci_inquiry_done, s); - s->lm.inquiry_next =qemu_new_timer_ns (vm_clock, bt_hci_inquiry_next, s); + s->lm.inquiry_done =timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_inquiry_done, s); + s->lm.inquiry_next =timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_inquiry_next, s); s->conn_accept_timer = -qemu_new_timer_ns (vm_clock, bt_hci_conn_accept_timeout, s); +timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_conn_accept_timeout, s); s->evt_packet = bt_hci_evt_packet; s->evt_submit = bt_hci_evt_submit;
@@ -2209,9 +2209,9 @@ static void bt_hci_done(struct HCIInfo *info)* s->device.lmp_connection_complete to free the remaining bits once * hci->lm.awaiting_bdaddr[] is empty. */ -qemu_free_timer (hci->lm.inquiry_done); -qemu_free_timer (hci->lm.inquiry_next); -qemu_free_timer (hci->conn_accept_timer); +timer_free (hci->lm.inquiry_done); +timer_free (hci->lm.inquiry_next); +timer_free (hci->conn_accept_timer);g_free (hci); }
hw/bt/l2cap.c +4 -4
@@ -166,9 +166,9 @@ static void l2cap_retransmission_timer_update(struct l2cap_chan_s *ch) {#if 0 if (ch->mode !=L2CAP_MODE_BASIC && ch->rexmit) -qemu_mod_timer (ch->retransmission_timer); +timer_mod (ch->retransmission_timer);else -qemu_del_timer (ch->retransmission_timer); +timer_del (ch->retransmission_timer);#endif }
@@ -176,9 +176,9 @@ static void l2cap_monitor_timer_update(struct l2cap_chan_s *ch) {#if 0 if (ch->mode !=L2CAP_MODE_BASIC && !ch->rexmit) -qemu_mod_timer (ch->monitor_timer); +timer_mod (ch->monitor_timer);else -qemu_del_timer (ch->monitor_timer); +timer_del (ch->monitor_timer);#endif }
hw/char/cadence_uart.c +6 -6
@@ -141,9 +141,9 @@ static void fifo_trigger_update(void *opaque)static void uart_tx_redo (UartState *s) { -uint64_t new_tx_time =qemu_get_clock_ns (vm_clock); +uint64_t new_tx_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); -qemu_mod_timer (s->tx_time_handle, new_tx_time + s->char_tx_time); +timer_mod (s->tx_time_handle, new_tx_time + s->char_tx_time); s->r[R_SR ] |=UART_SR_INTR_TEMPTY ;
@@ -265,7 +265,7 @@ static void uart_ctrl_update(UartState *s)static void uart_write_rx_fifo (void *opaque,const uint8_t *buf,int size) {UartState *s = (UartState *)opaque; -uint64_t new_rx_time =qemu_get_clock_ns (vm_clock); +uint64_t new_rx_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int i;if ((s->r[R_CR ] &UART_CR_RX_DIS ) || !(s->r[R_CR ] &UART_CR_RX_EN )) {
@@ -291,7 +291,7 @@ static void uart_write_rx_fifo(void *opaque, const uint8_t *buf, int size) s->r[R_SR ] |=UART_SR_INTR_RTRIG ; } } -qemu_mod_timer (s->fifo_trigger_handle, new_rx_time + +timer_mod (s->fifo_trigger_handle, new_rx_time + (s->char_tx_time *4 )); }uart_update_status (s);
@@ -452,10 +452,10 @@ static int cadence_uart_init(SysBusDevice *dev)sysbus_init_mmio (dev, &s->iomem);sysbus_init_irq (dev, &s->irq); - s->fifo_trigger_handle =qemu_new_timer_ns (vm_clock, + s->fifo_trigger_handle =timer_new_ns (QEMU_CLOCK_VIRTUAL , (QEMUTimerCB *)fifo_trigger_update, s); - s->tx_time_handle =qemu_new_timer_ns (vm_clock, + s->tx_time_handle =timer_new_ns (QEMU_CLOCK_VIRTUAL , (QEMUTimerCB *)uart_tx_write, s); s->char_tx_time = (get_ticks_per_sec () /9600 ) *10 ;
hw/char/serial.c +11 -11
@@ -188,7 +188,7 @@ static void serial_update_msl(SerialState *s)uint8_t omsr;int flags; -qemu_del_timer (s->modem_status_poll); +timer_del (s->modem_status_poll);if (qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_GET_TIOCM , &flags) == -ENOTSUP ) { s->poll_msl =-1 ;
@@ -215,7 +215,7 @@ static void serial_update_msl(SerialState *s)We'll be lazy and poll only every 10ms, and only poll it at all if MSI interrupts are turned on */ if (s->poll_msl) -qemu_mod_timer (s->modem_status_poll,qemu_get_clock_ns (vm_clock) +get_ticks_per_sec () /100 ); +timer_mod (s->modem_status_poll,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () /100 ); }static gboolean serial_xmit (GIOChannel *chan,GIOCondition cond,void *opaque)
@@ -252,7 +252,7 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) s->tsr_retry =0 ; } - s->last_xmit_ts =qemu_get_clock_ns (vm_clock); + s->last_xmit_ts =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (s->lsr &UART_LSR_THRE ) { s->lsr |=UART_LSR_TEMT ;
@@ -306,7 +306,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val, s->poll_msl =1 ;serial_update_msl (s); }else { -qemu_del_timer (s->modem_status_poll); +timer_del (s->modem_status_poll); s->poll_msl =0 ; } }
@@ -329,7 +329,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,/* FIFO clear */ if (val &UART_FCR_RFR ) { -qemu_del_timer (s->fifo_timeout_timer); +timer_del (s->fifo_timeout_timer); s->timeout_ipending=0 ;fifo8_reset (&s->recv_fifo); }
@@ -397,7 +397,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_SET_TIOCM , &flags);/* Update the modem status after a one-character-send wait-time, since there may be a response from the device/computer at the other end of the serial line */ -qemu_mod_timer (s->modem_status_poll,qemu_get_clock_ns (vm_clock) + s->char_transmit_time); +timer_mod (s->modem_status_poll,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->char_transmit_time); } }break ;
@@ -429,7 +429,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr addr, unsigned size)if (s->recv_fifo.num ==0 ) { s->lsr &= ~(UART_LSR_DR |UART_LSR_BI ); }else { -qemu_mod_timer (s->fifo_timeout_timer,qemu_get_clock_ns (vm_clock) + s->char_transmit_time *4 ); +timer_mod (s->fifo_timeout_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->char_transmit_time *4 ); } s->timeout_ipending =0 ; }else {
@@ -556,7 +556,7 @@ static void serial_receive1(void *opaque, const uint8_t *buf, int size) } s->lsr |=UART_LSR_DR ;/* call the timeout receive callback in 4 char transmit time */ -qemu_mod_timer (s->fifo_timeout_timer,qemu_get_clock_ns (vm_clock) + s->char_transmit_time *4 ); +timer_mod (s->fifo_timeout_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->char_transmit_time *4 ); }else {if (s->lsr &UART_LSR_DR ) s->lsr |=UART_LSR_OE ;
@@ -635,7 +635,7 @@ static void serial_reset(void *opaque)fifo8_reset (&s->recv_fifo);fifo8_reset (&s->xmit_fifo); - s->last_xmit_ts =qemu_get_clock_ns (vm_clock); + s->last_xmit_ts =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); s->thr_ipending =0 ; s->last_break_enable =0 ;
@@ -649,9 +649,9 @@ void serial_realize_core(SerialState *s, Error **errp)return ; } - s->modem_status_poll =qemu_new_timer_ns (vm_clock, (QEMUTimerCB *) serial_update_msl, s); + s->modem_status_poll =timer_new_ns (QEMU_CLOCK_VIRTUAL , (QEMUTimerCB *) serial_update_msl, s); - s->fifo_timeout_timer =qemu_new_timer_ns (vm_clock, (QEMUTimerCB *) fifo_timeout_int, s); + s->fifo_timeout_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , (QEMUTimerCB *) fifo_timeout_int, s);qemu_register_reset (serial_reset, s); qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
hw/char/virtio-serial-bus.c +5 -5
@@ -603,7 +603,7 @@ static void virtio_serial_post_load_timer_cb(void *opaque) } }g_free (s->post_load->connected); -qemu_free_timer (s->post_load->timer); +timer_free (s->post_load->timer);g_free (s->post_load); s->post_load =NULL ; }
@@ -618,7 +618,7 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, s->post_load->connected =g_malloc0 (sizeof (*s->post_load->connected) * nr_active_ports); - s->post_load->timer =qemu_new_timer_ns (vm_clock, + s->post_load->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , virtio_serial_post_load_timer_cb, s);
@@ -660,7 +660,7 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id, } } } -qemu_mod_timer (s->post_load->timer,1 ); +timer_mod (s->post_load->timer,1 );return 0 ; }
@@ -999,8 +999,8 @@ static int virtio_serial_device_exit(DeviceState *dev)g_free (vser->ports_map);if (vser->post_load) {g_free (vser->post_load->connected); -qemu_del_timer (vser->post_load->timer); -qemu_free_timer (vser->post_load->timer); +timer_del (vser->post_load->timer); +timer_free (vser->post_load->timer);g_free (vser->post_load); }virtio_cleanup (vdev);
hw/core/ptimer.c +9 -9
@@ -48,7 +48,7 @@ static void ptimer_reload(ptimer_state *s)if (s->period_frac) { s->next_event += ((int64_t )s->period_frac * s->delta) >>32 ; } -qemu_mod_timer (s->timer, s->next_event); +timer_mod (s->timer, s->next_event); }static void ptimer_tick (void *opaque)
@@ -69,7 +69,7 @@ uint64_t ptimer_get_count(ptimer_state *s)uint64_t counter;if (s->enabled) { - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );/* Figure out the current counter value. */ if (now - s->next_event >0 || s->period ==0 ) {
@@ -123,7 +123,7 @@ void ptimer_set_count(ptimer_state *s, uint64_t count) { s->delta = count;if (s->enabled) { - s->next_event =qemu_get_clock_ns (vm_clock); + s->next_event =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ptimer_reload (s); } }
@@ -138,7 +138,7 @@ void ptimer_run(ptimer_state *s, int oneshot)return ; } s->enabled = oneshot ?2 :1 ; - s->next_event =qemu_get_clock_ns (vm_clock); + s->next_event =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ptimer_reload (s); }
@@ -150,7 +150,7 @@ void ptimer_stop(ptimer_state *s)return ; s->delta =ptimer_get_count (s); -qemu_del_timer (s->timer); +timer_del (s->timer); s->enabled =0 ; }
@@ -160,7 +160,7 @@ void ptimer_set_period(ptimer_state *s, int64_t period) s->period = period; s->period_frac =0 ;if (s->enabled) { - s->next_event =qemu_get_clock_ns (vm_clock); + s->next_event =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ptimer_reload (s); } }
@@ -171,7 +171,7 @@ void ptimer_set_freq(ptimer_state *s, uint32_t freq) s->period =1000000000ll / freq; s->period_frac = (1000000000ll <<32 ) / freq;if (s->enabled) { - s->next_event =qemu_get_clock_ns (vm_clock); + s->next_event =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ptimer_reload (s); } }
@@ -197,7 +197,7 @@ void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload)if (reload) s->delta = limit;if (s->enabled && reload) { - s->next_event =qemu_get_clock_ns (vm_clock); + s->next_event =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ptimer_reload (s); } }
@@ -226,6 +226,6 @@ ptimer_state *ptimer_init(QEMUBH *bh) s = (ptimer_state *)g_malloc0 (sizeof (ptimer_state)); s->bh = bh; - s->timer =qemu_new_timer_ns (vm_clock, ptimer_tick, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , ptimer_tick, s);return s; }
hw/display/qxl-logger.c +1 -1
@@ -242,7 +242,7 @@ int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext)if (!qxl->cmdlog) {return 0 ; } -fprintf (stderr,"%" PRId64" qxl-%d/%s:" ,qemu_get_clock_ns (vm_clock), +fprintf (stderr,"%" PRId64" qxl-%d/%s:" ,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), qxl->id, ring); fprintf(stderr, " cmd @ 0x%" PRIx64 " %s%s", ext->cmd.data, qxl_name(qxl_type, ext->cmd.type),
hw/display/qxl.c +1 -1
@@ -1596,7 +1596,7 @@ async_common:trace_qxl_io_log (d->id, d->ram->log_buf);if (d->guestdebug) {fprintf (stderr,"qxl/guest-%d: %" PRId64": %s" , d->id, -qemu_get_clock_ns (vm_clock), d->ram->log_buf); +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), d->ram->log_buf); }break ;case QXL_IO_RESET :
hw/display/vga.c +3 -3
@@ -318,7 +318,7 @@ static uint8_t vga_precise_retrace(VGACommonState *s)int cur_line, cur_line_char, cur_char;int64_t cur_tick; - cur_tick =qemu_get_clock_ns (vm_clock); + cur_tick =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); cur_char = (cur_tick / r->ticks_per_char) % r->total_chars; cur_line = cur_char / r->htotal;
@@ -1304,7 +1304,7 @@ static void vga_draw_text(VGACommonState *s, int full_update)uint32_t *ch_attr_ptr;vga_draw_glyph8_func *vga_draw_glyph8;vga_draw_glyph9_func *vga_draw_glyph9; -int64_t now =qemu_get_clock_ms (vm_clock); +int64_t now =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL );/* compute font data address (in plane 2) */ v = s->sr[VGA_SEQ_CHARACTER_MAP ];
@@ -1907,7 +1907,7 @@ static void vga_update_display(void *opaque) }if (graphic_mode != s->graphic_mode) { s->graphic_mode = graphic_mode; - s->cursor_blink_time =qemu_get_clock_ms (vm_clock); + s->cursor_blink_time =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ); full_update =1 ; }switch (graphic_mode) {
hw/dma/pl330.c +3 -3
@@ -1256,7 +1256,7 @@ static void pl330_dma_stop_irq(void *opaque, int irq, int level)if (s->periph_busy[irq] != level) { s->periph_busy[irq] = level; -qemu_mod_timer (s->timer,qemu_get_clock_ns (vm_clock)); +timer_mod (s->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); } }
@@ -1519,7 +1519,7 @@ static void pl330_reset(DeviceState *d) s->periph_busy[i] =0 ; } -qemu_del_timer (s->timer); +timer_del (s->timer); }static void pl330_realize (DeviceState *dev,Error **errp)
@@ -1532,7 +1532,7 @@ static void pl330_realize(DeviceState *dev, Error **errp) "dma", PL330_IOMEM_SIZE);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); - s->timer =qemu_new_timer_ns (vm_clock, pl330_exec_cycle_timer, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pl330_exec_cycle_timer, s); s->cfg[0 ] = (s->mgr_ns_at_rst ?0x4 :0 ) | (s->num_periph_req > 0 ? 1 : 0) |
hw/dma/rc4030.c +2 -2
@@ -107,7 +107,7 @@ static void set_next_tick(rc4030State *s) tm_hz =1000 / (s->itr +1 ); -qemu_mod_timer (s->periodic_timer,qemu_get_clock_ns (vm_clock) + +timer_mod (s->periodic_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () / tm_hz); }
@@ -806,7 +806,7 @@ void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus, *irqs =qemu_allocate_irqs (rc4030_irq_jazz_request, s,16 ); *dmas =rc4030_allocate_dmas (s,4 ); - s->periodic_timer =qemu_new_timer_ns (vm_clock, rc4030_periodic_timer, s); + s->periodic_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , rc4030_periodic_timer, s); s->timer_irq = timer; s->jazz_bus_irq = jazz_bus;
hw/dma/soc_dma.c +4 -4
@@ -84,10 +84,10 @@ struct dma_s {static void soc_dma_ch_schedule (struct soc_dma_ch_s *ch,int delay_bytes) { -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );struct dma_s *dma = (struct dma_s *) ch->dma; -qemu_mod_timer (ch->timer, now + delay_bytes / dma->channel_freq); +timer_mod (ch->timer, now + delay_bytes / dma->channel_freq); }static void soc_dma_ch_run (void *opaque)
@@ -217,7 +217,7 @@ void soc_dma_set_request(struct soc_dma_ch_s *ch, int level) ch->enable = level;if (!ch->enable) -qemu_del_timer (ch->timer); +timer_del (ch->timer);else if (!ch->running)soc_dma_ch_run (ch);else
@@ -246,7 +246,7 @@ struct soc_dma_s *soc_dma_init(int n)for (i =0 ; i < n; i ++) { s->ch[i].dma = &s->soc; s->ch[i].num = i; - s->ch[i].timer =qemu_new_timer_ns (vm_clock, soc_dma_ch_run, &s->ch[i]); + s->ch[i].timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , soc_dma_ch_run, &s->ch[i]); }soc_dma_reset (&s->soc);
hw/i386/kvm/apic.c +1 -1
@@ -79,7 +79,7 @@ void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic) v = (s->divide_conf &3 ) | ((s->divide_conf >>1 ) &4 ); s->count_shift = (v +1 ) &7 ; - s->initial_count_load_time =qemu_get_clock_ns (vm_clock); + s->initial_count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );apic_next_timer (s, s->initial_count_load_time); }
hw/i386/kvm/i8254.c +3 -3
@@ -65,12 +65,12 @@ static void kvm_pit_update_clock_offset(KVMPITState *s)/* * Measure the delta between CLOCK_MONOTONIC, the base used for -* kvm_pit_channel_state::count_load_time, and vm_clock. Take the +* kvm_pit_channel_state::count_load_time, and QEMU_CLOCK_VIRTUAL. Take the * minimum of several samples to filter out scheduling noise. */ clock_offset =INT64_MAX ;for (i =0 ; i <CALIBRATION_ROUNDS ; i++) { - offset =qemu_get_clock_ns (vm_clock); + offset =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );clock_gettime (CLOCK_MONOTONIC , &ts); offset -= ts.tv_nsec; offset -= (int64_t )ts.tv_sec *1000000000 ;
@@ -194,7 +194,7 @@ static void kvm_pit_set_gate(PITCommonState *s, PITChannelState *sc, int val)case 5 :if (sc->gate < val) {/* restart counting on rising edge */ - sc->count_load_time =qemu_get_clock_ns (vm_clock); + sc->count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }break ; }
hw/i386/xen_domainbuild.c +3 -3
@@ -148,7 +148,7 @@ static void xen_domain_poll(void *opaque) goto quit; } -qemu_mod_timer (xen_poll,qemu_get_clock_ms (rt_clock) +1000 ); +timer_mod (xen_poll,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +1000 );return ; quit:
@@ -290,8 +290,8 @@ int xen_domain_build_pv(const char *kernel, const char *ramdisk, goto err; } - xen_poll =qemu_new_timer_ms (rt_clock, xen_domain_poll,NULL ); -qemu_mod_timer (xen_poll,qemu_get_clock_ms (rt_clock) +1000 ); + xen_poll =timer_new_ms (QEMU_CLOCK_REALTIME , xen_domain_poll,NULL ); +timer_mod (xen_poll,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +1000 );return 0 ; err:
hw/ide/core.c +3 -3
@@ -768,8 +768,8 @@ static void ide_sector_write_cb(void *opaque, int ret)that at the expense of slower write performances. Use this option _only_ to install Windows 2000. You must disable it for normal use. */ -qemu_mod_timer (s->sector_write_timer, -qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () /1000 )); +timer_mod (s->sector_write_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () /1000 )); }else {ide_set_irq (s->bus); }
@@ -2163,7 +2163,7 @@ static void ide_init1(IDEBus *bus, int unit) s->smart_selftest_data =qemu_blockalign (s->bs,512 );memset (s->smart_selftest_data,0 ,512 ); - s->sector_write_timer =qemu_new_timer_ns (vm_clock, + s->sector_write_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , ide_sector_write_timer_cb, s); }
hw/input/hid.c +5 -5
@@ -85,8 +85,8 @@ static void hid_idle_timer(void *opaque)static void hid_del_idle_timer (HIDState *hs) {if (hs->idle_timer) { -qemu_del_timer (hs->idle_timer); -qemu_free_timer (hs->idle_timer); +timer_del (hs->idle_timer); +timer_free (hs->idle_timer); hs->idle_timer =NULL ; } }
@@ -94,12 +94,12 @@ static void hid_del_idle_timer(HIDState *hs)void hid_set_next_idle (HIDState *hs) {if (hs->idle) { -uint64_t expire_time =qemu_get_clock_ns (vm_clock) + +uint64_t expire_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +get_ticks_per_sec () * hs->idle *4 /1000 ;if (!hs->idle_timer) { - hs->idle_timer =qemu_new_timer_ns (vm_clock, hid_idle_timer, hs); + hs->idle_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , hid_idle_timer, hs); } -qemu_mod_timer_ns (hs->idle_timer, expire_time); +timer_mod_ns (hs->idle_timer, expire_time); }else {hid_del_idle_timer (hs); }
hw/input/lm832x.c +4 -4
@@ -365,7 +365,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)break ; } -qemu_del_timer (s->pwm.tm[(value &3 ) -1 ]); +timer_del (s->pwm.tm[(value &3 ) -1 ]);break ;case LM832x_GENERAL_ERROR:
@@ -463,9 +463,9 @@ static int lm8323_init(I2CSlave *i2c)LM823KbdState *s =FROM_I2C_SLAVE (LM823KbdState, i2c); s->model =0x8323 ; - s->pwm.tm[0 ] =qemu_new_timer_ns (vm_clock, lm_kbd_pwm0_tick, s); - s->pwm.tm[1 ] =qemu_new_timer_ns (vm_clock, lm_kbd_pwm1_tick, s); - s->pwm.tm[2 ] =qemu_new_timer_ns (vm_clock, lm_kbd_pwm2_tick, s); + s->pwm.tm[0 ] =timer_new_ns (QEMU_CLOCK_VIRTUAL , lm_kbd_pwm0_tick, s); + s->pwm.tm[1 ] =timer_new_ns (QEMU_CLOCK_VIRTUAL , lm_kbd_pwm1_tick, s); + s->pwm.tm[2 ] =timer_new_ns (QEMU_CLOCK_VIRTUAL , lm_kbd_pwm2_tick, s);qdev_init_gpio_out (&i2c->qdev, &s->nirq,1 );lm_kbd_reset (s);
hw/input/tsc2005.c +5 -5
@@ -201,7 +201,7 @@ static void tsc2005_write(TSC2005State *s, int reg, uint16_t data)fprintf (stderr,"%s: touchscreen sense %sabled\n" , __FUNCTION__, s->enabled ?"en" :"dis" );if (s->busy && !s->enabled) -qemu_del_timer (s->timer); +timer_del (s->timer); s->busy &= s->enabled; } s->nextprecision = (data >>13 ) &1 ;
@@ -290,8 +290,8 @@ static void tsc2005_pin_update(TSC2005State *s) s->precision = s->nextprecision; s->function = s->nextfunction; s->pdst = !s->pnd0;/* Synchronised on internal clock */ - expires =qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () >>7 ); -qemu_mod_timer (s->timer, expires); + expires =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () >>7 ); +timer_mod (s->timer, expires); }static void tsc2005_reset (TSC2005State *s)
@@ -337,7 +337,7 @@ static uint8_t tsc2005_txrx_word(void *opaque, uint8_t value)fprintf (stderr,"%s: touchscreen sense %sabled\n" , __FUNCTION__, s->enabled ?"en" :"dis" );if (s->busy && !s->enabled) -qemu_del_timer (s->timer); +timer_del (s->timer); s->busy &= s->enabled; }tsc2005_pin_update (s);
@@ -529,7 +529,7 @@ void *tsc2005_init(qemu_irq pintdav) s->y =240 ; s->pressure =0 ; s->precision = s->nextprecision =0 ; - s->timer =qemu_new_timer_ns (vm_clock, tsc2005_timer_tick, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , tsc2005_timer_tick, s); s->pint = pintdav; s->model =0x2005 ;
hw/input/tsc210x.c +13 -13
@@ -503,9 +503,9 @@ static uint16_t tsc2102_audio_register_read(TSC210xState *s, int reg) l_ch =1 ; r_ch =1 ;if (s->softstep && !(s->dac_power & (1 <<10 ))) { - l_ch = (qemu_get_clock_ns (vm_clock) > + l_ch = (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) > s->volume_change +TSC_SOFTSTEP_DELAY ); - r_ch = (qemu_get_clock_ns (vm_clock) > + r_ch = (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) > s->volume_change +TSC_SOFTSTEP_DELAY ); }
@@ -514,7 +514,7 @@ static uint16_t tsc2102_audio_register_read(TSC210xState *s, int reg)case 0x05 :/* Stereo DAC Power Control */ return 0x2aa0 | s->dac_power | (((s->dac_power & (1 <<10 )) && - (qemu_get_clock_ns (vm_clock) > + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) > s->powerdown +TSC_POWEROFF_DELAY )) <<6 );case 0x06 :/* Audio Control 3 */
@@ -594,7 +594,7 @@ static void tsc2102_control_register_write( s->host_mode = value >>15 ; s->enabled = !(value &0x4000 );if (s->busy && !s->enabled) -qemu_del_timer (s->timer); +timer_del (s->timer); s->busy &= s->enabled; s->nextfunction = (value >>10 ) &0xf ; s->nextprecision = (value >>8 ) &3 ;
@@ -629,7 +629,7 @@ static void tsc2102_control_register_write(case 0x04 :/* Reset */ if (value ==0xbb00 ) {if (s->busy) -qemu_del_timer (s->timer); +timer_del (s->timer);tsc210x_reset (s); #ifdef TSC_VERBOSE }else {
@@ -695,7 +695,7 @@ static void tsc2102_audio_register_write(case 0x02 :/* DAC Volume Control */ s->volume = value; - s->volume_change =qemu_get_clock_ns (vm_clock); + s->volume_change =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );return ;case 0x03 :
@@ -717,7 +717,7 @@ static void tsc2102_audio_register_write(case 0x05 :/* Stereo DAC Power Control */ if ((value & ~s->dac_power) & (1 <<10 )) - s->powerdown =qemu_get_clock_ns (vm_clock); + s->powerdown =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); s->dac_power = value &0x9543 ;#ifdef TSC_VERBOSE
@@ -864,8 +864,8 @@ static void tsc210x_pin_update(TSC210xState *s) s->busy =1 ; s->precision = s->nextprecision; s->function = s->nextfunction; - expires =qemu_get_clock_ns (vm_clock) + (get_ticks_per_sec () >>10 ); -qemu_mod_timer (s->timer, expires); + expires =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () >>10 ); +timer_mod (s->timer, expires); }static uint16_t tsc210x_read (TSC210xState *s)
@@ -1005,7 +1005,7 @@ static void tsc210x_i2s_set_rate(TSC210xState *s, int in, int out)static void tsc210x_save (QEMUFile *f,void *opaque) {TSC210xState *s = (TSC210xState *) opaque; -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int i;qemu_put_be16 (f, s->x);
@@ -1051,7 +1051,7 @@ static void tsc210x_save(QEMUFile *f, void *opaque)static int tsc210x_load (QEMUFile *f,void *opaque,int version_id) {TSC210xState *s = (TSC210xState *) opaque; -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int i; s->x =qemu_get_be16 (f);
@@ -1111,7 +1111,7 @@ uWireSlave *tsc2102_init(qemu_irq pint) s->y =160 ; s->pressure =0 ; s->precision = s->nextprecision =0 ; - s->timer =qemu_new_timer_ns (vm_clock, tsc210x_timer_tick, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , tsc210x_timer_tick, s); s->pint = pint; s->model =0x2102 ; s->name ="tsc2102" ;
@@ -1160,7 +1160,7 @@ uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav) s->y =240 ; s->pressure =0 ; s->precision = s->nextprecision =0 ; - s->timer =qemu_new_timer_ns (vm_clock, tsc210x_timer_tick, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , tsc210x_timer_tick, s); s->pint = penirq; s->kbint = kbirq; s->davint = dav;
hw/intc/apic.c +8 -8
@@ -606,7 +606,7 @@ static uint32_t apic_get_current_count(APICCommonState *s) {int64_t d;uint32_t val; - d = (qemu_get_clock_ns (vm_clock) - s->initial_count_load_time) >> + d = (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - s->initial_count_load_time) >> s->count_shift;if (s->lvt[APIC_LVT_TIMER ] &APIC_LVT_TIMER_PERIODIC ) {/* periodic */
@@ -623,9 +623,9 @@ static uint32_t apic_get_current_count(APICCommonState *s)static void apic_timer_update (APICCommonState *s,int64_t current_time) {if (apic_next_timer (s, current_time)) { -qemu_mod_timer (s->timer, s->next_time); +timer_mod (s->timer, s->next_time); }else { -qemu_del_timer (s->timer); +timer_del (s->timer); } }
@@ -822,7 +822,7 @@ static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)int n = index -0x32 ; s->lvt[n] = val;if (n ==APIC_LVT_TIMER ) { -apic_timer_update (s,qemu_get_clock_ns (vm_clock)); +apic_timer_update (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); }else if (n ==APIC_LVT_LINT0 &&apic_check_pic (s)) {apic_update_irq (s); }
@@ -830,7 +830,7 @@ static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)break ;case 0x38 : s->initial_count = val; - s->initial_count_load_time =qemu_get_clock_ns (vm_clock); + s->initial_count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );apic_timer_update (s, s->initial_count_load_time);break ;case 0x39 :
@@ -857,9 +857,9 @@ static void apic_pre_save(APICCommonState *s)static void apic_post_load (APICCommonState *s) {if (s->timer_expiry !=-1 ) { -qemu_mod_timer (s->timer, s->timer_expiry); +timer_mod (s->timer, s->timer_expiry); }else { -qemu_del_timer (s->timer); +timer_del (s->timer); } }
@@ -876,7 +876,7 @@ static void apic_init(APICCommonState *s)memory_region_init_io (&s->io_memory,OBJECT (s), &apic_io_ops, s,"apic-msi" ,APIC_SPACE_SIZE ); - s->timer =qemu_new_timer_ns (vm_clock, apic_timer, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , apic_timer, s); local_apics[s->idx] = s; msi_supported = true;
hw/intc/apic_common.c +1 -1
@@ -198,7 +198,7 @@ void apic_init_reset(DeviceState *d) s->wait_for_sipi =1 ;if (s->timer) { -qemu_del_timer (s->timer); +timer_del (s->timer); } s->timer_expiry =-1 ; }
hw/intc/armv7m_nvic.c +8 -8
@@ -78,9 +78,9 @@ static inline int64_t systick_scale(nvic_state *s)static void systick_reload (nvic_state *s,int reset) {if (reset) - s->systick.tick =qemu_get_clock_ns (vm_clock); + s->systick.tick =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); s->systick.tick += (s->systick.reload +1 ) *systick_scale (s); -qemu_mod_timer (s->systick.timer, s->systick.tick); +timer_mod (s->systick.timer, s->systick.tick); }static void systick_timer_tick (void * opaque)
@@ -103,7 +103,7 @@ static void systick_reset(nvic_state *s) s->systick.control =0 ; s->systick.reload =0 ; s->systick.tick =0 ; -qemu_del_timer (s->systick.timer); +timer_del (s->systick.timer); }/* The external routines use the hardware vector numbering, ie. the first
@@ -158,7 +158,7 @@ static uint32_t nvic_readl(nvic_state *s, uint32_t offset)int64_t t;if ((s->systick.control &SYSTICK_ENABLE ) ==0 )return 0 ; - t =qemu_get_clock_ns (vm_clock); + t =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (t >= s->systick.tick)return 0 ; val = ((s->systick.tick - (t +1 )) /systick_scale (s)) +1 ;
@@ -290,16 +290,16 @@ static void nvic_writel(nvic_state *s, uint32_t offset, uint32_t value) s->systick.control &=0xfffffff8 ; s->systick.control |= value &7 ;if ((oldval ^ value) &SYSTICK_ENABLE ) { -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (value &SYSTICK_ENABLE ) {if (s->systick.tick) { s->systick.tick += now; -qemu_mod_timer (s->systick.timer, s->systick.tick); +timer_mod (s->systick.timer, s->systick.tick); }else {systick_reload (s,1 ); } }else { -qemu_del_timer (s->systick.timer); +timer_del (s->systick.timer); s->systick.tick -= now;if (s->systick.tick <0 ) s->systick.tick =0 ;
@@ -511,7 +511,7 @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)* by the v7M architecture. */ memory_region_add_subregion (get_system_memory (),0xe000e000 , &s->container); - s->systick.timer =qemu_new_timer_ns (vm_clock, systick_timer_tick, s); + s->systick.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , systick_timer_tick, s); }static void armv7m_nvic_instance_init (Object *obj)
hw/intc/i8259.c +2 -2
@@ -150,7 +150,7 @@ static void pic_set_irq(void *opaque, int irq, int level)#endif #ifdef DEBUG_IRQ_LATENCY if (level) { - irq_time[irq_index] =qemu_get_clock_ns (vm_clock); + irq_time[irq_index] =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }#endif
@@ -228,7 +228,7 @@ int pic_read_irq(DeviceState *d)#ifdef DEBUG_IRQ_LATENCY printf ("IRQ%d latency=%0.3fus\n" , irq, - (double )(qemu_get_clock_ns (vm_clock) - + (double )(qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - irq_time[irq]) *1000000.0 /get_ticks_per_sec ());#endif DPRINTF ("pic_interrupt: irq=%d\n" , irq);
hw/mips/cputimer.c +6 -6
@@ -47,11 +47,11 @@ static void cpu_mips_timer_update(CPUMIPSState *env)uint64_t now, next;uint32_t wait; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); wait = env->CP0_Compare - env->CP0_Count - (uint32_t )muldiv64 (now,TIMER_FREQ ,get_ticks_per_sec ()); next = now +muldiv64 (wait,get_ticks_per_sec (),TIMER_FREQ ); -qemu_mod_timer (env->timer, next); +timer_mod (env->timer, next); }/* Expire the timer. */
@@ -71,7 +71,7 @@ uint32_t cpu_mips_get_count (CPUMIPSState *env) }else {uint64_t now; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (timer_pending (env->timer) &&timer_expired (env->timer, now)) {/* The timer has already expired. */
@@ -90,7 +90,7 @@ void cpu_mips_store_count (CPUMIPSState *env, uint32_t count)else {/* Store new count register */ env->CP0_Count = - count - (uint32_t )muldiv64 (qemu_get_clock_ns (vm_clock), + count - (uint32_t )muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ),TIMER_FREQ ,get_ticks_per_sec ());/* Update timer timer */ cpu_mips_timer_update (env);
@@ -115,7 +115,7 @@ void cpu_mips_start_count(CPUMIPSState *env)void cpu_mips_stop_count (CPUMIPSState *env) {/* Store the current value */ - env->CP0_Count += (uint32_t )muldiv64 (qemu_get_clock_ns (vm_clock), + env->CP0_Count += (uint32_t )muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ),TIMER_FREQ ,get_ticks_per_sec ()); }
@@ -141,7 +141,7 @@ static void mips_timer_cb (void *opaque)void cpu_mips_clock_init (CPUMIPSState *env) { - env->timer =qemu_new_timer_ns (vm_clock, &mips_timer_cb, env); + env->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &mips_timer_cb, env); env->CP0_Compare =0 ;cpu_mips_store_count (env,1 ); }
hw/misc/arm_sysctl.c +1 -1
@@ -170,7 +170,7 @@ static uint64_t arm_sysctl_read(void *opaque, hwaddr offset,case 0x58 :/* BOOTCS */ return 0 ;case 0x5c :/* 24MHz */ -return muldiv64 (qemu_get_clock_ns (vm_clock),24000000 ,get_ticks_per_sec ()); +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ),24000000 ,get_ticks_per_sec ());case 0x60 :/* MISC */ return 0 ;case 0x84 :/* PROCID0 */
hw/misc/macio/cuda.c +17 -17
@@ -128,7 +128,7 @@ static unsigned int get_counter(CUDATimer *s)int64_t d;unsigned int counter; - d =muldiv64 (qemu_get_clock_ns (vm_clock) - s->load_time, + d =muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - s->load_time,CUDA_TIMER_FREQ ,get_ticks_per_sec ());if (s->index ==0 ) {/* the timer goes down from latch to -1 (period of latch + 2) */
@@ -147,7 +147,7 @@ static unsigned int get_counter(CUDATimer *s)static void set_counter (CUDAState *s,CUDATimer *ti,unsigned int val) {CUDA_DPRINTF ("T%d.counter=%d\n" ,1 + (ti->timer ==NULL ), val); - ti->load_time =qemu_get_clock_ns (vm_clock); + ti->load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ti->counter_value = val;cuda_timer_update (s, ti, ti->load_time); }
@@ -191,10 +191,10 @@ static void cuda_timer_update(CUDAState *s, CUDATimer *ti,if (!ti->timer)return ;if ((s->acr &T1MODE ) !=T1MODE_CONT ) { -qemu_del_timer (ti->timer); +timer_del (ti->timer); }else { ti->next_irq_time =get_next_irq_time (ti, current_time); -qemu_mod_timer (ti->timer, ti->next_irq_time); +timer_mod (ti->timer, ti->next_irq_time); } }
@@ -304,7 +304,7 @@ static void cuda_writeb(void *opaque, hwaddr addr, uint32_t val)break ;case 4 : s->timers[0 ].latch = (s->timers[0 ].latch &0xff00 ) | val; -cuda_timer_update (s, &s->timers[0 ],qemu_get_clock_ns (vm_clock)); +cuda_timer_update (s, &s->timers[0 ],qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));break ;case 5 : s->timers[0 ].latch = (s->timers[0 ].latch &0xff ) | (val <<8 );
@@ -313,12 +313,12 @@ static void cuda_writeb(void *opaque, hwaddr addr, uint32_t val)break ;case 6 : s->timers[0 ].latch = (s->timers[0 ].latch &0xff00 ) | val; -cuda_timer_update (s, &s->timers[0 ],qemu_get_clock_ns (vm_clock)); +cuda_timer_update (s, &s->timers[0 ],qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));break ;case 7 : s->timers[0 ].latch = (s->timers[0 ].latch &0xff ) | (val <<8 ); s->ifr &= ~T1_INT ; -cuda_timer_update (s, &s->timers[0 ],qemu_get_clock_ns (vm_clock)); +cuda_timer_update (s, &s->timers[0 ],qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));break ;case 8 : s->timers[1 ].latch = val;
@@ -332,7 +332,7 @@ static void cuda_writeb(void *opaque, hwaddr addr, uint32_t val)break ;case 11 : s->acr = val; -cuda_timer_update (s, &s->timers[0 ],qemu_get_clock_ns (vm_clock)); +cuda_timer_update (s, &s->timers[0 ],qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));cuda_update (s);break ;case 12 :
@@ -463,8 +463,8 @@ static void cuda_adb_poll(void *opaque) obuf[1 ] =0x40 ;/* polled data */ cuda_send_packet_to_host (s, obuf, olen +2 ); } -qemu_mod_timer (s->adb_poll_timer, -qemu_get_clock_ns (vm_clock) + +timer_mod (s->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); }
@@ -481,11 +481,11 @@ static void cuda_receive_packet(CUDAState *s,if (autopoll != s->autopoll) { s->autopoll = autopoll;if (autopoll) { -qemu_mod_timer (s->adb_poll_timer, -qemu_get_clock_ns (vm_clock) + +timer_mod (s->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); }else { -qemu_del_timer (s->adb_poll_timer); +timer_del (s->adb_poll_timer); } } obuf[0 ] =CUDA_PACKET ;
@@ -494,14 +494,14 @@ static void cuda_receive_packet(CUDAState *s,break ;case CUDA_SET_TIME : ti = (((uint32_t )data[1 ]) <<24 ) + (((uint32_t )data[2 ]) <<16 ) + (((uint32_t )data[3 ]) <<8 ) + data[4 ]; - s->tick_offset = ti - (qemu_get_clock_ns (vm_clock) /get_ticks_per_sec ()); + s->tick_offset = ti - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ()); obuf[0 ] =CUDA_PACKET ; obuf[1 ] =0 ; obuf[2 ] =0 ;cuda_send_packet_to_host (s, obuf,3 );break ;case CUDA_GET_TIME : - ti = s->tick_offset + (qemu_get_clock_ns (vm_clock) /get_ticks_per_sec ()); + ti = s->tick_offset + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ()); obuf[0 ] =CUDA_PACKET ; obuf[1 ] =0 ; obuf[2 ] =0 ;
@@ -689,12 +689,12 @@ static void cuda_realizefn(DeviceState *dev, Error **errp)CUDAState *s =CUDA (dev);struct tm tm; - s->timers[0 ].timer =qemu_new_timer_ns (vm_clock, cuda_timer1, s); + s->timers[0 ].timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cuda_timer1, s);qemu_get_timedate (&tm,0 ); s->tick_offset = (uint32_t )mktimegm (&tm) +RTC_OFFSET ; - s->adb_poll_timer =qemu_new_timer_ns (vm_clock, cuda_adb_poll, s); + s->adb_poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cuda_adb_poll, s); }static void cuda_initfn (Object *obj)
hw/misc/macio/macio.c +2 -2
@@ -245,10 +245,10 @@ static uint64_t timer_read(void *opaque, hwaddr addr, unsigned size)switch (addr) {case 0x38 : - value =qemu_get_clock_ns (vm_clock); + value =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );break ;case 0x3c : - value =qemu_get_clock_ns (vm_clock) >>32 ; + value =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) >>32 ;break ; }
hw/misc/vfio.c +7 -7
@@ -276,8 +276,8 @@ static void vfio_intx_mmap_enable(void *opaque)VFIODevice *vdev = opaque;if (vdev->intx.pending) { -qemu_mod_timer (vdev->intx.mmap_timer, -qemu_get_clock_ms (vm_clock) + vdev->intx.mmap_timeout); +timer_mod (vdev->intx.mmap_timer, +qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + vdev->intx.mmap_timeout);return ; }
@@ -300,8 +300,8 @@ static void vfio_intx_interrupt(void *opaque)qemu_set_irq (vdev->pdev.irq[vdev->intx.pin],1 );vfio_mmap_set_enabled (vdev, false);if (vdev->intx.mmap_timeout) { -qemu_mod_timer (vdev->intx.mmap_timer, -qemu_get_clock_ms (vm_clock) + vdev->intx.mmap_timeout); +timer_mod (vdev->intx.mmap_timer, +qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + vdev->intx.mmap_timeout); } }
@@ -543,7 +543,7 @@ static void vfio_disable_intx(VFIODevice *vdev) {int fd; -qemu_del_timer (vdev->intx.mmap_timer); +timer_del (vdev->intx.mmap_timer);vfio_disable_intx_kvm (vdev);vfio_disable_irqindex (vdev,VFIO_PCI_INTX_IRQ_INDEX ); vdev->intx.pending = false;
@@ -3176,7 +3176,7 @@ static int vfio_initfn(PCIDevice *pdev) }if (vfio_pci_read_config (&vdev->pdev,PCI_INTERRUPT_PIN ,1 )) { - vdev->intx.mmap_timer =qemu_new_timer_ms (vm_clock, + vdev->intx.mmap_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL , vfio_intx_mmap_enable, vdev);pci_device_set_intx_routing_notifier (&vdev->pdev, vfio_update_irq); ret =vfio_enable_intx (vdev);
@@ -3210,7 +3210,7 @@ static void vfio_exitfn(PCIDevice *pdev)pci_device_set_intx_routing_notifier (&vdev->pdev,NULL );vfio_disable_interrupts (vdev);if (vdev->intx.mmap_timer) { -qemu_free_timer (vdev->intx.mmap_timer); +timer_free (vdev->intx.mmap_timer); }vfio_teardown_msi (vdev);vfio_unmap_bars (vdev);
hw/net/dp8393x.c +10 -10
@@ -274,7 +274,7 @@ static void do_read_rra(dp8393xState *s)static void do_software_reset (dp8393xState *s) { -qemu_del_timer (s->watchdog); +timer_del (s->watchdog); s->regs[SONIC_CR ] &= ~(SONIC_CR_LCAM |SONIC_CR_RRRA |SONIC_CR_TXP |SONIC_CR_HTX ); s->regs[SONIC_CR ] |=SONIC_CR_RST |SONIC_CR_RXDIS ;
@@ -286,14 +286,14 @@ static void set_next_tick(dp8393xState *s)int64_t delay;if (s->regs[SONIC_CR ] &SONIC_CR_STP ) { -qemu_del_timer (s->watchdog); +timer_del (s->watchdog);return ; } ticks = s->regs[SONIC_WT1 ] <<16 | s->regs[SONIC_WT0 ]; - s->wt_last_update =qemu_get_clock_ns (vm_clock); + s->wt_last_update =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); delay =get_ticks_per_sec () * ticks /5000000 ; -qemu_mod_timer (s->watchdog, s->wt_last_update + delay); +timer_mod (s->watchdog, s->wt_last_update + delay); }static void update_wt_regs (dp8393xState *s)
@@ -302,11 +302,11 @@ static void update_wt_regs(dp8393xState *s)uint32_t val;if (s->regs[SONIC_CR ] &SONIC_CR_STP ) { -qemu_del_timer (s->watchdog); +timer_del (s->watchdog);return ; } - elapsed = s->wt_last_update -qemu_get_clock_ns (vm_clock); + elapsed = s->wt_last_update -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); val = s->regs[SONIC_WT1 ] <<16 | s->regs[SONIC_WT0 ]; val -= elapsed /5000000 ; s->regs[SONIC_WT1 ] = (val >>16 ) &0xffff ;
@@ -838,7 +838,7 @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size)static void nic_reset (void *opaque) {dp8393xState *s = opaque; -qemu_del_timer (s->watchdog); +timer_del (s->watchdog); s->regs[SONIC_CR ] =SONIC_CR_RST |SONIC_CR_STP |SONIC_CR_RXDIS ; s->regs[SONIC_DCR ] &= ~(SONIC_DCR_EXBUS |SONIC_DCR_LBR );
@@ -866,8 +866,8 @@ static void nic_cleanup(NetClientState *nc)memory_region_del_subregion (s->address_space, &s->mmio);memory_region_destroy (&s->mmio); -qemu_del_timer (s->watchdog); -qemu_free_timer (s->watchdog); +timer_del (s->watchdog); +timer_free (s->watchdog);g_free (s); }
@@ -896,7 +896,7 @@ void dp83932_init(NICInfo *nd, hwaddr base, int it_shift, s->memory_rw = memory_rw; s->it_shift = it_shift; s->irq = irq; - s->watchdog =qemu_new_timer_ns (vm_clock, dp8393x_watchdog, s); + s->watchdog =timer_new_ns (QEMU_CLOCK_VIRTUAL , dp8393x_watchdog, s); s->regs[SONIC_SR ] =0x0004 ;/* only revision recognized by Linux */ s->conf.macaddr = nd->macaddr;
hw/net/e1000.c +6 -6
@@ -190,7 +190,7 @@ set_phy_ctrl(E1000State *s, int index, uint16_t val)e1000_link_down (s); s->phy_reg[PHY_STATUS ] &= ~MII_SR_AUTONEG_COMPLETE ;DBGOUT (PHY ,"Start link auto negotiation\n" ); -qemu_mod_timer (s->autoneg_timer,qemu_get_clock_ms (vm_clock) +500 ); +timer_mod (s->autoneg_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +500 ); } }
@@ -306,7 +306,7 @@ static void e1000_reset(void *opaque)uint8_t *macaddr = d->conf.macaddr.a;int i; -qemu_del_timer (d->autoneg_timer); +timer_del (d->autoneg_timer);memset (d->phy_reg,0 ,sizeof d->phy_reg);memmove (d->phy_reg, phy_reg_init,sizeof phy_reg_init);memset (d->mac_reg,0 ,sizeof d->mac_reg);
@@ -1184,7 +1184,7 @@ static int e1000_post_load(void *opaque, int version_id) s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG && !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) { nc->link_down = false; -qemu_mod_timer (s->autoneg_timer,qemu_get_clock_ms (vm_clock) +500 ); +timer_mod (s->autoneg_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +500 ); }return 0 ;
@@ -1314,8 +1314,8 @@ pci_e1000_uninit(PCIDevice *dev) {E1000State *d =E1000 (dev); -qemu_del_timer (d->autoneg_timer); -qemu_free_timer (d->autoneg_timer); +timer_del (d->autoneg_timer); +timer_free (d->autoneg_timer);memory_region_destroy (&d->mmio);memory_region_destroy (&d->io);qemu_del_nic (d->nic);
@@ -1370,7 +1370,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)add_boot_device_path (d->conf.bootindex, dev,"/ethernet-phy@0" ); - d->autoneg_timer =qemu_new_timer_ms (vm_clock, e1000_autoneg_timer, d); + d->autoneg_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL , e1000_autoneg_timer, d);return 0 ; }
hw/net/lan9118.c +2 -2
@@ -439,7 +439,7 @@ static void lan9118_reset(DeviceState *d) s->afc_cfg =0 ; s->e2p_cmd =0 ; s->e2p_data =0 ; - s->free_timer_start =qemu_get_clock_ns (vm_clock) /40 ; + s->free_timer_start =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /40 ;ptimer_stop (s->timer);ptimer_set_count (s->timer,0xffff );
@@ -1236,7 +1236,7 @@ static uint64_t lan9118_readl(void *opaque, hwaddr offset,case CSR_WORD_SWAP :return s->word_swap;case CSR_FREE_RUN : -return (qemu_get_clock_ns (vm_clock) /40 ) - s->free_timer_start; +return (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /40 ) - s->free_timer_start;case CSR_RX_DROP :/* TODO: Implement dropped frames counter. */ return 0 ;
hw/net/pcnet-pci.c +2 -2
@@ -284,8 +284,8 @@ static void pci_pcnet_uninit(PCIDevice *dev)memory_region_destroy (&d->state.mmio);memory_region_destroy (&d->io_bar); -qemu_del_timer (d->state.poll_timer); -qemu_free_timer (d->state.poll_timer); +timer_del (d->state.poll_timer); +timer_free (d->state.poll_timer);qemu_del_nic (d->state.nic); }
hw/net/pcnet.c +5 -5
@@ -1331,7 +1331,7 @@ static void pcnet_poll_timer(void *opaque) {PCNetState *s = opaque; -qemu_del_timer (s->poll_timer); +timer_del (s->poll_timer);if (CSR_TDMD (s)) {pcnet_transmit (s);
@@ -1340,7 +1340,7 @@ static void pcnet_poll_timer(void *opaque)pcnet_update_irq (s);if (!CSR_STOP (s) && !CSR_SPND (s) && !CSR_DPOLL (s)) { -uint64_t now =qemu_get_clock_ns (vm_clock) *33 ; +uint64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) *33 ;if (!s->timer || !now) s->timer = now;else {
@@ -1351,8 +1351,8 @@ static void pcnet_poll_timer(void *opaque) }else CSR_POLL (s) = t; } -qemu_mod_timer (s->poll_timer, -pcnet_get_next_poll_time (s,qemu_get_clock_ns (vm_clock))); +timer_mod (s->poll_timer, +pcnet_get_next_poll_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ))); } }
@@ -1731,7 +1731,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)int i;uint16_t checksum; - s->poll_timer =qemu_new_timer_ns (vm_clock, pcnet_poll_timer, s); + s->poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pcnet_poll_timer, s);qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (info, &s->conf,object_get_typename (OBJECT (dev)), dev->id, s);
hw/net/rtl8139.c +14 -14
@@ -2648,7 +2648,7 @@ static void rtl8139_IntrMask_write(RTL8139State *s, uint32_t val) s->IntrMask = val; -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));rtl8139_update_irq (s); }
@@ -2689,7 +2689,7 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)* and probably emulated is slower is better to assume this resetting was * done before testing on previous rtl8139_update_irq lead to IRQ losing */ -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));rtl8139_update_irq (s);#endif
@@ -2697,7 +2697,7 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)static uint32_t rtl8139_IntrStatus_read (RTL8139State *s) { -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));uint32_t ret = s->IntrStatus;
@@ -2913,7 +2913,7 @@ static void rtl8139_set_next_tctr_time(RTL8139State *s, int64_t current_time) s->TimerExpire = next_time;if ((s->IntrMask & PCSTimeout) !=0 && (s->IntrStatus & PCSTimeout) ==0 ) { -qemu_mod_timer (s->timer, next_time); +timer_mod (s->timer, next_time); } }
@@ -2960,7 +2960,7 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)case Timer:DPRINTF ("TCTR Timer reset on write\n" ); - s->TCTR_base =qemu_get_clock_ns (vm_clock); + s->TCTR_base =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );rtl8139_set_next_tctr_time (s, s->TCTR_base);break ;
@@ -2968,7 +2968,7 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)DPRINTF ("FlashReg TimerInt write val=0x%08x\n" , val);if (s->TimerInt != val) { s->TimerInt = val; -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); }break ;
@@ -3183,7 +3183,7 @@ static uint32_t rtl8139_io_readl(void *opaque, uint8_t addr)break ;case Timer: - ret =muldiv64 (qemu_get_clock_ns (vm_clock) - s->TCTR_base, + ret =muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - s->TCTR_base,PCI_FREQUENCY ,get_ticks_per_sec ());DPRINTF ("TCTR Timer read val=0x%08x\n" , ret);break ;
@@ -3245,7 +3245,7 @@ static uint32_t rtl8139_mmio_readl(void *opaque, hwaddr addr)static int rtl8139_post_load (void *opaque,int version_id) {RTL8139State * s = opaque; -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));if (version_id <4 ) { s->cplus_enabled = s->CpCmd !=0 ; }
@@ -3275,7 +3275,7 @@ static const VMStateDescription vmstate_rtl8139_hotplug_ready ={static void rtl8139_pre_save (void *opaque) {RTL8139State * s = opaque; -int64_t current_time =qemu_get_clock_ns (vm_clock); +int64_t current_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );/* set IntrStatus correctly */ rtl8139_set_next_tctr_time (s, current_time);
@@ -3446,7 +3446,7 @@ static void rtl8139_timer(void *opaque) s->IntrStatus |= PCSTimeout;rtl8139_update_irq (s); -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); }static void rtl8139_cleanup (NetClientState *nc)
@@ -3466,8 +3466,8 @@ static void pci_rtl8139_uninit(PCIDevice *dev)g_free (s->cplus_txbuffer); s->cplus_txbuffer =NULL ; } -qemu_del_timer (s->timer); -qemu_free_timer (s->timer); +timer_del (s->timer); +timer_free (s->timer);qemu_del_nic (s->nic); }
@@ -3535,8 +3535,8 @@ static int pci_rtl8139_init(PCIDevice *dev) s->cplus_txbuffer_offset =0 ; s->TimerExpire =0 ; - s->timer =qemu_new_timer_ns (vm_clock, rtl8139_timer, s); -rtl8139_set_next_tctr_time (s,qemu_get_clock_ns (vm_clock)); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , rtl8139_timer, s); +rtl8139_set_next_tctr_time (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ));add_boot_device_path (s->conf.bootindex, d,"/ethernet-phy@0" );
hw/net/virtio-net.c +10 -10
@@ -162,14 +162,14 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)if (virtio_net_started (n, queue_status) && !n->vhost_started) {if (q->tx_timer) { -qemu_mod_timer (q->tx_timer, -qemu_get_clock_ns (vm_clock) + n->tx_timeout); +timer_mod (q->tx_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + n->tx_timeout); }else {qemu_bh_schedule (q->tx_bh); } }else {if (q->tx_timer) { -qemu_del_timer (q->tx_timer); +timer_del (q->tx_timer); }else {qemu_bh_cancel (q->tx_bh); }
@@ -1131,12 +1131,12 @@ static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)if (q->tx_waiting) {virtio_queue_set_notification (vq,1 ); -qemu_del_timer (q->tx_timer); +timer_del (q->tx_timer); q->tx_waiting =0 ;virtio_net_flush_tx (q); }else { -qemu_mod_timer (q->tx_timer, -qemu_get_clock_ns (vm_clock) + n->tx_timeout); +timer_mod (q->tx_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + n->tx_timeout); q->tx_waiting =1 ;virtio_queue_set_notification (vq,0 ); }
@@ -1233,7 +1233,7 @@ static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue)if (n->vqs[i].tx_timer) { n->vqs[i].tx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_tx_timer); - n->vqs[i].tx_timer =qemu_new_timer_ns (vm_clock, + n->vqs[i].tx_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , virtio_net_tx_timer, &n->vqs[i]); }else {
@@ -1513,7 +1513,7 @@ static int virtio_net_device_init(VirtIODevice *vdev)if (n->net_conf.tx && !strcmp (n->net_conf.tx,"timer" )) { n->vqs[0 ].tx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_tx_timer); - n->vqs[0 ].tx_timer =qemu_new_timer_ns (vm_clock, virtio_net_tx_timer, + n->vqs[0 ].tx_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , virtio_net_tx_timer, &n->vqs[0 ]); }else { n->vqs[0].tx_vq = virtio_add_queue(vdev, 256,
@@ -1598,8 +1598,8 @@ static int virtio_net_device_exit(DeviceState *qdev)qemu_purge_queued_packets (nc);if (q->tx_timer) { -qemu_del_timer (q->tx_timer); -qemu_free_timer (q->tx_timer); +timer_del (q->tx_timer); +timer_free (q->tx_timer); }else {qemu_bh_delete (q->tx_bh); }
hw/openrisc/cputimer.c +5 -5
@@ -33,9 +33,9 @@ void cpu_openrisc_count_update(OpenRISCCPU *cpu)uint64_t now, next;uint32_t wait; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );if (!is_counting) { -qemu_del_timer (cpu->env.timer); +timer_del (cpu->env.timer); last_clk = now;return ; }
@@ -52,7 +52,7 @@ void cpu_openrisc_count_update(OpenRISCCPU *cpu) } next = now +muldiv64 (wait,get_ticks_per_sec (),TIMER_FREQ ); -qemu_mod_timer (cpu->env.timer, next); +timer_mod (cpu->env.timer, next); }void cpu_openrisc_count_start (OpenRISCCPU *cpu)
@@ -72,7 +72,7 @@ static void openrisc_timer_cb(void *opaque)OpenRISCCPU *cpu = opaque;if ((cpu->env.ttmr &TTMR_IE ) && -timer_expired (cpu->env.timer,qemu_get_clock_ns (vm_clock))) { +timer_expired (cpu->env.timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ))) {CPUState *cs =CPU (cpu); cpu->env.ttmr |=TTMR_IP ;
@@ -97,7 +97,7 @@ static void openrisc_timer_cb(void *opaque)void cpu_openrisc_clock_init (OpenRISCCPU *cpu) { - cpu->env.timer =qemu_new_timer_ns (vm_clock, &openrisc_timer_cb, cpu); + cpu->env.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &openrisc_timer_cb, cpu); cpu->env.ttmr =0x00000000 ; cpu->env.ttcr =0x00000000 ; }
hw/ppc/ppc.c +32 -32
218 lines not on this page · raw message
hw/ppc/ppc405_uc.c +4 -4
@@ -1348,7 +1348,7 @@ static uint32_t ppc4xx_gpt_readl (void *opaque, hwaddr addr)switch (addr) {case 0x00 :/* Time base counter */ - ret =muldiv64 (qemu_get_clock_ns (vm_clock) + gpt->tb_offset, + ret =muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + gpt->tb_offset, gpt->tb_freq,get_ticks_per_sec ());break ;case 0x10 :
@@ -1405,7 +1405,7 @@ static void ppc4xx_gpt_writel (void *opaque,case 0x00 :/* Time base counter */ gpt->tb_offset =muldiv64 (value,get_ticks_per_sec (), gpt->tb_freq) - -qemu_get_clock_ns (vm_clock); + -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );ppc4xx_gpt_compute_timer (gpt);break ;case 0x10 :
@@ -1476,7 +1476,7 @@ static void ppc4xx_gpt_reset (void *opaque)int i; gpt = opaque; -qemu_del_timer (gpt->timer); +timer_del (gpt->timer); gpt->oe =0x00000000 ; gpt->ol =0x00000000 ; gpt->im =0x00000000 ;
@@ -1497,7 +1497,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])for (i =0 ; i <5 ; i++) { gpt->irqs[i] = irqs[i]; } - gpt->timer =qemu_new_timer_ns (vm_clock, &ppc4xx_gpt_cb, gpt); + gpt->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &ppc4xx_gpt_cb, gpt);#ifdef DEBUG_GPT printf ("%s: offset " TARGET_FMT_plx"\n" , __func__, base);#endif
hw/ppc/ppc_booke.c +5 -5
@@ -136,7 +136,7 @@ static void booke_update_fixed_timer(CPUPPCState *env,uint64_t period;uint64_t now; - now =qemu_get_clock_ns (vm_clock); + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); tb =cpu_ppc_get_tb (tb_env, now, tb_env->tb_offset); period =1ULL << target_bit; delta_tick = period - (tb & (period -1 ));
@@ -167,7 +167,7 @@ static void booke_update_fixed_timer(CPUPPCState *env, (*next)++; } -qemu_mod_timer (timer, *next); +timer_mod (timer, *next); }static void booke_decr_cb (void *opaque)
@@ -303,12 +303,12 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags) tb_env->tb_freq = freq; tb_env->decr_freq = freq; tb_env->opaque = booke_timer; - tb_env->decr_timer =qemu_new_timer_ns (vm_clock, &booke_decr_cb, cpu); + tb_env->decr_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &booke_decr_cb, cpu); booke_timer->fit_timer = -qemu_new_timer_ns (vm_clock, &booke_fit_cb, cpu); +timer_new_ns (QEMU_CLOCK_VIRTUAL , &booke_fit_cb, cpu); booke_timer->wdt_timer = -qemu_new_timer_ns (vm_clock, &booke_wdt_cb, cpu); +timer_new_ns (QEMU_CLOCK_VIRTUAL , &booke_wdt_cb, cpu); ret =kvmppc_booke_watchdog_enable (cpu);
hw/ppc/spapr.c +4 -4
@@ -789,7 +789,7 @@ static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr, {int htabslots =HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ;int index = spapr->htab_save_index; -int64_t starttime =qemu_get_clock_ns (rt_clock); +int64_t starttime =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );assert (spapr->htab_first_pass);
@@ -820,7 +820,7 @@ static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr,qemu_put_buffer (f,HPTE (spapr->htab, chunkstart),HASH_PTE_SIZE_64 * n_valid); -if ((qemu_get_clock_ns (rt_clock) - starttime) > max_ns) { +if ((qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - starttime) > max_ns) {break ; } }
@@ -841,7 +841,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,int htabslots =HTAB_SIZE (spapr) /HASH_PTE_SIZE_64 ;int examined =0 , sent =0 ;int index = spapr->htab_save_index; -int64_t starttime =qemu_get_clock_ns (rt_clock); +int64_t starttime =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );assert (!spapr->htab_first_pass);
@@ -886,7 +886,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr, HASH_PTE_SIZE_64 * n_valid); sent += index - chunkstart; -if (!final && (qemu_get_clock_ns (rt_clock) - starttime) > max_ns) { +if (!final && (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - starttime) > max_ns) {break ; } }
hw/sd/sdhci.c +14 -14
@@ -134,8 +134,8 @@ static void sdhci_raise_insertion_irq(void *opaque)SDHCIState *s = (SDHCIState *)opaque;if (s->norintsts &SDHC_NIS_REMOVE ) { -qemu_mod_timer (s->insert_timer, -qemu_get_clock_ns (vm_clock) +SDHC_INSERTION_DELAY ); +timer_mod (s->insert_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +SDHC_INSERTION_DELAY ); }else { s->prnsts =0x1ff0000 ;if (s->norintstsen &SDHC_NISEN_INSERT ) {
@@ -152,8 +152,8 @@ static void sdhci_insert_eject_cb(void *opaque, int irq, int level)if ((s->norintsts &SDHC_NIS_REMOVE ) && level) {/* Give target some time to notice card ejection */ -qemu_mod_timer (s->insert_timer, -qemu_get_clock_ns (vm_clock) +SDHC_INSERTION_DELAY ); +timer_mod (s->insert_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +SDHC_INSERTION_DELAY ); }else {if (level) { s->prnsts =0x1ff0000 ;
@@ -186,8 +186,8 @@ static void sdhci_card_readonly_cb(void *opaque, int irq, int level)static void sdhci_reset (SDHCIState *s) { -qemu_del_timer (s->insert_timer); -qemu_del_timer (s->transfer_timer); +timer_del (s->insert_timer); +timer_del (s->transfer_timer);/* Set all registers to 0. Capabilities registers are not cleared * and assumed to always preserve their value, given to them during * initialization */
@@ -764,8 +764,8 @@ static void sdhci_do_adma(SDHCIState *s) }/* we have unfinished business - reschedule to continue ADMA */ -qemu_mod_timer (s->transfer_timer, -qemu_get_clock_ns (vm_clock) +SDHC_TRANSFER_DELAY ); +timer_mod (s->transfer_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +SDHC_TRANSFER_DELAY ); }/* Perform data transfer according to controller configuration */
@@ -1170,18 +1170,18 @@ static void sdhci_initfn(Object *obj) s->ro_cb =qemu_allocate_irqs (sdhci_card_readonly_cb, s,1 )[0 ];sd_set_cb (s->card, s->ro_cb, s->eject_cb); - s->insert_timer =qemu_new_timer_ns (vm_clock, sdhci_raise_insertion_irq, s); - s->transfer_timer =qemu_new_timer_ns (vm_clock, sdhci_do_data_transfer, s); + s->insert_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sdhci_raise_insertion_irq, s); + s->transfer_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sdhci_do_data_transfer, s); }static void sdhci_uninitfn (Object *obj) {SDHCIState *s =SDHCI (obj); -qemu_del_timer (s->insert_timer); -qemu_free_timer (s->insert_timer); -qemu_del_timer (s->transfer_timer); -qemu_free_timer (s->transfer_timer); +timer_del (s->insert_timer); +timer_free (s->insert_timer); +timer_del (s->transfer_timer); +timer_free (s->transfer_timer);qemu_free_irqs (&s->eject_cb);qemu_free_irqs (&s->ro_cb);
hw/sparc64/sun4u.c +10 -10
@@ -387,9 +387,9 @@ static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu, timer->disabled_mask = disabled_mask; timer->disabled =1 ; - timer->clock_offset =qemu_get_clock_ns (vm_clock); + timer->clock_offset =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - timer->qtimer =qemu_new_timer_ns (vm_clock, cb, cpu); + timer->qtimer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cb, cpu);return timer; }
@@ -397,9 +397,9 @@ static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu,static void cpu_timer_reset (CPUTimer *timer) { timer->disabled =1 ; - timer->clock_offset =qemu_get_clock_ns (vm_clock); + timer->clock_offset =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); -qemu_del_timer (timer->qtimer); +timer_del (timer->qtimer); }static void main_cpu_reset (void *opaque)
@@ -495,7 +495,7 @@ void cpu_tick_set_count(CPUTimer *timer, uint64_t count)uint64_t real_count = count & ~timer->disabled_mask;uint64_t disabled_bit = count & timer->disabled_mask; -int64_t vm_clock_offset =qemu_get_clock_ns (vm_clock) - +int64_t vm_clock_offset =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) -cpu_to_timer_ticks (real_count, timer->frequency); TIMER_DPRINTF("%s set_count count=0x%016lx (%s) p=%p\n",
@@ -509,7 +509,7 @@ void cpu_tick_set_count(CPUTimer *timer, uint64_t count)uint64_t cpu_tick_get_count (CPUTimer *timer) {uint64_t real_count =timer_to_cpu_ticks ( -qemu_get_clock_ns (vm_clock) - timer->clock_offset, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - timer->clock_offset, timer->frequency); TIMER_DPRINTF("%s get_count count=0x%016lx (%s) p=%p\n",
@@ -524,7 +524,7 @@ uint64_t cpu_tick_get_count(CPUTimer *timer)void cpu_tick_set_limit (CPUTimer *timer,uint64_t limit) { -int64_t now =qemu_get_clock_ns (vm_clock); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );uint64_t real_limit = limit & ~timer->disabled_mask; timer->disabled = (limit & timer->disabled_mask) ?1 :0 ;
@@ -548,11 +548,11 @@ void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit)if (!real_limit) {TIMER_DPRINTF ("%s set_limit limit=ZERO - not starting timer\n" , timer->name); -qemu_del_timer (timer->qtimer); +timer_del (timer->qtimer); }else if (timer->disabled) { -qemu_del_timer (timer->qtimer); +timer_del (timer->qtimer); }else { -qemu_mod_timer (timer->qtimer, expires); +timer_mod (timer->qtimer, expires); } }
hw/timer/arm_mptimer.c +6 -6
@@ -81,10 +81,10 @@ static void timerblock_reload(TimerBlock *tb, int restart)return ; }if (restart) { - tb->tick =qemu_get_clock_ns (vm_clock); + tb->tick =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); } tb->tick += (int64_t )tb->count *timerblock_scale (tb); -qemu_mod_timer (tb->timer, tb->tick); +timer_mod (tb->timer, tb->tick); }static void timerblock_tick (void *opaque)
@@ -113,7 +113,7 @@ static uint64_t timerblock_read(void *opaque, hwaddr addr,return 0 ; }/* Slow and ugly, but hopefully won't happen too often. */ - val = tb->tick -qemu_get_clock_ns (vm_clock); + val = tb->tick -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); val /=timerblock_scale (tb);if (val <0 ) { val =0 ;
@@ -140,7 +140,7 @@ static void timerblock_write(void *opaque, hwaddr addr,case 4 :/* Counter. */ if ((tb->control &1 ) && tb->count) {/* Cancel the previous timer. */ -qemu_del_timer (tb->timer); +timer_del (tb->timer); } tb->count = value;if (tb->control &1 ) {
@@ -211,7 +211,7 @@ static void timerblock_reset(TimerBlock *tb) tb->status =0 ; tb->tick =0 ;if (tb->timer) { -qemu_del_timer (tb->timer); +timer_del (tb->timer); } }
@@ -248,7 +248,7 @@ static int arm_mptimer_init(SysBusDevice *dev)sysbus_init_mmio (dev, &s->iomem);for (i =0 ; i < s->num_cpu; i++) {TimerBlock *tb = &s->timerblock[i]; - tb->timer =qemu_new_timer_ns (vm_clock, timerblock_tick, tb); + tb->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , timerblock_tick, tb);sysbus_init_irq (dev, &tb->irq);memory_region_init_io (&tb->iomem,OBJECT (s), &timerblock_ops, tb,"arm_mptimer_timerblock" ,0x20 );
hw/timer/cadence_ttc.c +3 -3
@@ -172,7 +172,7 @@ static void cadence_timer_run(CadenceTimerState *s) event_interval = next_value - (int64_t )s->reg_value; event_interval = (event_interval <0 ) ? -event_interval : event_interval; -qemu_mod_timer (s->timer, s->cpu_time + +timer_mod (s->timer, s->cpu_time +cadence_timer_get_ns (s, event_interval)); }
@@ -184,7 +184,7 @@ static void cadence_timer_sync(CadenceTimerState *s) (int64_t)s->reg_interval + 1 : 0x10000ULL) << 16;uint64_t old_time = s->cpu_time; - s->cpu_time =qemu_get_clock_ns (vm_clock); + s->cpu_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );DB_PRINT ("cpu time: %lld ns\n" , (long long )old_time);if (!s->cpu_time_valid || old_time == s->cpu_time) {
@@ -401,7 +401,7 @@ static void cadence_timer_init(uint32_t freq, CadenceTimerState *s)cadence_timer_reset (s); - s->timer =qemu_new_timer_ns (vm_clock, cadence_timer_tick, s); + s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cadence_timer_tick, s); }static int cadence_ttc_init (SysBusDevice *dev)
hw/timer/etraxfs_timer.c +1 -1
@@ -93,7 +93,7 @@ timer_read(void *opaque, hwaddr addr, unsigned int size) r =ptimer_get_count (t->ptimer_t1);break ;case R_TIME : - r =qemu_get_clock_ns (vm_clock) /10 ; + r =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /10 ;break ;case RW_INTR_MASK : r = t->rw_intr_mask;
hw/timer/exynos4210_mct.c +1 -1
@@ -906,7 +906,7 @@ static void exynos4210_ltick_event(void *opaque)/* raise interrupt if enabled */ if (s->reg.int_enb &L_INT_INTENB_ICNTEIE ) {#ifdef DEBUG_MCT - time2[s->id] =qemu_get_clock_ns (vm_clock); + time2[s->id] =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );DPRINTF ("local timer[%d] IRQ: %llx\n" , s->id, time2[s->id] - time1[s->id]); time1[s->id] = time2[s->id];
hw/timer/hpet.c +10 -10
@@ -152,7 +152,7 @@ static int deactivating_bit(uint64_t old, uint64_t new, uint64_t mask)static uint64_t hpet_get_ticks (HPETState *s) { -return ns_to_ticks (qemu_get_clock_ns (vm_clock) + s->hpet_offset); +return ns_to_ticks (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->hpet_offset); }/*
@@ -233,7 +233,7 @@ static int hpet_post_load(void *opaque, int version_id)HPETState *s = opaque;/* Recalculate the offset between the main counter and guest time */ - s->hpet_offset =ticks_to_ns (s->hpet_counter) -qemu_get_clock_ns (vm_clock); + s->hpet_offset =ticks_to_ns (s->hpet_counter) -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );/* Push number of timers into capability returned via HPET_ID */ s->capability &= ~HPET_ID_NUM_TIM_MASK ;
@@ -332,12 +332,12 @@ static void hpet_timer(void *opaque) } } diff =hpet_calculate_diff (t, cur_tick); -qemu_mod_timer (t->qemu_timer, -qemu_get_clock_ns (vm_clock) + (int64_t )ticks_to_ns (diff)); +timer_mod (t->qemu_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (int64_t )ticks_to_ns (diff)); }else if (t->config &HPET_TN_32BIT && !timer_is_periodic (t)) {if (t->wrap_flag) { diff =hpet_calculate_diff (t, cur_tick); -qemu_mod_timer (t->qemu_timer,qemu_get_clock_ns (vm_clock) + +timer_mod (t->qemu_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (int64_t )ticks_to_ns (diff)); t->wrap_flag =0 ; }
@@ -365,13 +365,13 @@ static void hpet_set_timer(HPETTimer *t) t->wrap_flag =1 ; } } -qemu_mod_timer (t->qemu_timer, -qemu_get_clock_ns (vm_clock) + (int64_t )ticks_to_ns (diff)); +timer_mod (t->qemu_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + (int64_t )ticks_to_ns (diff)); }static void hpet_del_timer (HPETTimer *t) { -qemu_del_timer (t->qemu_timer); +timer_del (t->qemu_timer);update_irq (t,0 ); }
@@ -567,7 +567,7 @@ static void hpet_ram_write(void *opaque, hwaddr addr,if (activating_bit (old_val, new_val,HPET_CFG_ENABLE )) {/* Enable main counter and interrupt generation. */ s->hpet_offset = -ticks_to_ns (s->hpet_counter) -qemu_get_clock_ns (vm_clock); +ticks_to_ns (s->hpet_counter) -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );for (i =0 ; i < s->num_timers; i++) {if ((&s->timer[i])->cmp != ~0ULL ) {hpet_set_timer (&s->timer[i]);
@@ -726,7 +726,7 @@ static void hpet_realize(DeviceState *dev, Error **errp) }for (i =0 ; i <HPET_MAX_TIMERS ; i++) { timer = &s->timer[i]; - timer->qemu_timer =qemu_new_timer_ns (vm_clock, hpet_timer, timer); + timer->qemu_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , hpet_timer, timer); timer->tn = i; timer->state = s; }
hw/timer/i8254.c +13 -13
@@ -51,7 +51,7 @@ static int pit_get_count(PITChannelState *s)uint64_t d;int counter; - d =muldiv64 (qemu_get_clock_ns (vm_clock) - s->count_load_time,PIT_FREQ , + d =muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - s->count_load_time,PIT_FREQ ,get_ticks_per_sec ());switch (s->mode) {case 0 :
@@ -85,7 +85,7 @@ static void pit_set_channel_gate(PITCommonState *s, PITChannelState *sc,case 5 :if (sc->gate < val) {/* restart counting on rising edge */ - sc->count_load_time =qemu_get_clock_ns (vm_clock); + sc->count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );pit_irq_timer_update (sc, sc->count_load_time); }break ;
@@ -93,7 +93,7 @@ static void pit_set_channel_gate(PITCommonState *s, PITChannelState *sc,case 3 :if (sc->gate < val) {/* restart counting on rising edge */ - sc->count_load_time =qemu_get_clock_ns (vm_clock); + sc->count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );pit_irq_timer_update (sc, sc->count_load_time); }/* XXX: disable/enable counting */
@@ -106,7 +106,7 @@ static inline void pit_load_count(PITChannelState *s, int val) {if (val ==0 ) val =0x10000 ; - s->count_load_time =qemu_get_clock_ns (vm_clock); + s->count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); s->count = val;pit_irq_timer_update (s, s->count_load_time); }
@@ -143,7 +143,7 @@ static void pit_ioport_write(void *opaque, hwaddr addr,/* XXX: add BCD and null count */ s->status = (pit_get_out (s, -qemu_get_clock_ns (vm_clock)) <<7 ) | +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )) <<7 ) | (s->rw_mode <<4 ) | (s->mode <<1 ) | s->bcd;
@@ -260,9 +260,9 @@ static void pit_irq_timer_update(PITChannelState *s, int64_t current_time)#endif s->next_transition_time = expire_time;if (expire_time !=-1 ) -qemu_mod_timer (s->irq_timer, expire_time); +timer_mod (s->irq_timer, expire_time);else -qemu_del_timer (s->irq_timer); +timer_del (s->irq_timer); }static void pit_irq_timer (void *opaque)
@@ -281,7 +281,7 @@ static void pit_reset(DeviceState *dev) s = &pit->channels[0 ];if (!s->irq_disabled) { -qemu_mod_timer (s->irq_timer, s->next_transition_time); +timer_mod (s->irq_timer, s->next_transition_time); } }
@@ -294,10 +294,10 @@ static void pit_irq_control(void *opaque, int n, int enable)if (enable) { s->irq_disabled =0 ; -pit_irq_timer_update (s,qemu_get_clock_ns (vm_clock)); +pit_irq_timer_update (s,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); }else { s->irq_disabled =1 ; -qemu_del_timer (s->irq_timer); +timer_del (s->irq_timer); } }
@@ -316,9 +316,9 @@ static void pit_post_load(PITCommonState *s)PITChannelState *sc = &s->channels[0 ];if (sc->next_transition_time !=-1 ) { -qemu_mod_timer (sc->irq_timer, sc->next_transition_time); +timer_mod (sc->irq_timer, sc->next_transition_time); }else { -qemu_del_timer (sc->irq_timer); +timer_del (sc->irq_timer); } }
@@ -330,7 +330,7 @@ static void pit_realizefn(DeviceState *dev, Error **err) s = &pit->channels[0 ];/* the timer 0 is connected to an IRQ */ - s->irq_timer =qemu_new_timer_ns (vm_clock, pit_irq_timer, s); + s->irq_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pit_irq_timer, s);qdev_init_gpio_out (dev, &s->irq,1 ); memory_region_init_io(&pit->ioports, OBJECT(pit), &pit_ioport_ops,
hw/timer/i8254_common.c +2 -2
@@ -136,7 +136,7 @@ void pit_get_channel_info_common(PITCommonState *s, PITChannelState *sc, info->gate = sc->gate; info->mode = sc->mode; info->initial_count = sc->count; - info->out =pit_get_out (sc,qemu_get_clock_ns (vm_clock)); + info->out =pit_get_out (sc,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL )); }void pit_get_channel_info (ISADevice *dev,int channel,PITChannelInfo *info)
@@ -157,7 +157,7 @@ void pit_reset_common(PITCommonState *pit) s = &pit->channels[i]; s->mode =3 ; s->gate = (i !=2 ); - s->count_load_time =qemu_get_clock_ns (vm_clock); + s->count_load_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); s->count =0x10000 ;if (i ==0 && !s->irq_disabled) { s->next_transition_time =
hw/timer/m48t59.c +8 -8
@@ -137,7 +137,7 @@ static void alarm_cb (void *opaque)/* Repeat once a second */ next_time =1 ; } - qemu_mod_timer(NVRAM->alrm_timer, qemu_clock_get_ns(rtc_clock) +
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
Part of the diff is not shown here. View the raw message.
RFC PATCH v10 31/31 aio / timers: Remove legacy interface
In reply to Alex BlighRemove the legacy interface from include/qemu/timers.h.
Ensure struct QEMUClock is not exposed at all.
--- include/qemu/timer.h | 214 +------------------------------------------------- qemu-timer.c | 35 +-------- 2 files changed, 5 insertions(+), 244 deletions(-)
include/qemu/timer.h +2 -212
@@ -44,7 +44,6 @@ typedef enum {QEMU_CLOCK_MAX } QEMUClockType; -typedef struct QEMUClock QEMUClock ;typedef struct QEMUTimerList QEMUTimerList ; typedef struct QEMUTimerListGroup {
@@ -66,20 +65,10 @@ typedef struct QEMUTimer {extern QEMUTimerListGroup main_loop_tlg;/* -* QEMUClock & QEMUClockType +* QEMUClockType */ -/** -* qemu_clock_ptr: -* @type: type of clock -* -* Translate a clock type into a pointer to QEMUClock object. -* -* Returns: a pointer to the QEMUClock object -*/ -QEMUClock *qemu_clock_ptr (QEMUClockType type); - -/** +/* * qemu_clock_get_ns; * @type: the clock type *
@@ -654,205 +643,6 @@ static inline int64_t get_ticks_per_sec(void)return 1000000000LL ; } -/************************************************** -* LEGACY API SECTION -* -* All these calls will be deleted in due course -*/ - -/* These three clocks are maintained here with separate variable -* names for compatibility only. -*/ -#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) -#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) -#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) - -/** LEGACY -* qemu_get_clock_ns: -* @clock: the clock to operate on -* -* Get the nanosecond value of a clock -* -* Returns: the clock value in nanoseconds -*/ -int64_t qemu_get_clock_ns (QEMUClock *clock); - -/** LEGACY -* qemu_get_clock_ms: -* @clock: the clock to operate on -* -* Get the millisecond value of a clock -* -* Returns: the clock value in milliseconds -*/ -static inline int64_t qemu_get_clock_ms (QEMUClock *clock) -{ -return qemu_get_clock_ns (clock) /SCALE_MS ; -} - -/** LEGACY -* qemu_register_clock_reset_notifier: -* @clock: the clock to operate on -* @notifier: the notifier function -* -* Register a notifier function to call when the clock -* concerned is reset. -*/ -void qemu_register_clock_reset_notifier (QEMUClock *clock, -Notifier *notifier); - -/** LEGACY -* qemu_unregister_clock_reset_notifier: -* @clock: the clock to operate on -* @notifier: the notifier function -* -* Unregister a notifier function to call when the clock -* concerned is reset. -*/ -void qemu_unregister_clock_reset_notifier (QEMUClock *clock, -Notifier *notifier); - -/** LEGACY -* qemu_new_timer: -* @clock: the clock to operate on -* @scale: the scale of the clock -* @cb: the callback function to call when the timer expires -* @opaque: an opaque pointer to pass to the callback -* -* Produce a new timer attached to clock @clock. This is a legacy -* function. Use timer_new instead. -* -* Returns: a pointer to the new timer allocated. -*/ -QEMUTimer *qemu_new_timer (QEMUClock *clock,int scale, -QEMUTimerCB *cb,void *opaque); - -/** LEGACY -* qemu_free_timer: -* @ts: the timer to operate on -* -* free the timer @ts. @ts must not be active. -* -* This is a legacy function. Use timer_free instead. -*/ -static inline void qemu_free_timer (QEMUTimer *ts) -{ -timer_free (ts); -} - -/** LEGACY -* qemu_del_timer: -* @ts: the timer to operate on -* -* Delete a timer. This makes it inactive. It does not free -* memory. -* -* This is a legacy function. Use timer_del instead. -*/ -static inline void qemu_del_timer (QEMUTimer *ts) -{ -timer_del (ts); -} - -/** LEGACY -* qemu_mod_timer_ns: -* @ts: the timer to operate on -* @expire_time: the expiry time in nanoseconds -* -* Modify a timer such that the expiry time is @expire_time -* as measured in nanoseconds -* -* This is a legacy function. Use timer_mod_ns. -*/ -static inline void qemu_mod_timer_ns (QEMUTimer *ts,int64_t expire_time) -{ -timer_mod_ns (ts, expire_time); -} - -/** LEGACY -* qemu_mod_timer: -* @ts: the timer to operate on -* @expire_time: the expiry time -* -* Modify a timer such that the expiry time is @expire_time -* as measured in the timer's scale -* -* This is a legacy function. Use timer_mod. -*/ -static inline void qemu_mod_timer (QEMUTimer *ts,int64_t expire_time) -{ -timer_mod (ts, expire_time); -} - -/** LEGACY -* qemu_run_timers: -* @clock: clock on which to operate -* -* Run all the timers associated with the default timer list -* of a clock. -* -* Returns: true if any timer ran. -*/ -bool qemu_run_timers (QEMUClock *clock); - -/** LEGACY -* qemu_new_timer_ns: -* @clock: the clock to associate with the timer -* @callback: the callback to call when the timer expires -* @opaque: the opaque pointer to pass to the callback -* -* Create a new timer with nanosecond scale on the default timer list -* associated with the clock. -* -* Returns: a pointer to the newly created timer -*/ -static inline QEMUTimer *qemu_new_timer_ns (QEMUClock *clock,QEMUTimerCB *cb, -void *opaque) -{ -return qemu_new_timer (clock,SCALE_NS , cb, opaque); -} - -/** LEGACY -* qemu_new_timer_us: -* @clock: the clock to associate with the timer -* @callback: the callback to call when the timer expires -* @opaque: the opaque pointer to pass to the callback -* -* Create a new timer with microsecond scale on the default timer list -* associated with the clock. -* -* Returns: a pointer to the newly created timer -*/ -static inline QEMUTimer *qemu_new_timer_us (QEMUClock *clock, -QEMUTimerCB *cb, -void *opaque) -{ -return qemu_new_timer (clock,SCALE_US , cb, opaque); -} - -/** LEGACY -* qemu_new_timer_ms: -* @clock: the clock to associate with the timer -* @callback: the callback to call when the timer expires -* @opaque: the opaque pointer to pass to the callback -* -* Create a new timer with millisecond scale on the default timer list -* associated with the clock. -* -* Returns: a pointer to the newly created timer -*/ -static inline QEMUTimer *qemu_new_timer_ms (QEMUClock *clock, -QEMUTimerCB *cb, -void *opaque) -{ -return qemu_new_timer (clock,SCALE_MS , cb, opaque); -} - -/**************************************************** -* END OF LEGACY API SECTION -*/ - -/* * Low level clock functions */
qemu-timer.c +3 -32
@@ -44,7 +44,7 @@/***********************************************************/ /* timers */ -struct QEMUClock { +typedef struct QEMUClock { QLIST_HEAD(, QEMUTimerList) timerlists; NotifierList reset_notifiers;
@@ -52,7 +52,7 @@ struct QEMUClock {QEMUClockType type;bool enabled; -}; +} QEMUClock;QEMUTimerListGroup main_loop_tlg;QEMUClock qemu_clocks[QEMU_CLOCK_MAX ];
@@ -80,7 +80,7 @@ struct QEMUTimerList {* * Returns: a pointer to the QEMUClock object */ -QEMUClock *qemu_clock_ptr (QEMUClockType type) +static inline QEMUClock *qemu_clock_ptr (QEMUClockType type) {return &qemu_clocks[type]; }
@@ -291,13 +291,6 @@ void timer_init(QEMUTimer *ts, ts->scale = scale; } -QEMUTimer *qemu_new_timer (QEMUClock *clock,int scale, -QEMUTimerCB *cb,void *opaque) -{ -return timer_new_tl (main_loop_tlg.tl[clock->type], - scale, cb, opaque); -} -void timer_free (QEMUTimer *ts) {g_free (ts);
@@ -407,11 +400,6 @@ bool qemu_clock_run_timers(QEMUClockType type)return timerlist_run_timers (main_loop_tlg.tl[type]); } -bool qemu_run_timers (QEMUClock *clock) -{ -return qemu_clock_run_timers (clock->type); -} -void timerlistgroup_init (QEMUTimerListGroup *tlg,QEMUTimerListNotifyCB *cb,void *opaque) {
@@ -479,11 +467,6 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } -int64_t qemu_get_clock_ns (QEMUClock *clock) -{ -return qemu_clock_get_ns (clock->type); -} -void qemu_clock_register_reset_notifier (QEMUClockType type,Notifier *notifier) {
@@ -497,18 +480,6 @@ void qemu_clock_unregister_reset_notifier(QEMUClockType type,notifier_remove (notifier); } -void qemu_register_clock_reset_notifier (QEMUClock *clock, -Notifier *notifier) -{ -qemu_clock_register_reset_notifier (clock->type, notifier); -} - -void qemu_unregister_clock_reset_notifier (QEMUClock *clock, -Notifier *notifier) -{ -qemu_clock_unregister_reset_notifier (clock->type, notifier); -} -void init_clocks (void ) {QEMUClockType type;
Signature · 1 line
1.7.9.5
Quoted 6 lines · Alex Bligh
[ This patch set is available from git at:
https://github.com/abligh/qemu/tree/aio-timers10
As autogenerated patch 30 of the series is too large for the mailing list. ]This patch series adds support for timers attached to an AioContext clock which get called within
aio_poll.
OK, here are my findings while making use of this API for threading timers of the RTC device model:
In general, the new timer API makes sense to me and turned out to be reusable for factoring out separate timer threads. There are basically two ways to do this. One is to use the timerlist abstraction directly, mostly reimplementing what AioContext provides (timerlist processing + early wakeups via notification). The second is to tweak aio_poll and the AioContext setup according to the needs of a timer handling thread.
With tweaking I mean:
bool aio_poll(AioContext *ctx, bool blocking,
void (*blocking_cb)(bool, void *),
void *blocking_cb_opaque);i.e. adding a callback that aio_poll will invoke before and right after waiting for events/timeouts. This allows to drop/reacquire locks that protect data structures used both by the timer thread and other threads running the device model. The result looks like this:
static void rtc_aio_blocking_cb(bool blocking, void *opaque)
{
RTCState *s = opaque;
if (blocking) {
qemu_mutex_unlock(&s->lock);
} else {
qemu_mutex_lock(&s->lock);
}
}static void *rtc_aio_thread(void *opaque)
{
RTCState *s = opaque;
qemu_mutex_lock(&s->lock);
s->thread_init_done = true;
qemu_cond_signal(&s->init_cond);
while (1) {
aio_poll(s->aio_ctx, true, rtc_aio_blocking_cb, s);
}
return NULL;
}Another trick necessary to make this work is the following:
static int rtc_aio_flush_true(EventNotifier *e)
{
return 1;
}...
s->aio_ctx = aio_context_new();
aio_set_event_notifier(s->aio_ctx, &s->aio_ctx->notifier,
(EventNotifierHandler *)
event_notifier_test_and_clear,
rtc_aio_flush_true);ie. enable blocking of aio_poll via the only i/o channel a timer thread
has: the event notifier.
But these shortcomings when reusing AioContext are not due to the new timer API, they predate it.
I've just tested a prototype here. It consists of Paolo's RCU work, this series, support for real-time threads, unlocked address space access dispatching and several hacks to make the RTC work outside of BQL (most of the time). Our benchmark is a guest that validates the periodic RTC timer IRQ against a second clock source at ~1 KHz - and it's happy with the result so far.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
With tweaking I mean:
bool aio_poll(AioContext *ctx, bool blocking,
void (*blocking_cb)(bool, void *), void *blocking_cb_opaque);i.e. adding a callback that
aio_pollwill invoke before and right after waiting for events/timeouts. This allows to drop/reacquire locks that protect data structures used both by the timer thread and other threads running the device model.
That's interesting. I didn't give a huge amount of thought to thread extensibility (not least as the locking needed fixing first), but the model I had in my head was not that the locks were taken on exit from qemu_poll_ns and released on entry to it, but rather that the individual dispatch functions and timer functions called only took whatever locks they needed as and when they needed them. IE everything would already be unlocked prior to calling qemu_poll_ns. I suppose both would work.
Signature · 1 line
Alex Bligh
Quoted 14 lines · Alex Bligh
Quoted 10 lines · Jan Kiszka
With tweaking I mean:
bool aio_poll(AioContext *ctx, bool blocking,
void (*blocking_cb)(bool, void *), void *blocking_cb_opaque);i.e. adding a callback that
aio_pollwill invoke before and right after waiting for events/timeouts. This allows to drop/reacquire locks that protect data structures used both by the timer thread and other threads running the device model.
Quoted 9 lines
That's interesting. I didn't give a huge amount of thought to thread extensibility (not least as the locking needed fixing first), but the model I had in my head was not that the locks were taken on exit from
qemu_poll_nsand released on entry to it, but rather that the individual dispatch functions and timer functions called only took whatever locks they needed as and when they needed them. IE everything would already be unlocked prior to callingqemu_poll_ns. I suppose both would work.
Well, all the timer machinery requires some locking as well. So one option is to add this to the core, the other - the one that I'm following - is to push the locking to the timer users. The advantage of the latter approach is that you can often reuse existing locks instead of extending their number excessively, potentially causing ordering issues.
The locks to be reused are, or course, the BQL or device model locks, like in my RTC scenario. Or think of a networking backend like slirp:
TCP timers could run under the same lock that is also protecting the rest of a slirp instance state machine. Well, not sure we can gain a lot by threading slirp, but the concept remains the same.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 8 lines · Jan Kiszka
Another trick necessary to make this work is the following:
static int
rtc_aio_flush_true(EventNotifier *e){ return 1; }...
Quoted 8 lines
s->aio_ctx = aio_context_new(); aio_set_event_notifier(s->aio_ctx, &s->aio_ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear, rtc_aio_flush_true);ie. enable blocking of
aio_pollvia the only i/o channel a timer thread
has: the event notifier.
Personally I think this is a straightforward bug in aio_poll. I think it should block if it has no fds to listen to until the next timer occurs. People who call it with no fds and no timers deserve all they get. But as you've just proved, this is useful (for instance when another thread can add timers).
I think stefanha disagrees this is a bug though :-)
Signature · 1 line
Alex Bligh
Quoted 21 lines · Alex Bligh
Quoted 8 lines · Jan Kiszka
Another trick necessary to make this work is the following:
static int
rtc_aio_flush_true(EventNotifier *e){ return 1; }...
Quoted 8 lines
s->aio_ctx = aio_context_new(); aio_set_event_notifier(s->aio_ctx, &s->aio_ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear, rtc_aio_flush_true);ie. enable blocking of
aio_pollvia the only i/o channel a timer thread
has: the event notifier.
Quoted 8 lines
Personally I think this is a straightforward bug in
aio_poll. I think it should block if it has no fds to listen to until the next timer occurs. People who call it with no fds and no timers deserve all they get. But as you've just proved, this is useful (for instance when another thread can add timers).I think stefanha disagrees this is a bug though :-)
To my understanding, the use case behind the current behavior is qemu_aio_wait() which is only supposed to block when there are pending requests for the main aio context. We should be able to address this scenarios also in a different way. I would definitely prefer to not depend on that hack above.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Jan,
Quoted 5 lines · Jan Kiszka
To my understanding, the use case behind the current behavior is
qemu_aio_wait()which is only supposed to block when there are pending requests for the main aio context. We should be able to address this scenarios also in a different way. I would definitely prefer to not depend on that hack above.
I don't *think* so. If I'm right the problem is line 233 of aio-posix.c (and similar in the windows variant):
/* No AIO operations? Get us out of here */
if (!busy) {
return progress;
}
... do qemu_poll_ns ...busy is set to true if there are any FDs for which ->flush is true and ->io_flush() returns non-zero.
I think this should instead be looking the equivalent of FD_ISSET across all FDs (read and write) and the blocking flag. IE if blocking is set to true, then it should ALWAYS do qemu_poll_ns, lest it busyloop rather than wait for the next timer expiry.
More here:
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03950.html
I'm not very happy with this logic (but it's the same as before), and I note Stefan removes the horrible busy flag in this series:
http://lists.nongnu.org/archive/html/qemu-devel/2013-07/msg00092.html
In this case, I'm not sure it makes a great deal of difference in practice as you'll need an eventfd or something similar to signal to the thread that it should exit, I presume.
Signature · 1 line
Alex Bligh
Quoted 20 lines · Alex Bligh
Jan,
Quoted 5 lines · Jan Kiszka
To my understanding, the use case behind the current behavior is
qemu_aio_wait()which is only supposed to block when there are pending requests for the main aio context. We should be able to address this scenarios also in a different way. I would definitely prefer to not depend on that hack above.I don't *think* so. If I'm right the problem is line 233 of
aio-posix.c(and similar in the windows variant):/* No AIO operations? Get us out of here */ if (!busy) { return progress; } ... do qemu_poll_ns ...
Quoted 2 lines
busy is set to true if there are any FDs for which ->flush is true and ->io_flush() returns non-zero.
Right.
Quoted 6 lines
I think this should instead be looking the equivalent of
FD_ISSETacross all FDs (read and write) and the blocking flag. IE if blocking is set to true, then it should ALWAYS doqemu_poll_ns, lest it busyloop rather than wait for the next timer expiry.
Yes, that would be needed.
Quoted 8 lines
More here:
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03950.htmlI'm not very happy with this logic (but it's the same as before), and I note Stefan removes the horrible busy flag in this series:
http://lists.nongnu.org/archive/html/qemu-devel/2013-07/msg00092.html
Yeah:
- /* No AIO operations? Get us out of here */
- if (!busy) {
+ /* early return if we only have the aio_notify() fd */
+ if (ctx->pollfds->len == 1) {
return progress;
}So this is even worse for my use case.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Yeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }So this is even worse for my use case.
Oh yes :-) OK, well Stefan's patch series is thus more predictable, but I think still wrong (to be fair to Stefan, his patch was made before it made sense for aio_poll to be called with no FDs bar the eventfd and blocking=1)
I think it should be:
- /* No AIO operations? Get us out of here */
- if (!busy) {
+ /* early return if we only have the aio_notify() fd */
+ if (!blocking && (ctx->pollfds->len == 1)) {
return progress;
}And perhaps <=1 for safety.
Signature · 1 line
Alex Bligh
Quoted 53 lines · Jan Kiszka
Quoted 20 lines · Alex Bligh
Jan,
Quoted 5 lines · Jan Kiszka
To my understanding, the use case behind the current behavior is
qemu_aio_wait()which is only supposed to block when there are pending requests for the main aio context. We should be able to address this scenarios also in a different way. I would definitely prefer to not depend on that hack above.I don't *think* so. If I'm right the problem is line 233 of
aio-posix.c(and similar in the windows variant):/* No AIO operations? Get us out of here */ if (!busy) { return progress; } ... do qemu_poll_ns ...Quoted 2 lines
busy is set to true if there are any FDs for which ->flush is true and ->io_flush() returns non-zero.
Right.
Quoted 6 lines
I think this should instead be looking the equivalent of
FD_ISSETacross all FDs (read and write) and the blocking flag. IE if blocking is set to true, then it should ALWAYS doqemu_poll_ns, lest it busyloop rather than wait for the next timer expiry.Yes, that would be needed.
Quoted 8 lines
More here:
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03950.htmlI'm not very happy with this logic (but it's the same as before), and I note Stefan removes the horrible busy flag in this series:
http://lists.nongnu.org/archive/html/qemu-devel/2013-07/msg00092.htmlYeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }
Quoted 1 line
So this is even worse for my use case.
We can change the semantics of aio_poll() so long as we don't break existing callers and tests. It would make sense to do that after merging the io_flush and AioContext timers series.
Stefan
Quoted 3 lines · Stefan Hajnoczi
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Whilst I think we should wait until your 'drop ioflush' stuff is merged, without doing an audit, I doubt there is any existing code which uses an AioContext with just its notifier fd, and is calls aio_poll with blocking=1. If there is, I doubt that code does anything useful :-)
Signature · 1 line
Alex Bligh
Quoted 7 lines · Alex Bligh
Quoted 3 lines · Stefan Hajnoczi
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Quoted 5 lines
Whilst I think we should wait until your 'drop ioflush' stuff is merged, without doing an audit, I doubt there is any existing code which uses an AioContext with just its notifier fd, and is calls
aio_pollwith blocking=1. If there is, I doubt that code does anything useful :-)
It would be great to have a use case for this upstream, maybe one that is less special than mine.
Ping Fan was talking about that he's working on the HPET. Decoupling it from our lousy iothread should improve its timer accuracy noticeably, maybe finally making it usable for Windows guest. On the other side, it's far from easy to disentangle its logic from the rest of a PC platform devices.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 7 lines · Alex Bligh
Quoted 3 lines · Stefan Hajnoczi
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Quoted 5 lines
Whilst I think we should wait until your 'drop ioflush' stuff is merged, without doing an audit, I doubt there is any existing code which uses an AioContext with just its notifier fd, and is calls
aio_pollwith blocking=1. If there is, I doubt that code does anything useful :-)
Yes, I think we need to merge the io_flush and AioTimers patch series when the QEMU 1.7 window opens so that development can progress without building up too many out-of-tree dependencies.
QEMU 1.6 should be released tomorrow or soon after. So I'll revisit these series so we can bring them into the block-next branch.
Stefan
Quoted 54 lines · Stefan Hajnoczi
Quoted 53 lines · Jan Kiszka
Quoted 20 lines · Alex Bligh
Jan,
Quoted 5 lines · Jan Kiszka
To my understanding, the use case behind the current behavior is
qemu_aio_wait()which is only supposed to block when there are pending requests for the main aio context. We should be able to address this scenarios also in a different way. I would definitely prefer to not depend on that hack above.I don't *think* so. If I'm right the problem is line 233 of
aio-posix.c(and similar in the windows variant):/* No AIO operations? Get us out of here */ if (!busy) { return progress; } ... do qemu_poll_ns ...Quoted 2 lines
busy is set to true if there are any FDs for which ->flush is true and ->io_flush() returns non-zero.
Right.
Quoted 6 lines
I think this should instead be looking the equivalent of
FD_ISSETacross all FDs (read and write) and the blocking flag. IE if blocking is set to true, then it should ALWAYS doqemu_poll_ns, lest it busyloop rather than wait for the next timer expiry.Yes, that would be needed.
Quoted 8 lines
More here:
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03950.htmlI'm not very happy with this logic (but it's the same as before), and I note Stefan removes the horrible busy flag in this series:
http://lists.nongnu.org/archive/html/qemu-devel/2013-07/msg00092.htmlYeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }
Quoted 5 lines
Quoted 1 line
So this is even worse for my use case.
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Need to pick up this topic again because above change is now mainline and breaks aio_poll-based timer threads:
How can we make progress with overcoming that check, at least for the timer thread use case? Additional argument "truly_block" for aio_poll?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Il 17/09/2013 18:09, Jan Kiszka ha scritto:
Quoted 17 lines · Stefan Hajnoczi
Quoted 10 lines · Jan Kiszka
Quoted 9 lines
Yeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }Quoted 5 lines
Quoted 1 line
So this is even worse for my use case.
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Quoted 5 lines
Need to pick up this topic again because above change is now mainline and breaks aio_poll-based timer threads:
How can we make progress with overcoming that check, at least for the timer thread use case? Additional argument "
truly_block" foraio_poll?
I wonder if we still need that "if" at all. Guys, do you remember what it is good for? O:-)
Paolo
Quoted 18 lines · Paolo Bonzini
Il 17/09/2013 18:09, Jan Kiszka ha scritto:
Quoted 17 lines · Stefan Hajnoczi
Quoted 15 lines · Jan Kiszka
Quoted 10 lines
Yeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }So this is even worse for my use case.
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.
Quoted 8 lines
Quoted 5 lines
Need to pick up this topic again because above change is now mainline and breaks aio_poll-based timer threads:
How can we make progress with overcoming that check, at least for the timer thread use case? Additional argument "
truly_block" foraio_poll?I wonder if we still need that "if" at all. Guys, do you remember what it is good for? O:-)
I can't remember whether the code above was in my patch or Stefan's subsequent ones, but I had suggested
if (blocking && (ctx->pollfds->len <= 1))
On reflection, I don't think the 'if' line should be there at all.
I think the argument was that it was meant to be for stupidity protection, i.e. where someone calls with blocking set to 1 and no fds, it would block indefinitely (if there were no timers) as it would select with no timeout and no fds.
Personally I think if you call things this way you deserve all you get. I'm not sure attempting to rescue the user by returning immediately is a great plan. If there are truly no fds at all (not even the notify fd) and an infinite timeout perhaps we should set the timeout to a second and log an error?
I presume the reason it's breaking aio_poll based timer threads is because there is only one fd (the aio_notify_fd), there are no other fd's, but there is a timeout (from the timers)? If that's true, I think we /shouldn't/ return. Equally if there are no timers but something is genuinely attempting to wait on an aio_notify, I don't think we should return.
Signature · 1 line
Alex Bligh
Quoted 47 lines · Alex Bligh
Quoted 18 lines · Paolo Bonzini
Il 17/09/2013 18:09, Jan Kiszka ha scritto:
Quoted 17 lines · Stefan Hajnoczi
Quoted 15 lines · Jan Kiszka
Quoted 10 lines
Yeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }So this is even worse for my use case.
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.Quoted 8 lines
Quoted 5 lines
Need to pick up this topic again because above change is now mainline and breaks aio_poll-based timer threads:
How can we make progress with overcoming that check, at least for the timer thread use case? Additional argument "
truly_block" foraio_poll?I wonder if we still need that "if" at all. Guys, do you remember what it is good for? O:-)
I can't remember whether the code above was in my patch or Stefan's subsequent ones, but I had suggested
if (blocking && (ctx->pollfds->len<= 1))On reflection, I don't think the 'if' line should be there at all.
I think the argument was that it was meant to be for stupidity protection, i.e. where someone calls with blocking set to 1 and no fds, it would block indefinitely (if there were no timers) as it would select with no timeout and no fds.
Personally I think if you call things this way you deserve all you get. I'm not sure attempting to rescue the user by returning immediately is a great plan. If there are truly no fds at all (not even the notify fd) and an infinite timeout perhaps we should set the timeout to a second and log an error?
Quoted 3 lines
I presume the reason it's breaking
aio_pollbased timer threads is because there is only one fd (theaio_notify_fd), there are no other fd's, but there is a timeout (from the timers)?
Right.
Quoted 5 lines
If
that's true, I think we /shouldn't/ return. Equally if there are no timers but something is genuinely attempting to wait on anaio_notify, I don't think we should return.
In any case, test-aio seems to stress that if clause. If we remove it, the test case hangs infinitely. But I'm more worried about understanding if there are actual users depending on the current behavior (bdrv_drain_all?).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 11 lines · Jan Kiszka
Quoted 6 lines
If
that's true, I think we /shouldn't/ return. Equally if there are no timers but something is genuinely attempting to wait on anaio_notify, I don't think we should return.In any case, test-aio seems to stress that if clause. If we remove it, the test case hangs infinitely. But I'm more worried about understanding if there are actual users depending on the current behavior (
bdrv_drain_all?).
That's in make check, so I think that will be Stefan's bdrv_drain* patches in combination with this, as the timer stuff definitely passed make check. I think I'll defer to Stefan on how bdrv_drain* is meant to work now as I think it had or was proposed to have major surgery after the timer patches went in.
Signature · 1 line
Alex Bligh
Il 17/09/2013 18:50, Jan Kiszka ha scritto:
Quoted 60 lines · Alex Bligh
Quoted 47 lines · Paolo Bonzini
Quoted 19 lines
Il 17/09/2013 18:09, Jan Kiszka ha scritto:
Quoted 17 lines · Stefan Hajnoczi
Quoted 15 lines · Jan Kiszka
Quoted 10 lines
Yeah:
(quoted diff) +2
-2- /* No AIO operations? Get us out of here */ - if (!busy) { + /* early return if we only have the aio_notify() fd */ + if (ctx->pollfds->len == 1) { return progress; }So this is even worse for my use case.
We can change the semantics of
aio_poll()so long as we don't break existing callers and tests. It would make sense to do that after merging theio_flushand AioContext timers series.Quoted 8 lines
Quoted 5 lines
Need to pick up this topic again because above change is now mainline and breaks aio_poll-based timer threads:
How can we make progress with overcoming that check, at least for the timer thread use case? Additional argument "
truly_block" foraio_poll?I wonder if we still need that "if" at all. Guys, do you remember what it is good for? O:-)
I can't remember whether the code above was in my patch or Stefan's subsequent ones, but I had suggested
if (blocking && (ctx->pollfds->len<= 1))On reflection, I don't think the 'if' line should be there at all.
I think the argument was that it was meant to be for stupidity protection, i.e. where someone calls with blocking set to 1 and no fds, it would block indefinitely (if there were no timers) as it would select with no timeout and no fds.
Personally I think if you call things this way you deserve all you get. I'm not sure attempting to rescue the user by returning immediately is a great plan. If there are truly no fds at all (not even the notify fd) and an infinite timeout perhaps we should set the timeout to a second and log an error?
Quoted 3 lines
I presume the reason it's breaking
aio_pollbased timer threads is because there is only one fd (theaio_notify_fd), there are no other fd's, but there is a timeout (from the timers)?Right.
Quoted 5 lines
If
that's true, I think we /shouldn't/ return. Equally if there are no timers but something is genuinely attempting to wait on anaio_notify, I don't think we should return.
Quoted 4 lines
In any case, test-aio seems to stress that if clause. If we remove it, the test case hangs infinitely. But I'm more worried about understanding if there are actual users depending on the current behavior (
bdrv_drain_all?).
Yes, bdrv_drain_all comes to mind. But now we should be able to fix this old remark:
/* FIXME: We do not have timer support here, so this is effectively
* a busy wait.
*/
QTAILQ_FOREACH(bs, &bdrv_states, list) {
if (bdrv_start_throttled_reqs(bs)) {
busy = true;
}
}
busy = bdrv_requests_pending_all();
busy |= aio_poll(qemu_get_aio_context(), busy);Alex, what's missing before block.c and QED can use aio_timer_new on the main AioContext, instead of timer_new?
Paolo
Quoted 2 lines · Paolo Bonzini
Alex, what's missing before
block.cand QED can useaio_timer_newon the main AioContext, instead oftimer_new?
If we assume at this stage the threading is no different, very little I think. Off the top of my head it should be a case of:
1. Audit timer routines to ensure they are safe to call from inside aio_poll rather than mainloop. EG if there is a timer routine that itself calls aio_poll, that would presumably be bad. A quick check suggests we need to think about the coroutine stuff carefully here if we don't want recursion.
2. Replace timer_new by aio_timer_new
3. Cross fingers and hope for the best.
I think block/iscsi.c needs doing too.
If we're worried about threading changes, then I'm not sure how much of the thread safety stuff has been pulled to master, plus someone needs to audit thread safety for use_icount=1.
Signature · 1 line
Alex Bligh
Il 17/09/2013 19:32, Alex Bligh ha scritto:
Quoted 15 lines · Paolo Bonzini
Quoted 3 lines
Alex, what's missing before
block.cand QED can useaio_timer_newon the main AioContext, instead oftimer_new?If we assume at this stage the threading is no different, very little I think. Off the top of my head it should be a case of:
1. Audit timer routines to ensure they are safe to call from inside
aio_pollrather than mainloop. EG if there is a timer routine that itself callsaio_poll, that would presumably be bad. A quick check suggests we need to think about the coroutine stuff carefully here if we don't want recursion.
Quoted 3 lines
2. Replace
timer_newbyaio_timer_new3. Cross fingers and hope for the best.
Yes, that was my understanding too. Can we do it for 1.7?
Quoted 5 lines
I think
block/iscsi.cneeds doing too.If we're worried about threading changes, then I'm not sure how much of the thread safety stuff has been pulled to master, plus someone needs to audit thread safety for use_icount=1.
Nothing has. use_icount=1 is still on my todo list.
Paolo
Paolo,
Quoted 16 lines · Paolo Bonzini
Il 17/09/2013 19:32, Alex Bligh ha scritto:
Quoted 15 lines · Paolo Bonzini
Quoted 3 lines
Alex, what's missing before
block.cand QED can useaio_timer_newon the main AioContext, instead oftimer_new?If we assume at this stage the threading is no different, very little I think. Off the top of my head it should be a case of:
1. Audit timer routines to ensure they are safe to call from inside
aio_pollrather than mainloop. EG if there is a timer routine that itself callsaio_poll, that would presumably be bad. A quick check suggests we need to think about the coroutine stuff carefully here if we don't want recursion.
Quoted 5 lines
Quoted 3 lines
2. Replace
timer_newbyaio_timer_new3. Cross fingers and hope for the best.
Yes, that was my understanding too. Can we do it for 1.7?
Don't see why not. I'd need to immerse myself in coroutines and understand how they all work and am off on vacation for a week tomorrow, so someone else (Stefan?) may be able to do it faster than me. I expect it's just a case of saying "yup, that will work" for someone who knows the co-routine call-graph. If not, I'll have a look at it on my return.
Quoted 7 lines
Quoted 5 lines
I think
block/iscsi.cneeds doing too.If we're worried about threading changes, then I'm not sure how much of the thread safety stuff has been pulled to master, plus someone needs to audit thread safety for use_icount=1.
Nothing has. use_icount=1 is still on my todo list.
Rather you than me!
Signature · 1 line
Alex Bligh
Paolo,
Quoted 1 line · Alex Bligh
Quoted 1 line
Yes, that was my understanding too. Can we do it for 1.7?
Whilst we are changing the calling semantics, do you think qemu_coroutine_yield() should also run the timers for the aio_context? IE should timers always be deferred to the next qemu_aio_wait() / aio_poll(), or should we make it so they can run whenever there is a 'schedule' between coroutines?
I suspect making the change would be trivial. Its implications might not be.
Signature · 1 line
Alex Bligh
Il 18/09/2013 11:02, Alex Bligh ha scritto:
Quoted 4 lines
Paolo,
On 18 Sep 2013, at 09:23, Alex Bligh wrote:
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Yes, that was my understanding too. Can we do it for 1.7?
Whilst we are changing the calling semantics, do you think
qemu_coroutine_yield()should also run the timers for theaio_context? IE should timers always be deferred to the nextqemu_aio_wait()/aio_poll(), or should we make it so they can run whenever there is a 'schedule' between coroutines?
No, they should be left for the next aio_poll().
Quoted 2 lines
I suspect making the change would be trivial. Its implications might not be.
Yes, they would not. :)
Paolo
Quoted 7 lines · Paolo Bonzini
Il 18/09/2013 11:02, Alex Bligh ha scritto:
Quoted 6 lines
Paolo,
Quoted 1 line · Alex Bligh
Quoted 1 line
Yes, that was my understanding too. Can we do it for 1.7?
Quoted 8 lines
Quoted 6 lines
Whilst we are changing the calling semantics, do you think
qemu_coroutine_yield()should also run the timers for theaio_context? IE should timers always be deferred to the nextqemu_aio_wait()/aio_poll(), or should we make it so they can run whenever there is a 'schedule' between coroutines?No, they should be left for the next
aio_poll().
I agree. Besides the side-effects, I want to avoid coupling coroutines too deeply with event loop entities like timers. They should not know about each other.
Stefan
Quoted 24 lines · Alex Bligh
Paolo,
Quoted 20 lines · Paolo Bonzini
Il 17/09/2013 19:32, Alex Bligh ha scritto:
Quoted 18 lines · Paolo Bonzini
Quoted 3 lines
Alex, what's missing before
block.cand QED can useaio_timer_newon the main AioContext, instead oftimer_new?If we assume at this stage the threading is no different, very little I think. Off the top of my head it should be a case of:
1. Audit timer routines to ensure they are safe to call from inside
aio_pollrather than mainloop. EG if there is a timer routine that itself callsaio_poll, that would presumably be bad. A quick check suggests we need to think about the coroutine stuff carefully here if we don't want recursion.2. Replace
timer_newbyaio_timer_new3. Cross fingers and hope for the best.
Quoted 8 lines
Quoted 1 line
Yes, that was my understanding too. Can we do it for 1.7?
Don't see why not. I'd need to immerse myself in coroutines and understand how they all work and am off on vacation for a week tomorrow, so someone else (Stefan?) may be able to do it faster than me. I expect it's just a case of saying "yup, that will work" for someone who knows the co-routine call-graph. If not, I'll have a look at it on my return.
Sorry I wasn't following this thread. But I will put together patches to convert existing block layer timers to use AioContext timers and finally let drain work without spinning.
Stefan
Quoted 42 lines · Alex Bligh
[ This patch set is available from git at:
https://github.com/abligh/qemu/tree/aio-timers10
As autogenerated patch 30 of the series is too large for the mailing list. ]This patch series adds support for timers attached to an AioContext clock which get called within
aio_poll.In doing so it removes alarm timers and moves to use ppoll where possible.
This patch set 'sort of' passes make check (see below for caveat) including a new test harness for the aio timers, but has not been tested much beyond that. In particular, the win32 changes have not even been compile tested. Equally, alterations to
use_icountare untested.Caveat: I have had to alter
tests/test-aio.cso the following error no longer occurs.ERROR:tests/test-aio.c:346:test_wait_event_notifier_noflush: assertion failed: (
aio_poll(ctx, false))As gar as I can tell, this check was incorrect, in that it checking
aio_pollmakes progress when in fact it should not make progress. I fixed an issue whereaio_pollwas (as far as I can tell) wrongly returning true on a timeout, and that generated this error.Note also the comment on patch 19 in relation to a possible bug in
cpus.c.The penultimate patch is patch which is created in an automated manner using
scripts/switch-timer-api, added in this patch set. It violates some coding standards (e.g. line length >= 80 characters), but this is preferable in terms of giving a provably correct conversion. This patch is too large for the mailing list, soEITHER: get it from git at the URL at the top of this message.
OR: Do the following:
1. Apply patches 0000-0029 inclusive
2. Runscripts/switch-timer-api
3. git commit -a (+ suitable commit message)
4. Apply patch 0031
Quoted 6 lines
If there is demand I can split it one commit per file.
This patch set has been compile tested & make check tested on a 'christmas-tree' configuration, meaning a configuration with every --enable-* value tested that can be easily configured on Ubuntu Precise, after application of each patch.
This is looking pretty good. Jan, Ping Fan, and I have already worked on top of this series. I'd like to merge it soon.
Are you ready to roll v11?
Stefan
Quoted 4 lines · Stefan Hajnoczi
This is looking pretty good. Jan, Ping Fan, and I have already worked on top of this series. I'd like to merge it soon.
Are you ready to roll v11?
The only things I have queued for v11 are:
* Disentangle typedef struct vs struct in header files
* (Possibly) delete spurious cap on timeout in cpus.c (see thread on patch 19).
If no one has any other comments, I will roll v11 either tonight or tomorrow.
Signature · 1 line
Alex Bligh