Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

time: Add timerkeeper::tkr_raw

Introduce tkr_raw and make use of it.

base_raw -> tkr_raw.base
clock->{mult,shift} -> tkr_raw.{mult.shift}

Kill timekeeping_get_ns_raw() in favour of
timekeeping_get_ns(&tkr_raw), this removes all mono_raw special
casing.

Duplicate the updates to tkr_mono.cycle_last into tkr_raw.cycle_last,
both need the same value.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150319093400.422589590@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Peter Zijlstra and committed by
Ingo Molnar
4a4ad80d 876e7881

+21 -24
+2 -2
include/linux/timekeeper_internal.h
··· 41 41 /** 42 42 * struct timekeeper - Structure holding internal timekeeping values. 43 43 * @tkr_mono: The readout base structure for CLOCK_MONOTONIC 44 + * @tkr_raw: The readout base structure for CLOCK_MONOTONIC_RAW 44 45 * @xtime_sec: Current CLOCK_REALTIME time in seconds 45 46 * @ktime_sec: Current CLOCK_MONOTONIC time in seconds 46 47 * @wall_to_monotonic: CLOCK_REALTIME to CLOCK_MONOTONIC offset ··· 49 48 * @offs_boot: Offset clock monotonic -> clock boottime 50 49 * @offs_tai: Offset clock monotonic -> clock tai 51 50 * @tai_offset: The current UTC to TAI offset in seconds 52 - * @base_raw: Monotonic raw base time in ktime_t format 53 51 * @raw_time: Monotonic raw base time in timespec64 format 54 52 * @cycle_interval: Number of clock cycles in one NTP interval 55 53 * @xtime_interval: Number of clock shifted nano seconds in one NTP ··· 77 77 */ 78 78 struct timekeeper { 79 79 struct tk_read_base tkr_mono; 80 + struct tk_read_base tkr_raw; 80 81 u64 xtime_sec; 81 82 unsigned long ktime_sec; 82 83 struct timespec64 wall_to_monotonic; ··· 85 84 ktime_t offs_boot; 86 85 ktime_t offs_tai; 87 86 s32 tai_offset; 88 - ktime_t base_raw; 89 87 struct timespec64 raw_time; 90 88 91 89 /* The following members are for timekeeping internal use */
+19 -22
kernel/time/timekeeping.c
··· 252 252 tk->tkr_mono.mask = clock->mask; 253 253 tk->tkr_mono.cycle_last = tk->tkr_mono.read(clock); 254 254 255 + tk->tkr_raw.clock = clock; 256 + tk->tkr_raw.read = clock->read; 257 + tk->tkr_raw.mask = clock->mask; 258 + tk->tkr_raw.cycle_last = tk->tkr_mono.cycle_last; 259 + 255 260 /* Do the ns -> cycle conversion first, using original mult */ 256 261 tmp = NTP_INTERVAL_LENGTH; 257 262 tmp <<= clock->shift; ··· 283 278 else 284 279 tk->tkr_mono.xtime_nsec <<= shift_change; 285 280 } 281 + tk->tkr_raw.xtime_nsec = 0; 282 + 286 283 tk->tkr_mono.shift = clock->shift; 284 + tk->tkr_raw.shift = clock->shift; 287 285 288 286 tk->ntp_error = 0; 289 287 tk->ntp_error_shift = NTP_SCALE_SHIFT - clock->shift; ··· 298 290 * to counteract clock drifting. 299 291 */ 300 292 tk->tkr_mono.mult = clock->mult; 293 + tk->tkr_raw.mult = clock->mult; 301 294 tk->ntp_err_mult = 0; 302 295 } 303 296 ··· 320 311 321 312 nsec = delta * tkr->mult + tkr->xtime_nsec; 322 313 nsec >>= tkr->shift; 323 - 324 - /* If arch requires, add in get_arch_timeoffset() */ 325 - return nsec + arch_gettimeoffset(); 326 - } 327 - 328 - static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) 329 - { 330 - struct clocksource *clock = tk->tkr_mono.clock; 331 - cycle_t delta; 332 - s64 nsec; 333 - 334 - delta = timekeeping_get_delta(&tk->tkr_mono); 335 - 336 - /* convert delta to nanoseconds. */ 337 - nsec = clocksource_cyc2ns(delta, clock->mult, clock->shift); 338 314 339 315 /* If arch requires, add in get_arch_timeoffset() */ 340 316 return nsec + arch_gettimeoffset(); ··· 556 562 tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); 557 563 558 564 /* Update the monotonic raw base */ 559 - tk->base_raw = timespec64_to_ktime(tk->raw_time); 565 + tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time); 560 566 561 567 /* 562 568 * The sum of the nanoseconds portions of xtime and ··· 605 611 cycle_now = tk->tkr_mono.read(clock); 606 612 delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask); 607 613 tk->tkr_mono.cycle_last = cycle_now; 614 + tk->tkr_raw.cycle_last = cycle_now; 608 615 609 616 tk->tkr_mono.xtime_nsec += delta * tk->tkr_mono.mult; 610 617 ··· 614 619 615 620 tk_normalize_xtime(tk); 616 621 617 - nsec = clocksource_cyc2ns(delta, clock->mult, clock->shift); 622 + nsec = clocksource_cyc2ns(delta, tk->tkr_raw.mult, tk->tkr_raw.shift); 618 623 timespec64_add_ns(&tk->raw_time, nsec); 619 624 } 620 625 ··· 743 748 744 749 do { 745 750 seq = read_seqcount_begin(&tk_core.seq); 746 - base = tk->base_raw; 747 - nsecs = timekeeping_get_ns_raw(tk); 751 + base = tk->tkr_raw.base; 752 + nsecs = timekeeping_get_ns(&tk->tkr_raw); 748 753 749 754 } while (read_seqcount_retry(&tk_core.seq, seq)); 750 755 ··· 857 862 ts_real->tv_sec = tk->xtime_sec; 858 863 ts_real->tv_nsec = 0; 859 864 860 - nsecs_raw = timekeeping_get_ns_raw(tk); 865 + nsecs_raw = timekeeping_get_ns(&tk->tkr_raw); 861 866 nsecs_real = timekeeping_get_ns(&tk->tkr_mono); 862 867 863 868 } while (read_seqcount_retry(&tk_core.seq, seq)); ··· 1091 1096 1092 1097 do { 1093 1098 seq = read_seqcount_begin(&tk_core.seq); 1094 - nsecs = timekeeping_get_ns_raw(tk); 1099 + nsecs = timekeeping_get_ns(&tk->tkr_raw); 1095 1100 ts64 = tk->raw_time; 1096 1101 1097 1102 } while (read_seqcount_retry(&tk_core.seq, seq)); ··· 1212 1217 tk_set_xtime(tk, &now); 1213 1218 tk->raw_time.tv_sec = 0; 1214 1219 tk->raw_time.tv_nsec = 0; 1215 - tk->base_raw.tv64 = 0; 1216 1220 if (boot.tv_sec == 0 && boot.tv_nsec == 0) 1217 1221 boot = tk_xtime(tk); 1218 1222 ··· 1361 1367 1362 1368 /* Re-base the last cycle value */ 1363 1369 tk->tkr_mono.cycle_last = cycle_now; 1370 + tk->tkr_raw.cycle_last = cycle_now; 1371 + 1364 1372 tk->ntp_error = 0; 1365 1373 timekeeping_suspended = 0; 1366 1374 timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET); ··· 1677 1681 /* Accumulate one shifted interval */ 1678 1682 offset -= interval; 1679 1683 tk->tkr_mono.cycle_last += interval; 1684 + tk->tkr_raw.cycle_last += interval; 1680 1685 1681 1686 tk->tkr_mono.xtime_nsec += tk->xtime_interval << shift; 1682 1687 *clock_set |= accumulate_nsecs_to_secs(tk);