Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 232875 - System hangs at shutdown after message "Killing processes using ALSA"
Summary: System hangs at shutdown after message "Killing processes using ALSA"
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo ALSA team [DISABLED]
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-24 19:05 UTC by Bob Raitz
Modified: 2009-08-11 19:35 UTC (History)
25 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch that fixes snd-intel-hda shutdown hang (alsasound_intel_hda_endfreeze.patch,236 bytes, patch)
2008-08-11 17:45 UTC, Bob Raitz
Details | Diff
alsasound module unload on stop patch (alsasound.patch,1.77 KB, patch)
2009-03-27 01:51 UTC, nvinson234
Details | Diff
rmmod snd* modules in topological order (alsa-rmmod-topsort.patch,1.49 KB, patch)
2009-04-05 12:03 UTC, Pavel Shved
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Raitz 2008-07-24 19:05:21 UTC
At shutdown, whether during a reboot or a full shutdown, the process will hang after putting the message "Killing processes using ALSA" on the screen. This is an intermittant problem. Sometimes, the system will shutdown properly. However, when the error hits, it can take upwards of ten minutes to shutdown properly. If the shutdown is forced, the root partition comes up as dirty on the next boot, and receives a full fscking.

Reproducible: Sometimes

Steps to Reproduce:
1. Shutdown system normally
2. Receive "Killing processes using ALSA" message
3. Wait ten minutes or more for the computer to finish shutdown cycle.

Actual Results:  
This is an intermittent bug. Sometimes the results are fine, sometimes, not. 

Expected Results:  
That this error shouldn't occur.

It seems limited to the snd-intel-hda sound chip, as I have two systems with different sound chips, and neither of them experience this issue.

EMERGE --INFO FOR AFFECTED MACHINE.


pappy-lap ~ # emerge --info
Portage 2.2_rc3 (default-linux/x86/2007.0, gcc-4.2.3, glibc-2.8_p20080602-r0, 2.6.26 i686)
=================================================================
System uname: Linux-2.6.26-i686-Intel-R-_Celeron-R-_M_CPU_440_@_1.86GHz-with-glibc2.0
Timestamp of tree: Thu, 24 Jul 2008 17:00:03 +0000
distcc 2.18.3 i486-pc-linux-gnu (protocols 1 and 2) (default port 3632) [enabled]
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p39
dev-java/java-config: 1.3.7, 2.1.4
dev-lang/python:     2.5.2-r5
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.12
sys-apps/sandbox:    1.2.18.1-r3
sys-devel/autoconf:  2.13, 2.62-r1
sys-devel/automake:  1.4_p6, 1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1-r1
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.25-r4
ACCEPT_KEYWORDS="x86 ~x86"
CBUILD="i486-pc-linux-gnu"
CFLAGS="-march=pentium4 -O2 -pipe"
CHOST="i486-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=pentium4 -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distcc distlocks metadata-transfer parallel-fetch preserve-libs sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
LDFLAGS=""
LINGUAS="en"
MAKEOPTS="-j256"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X a52 aac acl alsa ao audiofile avi bash-completion berkdb bitmap-fonts bzip2 cairo cdr cli cracklib crypt css cups dbus dlloader dri dts dv dvd dvdr dvdread eds encode fam fbcon ffmpeg fftw flac foomaticdb fortran gdbm gif gimp gpm gsl gtk hal iconv ipv6 isdnlog jack jpeg kde ladspa lame ldap libg++ libsamplerate live mad midi mikmod mp3 mpeg mudflap nas ncurses nls nptl nptlonly ogg opengl openmp pam pcre pdcre pdf pdflib perl php png ppds pppd python qt3 quicktime readline reflection samba sdl session slang slp sndfile spell spl sse ssl swat tcpd theora tiff truetype truetype-fonts type1-fonts udev unicode usb vidix vorbis wifi win32codecs wxwindows x264 x86 xine xml xorg xscreensaver xv zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 	emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m 	maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="evdev keyboard mouse synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en" USERLAND="GNU" VIDEO_CARDS="i810"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Sergey Kondakov 2008-07-25 07:24:01 UTC
confirming it. this is major failure, you know.

Portage 2.2_rc3 (default/linux/amd64/2008.0/desktop, gcc-4.3.1, glibc-2.8_p20080602-r0, 2.6.26-gentoo-v-fox-laptop x86_64)
=================================================================
System uname: Linux-2.6.26-gentoo-v-fox-laptop-x86_64-AMD_Athlon-tm-_64_X2_Dual-Core_Processor_TK-57-with-glibc2.2.5
Timestamp of tree: Fri, 25 Jul 2008 07:04:01 +0000
distcc 2.18.3 x86_64-pc-linux-gnu (protocols 1 and 2) (default port 3632) [enabled]
app-shells/bash:     3.2_p39
dev-lang/python:     2.4.4-r13, 2.5.2-r5
dev-python/pycrypto: 2.0.1-r6
sys-apps/baselayout: 2.0.0
sys-apps/openrc:     0.2.5
sys-apps/sandbox:    1.2.18.1-r3
sys-devel/autoconf:  2.13, 2.62-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1-r1
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   2.2.4
virtual/os-headers:  2.6.25-r4
ACCEPT_KEYWORDS="amd64 ~amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=k8-sse3 -O2 -Wno-error -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=k8-sse3 -O2 -Wno-error -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distcc distlocks fixpackages parallel-fetch preserve-libs sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://ftp.roedu.net/pub/mirrors/gentoo.org/ http://gentoo.tiscali.nl/ http://ftp.dei.uc.pt/pub/linux/gentoo/ http://gentoo.virginmedia.com/ http://fido.online.kz/gentoo"
LANG="ru_RU.UTF-8"
LC_ALL=""
LDFLAGS="-Wl,--sort-common -Wl,--enable-new-dtags -Wl,--as-needed -Wl,--hash-style=gnu -Wl,-O1"
LINGUAS="ru en"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/berkano /usr/portage/local/layman/lila-theme /usr/portage/local/v-fox"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext 3ds 64bit 7zip X Xaw3d Xorg a52 aac aalib ace acl acpi addbookmarks alias alsa amarok amd64 ao apache2 async audiofile autoreplace bash-completion bluetooth branding bzip2 cairo cap caps cardbus cdb cddb cdparanoia cdr cdrom cg charconv chm chroot cisco cli colordiff compress connectionstatus contactnotes cpio cracklib crypt css cups curl curlwrappers curses cyrillic dbus dedicated dhcp dia dialup directfb disk-partition diskio divx djvu dlz dmi dmx dri dts dv dvb dvd dvdnav dvdr dvdread dynamicplugin elf emboss emovix enca encode erandom evdev examples exif expat fam fame fat fbcon fbcondecor fbdev fbsplash ffmpeg firefox flac foomaticdb fortran ftp gd gdbm geoip geos ggi gif glibc-omitfp gpm gre groupwise gsm gtk h264 h323 hal hda-intel hddtemp highlight history html iconv icq ieee1394 imagemagick imlib ipv6 irc isdnlog jabber jingle john joystick jpeg jpeg2k kde kdexdeltas kerberos keyboard kqemu lame laptop latex lcms libcaca libnotify libsamplerate libssh2 libwww lighttpd live lm_sensors login-watch logitech-mouse logrotate lzo mad matroska md5sum midi mikmod mime mjpeg mmap mmx mmxext mng mouse mp2 mp3 mp4 mpeg mplayer msn mudflap multilib musepack nas ncurses neXt netboot netmeeting network network-cron nls nntp nowlistening nptl nptlonly nsplugin ntfs objc objc++ objc-gc offensive ogg openal openexr opengl openmp openssl openvpn oscar pam pcmcia pcntl pcre pdf perl php physfs plugins png pnm portaudio posix ppds pppd pptp python qemu qt3 qt3support qt4 quicktime radio rar rdesktop readline reflection reiser4 reiserfs rtc samba sametime scanner scsi sdl session sharedext shorten skey slang slp smp sms sockets socks5 sox speex spell spl sqlite sqlite3 srt sse sse2 sse3 ssl ssse3 startup-notification statistics subtitles svg symlink sysfs tcpd tftp tga theora threads tiff timidity truetype udev unicode upnp urandom usb utf8 uuencode v4l v4l2 vcd vesa vesafb vhosts videos vorbis wavpack wddx webpresence wifi winpopup wma wmf wmp x264 xattr xcb xcomposite xface xfs xine xml xorg xosd xpm xscreensaver xv xvid yahoo zip zlib zsh-completion" ALSA_CARDS="hda-intel hda-codec-analog hda-codec-atihdmi hda-codec-cmedia hda-codec-conexant hda-codec-realtek hda-codec-si3054 hda-codec-sigmatel hda-codec-via hda-generic hda-hwdep hda-power-save hpet seq-rtctimer-default virmidi rtctimer" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile  authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers  ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite  setenvif so speling status unique_id userdir usertrack vhost_alias" APACHE2_MPMS="worker" ELIBC="glibc" INPUT_DEVICES="evdev keyboard mouse joystick synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="ru en" LIRC_DEVICES="audio_alsa devinput inputlirc usb usbx" USERLAND="GNU" VIDEO_CARDS="fglrx radeon fbdev v4l"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 Bob Raitz 2008-07-25 07:29:29 UTC
(In reply to comment #1)
> confirming it. this is major failure, you know.
> 
I'm getting that feeling. It never really bothers me that much since I tend to shut this machine down at the end of the day, and frankly, I don't care if it takes its sweet time to shut down. The real PITA comes when I'm doing kernel compilation or other things that require reboot. 

Blessed be!
Pappy
Comment 3 George GTN 2008-07-25 10:04:31 UTC
The same issue here!

emerge --info
Portage 2.1.4.4 (default/linux/amd64/2008.0, gcc-4.1.2, glibc-2.6.1-r0, 2.6.25-gentoo-r6 x86_64)
=================================================================
System uname: 2.6.25-gentoo-r6 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 4800+
Timestamp of tree: Thu, 24 Jul 2008 07:15:01 +0000
app-shells/bash:     3.2_p33
dev-java/java-config: 1.3.7, 2.1.6
dev-lang/python:     2.5.2-r5
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r2
sys-devel/automake:  1.4_p6, 1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=athlon64 -O2 -pipe -msse3"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config /var/qmail/alias /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=athlon64 -O2 -pipe -msse3"
DISTDIR="/usr/portage/distfiles"
FEATURES="buildpkg distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://files.gentoo.org http://files.gentoo.org ftp://ftp.ntua.gr/pub/linux/gentoo/ http://ftp.ntua.gr/pub/linux/gentoo/ ftp://ftp.uoi.gr/mirror/OS/gentoo/ http://ftp.uoi.gr/mirror/OS/gentoo/ http://ftp.physics.auth.gr/pub/mirrors/gentoo/ ftp://ftp.physics.auth.gr/pub/mirrors/gentoo/ "
LANG="en_GB.UTF-8"
LDFLAGS="-Wl,-O1"
LINGUAS="en en_GB el uk"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X Xaw3d a52 aac aalib accessibility acl acpi addbookmarks akode alias alsa amd64 amr aotuv apache2 asf asterisk audiofile avahi avi bindist bitmap-fonts bzip2 bzlib cairo caps cdda cddb cdparanoia cdr connectionstatus contactnotes cpudetection cracklib crypt css ctype cups curl curlwrappers cxx dbus dc1394 divx divx4linux djbfft dlloader dmi doc dri dts dv dvb dvd dvdr dvdread ecc effects elf encode exif expat extrafilters fam fame ffmpeg firefox flac flash fontconfig fortran fpx fuse gadu gd gdbm gif gimp gimpprint gmedia gnutls gpac gphoto2 gpm graphviz gs gstreamer gtk gtk2 hal highlight history iconv ieee1394 imagemagick imap imlib inkjar irc jack java javascript jbig jingle jpeg jpeg2k kde ladspa lcms ldap lesstif libcaca libsamplerate libwww live lm_sensors logitech-mouse lua lzo mad maildir matroska mbrola mdnsresponder-compat memlimit midi mikmod mjpeg mmap mmx mmxext mng modplug motif mozilla mp3 mp4 mpeg mpi mplayer mpm-prefork multilib musepack musicbrainz nas ncurses neXt network nls no-suexec nowlistening nptl nptlonly nsplugin nvidia odbc offensive ogg oggvorbis openexr opengl oss pam pcre pda pdf perl png posix povray ppds python qt3 qt4 quicktime rdesktop readline realmedia rpm rtc ruby sametime scanner sdl session slp smartcard smp sms smux sndfile snmp sockets sox speex spell sqlite sse sse2 ssl static-modules statistics stream subtitles svg tcl tcltk tcpd tetex texteffect theora tidy tiff tk tokenizer translator truetype type1-fonts udev unicode usb utf8 v4l v4l2 vcd vdr vlm vorbis wavpack webpresence winpopup wmf wmp wxwindows x264 xanim xine xml xorg xpm xscreensaver xsl xv xvid xvmc yahoo yv12 zeroconf zlib zvbi" ALSA_CARDS="hda-intel" ALSA_PCM_PLUGINS="alaw copy dshare dsnoop extplug null shm adpcm file hooks ladspa lfloat linear meter mulaw multi rate route share" APACHE2_MODULES="access auth mime-magic headers log_config setenvif mime dir so authz_host" APACHE2_MPMS="prefork" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_GB el uk" USERLAND="GNU" VIDEO_CARDS="nvidia fbdev vesa vga"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 4 Jeroen Roovers (RETIRED) gentoo-dev 2008-07-25 15:24:11 UTC
Of course, ALSA isn't to blame for these problems, and neither is the init script system. The reporters should investigate which processes that use ALSA are slowing it down.
Comment 5 Bob Raitz 2008-07-25 18:27:09 UTC
(In reply to comment #4)
> Of course, ALSA isn't to blame for these problems, and neither is the init
> script system. The reporters should investigate which processes that use ALSA
> are slowing it down.
> 
So what is to blame? I do nothing on the machine that acts up that I don't do on the other systems that don't. The only thread that links this problem to others is the fact that it's happening with the snd-intel-hda driver. Maybe it's the chipset...maybe it's the drivers. NO matter what it is, the result is the same.

Blessed be!
Pappy
Comment 6 George GTN 2008-08-08 10:55:30 UTC
Trying to delineat the situation, I have observed that -before the occurrence of this situation- I get amarok not working at all (it will not load) and one directory stalled. It will not display its contents no matter what. 

It is the parent directory of the directory where my nfs partition is mounted, which is also stalled.

I could not find any logs about this, probably because I am unaware of how to search them properly.
Comment 7 Bob Raitz 2008-08-11 09:51:31 UTC
OK, I *think* I have a fix for this. I just tried it, and it seems to work. I'm going to leave my machine up overnight pulling in an internet stream via gxine. If anything will cause problems, that will. If my fix works, I'll publish it here.

Cross your collective fingers!

Blessed be!
Pappy
Comment 8 Bob Raitz 2008-08-11 17:42:11 UTC
Ok, I have tried this fix eight times, including one time where the machine ran overnight with an internet stream feeding gxine. If there was anything that was sure to cause the problem in this bug, that was it.

The problem lies in the /etc/init.d/alsasound file; specifically, the problem exists in function unload_modules_recursive() to whit:
unload_modules_recursive() {
	local revdeps="$(lsmod | sed -n -e "s/,/ /g" -e "s/^$1 *[0-9]* *[0-9]* \(.*\)/\1/p")"

	for module in ${revdeps} ; do
		unload_modules_recursive "${module}"
	done

	vebegin "Unloading: $1"
	rmmod --wait "$1"
	veend $?
}

The problem lies in the heart of the fucntion 'rmmod --wait "$1"' . If that function gets changed to:

unload_modules_recursive() {
	local revdeps="$(lsmod | sed -n -e "s/,/ /g" -e "s/^$1 *[0-9]* *[0-9]* \(.*\)/\1/p")"

	for module in ${revdeps} ; do
		unload_modules_recursive "${module}"
	done

	vebegin "Unloading: $1"
	rmmod --force "$1"
	veend $?
}
the kernel can then unload the modules without waiting. It's probably a really dirty fix, but I figure since the computer is shutting down anyway, if this taints the kernel, too bad.

Anyway, I have created a patch that I will be sending along after I post this.

Please try this and let me know if it works for you as well. I don't think that forced module uloading has to be set in the kernel. If the fix works for you without that option, please let me know.

Blessed be!
Pappy
Comment 9 Bob Raitz 2008-08-11 17:45:45 UTC
Created attachment 162692 [details, diff]
patch that fixes snd-intel-hda shutdown hang

This is not the world's greatest patch, but it does work.
Comment 10 Bob Raitz 2008-08-11 17:47:58 UTC
One final word: if you decide to manually fix /etc/init.d/alsasound, don't forget to make sure it is executable after the fact.

Please let me know how this fix works.

Blessed be!
Pappy
Comment 11 Peter Campion-Bye 2008-08-13 14:16:10 UTC
(In reply to comment #10)
> 
> Please let me know how this fix works.

Worked for me, thanks Bob. 
Don't think it's specific to the intel snd driver, I use emu10k1.
Comment 12 Bob Raitz 2008-08-13 21:47:54 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > 
> > Please let me know how this fix works.
> 
> Worked for me, thanks Bob. 
> Don't think it's specific to the intel snd driver, I use emu10k1.
> 

That's fantastic! I am so glad to hear that it helped.

Blessed be!
Pappy
Comment 13 Bob Raitz 2008-08-22 06:58:25 UTC
Unfortunately, this doesn't fix things. What appears to be happening is something takes hold of alsa, and won't let go. How would I go about finding which program is taking hold? 

Blessed be!
Pappy
Comment 14 Robert W. 2008-08-23 13:57:38 UTC
Confirmed on ibook G4 (ppc32). I also think, that the problem is not related to a specific sound driver.

mary@belle-gunness ~ $ lsmod|grep snd
snd_seq_dummy           2884  0
snd_seq_oss            35572  0
snd_seq_midi_event      7520  1 snd_seq_oss
snd_seq                59648  5 snd_seq_dummy,snd_seq_oss,snd_seq_midi_event
snd_seq_device          7596  3 snd_seq_dummy,snd_seq_oss,snd_seq
snd_pcm_oss            43968  0
snd_mixer_oss          16480  1 snd_pcm_oss
snd_aoa_codec_tas      12160  2
snd_aoa_fabric_layout    11144  3
snd_aoa                16800  2 snd_aoa_codec_tas,snd_aoa_fabric_layout
snd_aoa_i2sbus         20580  1
snd_pcm                83940  3 snd_pcm_oss,snd_aoa_i2sbus
snd_timer              24260  3 snd_seq,snd_pcm
snd_page_alloc          9128  1 snd_pcm
snd                    59028  15 snd_seq_oss,snd_seq,snd_seq_device,snd_pcm_oss,snd_mixer_oss,snd_aoa_codec_tas,snd_aoa_fabric_layout,snd_aoa,snd_aoa_i2sbus,snd_pcm,snd_timer
soundcore               7428  1 snd
snd_aoa_soundbus        5636  2 snd_aoa_fabric_layout,snd_aoa_i2sbus


For completeness, my emerge --info below.

Portage 2.1.4.4 (default/linux/powerpc/ppc32/2008.0/desktop, gcc-4.1.2, glibc-2.6.1-r0, 2.6.26.2-1 ppc)
=================================================================
System uname: 2.6.26.2-1 ppc 7447A, altivec supported
Timestamp of tree: Tue, 12 Aug 2008 20:37:01 +0000
distcc 2.18.3 powerpc-unknown-linux-gnu (protocols 1 and 2) (default port 3632) [disabled]
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p33
dev-java/java-config: 1.3.7, 2.1.6
dev-lang/python:     2.4.4-r13, 2.5.2-r6
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r2
sys-devel/automake:  1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="ppc"
CBUILD="powerpc-unknown-linux-gnu"
CFLAGS="-O2 -mtune=G4 -mcpu=G4 -maltivec -fno-strict-aliasing -pipe 	-mabi=altivec"
CHOST="powerpc-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CPPFLAGS="-O2 -mtune=G4 -mcpu=G4 -maltivec -fno-strict-aliasing -pipe 	-mabi=altivec"
CXXFLAGS="-O2 -mtune=G4 -mcpu=G4 -maltivec -fno-strict-aliasing -pipe 	-mabi=altivec"
DISTDIR="/var/portage/distfiles"
FEATURES="autoaddcvs ccache distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://ftp-stud.fht-esslingen.de/pub/Mirrors/gentoo/ http://mirror.bytemark.co.uk/gentoo/ http://gentoo.ynet.sk/pub http://ftp.uoi.gr/mirror/OS/gentoo/ http://mirror.qubenet.net/mirror/gentoo/"
LC_ALL="de_DE.utf8"
LDFLAGS="-Wl,-O1"
LINGUAS="de en"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/var/portage"
PORTDIR_OVERLAY="/var/portage/local/layman/sunrise /var/portage/local/layman/xfce /var/portage/local/layman/powerpc /var/portage/local/layman/sabayon /var/portage/local/layman/java-overlay /usr/local/portage /var/portage/local/layman/swegener"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X acl alsa altivec apm arts bash-completion berkdb bluetooth bzip2 cairo caps cddb cdr cli cracklib crypt cscope cups dbus doc dri dvd dvdread eds emacs emboss encode esd evo fam ffmpeg fftw firefox fortran gdbm gif gpg gpm graphviz gtk hal htmlhandbook iconv idn imap ipv6 isdnlog java java5 java6 jpeg jpg kde laptop latex ldap libnotify mad midi mikmod mp3 mpeg mudflap musicbrainz ncurses networkmanager nls nptl nptlonly ogg opengl openmp pam pcre pda pdf perl plotutils png ppc ppds pppd python qt3 qt3support qt4 quicktime readline reflection samba sasl sdl session socks5 spell spl ssl startup-notification svg sysfs tcpd threads tiff truetype unicode usb vcd vim-syntax vorbis wifi xattr xcomposite xine xml xorg xscreensaver xv zeroconf zlib" ALSA_CARDS="aoa aoa-fabric-layout aoa-onyx aoa-soundbus aoa-soundbus-i2s aoa-tas aoa-toonie powermac usb-audio via82xx" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="synaptics mouse evdev keyboard" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="de en" USERLAND="GNU" VIDEO_CARDS="fbdev radeon"
Unset:  CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 15 George GTN 2008-08-24 13:04:12 UTC
(In reply to comment #6)
> Trying to delineat the situation, I have observed that -before the occurrence
> of this situation- I get amarok not working at all (it will not load) and one
> directory stalled. It will not display its contents no matter what. 
> 
> It is the parent directory of the directory where my nfs partition is mounted,
> which is also stalled.
> 
> I could not find any logs about this, probably because I am unaware of how to
> search them properly.
> 

Disabling my nfs partition, the problem seems to have vanished. 
It has never occurred again.

I know this is not a solution but at least I seem to have found what caused the whole problem. 

It is nfs that made its directory stall, which in turn made its parent directory stall. 

The parent directory included the directory where reside the music files that Amarok uses and therefore Amarok was getting stalled and consequently Alsa was having a problem terminating due to Amarok being stalled.

This seems to be the story in my case. I have never received an error message. I repeat that the conclusion is due to the fact that after disabling NFS the problem vanished.
Comment 16 Robert W. 2008-08-24 14:08:05 UTC
(In reply to comment #15)
> 
> Disabling my nfs partition, the problem seems to have vanished. 
> It has never occurred again.
> 
> I know this is not a solution but at least I seem to have found what caused the
> whole problem. 
> 
> It is nfs that made its directory stall, which in turn made its parent
> directory stall. 
> 
> The parent directory included the directory where reside the music files that
> Amarok uses and therefore Amarok was getting stalled and consequently Alsa was
> having a problem terminating due to Amarok being stalled.
> 
> This seems to be the story in my case. I have never received an error message.
> I repeat that the conclusion is due to the fact that after disabling NFS the
> problem vanished.
> 

Sounds like a heisenbug. On my affected machine neither amarok nor any nfs is running, thus I doubt again that there's a relationship.
Comment 17 Daniel Macher 2008-10-12 21:19:00 UTC
(In reply to comment #16)
> Sounds like a heisenbug. On my affected machine neither amarok nor any nfs is
> running, thus I doubt again that there's a relationship.

I have a similar problem with alsa on shutdown. On my machine neither amarok nor nfs is in use, too. In my case the problem first occured after compiling and using the snd_usb_audio module to get the micro of a logitech usb-webcam running.
Comment 18 Steve Dibb (RETIRED) gentoo-dev 2008-11-05 04:27:06 UTC
I'm curious, has anyone tried editing /etc/init.d/alsasound and actually telling the init not to unload modules and/or kill processes?
Comment 19 Steve Dibb (RETIRED) gentoo-dev 2008-11-05 04:27:38 UTC
(In reply to comment #18)
> I'm curious, has anyone tried editing /etc/init.d/alsasound and actually
> telling the init not to unload modules and/or kill processes?
> 

Gah, typo, I meant /etc/conf.d/alsasound

UNLOAD_ON_STOP="no"
KILLPROC_ON_STOP="no"
Comment 20 Bob Raitz 2008-11-05 06:16:49 UTC
(In reply to comment #19)
> (In reply to comment #18)
> > I'm curious, has anyone tried editing /etc/init.d/alsasound and actually
> > telling the init not to unload modules and/or kill processes?
> > 
> 
> Gah, typo, I meant /etc/conf.d/alsasound
> 
> UNLOAD_ON_STOP="no"
> KILLPROC_ON_STOP="no"
> 

That doesn't fix the problem. It leaves the open audio connnection until it's time to unmount file systems and remount them read-only...then it ties up yet again. 

I just don't see that there's a lot of interest with this bug. It remains unfixed.
Comment 21 Bob Raitz 2008-12-12 06:12:56 UTC
The problem remains with alsa-1.0.18. I've turned of system sounds, which keeps it from happening until I use kaffeine or xine-ui.

Blessed be!
Pappy
Comment 22 Eric Bosch 2009-01-04 00:57:07 UTC
I just ran into this issue myself, and in my case, I was able to determine that NFS was trying to shut down, however it had locked up for some yet to be determined reason.  Forced to coldboot it.  I am in process now of re-emerging world to see if there is improvement.
Comment 23 Carl Michal 2009-03-12 22:30:46 UTC
I see exactly the same symptoms reproducibly.  I've just installed kernel-2.6.29-rc7, and the order the modules need to be removed seems to matter.

In particular, the alsasound initscript tries to remove
snd_hda_realtek_codec before snd_hda_codec - but it hangs waiting for snd_hda_realtek_codec.  snd_hda_codec has to be removed first.

Comment 24 nvinson234 2009-03-27 01:51:45 UTC
Created attachment 186372 [details, diff]
alsasound module unload on stop patch

Here's a second patch for the issue.  This one is much more sophisticated than the previously posted one.  Basically this patch ensures that all driver and sequencer modules are unloaded before everything else.  Hopefully, this fixes the problem for everyone.
Comment 25 Carl Michal 2009-03-27 05:22:10 UTC
This is a bit weird.  The patch *nearly* works for me, but not quite.

On boot, the alsasound initscript doesn't complain about anything, but the /var/run/alsasound/alsa.modules file that it creates contains one blank line.  And so then when I shutdown I run into the same problem.

However, if I stop alsa (I have to manually remove snd_intel_hda before stopping with the initscript), and then start again with the initscript, then the script complains:

 *   Could not detect custom ALSA settings.  Loading all detected alsa drivers.

My /proc/asound/cards looks like:

 0 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0xdfebc000 irq 16

but now /var/run/alsasound/alsa.modules looks like:
snd_hda_intel 
and after that the initscript will shutdown nicely.
Comment 26 Pavel Shved 2009-04-05 11:57:09 UTC
I had the same issue and here's what i figured out:

Some modules are listed in lsmod without their reverse dependencies.  However, number of revdeps is correct.

In my lsmod the following line presents:
----- snip ------
snd_hda_codec_realtek   241652  1
----- snip ------                 ^^^^^^
                               nothing here!

I manually figured out that i should rmmod snd_hda_intel for snd_hda_codec_realtek to unload.

In comment #14 we see several such modules:
> snd_aoa_codec_tas      12160  2
> snd_aoa_fabric_layout    11144  3
> snd_aoa_i2sbus         20580  1

I think it's alsa/kernel bug.  Please, report it to them (i don't know where exactly).

What i propose is the other algorithm of recursive module unloading: 1) lsmod; 2) pick a module with zero reverse dependencies; 3) rmmod it; 4) repeat.

That would work in all cases (except some even more weird).  But the problem is more profound.
Comment 27 Pavel Shved 2009-04-05 12:03:52 UTC
Created attachment 187365 [details, diff]
rmmod snd* modules in topological order

The patch implements the algorithm proposed in comment #26.

WARNING! This patch won't work if snd* module may depend on any other module (that doesn't match snd* pattern).  I think that it's impossible by design, but you know better.  However, the patch can be fixed if the opposite holds.
Comment 28 renato gallo 2009-04-07 13:38:59 UTC
same problem on kernel 2.6.29.1

(In reply to comment #27)
> Created an attachment (id=187365) [edit]
> rmmod snd* modules in topological order
> 
> The patch implements the algorithm proposed in comment #26.
> 
> WARNING! This patch won't work if snd* module may depend on any other module
> (that doesn't match snd* pattern).  I think that it's impossible by design, but
> you know better.  However, the patch can be fixed if the opposite holds.
> 

Comment 29 renato gallo 2009-04-07 13:45:24 UTC
patch tested it seems to work

(In reply to comment #27)
> Created an attachment (id=187365) [edit]
> rmmod snd* modules in topological order
> 
> The patch implements the algorithm proposed in comment #26.
> 
> WARNING! This patch won't work if snd* module may depend on any other module
> (that doesn't match snd* pattern).  I think that it's impossible by design, but
> you know better.  However, the patch can be fixed if the opposite holds.
> 

Comment 30 Gabor Garami 2009-04-15 18:19:48 UTC
I have same issue with 2.6.29-gentoo-r1 kernel. My laptop uses snd_hda_codec_realtek module, and it cannot removable even if no sound application running (i booted firstly without X and the shutdown was freezed at alsasound). No nfs installed...

Portage 2.1.6.11 (default/linux/amd64/2008.0, gcc-4.3.2, glibc-2.8_p20080602-r1, 2.6.29-gentoo-r1 x86_64)
=================================================================
System uname: Linux-2.6.29-gentoo-r1-x86_64-Intel-R-_Pentium-R-_Dual_CPU_T2370_@_1.73GHz-with-glibc2.2.5
Timestamp of tree: Tue, 14 Apr 2009 01:45:03 +0000
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p39
dev-java/java-config: 1.3.7-r1, 2.1.7
dev-lang/python:     2.4.4-r14, 2.5.2-r7
dev-python/pycrypto: 2.0.1-r8
dev-util/ccache:     2.4-r7
dev-util/cmake:      2.6.2
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.3.0
sys-devel/autoconf:  2.13, 2.63
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=nocona -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /opt/kde/4.3/env /opt/kde/4.3/share/config /opt/kde/4.3/shutdown /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/splash /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-O2 -march=nocona -pipe"
DISTDIR="/mnt/portage/distfiles"
FEATURES="ccache distlocks fixpackages parallel-fetch protect-owned sandbox sfperms strict unmerge-orphans userfetch userpriv"
GENTOO_MIRRORS="http://gentoo.osuosl.org"
LANG="hu_HU.UTF-8"
LDFLAGS="-Wl,-O1"
LINGUAS="hu"
MAKEOPTS="-j3"
PKGDIR="/mnt/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--bwlimit=512"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/solaris-theme /usr/portage/local/layman/hron /usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X acl acpi alsa amd64 avahi bash-completion berkdb bluetooth branding bzip2 cli cracklib crypt cups dbus dri eds fortran gdbm gif gnome gnome-keyring gpm gtk hal iconv ipv6 isdnlog jpeg kdeprefix kerberos ldap libnotify midi mmx mudflap multilib ncurses networkmanager nls nptl nptlonly opengl openmp pam pcre perl png pppd python readline reflection samba session spl sse sse2 ssl sysfs tcpd tiff truetype ttf unicode vim-syntax xinerama xml xorg xulrunner zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse synaptics evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="hu" NETBEANS_MODULES="apisupport groovy gsf harness ide j2ee java nb websvccommon xml" USERLAND="GNU" VIDEO_CARDS="nvidia"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS


Module                  Size  Used by
snd_hda_codec_realtek  243652 1 
snd_hda_intel          25656  1 
snd_hda_codec          62208  2 snd_hda_codec_realtek,snd_hda_intel
snd_pcm                79256  2 snd_hda_intel,snd_hda_codec
snd_timer              21808  1 snd_pcm
snd                    63176  7 snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_pcm,snd_timer
snd_page_alloc          9760  2 snd_hda_intel,snd_pcm

Comment 31 Gabor Garami 2009-04-15 18:24:55 UTC
I thinking... it is a correct way? Because, in your example, the snd_hda_codec_realtek have zero dependencies but 1 user. How it can works if no sound application started, so definitelly not uses anythin sound in system?

(In reply to comment #26)
[...]
> What i propose is the other algorithm of recursive module unloading: 1) lsmod;
> 2) pick a module with zero reverse dependencies; 3) rmmod it; 4) repeat.
> 
> That would work in all cases (except some even more weird).  But the problem is
> more profound.
> 

Comment 32 Pavel Shved 2009-04-15 19:49:32 UTC
(In reply to comment #31)
> I thinking... it is a correct way? Because, in your example, the
> snd_hda_codec_realtek have zero dependencies but 1 user. How it can works if no
> sound application started, so definitelly not uses anythin sound in system?
What you call a `user' I call a `dependency'.  Anyway modules can also be `users' of other modules, however, whithout being listed in lsmod!  Try `rmmod snd_hda_codec_realtek` and check number of users of `snd_hda_intel'.

Anyway, to see an error in generic algorithm and fix it, it doesn't require profound knowledge on deeper levels.  Experience, Intuition and Experiment are engineer's weapons.  So, please, try my patch and report whether it works :-) 

Comment 33 renato gallo 2009-04-15 20:15:55 UTC
I am looking forward to see this patch on the tree

(In reply to comment #32)
> (In reply to comment #31)
> > I thinking... it is a correct way? Because, in your example, the
> > snd_hda_codec_realtek have zero dependencies but 1 user. How it can works if no
> > sound application started, so definitelly not uses anythin sound in system?
> What you call a `user' I call a `dependency'.  Anyway modules can also be
> `users' of other modules, however, whithout being listed in lsmod!  Try `rmmod
> snd_hda_codec_realtek` and check number of users of `snd_hda_intel'.
> 
> Anyway, to see an error in generic algorithm and fix it, it doesn't require
> profound knowledge on deeper levels.  Experience, Intuition and Experiment are
> engineer's weapons.  So, please, try my patch and report whether it works :-) 
> 

Comment 34 Matthew Schultz 2009-04-15 21:21:29 UTC
(In reply to comment #32)
> (In reply to comment #31)
> > I thinking... it is a correct way? Because, in your example, the
> > snd_hda_codec_realtek have zero dependencies but 1 user. How it can works if no
> > sound application started, so definitelly not uses anythin sound in system?
> What you call a `user' I call a `dependency'.  Anyway modules can also be
> `users' of other modules, however, whithout being listed in lsmod!  Try `rmmod
> snd_hda_codec_realtek` and check number of users of `snd_hda_intel'.
> 
> Anyway, to see an error in generic algorithm and fix it, it doesn't require
> profound knowledge on deeper levels.  Experience, Intuition and Experiment are
> engineer's weapons.  So, please, try my patch and report whether it works :-) 
> 

Your patch is working flawlessly here with emu10k1 and intel hda.
Comment 35 Bob Raitz 2009-04-15 21:41:29 UTC
Just a word of advice. This problem can be very intermittent. If the new patch works properly for at least two weeks, I'd say it's fixed. I've got my fingers crossed.
Comment 36 ranson 2009-04-21 07:17:45 UTC
My computer hadn't shut down properly once since I upgraded to 2.6.29.

With alsa-rmmod-topsort.patch, it now shuts down cleanly.
Comment 37 renato gallo 2009-04-21 07:20:20 UTC
It solves the problem please add to tree

(In reply to comment #36)
> My computer hadn't shut down properly once since I upgraded to 2.6.29.
> 
> With alsa-rmmod-topsort.patch, it now shuts down cleanly.
> 

Comment 38 Tony Vroon (RETIRED) gentoo-dev 2009-04-21 10:53:16 UTC
All that should be done is stabilising a newer ALSA. We no longer support module unloading in that version, it was a bad idea in the first place.
Comment 39 Matthew Schultz 2009-04-21 16:46:48 UTC
(In reply to comment #38)
> All that should be done is stabilising a newer ALSA. We no longer support
> module unloading in that version, it was a bad idea in the first place.
> 

When will alsa-utils 1.0.19 be stabilized then?
Comment 40 Bob Raitz 2009-04-21 18:57:56 UTC
One week down, and not a hang in sight. This might actually be the one to do the trick. I'll check back next week. :)
Comment 41 pier 2009-04-22 11:40:46 UTC
Patch worked for me too. Thanks!

Linux localhost 2.6.29-gentoo-r1 #2 SMP Tue Apr 21 10:53:38 CEST 2009 i686 Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz GenuineIntel GNU/Linux

dmidecode | grep Mac
        Product Name: MacBook4,1
        Family: MacBook
        Product Name: Mac-F22788A9
        Version: Mac-F22788A9

00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 04)

Comment 42 Gabor Garami 2009-04-24 10:41:42 UTC
No, i mean in 'user' as app/service what uses this. For example, if you mount something, you see 1 user, but no defined dependency. I think, if sound app is stuck, then the number is greater than 1. How do you decide what happen?

(In reply to comment #32)
> (In reply to comment #31)
> > I thinking... it is a correct way? Because, in your example, the
> > snd_hda_codec_realtek have zero dependencies but 1 user. How it can works if no
> > sound application started, so definitelly not uses anythin sound in system?
> What you call a `user' I call a `dependency'.  Anyway modules can also be
> `users' of other modules, however, whithout being listed in lsmod!  Try `rmmod
> snd_hda_codec_realtek` and check number of users of `snd_hda_intel'.
> 
> Anyway, to see an error in generic algorithm and fix it, it doesn't require
> profound knowledge on deeper levels.  Experience, Intuition and Experiment are
> engineer's weapons.  So, please, try my patch and report whether it works :-) 
> 

Comment 43 Bob Raitz 2009-04-30 18:35:39 UTC
Barring the fact that the patch tells me I have some devices not loading, it has been over two weeks, and I have not experienced a lock up. I'd say this is probably as close to fixed as the problem has been since I posted it.

Thanks to all.
Comment 44 renato gallo 2009-04-30 23:26:45 UTC
I think this is solved it misses just to be added on tree

(In reply to comment #43)
> Barring the fact that the patch tells me I have some devices not loading, it
> has been over two weeks, and I have not experienced a lock up. I'd say this is
> probably as close to fixed as the problem has been since I posted it.
> 
> Thanks to all.
> 

Comment 45 Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2009-04-30 23:51:05 UTC
(In reply to comment #44)
> I think this is solved it misses just to be added on tree

I think alsa team is planning to stabilize new alsa which does not unload modules anymore by default, per comment 38.
Meanwhile you can try the same behaviour with older alsa as comment 19 suggests.

Comment 20 suggests that disabling module unloading just postpones the problem. I don't see how the patches on this bug could help in that case, but if that's still reproducible, then that's a bug to solve IMHO. Otherwise, if disabling module unloading works for you, that's the solution.
Comment 46 Christophe PEREZ 2009-06-03 04:58:50 UTC
(In reply to comment #27)
> Created an attachment (id=187365) [edit]
> rmmod snd* modules in topological order

Worked for me too.
Thanks.

But I wanted to say that I haven't this problem if I boot with gentoo-sources-2.6.28-r5 kernel. Only with gentoo-sources-2.6.29-r5.
Comment 47 Eric Johnson 2009-06-06 21:22:13 UTC
(In reply to comment #27)
> Created an attachment (id=187365) [edit]
> rmmod snd* modules in topological order
> 
> The patch implements the algorithm proposed in comment #26.

Much appreciated. The patch worked for me, as well, running gentoo-sources 2.6.29-r5. And, as in comment #46, under gentoo-sources 2.6.28-r5, the problem did not exist.
Comment 48 Patrick Leetzor 2009-06-08 22:15:26 UTC
If anyone is still having this problem you can fix this by editing:

/etc/conf.d/rc

And disabling unload modules on shutdown.

This is probably for more recent or the MOST recent version of alsa.
Comment 49 Jakob Schiotz 2009-06-10 09:04:08 UTC
The suggestion in comment #19 of setting

UNLOAD_ON_STOP="no"

in /etc/conf.d/alsasound worked well for me.  I did *not* set KILLPROC_ON_STOP to no since that part was not hanging.  Perhaps that is the reason I did not get hangs at the end of the shutdown process, as reported in comment #20.

/Jakob

Comment 50 Michael Pyne 2009-06-21 06:07:36 UTC
I've encountered this bug when building the kernel with the "snd" module compiled in (so it didn't show up in lsmod).  My fix I generated here was essentially the same as the last patch attached to this bug (i.e. remove snd* modules that have 0 dependents until all are removed).

However, I would say that the best fix is to disable module unloading, especially after reading the rmmod man page (some kernels even have unloading disabled completely).  Module unloading is not needed to shutdown the computer and actually it even increases the time it takes to shutdown.  It's also not needed for saving audio settings, since unloading happens after that is done.

If it is decided to leave in the option to unload modules then it will be necessary to implement Pavel's patch however as the current unloading is broken.
Comment 51 Sebastián Treu 2009-07-02 09:58:27 UTC
Hi there,

I was having similar problems with alsa. Kernel is vanilla-sources-2.6.29.5 patched with the real time patch: ftp://ftp.kernel.org/pub/linux/kernel/projects/rt/

When the system was going down the alsasound script hangs on "Unloading Alsa modules". Same when doing "/etc/init.d/alsasoun stop". I issue this manually, and in another terminal I issue: "modprobe -r snd-hda-intel". Then, alsasound script exits complaining on unexisting modules. For debug purposes I enabled more verbose debug (all posible) on alsa. I've donde the same without any modules message.

Then, I was sure that it was a kernel issue, because prior this kernel I had no problems. So I tried removing options until it works fine for now and I removed this ones:

< > HR-timer backend support 
< > RTC Timer support 
[ ] Build hwdep interface for HD-audio driver

And the only features enabled on HDA are the ones that correspond to my chipset, and the generic parser (this is needed, module loading will complaint if not):

[*] Enable generic HD-audio codec parser
[*] Build NVIDIA HDMI HD-audio codec support

With that and this:
<M>   Sequencer support
<M>   Sequencer dummy client
<M>   OSS Mixer API
<M>   OSS PCM (digital audio) API
[*]     OSS PCM (digital audio) API - Include plugin system
[*]   OSS Sequencer API

But, this is with vanilla-sources, not with gentoo-sources. I repeat that prior using vanilla-sources I was using gentoo-sources-2.6.25 without this problem.

Hope it helps,
Regards

Comment 52 Sebastián Treu 2009-07-02 10:03:29 UTC
Sorry for my incompleteness. 

I forgot to mention an important thing. When I said that I issued "modprobe -r snd-hda-intel", I really was able to unload the modules. That is not explicity said in my comment, just in case of a doubt I want it to specify that. And, that's why alsasound scripts complain about modules that want to remove that there aren't there.

Regards,
Comment 53 Pacho Ramos gentoo-dev 2009-07-03 16:17:59 UTC
All these problems ended for me when I upsated to alsa-*-1.0.19 :-/
Comment 54 Bob Raitz 2009-07-23 07:55:31 UTC
Is anyone still having issues with this? If not, I'd say it might be time to close this one. This has long since stopped being an issue for me, and last I read, it's pretty much that way for everyone else who signed on to this bug. Maybe it's time to close this one as fixed.
Comment 55 Steve Dibb (RETIRED) gentoo-dev 2009-08-01 05:06:21 UTC
(In reply to comment #54)
> Is anyone still having issues with this? If not, I'd say it might be time to
> close this one. This has long since stopped being an issue for me, and last I
> read, it's pretty much that way for everyone else who signed on to this bug.
> Maybe it's time to close this one as fixed.
> 

The option is getting punted from initd/confd soon.
Comment 56 Steve Dibb (RETIRED) gentoo-dev 2009-08-03 16:36:18 UTC
(In reply to comment #55)
> (In reply to comment #54)
> > Is anyone still having issues with this? If not, I'd say it might be time to
> > close this one. This has long since stopped being an issue for me, and last I
> > read, it's pretty much that way for everyone else who signed on to this bug.
> > Maybe it's time to close this one as fixed.
> > 
> 
> The option is getting punted from initd/confd soon.
> 

Gone
Comment 57 Bob Raitz 2009-08-04 04:32:03 UTC
YAY!
Comment 58 Leho Kraav (:macmaN @lkraav) 2009-08-11 19:35:14 UTC
i ran into the same 'snd-hda-intel not unloading when stopping alsasound' problem. running 2.6.30-tuxonice-r4 and alsa-* 1.17. upgrading to alsa-* 1.19 seems to have implemented a new strategy for simply not unloading the modules at all when stopping alsasound. i guess that does fix the problem in a way.