Dmitry Osipenko | 5b262bb | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Stubs for the ptimer-test |
| 3 | * |
Dmitry Osipenko | 673c7e8 | 2016-10-24 16:26:53 +0100 | [diff] [blame] | 4 | * Copyright (c) 2016 Dmitry Osipenko <digetx@gmail.com> |
Dmitry Osipenko | 5b262bb | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 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" |
Paolo Bonzini | 24b9462 | 2016-10-17 19:22:17 +0100 | [diff] [blame] | 14 | #include "migration/vmstate.h" |
Dmitry Osipenko | 5b262bb | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 15 | |
| 16 | #include "ptimer-test.h" |
| 17 | |
Paolo Bonzini | 24b9462 | 2016-10-17 19:22:17 +0100 | [diff] [blame] | 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 | |
Dmitry Osipenko | 5b262bb | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 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 | |
| 33 | void timer_init_tl(QEMUTimer *ts, |
| 34 | QEMUTimerList *timer_list, int scale, |
| 35 | QEMUTimerCB *cb, void *opaque) |
| 36 | { |
| 37 | ts->timer_list = timer_list; |
| 38 | ts->cb = cb; |
| 39 | ts->opaque = opaque; |
| 40 | ts->scale = scale; |
| 41 | ts->expire_time = -1; |
| 42 | } |
| 43 | |
| 44 | void timer_mod(QEMUTimer *ts, int64_t expire_time) |
| 45 | { |
| 46 | QEMUTimerList *timer_list = ts->timer_list; |
| 47 | QEMUTimer *t = &timer_list->active_timers; |
| 48 | |
| 49 | while (t->next != NULL) { |
| 50 | if (t->next == ts) { |
| 51 | break; |
| 52 | } |
| 53 | |
| 54 | t = t->next; |
| 55 | } |
| 56 | |
| 57 | ts->expire_time = MAX(expire_time * ts->scale, 0); |
| 58 | ts->next = NULL; |
| 59 | t->next = ts; |
| 60 | } |
| 61 | |
| 62 | void timer_del(QEMUTimer *ts) |
| 63 | { |
| 64 | QEMUTimerList *timer_list = ts->timer_list; |
| 65 | QEMUTimer *t = &timer_list->active_timers; |
| 66 | |
| 67 | while (t->next != NULL) { |
| 68 | if (t->next == ts) { |
| 69 | t->next = ts->next; |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | t = t->next; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | int64_t qemu_clock_get_ns(QEMUClockType type) |
| 78 | { |
| 79 | return ptimer_test_time_ns; |
| 80 | } |
| 81 | |
| 82 | int64_t qemu_clock_deadline_ns_all(QEMUClockType type) |
| 83 | { |
| 84 | QEMUTimerList *timer_list = main_loop_tlg.tl[type]; |
| 85 | QEMUTimer *t = timer_list->active_timers.next; |
| 86 | int64_t deadline = -1; |
| 87 | |
| 88 | while (t != NULL) { |
| 89 | if (deadline == -1) { |
| 90 | deadline = t->expire_time; |
| 91 | } else { |
| 92 | deadline = MIN(deadline, t->expire_time); |
| 93 | } |
| 94 | |
| 95 | t = t->next; |
| 96 | } |
| 97 | |
| 98 | return deadline; |
| 99 | } |
| 100 | |
| 101 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) |
| 102 | { |
| 103 | QEMUBH *bh = g_new(QEMUBH, 1); |
| 104 | |
| 105 | bh->cb = cb; |
| 106 | bh->opaque = opaque; |
| 107 | |
| 108 | return bh; |
| 109 | } |
| 110 | |
Marc-André Lureau | 072bdb0 | 2017-01-27 12:55:51 +0400 | [diff] [blame] | 111 | void qemu_bh_delete(QEMUBH *bh) |
| 112 | { |
| 113 | g_free(bh); |
| 114 | } |
| 115 | |
Dmitry Osipenko | 5b262bb | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 116 | void replay_bh_schedule_event(QEMUBH *bh) |
| 117 | { |
| 118 | bh->cb(bh->opaque); |
| 119 | } |