From nobody Sat May 4 09:18:41 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151375674893626.787034197631897; Tue, 19 Dec 2017 23:59:08 -0800 (PST) Received: from localhost ([::1]:38602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRZHK-0003xc-LE for importer@patchew.org; Wed, 20 Dec 2017 02:59:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRZGT-0003dC-Qo for qemu-devel@nongnu.org; Wed, 20 Dec 2017 02:58:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRZGQ-0001gk-J6 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 02:58:09 -0500 Received: from mail.ispras.ru ([83.149.199.45]:45036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRZGQ-0001f8-9e for qemu-devel@nongnu.org; Wed, 20 Dec 2017 02:58:06 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 5946654006A; Wed, 20 Dec 2017 10:58:03 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 10:58:04 +0300 Message-ID: <20171220075804.15036.93598.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] [ PATCH ] hpet: recover timer offset correctly 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: mst@redhat.com, quintela@redhat.com, dgilbert@redhat.com, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 HPET saves its state by calculating the current time and recovers timer offset using this calculated value. But these calculations include divisions and multiplications. Therefore the timer state cannot be recovered precise enough. This patch introduces saving of the original value of the offset to preserve the determinism of the timer. Signed-off-by: Maria Klimushenkova Signed-off-by: Pavel Dovgalyuk --- hw/timer/hpet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 577371b..4cf6a5b 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -221,7 +221,9 @@ static int hpet_pre_save(void *opaque) HPETState *s =3D opaque; =20 /* save current counter value */ - s->hpet_counter =3D hpet_get_ticks(s); + if (hpet_enabled(s)) { + s->hpet_counter =3D hpet_get_ticks(s); + } =20 return 0; } @@ -252,7 +254,10 @@ static int hpet_post_load(void *opaque, int version_id) HPETState *s =3D opaque; =20 /* Recalculate the offset between the main counter and guest time */ - s->hpet_offset =3D ticks_to_ns(s->hpet_counter) - qemu_clock_get_ns(QE= MU_CLOCK_VIRTUAL); + if (version_id <=3D 2) { + s->hpet_offset =3D ticks_to_ns(s->hpet_counter) + - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + } =20 /* Push number of timers into capability returned via HPET_ID */ s->capability &=3D ~HPET_ID_NUM_TIM_MASK; @@ -303,7 +308,7 @@ static const VMStateDescription vmstate_hpet_timer =3D { =20 static const VMStateDescription vmstate_hpet =3D { .name =3D "hpet", - .version_id =3D 2, + .version_id =3D 3, .minimum_version_id =3D 1, .pre_save =3D hpet_pre_save, .pre_load =3D hpet_pre_load, @@ -312,6 +317,7 @@ static const VMStateDescription vmstate_hpet =3D { VMSTATE_UINT64(config, HPETState), VMSTATE_UINT64(isr, HPETState), VMSTATE_UINT64(hpet_counter, HPETState), + VMSTATE_UINT64_V(hpet_offset, HPETState, 3), VMSTATE_UINT8_V(num_timers, HPETState, 2), VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers), VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,