cpu: replay instructions sequence
[qemu/ar7.git] / replay / replay.c
blobb2c67501a5846d59259ab4901d9dc07fd08ffb28
1 /*
2 * 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"
18 ReplayMode replay_mode = REPLAY_MODE_NONE;
20 ReplayState replay_state;
22 bool replay_next_event_is(int event)
24 bool res = false;
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;
32 while (true) {
33 if (event == replay_data_kind) {
34 res = true;
36 switch (replay_data_kind) {
37 default:
38 /* clock, time_t, checkpoint and other events */
39 return res;
42 return res;
45 uint64_t replay_get_current_step(void)
47 return cpu_get_icount_raw();
50 int replay_get_instructions(void)
52 int res = 0;
53 replay_mutex_lock();
54 if (replay_next_event_is(EVENT_INSTRUCTION)) {
55 res = replay_state.instructions_count;
57 replay_mutex_unlock();
58 return res;
61 void replay_account_executed_instructions(void)
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();
79 replay_mutex_unlock();