xref: /openbmc/qemu/tests/unit/ptimer-test-stubs.c (revision 9c86c97f)
1da668aa1SThomas Huth /*
2da668aa1SThomas Huth  * Stubs for the ptimer-test
3da668aa1SThomas Huth  *
4da668aa1SThomas Huth  * Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com>
5da668aa1SThomas Huth  *
6da668aa1SThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7da668aa1SThomas Huth  * See the COPYING file in the top-level directory.
8da668aa1SThomas Huth  *
9da668aa1SThomas Huth  */
10da668aa1SThomas Huth 
11da668aa1SThomas Huth #include "qemu/osdep.h"
12da668aa1SThomas Huth #include "qemu/main-loop.h"
135b5968c4SPhilippe Mathieu-Daudé #include "exec/replay-core.h"
14da668aa1SThomas Huth #include "migration/vmstate.h"
15da668aa1SThomas Huth 
16da668aa1SThomas Huth #include "ptimer-test.h"
17da668aa1SThomas Huth 
18da668aa1SThomas Huth const VMStateInfo vmstate_info_uint8;
19da668aa1SThomas Huth const VMStateInfo vmstate_info_uint32;
20da668aa1SThomas Huth const VMStateInfo vmstate_info_uint64;
21da668aa1SThomas Huth const VMStateInfo vmstate_info_int64;
22da668aa1SThomas Huth const VMStateInfo vmstate_info_timer;
23da668aa1SThomas Huth 
24da668aa1SThomas Huth struct QEMUBH {
25da668aa1SThomas Huth     QEMUBHFunc *cb;
26da668aa1SThomas Huth     void *opaque;
27da668aa1SThomas Huth };
28da668aa1SThomas Huth 
29da668aa1SThomas Huth QEMUTimerListGroup main_loop_tlg;
30da668aa1SThomas Huth 
31da668aa1SThomas Huth int64_t ptimer_test_time_ns;
32da668aa1SThomas Huth 
33da668aa1SThomas Huth /* under qtest_enabled(), will not artificially limit period - see hw/core/ptimer.c. */
34da668aa1SThomas Huth int use_icount;
35da668aa1SThomas Huth bool qtest_allowed;
36da668aa1SThomas Huth 
timer_init_full(QEMUTimer * ts,QEMUTimerListGroup * timer_list_group,QEMUClockType type,int scale,int attributes,QEMUTimerCB * cb,void * opaque)37da668aa1SThomas Huth void timer_init_full(QEMUTimer *ts,
38da668aa1SThomas Huth                      QEMUTimerListGroup *timer_list_group, QEMUClockType type,
39da668aa1SThomas Huth                      int scale, int attributes,
40da668aa1SThomas Huth                      QEMUTimerCB *cb, void *opaque)
41da668aa1SThomas Huth {
42da668aa1SThomas Huth     if (!timer_list_group) {
43da668aa1SThomas Huth         timer_list_group = &main_loop_tlg;
44da668aa1SThomas Huth     }
45da668aa1SThomas Huth     ts->timer_list = timer_list_group->tl[type];
46da668aa1SThomas Huth     ts->cb = cb;
47da668aa1SThomas Huth     ts->opaque = opaque;
48da668aa1SThomas Huth     ts->scale = scale;
49da668aa1SThomas Huth     ts->attributes = attributes;
50da668aa1SThomas Huth     ts->expire_time = -1;
51da668aa1SThomas Huth }
52da668aa1SThomas Huth 
timer_mod(QEMUTimer * ts,int64_t expire_time)53da668aa1SThomas Huth void timer_mod(QEMUTimer *ts, int64_t expire_time)
54da668aa1SThomas Huth {
55da668aa1SThomas Huth     QEMUTimerList *timer_list = ts->timer_list;
56da668aa1SThomas Huth     QEMUTimer *t = &timer_list->active_timers;
57da668aa1SThomas Huth 
58da668aa1SThomas Huth     while (t->next != NULL) {
59da668aa1SThomas Huth         if (t->next == ts) {
60da668aa1SThomas Huth             break;
61da668aa1SThomas Huth         }
62da668aa1SThomas Huth 
63da668aa1SThomas Huth         t = t->next;
64da668aa1SThomas Huth     }
65da668aa1SThomas Huth 
66da668aa1SThomas Huth     ts->expire_time = MAX(expire_time * ts->scale, 0);
67da668aa1SThomas Huth     ts->next = NULL;
68da668aa1SThomas Huth     t->next = ts;
69da668aa1SThomas Huth }
70da668aa1SThomas Huth 
timer_del(QEMUTimer * ts)71da668aa1SThomas Huth void timer_del(QEMUTimer *ts)
72da668aa1SThomas Huth {
73da668aa1SThomas Huth     QEMUTimerList *timer_list = ts->timer_list;
74da668aa1SThomas Huth     QEMUTimer *t = &timer_list->active_timers;
75da668aa1SThomas Huth 
76da668aa1SThomas Huth     while (t->next != NULL) {
77da668aa1SThomas Huth         if (t->next == ts) {
78da668aa1SThomas Huth             t->next = ts->next;
79da668aa1SThomas Huth             return;
80da668aa1SThomas Huth         }
81da668aa1SThomas Huth 
82da668aa1SThomas Huth         t = t->next;
83da668aa1SThomas Huth     }
84da668aa1SThomas Huth }
85da668aa1SThomas Huth 
qemu_clock_get_ns(QEMUClockType type)86da668aa1SThomas Huth int64_t qemu_clock_get_ns(QEMUClockType type)
87da668aa1SThomas Huth {
88da668aa1SThomas Huth     return ptimer_test_time_ns;
89da668aa1SThomas Huth }
90da668aa1SThomas Huth 
qemu_clock_deadline_ns_all(QEMUClockType type,int attr_mask)91da668aa1SThomas Huth int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
92da668aa1SThomas Huth {
93da668aa1SThomas Huth     QEMUTimerList *timer_list = main_loop_tlg.tl[QEMU_CLOCK_VIRTUAL];
94da668aa1SThomas Huth     QEMUTimer *t = timer_list->active_timers.next;
95da668aa1SThomas Huth     int64_t deadline = -1;
96da668aa1SThomas Huth 
97da668aa1SThomas Huth     while (t != NULL) {
98da668aa1SThomas Huth         if (deadline == -1) {
99da668aa1SThomas Huth             deadline = t->expire_time;
100da668aa1SThomas Huth         } else {
101da668aa1SThomas Huth             deadline = MIN(deadline, t->expire_time);
102da668aa1SThomas Huth         }
103da668aa1SThomas Huth 
104da668aa1SThomas Huth         t = t->next;
105da668aa1SThomas Huth     }
106da668aa1SThomas Huth 
107da668aa1SThomas Huth     return deadline;
108da668aa1SThomas Huth }
109da668aa1SThomas Huth 
qemu_bh_new_full(QEMUBHFunc * cb,void * opaque,const char * name,MemReentrancyGuard * reentrancy_guard)110*9c86c97fSAlexander Bulekov QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name,
111*9c86c97fSAlexander Bulekov                          MemReentrancyGuard *reentrancy_guard)
112da668aa1SThomas Huth {
113da668aa1SThomas Huth     QEMUBH *bh = g_new(QEMUBH, 1);
114da668aa1SThomas Huth 
115da668aa1SThomas Huth     bh->cb = cb;
116da668aa1SThomas Huth     bh->opaque = opaque;
117da668aa1SThomas Huth 
118da668aa1SThomas Huth     return bh;
119da668aa1SThomas Huth }
120da668aa1SThomas Huth 
qemu_bh_delete(QEMUBH * bh)121da668aa1SThomas Huth void qemu_bh_delete(QEMUBH *bh)
122da668aa1SThomas Huth {
123da668aa1SThomas Huth     g_free(bh);
124da668aa1SThomas Huth }
125