On 3.10 kernel, there is a patch fixing the noise upon resume (when bypassing CRAS):
d1484eea7a32 CHROMIUM: ASoC: Intel: Reset hw_ptr on resume trigger
I applied the patch on 4.4 kernel, but I am not sure whether the result is expected.
In my testing, I play audio bypassing CRAS:
$ aplay -D hw:1,0 test.wav
$ powerd_dbus_suspend (in another terminal).
I attached the logs when the patch is not applied (messages.noise) and when the patch is applied (messages.reset_hw_ptr), both with dev_dbg enabled.
Then, I compared how appl_ptr and hw_ptr move after resume:
In messages.noise:
2017-08-03T05:35:48.781353-07:00 DEBUG kernel: [ 164.744220] Baytrail Audio: PCM: trigger 6
2017-08-03T05:35:48.781380-07:00 DEBUG kernel: [ 164.744265] Baytrail Audio: PCM: DMA pointer 92928 bytes
2017-08-03T05:35:48.781385-07:00 DEBUG kernel: [ 164.744650] Baytrail Audio: stream context restored at offset 92928
2017-08-03T05:35:48.781388-07:00 DEBUG kernel: [ 164.744744] Baytrail Audio: PCM: App/DMA pointer 92928/768 bytes (a)-------> appl_ptr is set to hw_ptr. hw_ptr is set to 768.
2017-08-03T05:35:48.781390-07:00 DEBUG kernel: [ 164.744750] Baytrail Audio: PCM: DMA pointer 768 bytes
2017-08-03T05:35:48.781445-07:00 DEBUG kernel: [ 164.744864] Baytrail Audio: PCM: App/DMA pointer 92928/1536 bytes
2017-08-03T05:35:48.781450-07:00 DEBUG kernel: [ 164.744868] Baytrail Audio: PCM: DMA pointer 1536 bytes
2017-08-03T05:35:48.782352-07:00 DEBUG kernel: [ 164.744947] Baytrail Audio: PCM: App/DMA pointer 0/2304 bytes (b) -------> appl_ptr is set to 0.
2017-08-03T05:35:48.782375-07:00 DEBUG kernel: [ 164.744952] Baytrail Audio: PCM: DMA pointer 2304 bytes
2017-08-03T05:35:48.782380-07:00 DEBUG kernel: [ 164.744975] Baytrail Audio: PCM: DMA pointer 2304 bytes
2017-08-03T05:35:48.784794-07:00 DEBUG kernel: [ 164.746833] Baytrail Audio: PCM: App/DMA pointer 2304/3072 bytes (c)-------> appl_ptr is set to hw_ptr.
2017-08-03T05:35:48.784808-07:00 DEBUG kernel: [ 164.746841] Baytrail Audio: PCM: DMA pointer 3072 bytes
2017-08-03T05:35:48.789154-07:00 DEBUG kernel: [ 164.750843] Baytrail Audio: PCM: App/DMA pointer 2304/3840 bytes
2017-08-03T05:35:48.789173-07:00 DEBUG kernel: [ 164.750852] Baytrail Audio: PCM: DMA pointer 3840 bytes
2017-08-03T05:35:48.792600-07:00 DEBUG kernel: [ 164.754849] Baytrail Audio: PCM: App/DMA pointer 2304/4608 bytes
2017-08-03T05:35:48.792615-07:00 DEBUG kernel: [ 164.754859] Baytrail Audio: PCM: DMA pointer 4608 bytes
2017-08-03T05:35:48.796377-07:00 DEBUG kernel: [ 164.758848] Baytrail Audio: PCM: App/DMA pointer 2304/5376 bytes
2017-08-03T05:35:48.796396-07:00 DEBUG kernel: [ 164.758857] Baytrail Audio: PCM: DMA pointer 5376 bytes
2017-08-03T05:35:48.800333-07:00 DEBUG kernel: [ 164.762851] Baytrail Audio: PCM: App/DMA pointer 2304/6144 bytes
2017-08-03T05:35:48.800346-07:00 DEBUG kernel: [ 164.762860] Baytrail Audio: PCM: DMA pointer 6144 bytes
2017-08-03T05:35:48.804338-07:00 DEBUG kernel: [ 164.766859] Baytrail Audio: PCM: App/DMA pointer 2304/6912 bytes
2017-08-03T05:35:48.804363-07:00 DEBUG kernel: [ 164.766868] Baytrail Audio: PCM: DMA pointer 6912 bytes
2017-08-03T05:35:48.808583-07:00 DEBUG kernel: [ 164.770866] Baytrail Audio: PCM: App/DMA pointer 2304/7680 bytes
2017-08-03T05:35:48.808608-07:00 DEBUG kernel: [ 164.770875] Baytrail Audio: PCM: DMA pointer 7680 bytes
2017-08-03T05:35:48.812345-07:00 DEBUG kernel: [ 164.774868] Baytrail Audio: PCM: App/DMA pointer 2304/8448 bytes
In messages.reset_hw_ptr:
2017-08-03T05:43:52.777344-07:00 DEBUG kernel: [ 218.165640] Baytrail Audio: PCM: trigger 6
2017-08-03T05:43:52.777371-07:00 DEBUG kernel: [ 218.165688] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T05:43:52.777375-07:00 DEBUG kernel: [ 218.165850] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T05:43:52.777378-07:00 DEBUG kernel: [ 218.165876] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T05:43:52.777381-07:00 DEBUG kernel: [ 218.165919] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T05:43:52.778266-07:00 DEBUG kernel: [ 218.166247] Baytrail Audio: stream context restored at offset 0
2017-08-03T05:43:52.778279-07:00 DEBUG kernel: [ 218.166560] Baytrail Audio: PCM: App/DMA pointer 0/768 bytes (d)--------> appl_ptr is set to 0. hw_ptr is set to 768.
2017-08-03T05:43:52.778283-07:00 DEBUG kernel: [ 218.166565] Baytrail Audio: PCM: DMA pointer 768 bytes
2017-08-03T05:43:52.778286-07:00 DEBUG kernel: [ 218.166683] Baytrail Audio: PCM: App/DMA pointer 0/1536 bytes
2017-08-03T05:43:52.778288-07:00 DEBUG kernel: [ 218.166688] Baytrail Audio: PCM: DMA pointer 1536 bytes
2017-08-03T05:43:52.778291-07:00 DEBUG kernel: [ 218.166760] Baytrail Audio: PCM: App/DMA pointer 0/2304 bytes
2017-08-03T05:43:52.778294-07:00 DEBUG kernel: [ 218.166764] Baytrail Audio: PCM: DMA pointer 2304 bytes
2017-08-03T05:43:52.780319-07:00 DEBUG kernel: [ 218.168649] Baytrail Audio: PCM: App/DMA pointer 0/3072 bytes
2017-08-03T05:43:52.780339-07:00 DEBUG kernel: [ 218.168658] Baytrail Audio: PCM: DMA pointer 3072 bytes
2017-08-03T05:43:52.784545-07:00 DEBUG kernel: [ 218.172692] Baytrail Audio: PCM: App/DMA pointer 0/3840 bytes
...(App remains at 0 for some time until jumping to 24576)
2017-08-03T05:43:52.888294-07:00 DEBUG kernel: [ 218.276826] Baytrail Audio: PCM: DMA pointer 23808 bytes
2017-08-03T05:43:52.892277-07:00 DEBUG kernel: [ 218.280831] Baytrail Audio: PCM: App/DMA pointer 0/24576 bytes
2017-08-03T05:43:52.892303-07:00 DEBUG kernel: [ 218.280840] Baytrail Audio: PCM: DMA pointer 24576 bytes
2017-08-03T05:43:52.893279-07:00 DEBUG kernel: [ 218.281387] Baytrail Audio: PCM: DMA pointer 24576 bytes
2017-08-03T05:43:52.897834-07:00 DEBUG kernel: [ 218.284833] Baytrail Audio: PCM: App/DMA pointer 24576/25344 bytes
2017-08-03T05:43:52.897853-07:00 DEBUG kernel: [ 218.284841] Baytrail Audio: PCM: DMA pointer 25344 bytes
2017-08-03T05:43:52.900284-07:00 DEBUG kernel: [ 218.288842] Baytrail Audio: PCM: App/DMA pointer 24576/26112 bytes
2017-08-03T05:43:52.900296-07:00 DEBUG kernel: [ 218.288851] Baytrail Audio: PCM: DMA pointer 26112 bytes
2017-08-03T05:43:52.904361-07:00 DEBUG kernel: [ 218.292844] Baytrail Audio: PCM: App/DMA pointer 24576/26880 bytes
There are some different behaviors that I could not understand:
1. The appl_ptr is assigned to be hw_ptr soon after resume in messages.noise at (a), (b), (c).
2. In contrast to 1, at (d), appl_ptr is assigned to be 0 soon after resume.
3. Comparing (a) and (d), it seems that reseting hw_ptr upon resume affects appl_ptr for a short time after resume. hw_ptr always starts from 0. I think the hw_ptr 768 we get at (a) and (d) are both after one period.
With the reset hw_ptr patch, I also found that resume sometimes does not work:
localhost ~ # aplay -D hw:1,0 /usr/local/test.wav
Playing WAVE '/usr/local/test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Warning: rate is not accurate (requested = 44100Hz, got = 48000Hz)
please, try the plug plugin
Suspended. Trying resume. Done.
underrun!!! (at least 0.019 ms long)
aplay: pcm_write:2011: write error: Input/output error
Attached log as messages.reset_hw_ptr_underrun.
2017-08-03T06:04:52.787711-07:00 DEBUG kernel: [ 1477.811762] Baytrail Audio: PCM: trigger 6
2017-08-03T06:04:52.787727-07:00 DEBUG kernel: [ 1477.811811] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T06:04:52.787730-07:00 DEBUG kernel: [ 1477.811818] Baytrail Audio: PCM: trigger 0
2017-08-03T06:04:52.788533-07:00 DEBUG kernel: [ 1477.812866] Baytrail Audio: PCM: trigger 1
2017-08-03T06:04:52.788549-07:00 DEBUG kernel: [ 1477.812897] Baytrail Audio: PCM: DMA pointer 0 bytes
2017-08-03T06:05:02.788592-07:00 DEBUG kernel: [ 1487.828506] Baytrail Audio: PCM: trigger 0
2017-08-03T06:05:02.799493-07:00 DEBUG kernel: [ 1487.839909] Baytrail Audio: PCM: hw_free
2017-08-03T06:05:02.799507-07:00 DEBUG kernel: [ 1487.839974] Baytrail Audio: PCM: close
The repro rate of underrun failure is about 20%.
I think we should check whether the appl_ptr and hw_ptr movement are expected, and figure out the root cause of underrun failure upon resume, before merging this upstream. Otherwise, it will break upstream user.
As for Chromium OS, since our audio server closes all streams at suspend, this patch will not affect our usage.
Could Intel be the owner of this issue to figure this out ?
Thanks!
|
Deleted:
messages.noise
1.1 MB
|
|
Deleted:
messages.reset_hw_ptr
888 KB
|
|
Deleted:
messages.reset_hw_ptr_underrun
334 KB
|
|
messages.reset_hw_ptr_underrun
334 KB
Download
|
Comment 1 by benhenry@google.com
, Jan 10