s390x/cpumodel: fix segmentation fault when baselining models
[qemu/ar7.git] / tests / ptimer-test-stubs.c
blobca5cc3b13bb3e5bcc22c3b42244f0685c2906384
1 /*
2 * Stubs for the ptimer-test
4 * Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 */
11 #include "qemu/osdep.h"
12 #include "qemu/main-loop.h"
13 #include "sysemu/replay.h"
14 #include "migration/vmstate.h"
16 #include "ptimer-test.h"
18 const VMStateInfo vmstate_info_uint8;
19 const VMStateInfo vmstate_info_uint32;
20 const VMStateInfo vmstate_info_uint64;
21 const VMStateInfo vmstate_info_int64;
22 const VMStateInfo vmstate_info_timer;
24 struct QEMUBH {
25 QEMUBHFunc *cb;
26 void *opaque;
29 QEMUTimerListGroup main_loop_tlg;
31 int64_t ptimer_test_time_ns;
33 /* Do not artificially limit period - see hw/core/ptimer.c. */
34 int use_icount = 1;
35 bool qtest_allowed;
37 void timer_init_tl(QEMUTimer *ts,
38 QEMUTimerList *timer_list, int scale,
39 QEMUTimerCB *cb, void *opaque)
41 ts->timer_list = timer_list;
42 ts->cb = cb;
43 ts->opaque = opaque;
44 ts->scale = scale;
45 ts->expire_time = -1;
48 void timer_mod(QEMUTimer *ts, int64_t expire_time)
50 QEMUTimerList *timer_list = ts->timer_list;
51 QEMUTimer *t = &timer_list->active_timers;
53 while (t->next != NULL) {
54 if (t->next == ts) {
55 break;
58 t = t->next;
61 ts->expire_time = MAX(expire_time * ts->scale, 0);
62 ts->next = NULL;
63 t->next = ts;
66 void timer_del(QEMUTimer *ts)
68 QEMUTimerList *timer_list = ts->timer_list;
69 QEMUTimer *t = &timer_list->active_timers;
71 while (t->next != NULL) {
72 if (t->next == ts) {
73 t->next = ts->next;
74 return;
77 t = t->next;
81 int64_t qemu_clock_get_ns(QEMUClockType type)
83 return ptimer_test_time_ns;
86 int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
88 QEMUTimerList *timer_list = main_loop_tlg.tl[type];
89 QEMUTimer *t = timer_list->active_timers.next;
90 int64_t deadline = -1;
92 while (t != NULL) {
93 if (deadline == -1) {
94 deadline = t->expire_time;
95 } else {
96 deadline = MIN(deadline, t->expire_time);
99 t = t->next;
102 return deadline;
105 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
107 QEMUBH *bh = g_new(QEMUBH, 1);
109 bh->cb = cb;
110 bh->opaque = opaque;
112 return bh;
115 void qemu_bh_delete(QEMUBH *bh)
117 g_free(bh);
120 void replay_bh_schedule_event(QEMUBH *bh)
122 bh->cb(bh->opaque);