Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp876408imu; Wed, 28 Nov 2018 00:38:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/UwoNDOEsthe9FXtT5m211iNs/7DbBFJP3/VdBg3tcgptLZ4/P+PrjDPrGqKIzPGp0xcdJQ X-Received: by 2002:a17:902:6b83:: with SMTP id p3mr16233879plk.118.1543394320283; Wed, 28 Nov 2018 00:38:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543394320; cv=none; d=google.com; s=arc-20160816; b=sV+EKyHvBz1YMWocSgW49w4DDMMzjeafiy+CYkEl/n2Bh1Ag6f7qkLgS+0JEFzlbEW lPi0ZPnxJLWwqBr5yJTcIXPniXh0UaD7J5IPjkkc5uA9whsuanEuiXvtbiBDmGN/mmGV E/6zCan2EYvLgnlTTXPIRe4gkyjEGCTiwBrxe7+7ZdzcqItPStoxjcb2W0wiKJ8rGzwQ g0oXPqwza7zLBZZ1t+sl0KSsrM+U1wkpW0MfInXVCjFzQgFSpy7YtxQnHJkXxt0VeTAw COHV6yTP2X6bAEfLQTiPlxBKcnoA+opcqjHHm//mEii07tjL5uhZa5okdQtt3zdawvk6 ul1A== 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=zhbaw2UoOPBJirj5Y7/loAJytU4nXzVM7Smbkzwm+1M=; b=MMZWKAZg6q8XMmmmTbVuENiJ81sygeUAd0rm38eaB1ULx0ZTQXrflLXCF1rWNyBYo2 BJieR5IrtGvhnJcYsOrlV5CzE3hmgTfvkf7MFs+c+5Y6NoBmEPn76Ut5Yyo7QaNSPx8e 3jchoYRXtzDW2qrlOFlAjN/34OREIQNRUMFbHknBdJb/bIJTtux3KSajeJ3P8b8TfnfX NMkRtjh2Ym7u3CW1njXNuOgZV99DmK6C29DGwR587zuJ+8rd7EnmlvKAOO0cmfzANkWF 72goh29uFHEbruMUm0wt463okwJaHZqHtHrS8F7/WUWl917Sxx4sPZ/eqfDgmxw6RfVm GLJg== 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 u8si6498112pgl.25.2018.11.28.00.38.24; Wed, 28 Nov 2018 00:38:40 -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 S1727736AbeK1Tii (ORCPT + 99 others); Wed, 28 Nov 2018 14:38:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:42484 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727476AbeK1Tii (ORCPT ); Wed, 28 Nov 2018 14:38:38 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9C87ADFF; Wed, 28 Nov 2018 08:37:47 +0000 (UTC) Date: Wed, 28 Nov 2018 09:37:47 +0100 Message-ID: From: Takashi Iwai To: "Chanho Min" Cc: "'Jaroslav Kysela'" , "'Takashi Iwai'" , "'Vinod Koul'" , "'Daniel Mentz'" , , , "'Seungho Park'" , "'Jongsung Kim'" , "'Wonmin Jung'" , "'Jaehyun Kim'" , "'Hyonwoo Park'" Subject: Re: [PATCH] ALSA: pcm: Fix starvation on down_write_nonblock() In-Reply-To: <1aaf01d486ab$8017a5b0$8046f110$@lge.com> References: <1543210597-6717-1-git-send-email-chanho.min@lge.com> <1aaf01d486ab$8017a5b0$8046f110$@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 Wed, 28 Nov 2018 00:47:03 +0100, Chanho Min wrote: > > > 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. > 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. Takashi