]>
Commit | Line | Data |
---|---|---|
d73abd6d PD |
1 | /* |
2 | * replay.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 | ||
26bc60ac | 12 | #include "qemu-common.h" |
d73abd6d | 13 | #include "sysemu/replay.h" |
26bc60ac PD |
14 | #include "replay-internal.h" |
15 | #include "qemu/timer.h" | |
8b427044 | 16 | #include "qemu/main-loop.h" |
d73abd6d PD |
17 | |
18 | ReplayMode replay_mode = REPLAY_MODE_NONE; | |
26bc60ac PD |
19 | |
20 | ReplayState replay_state; | |
21 | ||
22 | bool replay_next_event_is(int event) | |
23 | { | |
24 | bool res = false; | |
25 | ||
26 | /* nothing to skip - not all instructions used */ | |
27 | if (replay_state.instructions_count != 0) { | |
28 | assert(replay_data_kind == EVENT_INSTRUCTION); | |
29 | return event == EVENT_INSTRUCTION; | |
30 | } | |
31 | ||
32 | while (true) { | |
33 | if (event == replay_data_kind) { | |
34 | res = true; | |
35 | } | |
36 | switch (replay_data_kind) { | |
37 | default: | |
38 | /* clock, time_t, checkpoint and other events */ | |
39 | return res; | |
40 | } | |
41 | } | |
42 | return res; | |
43 | } | |
44 | ||
45 | uint64_t replay_get_current_step(void) | |
46 | { | |
47 | return cpu_get_icount_raw(); | |
48 | } | |
8b427044 PD |
49 | |
50 | int replay_get_instructions(void) | |
51 | { | |
52 | int res = 0; | |
53 | replay_mutex_lock(); | |
54 | if (replay_next_event_is(EVENT_INSTRUCTION)) { | |
55 | res = replay_state.instructions_count; | |
56 | } | |
57 | replay_mutex_unlock(); | |
58 | return res; | |
59 | } | |
60 | ||
61 | void replay_account_executed_instructions(void) | |
62 | { | |
63 | if (replay_mode == REPLAY_MODE_PLAY) { | |
64 | replay_mutex_lock(); | |
65 | if (replay_state.instructions_count > 0) { | |
66 | int count = (int)(replay_get_current_step() | |
67 | - replay_state.current_step); | |
68 | replay_state.instructions_count -= count; | |
69 | replay_state.current_step += count; | |
70 | if (replay_state.instructions_count == 0) { | |
71 | assert(replay_data_kind == EVENT_INSTRUCTION); | |
72 | replay_finish_event(); | |
73 | /* Wake up iothread. This is required because | |
74 | timers will not expire until clock counters | |
75 | will be read from the log. */ | |
76 | qemu_notify_event(); | |
77 | } | |
78 | } | |
79 | replay_mutex_unlock(); | |
80 | } | |
81 | } |