Ticket #1599 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

Suspend / resume breaks audio

Reported by: phyce Owned by: openmoko-kernel
Priority: normal Milestone: Om2007.2
Component: kernel Version: GTA02v5
Severity: normal Keywords: sound audio suspend resume
Cc: timo.lindfors@…, yorick Blocked By:
Blocking: Estimated Completion (week):
HasPatchForReview: no PatchReviewResult:
Reproducible:

Description

Media player works fine on a cold start.
Then I suspend the FR :

# apm -s

or if I let the "dim first, then lock" option suspend it after a while.

On resume, sound isn't working anymore in media player.

And I guess this means you can't take an incoming call out of suspend.

I know the suspend/resume is a work in progress but this have to work in order to allow a decent battery life.

Attachments

neosleep (1.1 KB) - added by paipai62 6 years ago.
list_installed (42.9 KB) - added by yarikoptic 6 years ago.
installed packages
dmesg (15.3 KB) - added by yarikoptic 6 years ago.
dmesg prior suspend
logread (63.3 KB) - added by yarikoptic 6 years ago.
logread prior suspend
dmesg.2 (15.2 KB) - added by yarikoptic 6 years ago.
dmesg post suspend
logread.2 (63.2 KB) - added by yarikoptic 6 years ago.
logread postsuspend

Change History

comment:1 Changed 6 years ago by phyce

  • Keywords sound audio suspend resume added

comment:2 Changed 6 years ago by andy

How old is your kernel? Try cat /proc/version for a quick idea. You will need to make sure it is updated to something current if it is the one that was used in the factory.

I tested audio on resume by aplaying a beep out of the back speaker thing before and after, and I even tested suspending inside a longer aplay and hearing it continue after resume.

comment:3 Changed 6 years ago by montgoss

I have the same issue.
"cat /proc/version" says:
Linux version 2.6.24 (oe@…) (gcc version 4.1.2) #1 PREEMPT Thu Jul 17 02:11:24 CEST 2008

comment:4 Changed 6 years ago by phyce

My kernel is 2:2.6.24+git18+9c058ff0d2641df3c36fc3300acb72078d2c41d4-r0 (a few days old)

I'll do some more tests to see if it can be reproduced and keep you posted. Some others on the community list seem to have the same problem.

comment:5 Changed 6 years ago by andy

If you can explain the steps to reproduce it with aplay from Ash commandline that would be great.

comment:6 Changed 6 years ago by zecke

This is not tested but should highlight the bug.

alsactl -f someprofile restore
alsactl -f someprofile.save store
diff oldprofile newprofile <= should be indentical

alsactl -f someprofile restore
suspend/resume
alsactl -f someprofile resume
diff oldprofile newprofile <= is not identical?

I have witnessed the following:

Have an active call

comment:7 Changed 6 years ago by andy

Hm. I didn't load any state file:

root@om-gta02:~# alsactl store -f /tmp/test.txt
root@om-gta02:~# apm -s
root@om-gta02:~# alsactl store -f /tmp/test1.txt
root@om-gta02:~# diff -urN /tmp/test.txt /tmp/test1.txt
root@om-gta02:~#

Then I did load a state file:

root@om-gta02:~# alsactl restore -f /usr/share/openmoko/scenarios/gsmspeakerout.state
root@om-gta02:~# alsactl store -f /tmp/test.txt
root@om-gta02:~# apm -s
root@om-gta02:~# alsactl store -f /tmp/test1.txt
root@om-gta02:~# diff -urN /tmp/test.txt /tmp/test1.txt
root@om-gta02:~#

comment:8 Changed 6 years ago by phyce

  • Milestone set to OM-2007.2

Some more testing (suspending while playing) :

root@om-gta02:~# aplay Alias.wav &
root@om-gta02:~# Playing WAVE 'Alias.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

root@om-gta02:~#
root@om-gta02:~#
root@om-gta02:~# apm -s
Suspended. Trying resume. root@om-gta02:~# Done.
underrun!!! (at least 36217.829 ms long)

[No sound anymore]

root@om-gta02:~# ps -edf
[...]
root 1412 1407 4 20:22 pts/0 00:00:01 aplay Alias.wav
[...]

root@om-gta02:~# kill 1412
root@om-gta02:~# Aborted by signal Terminated...

[1] + Done(1) aplay Alias.wav
root@om-gta02:~#
root@om-gta02:~# aplay Alias.wav
Playing WAVE 'Alias.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

[aplay hangs. No sound anymore until reboot]

I checked logread, some interesting parts (maybe) :
Jul 18 20:22:35 om-gta02 user.info kernel: soc-audio soc-audio: starting resume work
Jul 18 20:22:36 om-gta02 user.info kernel: soc-audio soc-audio: resume work completed
Jul 18 20:22:36 om-gta02 user.err kernel: dma2: channel has nothing loaded
Jul 18 20:22:36 om-gta02 user.err kernel: dma2: channel has nothing loaded

using 2007.2 updated to a recent kernel and userspace (see above)

comment:9 Changed 6 years ago by phyce

OK I found something : if I restart pulseaudio it unfreezes the sound system. So basically

root@om-gta02:~# /etc/init.d/pulseaudio restart

allows to play with asound again. But in order to get pulseaudio working again (clicking noise, ringrone, etc)

Have to restart X to get pulseaudio working again :

root@om-gta02:/etc/pulse# /etc/init.d/xserver-nodm restart

Hope this norrows it down...

comment:10 Changed 6 years ago by mwester

Executing "pactl suspend-sink 1" prior to suspend, and "pactl suspend-sink 0" upon resume will work around this issue. These commands can be executed by apm automagically, if apm is handling the suspend/resume activity.

Fortunately this is the case for the 2007.2 images, so you can simply add the preceding commands to the /etc/apm/suspend.d and /etc/apm/resume.d directories.

See http://moko.mwester.net/fixes.html for an example that performs these steps (along with some other suspend/resume related actions).

--

I've dug into the code a little; it seems that pulseaudio is doing something with a file in /sys that triggers this problem; clearly upon resume the driver is in some state that is different than the way pulseaudio left it when the system suspended.

comment:11 Changed 6 years ago by phyce

Yep, this solves the issue. I'm hoping this is added to the default Openmoko image soon.

Thanks for the help

comment:12 Changed 6 years ago by zecke

Looking at my current workload I'm happy to git-cherry-pick/git-am a change from any of you. I sadly lack the time to do that myself.

comment:13 Changed 6 years ago by andy

Great work finding a workaround... we play a trick to get fast resume, reloading WM8753 registers takes 700ms, so we push it off into a workqueue so it can complete parallel with rest of resume rather than holding us up. Alsa stuff has good locking concept that allows us to freeze stuff using Alsa assets until this is completed, but I wonder if this /sys guy is not under that lock, in which case pulseaudio might be exposed to stuff that is still "in a state of undress". (BTW this trick originated here has gone into upstream Alsa).

I confirmed here just now that aplay still continues to play fine without pulseaudio around if interrupted by apm -s, it does throw underrun complaint but it is legitimate considering what we are doing.

I guess we need a change to pulseaudio package so it inserts these /etc/apm/* actions I am afraid I have no idea how to do that with OE.

comment:14 Changed 6 years ago by broonie

I'm not sure which sysfs file is being used by pulseaudio but the ALSA locking is a purely ALSA thing and I'm not aware of any writable sysfs files that it exports so I would be surprised if the file in question were being covered by this locking mechanism. Which file is it?

Changed 6 years ago by paipai62

comment:15 Changed 6 years ago by paipai62

Here is a draft script for apm.
Simple, but it is always a problem on neod (set with a restart Xserver).
neod: Loss of sound, at the resume.

comment:16 Changed 6 years ago by lindi

  • Cc timo.lindfors@… added

comment:17 Changed 6 years ago by Yorick

  • Cc yorick added

I have the same problem with 2008.8 image, should I open a new bugreport on this or not?

comment:18 follow-up: ↓ 20 Changed 6 years ago by yarikoptic

I originally inquired on the mailing list
http://lists.openmoko.org/pipermail/support/2008-August/001910.html
and was forwarded over to this very bug report ;-)

I am running 2008.8 with some recent kernel (from Aug 19 I believe).
More information about the phone (logread/dmesg/installed packages) is available from
http://www.onerussian.com/Linux/bugs/om.nosound/debug.1/

alsa state didn't change after resume (ie it is not plain wrong alsa scenario problem)

Unfortunately I can't try given pactl recipe since there is no pulseaudio running on 2008.8 and I am not sure if that would be sane to bring it in -- would it?
I've installed pulseaudio-misc though to try pactl but apparently it is useless without server:

root@om-gta02:~# pactl suspend-sink 1
W: client-conf.c: Failed to open configuration file '/etc/pulse/client.conf': No such file or directory
Connection failure: Connection refused

Is there anything else to try?

Thanks in advance

comment:19 Changed 6 years ago by yarikoptic

restarting X doesn't help

if I stop X, killall mediaserver, start X again -- the same -- no sound

so it seems really to be some sound driver issue

comment:20 in reply to: ↑ 18 Changed 6 years ago by zecke

Replying to yarikoptic:

I am running 2008.8 with some recent kernel (from Aug 19 I believe).
More information about the phone (logread/dmesg/installed packages) is available from
http://www.onerussian.com/Linux/bugs/om.nosound/debug.1/

Please attach everything relevant to this bug report. But even more important how do you test audio? E.g. I hear the ring tone after suspend resume...

Changed 6 years ago by yarikoptic

installed packages

Changed 6 years ago by yarikoptic

dmesg prior suspend

Changed 6 years ago by yarikoptic

logread prior suspend

Changed 6 years ago by yarikoptic

dmesg post suspend

Changed 6 years ago by yarikoptic

logread postsuspend

comment:21 Changed 6 years ago by yarikoptic

I RESOLVED IT -- details follow:

ok -- attached things (although i thought browsing through dirrectories and diffing would be more 'interesting')

Mainly I tested audio with calling my cell phone and checking if I have a ring tone -- after resume -- no ring tone. Then I accept the call and listen if I can hear anything -- and nothing...

also -- with mplayer:
prior to suspend
mplayer -ao alsa /opt/./Qtopia/etc/SystemRingTones/phonering.wav

plays ringtone fine and exits

after suspend (apm -s) (Actually after resume ;-) ): it doesn't play and doesn't exit, looping in

nanosleep({0, 10000000}, NULL) = 0
ioctl(6, 0xc0844123, 0x83de18) = 0
ioctl(6, 0xc0844123, 0x83de18) = 0
ioctl(6, 0xc0844123, 0x83de18) = 0

where

1644 open("/dev/snd/pcmC0D0p", O_RDWR|O_NONBLOCK|O_APPEND) = 6

root@om-gta02:~# fuser /dev/snd/pcmC0D0p
1382 1387
root@om-gta02:~# ps auxw | grep 138[27]
root 1382 0.1 2.6 31772 3248 ? SLl 17:13 0:01
root 1387 0.1 1.5 17448 1952 ? SLl 17:13 0:01

WTF?

root@om-gta02:/proc/1382# ls -l /proc/138[27]/exe
lrwxrwxrwx 1 root root 0 Aug 19 17:14 /proc/1382/exe -> /usr/lib/speech-dispatcher-modules/sd_espeak
lrwxrwxrwx 1 root root 0 Aug 19 17:14 /proc/1387/exe -> /usr/lib/speech-dispatcher-modules/sd_flite

HO HO -- could it be silly gpsdrive issue? ;-)

opkg remove navit speech-dispatcher

mplayer.... WORKS!!!!!

doing suspend again (apm -s)
mplayer works...
set suspend in configuration and let is suspend
so please free to reassign this to anywhere you like ;-)

comment:22 Changed 6 years ago by xeros

Thanks, yarikoptic!
I've had the same problem and removing speech-dispatcher (and navit as dependency) fixed this issue.

comment:23 Changed 6 years ago by houska

RE: I RESOLVED IT -- details follow: ....

Hi,
in my case the troublemaker is pulse audio:

root@om-gta02:~# fuser /dev/snd/pcmC0D0p
2004 2040
root@om-gta02:~# ps aux|grep -e 2004 -e 2040
root      2004  9.5  2.4  16728  2980 ?        S<Lsl 10:48   1:04 /usr/bin/pulseaudio --no-cpu-limit --resample-method=trivial -D -nF /etc/pulse/session
root      2040  1.3  3.0  16024  3816 pts/0    SL+  10:53   0:04 mplayer -ao alsa /media/card/sirena.wav
root      2070  0.0  0.4   2752   592 pts/1    S+   10:59   0:00 grep -e 2004 -e 2040
root@om-gta02:~#

mplayer doesn't play:

Starting playback...
A:   0.0 (00.0) of 2.0 (02.0) ??,?%

pulseaudio strace:

poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 1915) = 0
gettimeofday({1220864597, 94808}, NULL) = 0
gettimeofday({1220864597, 100972}, NULL) = 0
gettimeofday({1220864597, 106696}, NULL) = 0
gettimeofday({1220864597, 110413}, NULL) = 0
poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 51) = 0
gettimeofday({1220864597, 172238}, NULL) = 0
gettimeofday({1220864597, 176766}, NULL) = 0
gettimeofday({1220864597, 180713}, NULL) = 0
gettimeofday({1220864597, 185510}, NULL) = 0
poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 1921) = 0
gettimeofday({1220864599, 119480}, NULL) = 0
gettimeofday({1220864599, 121626}, NULL) = 0
gettimeofday({1220864599, 126834}, NULL) = 0
gettimeofday({1220864599, 130141}, NULL) = 0
poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 50) = 0
gettimeofday({1220864599, 187026}, NULL) = 0
gettimeofday({1220864599, 191503}, NULL) = 0
gettimeofday({1220864599, 194857}, NULL) = 0
gettimeofday({1220864599, 197008}, NULL) = 0
poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 1929) = 0
gettimeofday({1220864601, 133140}, NULL) = 0
gettimeofday({1220864601, 139464}, NULL) = 0
gettimeofday({1220864601, 141464}, NULL) = 0
gettimeofday({1220864601, 146087}, NULL) = 0
poll([{fd=3, events=POLLIN}, {fd=20, events=POLLIN}, {fd=17, events=POLLIN}, {fd=14, events=POLLIN}, {fd=13, events=POLLIN}, {fd=12, events=POLLIN}, {fd=11, events=POLLIN}, {fd=10, events=POLLIN}, {fd=7, events=POLLIN}], 9, 48) = 0
gettimeofday({1220864601, 202131}, NULL) = 0
gettimeofday({1220864601, 208867}, NULL) = 0
gettimeofday({1220864601, 211057}, NULL) = 0
gettimeofday({1220864601, 213248}, NULL) = 0
poll( <unfinished ...>
Process 2004 detached
root@om-gta02:~#

restarting pulseaudio after wakeup helps

comment:24 Changed 6 years ago by gcasse

Some dmesg messages for hopefully completing bug #1599.

  • aplay is suspended (apm -s) on the FR, after resume, no more sound: the aplay process is hanging.
  • dmesg:

ALSA sound/core/pcm_lib.c:155: BUG: stream = 0, pos = 0x28c8000, buffer size = 0x4000, period size = 0x400

(line 155: snd_pcm_update_hw_ptr_pos).

If the hanging aplay process is nuked then another aplay can be started successfully.


More details:

  • kernel 2.6.24 (5 Oct git origin/stable), defconfig-gta02 + CONFIG_SND_VERBOSE_PRINTK=y, CONFIG_SND_DEBUG, CONFIG_SND_DEBUG_DETECT, CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753_DEBUG
  • alsa 1.0.15
  • dmesg:

...
glamo-mci glamo-mci.0: powered (vdd = 20) clk: 16666kHz div=2 (req: 16666kHz). Bus width=2
soc-audio soc-audio: scheduling resume work
PM: Finishing wakeup.
Restarting tasks ... <6>soc-audio soc-audio: starting resume work
done.
usb0: full speed config #1: 500 mA, Ethernet Gadget, using CDC Ethernet
soc-audio soc-audio: resume work completed
dma2: channel has nothing loaded
ALSA sound/core/pcm_lib.c:155: BUG: stream = 0, pos = 0x28c8000, buffer size = 0x4000, period size = 0x400
ALSA sound/core/pcm_lib.c:155: BUG: stream = 0, pos = 0x28c8000, buffer size = 0x4000, period size = 0x400
...

  • File sound/core/pcm_lib.c, line 155:

...
static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(struct snd_pcm_substream *substream,

struct snd_pcm_runtime *runtime)

{

snd_pcm_uframes_t pos;

pos = substream->ops->pointer(substream);
if (pos == SNDRV_PCM_POS_XRUN)

return pos; /* XRUN */

if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)

getnstimeofday((struct timespec *)&runtime->status->tstamp);

#ifdef CONFIG_SND_DEBUG

if (pos >= runtime->buffer_size) {

snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);

}

#endif

pos -= pos % runtime->min_align;
return pos;

}
...

comment:25 Changed 6 years ago by andy

  • HasPatchForReview unset

Do these problems still exist or are they apparently entirely due to pulseaudio or similar?

comment:26 Changed 5 years ago by PaulFertser

  • Status changed from new to closed
  • Resolution set to fixed

Modern distros don't use neither PA nor speech-dispatcher.

Note: See TracTickets for help on using tickets.