lib: vdso: Add support for CLOCK_BOOTTIME
Subsystems (3)
PATCH v6 11/12 lib: vdso: Add support for CLOCK_BOOTTIME
Take an effort to recode the arm64 vdso code from assembler to C previously submitted by Andrew Pinski <[email protected]>, 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_BOOTTIME as it is popular for measuring relative time on systems expected to suspend() or hibernate().
Android uses CLOCK_BOOTTIME for all relative time measurements and timeouts. Switching to vdso reduced CPU utilization and improves accuracy. There is also a desire by some partners to switch all logging over to CLOCK_BOOTTIME, and thus this operation alone would contribute to a near percentile CPU load.
v2:
- rebased and changed from 3/3 to 10/10, fortified commit message.
v3:
- move arch/arm/vdso/vgettimeofday.c to lib/vdso/vgettimeofday.c.
v4:
- update commit message to reflect specific, and overall reasoning of patch series.
- drop forced inline operations.
- switch typeof() with __kernel_time_t.
v5:
- added comment about open coded timepsec_add_ns() for clarity.
v6:
- fix issue with __iter_div_u64_rem scaling by splitting sec & nsec
--- arch/arm/include/asm/vdso_datapage.h | 2 ++ arch/arm/kernel/vdso.c | 4 +++ arch/arm64/include/asm/vdso_datapage.h | 2 ++ arch/arm64/kernel/vdso.c | 4 +++ lib/vdso/vgettimeofday.c | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+)
arch/arm/include/asm/vdso_datapage.h +2 -0
@@ -64,6 +64,8 @@ struct vdso_data {u32 tz_minuteswest;/* timezone info for gettimeofday(2) */ u32 tz_dsttime; +u32 btm_sec;/* monotonic to boot time */ +u32 btm_nsec;/* Raw clocksource multipler */ u32 cs_raw_mult;/* Raw time */
arch/arm/kernel/vdso.c +4 -0
@@ -335,6 +335,8 @@ void update_vsyscall(struct timekeeper *tk) vdso_data->wtm_clock_nsec = wtm->tv_nsec;if (!vdso_data->use_syscall) { +struct timespec btm =ktime_to_timespec (tk->offs_boot); + vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; vdso_data->raw_time_sec = tk->raw_sec; vdso_data->raw_time_nsec = tk->tkr_raw.xtime_nsec;
@@ -345,6 +347,8 @@ void update_vsyscall(struct timekeeper *tk)/* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; vdso_data->cs_mask = tk->tkr_mono.mask; + vdso_data->btm_sec = btm.tv_sec; + vdso_data->btm_nsec = btm.tv_nsec; }vdso_write_end (vdso_data);
arch/arm64/include/asm/vdso_datapage.h +2 -0
@@ -45,6 +45,8 @@ struct vdso_data {__u64 xtime_coarse_nsec;__u64 wtm_clock_sec;/* Wall to monotonic time */ vdso_wtm_clock_nsec_t wtm_clock_nsec; +__u32 btm_sec;/* monotonic to boot time */ +__u32 btm_nsec;__u32 tb_seq_count;/* Timebase sequence counter */ /* cs_* members must be adjacent and in this order (ldp accesses) */ __u32 cs_mono_mult;/* NTP-adjusted clocksource multiplier */
arch/arm64/kernel/vdso.c +4 -0
@@ -233,6 +233,8 @@ void update_vsyscall(struct timekeeper *tk) vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;if (!use_syscall) { +struct timespec btm =ktime_to_timespec (tk->offs_boot); +/* tkr_mono.cycle_last == tkr_raw.cycle_last */ vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; vdso_data->raw_time_sec = tk->raw_sec;
@@ -243,6 +245,8 @@ void update_vsyscall(struct timekeeper *tk) 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->btm_sec = btm.tv_sec; + vdso_data->btm_nsec = btm.tv_nsec; }smp_wmb ();
lib/vdso/vgettimeofday.c +56 -0
80 lines not on this page · raw message
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog