Commit | Line | Data |
---|---|---|
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 */ |
18 | enum ReplayClockKind { | |
19 | /* host_clock */ | |
20 | REPLAY_CLOCK_HOST, | |
21 | /* virtual_rt_clock */ | |
22 | REPLAY_CLOCK_VIRTUAL_RT, | |
23 | REPLAY_CLOCK_COUNT | |
24 | }; | |
25 | typedef enum ReplayClockKind ReplayClockKind; | |
26 | ||
8bd7f71d PD |
27 | /* IDs of the checkpoints */ |
28 | enum 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 | }; | |
40 | typedef enum ReplayCheckpoint ReplayCheckpoint; | |
41 | ||
d73abd6d PD |
42 | extern ReplayMode replay_mode; |
43 | ||
7615936e PD |
44 | /* Replay process control functions */ |
45 | ||
46 | /*! Enables recording or saving event log with specified parameters */ | |
47 | void replay_configure(struct QemuOpts *opts); | |
48 | /*! Initializes timers used for snapshotting and enables events recording */ | |
49 | void replay_start(void); | |
50 | /*! Closes replay log file and frees other resources. */ | |
51 | void replay_finish(void); | |
0194749a PD |
52 | /*! Adds replay blocker with the specified error description */ |
53 | void replay_add_blocker(Error *reason); | |
7615936e | 54 | |
26bc60ac PD |
55 | /* Processing the instructions */ |
56 | ||
57 | /*! Returns number of executed instructions. */ | |
58 | uint64_t replay_get_current_step(void); | |
8b427044 PD |
59 | /*! Returns number of instructions to execute in replay mode. */ |
60 | int replay_get_instructions(void); | |
61 | /*! Updates instructions counter in replay mode. */ | |
62 | void replay_account_executed_instructions(void); | |
26bc60ac | 63 | |
6f060969 PD |
64 | /* Interrupts and exceptions */ |
65 | ||
66 | /*! Called by exception handler to write or read | |
67 | exception processing events. */ | |
68 | bool replay_exception(void); | |
69 | /*! Used to determine that exception is pending. | |
70 | Does not proceed to the next event in the log. */ | |
71 | bool replay_has_exception(void); | |
72 | /*! Called by interrupt handlers to write or read | |
73 | interrupt processing events. | |
74 | \return true if interrupt should be processed */ | |
75 | bool replay_interrupt(void); | |
76 | /*! Tries to read interrupt event from the file. | |
77 | Returns true, when interrupt request is pending */ | |
78 | bool replay_has_interrupt(void); | |
79 | ||
8eda206e PD |
80 | /* Processing clocks and other time sources */ |
81 | ||
82 | /*! Save the specified clock */ | |
83 | int64_t replay_save_clock(ReplayClockKind kind, int64_t clock); | |
84 | /*! Read the specified clock from the log or return cached data */ | |
85 | int64_t replay_read_clock(ReplayClockKind kind); | |
86 | /*! Saves or reads the clock depending on the current replay mode. */ | |
87 | #define REPLAY_CLOCK(clock, value) \ | |
88 | (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \ | |
89 | : replay_mode == REPLAY_MODE_RECORD \ | |
90 | ? replay_save_clock((clock), (value)) \ | |
91 | : (value)) | |
92 | ||
b60c48a7 PD |
93 | /* Events */ |
94 | ||
95 | /*! Called when qemu shutdown is requested. */ | |
96 | void replay_shutdown_request(void); | |
8bd7f71d PD |
97 | /*! Should be called at check points in the execution. |
98 | These check points are skipped, if they were not met. | |
99 | Saves checkpoint in the SAVE mode and validates in the PLAY mode. | |
100 | Returns 0 in PLAY mode if checkpoint was not found. | |
101 | Returns 1 in all other cases. */ | |
102 | bool replay_checkpoint(ReplayCheckpoint checkpoint); | |
b60c48a7 | 103 | |
c0c071d0 PD |
104 | /* Asynchronous events queue */ |
105 | ||
106 | /*! Disables storing events in the queue */ | |
107 | void replay_disable_events(void); | |
6d0ceb80 PD |
108 | /*! Enables storing events in the queue */ |
109 | void replay_enable_events(void); | |
c0c071d0 PD |
110 | /*! Returns true when saving events is enabled */ |
111 | bool replay_events_enabled(void); | |
8a354bd9 PD |
112 | /*! Adds bottom half event to the queue */ |
113 | void replay_bh_schedule_event(QEMUBH *bh); | |
ee312992 PD |
114 | /*! Adds input event to the queue */ |
115 | void replay_input_event(QemuConsole *src, InputEvent *evt); | |
116 | /*! Adds input sync event to the queue */ | |
117 | void replay_input_sync_event(void); | |
63785678 PD |
118 | /*! Adds block layer event to the queue */ |
119 | void replay_block_event(QEMUBH *bh, uint64_t id); | |
6d0ceb80 PD |
120 | /*! Returns ID for the next block event */ |
121 | uint64_t blkreplay_next_id(void); | |
6f060969 | 122 | |
33577b47 PD |
123 | /* Character device */ |
124 | ||
125 | /*! Registers char driver to save it's events */ | |
126 | void replay_register_char_driver(struct CharDriverState *chr); | |
127 | /*! Saves write to char device event to the log */ | |
128 | void replay_chr_be_write(struct CharDriverState *s, uint8_t *buf, int len); | |
129 | /*! Writes char write return value to the replay log. */ | |
130 | void replay_char_write_event_save(int res, int offset); | |
131 | /*! Reads char write return value from the replay log. */ | |
132 | void replay_char_write_event_load(int *res, int *offset); | |
133 | /*! Reads information about read_all character event. */ | |
134 | int replay_char_read_all_load(uint8_t *buf); | |
135 | /*! Writes character read_all error code into the replay log. */ | |
136 | void replay_char_read_all_save_error(int res); | |
137 | /*! Writes character read_all execution result into the replay log. */ | |
138 | void replay_char_read_all_save_buf(uint8_t *buf, int offset); | |
139 | ||
d73abd6d | 140 | #endif |