From: Takashi Iwai <tiwai@suse.de>
To: Ricard Wanderlof <ricard.wanderlof@axis.com>
Cc: "Arvid Nihlgård Lindell" <arvidnl@axis.com>,
"Andreas x Larsson" <andrelan@axis.com>,
alsa-devel <alsa-devel@alsa-project.org>
Subject: Re: [PATCH] alsa-lib:Make snd_atomic_write_* truly atomic
Date: Tue, 17 May 2016 14:21:27 +0200 [thread overview]
Message-ID: <s5hr3d07u48.wl-tiwai@suse.de> (raw)
In-Reply-To: <alpine.DEB.2.02.1605171053010.31333@lnxricardw1.se.axis.com>
On Tue, 17 May 2016 14:11:43 +0200,
Ricard Wanderlof wrote:
>
>
> On Fri, 13 May 2016, Takashi Iwai wrote:
>
> > > > Yeah, that's why I stated the primary question. The atomic operation
> > > > there is mostly cosmetic, not really helpful. In the whole other
> > > > operation, we don't guarantee the thread safety at all. So,
> > > > implementing the atomic op only in a very small part of the whole code
> > > > appears like a superfluous optimization to me.
> > >
> > > The question is, if we decide to remove this atomic stuff, how do we
> > > verify that it actually causes no problems, on all architectures, etc?
> >
> > It's not what one can show in 100%, as you know. And, it's the reason
> > why the code is still left over years...
>
> We have come up upon this problem in conjunction with GStreamer. It
> appears that GStreamer uses one thread for the streaming and a separate
> one for the device management (open/close) on the same device handle,
> which triggers the problem. So it appears that GStreamer falsly is
> assuming some form of thread safety here.
>
> The atomic stuff is so specific to a couple of files, it seems as if it
> was added for a specific purpose, such as this particular case. In the
> other hand, looking at the git history of include/iatomic.h, it's gone
> through a number of cleanups over the years, lately mostly to remove
> originally buggy code, and what is remaining I guess like you say is just
> what nobody dared remove.
>
> On the other hand, as the code stands, I can't really understand how it
> enforces atomicity. The read and write memory barriers just guarantee
> ordering, but there's nothing to stop a context switch from occurring in
> the middle of a ++ operation. wmb() and rmb() might influence timing
> though so that code at least might behave differently with those
> operations in place.
There is a manual lock loop with snd_atomic_read_wait(), as found in
pcm_plugin.c. So, removing the stuff may potentially damage some apps
that wrongly assume the thread safety.
Now I've been considering this issue again, I'm inclined to suggest:
let's begin with deprecating the atomic stuff there, but opt-in via
via a configure option for a while, in case someone still really needs
it.
By making it optional, it's fine to take your patch and cleanup the
old code. Then we don't have to think of the compatibility with the
old toolchain so much.
Takashi
next prev parent reply other threads:[~2016-05-17 12:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-13 10:42 [PATCH] alsa-lib:Make snd_atomic_write_* truly atomic Andreas x Larsson
2016-04-13 13:49 ` Takashi Iwai
2016-05-12 12:51 ` Ricard Wanderlof
2016-05-12 13:04 ` Takashi Iwai
2016-05-12 14:17 ` Ricard Wanderlof
2016-05-12 14:47 ` Takashi Iwai
2016-05-12 16:09 ` Ricard Wanderlof
2016-05-13 12:26 ` Ricard Wanderlof
2016-05-13 12:37 ` Takashi Iwai
2016-05-17 12:11 ` Ricard Wanderlof
2016-05-17 12:21 ` Takashi Iwai [this message]
2016-05-17 13:29 ` Ricard Wanderlof
2016-05-17 13:37 ` Takashi Iwai
2016-05-17 15:28 ` Ricard Wanderlof
2016-05-17 15:37 ` Takashi Iwai
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=s5hr3d07u48.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=andrelan@axis.com \
--cc=arvidnl@axis.com \
--cc=ricard.wanderlof@axis.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.