]>
Commit | Line | Data |
---|---|---|
5b262bb6 DO |
1 | /* |
2 | * Stubs for the ptimer-test | |
3 | * | |
673c7e89 | 4 | * Copyright (c) 2016 Dmitry Osipenko <[email protected]> |
5b262bb6 DO |
5 | * |
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. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include "qemu/osdep.h" | |
12 | #include "qemu/main-loop.h" | |
13 | #include "sysemu/replay.h" | |
24b94625 | 14 | #include "migration/vmstate.h" |
5b262bb6 DO |
15 | |
16 | #include "ptimer-test.h" | |
17 | ||
24b94625 PB |
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; | |
23 | ||
5b262bb6 DO |
24 | struct QEMUBH { |
25 | QEMUBHFunc *cb; | |
26 | void *opaque; | |
27 | }; | |
28 | ||
29 | QEMUTimerListGroup main_loop_tlg; | |
30 | ||
31 | int64_t ptimer_test_time_ns; | |
32 | ||
9ee24e98 PB |
33 | /* Do not artificially limit period - see hw/core/ptimer.c. */ |
34 | int use_icount = 1; | |
35 | bool qtest_allowed; | |
36 | ||
89a603a0 AP |
37 | void timer_init_full(QEMUTimer *ts, |
38 | QEMUTimerListGroup *timer_list_group, QEMUClockType type, | |
39 | int scale, int attributes, | |
40 | QEMUTimerCB *cb, void *opaque) | |
5b262bb6 | 41 | { |
89a603a0 AP |
42 | if (!timer_list_group) { |
43 | timer_list_group = &main_loop_tlg; | |
44 | } | |
45 | ts->timer_list = timer_list_group->tl[type]; | |
5b262bb6 DO |
46 | ts->cb = cb; |
47 | ts->opaque = opaque; | |
48 | ts->scale = scale; | |
89a603a0 | 49 | ts->attributes = attributes; |
5b262bb6 DO |
50 | ts->expire_time = -1; |
51 | } | |
52 | ||
53 | void timer_mod(QEMUTimer *ts, int64_t expire_time) | |
54 | { | |
55 | QEMUTimerList *timer_list = ts->timer_list; | |
56 | QEMUTimer *t = &timer_list->active_timers; | |
57 | ||
58 | while (t->next != NULL) { | |
59 | if (t->next == ts) { | |
60 | break; | |
61 | } | |
62 | ||
63 | t = t->next; | |
64 | } | |
65 | ||
66 | ts->expire_time = MAX(expire_time * ts->scale, 0); | |
67 | ts->next = NULL; | |
68 | t->next = ts; | |
69 | } | |
70 | ||
71 | void timer_del(QEMUTimer *ts) | |
72 | { | |
73 | QEMUTimerList *timer_list = ts->timer_list; | |
74 | QEMUTimer *t = &timer_list->active_timers; | |
75 | ||
76 | while (t->next != NULL) { | |
77 | if (t->next == ts) { | |
78 | t->next = ts->next; | |
79 | return; | |
80 | } | |
81 | ||
82 | t = t->next; | |
83 | } | |
84 | } | |
85 | ||
86 | int64_t qemu_clock_get_ns(QEMUClockType type) | |
87 | { | |
88 | return ptimer_test_time_ns; | |
89 | } | |
90 | ||
91 | int64_t qemu_clock_deadline_ns_all(QEMUClockType type) | |
92 | { | |
93 | QEMUTimerList *timer_list = main_loop_tlg.tl[type]; | |
94 | QEMUTimer *t = timer_list->active_timers.next; | |
95 | int64_t deadline = -1; | |
96 | ||
97 | while (t != NULL) { | |
98 | if (deadline == -1) { | |
99 | deadline = t->expire_time; | |
100 | } else { | |
101 | deadline = MIN(deadline, t->expire_time); | |
102 | } | |
103 | ||
104 | t = t->next; | |
105 | } | |
106 | ||
107 | return deadline; | |
108 | } | |
109 | ||
110 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | |
111 | { | |
112 | QEMUBH *bh = g_new(QEMUBH, 1); | |
113 | ||
114 | bh->cb = cb; | |
115 | bh->opaque = opaque; | |
116 | ||
117 | return bh; | |
118 | } | |
119 | ||
072bdb07 MAL |
120 | void qemu_bh_delete(QEMUBH *bh) |
121 | { | |
122 | g_free(bh); | |
123 | } | |
124 | ||
5b262bb6 DO |
125 | void replay_bh_schedule_event(QEMUBH *bh) |
126 | { | |
127 | bh->cb(bh->opaque); | |
128 | } |