All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Nitish Ambastha <nits.ambastha@gmail.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Nitish Ambastha <nitish.a@samsung.com>,
	pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, cpgs@samsung.com
Subject: Re: [PATCHv3 1/1] kernel/power/autosleep.c: check for pm_suspend() return before queueing suspend again
Date: Tue, 14 Jul 2015 09:34:08 +0530	[thread overview]
Message-ID: <CAHWDpXj+AjD3F+8RvRFePXCXRKq=WBh0MKy-39B2emjG+Qamxw@mail.gmail.com> (raw)
In-Reply-To: <1834201.LA0RYhhP7u@vostro.rjw.lan>

On Tue, Jul 14, 2015 at 5:13 AM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Tuesday, July 14, 2015 01:38:02 AM Nitish Ambastha wrote:
>> Prevent tight loop for suspend-resume when some
>> devices failed to suspend
>
> This *still* doesn't explain what problem you're *really* trying to address.
>
> Even if a driver returns an error code from one of its suspend callbacks,
> you should get final_count == initial_count in the final check and we'll
> schedule the timeout.
>
> So there is a failure scenarion you're trying to address where that check is
> not sufficient, but you're not saying what the scenario is.
>
As I mentioned earlier, if some driver failed to suspend, and during
resume if *somebody* called pm_stay_awake() or pm_wakeup_event()
meantime, and then pm_relax(), final_count and initial_count will not
be the same in try_to_suspend(). We observed this behavior with
battery monitor thread on being restarted

In these scenarios, it will be considered a *valid wakeup* event and
it will try to queue suspend immediately, though the actual reason of
resume was driver returning error code.
For such scenarios, event count may not always be safe way to identify.

> Quite frankly, it seems to me that you're trying to hide a spurious wakeup.
>
>
>> If some devices failed to suspend, we monitor this
>> error in try_to_suspend(). pm_suspend() is already
>> an 'int' returning function, how about checking return
>> from pm_suspend() before queueing suspend again?
>>
>> For devices which do not register for pending events,
>> this will prevent tight loop for suspend-resume in
>> suspend abort scenarios due to device suspend failures
>>
>> Signed-off-by: Nitish Ambastha <nitish.a@samsung.com>
>> ---
>> v2: Rearranged code to make wait entry shared with
>>     existing one as suggested by Pavel Machek <pavel@ucw.cz>
>>     Corrected log level from pr_info to pr_err for failure log
>>     Added return check for hibernate()
>>
>> v3: Restructured code as suggested by Rafael J Wysocki <rjw@rjwysocki.net>
>>
>>  kernel/power/autosleep.c |   20 +++++++++-----------
>>  1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/kernel/power/autosleep.c b/kernel/power/autosleep.c
>> index 9012ecf..e458d0c 100644
>> --- a/kernel/power/autosleep.c
>> +++ b/kernel/power/autosleep.c
>> @@ -26,6 +26,7 @@ static struct wakeup_source *autosleep_ws;
>>  static void try_to_suspend(struct work_struct *work)
>>  {
>>       unsigned int initial_count, final_count;
>> +     int error;
>>
>>       if (!pm_get_wakeup_count(&initial_count, true))
>>               goto out;
>> @@ -42,23 +43,20 @@ static void try_to_suspend(struct work_struct *work)
>>               mutex_unlock(&autosleep_lock);
>>               return;
>>       }
>> -     if (autosleep_state >= PM_SUSPEND_MAX)
>> -             hibernate();
>> -     else
>> -             pm_suspend(autosleep_state);
>>
>> -     mutex_unlock(&autosleep_lock);
>> +     error = autosleep_state < PM_SUSPEND_MAX ?
>> +             pm_suspend(autosleep_state) : hibernate();
>>
>> -     if (!pm_get_wakeup_count(&final_count, false))
>> -             goto out;
>> +     mutex_unlock(&autosleep_lock);
>>
>>       /*
>> -      * If the wakeup occured for an unknown reason, wait to prevent the
>> -      * system from trying to suspend and waking up in a tight loop.
>> +      * If some devices failed to suspend or if the wakeup ocurred
>> +      * for an unknown reason, wait to prevent the system from
>> +      * trying to suspend and waking up in a tight loop.
>>        */
>> -     if (final_count == initial_count)
>> +     if (error || (pm_get_wakeup_count(&final_count, false)
>> +             && (final_count == initial_count)))
>>               schedule_timeout_uninterruptible(HZ / 2);
>> -
>>   out:
>>       queue_up_suspend_work();
>>  }
>>
>
> --
> I speak only for myself.
> Rafael J. Wysocki, Intel Open Source Technology Center.

  reply	other threads:[~2015-07-14  4:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 12:34 [PATCH 1/1] kernel/power/autosleep.c: check for pm_suspend() return before queueing suspend again Nitish Ambastha
2015-06-29  9:21 ` Pavel Machek
2015-06-29 18:54 ` [PATCHv2 " Nitish Ambastha
2015-06-29 19:56   ` Rafael J. Wysocki
2015-06-29 20:07     ` Rafael J. Wysocki
2015-06-30 19:22       ` Nitish Ambastha
2015-06-30 20:01         ` Rafael J. Wysocki
2015-07-04 18:06           ` Nitish Ambastha
2015-07-13 20:08   ` [PATCHv3 " Nitish Ambastha
2015-07-13 20:24     ` Nitish Ambastha
2015-07-13 23:43     ` Rafael J. Wysocki
2015-07-14  4:04       ` Nitish Ambastha [this message]
2015-07-15 22:29         ` Rafael J. Wysocki
2015-07-22 20:11           ` Nitish Ambastha

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='CAHWDpXj+AjD3F+8RvRFePXCXRKq=WBh0MKy-39B2emjG+Qamxw@mail.gmail.com' \
    --to=nits.ambastha@gmail.com \
    --cc=cpgs@samsung.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=nitish.a@samsung.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.