From nobody Mon Feb 9 16:34:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539898322744181.86549962041238; Thu, 18 Oct 2018 14:32:02 -0700 (PDT) Received: from localhost ([::1]:44847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFth-0000OJ-GG for importer@patchew.org; Thu, 18 Oct 2018 17:32:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEz0-0008Mu-W8 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyy-0006sf-1j for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:25 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:39657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyq-0006kc-97 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:33:17 -0400 Received: by mail-wm1-x330.google.com with SMTP id y144-v6so1608645wmd.4 for ; Thu, 18 Oct 2018 13:33:11 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.33.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=8r3sTWBWhTiD/8sRkve63BtWuTsIlPBKBUDE414YNPE=; b=dcOSso+U1rMAGfx+EhlSafovuQmVbYVvevktFeBC4W/9VZjTZKYAleuz4oOAydY35q TGc2ejuZrpJMJ6gTEHPLNaHMlS2feZNTPx0yKHnYMQZcPDsE56tuMYRAzrxVCXqHEs9O Ea0TpAwmn0avzytlJxspE2V+kCyq/GJFhv5FFtiwEXT6jFfKLegAjh2dpofzCftM2f/J zX4ydRCYT5vBMWLTHgUSMBEhvJUHE/CyyfwXhiwHT9aXnrFCdBpce4/gPSaLRVHrbrmx UBAe2EvHXXUsxMZn6oY5IluOfhRdbBFleVMf35K/z06h+bzCFlw8ZCgGMHjrXAmHzcM+ MRFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=8r3sTWBWhTiD/8sRkve63BtWuTsIlPBKBUDE414YNPE=; b=pJ67D/2cDd2RWnUu0RBA7BqqFbiW3KEpSmbSX16m9SnftNK50kiS531Ui/cjNUQj6o D0To4sQnMOhHK1wdiuLJUcp+SIzF2tct9ferwdbSobLp+SlsTXotjPQo75Qba7CUYDx8 ZBqyGizmVhQ5lQ1Og+EnJK55Yo4P5t82JPCIh767LR3tFAlFGrwrgnAtpCsGY+Nqki/H zsO+Ee8Ilq+W3K0zKYttJPiRm0nfED9w2mebHLC1U70zSNPo66gWO+3bYex4pZOHHXcC Nonc4lRRhI/oOwYRFwJWZIPVt7kxrz0MHYCjj+8WbE34WVdZPKg8eW6xXOZSvY+EYuO+ 4QgA== X-Gm-Message-State: ABuFfohV4vu6lzBUbITt4xH55+iFuORfJiabfYoQLks0Vu0vorilRNnN puLULphLSMjc/pwsmmN1EpBb4L3E X-Google-Smtp-Source: ACcGV60luzgsjbWlpn8i/5iNydiGVzAw30ZF9GnEY//P0ipDVc0SBq+dCdAvQTHrXyQz7znEP8Qn/g== X-Received: by 2002:a1c:af07:: with SMTP id y7-v6mr1940398wme.33.1539894790727; Thu, 18 Oct 2018 13:33:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:32:15 +0200 Message-Id: <1539894735-14232-49-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::330 Subject: [Qemu-devel] [PULL 48/48] replay: pass raw icount value to replay_save_clock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This avoids lock recursion when REPLAY_CLOCK is called inside the timers spinlock. Signed-off-by: Paolo Bonzini --- cpus.c | 4 ++-- include/sysemu/replay.h | 10 ++++++++-- replay/replay-internal.c | 25 +++++++++++++++---------- replay/replay-internal.h | 2 ++ replay/replay-time.c | 8 +++++--- stubs/cpu-get-icount.c | 5 +++++ stubs/replay.c | 2 +- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/cpus.c b/cpus.c index 361678e..1c741bc 100644 --- a/cpus.c +++ b/cpus.c @@ -509,8 +509,8 @@ static void icount_warp_rt(void) seqlock_write_lock(&timers_state.vm_clock_seqlock, &timers_state.vm_clock_lock); if (runstate_is_running()) { - int64_t clock =3D REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT, - cpu_get_clock_locked()); + int64_t clock =3D REPLAY_CLOCK_LOCKED(REPLAY_CLOCK_VIRTUAL_RT, + cpu_get_clock_locked()); int64_t warp_delta; =20 warp_delta =3D clock - timers_state.vm_clock_warp_start; diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 7f7a594..3a7c58e 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -100,14 +100,20 @@ bool replay_has_interrupt(void); /* Processing clocks and other time sources */ =20 /*! Save the specified clock */ -int64_t replay_save_clock(ReplayClockKind kind, int64_t clock); +int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, + int64_t raw_icount); /*! Read the specified clock from the log or return cached data */ int64_t replay_read_clock(ReplayClockKind kind); /*! Saves or reads the clock depending on the current replay mode. */ #define REPLAY_CLOCK(clock, value) \ (replay_mode =3D=3D REPLAY_MODE_PLAY ? replay_read_clock((clock)) = \ : replay_mode =3D=3D REPLAY_MODE_RECORD = \ - ? replay_save_clock((clock), (value)) \ + ? replay_save_clock((clock), (value), cpu_get_icount_raw()) \ + : (value)) +#define REPLAY_CLOCK_LOCKED(clock, value) \ + (replay_mode =3D=3D REPLAY_MODE_PLAY ? replay_read_clock((clock)) = \ + : replay_mode =3D=3D REPLAY_MODE_RECORD = \ + ? replay_save_clock((clock), (value), cpu_get_icount_raw_locke= d()) \ : (value)) =20 /* Events */ diff --git a/replay/replay-internal.c b/replay/replay-internal.c index b077cb5..1cea1d4 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -217,20 +217,25 @@ void replay_mutex_unlock(void) } } =20 +void replay_advance_current_step(uint64_t current_step) +{ + int diff =3D (int)(replay_get_current_step() - replay_state.current_st= ep); + + /* Time can only go forward */ + assert(diff >=3D 0); + + if (diff > 0) { + replay_put_event(EVENT_INSTRUCTION); + replay_put_dword(diff); + replay_state.current_step +=3D diff; + } +} + /*! Saves cached instructions. */ void replay_save_instructions(void) { if (replay_file && replay_mode =3D=3D REPLAY_MODE_RECORD) { g_assert(replay_mutex_locked()); - int diff =3D (int)(replay_get_current_step() - replay_state.curren= t_step); - - /* Time can only go forward */ - assert(diff >=3D 0); - - if (diff > 0) { - replay_put_event(EVENT_INSTRUCTION); - replay_put_dword(diff); - replay_state.current_step +=3D diff; - } + replay_advance_current_step(replay_get_current_step()); } } diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 9b0fd91..af6f4d5 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -122,6 +122,8 @@ void replay_finish_event(void); data_kind variable. */ void replay_fetch_data_kind(void); =20 +/*! Advance replay_state.current_step to the specified value. */ +void replay_advance_current_step(uint64_t current_step); /*! Saves queued events (like instructions and sound). */ void replay_save_instructions(void); =20 diff --git a/replay/replay-time.c b/replay/replay-time.c index 6a7565e..0df1693 100644 --- a/replay/replay-time.c +++ b/replay/replay-time.c @@ -15,13 +15,15 @@ #include "replay-internal.h" #include "qemu/error-report.h" =20 -int64_t replay_save_clock(ReplayClockKind kind, int64_t clock) +int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, int64_t raw= _icount) { - if (replay_file) { g_assert(replay_mutex_locked()); =20 - replay_save_instructions(); + /* Due to the caller's locking requirements we get the icount from= it + * instead of using replay_save_instructions(). + */ + replay_advance_current_step(raw_icount); replay_put_event(EVENT_CLOCK + kind); replay_put_qword(clock); } diff --git a/stubs/cpu-get-icount.c b/stubs/cpu-get-icount.c index 0b7239d..35f0c1e 100644 --- a/stubs/cpu-get-icount.c +++ b/stubs/cpu-get-icount.c @@ -11,6 +11,11 @@ int64_t cpu_get_icount(void) abort(); } =20 +int64_t cpu_get_icount_raw(void) +{ + abort(); +} + void qemu_timer_notify_cb(void *opaque, QEMUClockType type) { qemu_notify_event(); diff --git a/stubs/replay.c b/stubs/replay.c index 04279ab..4ac6078 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -4,7 +4,7 @@ =20 ReplayMode replay_mode; =20 -int64_t replay_save_clock(unsigned int kind, int64_t clock) +int64_t replay_save_clock(unsigned int kind, int64_t clock, int64_t raw_ic= ount) { abort(); return 0; --=20 1.8.3.1