]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/replay.h
bsd-user: Implement host_to_target_waitstatus conversion.
[mirror_qemu.git] / include / sysemu / replay.h
CommitLineData
5b5968c4
PMD
1#ifndef SYSEMU_REPLAY_H
2#define SYSEMU_REPLAY_H
d73abd6d
PD
3
4/*
5b5968c4 5 * QEMU replay (system interface)
d73abd6d
PD
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
5b5968c4 15#include "exec/replay-core.h"
112ed241 16#include "qapi/qapi-types-misc.h"
d5938f29 17#include "qapi/qapi-types-run-state.h"
112ed241 18#include "qapi/qapi-types-ui.h"
e4ec5ad4 19#include "block/aio.h"
d73abd6d 20
8eda206e
PD
21/* replay clock kinds */
22enum ReplayClockKind {
23 /* host_clock */
24 REPLAY_CLOCK_HOST,
25 /* virtual_rt_clock */
26 REPLAY_CLOCK_VIRTUAL_RT,
27 REPLAY_CLOCK_COUNT
28};
29typedef enum ReplayClockKind ReplayClockKind;
30
8bd7f71d
PD
31/* IDs of the checkpoints */
32enum ReplayCheckpoint {
e76d1798
PD
33 CHECKPOINT_CLOCK_WARP_START,
34 CHECKPOINT_CLOCK_WARP_ACCOUNT,
8bd7f71d
PD
35 CHECKPOINT_RESET_REQUESTED,
36 CHECKPOINT_SUSPEND_REQUESTED,
37 CHECKPOINT_CLOCK_VIRTUAL,
38 CHECKPOINT_CLOCK_HOST,
39 CHECKPOINT_CLOCK_VIRTUAL_RT,
40 CHECKPOINT_INIT,
41 CHECKPOINT_RESET,
42 CHECKPOINT_COUNT
43};
44typedef enum ReplayCheckpoint ReplayCheckpoint;
45
646c5478
PD
46typedef struct ReplayNetState ReplayNetState;
47
9c2037d0
PD
48/* Name of the initial VM snapshot */
49extern char *replay_snapshot;
50
a36544d3
AB
51/* Replay locking
52 *
53 * The locks are needed to protect the shared structures and log file
54 * when doing record/replay. They also are the main sync-point between
55 * the main-loop thread and the vCPU thread. This was a role
56 * previously filled by the BQL which has been busy trying to reduce
57 * its impact across the code. This ensures blocks of events stay
58 * sequential and reproducible.
59 */
60
61void replay_mutex_lock(void);
62void replay_mutex_unlock(void);
63
26bc60ac
PD
64/* Processing the instructions */
65
66/*! Returns number of executed instructions. */
13f26713 67uint64_t replay_get_current_icount(void);
8b427044
PD
68/*! Returns number of instructions to execute in replay mode. */
69int replay_get_instructions(void);
70/*! Updates instructions counter in replay mode. */
71void replay_account_executed_instructions(void);
26bc60ac 72
8eda206e
PD
73/* Processing clocks and other time sources */
74
75/*! Save the specified clock */
74c0b816
PB
76int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
77 int64_t raw_icount);
8eda206e 78/*! Read the specified clock from the log or return cached data */
366a85e4 79int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount);
8eda206e
PD
80/*! Saves or reads the clock depending on the current replay mode. */
81#define REPLAY_CLOCK(clock, value) \
366a85e4
PD
82 (replay_mode == REPLAY_MODE_PLAY \
83 ? replay_read_clock((clock), icount_get_raw()) \
8eda206e 84 : replay_mode == REPLAY_MODE_RECORD \
366a85e4
PD
85 ? replay_save_clock((clock), (value), icount_get_raw()) \
86 : (value))
74c0b816 87#define REPLAY_CLOCK_LOCKED(clock, value) \
366a85e4
PD
88 (replay_mode == REPLAY_MODE_PLAY \
89 ? replay_read_clock((clock), icount_get_raw_locked()) \
74c0b816 90 : replay_mode == REPLAY_MODE_RECORD \
8191d368 91 ? replay_save_clock((clock), (value), icount_get_raw_locked()) \
366a85e4 92 : (value))
8eda206e 93
b60c48a7
PD
94/* Events */
95
96/*! Called when qemu shutdown is requested. */
802f045a 97void replay_shutdown_request(ShutdownCause cause);
8bd7f71d
PD
98/*! Should be called at check points in the execution.
99 These check points are skipped, if they were not met.
100 Saves checkpoint in the SAVE mode and validates in the PLAY mode.
101 Returns 0 in PLAY mode if checkpoint was not found.
102 Returns 1 in all other cases. */
103bool replay_checkpoint(ReplayCheckpoint checkpoint);
60618e2d 104/*! Used to determine that checkpoint or async event is pending.
0c08185f 105 Does not proceed to the next event in the log. */
60618e2d
PD
106bool replay_has_event(void);
107/*
108 * Processes the async events added to the queue (while recording)
109 * or reads the events from the file (while replaying).
110 */
111void replay_async_events(void);
b60c48a7 112
c0c071d0
PD
113/* Asynchronous events queue */
114
115/*! Disables storing events in the queue */
116void replay_disable_events(void);
6d0ceb80
PD
117/*! Enables storing events in the queue */
118void replay_enable_events(void);
c0c071d0
PD
119/*! Returns true when saving events is enabled */
120bool replay_events_enabled(void);
f9a9fb65
PD
121/* Flushes events queue */
122void replay_flush_events(void);
8a354bd9
PD
123/*! Adds bottom half event to the queue */
124void replay_bh_schedule_event(QEMUBH *bh);
e4ec5ad4
PD
125/* Adds oneshot bottom half event to the queue */
126void replay_bh_schedule_oneshot_event(AioContext *ctx,
127 QEMUBHFunc *cb, void *opaque);
ee312992
PD
128/*! Adds input event to the queue */
129void replay_input_event(QemuConsole *src, InputEvent *evt);
130/*! Adds input sync event to the queue */
131void replay_input_sync_event(void);
63785678
PD
132/*! Adds block layer event to the queue */
133void replay_block_event(QEMUBH *bh, uint64_t id);
6d0ceb80
PD
134/*! Returns ID for the next block event */
135uint64_t blkreplay_next_id(void);
6f060969 136
33577b47
PD
137/* Character device */
138
139/*! Registers char driver to save it's events */
0ec7b3e7 140void replay_register_char_driver(struct Chardev *chr);
33577b47 141/*! Saves write to char device event to the log */
8f9abdf5 142void replay_chr_be_write(struct Chardev *s, const uint8_t *buf, int len);
33577b47
PD
143/*! Writes char write return value to the replay log. */
144void replay_char_write_event_save(int res, int offset);
145/*! Reads char write return value from the replay log. */
146void replay_char_write_event_load(int *res, int *offset);
147/*! Reads information about read_all character event. */
148int replay_char_read_all_load(uint8_t *buf);
149/*! Writes character read_all error code into the replay log. */
150void replay_char_read_all_save_error(int res);
151/*! Writes character read_all execution result into the replay log. */
152void replay_char_read_all_save_buf(uint8_t *buf, int offset);
153
646c5478
PD
154/* Network */
155
156/*! Registers replay network filter attached to some backend. */
157ReplayNetState *replay_register_net(NetFilterState *nfs);
158/*! Unregisters replay network filter. */
159void replay_unregister_net(ReplayNetState *rns);
160/*! Called to write network packet to the replay log. */
161void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
162 const struct iovec *iov, int iovcnt);
163
3d4d16f4
PD
164/* Audio */
165
166/*! Saves/restores number of played samples of audio out operation. */
7520462b 167void replay_audio_out(size_t *played);
3d4d16f4 168/*! Saves/restores recorded samples of audio in operation. */
7520462b 169void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
3d4d16f4 170
9c2037d0
PD
171/* VM state operations */
172
173/*! Called at the start of execution.
174 Loads or saves initial vmstate depending on execution mode. */
175void replay_vmstate_init(void);
377b21cc
PD
176/*! Called to ensure that replay state is consistent and VM snapshot
177 can be created */
178bool replay_can_snapshot(void);
9c2037d0 179
d73abd6d 180#endif