From nobody Sun Apr 28 17:58:20 2024 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; 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509447041088825.0931960014267; Tue, 31 Oct 2017 03:50:41 -0700 (PDT) Received: from localhost ([::1]:44697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U7v-00079U-97 for importer@patchew.org; Tue, 31 Oct 2017 06:50:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U5y-0005w1-7P for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:48:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9U5u-0004Ei-2b for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:48:34 -0400 Received: from mail.ispras.ru ([83.149.199.45]:39914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9U5t-0004EY-RN for qemu-devel@nongnu.org; Tue, 31 Oct 2017 06:48:30 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 1DCBD54006A; Tue, 31 Oct 2017 13:48:29 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 13:48:30 +0300 Message-ID: <20171031104830.3079.58104.stgit@pasha-VirtualBox> In-Reply-To: <20171031104741.3079.26584.stgit@pasha-VirtualBox> References: <20171031104741.3079.26584.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFCPATCH09/20] replay: save prior value of the host 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: , Cc: dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds saving/restoring of the host clock field 'last'. It is used in host clock calculation and therefore clock may become incorrect when using restored vmstate. Signed-off-by: Pavel Dovgalyuk --- include/qemu/timer.h | 14 ++++++++++++++ replay/replay-internal.h | 2 ++ replay/replay-snapshot.c | 3 +++ util/qemu-timer.c | 12 ++++++++++++ 4 files changed, 31 insertions(+) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 1b518bc..a610a17 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -251,6 +251,20 @@ bool qemu_clock_run_timers(QEMUClockType type); */ bool qemu_clock_run_all_timers(void); =20 +/** + * qemu_clock_get_last: + * + * Returns last clock query time. + */ +uint64_t qemu_clock_get_last(QEMUClockType type); +/** + * qemu_clock_set_last: + * + * Sets last clock query time. + */ +void qemu_clock_set_last(QEMUClockType type, uint64_t last); + + /* * QEMUTimerList */ diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 3ebb199..be96d7e 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -78,6 +78,8 @@ typedef struct ReplayState { This counter is global, because requests from different block devices should not get overlapping ids. */ uint64_t block_request_id; + /*! Prior value of the host clock */ + uint64_t host_clock_last; } ReplayState; extern ReplayState replay_state; =20 diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 7075986..e0b2204 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -25,6 +25,7 @@ static int replay_pre_save(void *opaque) { ReplayState *state =3D opaque; state->file_offset =3D ftell(replay_file); + state->host_clock_last =3D qemu_clock_get_last(QEMU_CLOCK_HOST); =20 return 0; } @@ -33,6 +34,7 @@ static int replay_post_load(void *opaque, int version_id) { ReplayState *state =3D opaque; fseek(replay_file, state->file_offset, SEEK_SET); + qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last); /* If this was a vmstate, saved in recording mode, we need to initialize replay data fields. */ replay_fetch_data_kind(); @@ -54,6 +56,7 @@ static const VMStateDescription vmstate_replay =3D { VMSTATE_UINT32(has_unread_data, ReplayState), VMSTATE_UINT64(file_offset, ReplayState), VMSTATE_UINT64(block_request_id, ReplayState), + VMSTATE_UINT64(host_clock_last, ReplayState), VMSTATE_END_OF_LIST() }, }; diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 82d5650..2ed1bf2 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -622,6 +622,18 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } =20 +uint64_t qemu_clock_get_last(QEMUClockType type) +{ + QEMUClock *clock =3D qemu_clock_ptr(type); + return clock->last; +} + +void qemu_clock_set_last(QEMUClockType type, uint64_t last) +{ + QEMUClock *clock =3D qemu_clock_ptr(type); + clock->last =3D last; +} + void qemu_clock_register_reset_notifier(QEMUClockType type, Notifier *notifier) {