Message ID | 20220825102025.53916-4-joey.gouly@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Use CNTVCTSS_EL0 in gettimeofday() | expand |
On Thu, Aug 25, 2022 at 11:20:25AM +0100, Joey Gouly wrote: > If FEAT_ECV is implemented, the self-synchronized counter CNTVCTSS_EL0 can > be used, removing the need for an ISB. > > Signed-off-by: Joey Gouly <joey.gouly@arm.com> > Cc: Catalin Marinas <catalin.marinas@arm.com> > Cc: Will Deacon <will@kernel.org> > Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> > Cc: Mark Rutland <mark.rutland@arm.com> > Cc: Andre Przywara <andre.przywara@arm.com> > --- > arch/arm64/include/asm/vdso/gettimeofday.h | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h > index 4f7a629df81f..d8aff747019c 100644 > --- a/arch/arm64/include/asm/vdso/gettimeofday.h > +++ b/arch/arm64/include/asm/vdso/gettimeofday.h > @@ -9,6 +9,8 @@ > > #include <asm/barrier.h> > #include <asm/unistd.h> > +#include <asm/sysreg.h> > +#include <asm/alternative.h> Nit: please sort this alphabetically. > > #define VDSO_HAS_CLOCK_GETRES 1 > > @@ -78,11 +80,15 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, > return 0; > > /* > - * This isb() is required to prevent that the counter value > + * If FEAT_ECV is available, use the self-synchronizing counter. > + * Otherwise the isb is required to prevent that the counter value > * is speculated. > - */ > - isb(); > - asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory"); > + */ > + asm volatile(ALTERNATIVE("isb\nmrs %0, cntvct_el0", > + "nop\n" __mrs_s("%0", SYS_CNTVCTSS_EL0), > + ARM64_HAS_ECV) > + : "=r" (res) :: "memory"); > + For legibility (and ease of future modification), could we please format this with the fields all aligned, e.g. asm volatile( ALTERNATIVE("isb\n" "mrs %0, cntvct_el0", "nop\n" __mrs_s("%0", SYS_CNTVCTSS_EL0), ARM64_HAS_ECV) : "=r" (res) : : "memory"); Regardless: Acked-by: Mark Rutland <mark.rutland@arm.com> Thanks, Mark. > arch_counter_enforce_ordering(res); > > return res; > -- > 2.17.1 >
diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h index 4f7a629df81f..d8aff747019c 100644 --- a/arch/arm64/include/asm/vdso/gettimeofday.h +++ b/arch/arm64/include/asm/vdso/gettimeofday.h @@ -9,6 +9,8 @@ #include <asm/barrier.h> #include <asm/unistd.h> +#include <asm/sysreg.h> +#include <asm/alternative.h> #define VDSO_HAS_CLOCK_GETRES 1 @@ -78,11 +80,15 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, return 0; /* - * This isb() is required to prevent that the counter value + * If FEAT_ECV is available, use the self-synchronizing counter. + * Otherwise the isb is required to prevent that the counter value * is speculated. - */ - isb(); - asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory"); + */ + asm volatile(ALTERNATIVE("isb\nmrs %0, cntvct_el0", + "nop\n" __mrs_s("%0", SYS_CNTVCTSS_EL0), + ARM64_HAS_ECV) + : "=r" (res) :: "memory"); + arch_counter_enforce_ordering(res); return res;
If FEAT_ECV is implemented, the self-synchronized counter CNTVCTSS_EL0 can be used, removing the need for an ISB. Signed-off-by: Joey Gouly <joey.gouly@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Andre Przywara <andre.przywara@arm.com> --- arch/arm64/include/asm/vdso/gettimeofday.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)