Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b70d6145 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Mark Salyzyn
Browse files

BACKPORT: time: Add timerkeeper::tkr_raw



(cherry pick from commit 4a4ad80d32cea69ee93bd4589f24dc478804cd80)

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: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarJohn Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150319093400.422589590@infradead.org


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Bug: 20045882
Bug: 19198045
Change-Id: I053fdc0e4c914dde90b1b8f037a05af85a571b42
parent 3712e427
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -41,13 +41,13 @@ struct tk_read_base {
/**
 * struct timekeeper - Structure holding internal timekeeping values.
 * @tkr_mono:		The readout base structure for CLOCK_MONOTONIC
 * @tkr_raw:		The readout base structure for CLOCK_MONOTONIC_RAW
 * @xtime_sec:		Current CLOCK_REALTIME time in seconds
 * @wall_to_monotonic:	CLOCK_REALTIME to CLOCK_MONOTONIC offset
 * @offs_real:		Offset clock monotonic -> clock realtime
 * @offs_boot:		Offset clock monotonic -> clock boottime
 * @offs_tai:		Offset clock monotonic -> clock tai
 * @tai_offset:		The current UTC to TAI offset in seconds
 * @base_raw:		Monotonic raw base time in ktime_t format
 * @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
@@ -76,13 +76,13 @@ struct tk_read_base {
 */
struct timekeeper {
	struct tk_read_base	tkr_mono;
	struct tk_read_base	tkr_raw;
	u64			xtime_sec;
	struct timespec64	wall_to_monotonic;
	ktime_t			offs_real;
	ktime_t			offs_boot;
	ktime_t			offs_tai;
	s32			tai_offset;
	ktime_t			base_raw;
	struct timespec64	raw_time;

	/* The following members are for timekeeping internal use */
+19 −26
Original line number Diff line number Diff line
@@ -141,6 +141,11 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock)
	tk->tkr_mono.mask = clock->mask;
	tk->tkr_mono.cycle_last = tk->tkr_mono.read(clock);

	tk->tkr_raw.clock = clock;
	tk->tkr_raw.read = clock->read;
	tk->tkr_raw.mask = clock->mask;
	tk->tkr_raw.cycle_last = tk->tkr_mono.cycle_last;

	/* Do the ns -> cycle conversion first, using original mult */
	tmp = NTP_INTERVAL_LENGTH;
	tmp <<= clock->shift;
@@ -167,7 +172,10 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock)
		else
			tk->tkr_mono.xtime_nsec <<= shift_change;
	}
	tk->tkr_raw.xtime_nsec = 0;

	tk->tkr_mono.shift = clock->shift;
	tk->tkr_raw.shift = clock->shift;

	tk->ntp_error = 0;
	tk->ntp_error_shift = NTP_SCALE_SHIFT - clock->shift;
@@ -179,6 +187,7 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock)
	 * to counteract clock drifting.
	 */
	tk->tkr_mono.mult = clock->mult;
	tk->tkr_raw.mult = clock->mult;
	tk->ntp_err_mult = 0;
}

@@ -209,25 +218,6 @@ static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
	return nsec + arch_gettimeoffset();
}

static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk)
{
	struct clocksource *clock = tk->tkr_mono.clock;
	cycle_t cycle_now, delta;
	s64 nsec;

	/* read clocksource: */
	cycle_now = tk->tkr_mono.read(clock);

	/* calculate the delta since the last update_wall_time: */
	delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);

	/* convert delta to nanoseconds. */
	nsec = clocksource_cyc2ns(delta, clock->mult, clock->shift);

	/* If arch requires, add in get_arch_timeoffset() */
	return nsec + arch_gettimeoffset();
}

/**
 * update_fast_timekeeper - Update the fast and NMI safe monotonic timekeeper.
 * @tk:		The timekeeper from which we take the update
@@ -432,7 +422,7 @@ static inline void tk_update_ktime_data(struct timekeeper *tk)
	tk->tkr_mono.base = ns_to_ktime(nsec);

	/* Update the monotonic raw base */
	tk->base_raw = timespec64_to_ktime(tk->raw_time);
	tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time);
}

/* must hold timekeeper_lock */
@@ -471,6 +461,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
	cycle_now = tk->tkr_mono.read(clock);
	delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
	tk->tkr_mono.cycle_last = cycle_now;
	tk->tkr_raw.cycle_last  = cycle_now;

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

@@ -479,7 +470,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)

	tk_normalize_xtime(tk);

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

@@ -608,8 +599,8 @@ ktime_t ktime_get_raw(void)

	do {
		seq = read_seqcount_begin(&tk_core.seq);
		base = tk->base_raw;
		nsecs = timekeeping_get_ns_raw(tk);
		base = tk->tkr_raw.base;
		nsecs = timekeeping_get_ns(&tk->tkr_raw);

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

@@ -674,7 +665,7 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
		ts_real->tv_sec = tk->xtime_sec;
		ts_real->tv_nsec = 0;

		nsecs_raw = timekeeping_get_ns_raw(tk);
		nsecs_raw  = timekeeping_get_ns(&tk->tkr_raw);
		nsecs_real = timekeeping_get_ns(&tk->tkr_mono);

	} while (read_seqcount_retry(&tk_core.seq, seq));
@@ -909,7 +900,7 @@ void getrawmonotonic(struct timespec *ts)

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

	} while (read_seqcount_retry(&tk_core.seq, seq));
@@ -1029,7 +1020,6 @@ void __init timekeeping_init(void)
	tk_set_xtime(tk, &now);
	tk->raw_time.tv_sec = 0;
	tk->raw_time.tv_nsec = 0;
	tk->base_raw.tv64 = 0;
	if (boot.tv_sec == 0 && boot.tv_nsec == 0)
		boot = tk_xtime(tk);

@@ -1181,6 +1171,8 @@ static void timekeeping_resume(void)

	/* Re-base the last cycle value */
	tk->tkr_mono.cycle_last = cycle_now;
	tk->tkr_raw.cycle_last  = cycle_now;

	tk->ntp_error = 0;
	timekeeping_suspended = 0;
	timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET);
@@ -1488,6 +1480,7 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset,
	/* Accumulate one shifted interval */
	offset -= interval;
	tk->tkr_mono.cycle_last += interval;
	tk->tkr_raw.cycle_last  += interval;

	tk->tkr_mono.xtime_nsec += tk->xtime_interval << shift;
	*clock_set |= accumulate_nsecs_to_secs(tk);