xref: /openbmc/qemu/include/sysemu/replay.h (revision f1f7e4bf)
1 #ifndef REPLAY_H
2 #define REPLAY_H
3 
4 /*
5  * replay.h
6  *
7  * Copyright (c) 2010-2015 Institute for System Programming
8  *                         of the Russian Academy of Sciences.
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2 or later.
11  * See the COPYING file in the top-level directory.
12  *
13  */
14 
15 #include <stdbool.h>
16 #include <stdint.h>
17 #include "qapi-types.h"
18 #include "qapi/error.h"
19 #include "qemu/typedefs.h"
20 
21 /* replay clock kinds */
22 enum ReplayClockKind {
23     /* host_clock */
24     REPLAY_CLOCK_HOST,
25     /* virtual_rt_clock */
26     REPLAY_CLOCK_VIRTUAL_RT,
27     REPLAY_CLOCK_COUNT
28 };
29 typedef enum ReplayClockKind ReplayClockKind;
30 
31 /* IDs of the checkpoints */
32 enum ReplayCheckpoint {
33     CHECKPOINT_CLOCK_WARP,
34     CHECKPOINT_RESET_REQUESTED,
35     CHECKPOINT_SUSPEND_REQUESTED,
36     CHECKPOINT_CLOCK_VIRTUAL,
37     CHECKPOINT_CLOCK_HOST,
38     CHECKPOINT_CLOCK_VIRTUAL_RT,
39     CHECKPOINT_INIT,
40     CHECKPOINT_RESET,
41     CHECKPOINT_COUNT
42 };
43 typedef enum ReplayCheckpoint ReplayCheckpoint;
44 
45 extern ReplayMode replay_mode;
46 
47 /* Replay process control functions */
48 
49 /*! Enables recording or saving event log with specified parameters */
50 void replay_configure(struct QemuOpts *opts);
51 /*! Initializes timers used for snapshotting and enables events recording */
52 void replay_start(void);
53 /*! Closes replay log file and frees other resources. */
54 void replay_finish(void);
55 /*! Adds replay blocker with the specified error description */
56 void replay_add_blocker(Error *reason);
57 
58 /* Processing the instructions */
59 
60 /*! Returns number of executed instructions. */
61 uint64_t replay_get_current_step(void);
62 /*! Returns number of instructions to execute in replay mode. */
63 int replay_get_instructions(void);
64 /*! Updates instructions counter in replay mode. */
65 void replay_account_executed_instructions(void);
66 
67 /* Interrupts and exceptions */
68 
69 /*! Called by exception handler to write or read
70     exception processing events. */
71 bool replay_exception(void);
72 /*! Used to determine that exception is pending.
73     Does not proceed to the next event in the log. */
74 bool replay_has_exception(void);
75 /*! Called by interrupt handlers to write or read
76     interrupt processing events.
77     \return true if interrupt should be processed */
78 bool replay_interrupt(void);
79 /*! Tries to read interrupt event from the file.
80     Returns true, when interrupt request is pending */
81 bool replay_has_interrupt(void);
82 
83 /* Processing clocks and other time sources */
84 
85 /*! Save the specified clock */
86 int64_t replay_save_clock(ReplayClockKind kind, int64_t clock);
87 /*! Read the specified clock from the log or return cached data */
88 int64_t replay_read_clock(ReplayClockKind kind);
89 /*! Saves or reads the clock depending on the current replay mode. */
90 #define REPLAY_CLOCK(clock, value)                                      \
91     (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))       \
92         : replay_mode == REPLAY_MODE_RECORD                             \
93             ? replay_save_clock((clock), (value))                       \
94         : (value))
95 
96 /* Events */
97 
98 /*! Called when qemu shutdown is requested. */
99 void replay_shutdown_request(void);
100 /*! Should be called at check points in the execution.
101     These check points are skipped, if they were not met.
102     Saves checkpoint in the SAVE mode and validates in the PLAY mode.
103     Returns 0 in PLAY mode if checkpoint was not found.
104     Returns 1 in all other cases. */
105 bool replay_checkpoint(ReplayCheckpoint checkpoint);
106 
107 /* Asynchronous events queue */
108 
109 /*! Disables storing events in the queue */
110 void replay_disable_events(void);
111 /*! Returns true when saving events is enabled */
112 bool replay_events_enabled(void);
113 /*! Adds bottom half event to the queue */
114 void replay_bh_schedule_event(QEMUBH *bh);
115 /*! Adds input event to the queue */
116 void replay_input_event(QemuConsole *src, InputEvent *evt);
117 /*! Adds input sync event to the queue */
118 void replay_input_sync_event(void);
119 
120 #endif
121