Skip to content

Commit 3e21408

Browse files
Dovgalyukbonzini
authored andcommitted
replay: simplify async event processing
This patch joins replay event id and async event id into single byte in the log. It makes processing a bit faster and log a bit smaller. Signed-off-by: Pavel Dovgalyuk <[email protected]> Reviewed-by: Richard Henderson <[email protected]> -- v2: minor enum fixes (suggested by Richard Henderson) Message-Id: <165364838393.688121.8191379555130516329.stgit@pasha-ThinkPad-X280> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 60618e2 commit 3e21408

File tree

4 files changed

+31
-42
lines changed

4 files changed

+31
-42
lines changed

replay/replay-events.c

+14-22
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ static void replay_save_event(Event *event)
174174
{
175175
if (replay_mode != REPLAY_MODE_PLAY) {
176176
/* put the event into the file */
177-
replay_put_event(EVENT_ASYNC);
178-
replay_put_byte(event->event_kind);
177+
g_assert(event->event_kind < REPLAY_ASYNC_COUNT);
178+
replay_put_event(EVENT_ASYNC + event->event_kind);
179179

180180
/* save event-specific data */
181181
switch (event->event_kind) {
@@ -220,14 +220,10 @@ void replay_save_events(void)
220220
static Event *replay_read_event(void)
221221
{
222222
Event *event;
223-
if (replay_state.read_event_kind == -1) {
224-
replay_state.read_event_kind = replay_get_byte();
225-
replay_state.read_event_id = -1;
226-
replay_check_error();
227-
}
223+
ReplayAsyncEventKind event_kind = replay_state.data_kind - EVENT_ASYNC;
228224

229225
/* Events that has not to be in the queue */
230-
switch (replay_state.read_event_kind) {
226+
switch (event_kind) {
231227
case REPLAY_ASYNC_EVENT_BH:
232228
case REPLAY_ASYNC_EVENT_BH_ONESHOT:
233229
if (replay_state.read_event_id == -1) {
@@ -236,17 +232,17 @@ static Event *replay_read_event(void)
236232
break;
237233
case REPLAY_ASYNC_EVENT_INPUT:
238234
event = g_new0(Event, 1);
239-
event->event_kind = replay_state.read_event_kind;
235+
event->event_kind = event_kind;
240236
event->opaque = replay_read_input_event();
241237
return event;
242238
case REPLAY_ASYNC_EVENT_INPUT_SYNC:
243239
event = g_new0(Event, 1);
244-
event->event_kind = replay_state.read_event_kind;
240+
event->event_kind = event_kind;
245241
event->opaque = 0;
246242
return event;
247243
case REPLAY_ASYNC_EVENT_CHAR_READ:
248244
event = g_new0(Event, 1);
249-
event->event_kind = replay_state.read_event_kind;
245+
event->event_kind = event_kind;
250246
event->opaque = replay_event_char_read_load();
251247
return event;
252248
case REPLAY_ASYNC_EVENT_BLOCK:
@@ -256,18 +252,17 @@ static Event *replay_read_event(void)
256252
break;
257253
case REPLAY_ASYNC_EVENT_NET:
258254
event = g_new0(Event, 1);
259-
event->event_kind = replay_state.read_event_kind;
255+
event->event_kind = event_kind;
260256
event->opaque = replay_event_net_load();
261257
return event;
262258
default:
263-
error_report("Unknown ID %d of replay event",
264-
replay_state.read_event_kind);
259+
error_report("Unknown ID %d of replay event", event_kind);
265260
exit(1);
266261
break;
267262
}
268263

269264
QTAILQ_FOREACH(event, &events_list, events) {
270-
if (event->event_kind == replay_state.read_event_kind
265+
if (event->event_kind == event_kind
271266
&& (replay_state.read_event_id == -1
272267
|| replay_state.read_event_id == event->id)) {
273268
break;
@@ -276,26 +271,23 @@ static Event *replay_read_event(void)
276271

277272
if (event) {
278273
QTAILQ_REMOVE(&events_list, event, events);
279-
} else {
280-
return NULL;
281274
}
282275

283-
/* Read event-specific data */
284-
285276
return event;
286277
}
287278

288279
/* Called with replay mutex locked */
289280
void replay_read_events(void)
290281
{
291282
g_assert(replay_mutex_locked());
292-
while (replay_state.data_kind == EVENT_ASYNC) {
283+
while (replay_state.data_kind >= EVENT_ASYNC
284+
&& replay_state.data_kind <= EVENT_ASYNC_LAST) {
293285
Event *event = replay_read_event();
294286
if (!event) {
295287
break;
296288
}
297289
replay_finish_event();
298-
replay_state.read_event_kind = -1;
290+
replay_state.read_event_id = -1;
299291
replay_run_event(event);
300292

301293
g_free(event);
@@ -304,7 +296,7 @@ void replay_read_events(void)
304296

305297
void replay_init_events(void)
306298
{
307-
replay_state.read_event_kind = -1;
299+
replay_state.read_event_id = -1;
308300
}
309301

310302
void replay_finish_events(void)

replay/replay-internal.h

+14-17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
*
1313
*/
1414

15+
/* Asynchronous events IDs */
16+
17+
typedef enum ReplayAsyncEventKind {
18+
REPLAY_ASYNC_EVENT_BH,
19+
REPLAY_ASYNC_EVENT_BH_ONESHOT,
20+
REPLAY_ASYNC_EVENT_INPUT,
21+
REPLAY_ASYNC_EVENT_INPUT_SYNC,
22+
REPLAY_ASYNC_EVENT_CHAR_READ,
23+
REPLAY_ASYNC_EVENT_BLOCK,
24+
REPLAY_ASYNC_EVENT_NET,
25+
REPLAY_ASYNC_COUNT
26+
} ReplayAsyncEventKind;
27+
1528
/* Any changes to order/number of events will need to bump REPLAY_VERSION */
1629
enum ReplayEvents {
1730
/* for instruction event */
@@ -22,6 +35,7 @@ enum ReplayEvents {
2235
EVENT_EXCEPTION,
2336
/* for async events */
2437
EVENT_ASYNC,
38+
EVENT_ASYNC_LAST = EVENT_ASYNC + REPLAY_ASYNC_COUNT - 1,
2539
/* for shutdown requests, range allows recovery of ShutdownCause */
2640
EVENT_SHUTDOWN,
2741
EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
@@ -49,21 +63,6 @@ enum ReplayEvents {
4963
EVENT_COUNT
5064
};
5165

52-
/* Asynchronous events IDs */
53-
54-
enum ReplayAsyncEventKind {
55-
REPLAY_ASYNC_EVENT_BH,
56-
REPLAY_ASYNC_EVENT_BH_ONESHOT,
57-
REPLAY_ASYNC_EVENT_INPUT,
58-
REPLAY_ASYNC_EVENT_INPUT_SYNC,
59-
REPLAY_ASYNC_EVENT_CHAR_READ,
60-
REPLAY_ASYNC_EVENT_BLOCK,
61-
REPLAY_ASYNC_EVENT_NET,
62-
REPLAY_ASYNC_COUNT
63-
};
64-
65-
typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
66-
6766
typedef struct ReplayState {
6867
/*! Cached clock values. */
6968
int64_t cached_clock[REPLAY_CLOCK_COUNT];
@@ -83,8 +82,6 @@ typedef struct ReplayState {
8382
uint64_t block_request_id;
8483
/*! Prior value of the host clock */
8584
uint64_t host_clock_last;
86-
/*! Asynchronous event type read from the log */
87-
int32_t read_event_kind;
8885
/*! Asynchronous event id read from the log */
8986
uint64_t read_event_id;
9087
} ReplayState;

replay/replay-snapshot.c

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static const VMStateDescription vmstate_replay = {
5959
VMSTATE_UINT32(has_unread_data, ReplayState),
6060
VMSTATE_UINT64(file_offset, ReplayState),
6161
VMSTATE_UINT64(block_request_id, ReplayState),
62-
VMSTATE_INT32(read_event_kind, ReplayState),
6362
VMSTATE_UINT64(read_event_id, ReplayState),
6463
VMSTATE_END_OF_LIST()
6564
},

replay/replay.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* Current version of the replay mechanism.
2424
Increase it when file format changes. */
25-
#define REPLAY_VERSION 0xe0200b
25+
#define REPLAY_VERSION 0xe0200c
2626
/* Size of replay log header */
2727
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
2828

@@ -221,7 +221,8 @@ bool replay_has_event(void)
221221
replay_account_executed_instructions();
222222
res = EVENT_CHECKPOINT <= replay_state.data_kind
223223
&& replay_state.data_kind <= EVENT_CHECKPOINT_LAST;
224-
res = res || replay_state.data_kind == EVENT_ASYNC;
224+
res = res || (EVENT_ASYNC <= replay_state.data_kind
225+
&& replay_state.data_kind <= EVENT_ASYNC_LAST);
225226
}
226227
return res;
227228
}

0 commit comments

Comments
 (0)