Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5476128imu; Mon, 26 Nov 2018 00:37:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/WcrPayMwJW9MAgqYsTFKXGmDA3KPXAZea1ShLm6VKigog81oiLBbzs3tCiEdUxQlyz5iR7 X-Received: by 2002:a63:4a4d:: with SMTP id j13mr24286679pgl.127.1543221466078; Mon, 26 Nov 2018 00:37:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543221466; cv=none; d=google.com; s=arc-20160816; b=kA5VmNXWYo7zDAi5iVkpK9SV9iY/yrwKzPx+xRAaJjjusBAZZIL2Ckvc1ptHRBaEn/ a401qxqO4CTkqRm/YK21uQreXrIEF97TJ9FgNLPd29/Z79N+KYXtjnJ+9shjWAcVnGpj 9JZtyUk8i5844xglPsWFNkoYwpIZczOiRMLZGzAGty+lzEMR82wwcqmweLcTJmdJFxY6 IYtlwWNJAqzqgCJc4GuBvwn4WXJsLzAcbU+Ul+5/jIY0+tslt7GEsv3U1PKJyd3NhFVd qGflrjMBV9JXOmplEFXWBo3u//GfSCdU6xT81oDis5Jbyqpmypd48S0z4n/n3byVwG5J fvFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=lzEdU/FOYlhkECvl0wZhVNOEivvjKP03qceNIhHPzZs=; b=CGRCGnGe6hD+N/kDW0RQzm7gduD6b7chHL30FWhvHvIt8VPGxCZiKvKDRewxqnD7BG 0iYjezzyJdv5CCCWvG3B6gr1YFJsh6Awgb1cQoWIoFX+npbszM9/iUCQdnJBjo5yLh/+ phJze1hBgbguef4x+ROyfVp6QiFY7C+B8HsSJQ5KglX/xt/HWtimOW0YWptnhkWJnGRh o2Q41di4rh4psRH8qCIIzxTESJgNAVYDvsGN2k8zq3AQo56qWQ5Ea4xH5OnWnyXYaSvD 472a+qIGcTEYSSmN0g3sDJPeh5xtMl14dt51+3Td3BplKH6KjDsXrOmV9XjoKx/LQbw8 7a/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si59507420pgd.478.2018.11.26.00.37.30; Mon, 26 Nov 2018 00:37:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726201AbeKZTaS (ORCPT + 99 others); Mon, 26 Nov 2018 14:30:18 -0500 Received: from mx2.suse.de ([195.135.220.15]:60210 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726157AbeKZTaS (ORCPT ); Mon, 26 Nov 2018 14:30:18 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D6ADBAD48; Mon, 26 Nov 2018 08:36:53 +0000 (UTC) Date: Mon, 26 Nov 2018 09:36:53 +0100 Message-ID: From: Takashi Iwai To: Chanho Min Cc: Jaroslav Kysela , Takashi Iwai , Vinod Koul , Daniel Mentz , linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Seungho Park , Jongsung Kim , Wonmin Jung , Jaehyun Kim , Hyonwoo Park Subject: Re: [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() In-Reply-To: <1543210597-6717-1-git-send-email-chanho.min@lge.com> References: <1543210597-6717-1-git-send-email-chanho.min@lge.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/26 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 26 Nov 2018 06:36:37 +0100, Chanho Min wrote: > > 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 readlocks > and writer gets stuck for a long time if they are pinned to single cpu. > > The deadlock described in the previous commit is because the linux rwsem > queues like a FIFO. So, we might need non-FIFO writelock, not non-block one. > > My suggestion is that the writer gives reader a chance to be scheduled by using > the minimum msleep() instaed of spinning without blocking by writer. Also, > The *_nonblock may be changed to *_nonfifo appropriately to this concept. > In terms of performance, when trylock is failed, this minimum periodic msleep > will have the same performance as the tick-based schedule()/wake_up_q(). > > Suggested-by: Wonmin Jung > Signed-off-by: Chanho Min Hrm, converting unconditionally with msleep() looks too drastic. I guess you've hit this while not explicitly using the linked PCM streams, i.e. in the call of snd_pcm_unlink() at close, right? Then this can be worked around by checking the link before calling it. Could you check the patch below? thanks, Takashi --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2369,7 +2369,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) static void pcm_release_private(struct snd_pcm_substream *substream) { - snd_pcm_unlink(substream); + if (snd_pcm_stream_linked(substream)) + snd_pcm_unlink(substream); } void snd_pcm_release_substream(struct snd_pcm_substream *substream)