From: Takashi Iwai <tiwai@suse.de>
To: David Henningsson <david.henningsson@canonical.com>
Cc: "Lin, Mengdong" <mengdong.lin@intel.com>,
"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Re: [PATCH] ALSA: hda - delay resume haswell hdmi codec in system resume
Date: Fri, 05 Apr 2013 15:01:47 +0200 [thread overview]
Message-ID: <s5hmwtd2ksk.wl%tiwai@suse.de> (raw)
In-Reply-To: <515AD3E4.2000208@canonical.com>
At Tue, 02 Apr 2013 14:49:40 +0200,
David Henningsson wrote:
>
> On 04/02/2013 02:18 PM, Takashi Iwai wrote:
> > At Tue, 02 Apr 2013 13:53:16 +0200,
> > David Henningsson wrote:
> >>
> >> On 03/27/2013 11:01 AM, Lin, Mengdong wrote:
> >>>> -----Original Message-----
> >>>> From: David Henningsson [mailto:david.henningsson@canonical.com]
> >>>> Sent: Wednesday, March 27, 2013 4:19 PM
> >>>
> >>>>> The Haswell codec set_power_state ops (intel_haswell_set_power_state) will
> >>>> only wait if this is a delayed resume and clear this flag after waiting. And
> >>>> actually, there is no waiting even in this case. Because when 1st user operation
> >>>> after system resume happens, Gfx already finishes resuming and audio
> >>>> initialization, so as long as intel_haswell_wait_ready_to_resume() enable the
> >>>> unsol event, the unsol event comes and so so waiting finishes. The 300ms time
> >>>> out is set for safety consideration in case unsol event is lost. I've not observed
> >>>> any unsol event lost till now.
> >>>>
> >>>> As for the timeout, I suggest you use the codec->bus->workq instead of
> >>>> creating a new workq. I think that will also give us some serialisation, i e,
> >>>> protection against race conditions if the timeout happen at the same time as
> >>>> the unsol event.
> >>>
> >>> Hi David,
> >>>
> >>> The new added "resume_wq" for hdmi codec is a wait queue, not a work queue like codec->bus->workq.
> >>> It's expected to wake up as soon as the unsol event is got.
> >>
> >> Sure; but I don't see why you need a wait queue for that? Why don't you
> >> just call the resume path from the unsol event handler
> >> (hdmi_present_sense, or its caller), and then also cancel the timeout
> >> handler (which can then be in the normal workq)?
> >
> > Because the delayed resume actually fakes as if the resume is done.
> > This is necessary not to block other device's resume operation.
> >
> > Since it looks as if ready, user-space might restart things soon again
> > before the delayed resume is really finished. So, some serialization
> > is required there.
>
> Lin, would it be possible to add some chain of events description to the
> bug commit? The different contexts are just boggling my mind :-)
Yeah, a nice code flow picture would be helpful :)
> Assume we have two cases, system idle after S3 and immediate playback
> after S3.
>
> Is this correct:
>
> System idle:
> 1. System skips hda_call_codec_resume and sets codec->resume_delayed.
> 2. Since the codec is not reinitialized, nothing powers up the codec,
> so this is all that happens.
> 3. Since unsol events are not enabled (?), we have a bug that jack
> detection does not work and cannot be detected from userspace...?
>
> Immediate playback:
> 1. System skips hda_call_codec_resume and sets codec->resume_delayed.
> 2. Process context wants to start playback, which powers up the codec
> and calls intel_haswell_set_power_state.
> 3. intel_haswell_wait_ready_to_resume enables unsol events and starts
> to wait on ready_to_resume
> 4. Gfx init finishes, and workq context fires the unsol event, which
> calls hdmi_intrinsic_event, which triggers the resume_wq.
> 5. Process context and workq context now continues in parallel,
> potentially (but hopefully not) leading to race conditions?
The current patch has a small race, but it can be avoided by clearing
spec->ready_to_resume early enough, e.g. in suspend callback or in
init callback, like the patch below.
Takashi
---
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 67e11ba..d0eafee 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -1740,6 +1740,9 @@ static int generic_hdmi_init(struct hda_codec *codec)
hdmi_init_pin(codec, pin_nid);
snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
}
+
+ spec->ready_to_resume = 0;
+
return 0;
}
@@ -1876,8 +1879,6 @@ static void intel_haswell_wait_ready_to_resume(struct hda_codec *codec)
struct hdmi_spec *spec = codec->spec;
int pin_idx;
- spec->ready_to_resume = 0;
-
for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
struct hdmi_spec_per_pin *per_pin;
hda_nid_t pin_nid;
next prev parent reply other threads:[~2013-04-05 13:01 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-26 18:12 [PATCH] ALSA: hda - delay resume haswell hdmi codec in system resume mengdong.lin
2013-03-26 7:02 ` Lin, Mengdong
2013-04-02 9:53 ` Takashi Iwai
2013-04-05 16:58 ` Lin, Mengdong
2013-04-07 7:28 ` Takashi Iwai
2013-03-26 10:58 ` David Henningsson
2013-03-27 2:03 ` Lin, Mengdong
2013-03-27 8:19 ` David Henningsson
2013-03-27 10:01 ` Lin, Mengdong
2013-04-02 11:53 ` David Henningsson
2013-04-02 12:18 ` Takashi Iwai
2013-04-02 12:49 ` David Henningsson
2013-04-05 13:01 ` Takashi Iwai [this message]
2013-04-05 13:08 ` Takashi Iwai
2013-04-05 16:42 ` Lin, Mengdong
2013-04-05 17:04 ` Takashi Iwai
2013-04-07 0:10 ` Lin, Mengdong
2013-04-08 9:49 ` David Henningsson
2013-04-08 10:24 ` Takashi Iwai
2013-04-08 11:06 ` Lin, Mengdong
2013-04-08 11:35 ` David Henningsson
2013-04-08 11:59 ` Takashi Iwai
2013-04-08 12:20 ` David Henningsson
2013-04-08 12:23 ` Takashi Iwai
2013-04-08 13:30 ` David Henningsson
2013-04-08 13:49 ` Takashi Iwai
2013-04-08 15:47 ` Lin, Mengdong
2013-04-09 6:45 ` David Henningsson
2013-04-09 6:53 ` Takashi Iwai
2013-04-09 7:10 ` David Henningsson
2013-04-09 7:42 ` Takashi Iwai
2013-04-09 8:18 ` Lin, Mengdong
2013-04-09 9:15 ` David Henningsson
2013-04-09 9:26 ` Takashi Iwai
2013-04-10 5:29 ` David Henningsson
2013-04-10 5:47 ` Takashi Iwai
2013-04-10 6:02 ` David Henningsson
2013-04-10 6:52 ` Takashi Iwai
2013-04-10 10:38 ` David Henningsson
2013-04-14 13:48 ` Lin, Mengdong
2013-04-15 7:02 ` David Henningsson
2013-04-15 7:48 ` Lin, Mengdong
2013-04-17 5:51 ` David Henningsson
2013-04-17 6:12 ` Takashi Iwai
2013-05-03 6:56 ` Lin, Mengdong
2013-05-03 7:20 ` David Henningsson
2013-05-03 7:30 ` Lin, Mengdong
2013-05-06 6:27 ` Lin, Mengdong
2013-05-06 7:08 ` David Henningsson
2013-05-06 9:48 ` Lin, Mengdong
2013-04-05 13:06 ` Takashi Iwai
2013-04-05 13:12 ` Takashi Iwai
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=s5hmwtd2ksk.wl%tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=david.henningsson@canonical.com \
--cc=mengdong.lin@intel.com \
/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