From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Adrian Hunter <adrian.hunter@intel.com>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Aneesh Kumar K.V <aneesh.kumar@kernel.org>,
"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
John Stultz <jstultz@google.com>, Stephen Boyd <sboyd@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Randy Dunlap <rdunlap@infradead.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Arnd Bergmann <arnd@arndb.de>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>
Subject: Re: [PATCH 01/19] vdso: Consolidate vdso_calc_delta()
Date: Sat, 9 Mar 2024 07:48:44 +0000 [thread overview]
Message-ID: <094a2fd9-23d9-405b-9b6f-0e2516cd5a57@csgroup.eu> (raw)
In-Reply-To: <20240308131512.44324-2-adrian.hunter@intel.com>
Le 08/03/2024 à 14:14, Adrian Hunter a écrit :
> [Vous ne recevez pas souvent de courriers de adrian.hunter@intel.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
>
> Consolidate vdso_calc_delta(), in preparation for further simplification.
>
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> arch/powerpc/include/asm/vdso/gettimeofday.h | 17 ++---------------
> arch/s390/include/asm/vdso/gettimeofday.h | 7 ++-----
> lib/vdso/gettimeofday.c | 4 ++++
> 3 files changed, 8 insertions(+), 20 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/vdso/gettimeofday.h b/arch/powerpc/include/asm/vdso/gettimeofday.h
> index f0a4cf01e85c..f4da8e18cdf3 100644
> --- a/arch/powerpc/include/asm/vdso/gettimeofday.h
> +++ b/arch/powerpc/include/asm/vdso/gettimeofday.h
> @@ -14,6 +14,8 @@
>
> #define VDSO_HAS_TIME 1
>
> +#define VDSO_DELTA_NOMASK 1
> +
> static __always_inline int do_syscall_2(const unsigned long _r0, const unsigned long _r3,
> const unsigned long _r4)
> {
> @@ -105,21 +107,6 @@ static inline bool vdso_clocksource_ok(const struct vdso_data *vd)
> }
> #define vdso_clocksource_ok vdso_clocksource_ok
>
> -/*
> - * powerpc specific delta calculation.
> - *
> - * This variant removes the masking of the subtraction because the
> - * clocksource mask of all VDSO capable clocksources on powerpc is U64_MAX
> - * which would result in a pointless operation. The compiler cannot
> - * optimize it away as the mask comes from the vdso data and is not compile
> - * time constant.
> - */
Please keep the comment. You can move it close to VDSO_DELTA_NOMASK
> -static __always_inline u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
> -{
> - return (cycles - last) * mult;
> -}
> -#define vdso_calc_delta vdso_calc_delta
> -
> #ifndef __powerpc64__
> static __always_inline u64 vdso_shift_ns(u64 ns, unsigned long shift)
> {
> diff --git a/arch/s390/include/asm/vdso/gettimeofday.h b/arch/s390/include/asm/vdso/gettimeofday.h
> index db84942eb78f..7937765ccfa5 100644
> --- a/arch/s390/include/asm/vdso/gettimeofday.h
> +++ b/arch/s390/include/asm/vdso/gettimeofday.h
> @@ -6,16 +6,13 @@
>
> #define VDSO_HAS_CLOCK_GETRES 1
>
> +#define VDSO_DELTA_NOMASK 1
> +
> #include <asm/syscall.h>
> #include <asm/timex.h>
> #include <asm/unistd.h>
> #include <linux/compiler.h>
>
> -#define vdso_calc_delta __arch_vdso_calc_delta
> -static __always_inline u64 __arch_vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
> -{
> - return (cycles - last) * mult;
> -}
>
> static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
> {
> diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
> index ce2f69552003..042b95e8164d 100644
> --- a/lib/vdso/gettimeofday.c
> +++ b/lib/vdso/gettimeofday.c
> @@ -13,7 +13,11 @@
> static __always_inline
> u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
> {
> +#ifdef VDSO_DELTA_NOMASK
> + return (cycles - last) * mult;
> +#else
> return ((cycles - last) & mask) * mult;
> +#endif
See
https://docs.kernel.org/process/coding-style.html#conditional-compilation
You don't need #ifdefs here.
One solution is to define VDSO_DELTA_NOMASK to 0 in
include/vdso/datapage.h after including asm/vdso/gettimeofday.h :
#ifndef VDSO_DELTA_NOMASK
#define VDSO_DELTA_NOMASK 0
#endif
Then
u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
{
if (VDSO_DELTA_NOMASK)
mask = ~0ULL;
return ((cycles - last) & mask) * mult;
}
or
u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
{
if (VDSO_DELTA_NOMASK)
return (cycles - last) * mult;
return ((cycles - last) & mask) * mult;
}
> }
> #endif
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-03-09 7:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 13:14 [PATCH 00/19] timekeeping: Handle potential multiplication overflow Adrian Hunter
2024-03-08 13:14 ` [PATCH 01/19] vdso: Consolidate vdso_calc_delta() Adrian Hunter
2024-03-09 2:09 ` John Stultz
2024-03-09 7:48 ` Christophe Leroy [this message]
2024-03-08 13:14 ` [PATCH 02/19] vdso: Consolidate nanoseconds calculation Adrian Hunter
2024-03-08 13:14 ` [PATCH 03/19] vdso: Add CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT Adrian Hunter
2024-03-08 13:14 ` [PATCH 04/19] math64: Tidy mul_u64_u32_shr() Adrian Hunter
2024-03-08 13:14 ` [PATCH 05/19] vdso: math64: Provide mul_u64_u32_add_u64_shr() Adrian Hunter
2024-03-08 13:14 ` [PATCH 06/19] vdso: Add vdso_data::max_cycles Adrian Hunter
2024-03-08 13:15 ` [PATCH 07/19] vdso: Make delta calculation overflow safe Adrian Hunter
2024-03-08 13:15 ` [PATCH 08/19] x86/vdso: " Adrian Hunter
2024-03-08 13:15 ` [PATCH 09/19] timekeeping: Move timekeeping helper functions Adrian Hunter
2024-03-08 13:15 ` [PATCH 10/19] timekeeping: Rename fast_tk_get_delta_ns() to __timekeeping_get_ns() Adrian Hunter
2024-03-08 13:15 ` [PATCH 11/19] timekeeping: Tidy timekeeping_cycles_to_ns() slightly Adrian Hunter
2024-03-08 13:15 ` [PATCH 12/19] timekeeping: Reuse timekeeping_cycles_to_ns() Adrian Hunter
2024-03-08 13:15 ` [PATCH 13/19] timekeeping: Refactor timekeeping helpers Adrian Hunter
2024-03-08 13:15 ` [PATCH 14/19] timekeeping: Consolidate " Adrian Hunter
2024-03-08 13:15 ` [PATCH 15/19] timekeeping: Fold in timekeeping_delta_to_ns() Adrian Hunter
2024-03-08 13:15 ` [PATCH 16/19] timekeeping: Prepare timekeeping_cycles_to_ns() for overflow safety Adrian Hunter
2024-03-08 13:15 ` [PATCH 17/19] timekeeping: Make delta calculation overflow safe Adrian Hunter
2024-03-08 13:15 ` [PATCH 18/19] timekeeping: Let timekeeping_cycles_to_ns() handle both under and overflow Adrian Hunter
2024-03-08 13:15 ` [PATCH 19/19] clocksource: Make watchdog and suspend-timing multiplication overflow safe Adrian Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=094a2fd9-23d9-405b-9b6f-0e2516cd5a57@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=adrian.hunter@intel.com \
--cc=agordeev@linux.ibm.com \
--cc=aneesh.kumar@kernel.org \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=borntraeger@linux.ibm.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=sboyd@kernel.org \
--cc=svens@linux.ibm.com \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®