Re: [PATCH 1/3] x86/tsc: Replace magic constants with xxx_PER_SEC

From: Petr Tesarik

Date: Mon Oct 12 2026 - 02:17:03 EST


On Fri, 9 Oct 2026 15:37:58 +0200
Thorsten Blum <blum@xxxxxxxxxx> wrote:

> On Fri, Oct 09, 2026 at 12:04:34PM +0200, Petr Tesarik wrote:
> > Make it clear that these constants refer to the conversion between seconds
> > and milliseconds or nanoseconds.
> >
> > No functional change intended.
> >
> > Signed-off-by: Petr Tesarik <ptesarik@xxxxxxxx>
> > ---
> > arch/x86/kernel/tsc.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> > index 723347e2cf7f8..bac81d37a90ce 100644
> > --- a/arch/x86/kernel/tsc.c
> > +++ b/arch/x86/kernel/tsc.c
> > @@ -253,7 +253,7 @@ noinstr u64 native_sched_clock(void)
> > */
> >
> > /* No locking but a rare wrong value is not a big deal: */
> > - return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ);
> > + return (jiffies_64 - INITIAL_JIFFIES) * (NSEC_PER_SEC / HZ);
> > }
>
> Maybe use TICK_NSEC here?

Note that the current code always rounds down. TICK_NSEC rounds to the
nearest integer, but since it makes no difference for any possible
value of HZ (100, 250, 300, 1000), I'm going to go for it anyway.

That said, there are other occurences of NSEC_PER_SEC / HZ in the
kernel, so I'm going to clean them up too (in a separate patch).

Thank you!

Petr T