1/* 2 * Stubs for the ptimer-test 3 * 4 * Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com> 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" 14#include "migration/vmstate.h" 15 16#include "ptimer-test.h" 17 18const VMStateInfo vmstate_info_uint8; 19const VMStateInfo vmstate_info_uint32; 20const VMStateInfo vmstate_info_uint64; 21const VMStateInfo vmstate_info_int64; 22const VMStateInfo vmstate_info_timer; 23 24struct QEMUBH { 25 QEMUBHFunc *cb; 26 void *opaque; 27}; 28 29QEMUTimerListGroup main_loop_tlg; 30 31int64_t ptimer_test_time_ns; 32 33/* Do not artificially limit period - see hw/core/ptimer.c. */ 34int use_icount = 1; 35bool qtest_allowed; 36 37void timer_init_tl(QEMUTimer *ts, 38 QEMUTimerList *timer_list, int scale, 39 QEMUTimerCB *cb, void *opaque) 40{ 41 ts->timer_list = timer_list; 42 ts->cb = cb; 43 ts->opaque = opaque; 44 ts->scale = scale; 45 ts->expire_time = -1; 46} 47 48void timer_mod(QEMUTimer *ts, int64_t expire_time) 49{ 50 QEMUTimerList *timer_list = ts->timer_list; 51 QEMUTimer *t = &timer_list->active_timers; 52 53 while (t->next != NULL) { 54 if (t->next == ts) { 55 break; 56 } 57 58 t = t->next; 59 } 60 61 ts->expire_time = MAX(expire_time * ts->scale, 0); 62 ts->next = NULL; 63 t->next = ts; 64} 65 66void timer_del(QEMUTimer *ts) 67{ 68 QEMUTimerList *timer_list = ts->timer_list; 69 QEMUTimer *t = &timer_list->active_timers; 70 71 while (t->next != NULL) { 72 if (t->next == ts) { 73 t->next = ts->next; 74 return; 75 } 76 77 t = t->next; 78 } 79} 80 81int64_t qemu_clock_get_ns(QEMUClockType type) 82{ 83 return ptimer_test_time_ns; 84} 85 86int64_t qemu_clock_deadline_ns_all(QEMUClockType type) 87{ 88 QEMUTimerList *timer_list = main_loop_tlg.tl[type]; 89 QEMUTimer *t = timer_list->active_timers.next; 90 int64_t deadline = -1; 91 92 while (t != NULL) { 93 if (deadline == -1) { 94 deadline = t->expire_time; 95 } else { 96 deadline = MIN(deadline, t->expire_time); 97 } 98 99 t = t->next; 100 } 101 102 return deadline; 103} 104 105QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) 106{ 107 QEMUBH *bh = g_new(QEMUBH, 1); 108 109 bh->cb = cb; 110 bh->opaque = opaque; 111 112 return bh; 113} 114 115void qemu_bh_delete(QEMUBH *bh) 116{ 117 g_free(bh); 118} 119 120void replay_bh_schedule_event(QEMUBH *bh) 121{ 122 bh->cb(bh->opaque); 123} 124