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 <Pavel.Dovgalyuk@ispras.ru> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> -- v2: minor enum fixes (suggested by Richard Henderson) Message-Id: <165364838393.688121.8191379555130516329.stgit@pasha-ThinkPad-X280> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
60618e2d77
commit
3e21408b05
@ -174,8 +174,8 @@ static void replay_save_event(Event *event)
|
|||||||
{
|
{
|
||||||
if (replay_mode != REPLAY_MODE_PLAY) {
|
if (replay_mode != REPLAY_MODE_PLAY) {
|
||||||
/* put the event into the file */
|
/* put the event into the file */
|
||||||
replay_put_event(EVENT_ASYNC);
|
g_assert(event->event_kind < REPLAY_ASYNC_COUNT);
|
||||||
replay_put_byte(event->event_kind);
|
replay_put_event(EVENT_ASYNC + event->event_kind);
|
||||||
|
|
||||||
/* save event-specific data */
|
/* save event-specific data */
|
||||||
switch (event->event_kind) {
|
switch (event->event_kind) {
|
||||||
@ -220,14 +220,10 @@ void replay_save_events(void)
|
|||||||
static Event *replay_read_event(void)
|
static Event *replay_read_event(void)
|
||||||
{
|
{
|
||||||
Event *event;
|
Event *event;
|
||||||
if (replay_state.read_event_kind == -1) {
|
ReplayAsyncEventKind event_kind = replay_state.data_kind - EVENT_ASYNC;
|
||||||
replay_state.read_event_kind = replay_get_byte();
|
|
||||||
replay_state.read_event_id = -1;
|
|
||||||
replay_check_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Events that has not to be in the queue */
|
/* Events that has not to be in the queue */
|
||||||
switch (replay_state.read_event_kind) {
|
switch (event_kind) {
|
||||||
case REPLAY_ASYNC_EVENT_BH:
|
case REPLAY_ASYNC_EVENT_BH:
|
||||||
case REPLAY_ASYNC_EVENT_BH_ONESHOT:
|
case REPLAY_ASYNC_EVENT_BH_ONESHOT:
|
||||||
if (replay_state.read_event_id == -1) {
|
if (replay_state.read_event_id == -1) {
|
||||||
@ -236,17 +232,17 @@ static Event *replay_read_event(void)
|
|||||||
break;
|
break;
|
||||||
case REPLAY_ASYNC_EVENT_INPUT:
|
case REPLAY_ASYNC_EVENT_INPUT:
|
||||||
event = g_new0(Event, 1);
|
event = g_new0(Event, 1);
|
||||||
event->event_kind = replay_state.read_event_kind;
|
event->event_kind = event_kind;
|
||||||
event->opaque = replay_read_input_event();
|
event->opaque = replay_read_input_event();
|
||||||
return event;
|
return event;
|
||||||
case REPLAY_ASYNC_EVENT_INPUT_SYNC:
|
case REPLAY_ASYNC_EVENT_INPUT_SYNC:
|
||||||
event = g_new0(Event, 1);
|
event = g_new0(Event, 1);
|
||||||
event->event_kind = replay_state.read_event_kind;
|
event->event_kind = event_kind;
|
||||||
event->opaque = 0;
|
event->opaque = 0;
|
||||||
return event;
|
return event;
|
||||||
case REPLAY_ASYNC_EVENT_CHAR_READ:
|
case REPLAY_ASYNC_EVENT_CHAR_READ:
|
||||||
event = g_new0(Event, 1);
|
event = g_new0(Event, 1);
|
||||||
event->event_kind = replay_state.read_event_kind;
|
event->event_kind = event_kind;
|
||||||
event->opaque = replay_event_char_read_load();
|
event->opaque = replay_event_char_read_load();
|
||||||
return event;
|
return event;
|
||||||
case REPLAY_ASYNC_EVENT_BLOCK:
|
case REPLAY_ASYNC_EVENT_BLOCK:
|
||||||
@ -256,18 +252,17 @@ static Event *replay_read_event(void)
|
|||||||
break;
|
break;
|
||||||
case REPLAY_ASYNC_EVENT_NET:
|
case REPLAY_ASYNC_EVENT_NET:
|
||||||
event = g_new0(Event, 1);
|
event = g_new0(Event, 1);
|
||||||
event->event_kind = replay_state.read_event_kind;
|
event->event_kind = event_kind;
|
||||||
event->opaque = replay_event_net_load();
|
event->opaque = replay_event_net_load();
|
||||||
return event;
|
return event;
|
||||||
default:
|
default:
|
||||||
error_report("Unknown ID %d of replay event",
|
error_report("Unknown ID %d of replay event", event_kind);
|
||||||
replay_state.read_event_kind);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTAILQ_FOREACH(event, &events_list, events) {
|
QTAILQ_FOREACH(event, &events_list, events) {
|
||||||
if (event->event_kind == replay_state.read_event_kind
|
if (event->event_kind == event_kind
|
||||||
&& (replay_state.read_event_id == -1
|
&& (replay_state.read_event_id == -1
|
||||||
|| replay_state.read_event_id == event->id)) {
|
|| replay_state.read_event_id == event->id)) {
|
||||||
break;
|
break;
|
||||||
@ -276,12 +271,8 @@ static Event *replay_read_event(void)
|
|||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
QTAILQ_REMOVE(&events_list, event, events);
|
QTAILQ_REMOVE(&events_list, event, events);
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read event-specific data */
|
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,13 +280,14 @@ static Event *replay_read_event(void)
|
|||||||
void replay_read_events(void)
|
void replay_read_events(void)
|
||||||
{
|
{
|
||||||
g_assert(replay_mutex_locked());
|
g_assert(replay_mutex_locked());
|
||||||
while (replay_state.data_kind == EVENT_ASYNC) {
|
while (replay_state.data_kind >= EVENT_ASYNC
|
||||||
|
&& replay_state.data_kind <= EVENT_ASYNC_LAST) {
|
||||||
Event *event = replay_read_event();
|
Event *event = replay_read_event();
|
||||||
if (!event) {
|
if (!event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
replay_finish_event();
|
replay_finish_event();
|
||||||
replay_state.read_event_kind = -1;
|
replay_state.read_event_id = -1;
|
||||||
replay_run_event(event);
|
replay_run_event(event);
|
||||||
|
|
||||||
g_free(event);
|
g_free(event);
|
||||||
@ -304,7 +296,7 @@ void replay_read_events(void)
|
|||||||
|
|
||||||
void replay_init_events(void)
|
void replay_init_events(void)
|
||||||
{
|
{
|
||||||
replay_state.read_event_kind = -1;
|
replay_state.read_event_id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void replay_finish_events(void)
|
void replay_finish_events(void)
|
||||||
|
@ -12,6 +12,19 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Asynchronous events IDs */
|
||||||
|
|
||||||
|
typedef enum ReplayAsyncEventKind {
|
||||||
|
REPLAY_ASYNC_EVENT_BH,
|
||||||
|
REPLAY_ASYNC_EVENT_BH_ONESHOT,
|
||||||
|
REPLAY_ASYNC_EVENT_INPUT,
|
||||||
|
REPLAY_ASYNC_EVENT_INPUT_SYNC,
|
||||||
|
REPLAY_ASYNC_EVENT_CHAR_READ,
|
||||||
|
REPLAY_ASYNC_EVENT_BLOCK,
|
||||||
|
REPLAY_ASYNC_EVENT_NET,
|
||||||
|
REPLAY_ASYNC_COUNT
|
||||||
|
} ReplayAsyncEventKind;
|
||||||
|
|
||||||
/* Any changes to order/number of events will need to bump REPLAY_VERSION */
|
/* Any changes to order/number of events will need to bump REPLAY_VERSION */
|
||||||
enum ReplayEvents {
|
enum ReplayEvents {
|
||||||
/* for instruction event */
|
/* for instruction event */
|
||||||
@ -22,6 +35,7 @@ enum ReplayEvents {
|
|||||||
EVENT_EXCEPTION,
|
EVENT_EXCEPTION,
|
||||||
/* for async events */
|
/* for async events */
|
||||||
EVENT_ASYNC,
|
EVENT_ASYNC,
|
||||||
|
EVENT_ASYNC_LAST = EVENT_ASYNC + REPLAY_ASYNC_COUNT - 1,
|
||||||
/* for shutdown requests, range allows recovery of ShutdownCause */
|
/* for shutdown requests, range allows recovery of ShutdownCause */
|
||||||
EVENT_SHUTDOWN,
|
EVENT_SHUTDOWN,
|
||||||
EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
|
EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
|
||||||
@ -49,21 +63,6 @@ enum ReplayEvents {
|
|||||||
EVENT_COUNT
|
EVENT_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Asynchronous events IDs */
|
|
||||||
|
|
||||||
enum ReplayAsyncEventKind {
|
|
||||||
REPLAY_ASYNC_EVENT_BH,
|
|
||||||
REPLAY_ASYNC_EVENT_BH_ONESHOT,
|
|
||||||
REPLAY_ASYNC_EVENT_INPUT,
|
|
||||||
REPLAY_ASYNC_EVENT_INPUT_SYNC,
|
|
||||||
REPLAY_ASYNC_EVENT_CHAR_READ,
|
|
||||||
REPLAY_ASYNC_EVENT_BLOCK,
|
|
||||||
REPLAY_ASYNC_EVENT_NET,
|
|
||||||
REPLAY_ASYNC_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
|
|
||||||
|
|
||||||
typedef struct ReplayState {
|
typedef struct ReplayState {
|
||||||
/*! Cached clock values. */
|
/*! Cached clock values. */
|
||||||
int64_t cached_clock[REPLAY_CLOCK_COUNT];
|
int64_t cached_clock[REPLAY_CLOCK_COUNT];
|
||||||
@ -83,8 +82,6 @@ typedef struct ReplayState {
|
|||||||
uint64_t block_request_id;
|
uint64_t block_request_id;
|
||||||
/*! Prior value of the host clock */
|
/*! Prior value of the host clock */
|
||||||
uint64_t host_clock_last;
|
uint64_t host_clock_last;
|
||||||
/*! Asynchronous event type read from the log */
|
|
||||||
int32_t read_event_kind;
|
|
||||||
/*! Asynchronous event id read from the log */
|
/*! Asynchronous event id read from the log */
|
||||||
uint64_t read_event_id;
|
uint64_t read_event_id;
|
||||||
} ReplayState;
|
} ReplayState;
|
||||||
|
@ -59,7 +59,6 @@ static const VMStateDescription vmstate_replay = {
|
|||||||
VMSTATE_UINT32(has_unread_data, ReplayState),
|
VMSTATE_UINT32(has_unread_data, ReplayState),
|
||||||
VMSTATE_UINT64(file_offset, ReplayState),
|
VMSTATE_UINT64(file_offset, ReplayState),
|
||||||
VMSTATE_UINT64(block_request_id, ReplayState),
|
VMSTATE_UINT64(block_request_id, ReplayState),
|
||||||
VMSTATE_INT32(read_event_kind, ReplayState),
|
|
||||||
VMSTATE_UINT64(read_event_id, ReplayState),
|
VMSTATE_UINT64(read_event_id, ReplayState),
|
||||||
VMSTATE_END_OF_LIST()
|
VMSTATE_END_OF_LIST()
|
||||||
},
|
},
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
/* Current version of the replay mechanism.
|
/* Current version of the replay mechanism.
|
||||||
Increase it when file format changes. */
|
Increase it when file format changes. */
|
||||||
#define REPLAY_VERSION 0xe0200b
|
#define REPLAY_VERSION 0xe0200c
|
||||||
/* Size of replay log header */
|
/* Size of replay log header */
|
||||||
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
|
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
|
||||||
|
|
||||||
@ -221,7 +221,8 @@ bool replay_has_event(void)
|
|||||||
replay_account_executed_instructions();
|
replay_account_executed_instructions();
|
||||||
res = EVENT_CHECKPOINT <= replay_state.data_kind
|
res = EVENT_CHECKPOINT <= replay_state.data_kind
|
||||||
&& replay_state.data_kind <= EVENT_CHECKPOINT_LAST;
|
&& replay_state.data_kind <= EVENT_CHECKPOINT_LAST;
|
||||||
res = res || replay_state.data_kind == EVENT_ASYNC;
|
res = res || (EVENT_ASYNC <= replay_state.data_kind
|
||||||
|
&& replay_state.data_kind <= EVENT_ASYNC_LAST);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user