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

Commit 7ea1c88f authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "time: Fix extra sleeptime injection when suspend fails"

parents f520358e aab245cc
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -1511,8 +1511,20 @@ void __weak read_boot_clock64(struct timespec64 *ts)
	ts->tv_nsec = 0;
}

/* Flag for if timekeeping_resume() has injected sleeptime */
static bool sleeptime_injected;
/*
 * Flag reflecting whether timekeeping_resume() has injected sleeptime.
 *
 * The flag starts of false and is only set when a suspend reaches
 * timekeeping_suspend(), timekeeping_resume() sets it to false when the
 * timekeeper clocksource is not stopping across suspend and has been
 * used to update sleep time. If the timekeeper clocksource has stopped
 * then the flag stays true and is used by the RTC resume code to decide
 * whether sleeptime must be injected and if so the flag gets false then.
 *
 * If a suspend fails before reaching timekeeping_resume() then the flag
 * stays false and prevents erroneous sleeptime injection.
 */
static bool suspend_timing_needed;

/* Flag for if there is a persistent clock on this platform */
static bool persistent_clock_exists;
@@ -1611,7 +1623,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
 */
bool timekeeping_rtc_skipresume(void)
{
	return sleeptime_injected;
	return !suspend_timing_needed;
}

/**
@@ -1647,6 +1659,8 @@ void timekeeping_inject_sleeptime64(struct timespec64 *delta)
	raw_spin_lock_irqsave(&timekeeper_lock, flags);
	write_seqcount_begin(&tk_core.seq);

	suspend_timing_needed = false;

	timekeeping_forward_now(tk);

	__timekeeping_inject_sleeptime(tk, delta);
@@ -1671,8 +1685,8 @@ void timekeeping_resume(void)
	unsigned long flags;
	struct timespec64 ts_new, ts_delta;
	cycle_t cycle_now, cycle_delta;
	bool inject_sleeptime = false;

	sleeptime_injected = false;
	read_persistent_clock64(&ts_new);

	clockevents_resume();
@@ -1718,14 +1732,16 @@ void timekeeping_resume(void)
		nsec += ((u64) cycle_delta * mult) >> shift;

		ts_delta = ns_to_timespec64(nsec);
		sleeptime_injected = true;
		inject_sleeptime = true;
	} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
		ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
		sleeptime_injected = true;
		inject_sleeptime = true;
	}

	if (sleeptime_injected)
	if (inject_sleeptime) {
		suspend_timing_needed = false;
		__timekeeping_inject_sleeptime(tk, &ts_delta);
	}

	/* Re-base the last cycle value */
	tk->tkr_mono.cycle_last = cycle_now;
@@ -1760,6 +1776,8 @@ int timekeeping_suspend(void)
	if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec)
		persistent_clock_exists = true;

	suspend_timing_needed = true;

	raw_spin_lock_irqsave(&timekeeper_lock, flags);
	write_seqcount_begin(&tk_core.seq);
	timekeeping_forward_now(tk);