4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
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.
12 #include "qemu-common.h"
13 #include "sysemu/replay.h"
14 #include "replay-internal.h"
15 #include "qemu/timer.h"
16 #include "qemu/main-loop.h"
18 ReplayMode replay_mode
= REPLAY_MODE_NONE
;
20 ReplayState replay_state
;
22 bool replay_next_event_is(int event
)
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
;
33 if (event
== replay_data_kind
) {
36 switch (replay_data_kind
) {
38 /* clock, time_t, checkpoint and other events */
45 uint64_t replay_get_current_step(void)
47 return cpu_get_icount_raw();
50 int replay_get_instructions(void)
54 if (replay_next_event_is(EVENT_INSTRUCTION
)) {
55 res
= replay_state
.instructions_count
;
57 replay_mutex_unlock();
61 void replay_account_executed_instructions(void)
63 if (replay_mode
== REPLAY_MODE_PLAY
) {
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. */
79 replay_mutex_unlock();