Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1810902imu; Wed, 28 Nov 2018 15:50:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVEpQAQQdV+TyaMzXHofE+paZzIN466ZLG4A4+8pJry0yeu9wkRCuNu1L0xa0NYHCcc/H/ X-Received: by 2002:a17:902:4c08:: with SMTP id a8mr39461609ple.74.1543449022721; Wed, 28 Nov 2018 15:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543449022; cv=none; d=google.com; s=arc-20160816; b=wr6VaFCpyTOUpE4/VGr71MAsPB9QnveveOgeXHvvNVHMbIuz0txVqxsVmpoXb23xfv Bi6nhN0f2PT6PXeXb8HWuAPxJMsl78QZyrey4f7ufmd6V2foZXD2+T9tC26JWGgxl2Ag zyqSYzFFo27cfPAtdkCcFj458leI8ayEPOrF1fcmCM6k6G7waQqW0rvrnTJ0JJNMLx0S kREVV8a9P/tjDdbMWnomOXB5q6XiF5OJYDG4NL6o51zcG57snL1ieuKU5AzxJsf68ZuQ ovh5xSQjK+TpqOj+/SBtCRSq6YMAXgssKyRN+LdxRA13cmChUzh+DqlELa68Y9GyEkpR dgEQ== 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=SljaGGTIq9MOwqO4cRcVtvo447nB4erqIRyDjknRmaA=; b=zK+op8UBb1vX9nm1IdEeuYIClqv1ix6gSCL76JpEDJc9IE8tyVQm0yt/zVkD231okP ZLLbx4hnVbuahytgXUmzlNYcB1/HyS6dy42C9STIR/fPDw9FMStjn578dMJE5yf0eYmW lwSUlCm/tyNUzkFDP/VPoSISnqD34Mffrm2rwqnR/PzhkrDATE8+wqzy/cX4XS9TjcP5 k6GSEduBoG12A2blU/Ol0pjkS1mg1Xtzy+GRIY4ksqU56iFtm6GVtB2sYyHb4zjP6r27 FpVgS3UTIvQBC6biAPkDWiI1ulG/noq/3JoyvJhvsTzA7P+LFsSJtil09xhKfgSLUVnV 2H1Q== 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 m7si65041pgi.547.2018.11.28.15.50.08; Wed, 28 Nov 2018 15:50:22 -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 S1726998AbeK2Kvp (ORCPT + 99 others); Thu, 29 Nov 2018 05:51:45 -0500 Received: from lgeamrelo12.lge.com ([156.147.23.52]:40692 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726382AbeK2Kvo (ORCPT ); Thu, 29 Nov 2018 05:51:44 -0500 Received: from unknown (HELO lgeamrelo02.lge.com) (156.147.1.126) by 156.147.23.52 with ESMTP; 29 Nov 2018 08:48:21 +0900 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: chanho.min@lge.com Received: from unknown (HELO WMRRD11NA101CK) (10.178.32.163) by 156.147.1.126 with ESMTP; 29 Nov 2018 08:48:20 +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> <1aaf01d486ab$8017a5b0$8046f110$@lge.com> In-Reply-To: Subject: RE: [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() Date: Thu, 29 Nov 2018 08:48:20 +0900 Message-ID: <046401d48774$d7d1e440$8775acc0$@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/AHddrpxAUNqWssDIGjXzqKoJSuQ 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. > > Right, but applying msleep(1) unconditionally is really bad. > > > > 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. > > Then I'm sure that my patch papers over. Thanks, Plz let me know when the patch is merged. > > > But, If the linked PCM is enabled, Can snd_pcm_unlink() be called? > > This also seems to be a workaround. > > Yes, for the linked streams, something else is needed *in addition*. > > The original fix with busy loop also assumed that this code path (via > snd_pcm_link() and snd_pcm_unlink()) is the rare occasion, and it didn't > consider that it were called for regular use cases. So the fix to make > things just works for regular use cases without any artifact must be > implemented in the first place. The fix for the linked streams comes at > next. It might be like your msleep() change as a workaround, but in > anyway it's far less urgency. msleep is worst, but If it is harmless, can I apply my patch to the private tree temporarily until your next fix comes? We may use the linked streams in the near future. It makes our product unstable. It's urgency for us. How is your opinion? Thanks Chanho