From nobody Thu May 2 02:46:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 165629876358753.5041641438537; Sun, 26 Jun 2022 19:59:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.356187.584255 (Exim 4.92) (envelope-from ) id 1o5exq-0005Ei-81; Mon, 27 Jun 2022 02:59:02 +0000 Received: by outflank-mailman (output) from mailman id 356187.584255; Mon, 27 Jun 2022 02:59:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o5exq-0005Eb-57; Mon, 27 Jun 2022 02:59:02 +0000 Received: by outflank-mailman (input) for mailman id 356187; Mon, 27 Jun 2022 02:59:01 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o5exp-0005ET-BT for xen-devel@lists.xenproject.org; Mon, 27 Jun 2022 02:59:01 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 17468c28-f5c5-11ec-b725-ed86ccbb4733; Mon, 27 Jun 2022 04:58:59 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C2DE223A; Sun, 26 Jun 2022 19:58:58 -0700 (PDT) Received: from a015971.shanghai.arm.com (unknown [10.169.188.104]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 324853F66F; Sun, 26 Jun 2022 19:58:55 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 17468c28-f5c5-11ec-b725-ed86ccbb4733 From: Jiamei Xie To: xen-devel@lists.xenproject.org Cc: Jiamei Xie , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Wei Chen Subject: [PATCH] xen/arm: avoid extra caclulations when setting vtimer in context switch Date: Mon, 27 Jun 2022 10:58:09 +0800 Message-Id: <20220627025809.1985720-1-jiamei.xie@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1656298765265100001 Content-Type: text/plain; charset="utf-8" virt_vtimer_save is calculating the new time for the vtimer in: "v->arch.virt_timer.cval + v->domain->arch.virt_timer_base.offset - boot_count". In this formula, "cval + offset" might cause uint64_t overflow. Changing it to "v->domain->arch.virt_timer_base.offset - boot_count + v->arch.virt_timer.cval" can reduce the possibility of overflow, and "arch.virt_timer_base.offset - boot_count" will be always the same, which has been caculated in domain_vtimer_init. Introduce a new field vtimer_offset.nanoseconds to store this value for arm in struct arch_domain, so we can use it directly and extra caclulations can be avoided. This patch is enlightened from [1]. Signed-off-by: Jiamei Xie [1] https://www.mail-archive.com/xen-devel@lists.xenproject.org/msg123139.h= tm --- xen/arch/arm/include/asm/domain.h | 4 ++++ xen/arch/arm/vtimer.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/d= omain.h index ed63c2b6f9..94fe5b6444 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -73,6 +73,10 @@ struct arch_domain uint64_t offset; } virt_timer_base; =20 + struct { + int64_t nanoseconds; + } vtimer_offset; + struct vgic_dist vgic; =20 struct vuart { diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index 6b78fea77d..54161e5fea 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -64,6 +64,7 @@ int domain_vtimer_init(struct domain *d, struct xen_arch_= domainconfig *config) { d->arch.virt_timer_base.offset =3D get_cycles(); d->time_offset.seconds =3D ticks_to_ns(d->arch.virt_timer_base.offset = - boot_count); + d->arch.vtimer_offset.nanoseconds =3D d->time_offset.seconds; do_div(d->time_offset.seconds, 1000000000); =20 config->clock_frequency =3D timer_dt_clock_frequency; @@ -144,8 +145,9 @@ void virt_timer_save(struct vcpu *v) if ( (v->arch.virt_timer.ctl & CNTx_CTL_ENABLE) && !(v->arch.virt_timer.ctl & CNTx_CTL_MASK)) { - set_timer(&v->arch.virt_timer.timer, ticks_to_ns(v->arch.virt_time= r.cval + - v->domain->arch.virt_timer_base.offset - boot_count)); + set_timer(&v->arch.virt_timer.timer, + v->domain->arch.vtimer_offset.nanoseconds + + ticks_to_ns(v->arch.virt_timer.cval)); } } =20 --=20 2.25.1