xref: /openbmc/qemu/include/sysemu/replay.h (revision 1cfe48c1)
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 "qapi-types.h"
16 #include "sysemu.h"
17 
18 /* replay clock kinds */
19 enum ReplayClockKind {
20     /* host_clock */
21     REPLAY_CLOCK_HOST,
22     /* virtual_rt_clock */
23     REPLAY_CLOCK_VIRTUAL_RT,
24     REPLAY_CLOCK_COUNT
25 };
26 typedef enum ReplayClockKind ReplayClockKind;
27 
28 /* IDs of the checkpoints */
29 enum ReplayCheckpoint {
30     CHECKPOINT_CLOCK_WARP_START,
31     CHECKPOINT_CLOCK_WARP_ACCOUNT,
32     CHECKPOINT_RESET_REQUESTED,
33     CHECKPOINT_SUSPEND_REQUESTED,
34     CHECKPOINT_CLOCK_VIRTUAL,
35     CHECKPOINT_CLOCK_HOST,
36     CHECKPOINT_CLOCK_VIRTUAL_RT,
37     CHECKPOINT_INIT,
38     CHECKPOINT_RESET,
39     CHECKPOINT_COUNT
40 };
41 typedef enum ReplayCheckpoint ReplayCheckpoint;
42 
43 typedef struct ReplayNetState ReplayNetState;
44 
45 extern ReplayMode replay_mode;
46 
47 /* Name of the initial VM snapshot */
48 extern char *replay_snapshot;
49 
50 /* Replay process control functions */
51 
52 /*! Enables recording or saving event log with specified parameters */
53 void replay_configure(struct QemuOpts *opts);
54 /*! Initializes timers used for snapshotting and enables events recording */
55 void replay_start(void);
56 /*! Closes replay log file and frees other resources. */
57 void replay_finish(void);
58 /*! Adds replay blocker with the specified error description */
59 void replay_add_blocker(Error *reason);
60 
61 /* Processing the instructions */
62 
63 /*! Returns number of executed instructions. */
64 uint64_t replay_get_current_step(void);
65 /*! Returns number of instructions to execute in replay mode. */
66 int replay_get_instructions(void);
67 /*! Updates instructions counter in replay mode. */
68 void replay_account_executed_instructions(void);
69 
70 /* Interrupts and exceptions */
71 
72 /*! Called by exception handler to write or read
73     exception processing events. */
74 bool replay_exception(void);
75 /*! Used to determine that exception is pending.
76     Does not proceed to the next event in the log. */
77 bool replay_has_exception(void);
78 /*! Called by interrupt handlers to write or read
79     interrupt processing events.
80     \return true if interrupt should be processed */
81 bool replay_interrupt(void);
82 /*! Tries to read interrupt event from the file.
83     Returns true, when interrupt request is pending */
84 bool replay_has_interrupt(void);
85 
86 /* Processing clocks and other time sources */
87 
88 /*! Save the specified clock */
89 int64_t replay_save_clock(ReplayClockKind kind, int64_t clock);
90 /*! Read the specified clock from the log or return cached data */
91 int64_t replay_read_clock(ReplayClockKind kind);
92 /*! Saves or reads the clock depending on the current replay mode. */
93 #define REPLAY_CLOCK(clock, value)                                      \
94     (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))       \
95         : replay_mode == REPLAY_MODE_RECORD                             \
96             ? replay_save_clock((clock), (value))                       \
97         : (value))
98 
99 /* Events */
100 
101 /*! Called when qemu shutdown is requested. */
102 void replay_shutdown_request(ShutdownCause cause);
103 /*! Should be called at check points in the execution.
104     These check points are skipped, if they were not met.
105     Saves checkpoint in the SAVE mode and validates in the PLAY mode.
106     Returns 0 in PLAY mode if checkpoint was not found.
107     Returns 1 in all other cases. */
108 bool replay_checkpoint(ReplayCheckpoint checkpoint);
109 
110 /* Asynchronous events queue */
111 
112 /*! Disables storing events in the queue */
113 void replay_disable_events(void);
114 /*! Enables storing events in the queue */
115 void replay_enable_events(void);
116 /*! Returns true when saving events is enabled */
117 bool replay_events_enabled(void);
118 /*! Adds bottom half event to the queue */
119 void replay_bh_schedule_event(QEMUBH *bh);
120 /*! Adds input event to the queue */
121 void replay_input_event(QemuConsole *src, InputEvent *evt);
122 /*! Adds input sync event to the queue */
123 void replay_input_sync_event(void);
124 /*! Adds block layer event to the queue */
125 void replay_block_event(QEMUBH *bh, uint64_t id);
126 /*! Returns ID for the next block event */
127 uint64_t blkreplay_next_id(void);
128 
129 /* Character device */
130 
131 /*! Registers char driver to save it's events */
132 void replay_register_char_driver(struct Chardev *chr);
133 /*! Saves write to char device event to the log */
134 void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);
135 /*! Writes char write return value to the replay log. */
136 void replay_char_write_event_save(int res, int offset);
137 /*! Reads char write return value from the replay log. */
138 void replay_char_write_event_load(int *res, int *offset);
139 /*! Reads information about read_all character event. */
140 int replay_char_read_all_load(uint8_t *buf);
141 /*! Writes character read_all error code into the replay log. */
142 void replay_char_read_all_save_error(int res);
143 /*! Writes character read_all execution result into the replay log. */
144 void replay_char_read_all_save_buf(uint8_t *buf, int offset);
145 
146 /* Network */
147 
148 /*! Registers replay network filter attached to some backend. */
149 ReplayNetState *replay_register_net(NetFilterState *nfs);
150 /*! Unregisters replay network filter. */
151 void replay_unregister_net(ReplayNetState *rns);
152 /*! Called to write network packet to the replay log. */
153 void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
154                              const struct iovec *iov, int iovcnt);
155 
156 /* Audio */
157 
158 /*! Saves/restores number of played samples of audio out operation. */
159 void replay_audio_out(int *played);
160 /*! Saves/restores recorded samples of audio in operation. */
161 void replay_audio_in(int *recorded, void *samples, int *wpos, int size);
162 
163 /* VM state operations */
164 
165 /*! Called at the start of execution.
166     Loads or saves initial vmstate depending on execution mode. */
167 void replay_vmstate_init(void);
168 
169 #endif
170