2015-09-17 19:23:37 +03:00
|
|
|
/*
|
2022-12-19 20:09:43 +03:00
|
|
|
* QEMU replay (system interface)
|
2015-09-17 19:23:37 +03:00
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2015 Institute for System Programming
|
|
|
|
* of the Russian Academy of Sciences.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
2024-01-06 02:23:37 +03:00
|
|
|
#ifndef SYSEMU_REPLAY_H
|
|
|
|
#define SYSEMU_REPLAY_H
|
|
|
|
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
#error Cannot include this header from user emulation
|
|
|
|
#endif
|
2015-09-17 19:23:37 +03:00
|
|
|
|
2022-12-19 20:09:43 +03:00
|
|
|
#include "exec/replay-core.h"
|
2018-02-27 02:13:27 +03:00
|
|
|
#include "qapi/qapi-types-misc.h"
|
2019-08-12 08:23:56 +03:00
|
|
|
#include "qapi/qapi-types-run-state.h"
|
2018-02-27 02:13:27 +03:00
|
|
|
#include "qapi/qapi-types-ui.h"
|
2019-09-17 14:58:19 +03:00
|
|
|
#include "block/aio.h"
|
2015-09-17 19:23:37 +03:00
|
|
|
|
2015-09-17 19:24:28 +03:00
|
|
|
/* replay clock kinds */
|
|
|
|
enum ReplayClockKind {
|
|
|
|
/* host_clock */
|
|
|
|
REPLAY_CLOCK_HOST,
|
|
|
|
/* virtual_rt_clock */
|
|
|
|
REPLAY_CLOCK_VIRTUAL_RT,
|
|
|
|
REPLAY_CLOCK_COUNT
|
|
|
|
};
|
|
|
|
typedef enum ReplayClockKind ReplayClockKind;
|
|
|
|
|
2015-09-17 19:24:44 +03:00
|
|
|
/* IDs of the checkpoints */
|
|
|
|
enum ReplayCheckpoint {
|
2016-03-10 14:56:09 +03:00
|
|
|
CHECKPOINT_CLOCK_WARP_START,
|
|
|
|
CHECKPOINT_CLOCK_WARP_ACCOUNT,
|
2015-09-17 19:24:44 +03:00
|
|
|
CHECKPOINT_RESET_REQUESTED,
|
|
|
|
CHECKPOINT_SUSPEND_REQUESTED,
|
|
|
|
CHECKPOINT_CLOCK_VIRTUAL,
|
|
|
|
CHECKPOINT_CLOCK_HOST,
|
|
|
|
CHECKPOINT_CLOCK_VIRTUAL_RT,
|
|
|
|
CHECKPOINT_INIT,
|
|
|
|
CHECKPOINT_RESET,
|
|
|
|
CHECKPOINT_COUNT
|
|
|
|
};
|
|
|
|
typedef enum ReplayCheckpoint ReplayCheckpoint;
|
|
|
|
|
2016-09-26 11:08:21 +03:00
|
|
|
typedef struct ReplayNetState ReplayNetState;
|
|
|
|
|
2017-01-24 10:17:47 +03:00
|
|
|
/* Name of the initial VM snapshot */
|
|
|
|
extern char *replay_snapshot;
|
|
|
|
|
2018-02-27 12:52:42 +03:00
|
|
|
/* Replay locking
|
|
|
|
*
|
|
|
|
* The locks are needed to protect the shared structures and log file
|
|
|
|
* when doing record/replay. They also are the main sync-point between
|
|
|
|
* the main-loop thread and the vCPU thread. This was a role
|
|
|
|
* previously filled by the BQL which has been busy trying to reduce
|
|
|
|
* its impact across the code. This ensures blocks of events stay
|
|
|
|
* sequential and reproducible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void replay_mutex_lock(void);
|
|
|
|
void replay_mutex_unlock(void);
|
|
|
|
|
2015-09-17 19:23:54 +03:00
|
|
|
/* Processing the instructions */
|
|
|
|
|
|
|
|
/*! Returns number of executed instructions. */
|
2019-07-25 11:44:43 +03:00
|
|
|
uint64_t replay_get_current_icount(void);
|
2015-09-17 19:24:05 +03:00
|
|
|
/*! Returns number of instructions to execute in replay mode. */
|
|
|
|
int replay_get_instructions(void);
|
|
|
|
/*! Updates instructions counter in replay mode. */
|
|
|
|
void replay_account_executed_instructions(void);
|
2015-09-17 19:23:54 +03:00
|
|
|
|
2023-12-11 12:13:40 +03:00
|
|
|
/**
|
|
|
|
* replay_can_wait: check if we should pause for wait-io
|
|
|
|
*/
|
|
|
|
bool replay_can_wait(void);
|
|
|
|
|
2015-09-17 19:24:28 +03:00
|
|
|
/* Processing clocks and other time sources */
|
|
|
|
|
|
|
|
/*! Save the specified clock */
|
2018-10-08 14:24:14 +03:00
|
|
|
int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
|
|
|
|
int64_t raw_icount);
|
2015-09-17 19:24:28 +03:00
|
|
|
/*! Read the specified clock from the log or return cached data */
|
2021-02-16 15:51:44 +03:00
|
|
|
int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount);
|
2015-09-17 19:24:28 +03:00
|
|
|
/*! Saves or reads the clock depending on the current replay mode. */
|
|
|
|
#define REPLAY_CLOCK(clock, value) \
|
2024-01-06 02:23:37 +03:00
|
|
|
!icount_enabled() ? (value) : \
|
2021-02-16 15:51:44 +03:00
|
|
|
(replay_mode == REPLAY_MODE_PLAY \
|
|
|
|
? replay_read_clock((clock), icount_get_raw()) \
|
2015-09-17 19:24:28 +03:00
|
|
|
: replay_mode == REPLAY_MODE_RECORD \
|
2021-02-16 15:51:44 +03:00
|
|
|
? replay_save_clock((clock), (value), icount_get_raw()) \
|
|
|
|
: (value))
|
2018-10-08 14:24:14 +03:00
|
|
|
#define REPLAY_CLOCK_LOCKED(clock, value) \
|
2024-01-06 02:23:37 +03:00
|
|
|
!icount_enabled() ? (value) : \
|
2021-02-16 15:51:44 +03:00
|
|
|
(replay_mode == REPLAY_MODE_PLAY \
|
|
|
|
? replay_read_clock((clock), icount_get_raw_locked()) \
|
2018-10-08 14:24:14 +03:00
|
|
|
: replay_mode == REPLAY_MODE_RECORD \
|
2020-08-31 17:18:34 +03:00
|
|
|
? replay_save_clock((clock), (value), icount_get_raw_locked()) \
|
2021-02-16 15:51:44 +03:00
|
|
|
: (value))
|
2015-09-17 19:24:28 +03:00
|
|
|
|
2015-09-17 19:24:33 +03:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/*! Called when qemu shutdown is requested. */
|
2017-05-16 00:41:12 +03:00
|
|
|
void replay_shutdown_request(ShutdownCause cause);
|
2015-09-17 19:24:44 +03:00
|
|
|
/*! Should be called at check points in the execution.
|
|
|
|
These check points are skipped, if they were not met.
|
|
|
|
Saves checkpoint in the SAVE mode and validates in the PLAY mode.
|
|
|
|
Returns 0 in PLAY mode if checkpoint was not found.
|
|
|
|
Returns 1 in all other cases. */
|
|
|
|
bool replay_checkpoint(ReplayCheckpoint checkpoint);
|
2022-05-27 13:46:18 +03:00
|
|
|
/*! Used to determine that checkpoint or async event is pending.
|
2018-09-12 11:19:45 +03:00
|
|
|
Does not proceed to the next event in the log. */
|
2022-05-27 13:46:18 +03:00
|
|
|
bool replay_has_event(void);
|
|
|
|
/*
|
|
|
|
* Processes the async events added to the queue (while recording)
|
|
|
|
* or reads the events from the file (while replaying).
|
|
|
|
*/
|
|
|
|
void replay_async_events(void);
|
2015-09-17 19:24:33 +03:00
|
|
|
|
2015-09-17 19:24:22 +03:00
|
|
|
/* Asynchronous events queue */
|
|
|
|
|
|
|
|
/*! Disables storing events in the queue */
|
|
|
|
void replay_disable_events(void);
|
2016-09-26 11:08:16 +03:00
|
|
|
/*! Enables storing events in the queue */
|
|
|
|
void replay_enable_events(void);
|
2015-09-17 19:24:22 +03:00
|
|
|
/*! Returns true when saving events is enabled */
|
|
|
|
bool replay_events_enabled(void);
|
2020-10-03 20:13:37 +03:00
|
|
|
/* Flushes events queue */
|
|
|
|
void replay_flush_events(void);
|
2015-09-17 19:24:56 +03:00
|
|
|
/*! Adds bottom half event to the queue */
|
|
|
|
void replay_bh_schedule_event(QEMUBH *bh);
|
2019-09-17 14:58:19 +03:00
|
|
|
/* Adds oneshot bottom half event to the queue */
|
|
|
|
void replay_bh_schedule_oneshot_event(AioContext *ctx,
|
|
|
|
QEMUBHFunc *cb, void *opaque);
|
2015-09-17 19:25:24 +03:00
|
|
|
/*! Adds input event to the queue */
|
|
|
|
void replay_input_event(QemuConsole *src, InputEvent *evt);
|
|
|
|
/*! Adds input sync event to the queue */
|
|
|
|
void replay_input_sync_event(void);
|
2016-03-14 10:45:10 +03:00
|
|
|
/*! Adds block layer event to the queue */
|
|
|
|
void replay_block_event(QEMUBH *bh, uint64_t id);
|
2016-09-26 11:08:16 +03:00
|
|
|
/*! Returns ID for the next block event */
|
|
|
|
uint64_t blkreplay_next_id(void);
|
2015-09-17 19:24:16 +03:00
|
|
|
|
2016-03-14 10:44:36 +03:00
|
|
|
/* Character device */
|
|
|
|
|
|
|
|
/*! Registers char driver to save it's events */
|
2016-12-07 16:20:22 +03:00
|
|
|
void replay_register_char_driver(struct Chardev *chr);
|
2016-03-14 10:44:36 +03:00
|
|
|
/*! Saves write to char device event to the log */
|
2022-09-11 21:18:37 +03:00
|
|
|
void replay_chr_be_write(struct Chardev *s, const uint8_t *buf, int len);
|
2016-03-14 10:44:36 +03:00
|
|
|
/*! Writes char write return value to the replay log. */
|
|
|
|
void replay_char_write_event_save(int res, int offset);
|
|
|
|
/*! Reads char write return value from the replay log. */
|
|
|
|
void replay_char_write_event_load(int *res, int *offset);
|
|
|
|
/*! Reads information about read_all character event. */
|
|
|
|
int replay_char_read_all_load(uint8_t *buf);
|
|
|
|
/*! Writes character read_all error code into the replay log. */
|
|
|
|
void replay_char_read_all_save_error(int res);
|
|
|
|
/*! Writes character read_all execution result into the replay log. */
|
|
|
|
void replay_char_read_all_save_buf(uint8_t *buf, int offset);
|
|
|
|
|
2016-09-26 11:08:21 +03:00
|
|
|
/* Network */
|
|
|
|
|
|
|
|
/*! Registers replay network filter attached to some backend. */
|
|
|
|
ReplayNetState *replay_register_net(NetFilterState *nfs);
|
|
|
|
/*! Unregisters replay network filter. */
|
|
|
|
void replay_unregister_net(ReplayNetState *rns);
|
|
|
|
/*! Called to write network packet to the replay log. */
|
|
|
|
void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
|
|
|
|
const struct iovec *iov, int iovcnt);
|
|
|
|
|
2017-02-02 08:50:54 +03:00
|
|
|
/* Audio */
|
|
|
|
|
|
|
|
/*! Saves/restores number of played samples of audio out operation. */
|
2019-08-19 02:06:58 +03:00
|
|
|
void replay_audio_out(size_t *played);
|
2017-02-02 08:50:54 +03:00
|
|
|
/*! Saves/restores recorded samples of audio in operation. */
|
2019-08-19 02:06:58 +03:00
|
|
|
void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
|
2017-02-02 08:50:54 +03:00
|
|
|
|
2017-01-24 10:17:47 +03:00
|
|
|
/* VM state operations */
|
|
|
|
|
|
|
|
/*! Called at the start of execution.
|
|
|
|
Loads or saves initial vmstate depending on execution mode. */
|
|
|
|
void replay_vmstate_init(void);
|
2018-02-27 12:52:14 +03:00
|
|
|
/*! Called to ensure that replay state is consistent and VM snapshot
|
|
|
|
can be created */
|
|
|
|
bool replay_can_snapshot(void);
|
2017-01-24 10:17:47 +03:00
|
|
|
|
2015-09-17 19:23:37 +03:00
|
|
|
#endif
|