1
2
3
4
5
6
7
8
9
10
11#include "qemu/osdep.h"
12#include "qemu/main-loop.h"
13#include "sysemu/replay.h"
14#include "migration/vmstate.h"
15#include "sysemu/cpu-timers.h"
16
17#include "ptimer-test.h"
18
19const VMStateInfo vmstate_info_uint8;
20const VMStateInfo vmstate_info_uint32;
21const VMStateInfo vmstate_info_uint64;
22const VMStateInfo vmstate_info_int64;
23const VMStateInfo vmstate_info_timer;
24
25struct QEMUBH {
26 QEMUBHFunc *cb;
27 void *opaque;
28};
29
30QEMUTimerListGroup main_loop_tlg;
31
32int64_t ptimer_test_time_ns;
33
34
35int use_icount;
36bool qtest_allowed;
37
38void timer_init_full(QEMUTimer *ts,
39 QEMUTimerListGroup *timer_list_group, QEMUClockType type,
40 int scale, int attributes,
41 QEMUTimerCB *cb, void *opaque)
42{
43 if (!timer_list_group) {
44 timer_list_group = &main_loop_tlg;
45 }
46 ts->timer_list = timer_list_group->tl[type];
47 ts->cb = cb;
48 ts->opaque = opaque;
49 ts->scale = scale;
50 ts->attributes = attributes;
51 ts->expire_time = -1;
52}
53
54void timer_mod(QEMUTimer *ts, int64_t expire_time)
55{
56 QEMUTimerList *timer_list = ts->timer_list;
57 QEMUTimer *t = &timer_list->active_timers;
58
59 while (t->next != NULL) {
60 if (t->next == ts) {
61 break;
62 }
63
64 t = t->next;
65 }
66
67 ts->expire_time = MAX(expire_time * ts->scale, 0);
68 ts->next = NULL;
69 t->next = ts;
70}
71
72void timer_del(QEMUTimer *ts)
73{
74 QEMUTimerList *timer_list = ts->timer_list;
75 QEMUTimer *t = &timer_list->active_timers;
76
77 while (t->next != NULL) {
78 if (t->next == ts) {
79 t->next = ts->next;
80 return;
81 }
82
83 t = t->next;
84 }
85}
86
87int64_t qemu_clock_get_ns(QEMUClockType type)
88{
89 return ptimer_test_time_ns;
90}
91
92int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
93{
94 QEMUTimerList *timer_list = main_loop_tlg.tl[QEMU_CLOCK_VIRTUAL];
95 QEMUTimer *t = timer_list->active_timers.next;
96 int64_t deadline = -1;
97
98 while (t != NULL) {
99 if (deadline == -1) {
100 deadline = t->expire_time;
101 } else {
102 deadline = MIN(deadline, t->expire_time);
103 }
104
105 t = t->next;
106 }
107
108 return deadline;
109}
110
111QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
112{
113 QEMUBH *bh = g_new(QEMUBH, 1);
114
115 bh->cb = cb;
116 bh->opaque = opaque;
117
118 return bh;
119}
120
121void qemu_bh_delete(QEMUBH *bh)
122{
123 g_free(bh);
124}
125