Repository navigation
tools/kmod: tolerate USB-audio-busy for shared ALSA core modules #1367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,20 +27,45 @@ remove_module() { | |||||
| fi | ||||||
| } | ||||||
|
|
||||||
| remove_usb_audio_module() | ||||||
| { | ||||||
| local module="$1" attempt | ||||||
|
|
||||||
| for attempt in 1 2 3; do | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please double check but I think you can replace this entire function with just this: try_remove_module_3times()
{
local _module="$1"
poll_wait_for 1 3 remove_module "$_module"
}
If true then you might want to just inline it everywhere? |
||||||
| if remove_module "$module"; then | ||||||
| return 0 | ||||||
| fi | ||||||
| if [ "$attempt" -lt 3 ]; then | ||||||
| printf 'Retrying removal of %s in 1s (attempt %s/3 failed)\n' \ | ||||||
| "$module" "$attempt" | ||||||
| sleep 1 | ||||||
| fi | ||||||
| done | ||||||
|
|
||||||
| return 1 | ||||||
| } | ||||||
|
|
||||||
| exit_handler() | ||||||
| { | ||||||
| local exit_status="$1" | ||||||
| local daemon | ||||||
|
|
||||||
| # Audio daemons can hold USB audio modules even when no SOF playback is active. | ||||||
| for daemon in pulseaudio pipewire pipewire-pulse wireplumber jackd jackdbus; do | ||||||
| pgrep -a -x "$daemon" || true | ||||||
| done | ||||||
|
|
||||||
| # Even without any active audio, pulseaudio can use modules | ||||||
| # "non-deterministically". So even if we are successful this time, | ||||||
| # warn about any running pulseaudio because it could make us fail | ||||||
| # the next time. | ||||||
| # TODO: display any pipewire process too. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is dropped but the code did not change? Confused. |
||||||
| if pgrep -a pulseaudio; then | ||||||
| systemctl_show_pulseaudio || true | ||||||
| fi | ||||||
|
|
||||||
| if test "$exit_status" -ne 0; then | ||||||
| lsmod | grep -e sof -e snd -e sound -e drm | ||||||
| sudo fuser -v /dev/snd/* || true | ||||||
| # rmmod can fail silently, for instance when "Used by" is -1 | ||||||
| printf "%s FAILED\n" "$0" | ||||||
| fi | ||||||
|
|
@@ -193,10 +218,14 @@ remove_module snd_soc_sdw_rt700 | |||||
| remove_module snd_soc_sdw_rt711_rt1308_rt715 | ||||||
| remove_module snd_usb_offload | ||||||
| remove_module soc_usb | ||||||
| # SOF CI has a dependency on usb audio. This has to come after | ||||||
| # snd_usb_offload and soc_usb, which hold references on snd_usb_audio. | ||||||
| remove_module snd_usb_audio | ||||||
| remove_module snd_usbmidi_lib | ||||||
| # CI may use a USB audio device outside the SOF stack under test. Retry | ||||||
| # removal in case its references are transient; if it remains loaded, | ||||||
| # tolerate failures only for the shared ALSA modules it keeps busy. Other | ||||||
| # unload failures remain fatal. This has to come after snd_usb_offload and | ||||||
| # soc_usb, which hold references on snd_usb_audio. | ||||||
| usb_audio_still_loaded=false | ||||||
| remove_usb_audio_module snd_usb_audio || usb_audio_still_loaded=true | ||||||
| remove_usb_audio_module snd_usbmidi_lib || usb_audio_still_loaded=true | ||||||
| remove_module snd_soc_sof_sdw | ||||||
| remove_module snd_soc_sdw_utils | ||||||
| remove_module snd_soc_sof_es8336 | ||||||
|
|
@@ -342,7 +371,7 @@ remove_module snd_soc_sdca | |||||
| remove_module snd_soc_core | ||||||
| remove_module snd_hda_codec | ||||||
| remove_module snd_hda_core | ||||||
| remove_module snd_hwdep | ||||||
| remove_module snd_hwdep || [ "$usb_audio_still_loaded" = true ] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming I understand this correctly, the brackets do not seem necessary
Suggested change
Either way this code is a bit cryptic, I think it deserves a short comment. Something simple like "ignore failure when USB failed to unload before" |
||||||
| remove_module snd_compress | ||||||
| remove_module snd_pcm_dmaengine | ||||||
| remove_module snd_pcm | ||||||
|
|
@@ -355,11 +384,11 @@ remove_module snd_seq_midi_event | |||||
| # rmmod: ERROR: Module snd_rawmidi is in use by: snd_ump | ||||||
| # aborting reload_drivers() and cascading into every driver-reload test case. | ||||||
| remove_module snd_ump | ||||||
| remove_module snd_rawmidi | ||||||
| remove_module snd_rawmidi || [ "$usb_audio_still_loaded" = true ] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, same below. |
||||||
| remove_module snd_seq_dummy | ||||||
| remove_module snd_seq | ||||||
| remove_module snd_seq_device | ||||||
| remove_module snd_seq_device || [ "$usb_audio_still_loaded" = true ] | ||||||
| remove_module snd_hrtimer | ||||||
| remove_module snd_timer | ||||||
| remove_module snd | ||||||
| remove_module soundcore | ||||||
| remove_module snd_timer || [ "$usb_audio_still_loaded" = true ] | ||||||
| remove_module snd || [ "$usb_audio_still_loaded" = true ] | ||||||
| remove_module soundcore || [ "$usb_audio_still_loaded" = true ] | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is actually not specific to USB.