]>
git.proxmox.com Git - mirror_qemu.git/blob - replay/replay.c
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"
17 #include "sysemu/sysemu.h"
19 ReplayMode replay_mode
= REPLAY_MODE_NONE
;
21 ReplayState replay_state
;
23 bool replay_next_event_is(int event
)
27 /* nothing to skip - not all instructions used */
28 if (replay_state
.instructions_count
!= 0) {
29 assert(replay_data_kind
== EVENT_INSTRUCTION
);
30 return event
== EVENT_INSTRUCTION
;
34 if (event
== replay_data_kind
) {
37 switch (replay_data_kind
) {
39 replay_finish_event();
40 qemu_system_shutdown_request();
43 /* clock, time_t, checkpoint and other events */
50 uint64_t replay_get_current_step(void)
52 return cpu_get_icount_raw();
55 int replay_get_instructions(void)
59 if (replay_next_event_is(EVENT_INSTRUCTION
)) {
60 res
= replay_state
.instructions_count
;
62 replay_mutex_unlock();
66 void replay_account_executed_instructions(void)
68 if (replay_mode
== REPLAY_MODE_PLAY
) {
70 if (replay_state
.instructions_count
> 0) {
71 int count
= (int)(replay_get_current_step()
72 - replay_state
.current_step
);
73 replay_state
.instructions_count
-= count
;
74 replay_state
.current_step
+= count
;
75 if (replay_state
.instructions_count
== 0) {
76 assert(replay_data_kind
== EVENT_INSTRUCTION
);
77 replay_finish_event();
78 /* Wake up iothread. This is required because
79 timers will not expire until clock counters
80 will be read from the log. */
84 replay_mutex_unlock();
88 bool replay_exception(void)
90 if (replay_mode
== REPLAY_MODE_RECORD
) {
91 replay_save_instructions();
93 replay_put_event(EVENT_EXCEPTION
);
94 replay_mutex_unlock();
96 } else if (replay_mode
== REPLAY_MODE_PLAY
) {
97 bool res
= replay_has_exception();
100 replay_finish_event();
101 replay_mutex_unlock();
109 bool replay_has_exception(void)
112 if (replay_mode
== REPLAY_MODE_PLAY
) {
113 replay_account_executed_instructions();
115 res
= replay_next_event_is(EVENT_EXCEPTION
);
116 replay_mutex_unlock();
122 bool replay_interrupt(void)
124 if (replay_mode
== REPLAY_MODE_RECORD
) {
125 replay_save_instructions();
127 replay_put_event(EVENT_INTERRUPT
);
128 replay_mutex_unlock();
130 } else if (replay_mode
== REPLAY_MODE_PLAY
) {
131 bool res
= replay_has_interrupt();
134 replay_finish_event();
135 replay_mutex_unlock();
143 bool replay_has_interrupt(void)
146 if (replay_mode
== REPLAY_MODE_PLAY
) {
147 replay_account_executed_instructions();
149 res
= replay_next_event_is(EVENT_INTERRUPT
);
150 replay_mutex_unlock();
155 void replay_shutdown_request(void)
157 if (replay_mode
== REPLAY_MODE_RECORD
) {
159 replay_put_event(EVENT_SHUTDOWN
);
160 replay_mutex_unlock();