Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp481807imu; Tue, 27 Nov 2018 15:48:01 -0800 (PST) X-Google-Smtp-Source: AJdET5eVhzl/3BLboW8vEkdtBfkzl8FmNrm4APQV0rAgXB7nRuJhDVX5vvxSWqFTXuYqUZa9WEL8 X-Received: by 2002:aa7:868f:: with SMTP id d15mr34626033pfo.225.1543362481790; Tue, 27 Nov 2018 15:48:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543362481; cv=none; d=google.com; s=arc-20160816; b=nKA/daPT1XYxMDma3jNlzj2NGW0OlYXoutO3+tQF6jPtfz5JnC557fESoZ2zEMiYVY DUjTQ28Hk51G7o9TTleAylDgp1ohCp9Wm+5PsSY/S7kAFgR2d9/6aJVOdSC5wBOQTx5A GZnhN8DESkyuwu+TohYRhA68dtX5Mtrq8cM83ynFRkSJgdsHVnAb7tXsk1GEZNfvCpQv 8E+0LO/rhcMYV1DVUNGUfsfYyYDwhY0rHj0FxNQTZtuHhpss8Rlt/H0pRMi/RPOPyZhO gWFds3q/Vj4rXWOklM51nhI5EDibkzY/vLnswb4ecb8XhhnTrIOrs+5n1GCZHKw+EP3M Yx1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:thread-index :content-transfer-encoding:mime-version:message-id:date:subject :in-reply-to:references:cc:to:from; bh=zomPGOiNUSy1iVrwuWt3yYGG9WZwbu4nQbVsKVFHLno=; b=DnnVS0dIJiABlsnj4RSb7CmijxknOwKo0C55sS40ySMahhh7XpbHfRoZZf5l6E/65y m6AFsS/ydbQAMO1883012Du48Pr3fzx15Tl8H1r5u/S8eeZYBqda3jK/T11Kgig/6dej LPcpBfrliOYu6DA3xv7v+xn/fIzESKhDPVb6FT6+V2SPhv9kuE1hgAADTzFGs9OZ3ESJ BA46RHkHy4vc7/v69mLHvQIJJiZHV/+fkq+69wO3xyhJC21ukIBFYc4PwBoRs+cwhhu0 RLpdHz5BI7KDltUCB3m4mhkP9CPf4G0wsAZTme9XQXDob5+28XSEr0gxC6F19gB6lmf+ j97Q== 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 q5si4568754pgk.46.2018.11.27.15.47.45; Tue, 27 Nov 2018 15:48:01 -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 S1726607AbeK1Kqk (ORCPT + 99 others); Wed, 28 Nov 2018 05:46:40 -0500 Received: from lgeamrelo13.lge.com ([156.147.23.53]:34397 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726345AbeK1Kqk (ORCPT ); Wed, 28 Nov 2018 05:46:40 -0500 Received: from unknown (HELO lgemrelse7q.lge.com) (156.147.1.151) by 156.147.23.53 with ESMTP; 28 Nov 2018 08:47:05 +0900 X-Original-SENDERIP: 156.147.1.151 X-Original-MAILFROM: chanho.min@lge.com Received: from unknown (HELO WMRRD11NA101CK) (10.178.32.163) by 156.147.1.151 with ESMTP; 28 Nov 2018 08:47:04 +0900 X-Original-SENDERIP: 10.178.32.163 X-Original-MAILFROM: chanho.min@lge.com From: "Chanho Min" To: "'Takashi Iwai'" Cc: "'Jaroslav Kysela'" , "'Takashi Iwai'" , "'Vinod Koul'" , "'Daniel Mentz'" , , , "'Seungho Park'" , "'Jongsung Kim'" , "'Wonmin Jung'" , "'Jaehyun Kim'" , "'Hyonwoo Park'" References: <1543210597-6717-1-git-send-email-chanho.min@lge.com> In-Reply-To: Subject: RE: [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() Date: Wed, 28 Nov 2018 08:47:03 +0900 Message-ID: <1aaf01d486ab$8017a5b0$8046f110$@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQMaVnIxoQzG0mth21qziKuhS7dD/AHddrpxosmyX+A= Content-Language: ko 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. Yes, it looks drastic. But, IMHO, I can't say busy-spin is not non-drastic. To fix the root cause, We may need another rwsem that does not work as a FIFO. > > 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? More testing is needed, but it seems to be fixed by your patch. We may not use the linked PCM. But, If the linked PCM is enabled, Can snd_pcm_unlink() be called? This also seems to be a workaround. > > > 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)