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