From nobody Tue Feb 10 11:35:25 2026 Delivered-To: importer@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+importer=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 1635246872474994.0700276859211; Tue, 26 Oct 2021 04:14:32 -0700 (PDT) Received: from localhost ([::1]:54598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfKPX-0008VS-Dz for importer@patchew.org; Tue, 26 Oct 2021 07:14:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfJk1-0006YN-FH for qemu-devel@nongnu.org; Tue, 26 Oct 2021 06:31:37 -0400 Received: from mail.ispras.ru ([83.149.199.84]:39288) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfJjy-00050Q-1T for qemu-devel@nongnu.org; Tue, 26 Oct 2021 06:31:37 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 0846540A2BAE; Tue, 26 Oct 2021 10:31:22 +0000 (UTC) Subject: [PATCH] hw/net: store timers for e1000 in vmstate From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 26 Oct 2021 13:31:21 +0300 Message-ID: <163524428177.1917083.7115508068018047923.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+importer=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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, pavel.dovgalyuk@ispras.ru, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1635246873624100001 Setting timers randomly when vmstate is loaded breaks execution determinism. Therefore this patch allows saving mit and autoneg timers for e1000. It makes execution deterministic and allows snapshotting and reverse debugging in icount mode. Signed-off-by: Pavel Dovgalyuk --- hw/net/e1000.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index a30546c5d5..2f706f7298 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -37,6 +37,7 @@ #include "qemu/iov.h" #include "qemu/module.h" #include "qemu/range.h" +#include "sysemu/replay.h" =20 #include "e1000x_common.h" #include "trace.h" @@ -1407,7 +1408,7 @@ static int e1000_pre_save(void *opaque) * complete auto-negotiation immediately. This allows us to look * at MII_SR_AUTONEG_COMPLETE to infer link status on load. */ - if (nc->link_down && have_autoneg(s)) { + if (replay_mode =3D=3D REPLAY_MODE_NONE && nc->link_down && have_auton= eg(s)) { s->phy_reg[PHY_STATUS] |=3D MII_SR_AUTONEG_COMPLETE; } =20 @@ -1438,22 +1439,12 @@ static int e1000_post_load(void *opaque, int versio= n_id) s->mac_reg[TADV] =3D 0; s->mit_irq_level =3D false; } - s->mit_ide =3D 0; - s->mit_timer_on =3D true; - timer_mod(s->mit_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1); =20 /* nc.link_down can't be migrated, so infer link_down according * to link status bit in mac_reg[STATUS]. * Alternatively, restart link negotiation if it was in progress. */ nc->link_down =3D (s->mac_reg[STATUS] & E1000_STATUS_LU) =3D=3D 0; =20 - if (have_autoneg(s) && - !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) { - nc->link_down =3D false; - timer_mod(s->autoneg_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); - } - s->tx.props =3D s->mig_props; if (!s->received_tx_tso) { /* We received only one set of offload data (tx.props) @@ -1472,6 +1463,13 @@ static int e1000_tx_tso_post_load(void *opaque, int = version_id) return 0; } =20 +static int e1000_mit_timer_post_load(void *opaque, int version_id) +{ + E1000State *s =3D opaque; + s->mit_timer_on =3D true; + return 0; +} + static bool e1000_mit_state_needed(void *opaque) { E1000State *s =3D opaque; @@ -1493,6 +1491,21 @@ static bool e1000_tso_state_needed(void *opaque) return chkflag(TSO); } =20 +static bool e1000_mit_timer_needed(void *opaque) +{ + E1000State *s =3D opaque; + + return s->mit_timer_on; +} + +static bool e1000_autoneg_timer_needed(void *opaque) +{ + E1000State *s =3D opaque; + + return have_autoneg(s) + && !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE); +} + static const VMStateDescription vmstate_e1000_mit_state =3D { .name =3D "e1000/mit_state", .version_id =3D 1, @@ -1541,6 +1554,30 @@ static const VMStateDescription vmstate_e1000_tx_tso= _state =3D { } }; =20 +static const VMStateDescription vmstate_e1000_mit_timer =3D { + .name =3D "e1000/mit_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D e1000_mit_timer_needed, + .post_load =3D e1000_mit_timer_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER_PTR(mit_timer, E1000State), + VMSTATE_UINT32(mit_ide, E1000State), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_e1000_autoneg_timer =3D { + .name =3D "e1000/autoneg_timer", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D e1000_autoneg_timer_needed, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER_PTR(autoneg_timer, E1000State), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_e1000 =3D { .name =3D "e1000", .version_id =3D 2, @@ -1622,6 +1659,8 @@ static const VMStateDescription vmstate_e1000 =3D { &vmstate_e1000_mit_state, &vmstate_e1000_full_mac_state, &vmstate_e1000_tx_tso_state, + &vmstate_e1000_mit_timer, + &vmstate_e1000_autoneg_timer, NULL } };