From: Takashi Iwai <tiwai@suse.de>
To: Jaroslav Kysela <perex@perex.cz>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH RFC] ALSA: control: Avoid nested locks at notification
Date: Wed, 24 May 2023 09:02:50 +0200 [thread overview]
Message-ID: <874jo2fbz9.wl-tiwai@suse.de> (raw)
In-Reply-To: <4a442399-9d92-0632-2354-8e31962c0728@perex.cz>
On Tue, 23 May 2023 18:53:11 +0200,
Jaroslav Kysela wrote:
>
> On 23. 05. 23 17:52, Takashi Iwai wrote:
> > The new control layer stuff introduced the nested rwsem for managing
> > the list of registered control layer ops. Since then, a global
> > snd_ctl_layer_rwsem is always read at each time a control notification
> > is sent via snd_ctl_notify*() in a nested matter inside the card's
> > controls_rwsem lock. This also required a bit complicated way of the
> > lock at snd_ctl_activate_id() and snd_ctl_elem_write() with the
> > downgrade of rwsem.
> >
> > This patch is an attempt to simplify the handling of ctl layer ops.
> > Now, instead of traversing the global linked list, we keep a local
> > list of lops in each card instance. This reduces the need of the
> > global snd_ctl_layer_rwsem lock at snd_ctl_notify*() invocation.
> > And, since the nested lock is avoided in most places, we can also
> > avoid the rwsem downgrade hack in the above, too.
> >
> > Since the local list entry is created dynamically,
> > snd_ctl_register_layer() may return an error, and the caller needs to
> > check the return value.
>
> I'm not convinced about this transition. What about to move the layer
> notifications to a workqueue to reorder the controls_rwsem locking
> (kctl access) ?
It'll need allocation of each new notify event, no?
IMO, keeping the list of ops in each card instance may have a room for
more possible improvement. The current patch chains always all lops
in the card's lops_list, but when the register callback returns a
certain error code for the uninteresting lops, we can skip chaining
it. Then the unnecessary hook invocation at each notification can be
avoided.
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >
> > I noticed the nested lock while looking at the pending bug report
>
> From the log or code ?
The code.
And, control_led.c has also a global mutex lock that is applied for
almost all code paths. If the hook is called from all cards, this
should be optimized as well. (OTOH, if it's called only from one
bound card, it won't matter much.)
thanks,
Takashi
prev parent reply other threads:[~2023-05-24 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 15:52 [PATCH RFC] ALSA: control: Avoid nested locks at notification Takashi Iwai
2023-05-23 16:53 ` Jaroslav Kysela
2023-05-24 7:02 ` Takashi Iwai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874jo2fbz9.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=perex@perex.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox