linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chanho Min <chanho.min@lge.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Vinod Koul <vinod.koul@intel.com>,
	Daniel Mentz <danielmentz@google.com>
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	Seungho Park <seungho1.park@lge.com>,
	Jongsung Kim <neidhard.kim@lge.com>,
	Wonmin Jung <wonmin.jung@lge.com>, Jaehyun Kim <jehn.kim@lge.com>,
	Hyonwoo Park <hyonwoo.park@lge.com>,
	Chanho Min <chanho.min@lge.com>
Subject: [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock()
Date: Sat, 24 Nov 2018 16:32:43 +0900	[thread overview]
Message-ID: <1543044763-31843-1-git-send-email-chanho.min@lge.com> (raw)

Commit 67ec1072b053 (ALSA: pcm: Fix rwsem deadlock for non-atomic PCM stream)
fixes deadlock for non-atomic PCM stream. But, This patch causes antother stuck.
If writer is RT thread and reader is a normal thread, the reader thread will
be difficult to get scheduled. It may not give chance to release read locks
and writer gets stuck for a long time or forever if they are pinned to single
cpu.

To fix this, The writer gives reader a chance to be scheduled by using the
minimum msleep() instaed of spinning. This is for concept, We may need to
change the function name and comments or suggest another approach.

Signed-off-by: Chanho Min <chanho.min@lge.com>
---
 sound/core/pcm_native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 66c90f4..88d4aab 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -96,7 +96,7 @@ static DECLARE_RWSEM(snd_pcm_link_rwsem);
 static inline void down_write_nonblock(struct rw_semaphore *lock)
 {
 	while (!down_write_trylock(lock))
-		cond_resched();
+		msleep(1);
 }
 
 #define PCM_LOCK_DEFAULT	0
-- 
2.1.4


             reply	other threads:[~2018-11-24  7:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-24  7:32 Chanho Min [this message]
2018-11-24 10:56 ` [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() kbuild test robot
2018-11-25 11:30 ` kbuild test robot
2018-11-26  5:36 Chanho Min
2018-11-26  8:36 ` Takashi Iwai
2018-11-27 23:47   ` Chanho Min
2018-11-28  8:37     ` Takashi Iwai
2018-11-28 23:48       ` Chanho Min
2018-11-29  7:19         ` Takashi Iwai
2018-11-29 23:03           ` Chanho Min
2018-11-28  6:26   ` Chanho Min

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=1543044763-31843-1-git-send-email-chanho.min@lge.com \
    --to=chanho.min@lge.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=danielmentz@google.com \
    --cc=hyonwoo.park@lge.com \
    --cc=jehn.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neidhard.kim@lge.com \
    --cc=perex@perex.cz \
    --cc=seungho1.park@lge.com \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@intel.com \
    --cc=wonmin.jung@lge.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).