From patchwork Sat Nov 24 07:32:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanho Min X-Patchwork-Id: 10696423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 608D01750 for ; Sat, 24 Nov 2018 07:33:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31A362AFE0 for ; Sat, 24 Nov 2018 07:33:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 248BB2AFF7; Sat, 24 Nov 2018 07:33:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE73C2AFE0 for ; Sat, 24 Nov 2018 07:33:20 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9338B2678DD; Sat, 24 Nov 2018 08:33:18 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id DC4E22678DF; Sat, 24 Nov 2018 08:33:15 +0100 (CET) Received: from lgeamrelo11.lge.com (lgeamrelo13.lge.com [156.147.23.53]) by alsa0.perex.cz (Postfix) with ESMTP id 68E5E2677E8 for ; Sat, 24 Nov 2018 08:33:10 +0100 (CET) Received: from unknown (HELO lgeamrelo01.lge.com) (156.147.1.125) by 156.147.23.53 with ESMTP; 24 Nov 2018 16:33:07 +0900 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: chanho.min@lge.com Received: from unknown (HELO kernel.lge.com) (165.186.175.97) by 156.147.1.125 with ESMTP; 24 Nov 2018 16:33:07 +0900 X-Original-SENDERIP: 165.186.175.97 X-Original-MAILFROM: chanho.min@lge.com From: Chanho Min To: Jaroslav Kysela , Takashi Iwai , Vinod Koul , Daniel Mentz Date: Sat, 24 Nov 2018 16:32:43 +0900 Message-Id: <1543044763-31843-1-git-send-email-chanho.min@lge.com> X-Mailer: git-send-email 2.1.4 Cc: alsa-devel@alsa-project.org, Jaehyun Kim , Jongsung Kim , Chanho Min , linux-kernel@vger.kernel.org, Hyonwoo Park , Wonmin Jung , Seungho Park Subject: [alsa-devel] [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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