All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaroslav Kysela <perex@perex.cz>
To: Tom Yan <tom.ty89@gmail.com>,
	alsa-devel@alsa-project.org,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	pulseaudio-discuss@lists.freedesktop.org,
	pierre-louis.bossart@linux.intel.com
Subject: Re: Why doesn't mixer control (values) have some kind of locking mechanism? (mutex?)
Date: Fri, 7 Aug 2020 11:08:46 +0200	[thread overview]
Message-ID: <b6a8e6fd-3577-08d3-e289-c7a121450fd3@perex.cz> (raw)
In-Reply-To: <20200806144729.GA381789@workstation>

Dne 06. 08. 20 v 16:47 Takashi Sakamoto napsal(a):
> Hi,
> 
> On Thu, Aug 06, 2020 at 08:31:51PM +0800, Tom Yan wrote:
>> Yeah I suppose a "full" lock would do. (That was what I was trying to
>> point out. I don't really understand Pierre's message. I merely
>> suppose you need some facility in the kernel anyway so that you can
>> lock from userspace.) I hope that amixer the utility will at least have
>> the capability to reschedule/wait by then though (instead of just
>> "failing" like in your python demo).
> 
> As long as I know, neither tools in alsa-utils/alsa-tools nor pulseaudio
> use the lock mechanism. In short, you are the first person to address
> to the issue. Thanks for your patience since the first post in 2015.
> 
>> As for the compare-and-swap part, it's just a plus. Not that
>> "double-looping" for *each* channel doesn't work. It just again seems
>> silly and primitive (and was once confusing to me).
> 
> I prepare a rough kernel patch abount the compare-and-swap idea for
> our discussion. The compare-and-swap is done under lock acquisition of
> 'struct snd_card.controls_rwsem', therefore many types of operations
> to control element (e.g. read as well) get affects. This idea works
> well at first when alsa-lib supports corresponding API and userspace
> applications uses it. Therefore we need more work than changing just
> in userspace.
> 
> But in my opinion, if things can be solved just in userspace, it should
> be done with no change in kernel space.

The compare-and-swap is just a limited mechanism which does not resolve all
possible usage cases (mainly the operation grouping).

I read the whole story and I basically don't think that we need to handle this
in the kernel space. The arbitration should be easily implementable in the
user space. We can agree that we need to add a new extension which will grant
to the user space application the exclusive access to change one or more
control elements exclusively possibly based on the previous contents.

I would propose a new alsa-lib API extension (which may be shared with other
ALSA user space APIs): System V semaphore (man 2 semop). We can use the named
semaphore. Two functions can be added like snd_ctl_transaction_begin() and
snd_ctl_transaction_end() to alsa-lib. The wait condition can be handled
through an argument to snd_ctl_transaction_begin(). It might be probably also
nice to consider the poll multiplexing implementation for the wait condition
(use a message queue to notify other tasks when the semaphore was released).

					Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

  parent reply	other threads:[~2020-08-07  9:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-05 17:31 Why doesn't mixer control (values) have some kind of locking mechanism? (mutex?) Tom Yan
2020-08-05 18:40 ` Pierre-Louis Bossart
2020-08-06  2:06 ` Takashi Sakamoto
2020-08-06  8:57   ` Tom Yan
2020-08-06  9:14     ` Takashi Sakamoto
2020-08-06 12:31       ` Tom Yan
2020-08-06 14:47         ` Takashi Sakamoto
2020-08-06 15:34           ` Tom Yan
2020-08-06 17:19             ` Takashi Sakamoto
2020-08-06 18:45               ` Tom Yan
2020-08-07  9:08           ` Jaroslav Kysela [this message]
2020-08-06 15:30   ` [pulseaudio-discuss] " Pierre-Louis Bossart
2020-08-06 17:47     ` Takashi Sakamoto
2020-08-07  0:12       ` Pierre-Louis Bossart
2020-08-07  2:34         ` Takashi Sakamoto

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=b6a8e6fd-3577-08d3-e289-c7a121450fd3@perex.cz \
    --to=perex@perex.cz \
    --cc=alsa-devel@alsa-project.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=pulseaudio-discuss@lists.freedesktop.org \
    --cc=tom.ty89@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.