xref: /qemu/replay/replay-time.c (revision 4f2d31fb)
1 /*
2  * replay-time.c
3  *
4  * Copyright (c) 2010-2015 Institute for System Programming
5  *                         of the Russian Academy of Sciences.
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or later.
8  * See the COPYING file in the top-level directory.
9  *
10  */
11 
12 #include "qemu-common.h"
13 #include "sysemu/replay.h"
14 #include "replay-internal.h"
15 #include "qemu/error-report.h"
16 
17 int64_t replay_save_clock(ReplayClockKind kind, int64_t clock)
18 {
19     replay_save_instructions();
20 
21     if (replay_file) {
22         replay_mutex_lock();
23         replay_put_event(EVENT_CLOCK + kind);
24         replay_put_qword(clock);
25         replay_mutex_unlock();
26     }
27 
28     return clock;
29 }
30 
31 void replay_read_next_clock(ReplayClockKind kind)
32 {
33     unsigned int read_kind = replay_data_kind - EVENT_CLOCK;
34 
35     assert(read_kind == kind);
36 
37     int64_t clock = replay_get_qword();
38 
39     replay_check_error();
40     replay_finish_event();
41 
42     replay_state.cached_clock[read_kind] = clock;
43 }
44 
45 /*! Reads next clock event from the input. */
46 int64_t replay_read_clock(ReplayClockKind kind)
47 {
48     replay_account_executed_instructions();
49 
50     if (replay_file) {
51         int64_t ret;
52         replay_mutex_lock();
53         if (replay_next_event_is(EVENT_CLOCK + kind)) {
54             replay_read_next_clock(kind);
55         }
56         ret = replay_state.cached_clock[kind];
57         replay_mutex_unlock();
58 
59         return ret;
60     }
61 
62     error_report("REPLAY INTERNAL ERROR %d", __LINE__);
63     exit(1);
64 }
65