2016-09-22 20:13:07 +03:00
|
|
|
/*
|
|
|
|
* Stubs for the ptimer-test
|
|
|
|
*
|
2016-10-24 18:26:53 +03:00
|
|
|
* Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com>
|
2016-09-22 20:13:07 +03:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/main-loop.h"
|
|
|
|
#include "sysemu/replay.h"
|
2016-10-17 21:22:17 +03:00
|
|
|
#include "migration/vmstate.h"
|
2016-09-22 20:13:07 +03:00
|
|
|
|
|
|
|
#include "ptimer-test.h"
|
|
|
|
|
2016-10-17 21:22:17 +03:00
|
|
|
const VMStateInfo vmstate_info_uint8;
|
|
|
|
const VMStateInfo vmstate_info_uint32;
|
|
|
|
const VMStateInfo vmstate_info_uint64;
|
|
|
|
const VMStateInfo vmstate_info_int64;
|
|
|
|
const VMStateInfo vmstate_info_timer;
|
|
|
|
|
2016-09-22 20:13:07 +03:00
|
|
|
struct QEMUBH {
|
|
|
|
QEMUBHFunc *cb;
|
|
|
|
void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
QEMUTimerListGroup main_loop_tlg;
|
|
|
|
|
|
|
|
int64_t ptimer_test_time_ns;
|
|
|
|
|
2020-08-19 14:17:19 +03:00
|
|
|
/* under qtest_enabled(), will not artificially limit period - see hw/core/ptimer.c. */
|
|
|
|
int use_icount;
|
2017-09-19 17:18:42 +03:00
|
|
|
bool qtest_allowed;
|
|
|
|
|
2018-10-17 11:24:19 +03:00
|
|
|
void timer_init_full(QEMUTimer *ts,
|
|
|
|
QEMUTimerListGroup *timer_list_group, QEMUClockType type,
|
|
|
|
int scale, int attributes,
|
|
|
|
QEMUTimerCB *cb, void *opaque)
|
2016-09-22 20:13:07 +03:00
|
|
|
{
|
2018-10-17 11:24:19 +03:00
|
|
|
if (!timer_list_group) {
|
|
|
|
timer_list_group = &main_loop_tlg;
|
|
|
|
}
|
|
|
|
ts->timer_list = timer_list_group->tl[type];
|
2016-09-22 20:13:07 +03:00
|
|
|
ts->cb = cb;
|
|
|
|
ts->opaque = opaque;
|
|
|
|
ts->scale = scale;
|
2018-10-17 11:24:19 +03:00
|
|
|
ts->attributes = attributes;
|
2016-09-22 20:13:07 +03:00
|
|
|
ts->expire_time = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_mod(QEMUTimer *ts, int64_t expire_time)
|
|
|
|
{
|
|
|
|
QEMUTimerList *timer_list = ts->timer_list;
|
|
|
|
QEMUTimer *t = &timer_list->active_timers;
|
|
|
|
|
|
|
|
while (t->next != NULL) {
|
|
|
|
if (t->next == ts) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts->expire_time = MAX(expire_time * ts->scale, 0);
|
|
|
|
ts->next = NULL;
|
|
|
|
t->next = ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_del(QEMUTimer *ts)
|
|
|
|
{
|
|
|
|
QEMUTimerList *timer_list = ts->timer_list;
|
|
|
|
QEMUTimer *t = &timer_list->active_timers;
|
|
|
|
|
|
|
|
while (t->next != NULL) {
|
|
|
|
if (t->next == ts) {
|
|
|
|
t->next = ts->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t qemu_clock_get_ns(QEMUClockType type)
|
|
|
|
{
|
|
|
|
return ptimer_test_time_ns;
|
|
|
|
}
|
|
|
|
|
2019-07-25 11:44:26 +03:00
|
|
|
int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
|
2016-09-22 20:13:07 +03:00
|
|
|
{
|
2019-07-25 11:44:26 +03:00
|
|
|
QEMUTimerList *timer_list = main_loop_tlg.tl[QEMU_CLOCK_VIRTUAL];
|
2016-09-22 20:13:07 +03:00
|
|
|
QEMUTimer *t = timer_list->active_timers.next;
|
|
|
|
int64_t deadline = -1;
|
|
|
|
|
|
|
|
while (t != NULL) {
|
|
|
|
if (deadline == -1) {
|
|
|
|
deadline = t->expire_time;
|
|
|
|
} else {
|
|
|
|
deadline = MIN(deadline, t->expire_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return deadline;
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:02:46 +03:00
|
|
|
QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
|
2016-09-22 20:13:07 +03:00
|
|
|
{
|
|
|
|
QEMUBH *bh = g_new(QEMUBH, 1);
|
|
|
|
|
|
|
|
bh->cb = cb;
|
|
|
|
bh->opaque = opaque;
|
|
|
|
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
|
2017-01-27 11:55:51 +03:00
|
|
|
void qemu_bh_delete(QEMUBH *bh)
|
|
|
|
{
|
|
|
|
g_free(bh);
|
|
|
|
}
|