[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <bb92e7208d820f74188ab3edc1d56e6733f2df29.1578934751.git.christophe.leroy@c-s.fr>
Date: Mon, 13 Jan 2020 17:08:49 +0000 (UTC)
From: Christophe Leroy <christophe.leroy@....fr>
To: Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Paul Mackerras <paulus@...ba.org>,
Michael Ellerman <mpe@...erman.id.au>, arnd@...db.de,
tglx@...utronix.de, vincenzo.frascino@....com, luto@...nel.org
Cc: linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-arm-kernel@...ts.infradead.org, linux-mips@...r.kernel.org,
x86@...nel.org
Subject: [RFC PATCH v3 11/12] lib: vdso: split clock verification out of
__arch_get_hw_counter()
__arch_get_hw_counter() returns the current value of the counter if
the counter is valid or a negative number if the counter is not valid.
This is suboptimal because the validity is checked twice: once before
reading the counter and once after reading the counter.
Optionaly split the verification out of __arch_get_hw_counter()
by providing an optional __arch_is_hw_counter_valid() function.
Signed-off-by: Christophe Leroy <christophe.leroy@....fr>
---
lib/vdso/gettimeofday.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index ea1a55507af5..001f6329e846 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -67,11 +67,18 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,
do {
seq = vdso_read_begin(vd);
+#ifdef __arch_is_hw_counter_valid
+ if (unlikely(!__arch_is_hw_counter_valid(vd->clock_mode)))
+ return -1;
+#endif
+
cycles = __arch_get_hw_counter(vd->clock_mode);
ns = vdso_ts->nsec;
last = vd->cycle_last;
+#ifndef __arch_is_hw_counter_valid
if (unlikely((s64)cycles < 0))
return -1;
+#endif
ns += vdso_calc_delta(cycles, last, vd->mask, vd->mult);
nsec = ns >> vd->shift;
--
2.13.3
Powered by blists - more mailing lists