cpu-timers, icount: new modules

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 <cfontana@suse.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
[remove redundant initialization with qemu_spice_init]
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
[fix lingering calls to icount_get]
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Claudio Fontana 2020-08-19 13:17:19 +02:00 committed by Paolo Bonzini
parent 0ac0b47c44
commit 740b175973
37 changed files with 1128 additions and 843 deletions

View file

@ -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();
}

View file

@ -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 <pthread.h>
@ -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();
}