All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	Oliver Neukum <oliver@neukum.org>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Jeff Garzik <jgarzik@pobox.com>,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org,
	Aaron Lu <aaron.lwe@gmail.com>
Subject: Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Date: Mon, 24 Sep 2012 09:20:12 +0800	[thread overview]
Message-ID: <20120924012010.GA14797@mint-spring.sh.intel.com> (raw)
In-Reply-To: <201209212249.33063.rjw@sisk.pl>

On Fri, Sep 21, 2012 at 10:49:32PM +0200, Rafael J. Wysocki wrote:
> On Friday, September 21, 2012, Aaron Lu wrote:
> > On Thu, Sep 20, 2012 at 10:48:10PM +0200, Rafael J. Wysocki wrote:
> > > On Wednesday, September 12, 2012, Aaron Lu wrote:
> > > > Place the ODD into runtime suspend state as soon as there is nobody
> > > > using it.
> > > 
> > > OK, so how is ODD related to the sr driver?
> > 
> > As Alan has explained, ODD(optical disk drive) is driven by scsi
> > sr driver.
> 
> OK, but what about writing "ODD (Optical Disk Drive)" in the changelog?
> 
> People reading git logs may not know all of the hardware acronyms and the
> "0" message doesn't go into the git log. :-)
> 
> > > > The only exception is, if we just find that a new medium is
> > > > inserted, we wait for the next events checking to idle it.
> > > 
> > > What exactly do you mean by "to idle it"?
> > 
> > I mean to put its usage count so that its idle callback will kick in.
> 
> So I'd just write that directly in the changelog.
> 
> > > Does this patch have any functional effect without the following patches?
> > 
> > Yes, this one alone takes care of ODD's runtime pm
> 
> I suppose you mean the runtime PM status and usage counter?  I.e. the "software
> state"?

Yes.

> 
> > while the following
> > patches take care of removing its power after it's runtime suspended.
> > But it doesn't have any real benefit without the following patches.
> 
> Please put that information into the changelog too.

As Alan explained, I think I would say:
Though currently it doesn't have any benefit, it allows its parent
devices enter runtime suspend state which may save some power.

> 
> > > > Based on ideas of Alan Stern and Oliver Neukum.
> > > > 
> > > > Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> > > > ---
> > > >  drivers/scsi/sr.c | 29 +++++++++++++++++++++++++----
> > > >  1 file changed, 25 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
> > > > index 5fc97d2..7a8222f 100644
> > > > --- a/drivers/scsi/sr.c
> > > > +++ b/drivers/scsi/sr.c
> > > > @@ -45,6 +45,7 @@
> > > >  #include <linux/blkdev.h>
> > > >  #include <linux/mutex.h>
> > > >  #include <linux/slab.h>
> > > > +#include <linux/pm_runtime.h>
> > > >  #include <asm/uaccess.h>
> > > >  
> > > >  #include <scsi/scsi.h>
> > > > @@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
> > > >  	kref_get(&cd->kref);
> > > >  	if (scsi_device_get(cd->device))
> > > >  		goto out_put;
> > > > +	if (scsi_autopm_get_device(cd->device))
> > > > +		goto out_pm;
> > > >  	goto out;
> > > 
> > > Why don't you do
> > > 
> > > > +	if (!scsi_autopm_get_device(cd->device))
> > > > +		goto out;
> > > 
> > > without the new label?
> > 
> > I was just stupidly following the pattern.
> > Thanks and I'll change this.
> > 
> > > 
> > > >  
> > > > + out_pm:
> > > > +	scsi_device_put(cd->device);
> > > >   out_put:
> > > >  	kref_put(&cd->kref, sr_kref_release);
> > > >  	cd = NULL;
> > > > @@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)
> > > >  	mutex_lock(&sr_ref_mutex);
> > > >  	kref_put(&cd->kref, sr_kref_release);
> > > >  	scsi_device_put(sdev);
> > > > +	scsi_autopm_put_device(sdev);
> > > >  	mutex_unlock(&sr_ref_mutex);
> > > >  }
> > > >  
> > > > @@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,
> > > >  				    unsigned int clearing, int slot)
> > > >  {
> > > >  	struct scsi_cd *cd = cdi->handle;
> > > > -	bool last_present;
> > > > +	bool last_present = cd->media_present;
> > > >  	struct scsi_sense_hdr sshdr;
> > > >  	unsigned int events;
> > > >  	int ret;
> > > > @@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,
> > > >  	if (CDSL_CURRENT != slot)
> > > >  		return 0;
> > > >  
> > > > +	scsi_autopm_get_device(cd->device);
> > > > +
> > > >  	events = sr_get_events(cd->device);
> > > >  	cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE;
> > > >  
> > > > @@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,
> > > >  	}
> > > >  
> > > >  	if (!(clearing & DISK_EVENT_MEDIA_CHANGE))
> > > > -		return events;
> > > > +		goto out;
> > > >  do_tur:
> > > >  	/* let's see whether the media is there with TUR */
> > > > -	last_present = cd->media_present;
> > > >  	ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
> > > >  
> > > >  	/*
> > > > @@ -270,7 +277,7 @@ do_tur:
> > > >  	}
> > > >  
> > > >  	if (cd->ignore_get_event)
> > > > -		return events;
> > > > +		goto out;
> > > >  
> > > >  	/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */
> > > >  	if (!cd->tur_changed) {
> > > > @@ -287,6 +294,12 @@ do_tur:
> > > >  	cd->tur_changed = false;
> > > >  	cd->get_event_changed = false;
> > > >  
> > > > +out:
> > > > +	if (cd->media_present && !last_present)
> > > > +		pm_runtime_put_noidle(&cd->device->sdev_gendev);
> > > > +	else
> > > > +		scsi_autopm_put_device(cd->device);
> > > > +
> > > 
> > > This thing is asking for a comment.
> > > 
> > > It looks like you're kind of avoiding to call _idle() for the device, but why?
> > > What might go wrong if pm_runtime_put() is used instead of the whole conditional,
> > > among other things?
> > 
> > The above code means, if we found that a disc is just inserted(reflected
> > by cd->media_present is true and last_present is false), we do not want
> > to put the device into suspend state immediately until next poll. In the
> > interval, some programs may decide to use this device by opening it.
> > 
> > Nothing will go wrong, but it can possibly avoid a runtime status change.
> 
> OK, so suppose the condition is true and we do the _noidle() put.  Who's
> going to suspend the device in that case if no one actually uses the device?

Next time when the check_events poll runs, it will find that:
1 Either the disc is still there, then both last_present and
  media_present would be true, we will do the put to idle it;
2 Or the disc is ejected, we will do the put to idle it.

The poll runs periodically, until the device is powered off(reflected by
the powered_off flag), in which case, the poll will simply return
0 without touching this device.

> 
> > > >  	return events;
> > > >  }
> > > >  
> > > > @@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)
> > > >  	dev_set_drvdata(dev, cd);
> > > >  	disk->flags |= GENHD_FL_REMOVABLE;
> > > >  	add_disk(disk);
> > > > +	disk_events_set_poll_msecs(disk, 5000);
> > > 
> > > Why do you need this and why is the poll interval universally suitable?
> > 
> > For a system with udev, the block module parameter events_dfl_poll_msecs
> > will be set to 2s. If disk's events_poll_msecs is not set, that will be
> > used. So the disk will be polled every 2s, that means it will be runtime
> > suspended/resumed every 2s if there is no user. I set it to 5s so that
> > the device can stay in runtime suspended state longer.
> > 
> > And the sysfs interface is still there, if udev thinks a device needs
> > special setting, it will do that and I'll not overwrite that setting.
> 
> I'm not quite convinced this is the right approach here.
> 
> So if you set it to 5 s this way, the user space will have no idea that
> the polling happens less often than it thinks, or am I misunderstanding
> what you said above?

That's correct.
AFAIK, user space does not care how often the device is polled, it
cares only one thing: when there is a media change event, please let me
know(through uevent).

I agree that we can't make user wait for too long before seeing
something happen(auto play, etc.) after he inserted a disc, and 5
seconds doesn't seem too long to me.

> 
> Moreover, what about changing the code so that the polling doesn't
> actually resume the device?

Since the device is going to do IO(executing a scsi command), I think I
should resume the device.

But there is a case for ZPODD, when the ODD is powered off(reflected by
the powered_off flag), the events checking will simply return without
resuming the device.

> 
> > > >  
> > > >  	sdev_printk(KERN_DEBUG, sdev,
> > > >  		    "Attached scsi CD-ROM %s\n", cd->cdi.name);
> > > > +
> > > > +	/* enable runtime pm */
> > > 
> > > Not really.  What it does is to enable the device to be suspended.
> > 
> > OK, will change this.
> > 
> > > 
> > > > +	scsi_autopm_put_device(cd->device);
> > > > +
> > > >  	return 0;
> > > >  
> > > >  fail_put:
> > > > @@ -965,6 +983,9 @@ static int sr_remove(struct device *dev)
> > > >  {
> > > >  	struct scsi_cd *cd = dev_get_drvdata(dev);
> > > >  
> > > > +	/* disable runtime pm */
> > > 
> > > And that prevents the device from being suspended (which means that it's
> > > going to be resumed at this point in case it was suspended before).
> > 
> > Yes, that's what I want.
> > We are removing its driver and I think we should undo what we have done
> > to it.
> 
> Yes, I agree.  Only the comment wording can better reflect what really
> happens here (runtime PM is not disabled, in particular).

OK, looks like you are saying by disable, disable_depth is the subject
while I'm playing with usage_count. I'll pay attention to these words,
thanks for the remind.

-Aaron

  reply	other threads:[~2012-09-24  1:20 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12  8:29 [PATCH v7 0/6] ZPODD patches Aaron Lu
2012-09-12  8:29 ` [PATCH v7 1/6] block: genhd: add an interface to set disk poll interval Aaron Lu
2012-09-20 20:35   ` Rafael J. Wysocki
2012-09-12  8:29 ` [PATCH v7 2/6] scsi: sr: support runtime pm Aaron Lu
2012-09-20 20:48   ` Rafael J. Wysocki
2012-09-20 20:54     ` Alan Stern
2012-09-21  1:02     ` Aaron Lu
2012-09-21 20:49       ` Rafael J. Wysocki
2012-09-24  1:20         ` Aaron Lu [this message]
2012-09-24 12:55           ` Rafael J. Wysocki
2012-09-24 14:52             ` Aaron Lu
2012-09-24 21:40               ` Rafael J. Wysocki
2012-09-25  8:01                 ` Aaron Lu
2012-09-25 11:47                   ` Rafael J. Wysocki
2012-09-25 14:20                     ` Aaron Lu
2012-09-25 14:23                       ` Oliver Neukum
2012-09-25 14:46                         ` Aaron Lu
2012-09-25 21:45                           ` Rafael J. Wysocki
2012-09-26  1:03                             ` Aaron Lu
2012-09-26 11:18                               ` Rafael J. Wysocki
2012-09-26 14:52                                 ` Aaron Lu
2012-09-26  7:20                           ` Oliver Neukum
2012-09-27 10:46                   ` Oliver Neukum
2012-09-28  8:20                     ` Aaron Lu
2012-09-12  8:29 ` [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD) Aaron Lu
2012-09-20 22:07   ` Rafael J. Wysocki
2012-09-21  1:39     ` Aaron Lu
2012-09-21 21:02       ` Rafael J. Wysocki
2012-09-27  9:26         ` Aaron Lu
2012-09-27 14:42           ` Alan Stern
2012-09-27 14:55             ` Aaron Lu
2012-09-27 23:29               ` Rafael J. Wysocki
2012-09-24 21:55   ` Jeff Garzik
2012-09-12  8:29 ` [PATCH v7 4/6] scsi: pm: add may_power_off flag Aaron Lu
2012-09-12  8:29 ` [PATCH v7 5/6] scsi: sr: use may_power_off Aaron Lu
2012-09-12  8:29 ` [PATCH v7 6/6] libata: acpi: respect may_power_off flag Aaron Lu
2012-09-24 21:55   ` Jeff Garzik
2012-09-19  8:03 ` [PATCH v7 0/6] ZPODD patches Aaron Lu
2012-09-19 12:27   ` James Bottomley
2012-09-19 12:50     ` Rafael J. Wysocki
2012-09-19 14:19       ` Aaron Lu
2012-09-20 20:00         ` Rafael J. Wysocki
2012-09-21  5:48           ` Aaron Lu
2012-09-21 21:18             ` Rafael J. Wysocki
2012-09-22  7:32               ` Oliver Neukum
2012-09-22 11:28                 ` Rafael J. Wysocki
2012-09-22 15:38                   ` Alan Stern
2012-09-22 19:46                     ` Rafael J. Wysocki
2012-09-22 20:23                       ` Alan Stern
2012-09-22 21:48                         ` Rafael J. Wysocki
2012-09-24  2:55               ` Aaron Lu
2012-09-24 13:06                 ` Rafael J. Wysocki
2012-09-24 15:04                   ` Aaron Lu
2012-09-24 21:46                     ` Rafael J. Wysocki
2012-09-25  8:18                       ` Aaron Lu
2012-09-25 11:02                         ` James Bottomley
2012-09-25 13:56                           ` Aaron Lu
2012-09-27  9:43                           ` Aaron Lu
2012-09-24 15:47                 ` Alan Stern
2012-09-19 14:52       ` James Bottomley
2012-09-20 21:46         ` Rafael J. Wysocki
2012-09-19 13:05     ` Oliver Neukum
2012-09-19 15:19     ` David Woodhouse
2012-09-20  0:34       ` Jack Wang
     [not found] ` <201209280115.06964.rjw@sisk.pl>
     [not found]   ` <5064FA08.6030005@intel.com>
     [not found]     ` <201209282346.15872.rjw@sisk.pl>
2012-09-29  2:10       ` [PATCH v7 2/6] scsi: sr: support runtime pm Aaron Lu
2012-09-29 14:29         ` Alan Stern
2012-09-29 15:03           ` Aaron Lu
2012-09-29 22:44             ` Rafael J. Wysocki
2012-09-30 12:32               ` Aaron Lu
2012-09-30 14:47                 ` Alan Stern
2012-09-30 15:39                   ` Aaron Lu
2012-09-30 19:15                   ` Jeff Garzik
2012-09-30 19:08               ` Jeff Garzik
2012-09-29 22:31           ` Rafael J. Wysocki
2012-09-30 19:03             ` Jeff Garzik
2012-09-30 19:43               ` Alan Stern
2012-10-01  4:57                 ` Jeff Garzik
2012-10-08  9:27                 ` Aaron Lu
2012-10-08 10:21                   ` James Bottomley
2012-10-09  7:20                     ` Aaron Lu
2012-10-09 14:58                       ` James Bottomley
2012-10-11  7:49                         ` Aaron Lu
2012-10-09 23:26                       ` Rafael J. Wysocki
2012-09-29 22:27         ` Rafael J. Wysocki
2012-09-30 12:38           ` Aaron Lu

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=20120924012010.GA14797@mint-spring.sh.intel.com \
    --to=aaron.lu@intel.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=aaron.lwe@gmail.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=oliver@neukum.org \
    --cc=rjw@sisk.pl \
    --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 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.