From nobody Mon Apr 13 05:24:12 2026 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771000181; cv=none; d=zohomail.com; s=zohoarc; b=aj0QLvwNUJWKg1wE2pbKJ2kI6pez4spUrsn52ZCXi5Q5hiXKHHUZLVE3AawkOjAmbQJHtkMEWhvBdbWU7ercZHkBVT9Mcyxov2E8Xhqj9tuVprtxFSm9VF7AwCX4guh1WIiI5iaB5+M6nt3c4ddix05EaVTNs0xETCmnJT7WahM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771000181; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GtYixxVFRGricJNR3QGHatVLbdL2gCHohkRG/oMMero=; b=SITA91mD1H+gyweqGVdku2lrSCqh3Q0W8hzzyQ6fBDkDBgGLLoADMS1W/NJLjP0Uv35xrM0jViHrrkokOf9ZMyrkduf3KWkB/FZbRFueCjz/bauO+Xsfh/FG0DAEgXc0nEEeEoA9yF2a0F+8LQiLuOj1rW8d4O0W6Uk4ENULKJY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1771000181368143.49567335318955; Fri, 13 Feb 2026 08:29:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1231316.1536543 (Exim 4.92) (envelope-from ) id 1vqw2j-0006wz-99; Fri, 13 Feb 2026 16:29:21 +0000 Received: by outflank-mailman (output) from mailman id 1231316.1536543; Fri, 13 Feb 2026 16:29:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vqw2j-0006v6-1B; Fri, 13 Feb 2026 16:29:21 +0000 Received: by outflank-mailman (input) for mailman id 1231316; Fri, 13 Feb 2026 16:29:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vqw2h-0005Ws-EK for xen-devel@lists.xenproject.org; Fri, 13 Feb 2026 16:29:19 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 250672fc-08f9-11f1-b163-2bf370ae4941; Fri, 13 Feb 2026 17:29:18 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4807068eacbso9047375e9.2 for ; Fri, 13 Feb 2026 08:29:18 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4834d5ebd1bsm303288185e9.6.2026.02.13.08.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 08:29:17 -0800 (PST) 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: 250672fc-08f9-11f1-b163-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771000158; x=1771604958; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GtYixxVFRGricJNR3QGHatVLbdL2gCHohkRG/oMMero=; b=a9hrPUnYVSTpnjsjLOdKvuRFZD9HXiXb2CCe0xQaeZa4r7ZmNX1xF2TDtV0G7l02a8 hPxzBcDf0OeZfbXXtgApM9i5EQ1XzYXJQBaX3Xs94x1FDKGkVvx3DZiOqIVmB9VzvgyC i18Nnb8STNMDv+PsWF0u1xVn6AYMbTdrL1Dt5p1HgHiQqPpVb8NUujhEVAH+uNLCUx+m 0+OEsEBvFfRk3dLVSmxEZWosFeJy0Wd8vwOhb03B40LSDbRKRBelcmf74mpVXVhbFttI LNCP3vupLGsiM9R9UuHjcSNq/FOoVQ0m8zyGWZyMj7RSPRU1OqwsbcueQEdUbs2vHkZU Nkgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771000158; x=1771604958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GtYixxVFRGricJNR3QGHatVLbdL2gCHohkRG/oMMero=; b=BWlBfC7d6Aqr2+4QyRdCNzjzeMH/4Bm1jxMnTEwdgAnbh2QcF+GIzFR53YfhHwMBUA 9VP8BTouq8oP8ZBcEf7+YbEX3XmiX7HkKY0+H0gjguoZ+lTHibQfu0vgLyYNTPwaCtIm wJJLRWmgQzPbUIBqCJbX2GIgJyzjKiq3LMWVw+FIMnOGi/2Wzx7DMkZ2yKNV0Tb09shB IqcVnjdNicxSDYw+MyuiNh6x0P7AQAJJoDnzz2AMAkia5w2eWinYn0gfbW8gFDbpBRQP BtfP2Jyri/OGvkjVN6qgj7x5gEead/DbZA+qszuIRAyzdxWsp7SuTdLsvh/QdrPUGMJG qGRA== X-Gm-Message-State: AOJu0YxLeWJOH5ABvPRdXiCbpWh59uNVNl34qdPbHIlnWYzJnhdP/4Cz 6xNt67WBH0mtsJc6YGJM/GRjmnz/LetlPNhjoYfNcJR5qgAVytfr1YO4P27ywQia X-Gm-Gg: AZuq6aLiZOiIQE2kKeIoCeWed3lRwosKKGFq3bwLtLymUF/+x3dtsRcIeftW2I1U/6Y nWybUpmMrlliKlFk+PuOgbkJG8LxHA0Ipi0mnUIISjivXvsnLsY6gwRq25ApsGSPZz3fAh1Odc2 MX0c7zg4HD/mO2IbJGrDaoTSF1HygV44KMoJxgr6qwtQm0zMqglS2C3m7eACOTMdYo3ca/xef9L 94jbjVFIvta5c4U6boXX7bKtGhKkPzs/Uun0pHqdFuZhUFqX/JJx22zmk+FNNQ4yK3I7ej4AINX ROxlbLpPnJ1LVVhkYigz/XuAactimFn6ni7lZCOBTTvMg5qF482S2Jgtngu10uiBySucv9Xq1g0 px5SUBUAYDmK19wLot0eWYF70F67u8HIGdHAIXgBFxF6+Xfy0aIl18p4YhAGj/B++xDiLciN6C0 +Qdp6OjapA4Q7wJAu+knOspWwms4WX5oVnMw07lf2/5Z+2z+CpPecuiJW1zPN3zfowFowtPvKg7 rTv/dF3 X-Received: by 2002:a05:600c:1907:b0:477:73e9:dc17 with SMTP id 5b1f17b1804b1-48373a79afbmr42485465e9.35.1771000157888; Fri, 13 Feb 2026 08:29:17 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Alistair Francis , Connor Davis Subject: [PATCH v4 07/16] xen/time: move ticks<->ns helpers to common code Date: Fri, 13 Feb 2026 17:28:53 +0100 Message-ID: <360aa61f2a0d1a95268e431909d1f210733d7dc9.1770999383.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771000183468154100 Content-Type: text/plain; charset="utf-8" ticks_to_ns() and ns_to_ticks() are not architecture-specific, so provide a common implementation that is more resilient to overflow than the historical Arm version. This is not a practical issue for Arm, as the latest ARM ARM that timer frequency should be fixed at 1 GHz and older platforms used much lower rates, which is shy of 32-bit overflow. As the helpers are declared as static inline, they should not affect x86, which does not use them. On Arm, these helpers were historically implemented as out-of-line functions because the counter frequency was originally defined as static and unavaila= ble to headers [1]. Later changes [2] removed this restriction, but the helpers remained unchanged. Now they can be implemented as static inline without any issues. Centralising the helpers avoids duplication and removes subtle differences between architectures while keeping the implementation simple. Drop redundant includes where already pulls it in. No functional change is intended. [1] ddee56dc2994 arm: driver for the generic timer for ARMv7 [2] 096578b4e489 xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Suggested-by: Jan Beulich Signed-off-by: Oleksii Kurochko Reviewed-by: Jan Beulich --- Changes in v4: - Nothing changed. Only rebase. --- Changes in v3: - Add Reviewed-by: Jan Beulich . --- Changes in v2: - Move ns_to_ticks() and ticks_to_ns() to common code. --- xen/arch/arm/include/asm/time.h | 3 --- xen/arch/arm/time.c | 11 ----------- xen/arch/arm/vtimer.c | 2 +- xen/arch/riscv/include/asm/time.h | 5 ----- xen/arch/riscv/time.c | 1 + xen/include/xen/time.h | 11 +++++++++++ 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/include/asm/time.h b/xen/arch/arm/include/asm/tim= e.h index 49ad8c1a6d47..c194dbb9f52d 100644 --- a/xen/arch/arm/include/asm/time.h +++ b/xen/arch/arm/include/asm/time.h @@ -101,9 +101,6 @@ extern void init_timer_interrupt(void); /* Counter value at boot time */ extern uint64_t boot_count; =20 -extern s_time_t ticks_to_ns(uint64_t ticks); -extern uint64_t ns_to_ticks(s_time_t ns); - void preinit_xen_time(void); =20 void force_update_vcpu_system_time(struct vcpu *v); diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index cc3fcf47b66a..a12912a106a0 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -27,7 +27,6 @@ #include #include #include -#include #include =20 uint64_t __read_mostly boot_count; @@ -47,16 +46,6 @@ unsigned int timer_get_irq(enum timer_ppi ppi) return timer_irq[ppi]; } =20 -/*static inline*/ s_time_t ticks_to_ns(uint64_t ticks) -{ - return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz); -} - -/*static inline*/ uint64_t ns_to_ticks(s_time_t ns) -{ - return muldiv64(ns, 1000 * cpu_khz, SECONDS(1)); -} - static __initdata struct dt_device_node *timer; =20 #ifdef CONFIG_ACPI diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index d2124b175521..2e85ff2b6e62 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -12,13 +12,13 @@ #include #include #include +#include #include =20 #include #include #include #include -#include #include #include #include diff --git a/xen/arch/riscv/include/asm/time.h b/xen/arch/riscv/include/asm= /time.h index 1e7801e2ea0e..be3875b9984e 100644 --- a/xen/arch/riscv/include/asm/time.h +++ b/xen/arch/riscv/include/asm/time.h @@ -24,11 +24,6 @@ static inline cycles_t get_cycles(void) return csr_read(CSR_TIME); } =20 -static inline s_time_t ticks_to_ns(uint64_t ticks) -{ - return muldiv64(ticks, MILLISECS(1), cpu_khz); -} - void preinit_xen_time(void); =20 #endif /* ASM__RISCV__TIME_H */ diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c index e962f8518d78..2c7af0a5d63b 100644 --- a/xen/arch/riscv/time.c +++ b/xen/arch/riscv/time.c @@ -4,6 +4,7 @@ #include #include #include +#include #include =20 unsigned long __ro_after_init cpu_khz; /* CPU clock frequency in kHz. */ diff --git a/xen/include/xen/time.h b/xen/include/xen/time.h index fe0d7a578a99..2185dd26a439 100644 --- a/xen/include/xen/time.h +++ b/xen/include/xen/time.h @@ -8,6 +8,7 @@ #ifndef __XEN_TIME_H__ #define __XEN_TIME_H__ =20 +#include #include #include =20 @@ -75,6 +76,16 @@ extern void send_timer_event(struct vcpu *v); =20 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds); =20 +static inline s_time_t ticks_to_ns(uint64_t ticks) +{ + return muldiv64(ticks, MILLISECS(1), cpu_khz); +} + +static inline uint64_t ns_to_ticks(s_time_t ns) +{ + return muldiv64(ns, cpu_khz, MILLISECS(1)); +} + #include =20 #endif /* __XEN_TIME_H__ */ --=20 2.52.0