xen/time: move ticks<->ns helpers to common code

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] ddee56dc29 arm: driver for the generic timer for ARMv7
[2] 096578b4e4 xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and
                      XEN_SYSCTL_topologyinfo to common code

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Bertrand Marquis <bertrand.marquis@arm.com>
This commit is contained in:
Oleksii Kurochko authored and Jan Beulich committed 2026-03-04 08:24:28 +01:00
1 parent 16c3761129
commit c66d203577
6 files changed
+13 -20

No files matched your search

-3
View File
@@ -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);
-11
View File
@@ -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
+1 -1
View File
@@ -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>
-5
View File
@@ -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 */
+1
View File
@@ -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. */
+11
View File
@@ -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__ */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.