* [PATCH v5 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW
@ 2017-11-06 21:02 Mark Salyzyn
2017-11-09 11:13 ` kbuild test robot
0 siblings, 1 reply; 2+ messages in thread
From: Mark Salyzyn @ 2017-11-06 21:02 UTC (permalink / raw)
To: linux-kernel
Cc: Mark Salyzyn, James Morse, Russell King, Catalin Marinas,
Will Deacon, Andy Lutomirski, Dmitry Safonov, John Stultz,
Mark Rutland, Laura Abbott, Kees Cook, Ard Biesheuvel,
Andy Gross, Kevin Brodsky, Andrew Pinski, Thomas Gleixner,
linux-arm-kernel
Take an effort to recode the arm64 vdso code from assembler to C
previously submitted by Andrew Pinski <apinski@cavium.com>, rework
it for use in both arm and arm64, overlapping any optimizations
for each architecture. But instead of landing it in arm64, land the
result into lib/vdso and unify both implementations to simplify
future maintenance.
Add a case for CLOCK_MONOTONIC_RAW to match up with support that
is available in arm64's vdso.
Signed-off-by: Mark Salyzyn <salyzyn@android.com>
Cc: James Morse <james.morse@arm.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dmitry Safonov <dsafonov@virtuozzo.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Andy Gross <andy.gross@linaro.org>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Andrew Pinski <apinski@cavium.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
v2:
- split first CL into 6 of 7 pieces
v4:
- Move out ARCH_CLOCK_FIXED_MASK to later adjustment.
- update commit message to reflect overall reasoning.
- replace typeof() with type vdso_raw_time_sec_t.
v5:
- replace erroneous tk->raw_time.shift with tk->tkr_raw.shift
---
arch/arm/include/asm/vdso_datapage.h | 11 +++++++++
arch/arm/kernel/vdso.c | 5 ++++
arch/arm/vdso/vgettimeofday.c | 44 ++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h
index 8dd7303db4ec..1c6e6a5d5d9d 100644
--- a/arch/arm/include/asm/vdso_datapage.h
+++ b/arch/arm/include/asm/vdso_datapage.h
@@ -34,6 +34,11 @@ typedef u32 vdso_wtm_clock_nsec_t;
typedef u32 vdso_xtime_clock_sec_t;
#endif
+#ifndef _VDSO_RAW_TIME_SEC_T
+#define _VDSO_RAW_TIME_SEC_T
+typedef u32 vdso_raw_time_sec_t;
+#endif
+
/* Try to be cache-friendly on systems that don't implement the
* generic timer: fit the unconditionally updated fields in the first
* 32 bytes.
@@ -58,6 +63,12 @@ struct vdso_data {
u64 xtime_clock_snsec; /* CLOCK_REALTIME sub-ns base */
u32 tz_minuteswest; /* timezone info for gettimeofday(2) */
u32 tz_dsttime;
+
+ /* Raw clocksource multipler */
+ u32 cs_raw_mult;
+ /* Raw time */
+ vdso_raw_time_sec_t raw_time_sec;
+ u32 raw_time_nsec;
};
union vdso_data_store {
diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c
index aed84b659cc5..b7c93fce2f59 100644
--- a/arch/arm/kernel/vdso.c
+++ b/arch/arm/kernel/vdso.c
@@ -335,9 +335,14 @@ void update_vsyscall(struct timekeeper *tk)
if (!vdso_data->use_syscall) {
vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last;
+ vdso_data->raw_time_sec = tk->raw_time.tv_sec;
+ vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec <<
+ tk->tkr_raw.shift) +
+ tk->tkr_raw.xtime_nsec;
vdso_data->xtime_clock_sec = tk->xtime_sec;
vdso_data->xtime_clock_snsec = tk->tkr_mono.xtime_nsec;
vdso_data->cs_mono_mult = tk->tkr_mono.mult;
+ vdso_data->cs_raw_mult = tk->tkr_raw.mult;
/* tkr_mono.shift == tkr_raw.shift */
vdso_data->cs_shift = tk->tkr_mono.shift;
vdso_data->cs_mask = tk->tkr_mono.mask;
diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c
index 59893fca03b3..a2c4db83edc4 100644
--- a/arch/arm/vdso/vgettimeofday.c
+++ b/arch/arm/vdso/vgettimeofday.c
@@ -194,6 +194,40 @@ static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts)
return 0;
}
+static notrace int do_monotonic_raw(const struct vdso_data *vd,
+ struct timespec *ts)
+{
+ u32 seq, mult, shift;
+ u64 nsec, cycle_last;
+ u64 mask;
+ vdso_raw_time_sec_t sec;
+
+ do {
+ seq = vdso_read_begin(vd);
+
+ if (vd->use_syscall)
+ return -1;
+
+ cycle_last = vd->cs_cycle_last;
+
+ mult = vd->cs_raw_mult;
+ shift = vd->cs_shift;
+ mask = vd->cs_mask;
+
+ sec = vd->raw_time_sec;
+ nsec = vd->raw_time_nsec;
+
+ } while (unlikely(vdso_read_retry(vd, seq)));
+
+ nsec += get_clock_shifted_nsec(cycle_last, mult, mask);
+ nsec >>= shift;
+ /* open coding timespec_add_ns to save a ts->tv_nsec = 0 */
+ ts->tv_sec = sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec);
+ ts->tv_nsec = nsec;
+
+ return 0;
+}
+
#else /* CONFIG_ARM_ARCH_TIMER */
static notrace int do_realtime(const struct vdso_data *vd, struct timespec *ts)
@@ -206,6 +240,12 @@ static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts)
return -1;
}
+static notrace int do_monotonic_raw(const struct vdso_data *vd,
+ struct timespec *ts)
+{
+ return -1;
+}
+
#endif /* CONFIG_ARM_ARCH_TIMER */
notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
@@ -227,6 +267,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
if (do_monotonic(vd, ts))
goto fallback;
break;
+ case CLOCK_MONOTONIC_RAW:
+ if (do_monotonic_raw(vd, ts))
+ goto fallback;
+ break;
default:
goto fallback;
}
--
2.15.0.403.gc27cc4dac6-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v5 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW
2017-11-06 21:02 [PATCH v5 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Mark Salyzyn
@ 2017-11-09 11:13 ` kbuild test robot
0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2017-11-09 11:13 UTC (permalink / raw)
To: Mark Salyzyn
Cc: kbuild-all, linux-kernel, Mark Salyzyn, James Morse,
Russell King, Catalin Marinas, Will Deacon, Andy Lutomirski,
Dmitry Safonov, John Stultz, Mark Rutland, Laura Abbott,
Kees Cook, Ard Biesheuvel, Andy Gross, Kevin Brodsky,
Andrew Pinski, Thomas Gleixner, linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 3907 bytes --]
Hi Mark,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.14-rc8]
[cannot apply to next-20171109]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Mark-Salyzyn/arm-vdso-rename-vdso_datapage-variables/20171109-160311
config: arm-sunxi_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All errors (new ones prefixed by >>):
arch/arm/kernel/vdso.c: In function 'update_vsyscall':
>> arch/arm/kernel/vdso.c:338:32: error: 'struct timekeeper' has no member named 'raw_time'; did you mean 'raw_sec'?
vdso_data->raw_time_sec = tk->raw_time.tv_sec;
^~
arch/arm/kernel/vdso.c:339:33: error: 'struct timekeeper' has no member named 'raw_time'; did you mean 'raw_sec'?
vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec <<
^~
vim +338 arch/arm/kernel/vdso.c
297
298 /**
299 * update_vsyscall - update the vdso data page
300 *
301 * Increment the sequence counter, making it odd, indicating to
302 * userspace that an update is in progress. Update the fields used
303 * for coarse clocks and, if the architected system timer is in use,
304 * the fields used for high precision clocks. Increment the sequence
305 * counter again, making it even, indicating to userspace that the
306 * update is finished.
307 *
308 * Userspace is expected to sample tb_seq_count before reading any other
309 * fields from the data page. If tb_seq_count is odd, userspace is
310 * expected to wait until it becomes even. After copying data from
311 * the page, userspace must sample tb_seq_count again; if it has changed
312 * from its previous value, userspace must retry the whole sequence.
313 *
314 * Calls to update_vsyscall are serialized by the timekeeping core.
315 */
316 void update_vsyscall(struct timekeeper *tk)
317 {
318 struct timespec64 *wtm = &tk->wall_to_monotonic;
319
320 if (!cntvct_ok) {
321 /* The entry points have been zeroed, so there is no
322 * point in updating the data page.
323 */
324 return;
325 }
326
327 vdso_write_begin(vdso_data);
328
329 vdso_data->use_syscall = !tk_is_cntvct(tk);
330 vdso_data->xtime_coarse_sec = tk->xtime_sec;
331 vdso_data->xtime_coarse_nsec = (u32)(tk->tkr_mono.xtime_nsec >>
332 tk->tkr_mono.shift);
333 vdso_data->wtm_clock_sec = wtm->tv_sec;
334 vdso_data->wtm_clock_nsec = wtm->tv_nsec;
335
336 if (!vdso_data->use_syscall) {
337 vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last;
> 338 vdso_data->raw_time_sec = tk->raw_time.tv_sec;
339 vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec <<
340 tk->tkr_raw.shift) +
341 tk->tkr_raw.xtime_nsec;
342 vdso_data->xtime_clock_sec = tk->xtime_sec;
343 vdso_data->xtime_clock_snsec = tk->tkr_mono.xtime_nsec;
344 vdso_data->cs_mono_mult = tk->tkr_mono.mult;
345 vdso_data->cs_raw_mult = tk->tkr_raw.mult;
346 /* tkr_mono.shift == tkr_raw.shift */
347 vdso_data->cs_shift = tk->tkr_mono.shift;
348 vdso_data->cs_mask = tk->tkr_mono.mask;
349 }
350
351 vdso_write_end(vdso_data);
352
353 flush_dcache_page(virt_to_page(vdso_data));
354 }
355
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 23021 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-09 11:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-06 21:02 [PATCH v5 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Mark Salyzyn
2017-11-09 11:13 ` kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).