Skip to content
This repository has been archived by the owner on Mar 17, 2019. It is now read-only.

Commit

Permalink
Revert "BACKPORT: time: Clean up CLOCK_MONOTONIC_RAW time handling"
Browse files Browse the repository at this point in the history
This backport breaks Kodi (app either loads to a black screen or it
freezes constantly).

This reverts commit 562e534.

Reported-and-tested-by: Nathan Chancellor <[email protected]>
Signed-off-by: Harsh Shandilya <[email protected]>
  • Loading branch information
Harsh Shandilya committed Jan 17, 2018
1 parent c0a215e commit f977752
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions arch/arm64/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ void update_vsyscall(struct timekeeper *tk)
if (!use_syscall) {
/* 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;
vdso_data->raw_time_nsec = tk->tkr_raw.xtime_nsec;
vdso_data->raw_time_sec = tk->raw_time.tv_sec;
vdso_data->raw_time_nsec = tk->raw_time.tv_nsec;
vdso_data->xtime_clock_sec = tk->xtime_sec;
vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec;
/* tkr_raw.xtime_nsec == 0 */
Expand Down
4 changes: 2 additions & 2 deletions include/linux/timekeeper_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct tk_read_base {
* @offs_boot: Offset clock monotonic -> clock boottime
* @offs_tai: Offset clock monotonic -> clock tai
* @tai_offset: The current UTC to TAI offset in seconds
* @raw_sec: CLOCK_MONOTONIC_RAW time in seconds
* @raw_time: Monotonic raw base time in timespec64 format
* @cycle_interval: Number of clock cycles in one NTP interval
* @xtime_interval: Number of clock shifted nano seconds in one NTP
* interval.
Expand Down Expand Up @@ -83,7 +83,7 @@ struct timekeeper {
ktime_t offs_boot;
ktime_t offs_tai;
s32 tai_offset;
u64 raw_sec;
struct timespec64 raw_time;

/* The following members are for timekeeping internal use */
cycle_t cycle_interval;
Expand Down
42 changes: 18 additions & 24 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ static inline void tk_normalize_xtime(struct timekeeper *tk)
tk->tkr_mono.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_mono.shift;
tk->xtime_sec++;
}
while (tk->tkr_raw.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_raw.shift)) {
tk->tkr_raw.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_raw.shift;
tk->raw_sec++;
}
}

static inline struct timespec64 tk_xtime(struct timekeeper *tk)
Expand Down Expand Up @@ -170,14 +166,12 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock)
/* if changing clocks, convert xtime_nsec shift units */
if (old_clock) {
int shift_change = clock->shift - old_clock->shift;
if (shift_change < 0) {
if (shift_change < 0)
tk->tkr_mono.xtime_nsec >>= -shift_change;
tk->tkr_raw.xtime_nsec >>= -shift_change;
} else {
else
tk->tkr_mono.xtime_nsec <<= shift_change;
tk->tkr_raw.xtime_nsec <<= shift_change;
}
}
tk->tkr_raw.xtime_nsec = 0;

tk->tkr_mono.shift = clock->shift;
tk->tkr_raw.shift = clock->shift;
Expand Down Expand Up @@ -411,7 +405,6 @@ EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier);
*/
static inline void tk_update_ktime_data(struct timekeeper *tk)
{
u64 seconds;
s64 nsec;

/*
Expand All @@ -427,9 +420,7 @@ static inline void tk_update_ktime_data(struct timekeeper *tk)
tk->tkr_mono.base = ns_to_ktime(nsec);

/* Update the monotonic raw base */
seconds = tk->raw_sec;
nsec = (u32)(tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift);
tk->tkr_raw.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec);
tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time);
}

/* must hold timekeeper_lock */
Expand Down Expand Up @@ -463,6 +454,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
{
struct clocksource *clock = tk->tkr_mono.clock;
cycle_t cycle_now, delta;
s64 nsec;

cycle_now = tk->tkr_mono.read(clock);
delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
Expand All @@ -474,13 +466,10 @@ static void timekeeping_forward_now(struct timekeeper *tk)
/* If arch requires, add in get_arch_timeoffset() */
tk->tkr_mono.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_mono.shift;


tk->tkr_raw.xtime_nsec += delta * tk->tkr_raw.mult;

/* If arch requires, add in get_arch_timeoffset() */
tk->tkr_raw.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_raw.shift;

tk_normalize_xtime(tk);

nsec = clocksource_cyc2ns(delta, tk->tkr_raw.mult, tk->tkr_raw.shift);
timespec64_add_ns(&tk->raw_time, nsec);
}

/**
Expand Down Expand Up @@ -910,18 +899,19 @@ int timekeeping_notify(struct clocksource *clock)
void getrawmonotonic(struct timespec *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 ts64;
unsigned long seq;
s64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);
ts->tv_sec = tk->raw_sec;
nsecs = timekeeping_get_ns(&tk->tkr_raw);
ts64 = tk->raw_time;

} while (read_seqcount_retry(&tk_core.seq, seq));

ts->tv_nsec = 0;
timespec_add_ns(ts, nsecs);
timespec64_add_ns(&ts64, nsecs);
*ts = timespec64_to_timespec(ts64);
}
EXPORT_SYMBOL(getrawmonotonic);

Expand Down Expand Up @@ -1033,7 +1023,8 @@ void __init timekeeping_init(void)
tk_setup_internals(tk, clock);

tk_set_xtime(tk, &now);
tk->raw_sec = 0;
tk->raw_time.tv_sec = 0;
tk->raw_time.tv_nsec = 0;
if (boot.tv_sec == 0 && boot.tv_nsec == 0)
boot = tk_xtime(tk);

Expand Down Expand Up @@ -1500,12 +1491,15 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset,
*clock_set |= accumulate_nsecs_to_secs(tk);

/* Accumulate raw time */
tk->tkr_raw.xtime_nsec += (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift;
tk->tkr_raw.xtime_nsec += tk->raw_interval << shift;
snsec_per_sec = (u64)NSEC_PER_SEC << tk->tkr_raw.shift;
while (tk->tkr_raw.xtime_nsec >= snsec_per_sec) {
tk->tkr_raw.xtime_nsec -= snsec_per_sec;
tk->raw_sec++;
tk->raw_time.tv_sec++;
}
tk->raw_time.tv_nsec = tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift;
tk->tkr_raw.xtime_nsec -= (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift;

/* Accumulate error between NTP and clock interval */
tk->ntp_error += tk->ntp_tick << shift;
Expand Down

0 comments on commit f977752

Please sign in to comment.