ALSA: pcm: Remove down_write() hack for snd_pcm_link_rwsem
authorTakashi Iwai <tiwai@suse.de>
Tue, 22 Jan 2019 13:29:51 +0000 (14:29 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 23 Jan 2019 06:40:49 +0000 (07:40 +0100)
Remove the hackish down_write_nonfifo() that was introduced as a
workaround of rwsem deadlock.

It used to be a problem for non-atomic PCM streams that take the rwsem
for the locking and hit the high lock contention.  Since the current
PCM locking refactoring, we'll no longer hit it as the hot code-paths
don't take global locks.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_native.c

index cbde23fc67a9b9930bc8249ee24d40b50eb79c09..f450083eb07383e568863a5ae463a22039c00e59 100644 (file)
@@ -87,18 +87,6 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream);
 
 static DECLARE_RWSEM(snd_pcm_link_rwsem);
 
-/* Writer in rwsem may block readers even during its waiting in queue,
- * and this may lead to a deadlock when the code path takes read sem
- * twice (e.g. one in snd_pcm_action_nonatomic() and another in
- * snd_pcm_stream_lock()).  As a (suboptimal) workaround, let writer to
- * sleep until all the readers are completed without blocking by writer.
- */
-static inline void down_write_nonfifo(struct rw_semaphore *lock)
-{
-       while (!down_write_trylock(lock))
-               msleep(1);
-}
-
 void snd_pcm_group_init(struct snd_pcm_group *group)
 {
        spin_lock_init(&group->lock);
@@ -2052,7 +2040,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
        }
        snd_pcm_group_init(group);
 
-       down_write_nonfifo(&snd_pcm_link_rwsem);
+       down_write(&snd_pcm_link_rwsem);
        if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN ||
            substream->runtime->status->state != substream1->runtime->status->state ||
            substream->pcm->nonatomic != substream1->pcm->nonatomic) {
@@ -2100,7 +2088,7 @@ static int snd_pcm_unlink(struct snd_pcm_substream *substream)
        bool do_free = false;
        int res = 0;
 
-       down_write_nonfifo(&snd_pcm_link_rwsem);
+       down_write(&snd_pcm_link_rwsem);
 
        if (!snd_pcm_stream_linked(substream)) {
                res = -EALREADY;