All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled
@ 2020-12-31  6:03 Kai-Heng Feng
  2021-01-28  8:09 ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Kai-Heng Feng @ 2020-12-31  6:03 UTC (permalink / raw)
  To: rjw
  Cc: tiwai, kenny, Kai-Heng Feng, Pavel Machek, Len Brown,
	Greg Kroah-Hartman, open list:HIBERNATION (aka Software Suspend,
	aka swsusp),
	open list

HDA controller can't be runtime-suspended after commit 215a22ed31a1
("ALSA: hda: Refactor codjc PM to use direct-complete optimization"),
which enables direct-complete for HDA codec.

The HDA codec driver doesn't expect direct-complete will be disabled
after it returns a positive value from prepare() callback. So freeze()
is called directly when it's runtime-suspended, breaks the balance of
its internal codec_powered counting.

So if a device is prepared for direct-complete but PM core breaks the
assumption, resume the device to keep PM operations balanced.

Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization")
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/base/power/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 46793276598d..9c0e25a92ad0 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1849,6 +1849,10 @@ static int device_prepare(struct device *dev, pm_message_t state)
 		(ret > 0 || dev->power.no_pm_callbacks) &&
 		!dev_pm_test_driver_flags(dev, DPM_FLAG_NO_DIRECT_COMPLETE);
 	spin_unlock_irq(&dev->power.lock);
+
+	if (ret > 0 && !dev->power.direct_complete)
+		pm_runtime_resume(dev);
+
 	return 0;
 }
 
-- 
2.29.2


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

* Re: [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled
  2020-12-31  6:03 [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled Kai-Heng Feng
@ 2021-01-28  8:09 ` Takashi Iwai
  2021-01-28  8:15   ` Kai-Heng Feng
  2021-01-28 10:23   ` Rafael J. Wysocki
  0 siblings, 2 replies; 5+ messages in thread
From: Takashi Iwai @ 2021-01-28  8:09 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: rjw, kenny, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	open list:HIBERNATION (aka Software Suspend, aka swsusp),
	open list

On Thu, 31 Dec 2020 07:03:19 +0100,
Kai-Heng Feng wrote:
> 
> HDA controller can't be runtime-suspended after commit 215a22ed31a1
> ("ALSA: hda: Refactor codjc PM to use direct-complete optimization"),
> which enables direct-complete for HDA codec.
> 
> The HDA codec driver doesn't expect direct-complete will be disabled
> after it returns a positive value from prepare() callback. So freeze()
> is called directly when it's runtime-suspended, breaks the balance of
> its internal codec_powered counting.
> 
> So if a device is prepared for direct-complete but PM core breaks the
> assumption, resume the device to keep PM operations balanced.
> 
> Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization")
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Kai-Heng, is this fix still needed for 5.11?

The description mentions about HD-audio controller, while the recent
revert was the HD-audio codec, so I suppose it's still affected?


thanks,

Takashi

> ---
>  drivers/base/power/main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 46793276598d..9c0e25a92ad0 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1849,6 +1849,10 @@ static int device_prepare(struct device *dev, pm_message_t state)
>  		(ret > 0 || dev->power.no_pm_callbacks) &&
>  		!dev_pm_test_driver_flags(dev, DPM_FLAG_NO_DIRECT_COMPLETE);
>  	spin_unlock_irq(&dev->power.lock);
> +
> +	if (ret > 0 && !dev->power.direct_complete)
> +		pm_runtime_resume(dev);
> +
>  	return 0;
>  }
>  
> -- 
> 2.29.2
> 

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

* Re: [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled
  2021-01-28  8:09 ` Takashi Iwai
@ 2021-01-28  8:15   ` Kai-Heng Feng
  2021-01-28  8:19     ` Takashi Iwai
  2021-01-28 10:23   ` Rafael J. Wysocki
  1 sibling, 1 reply; 5+ messages in thread
From: Kai-Heng Feng @ 2021-01-28  8:15 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Rafael J. Wysocki, Kenneth R . Crudup, Pavel Machek, Len Brown,
	Greg Kroah-Hartman, open list:HIBERNATION (aka Software Suspend,
	aka swsusp),
	open list

On Thu, Jan 28, 2021 at 4:09 PM Takashi Iwai <tiwai@suse.de> wrote:
>
> On Thu, 31 Dec 2020 07:03:19 +0100,
> Kai-Heng Feng wrote:
> >
> > HDA controller can't be runtime-suspended after commit 215a22ed31a1
> > ("ALSA: hda: Refactor codjc PM to use direct-complete optimization"),
> > which enables direct-complete for HDA codec.
> >
> > The HDA codec driver doesn't expect direct-complete will be disabled
> > after it returns a positive value from prepare() callback. So freeze()
> > is called directly when it's runtime-suspended, breaks the balance of
> > its internal codec_powered counting.
> >
> > So if a device is prepared for direct-complete but PM core breaks the
> > assumption, resume the device to keep PM operations balanced.
> >
> > Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization")
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>
> Kai-Heng, is this fix still needed for 5.11?

No it's not needed anymore because "ALSA: hda: Balance runtime/system
PM if direct-complete is disabled" is in place.

>
> The description mentions about HD-audio controller, while the recent
> revert was the HD-audio codec, so I suppose it's still affected?

Not affected anymore if above mentioned patch is applied.

Kai-Heng

>
>
> thanks,
>
> Takashi
>
> > ---
> >  drivers/base/power/main.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > index 46793276598d..9c0e25a92ad0 100644
> > --- a/drivers/base/power/main.c
> > +++ b/drivers/base/power/main.c
> > @@ -1849,6 +1849,10 @@ static int device_prepare(struct device *dev, pm_message_t state)
> >               (ret > 0 || dev->power.no_pm_callbacks) &&
> >               !dev_pm_test_driver_flags(dev, DPM_FLAG_NO_DIRECT_COMPLETE);
> >       spin_unlock_irq(&dev->power.lock);
> > +
> > +     if (ret > 0 && !dev->power.direct_complete)
> > +             pm_runtime_resume(dev);
> > +
> >       return 0;
> >  }
> >
> > --
> > 2.29.2
> >

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

* Re: [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled
  2021-01-28  8:15   ` Kai-Heng Feng
@ 2021-01-28  8:19     ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2021-01-28  8:19 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Rafael J. Wysocki, Kenneth R . Crudup, Pavel Machek, Len Brown,
	Greg Kroah-Hartman, open list:HIBERNATION (aka Software Suspend,
	aka swsusp),
	open list

On Thu, 28 Jan 2021 09:15:10 +0100,
Kai-Heng Feng wrote:
> 
> On Thu, Jan 28, 2021 at 4:09 PM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > On Thu, 31 Dec 2020 07:03:19 +0100,
> > Kai-Heng Feng wrote:
> > >
> > > HDA controller can't be runtime-suspended after commit 215a22ed31a1
> > > ("ALSA: hda: Refactor codjc PM to use direct-complete optimization"),
> > > which enables direct-complete for HDA codec.
> > >
> > > The HDA codec driver doesn't expect direct-complete will be disabled
> > > after it returns a positive value from prepare() callback. So freeze()
> > > is called directly when it's runtime-suspended, breaks the balance of
> > > its internal codec_powered counting.
> > >
> > > So if a device is prepared for direct-complete but PM core breaks the
> > > assumption, resume the device to keep PM operations balanced.
> > >
> > > Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization")
> > > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> >
> > Kai-Heng, is this fix still needed for 5.11?
> 
> No it's not needed anymore because "ALSA: hda: Balance runtime/system
> PM if direct-complete is disabled" is in place.
> 
> >
> > The description mentions about HD-audio controller, while the recent
> > revert was the HD-audio codec, so I suppose it's still affected?
> 
> Not affected anymore if above mentioned patch is applied.

OK, thanks for clarification!


Takashi

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

* Re: [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled
  2021-01-28  8:09 ` Takashi Iwai
  2021-01-28  8:15   ` Kai-Heng Feng
@ 2021-01-28 10:23   ` Rafael J. Wysocki
  1 sibling, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2021-01-28 10:23 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Kai-Heng Feng, Rafael J. Wysocki, Kenneth R. Crudup,
	Pavel Machek, Len Brown, Greg Kroah-Hartman,
	open list:HIBERNATION (aka Software Suspend, aka swsusp),
	open list

On Thu, Jan 28, 2021 at 9:11 AM Takashi Iwai <tiwai@suse.de> wrote:
>
> On Thu, 31 Dec 2020 07:03:19 +0100,
> Kai-Heng Feng wrote:
> >
> > HDA controller can't be runtime-suspended after commit 215a22ed31a1
> > ("ALSA: hda: Refactor codjc PM to use direct-complete optimization"),
> > which enables direct-complete for HDA codec.
> >
> > The HDA codec driver doesn't expect direct-complete will be disabled
> > after it returns a positive value from prepare() callback. So freeze()
> > is called directly when it's runtime-suspended, breaks the balance of
> > its internal codec_powered counting.
> >
> > So if a device is prepared for direct-complete but PM core breaks the
> > assumption, resume the device to keep PM operations balanced.
> >
> > Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization")
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>
> Kai-Heng, is this fix still needed for 5.11?
>
> The description mentions about HD-audio controller, while the recent
> revert was the HD-audio codec, so I suppose it's still affected?

Regardless, this is not the right fix, because it doesn't take driver
flags into account AFAICS.

> > ---
> >  drivers/base/power/main.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > index 46793276598d..9c0e25a92ad0 100644
> > --- a/drivers/base/power/main.c
> > +++ b/drivers/base/power/main.c
> > @@ -1849,6 +1849,10 @@ static int device_prepare(struct device *dev, pm_message_t state)
> >               (ret > 0 || dev->power.no_pm_callbacks) &&
> >               !dev_pm_test_driver_flags(dev, DPM_FLAG_NO_DIRECT_COMPLETE);
> >       spin_unlock_irq(&dev->power.lock);
> > +
> > +     if (ret > 0 && !dev->power.direct_complete)
> > +             pm_runtime_resume(dev);
> > +
> >       return 0;
> >  }
> >
> > --
> > 2.29.2
> >

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

end of thread, other threads:[~2021-01-28 10:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-31  6:03 [PATCH] PM: sleep: core: Resume suspended device if direct-complete is disabled Kai-Heng Feng
2021-01-28  8:09 ` Takashi Iwai
2021-01-28  8:15   ` Kai-Heng Feng
2021-01-28  8:19     ` Takashi Iwai
2021-01-28 10:23   ` Rafael J. Wysocki

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.