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