Skip to contentSkip to conversation

time: Fix sleeptime injection for non-stop clocksource & persistent clock

PATCH Superseded Mukesh Ojha 2 participants 3 messages May 29, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 time: Fix sleeptime injection for non-stop clocksource & persistent clock

Currently, for both non-stop clocksource and persistent clock there is a corner case, when a driver failed to go suspend mode rtc_resume injects the sleeptime as timekeeping_rtc_skipresume returned 'false' due to which we can see mismatch in time with system clock.

Success case:

                                         {sleeptime_injected=true}

rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => rtc_resume()

Failure case:

             {failure in sleep path} {sleeptime_injected=false}

rtc_suspend() => rtc_resume()

Change-Id I98928761c98cec21a3033a55d3e10fb34138f38c
---
 kernel/time/timekeeping.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/time/timekeeping.c +9 -5
index 427e33d..c022d82 100644
@@ -1511,9 +1511,6 @@ 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 for if there is a persistent clock on this platform */
 static bool persistent_clock_exists;
 
@@ -1611,7 +1608,14 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
  */
 bool timekeeping_rtc_skipresume(void)
 {
-	return sleeptime_injected;
+	struct timekeeper *tk = &tk_core.timekeeper;
+	bool skip_rtc_resume = false;
+
+	skip_rtc_resume = ((tk->tkr_mono.clock->flags &
+			CLOCK_SOURCE_SUSPEND_NONSTOP) ||
+			(persistent_clock_exists)) ? true : false;
+
+	return skip_rtc_resume;
 }
 
 /**
@@ -1671,8 +1675,8 @@ void timekeeping_resume(void)
 	unsigned long flags;
 	struct timespec64 ts_new, ts_delta;
 	cycle_t cycle_now, cycle_delta;
+	bool sleeptime_injected = false;
 
-	sleeptime_injected = false;
 	read_persistent_clock64(&ts_new);
 
 	clockevents_resume();
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw
Quoted 7 lines · Mukesh Ojha

Currently, for both non-stop clocksource and persistent clock there is a corner case, when a driver failed to go suspend mode rtc_resume injects the sleeptime as timekeeping_rtc_skipresume returned 'false' due to which we can see mismatch in time with system clock.

Success case:

Quoted 8 lines
                                         {sleeptime_injected=true}

rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => rtc_resume()

Failure case:

             {failure in sleep path} {sleeptime_injected=false}

rtc_suspend() => rtc_resume()

Change-Id: I98928761c98cec21a3033a55d3e10fb34138f38c

This does not belong in upstream please remove. I think checkpatch warns.

Also I see that you have sent to lkml and arm-msm mailing list, but have not CCed any maintainers. Please run ./scripts/get_maintainer.pl to find who to send patches to. Chances are it will get ignored...

Quoted 53 lines
---
 kernel/time/timekeeping.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/time/timekeeping.c +9 -5
index 427e33d..c022d82 100644
@@ -1511,9 +1511,6 @@ 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 for if there is a persistent clock on this platform */
 static bool persistent_clock_exists;
 
@@ -1611,7 +1608,14 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
  */
 bool timekeeping_rtc_skipresume(void)
 {
-	return sleeptime_injected;
+	struct timekeeper *tk = &tk_core.timekeeper;
+	bool skip_rtc_resume = false;
+
+	skip_rtc_resume = ((tk->tkr_mono.clock->flags &
+			CLOCK_SOURCE_SUSPEND_NONSTOP) ||
+			(persistent_clock_exists)) ? true : false;
+
+	return skip_rtc_resume;
 }
 
 /**
@@ -1671,8 +1675,8 @@ void timekeeping_resume(void)
 	unsigned long flags;
 	struct timespec64 ts_new, ts_delta;
 	cycle_t cycle_now, cycle_delta;
+	bool sleeptime_injected = false;
 
-	sleeptime_injected = false;
 	read_persistent_clock64(&ts_new);
 
 	clockevents_resume();
Signature · 7 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
~Vinod
#2 lore raw
Quoted 15 lines · Vinod Koul
Quoted 14 lines · Mukesh Ojha

Currently, for both non-stop clocksource and persistent clock there is a corner case, when a driver failed to go suspend mode rtc_resume injects the sleeptime as timekeeping_rtc_skipresume returned 'false' due to which we can see mismatch in time with system clock.

Success case:

                                          {sleeptime_injected=true}

rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => rtc_resume()

Failure case:

              {failure in sleep path} {sleeptime_injected=false}

rtc_suspend() => rtc_resume()

Quoted 6 lines
Quoted 1 line

Change-Id: I98928761c98cec21a3033a55d3e10fb34138f38c

This does not belong in upstream please remove. I think checkpatch warns.

Also I see that you have sent to lkml and arm-msm mailing list, but have not CCed any maintainers. Please run ./scripts/get_maintainer.pl to find who to send patches to. Chances are it will get ignored...

Thanks Vinod.
Will resend it after including maintainers.

-Mukesh

Quoted 54 lines
Quoted 54 lines
---
  kernel/time/timekeeping.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)
kernel/time/timekeeping.c +9 -5
index 427e33d..c022d82 100644
@@ -1511,9 +1511,6 @@ 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 for if there is a persistent clock on this platform */
  static bool persistent_clock_exists;
 
@@ -1611,7 +1608,14 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
   */
  bool timekeeping_rtc_skipresume(void)
  {
-	return sleeptime_injected;
+	struct timekeeper *tk = &tk_core.timekeeper;
+	bool skip_rtc_resume = false;
+
+	skip_rtc_resume = ((tk->tkr_mono.clock->flags &
+			CLOCK_SOURCE_SUSPEND_NONSTOP) ||
+			(persistent_clock_exists)) ? true : false;
+
+	return skip_rtc_resume;
  }
 
  /**
@@ -1671,8 +1675,8 @@ void timekeeping_resume(void)
  	unsigned long flags;
  	struct timespec64 ts_new, ts_delta;
  	cycle_t cycle_now, cycle_delta;
+	bool sleeptime_injected = false;
 
-	sleeptime_injected = false;
  	read_persistent_clock64(&ts_new);
 
  	clockevents_resume();
Signature · 7 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html