mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
@ 2009-09-21 21:37 Rafael J. Wysocki
  2009-09-22  7:16 ` Arjan van de Ven
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2009-09-21 21:37 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: LKML, Linux PCI, pm list

From: Rafael J. Wysocki <rjw@sisk.pl>

After attempting to change the power state of a PCI device
pci_raw_set_power_state() doesn't check if the value it wrote into
the device's PCI_PM_CTRL register has been stored in there, but
unconditionally modifies the device's current_state field to reflect
the change.  This may cause problems to happen if the power state of
the device hasn't been changed in fact, because it will make the PCI
PM core think that the device is in a power state it really is not
in.

To prevent such situations from happening modify
pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL
register after writing into it and uses the value read from the
register to update the device's current_state field.  Also make it
print a message saying that the device refused to change its power
state as requested (returning an error code in such cases would cause
suspend regressions to appear on some systems, where device drivers'
suspend routines return error codes if pci_set_power_state() fails).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/pci/pci.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/pci/pci.c
===================================================================
--- linux-2.6.orig/drivers/pci/pci.c
+++ linux-2.6/drivers/pci/pci.c
@@ -513,7 +513,12 @@ static int pci_raw_set_power_state(struc
 	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(PCI_PM_D2_DELAY);
 
-	dev->current_state = state;
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	/* Return error code if we have failed to change the state */
+	if (dev->current_state != state)
+		dev_info(&dev->dev, "Refused to change power state, "
+			"currently in D%d\n", dev->current_state);
 
 	/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
 	 * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
  2009-09-21 21:37 [PATCH] PCI PM: Read device power state from register after updating it (rev. 2) Rafael J. Wysocki
@ 2009-09-22  7:16 ` Arjan van de Ven
  2009-09-22 19:51   ` Rafael J. Wysocki
  2009-09-22  8:07 ` Andreas Mohr
  2009-09-22 20:58 ` [PATCH] PCI PM: Read device power state from register after updating it (rev. 3) Rafael J. Wysocki
  2 siblings, 1 reply; 7+ messages in thread
From: Arjan van de Ven @ 2009-09-22  7:16 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jesse Barnes, LKML, Linux PCI, pm list

On Mon, 21 Sep 2009 23:37:01 +0200
"Rafael J. Wysocki" <rjw@sisk.pl> wrote:
>  
> -	dev->current_state = state;
> +	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> +	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
> +	/* Return error code if we have failed to change the state */
> +	if (dev->current_state != state)
> +		dev_info(&dev->dev, "Refused to change power state, "
> +			"currently in D%d\n", dev->current_state);

I would suspect that you want this message only once...
to avoid it flooding logs and such

or at least ratelimiting it


-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
  2009-09-21 21:37 [PATCH] PCI PM: Read device power state from register after updating it (rev. 2) Rafael J. Wysocki
  2009-09-22  7:16 ` Arjan van de Ven
@ 2009-09-22  8:07 ` Andreas Mohr
  2009-09-22 19:50   ` Rafael J. Wysocki
  2009-09-22 20:58 ` [PATCH] PCI PM: Read device power state from register after updating it (rev. 3) Rafael J. Wysocki
  2 siblings, 1 reply; 7+ messages in thread
From: Andreas Mohr @ 2009-09-22  8:07 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pci, pm list, LKML

Hi Rafael,

first you say "returning an error code in such cases would..."
and then the patch content has...?

Andreas Mohr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
  2009-09-22  8:07 ` Andreas Mohr
@ 2009-09-22 19:50   ` Rafael J. Wysocki
       [not found]     ` <7004b08e0909221256m6d917531kc8b51e1af85d3459@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2009-09-22 19:50 UTC (permalink / raw)
  To: Andreas Mohr; +Cc: linux-pci, pm list, LKML

On Tuesday 22 September 2009, Andreas Mohr wrote:
> Hi Rafael,

Hi,

> first you say "returning an error code in such cases would..."
> and then the patch content has...?

I don't quite understand your comment, care to elaborate?

Rafael

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
  2009-09-22  7:16 ` Arjan van de Ven
@ 2009-09-22 19:51   ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2009-09-22 19:51 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Jesse Barnes, LKML, Linux PCI, pm list

On Tuesday 22 September 2009, Arjan van de Ven wrote:
> On Mon, 21 Sep 2009 23:37:01 +0200
> "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> >  
> > -	dev->current_state = state;
> > +	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> > +	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
> > +	/* Return error code if we have failed to change the state */
> > +	if (dev->current_state != state)
> > +		dev_info(&dev->dev, "Refused to change power state, "
> > +			"currently in D%d\n", dev->current_state);
> 
> I would suspect that you want this message only once...
> to avoid it flooding logs and such

Hmm?  I don't think we use pci_set_power_state() _that_ often.

> or at least ratelimiting it

That sounds like a good idea, though, will respin.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] PCI PM: Read device power state from register after updating it (rev. 2)
       [not found]     ` <7004b08e0909221256m6d917531kc8b51e1af85d3459@mail.gmail.com>
@ 2009-09-22 20:39       ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2009-09-22 20:39 UTC (permalink / raw)
  To: kevin granade; +Cc: Andreas Mohr, linux-pci, pm list, LKML

On Tuesday 22 September 2009, kevin granade wrote:
> On Tue, Sep 22, 2009 at 2:50 PM, Rafael J. Wysocki <rjw@sisk.pl> wrote:
> 
> > On Tuesday 22 September 2009, Andreas Mohr wrote:
> > > Hi Rafael,
> >
> > Hi,
> >
> > > first you say "returning an error code in such cases would..."
> > > and then the patch content has...?
> >
> > I don't quite understand your comment, care to elaborate?
> >
> >
> I think this is what was being referenced:
> 
> +       /* Return error code if we have failed to change the state */
> +       if (dev->current_state != state)
> +               dev_info(&dev->dev, "Refused to change power state, "
> +                       "currently in D%d\n", dev->current_state);
> 
> The comment says, "Return error code", where it should probably say, "Log
> error".  Or possibly no comment at all.

Ah, thanks.

Rafael

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] PCI PM: Read device power state from register after updating it (rev. 3)
  2009-09-21 21:37 [PATCH] PCI PM: Read device power state from register after updating it (rev. 2) Rafael J. Wysocki
  2009-09-22  7:16 ` Arjan van de Ven
  2009-09-22  8:07 ` Andreas Mohr
@ 2009-09-22 20:58 ` Rafael J. Wysocki
  2 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2009-09-22 20:58 UTC (permalink / raw)
  To: Jesse Barnes
  Cc: LKML, Linux PCI, pm list, Arjan van de Ven, Andreas Mohr, kevin granade

From: Rafael J. Wysocki <rjw@sisk.pl>

After attempting to change the power state of a PCI device
pci_raw_set_power_state() doesn't check if the value it wrote into
the device's PCI_PM_CTRL register has been stored in there, but
unconditionally modifies the device's current_state field to reflect
the change.  This may cause problems to happen if the power state of
the device hasn't been changed in fact, because it will make the PCI
PM core think that the device is in a power state it really is not
in.

To prevent such situations from happening modify
pci_raw_set_power_state() so that it reads the device's PCI_PM_CTRL
register after writing into it and uses the value read from the
register to update the device's current_state field.  Also make it
print a message saying that the device refused to change its power
state as requested (returning an error code in such cases would cause
suspend regressions to appear on some systems, where device drivers'
suspend routines return error codes if pci_set_power_state() fails).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
Respin to fix issues pointed out by the reviewers.

Thanks,
Rafael
---
 drivers/pci/pci.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/pci/pci.c
===================================================================
--- linux-2.6.orig/drivers/pci/pci.c
+++ linux-2.6/drivers/pci/pci.c
@@ -513,7 +513,11 @@ static int pci_raw_set_power_state(struc
 	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(PCI_PM_D2_DELAY);
 
-	dev->current_state = state;
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	if (dev->current_state != state && printk_ratelimit())
+		dev_info(&dev->dev, "Refused to change power state, "
+			"currently in D%d\n", dev->current_state);
 
 	/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
 	 * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-09-22 20:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-21 21:37 [PATCH] PCI PM: Read device power state from register after updating it (rev. 2) Rafael J. Wysocki
2009-09-22  7:16 ` Arjan van de Ven
2009-09-22 19:51   ` Rafael J. Wysocki
2009-09-22  8:07 ` Andreas Mohr
2009-09-22 19:50   ` Rafael J. Wysocki
     [not found]     ` <7004b08e0909221256m6d917531kc8b51e1af85d3459@mail.gmail.com>
2009-09-22 20:39       ` Rafael J. Wysocki
2009-09-22 20:58 ` [PATCH] PCI PM: Read device power state from register after updating it (rev. 3) Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®