From nobody Sat Jul 12 06:30:37 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ispras.ru Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16506317726651005.2583086908346; Fri, 22 Apr 2022 05:49:32 -0700 (PDT) Received: from localhost ([::1]:48946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhsj5-0001ED-M2 for importer2@patchew.org; Fri, 22 Apr 2022 08:49:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhrrL-0001wJ-4U for qemu-devel@nongnu.org; Fri, 22 Apr 2022 07:53:59 -0400 Received: from mail.ispras.ru ([83.149.199.84]:39414) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhrrH-0005FS-I2 for qemu-devel@nongnu.org; Fri, 22 Apr 2022 07:53:58 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 351B5407626A; Fri, 22 Apr 2022 11:53:31 +0000 (UTC) Subject: [PATCH 4/9] replay: simplify async event processing From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Fri, 22 Apr 2022 14:53:31 +0300 Message-ID: <165062841103.526882.9023955155829649867.stgit@pasha-ThinkPad-X280> In-Reply-To: <165062838915.526882.13230207960407998257.stgit@pasha-ThinkPad-X280> References: <165062838915.526882.13230207960407998257.stgit@pasha-ThinkPad-X280> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=83.149.199.84; envelope-from=pavel.dovgalyuk@ispras.ru; helo=mail.ispras.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pavel.dovgalyuk@ispras.ru, philmd@redhat.com, wrampazz@redhat.com, crosa@redhat.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650631773247100001 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 --- replay/replay-events.c | 36 ++++++++++++++---------------------- replay/replay-internal.h | 29 ++++++++++++++--------------- replay/replay-snapshot.c | 1 - replay/replay.c | 5 +++-- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/replay/replay-events.c b/replay/replay-events.c index db1decf9dd..7bc9d6c2ff 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 !=3D 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); =20 /* 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 =3D=3D -1) { - replay_state.read_event_kind =3D replay_get_byte(); - replay_state.read_event_id =3D -1; - replay_check_error(); - } + int event_kind =3D replay_state.data_kind - EVENT_ASYNC; =20 /* 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 =3D=3D -1) { @@ -236,17 +232,17 @@ static Event *replay_read_event(void) break; case REPLAY_ASYNC_EVENT_INPUT: event =3D g_new0(Event, 1); - event->event_kind =3D replay_state.read_event_kind; + event->event_kind =3D event_kind; event->opaque =3D replay_read_input_event(); return event; case REPLAY_ASYNC_EVENT_INPUT_SYNC: event =3D g_new0(Event, 1); - event->event_kind =3D replay_state.read_event_kind; + event->event_kind =3D event_kind; event->opaque =3D 0; return event; case REPLAY_ASYNC_EVENT_CHAR_READ: event =3D g_new0(Event, 1); - event->event_kind =3D replay_state.read_event_kind; + event->event_kind =3D event_kind; event->opaque =3D 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 =3D g_new0(Event, 1); - event->event_kind =3D replay_state.read_event_kind; + event->event_kind =3D event_kind; event->opaque =3D 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; } =20 QTAILQ_FOREACH(event, &events_list, events) { - if (event->event_kind =3D=3D replay_state.read_event_kind + if (event->event_kind =3D=3D event_kind && (replay_state.read_event_id =3D=3D -1 || replay_state.read_event_id =3D=3D event->id)) { break; @@ -276,12 +271,8 @@ static Event *replay_read_event(void) =20 if (event) { QTAILQ_REMOVE(&events_list, event, events); - } else { - return NULL; } =20 - /* Read event-specific data */ - return event; } =20 @@ -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 =3D=3D EVENT_ASYNC) { + while (replay_state.data_kind >=3D EVENT_ASYNC + && replay_state.data_kind <=3D EVENT_ASYNC_LAST) { Event *event =3D replay_read_event(); if (!event) { break; } replay_finish_event(); - replay_state.read_event_kind =3D -1; + replay_state.read_event_id =3D -1; replay_run_event(event); =20 g_free(event); @@ -304,7 +296,7 @@ void replay_read_events(void) =20 void replay_init_events(void) { - replay_state.read_event_kind =3D -1; + replay_state.read_event_id =3D -1; } =20 void replay_finish_events(void) diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 59797c86cf..3be2e077ad 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -12,6 +12,19 @@ * */ =20 +/* 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 +}; + /* Any changes to order/number of events will need to bump REPLAY_VERSION = */ enum ReplayEvents { /* for instruction event */ @@ -22,6 +35,7 @@ enum ReplayEvents { EVENT_EXCEPTION, /* for async events */ EVENT_ASYNC, + EVENT_ASYNC_LAST =3D EVENT_ASYNC + REPLAY_ASYNC_COUNT - 1, /* for shutdown requests, range allows recovery of ShutdownCause */ EVENT_SHUTDOWN, EVENT_SHUTDOWN_LAST =3D EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX, @@ -49,19 +63,6 @@ enum ReplayEvents { EVENT_COUNT }; =20 -/* 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; =20 typedef struct ReplayState { @@ -83,8 +84,6 @@ typedef struct ReplayState { uint64_t block_request_id; /*! Prior value of the host clock */ uint64_t host_clock_last; - /*! Asynchronous event type read from the log */ - int32_t read_event_kind; /*! Asynchronous event id read from the log */ uint64_t read_event_id; } ReplayState; diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 7e935deb15..10a7cf7992 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -59,7 +59,6 @@ static const VMStateDescription vmstate_replay =3D { VMSTATE_UINT32(has_unread_data, ReplayState), VMSTATE_UINT64(file_offset, ReplayState), VMSTATE_UINT64(block_request_id, ReplayState), - VMSTATE_INT32(read_event_kind, ReplayState), VMSTATE_UINT64(read_event_id, ReplayState), VMSTATE_END_OF_LIST() }, diff --git a/replay/replay.c b/replay/replay.c index cb1b68c46d..f01f79cd38 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -22,7 +22,7 @@ =20 /* Current version of the replay mechanism. Increase it when file format changes. */ -#define REPLAY_VERSION 0xe0200b +#define REPLAY_VERSION 0xe0200c /* Size of replay log header */ #define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t)) =20 @@ -219,7 +219,8 @@ bool replay_has_event(void) replay_account_executed_instructions(); res =3D EVENT_CHECKPOINT <=3D replay_state.data_kind && replay_state.data_kind <=3D EVENT_CHECKPOINT_LAST; - res =3D res || replay_state.data_kind =3D=3D EVENT_ASYNC; + res =3D res || (EVENT_ASYNC <=3D replay_state.data_kind + && replay_state.data_kind <=3D EVENT_ASYNC_LAST); } return res; }