public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Linux-pm mailing list <linux-pm@lists.linux-foundation.org>
Subject: Re: [PATCH ver. 2] PM: allow for usage_count > 0 in pm_runtime_get()
Date: Thu, 3 Dec 2009 21:03:34 +0100	[thread overview]
Message-ID: <200912032103.34989.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0912031235560.4795-100000@iolanthe.rowland.org>

On Thursday 03 December 2009, Alan Stern wrote:
> On Wed, 2 Dec 2009, Alan Stern wrote:
> 
> > This patch (as1308b) fixes __pm_runtime_get().  Currently the routine
> > will resume a device if the prior usage count was 0.  But this isn't
> > right; thanks to pm_runtime_get_noresume() the usage count can be
> > positive even while the device is suspended.
> > 
> > Now the routine always tries to carry out a resume when called
> > synchronously.  When called asynchronously, it avoids the overhead of
> > an unnecessary spinlock acquisition by doing the resume only if the
> > device's state was SUSPENDING or SUSPENDED.  Since the access to the
> > state is unprotected, be careful to read the value only once.
> 
> ...
> 
> >  int __pm_runtime_get(struct device *dev, bool sync)
> >  {
> > -	int retval = 1;
> > +	int retval = 0;
> >  
> > -	if (atomic_add_return(1, &dev->power.usage_count) == 1)
> > -		retval = sync ? pm_runtime_resume(dev) : pm_request_resume(dev);
> > +	atomic_inc(&dev->power.usage_count);
> > +	if (sync) {
> > +		retval = pm_runtime_resume(dev);
> > +	} else {
> > +		enum rpm_status s = ACCESS_ONCE(dev->power.runtime_status);
> >  
> > +		if (s == RPM_SUSPENDING || s == RPM_SUSPENDED)
> > +			retval = pm_request_resume(dev);
> > +	}
> >  	return retval;
> >  }
> 
> I wonder whether this is really a good thing to do.  It changes the
> semantics in the async case where the device is already active.  The
> old code would cancel a pending or scheduled suspend request, whereas
> the new code will leave it alone.

I prefer the old behavior in that respect.

> My feeling was that an atomic routine would most likely do its work and
> then schedule a new suspend request before the old one expired, so it
> wouldn't matter if the old request wasn't cancelled.  Still, some
> drivers might have their own preferences.
> 
> Of course, this is just a convenient utility routine.  Anybody can 
> simply do
> 
> 	pm_runtime_get_noresume(dev);
> 	switch (ACCESS_ONCE(dev->power.runtime_status)) {
> 	case RPM_SUSPENDING:
> 	case RPM_SUSPENDED:
> 		pm_request_resume(dev);
> 	default:
> 	}
> 
> and obtain the same effect.  So I don't know...  Should
> pm_runtime_get() call pm_request_resume() always, or only when the
> state is SUSPENDING or SUSPENDED?  Should we offer two routines and let
> people choose which they want?

I'd prefer to keep the current semantics, ie. drop the patch, at least for now.

I think it's reasonable to expect the users of pm_runtime_get_noresume() to
pay attention. ;-)

Thanks,
Rafael

  reply	other threads:[~2009-12-03 20:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-02 16:13 [PATCH ver. 2] PM: allow for usage_count > 0 in pm_runtime_get() Alan Stern
2009-12-03 17:47 ` Alan Stern
2009-12-03 20:03   ` Rafael J. Wysocki [this message]
2009-12-03 20:24     ` Alan Stern

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=200912032103.34989.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=stern@rowland.harvard.edu \
    /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