From: Mukesh Ojha <mojha@codeaurora.org>
To: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
lkml <linux-kernel@vger.kernel.org>,
gkohli@codeaurora.org, cpandya@codeaurora.org,
neeraju@codeaurora.org, Baolin Wang <baolin.wang@linaro.org>
Subject: Re: [PATCH v3] time: Fix incorrect sleeptime injection when suspend fails
Date: Fri, 13 Jul 2018 12:43:24 +0530 [thread overview]
Message-ID: <7e25b63e-cc9b-1f6d-e3d2-087dd484f631@codeaurora.org> (raw)
In-Reply-To: <CALAqxLVs=EbbJ83bw=YRb=1B7E2uLcnrUh+qWEjm9U3iYd7FAg@mail.gmail.com>
Hi John,
Thanks for your response
Please find my comments inline.
On 7/11/2018 1:43 AM, John Stultz wrote:
> On Fri, Jul 6, 2018 at 6:17 AM, Mukesh Ojha <mojha@codeaurora.org> wrote:
>> Currently, there exists a corner case assuming when there is
>> only one clocksource e.g RTC, and system failed to go to
>> suspend mode. While resume rtc_resume() injects the sleeptime
>> as timekeeping_rtc_skipresume() returned 'false' (default value
>> of sleeptime_injected) due to which we can see mismatch in
>> timestamps.
>>
>> This issue can also come in a system where more than one
>> clocksource are present and very first suspend fails.
>>
>> Fix this by handling `sleeptime_injected` flag properly.
>>
>> Success case:
>> ------------
>> {sleeptime_injected=false}
>> rtc_suspend() => timekeeping_suspend() => timekeeping_resume() =>
>>
>> (sleeptime injected)
>> rtc_resume()
>>
>> Failure case:
>> ------------
>> {failure in sleep path} {sleeptime_injected=false}
>> rtc_suspend() => rtc_resume()
>>
>> sleeptime injected again which was not required as the suspend failed)
>>
>> Originally-by: Thomas Gleixner <tglx@linutronix.de>
>> Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
>> ---
>> Changes in v3:
>> * Updated commit subject and description.
>> * Updated the patch as per the fix given by Thomas Gleixner.
>>
>> Changes in v2:
>> * Updated the commit text.
>> * Removed extra variable and used the earlier static
>> variable 'sleeptime_injected'.
>>
>> kernel/time/timekeeping.c | 21 ++++++++++++++++++---
>> 1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
>> index 4786df9..32ae9ae 100644
>> --- a/kernel/time/timekeeping.c
>> +++ b/kernel/time/timekeeping.c
>> @@ -1510,8 +1510,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 true and is only cleared when a suspend reaches
>> + * timekeeping_suspend(), timekeeping_resume() sets it 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 false and is used by the RTC resume code to decide whether sleep
>> + * time must be injected and if so the flag gets set then.
>> + *
>> + * If a suspend fails before reaching timekeeping_resume() then the flag
>> + * stays true and prevents erroneous sleeptime injection.
>> + */
>> +static bool sleeptime_injected = true;
> I worry this upside-down logic is too subtle to be easily reasoned
> about, and will just lead to future mistakes.
>
> Can we instead call this "suspend_timing_needed" and only set it to
> true when we don't inject any sleep time on resume?
I did not get your point "only set it to true when we don't inject any
sleep time on resume? "
How do we know this ?
This question itself depends on the "sleeptime_injected" if it is true
means no need to inject else need to inject.
Also, we need to make this variable back and forth true, false; suspends
path ensures it to make it false.
Just to add here there are already two path where `sleeptime_injected`
set to true one from
NON-stop clocksource and other from persistant clock and the RTC one was
missing, so we are adding
with this patch.
Cheers,
-Mukesh
next prev parent reply other threads:[~2018-07-13 7:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-06 13:17 Mukesh Ojha
2018-07-10 20:13 ` John Stultz
2018-07-13 7:13 ` Mukesh Ojha [this message]
2018-07-13 17:20 ` John Stultz
2018-07-16 16:17 ` Mukesh Ojha
2018-07-16 16:30 ` John Stultz
2018-07-16 17:14 ` John Stultz
2018-07-16 18:30 ` Mukesh Ojha
2018-07-16 18:54 ` John Stultz
2018-07-16 19:18 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7e25b63e-cc9b-1f6d-e3d2-087dd484f631@codeaurora.org \
--to=mojha@codeaurora.org \
--cc=baolin.wang@linaro.org \
--cc=cpandya@codeaurora.org \
--cc=gkohli@codeaurora.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neeraju@codeaurora.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome