From 740b175973427bcfa32ad894bb1f83b96d184c28 Mon Sep 17 00:00:00 2001 From: Claudio Fontana Date: Wed, 19 Aug 2020 13:17:19 +0200 Subject: cpu-timers, icount: new modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactoring of cpus.c continues with cpu timer state extraction. cpu-timers: responsible for the softmmu cpu timers state, including cpu clocks and ticks. icount: counts the TCG instructions executed. As such it is specific to the TCG accelerator. Therefore, it is built only under CONFIG_TCG. One complication is due to qtest, which uses an icount field to warp time as part of qtest (qtest_clock_warp). In order to solve this problem, provide a separate counter for qtest. This requires fixing assumptions scattered in the code that qtest_enabled() implies icount_enabled(), checking each specific case. Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson [remove redundant initialization with qemu_spice_init] Reviewed-by: Alex Bennée [fix lingering calls to icount_get] Signed-off-by: Claudio Fontana Signed-off-by: Paolo Bonzini --- util/main-loop.c | 12 ++++++++---- util/qemu-timer.c | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'util') diff --git a/util/main-loop.c b/util/main-loop.c index 217c8d6..0c5fe01 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -27,7 +27,7 @@ #include "qemu/cutils.h" #include "qemu/timer.h" #include "sysemu/qtest.h" -#include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" #include "qemu/main-loop.h" #include "block/aio.h" @@ -521,9 +521,13 @@ void main_loop_wait(int nonblocking) mlpoll.state = ret < 0 ? MAIN_LOOP_POLL_ERR : MAIN_LOOP_POLL_OK; notifier_list_notify(&main_loop_poll_notifiers, &mlpoll); - /* CPU thread can infinitely wait for event after - missing the warp */ - qemu_start_warp_timer(); + if (icount_enabled()) { + /* + * CPU thread can infinitely wait for event after + * missing the warp + */ + qemu_start_warp_timer(); + } qemu_clock_run_all_timers(); } diff --git a/util/qemu-timer.c b/util/qemu-timer.c index ca67783..0674046 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -26,8 +26,10 @@ #include "qemu/main-loop.h" #include "qemu/timer.h" #include "qemu/lockable.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" #include "sysemu/cpus.h" +#include "sysemu/qtest.h" #ifdef CONFIG_POSIX #include @@ -134,7 +136,7 @@ static void qemu_clock_init(QEMUClockType type, QEMUTimerListNotifyCB *notify_cb bool qemu_clock_use_for_deadline(QEMUClockType type) { - return !(use_icount && (type == QEMU_CLOCK_VIRTUAL)); + return !(icount_enabled() && (type == QEMU_CLOCK_VIRTUAL)); } void qemu_clock_notify(QEMUClockType type) @@ -416,7 +418,7 @@ static bool timer_mod_ns_locked(QEMUTimerList *timer_list, static void timerlist_rearm(QEMUTimerList *timer_list) { /* Interrupt execution to force deadline recalculation. */ - if (timer_list->clock->type == QEMU_CLOCK_VIRTUAL) { + if (icount_enabled() && timer_list->clock->type == QEMU_CLOCK_VIRTUAL) { qemu_start_warp_timer(); } timerlist_notify(timer_list); @@ -633,8 +635,10 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return get_clock(); default: case QEMU_CLOCK_VIRTUAL: - if (use_icount) { + if (icount_enabled()) { return cpu_get_icount(); + } else if (qtest_enabled()) { /* for qtest_clock_warp */ + return qtest_get_virtual_clock(); } else { return cpu_get_clock(); } -- cgit v1.1 From 8191d3684157884bf7e6eff0d247d7e91a1cc543 Mon Sep 17 00:00:00 2001 From: Claudio Fontana Date: Mon, 31 Aug 2020 16:18:34 +0200 Subject: icount: rename functions to be consistent with the module name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Paolo Bonzini --- util/main-loop.c | 2 +- util/qemu-timer.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/main-loop.c b/util/main-loop.c index 0c5fe01..6470f8e 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -526,7 +526,7 @@ void main_loop_wait(int nonblocking) * CPU thread can infinitely wait for event after * missing the warp */ - qemu_start_warp_timer(); + icount_start_warp_timer(); } qemu_clock_run_all_timers(); } diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 0674046..b69c6bb 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -419,7 +419,7 @@ static void timerlist_rearm(QEMUTimerList *timer_list) { /* Interrupt execution to force deadline recalculation. */ if (icount_enabled() && timer_list->clock->type == QEMU_CLOCK_VIRTUAL) { - qemu_start_warp_timer(); + icount_start_warp_timer(); } timerlist_notify(timer_list); } @@ -636,7 +636,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type) default: case QEMU_CLOCK_VIRTUAL: if (icount_enabled()) { - return cpu_get_icount(); + return icount_get(); } else if (qtest_enabled()) { /* for qtest_clock_warp */ return qtest_get_virtual_clock(); } else { -- cgit v1.1 From 430065dab060f04a74f915ea1260dcc79701ca75 Mon Sep 17 00:00:00 2001 From: Claudio Fontana Date: Fri, 31 Jul 2020 12:23:42 +0200 Subject: cpus: prepare new CpusAccel cpu accelerator interface The new interface starts unused, will start being used by the next patches. It provides methods for each accelerator to start a vcpu, kick a vcpu, synchronize state, get cpu virtual clock and elapsed ticks. In qemu_wait_io_event, make it clear that APC is used only for HAX on Windows. Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- util/qemu-timer.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'util') diff --git a/util/qemu-timer.c b/util/qemu-timer.c index b69c6bb..81c28af 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -635,13 +635,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return get_clock(); default: case QEMU_CLOCK_VIRTUAL: - if (icount_enabled()) { - return icount_get(); - } else if (qtest_enabled()) { /* for qtest_clock_warp */ - return qtest_get_virtual_clock(); - } else { - return cpu_get_clock(); - } + return cpus_get_virtual_clock(); case QEMU_CLOCK_HOST: return REPLAY_CLOCK(REPLAY_CLOCK_HOST, get_clock_realtime()); case QEMU_CLOCK_VIRTUAL_RT: -- cgit v1.1