[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 05/14] xen/time: move ticks<->ns helpers to common code


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 3 Mar 2026 14:56:50 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=gmail.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XZJ6unCO6hnV4jRvbsZ0yfL6SFJrbINWnvnbn3XZ/9k=; b=F1zyermFNIMaEh3DaCRY9DXshqLXO3t+OiQPH6DunBo4CIEsyttLX8OnffVq5/phyGBcvFRHCsoOW1h/9rQ4141ZUwQnTeXZ7Od6tw8L3fX34LjhozSYqPUYYyItkYuC8+cnUnOzL+uHGS04rQidFElSmEAyCv8EpBuHDYeuVzhux6cqabH2i8dKlVmOOGG/aGgDRZ8QJUWw/zUlGvEy0X4gIhYeJxOdoaoy2VplOZnJ+1k6EZrxcteA8UN88d++KEZvrr/WbmNz1uHwcT5D2lwnqoc35UxopK6DGj+s+RgWi/C0mKYTV7fimR9fvLpSnrjsOp8kD00gkkOtpnYhWQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XZJ6unCO6hnV4jRvbsZ0yfL6SFJrbINWnvnbn3XZ/9k=; b=VMClxGhBoX2uecS0Zg+OsC00Hz4eilpHmQl107OKH0TXX4FKXJ9IzQHy5I/ttd+f9AdrFdDljY3Urj8gJiWrD4zipf3uSwvM6omrD9BGZIiNNOqaRJWAMVNqckHBJ+d5St7ZiEntZaJUwXc6BSJQdcBJsnhjVB490TyAnB3X39dnIgMqGbSEoHycMhg5oKHtaqauYE+tPNgs4B+JJ06Jm1nePeTvc0TjroWr4ho5ytJyb1uGtw1SPEO6F1kMN6f1Y6BC8b6wZ6iPnUZNND2e4lNTYBP1Mv+/wqCKjylD3cJmUUkT+kAMT2QWKEVtAkPMRq7d5kK7ZPPAxQtsnbAwBQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=QUadyBHxJzuQnJiBDFzuoTvJrwMR6HoAu3yLR3UZdiCCAvIL9vIWZOUf3Nw2Fm2qxde5QTy4O3cBQK820JY05yzmzgpQwzvXZyON+iMgxkk68/PfE0szIxJzNnn7zxPNvbpsFS5kE+Fr0YcviO4hpWRNM9aDMhW+5Tk9Gwgui7nwiTq0cgVkg31f5FWcVlFmtBxP7x+0ohrBaOn9lgx8lmCHGTqJrY9pV/wMHBPVvg8vcLemG+Eq+b7tEd4ZpZxHzziYVlrlzR9vC8YRkX17Hfnm/W8Ed3IgROjLtE09ns7F1CgPIoM+05q299UP/s+FS3lOwavbTLcN8YJBjT1GPw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZR+ghtcmeVNLUajld7A4uQ6DlxuVrhFVhy+wGUMgpEzGyusYe07BKZu7N2E5F3PzEaKC+by1zaFHRZHe3CfeNGKp8pz8jeuM4/zr5AVF8FTK3SMEnYF3nAi49YW8vkgtzENT8TJzoSh2JprXn9hSiowb7BQWYDPaB78mbmFfrq0XGcopfxfSYpSVqwnpEvN+TUpzXMbEzftqWbbqRC61FlvV24IXcnurN13Nx3ZN6sC2Qb2r3P6WaT1jFHUdyH6K6aRBc3w1m9s1Ve4Q1kKkFUOFx34WAguVQqIen3v0qbVP7EgewBFhD5AaXMvqFLo2UN/r15u1uFPHw5KYyt3p9w==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>
  • Delivery-date: Tue, 03 Mar 2026 14:58:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHcpxZBc3YdHjKklE6Q6qyeWG5VUrWc7bSA
  • Thread-topic: [PATCH v6 05/14] xen/time: move ticks<->ns helpers to common code

Hi Oleksii

> On 26 Feb 2026, at 12:51, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx> wrote:
> 
> 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 unavailable
> 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 <asm/time.h> includes where <xen/time.h> 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 <jbeulich@xxxxxxxx>
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Computation is changing a bit from MS to S removing the 1000 factor on arm
but i do not think this would have an impact so:

Acked-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

Cheers
Bertrand

> ---
> Changes in v4-v6:
> - Nothing changed. Only rebase.
> ---
> Changes in v3:
> - Add Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>.
> ---
> 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/time.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;
> 
> -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);
> 
> 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 <asm/cpufeature.h>
> #include <asm/platform.h>
> #include <asm/system.h>
> -#include <asm/time.h>
> #include <asm/vgic.h>
> 
> uint64_t __read_mostly boot_count;
> @@ -47,16 +46,6 @@ unsigned int timer_get_irq(enum timer_ppi ppi)
>     return timer_irq[ppi];
> }
> 
> -/*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;
> 
> #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 <xen/lib.h>
> #include <xen/perfc.h>
> #include <xen/sched.h>
> +#include <xen/time.h>
> #include <xen/timer.h>
> 
> #include <asm/cpregs.h>
> #include <asm/div64.h>
> #include <asm/irq.h>
> #include <asm/regs.h>
> -#include <asm/time.h>
> #include <asm/vgic.h>
> #include <asm/vreg.h>
> #include <asm/vtimer.h>
> 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);
> }
> 
> -static inline s_time_t ticks_to_ns(uint64_t ticks)
> -{
> -    return muldiv64(ticks, MILLISECS(1), cpu_khz);
> -}
> -
> void preinit_xen_time(void);
> 
> #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 <xen/init.h>
> #include <xen/lib.h>
> #include <xen/sections.h>
> +#include <xen/time.h>
> #include <xen/types.h>
> 
> 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__
> 
> +#include <xen/muldiv64.h>
> #include <xen/types.h>
> #include <public/xen.h>
> 
> @@ -75,6 +76,16 @@ extern void send_timer_event(struct vcpu *v);
> 
> void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds);
> 
> +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 <asm/time.h>
> 
> #endif /* __XEN_TIME_H__ */
> -- 
> 2.53.0
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.