aboutsummaryrefslogtreecommitdiff
path: root/replay/replay-events.c
diff options
context:
space:
mode:
authorPavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>2022-05-27 13:46:23 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2022-06-06 09:26:53 +0200
commit3e21408b0596aa2babe1e26996a15e7ad5eee71a (patch)
treebf75b38196d4954205aecba7bd279abe7d484ce7 /replay/replay-events.c
parent60618e2d77691e44bb78e23b2b0cf07b5c405e56 (diff)
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>
Diffstat (limited to 'replay/replay-events.c')
-rw-r--r--replay/replay-events.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/replay/replay-events.c b/replay/replay-events.c
index db1decf9dd..af0721cc1a 100644
--- a/replay/replay-events.c
+++ b/replay/replay-events.c
@@ -174,8 +174,8 @@ static void replay_save_event(Event *event)
{
if (replay_mode != REPLAY_MODE_PLAY) {
/* put the event into the file */
- replay_put_event(EVENT_ASYNC);
- replay_put_byte(event->event_kind);
+ g_assert(event->event_kind < REPLAY_ASYNC_COUNT);
+ replay_put_event(EVENT_ASYNC + event->event_kind);
/* save event-specific data */
switch (event->event_kind) {
@@ -220,14 +220,10 @@ void replay_save_events(void)
static Event *replay_read_event(void)
{
Event *event;
- if (replay_state.read_event_kind == -1) {
- replay_state.read_event_kind = replay_get_byte();
- replay_state.read_event_id = -1;
- replay_check_error();
- }
+ ReplayAsyncEventKind event_kind = replay_state.data_kind - EVENT_ASYNC;
/* 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_ONESHOT:
if (replay_state.read_event_id == -1) {
@@ -236,17 +232,17 @@ static Event *replay_read_event(void)
break;
case REPLAY_ASYNC_EVENT_INPUT:
event = g_new0(Event, 1);
- event->event_kind = replay_state.read_event_kind;
+ event->event_kind = event_kind;
event->opaque = replay_read_input_event();
return event;
case REPLAY_ASYNC_EVENT_INPUT_SYNC:
event = g_new0(Event, 1);
- event->event_kind = replay_state.read_event_kind;
+ event->event_kind = event_kind;
event->opaque = 0;
return event;
case REPLAY_ASYNC_EVENT_CHAR_READ:
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();
return event;
case REPLAY_ASYNC_EVENT_BLOCK:
@@ -256,18 +252,17 @@ static Event *replay_read_event(void)
break;
case REPLAY_ASYNC_EVENT_NET:
event = g_new0(Event, 1);
- event->event_kind = replay_state.read_event_kind;
+ event->event_kind = event_kind;
event->opaque = replay_event_net_load();
return event;
default:
- error_report("Unknown ID %d of replay event",
- replay_state.read_event_kind);
+ error_report("Unknown ID %d of replay event", event_kind);
exit(1);
break;
}
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 == event->id)) {
break;
@@ -276,12 +271,8 @@ static Event *replay_read_event(void)
if (event) {
QTAILQ_REMOVE(&events_list, event, events);
- } else {
- return NULL;
}
- /* Read event-specific data */
-
return event;
}
@@ -289,13 +280,14 @@ static Event *replay_read_event(void)
void replay_read_events(void)
{
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();
if (!event) {
break;
}
replay_finish_event();
- replay_state.read_event_kind = -1;
+ replay_state.read_event_id = -1;
replay_run_event(event);
g_free(event);
@@ -304,7 +296,7 @@ void replay_read_events(void)
void replay_init_events(void)
{
- replay_state.read_event_kind = -1;
+ replay_state.read_event_id = -1;
}
void replay_finish_events(void)