ALSA: usb-audio: Refcount multiple accesses on the single clock
PATCH 1/1 ALSA: usb-audio: Refcount multiple accesses on the single clock
When a clock source is connected to multiple nodes / endpoints, the current USB-audio driver tries to set up at each time one of them is configured. Although it reads the current rate and updates only if it differs, some devices seem unhappy with this behavior and spew the errors when reading/updating the rate unnecessarily.
This patch tries to reduce the redundant clock setup by introducing a refcount for each clock source. When the stream is actually running, a clock rate is "locked", and it bypasses the clock and/or refuse to change any longer.
--- sound/usb/card.c | 1 + sound/usb/card.h | 3 +- sound/usb/endpoint.c | 90 +++++++++++++++++++++++++++++++++++++++----- sound/usb/usbaudio.h | 1 + 4 files changed, 85 insertions(+), 10 deletions(-)
sound/usb/card.c +1 -0
@@ -635,6 +635,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,INIT_LIST_HEAD (&chip->pcm_list);INIT_LIST_HEAD (&chip->ep_list);INIT_LIST_HEAD (&chip->iface_ref_list); +INIT_LIST_HEAD (&chip->clock_ref_list);INIT_LIST_HEAD (&chip->midi_list);INIT_LIST_HEAD (&chip->mixer_list);
sound/usb/card.h +2 -1
@@ -44,6 +44,7 @@ struct audioformat {struct snd_usb_substream ;struct snd_usb_iface_ref ; +struct snd_usb_clock_ref ;struct snd_usb_endpoint ;struct snd_usb_power_domain ;
@@ -62,6 +63,7 @@ struct snd_urb_ctx {struct snd_usb_endpoint {struct snd_usb_audio *chip;struct snd_usb_iface_ref *iface_ref; +struct snd_usb_clock_ref *clock_ref;int opened;/* open refcount; protect with chip->mutex */ atomic_t running;/* running status */
@@ -138,7 +140,6 @@ struct snd_usb_endpoint {unsigned int cur_period_frames;unsigned int cur_period_bytes;unsigned int cur_buffer_periods; -unsigned char cur_clock;spinlock_t lock;struct list_head list;
sound/usb/endpoint.c +81 -9
180 lines not on this page · raw message
sound/usb/usbaudio.h +1 -0
@@ -45,6 +45,7 @@ struct snd_usb_audio {struct list_head pcm_list;/* list of pcm streams */ struct list_head ep_list;/* list of audio-related endpoints */ struct list_head iface_ref_list;/* list of interface refcounts */ +struct list_head clock_ref_list;/* list of clock refcounts */ int pcm_devs;struct list_head midi_list;/* list of midi interfaces */
Signature · 1 line
2.35.3
Hi Takashi,
Quoted 10 lines · Takashi Iwai
When a clock source is connected to multiple nodes / endpoints, the current USB-audio driver tries to set up at each time one of them is configured. Although it reads the current rate and updates only if it differs, some devices seem unhappy with this behavior and spew the errors when reading/updating the rate unnecessarily.
This patch tries to reduce the redundant clock setup by introducing a refcount for each clock source. When the stream is actually running, a clock rate is "locked", and it bypasses the clock and/or refuse to change any longer.
This breaks things on 5.19+. Specifically, it causes pipewire and pulseaudio to be stuck using 44.1khz rather than 48.0khz (or anything else). The reason is that initially devices are started at 44.1khz, and then the list of supported sample rates is read, and finally the best one is chosen. With this commit, the returned list of sample rates is locked at 44.1khz, which means pulseaudio and pipewire can't change it to 48.0khz (or anything else).
This headscratcher is being tracked over at:
https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2620
where I triaged it to this commit.
Can we revert this for the time being and backport the revert to stable? Or might you have some other fix idea in mind?
Thanks,
Jason
Quoted 1 line · Jason A. Donenfeld
Can we revert this for the time being and backport the revert to stable?
I sent the revert here:
https://lore.kernel.org/all/[email protected]/