From patchwork Wed Jun 9 14:31:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 456853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E851C48BCF for ; Wed, 9 Jun 2021 14:33:53 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2427B613B8 for ; Wed, 9 Jun 2021 14:33:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2427B613B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 33B5B16CD; Wed, 9 Jun 2021 16:33:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 33B5B16CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1623249230; bh=C/tPoCEFLvjz1MT7R40JTrabOAMaWPK/Hv2tNLGNmqw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=F9PsqJCAeei/ogxuIUVxy0EjdwiBqkaB9O4yk42UubANFaqGcJiRO6j4tBJ81MqfW 9C7XlAPLzBi2n4y1GkQoIsBi64m8ElcLv4BgFAsxyac6EGnAIdLljIsYTcd6+27qAs A4gMCcE0y0TaVXa1KYFtavguP/rrl0tMjIzqOz4M= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B418FF802DF; Wed, 9 Jun 2021 16:32:09 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 642FDF800F4; Wed, 9 Jun 2021 16:32:07 +0200 (CEST) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8B826F80212 for ; Wed, 9 Jun 2021 16:31:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8B826F80212 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="cSEkUQVS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Lj9JLJbe" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 01C16964; Wed, 9 Jun 2021 10:31:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 09 Jun 2021 10:31:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=Pd+0x1YQKAU48 1gKY2aPEc+4cxFyhSgyLBETHaxL5Mw=; b=cSEkUQVS43R7wM9lz/ViI4G2qnXLI 5sgDwiHR436LdLAiqZRPrCtJnRE9uygZ6SS7QGwZWr4nRPbQgqRfdzLDqyr0AlVy DleZeXDtkgB0qpxa6K9QeBZZxCb1wXSeEfq1viQEWM9b/hAc0E3EdLIina+aVSzQ /ZOlap+7/qp0AIKAjqCh7b+snILwAW7RmOK/o2+HHmPSdaMc3Vtv9cEdzrtH/Zhn Pl5YQ8oMvOgmNuOPxaeC1NIqp7IthYtSh/+3ElG6sOrr93DAH7FBJc/5tdBWTTbC i9UB9Hz9GCTbA8r3qkMQrS3HlR5UnO3cuAfr+kTBfEM4xClBIJus4XZjg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Pd+0x1YQKAU481gKY2aPEc+4cxFyhSgyLBETHaxL5Mw=; b=Lj9JLJbe 9/qvm1GFRoAjD56YvTMtQ+RVItA+e6EQdZNZGW2JznzKa0jYp8Hb19fu2yhKdI8I Ra1RRsSCPz84TAYtgZdA8Yub2KD81mRLmNGQiZzxLAR7YEjpQnXv8tUv6njfpauW DOY2uRuIwoI0TrKlBkxDF50dpmvKuhFPbbvwtUgx7KDcofSoTcGD/Q6md575aaNI VSI8r8i/ukzg7BAoPs5NeZr27YedkC8BD3x8SwA6wO6bS4liP6Vs0v93FD8XKHIl kiGdH+vl0I3AuVLkT5ATtUnoiD8TMvmHhieoZHJ275nZztZGiVaRv91qyU88IB2F btY4iOBBsS/lcw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeduuddgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Jun 2021 10:31:54 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH v2 2/3] ALSA: firewire-lib: operate for period elapse event in process context Date: Wed, 9 Jun 2021 23:31:44 +0900 Message-Id: <20210609143145.146680-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210609143145.146680-1-o-takashi@sakamocchi.jp> References: <20210609143145.146680-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, clemens@ladisch.de X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" All of drivers in ALSA firewire stack processes two chances to process isochronous packets in any isochronous context; in software IRQ context for 1394 OHCI, and in process context of ALSA PCM application. In the process context, callbacks of .pointer and .ack are utilized. The callbacks are done by ALSA PCM core under acquiring lock of PCM substream, In design of ALSA PCM core, call of snd_pcm_period_elapsed() is used for drivers to awaken user processes from waiting for available frames. The function voluntarily acquires lock of PCM substream, therefore it is not called in the process context since it causes dead lock. As a workaround to avoid the dead lock, all of drivers in ALSA firewire stack uses workqueue to delegate the call. A variant of snd_pcm_period_elapsed() without lock acquisition can obsolete the workqueue. An extra care is needed for the callback of .pointer since it's called from snd_pcm_period_elapsed(). The isochronous context in Linux FireWire subsystem is safe mostly for nested call except in software IRQ context. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp-stream.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 150ee0b9e707..426a85b56cf1 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c @@ -613,8 +613,16 @@ static void update_pcm_pointers(struct amdtp_stream *s, // The program in user process should periodically check the status of intermediate // buffer associated to PCM substream to process PCM frames in the buffer, instead // of receiving notification of period elapsed by poll wait. - if (!pcm->runtime->no_period_wakeup) - queue_work(system_highpri_wq, &s->period_work); + if (!pcm->runtime->no_period_wakeup) { + if (in_interrupt()) { + // In software IRQ context for 1394 OHCI. + snd_pcm_period_elapsed(pcm); + } else { + // In process context of ALSA PCM application under acquired lock of + // PCM substream. + snd_pcm_period_elapsed_under_stream_lock(pcm); + } + } } } @@ -1740,22 +1748,11 @@ unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d, { struct amdtp_stream *irq_target = d->irq_target; + // Process isochronous packets queued till recent isochronous cycle to handle PCM frames. if (irq_target && amdtp_stream_running(irq_target)) { - // This function is called in software IRQ context of - // period_work or process context. - // - // When the software IRQ context was scheduled by software IRQ - // context of IT contexts, queued packets were already handled. - // Therefore, no need to flush the queue in buffer furthermore. - // - // When the process context reach here, some packets will be - // already queued in the buffer. These packets should be handled - // immediately to keep better granularity of PCM pointer. - // - // Later, the process context will sometimes schedules software - // IRQ context of the period_work. Then, no need to flush the - // queue by the same reason as described in the above - if (current_work() != &s->period_work) + // In software IRQ context, the call causes dead-lock to disable the tasklet + // synchronously. + if (!in_interrupt()) fw_iso_context_flush_completions(irq_target->context); } From patchwork Wed Jun 9 14:31:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 456852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D565C48BCF for ; Wed, 9 Jun 2021 14:34:35 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D1036139A for ; Wed, 9 Jun 2021 14:34:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D1036139A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 32E5116EC; Wed, 9 Jun 2021 16:33:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 32E5116EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1623249273; bh=l2Qtut3VbwZ6UM6Ttgeb7QGVD3my6oi3/TX10/O8b6o=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TK2oEjTa4F5BTOpmXZ4ZLhhYzqhl4n1A6Ncovf9xpcgxekpckEwz8sISUXalMsnL/ PZeL476bYCJ0pXo0mXaey71YeUXzj18NF5Xrrsj8M5m1w+fPv9R6TBh2GXG/DlcQ3c hZcnKcLmqkTPBq4sZ/T1UUq9Vwuhp/1JrjYNKIOY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B01E4F804CF; Wed, 9 Jun 2021 16:32:13 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 52DBDF8032B; Wed, 9 Jun 2021 16:32:12 +0200 (CEST) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 85493F8026C for ; Wed, 9 Jun 2021 16:32:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 85493F8026C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="bavGe0AN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kJf+KzwN" Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 68AC9157A; Wed, 9 Jun 2021 10:31:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 09 Jun 2021 10:31:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=oXvWhLbwOh/u0 n7UxIKnxJd7w7AA/kV4i4aL6hsnj80=; b=bavGe0ANPIMohJflK+QdkEna+SfEc UmmgnRVWKrS6VIiGd+DjrqATsBZYF0lZSmeA/ZVotLzZTSQY04RPYgtHgOyd1t63 8LiIT4ipXE2rZHe0MxQM9h0nCgWZgT4wlxEry3avAp0EQzoG9vbuqbjmJLmb9JdB +tkpQyQTW7k6LMzU+n1ljTEMKYD54DrQmJHw43MF2Td1N6mJor52kNlwUHNxjJDj CtHDBdtGU3cPEzvMaGYhhQwg0ssCJKJTwbbULlfhaaw0qsE0NeJxojjYkIc56ayw zH3aPdmac6E/J9gp2/e+fdIcfhAAqBk86zQuc52TpbkUf0Pbe+C+SrFuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=oXvWhLbwOh/u0n7UxIKnxJd7w7AA/kV4i4aL6hsnj80=; b=kJf+KzwN WpTl/v6zmteZCv3mzq+PQzLbQt4qLObUpECkSx61xx2bFQsE5TWdU6FZg0BeBkcA n6KUSqD7D3I5w9yMApQOYg3uJP+3S9mpu1tfL79EIMf1WU89x+G94Lj9MPqZL8PI biSC1+Do71Nm36XrH0YkgWAQyAMmuB2ed1ggOzhYxQQPUxSo1DaIOvfk3zM0rjny R4KfbCh8J8NHdSlFEMWEs7pLzQF9aHjdersQsBSDXJorO24/iaWXLuBY9RdLZgzo +VBuakrfx2avt5pT8DLa1GlmSB9hNaTBkpqYRA7o5TOhhssqHU2yfwAsvFPFiaet 9DSCznk8J6rMTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeduuddgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Jun 2021 10:31:56 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH v2 3/3] ALSA: firewire-lib: obsolete workqueue for period update Date: Wed, 9 Jun 2021 23:31:45 +0900 Message-Id: <20210609143145.146680-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210609143145.146680-1-o-takashi@sakamocchi.jp> References: <20210609143145.146680-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, clemens@ladisch.de X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The workqueue to notify PCM period elapse is not used anymore. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp-stream.c | 15 --------------- sound/firewire/amdtp-stream.h | 1 - 2 files changed, 16 deletions(-) diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 426a85b56cf1..1d9bc7b07df1 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c @@ -77,8 +77,6 @@ // overrun. Actual device can skip more, then this module stops the packet streaming. #define IR_JUMBO_PAYLOAD_MAX_SKIP_CYCLES 5 -static void pcm_period_work(struct work_struct *work); - /** * amdtp_stream_init - initialize an AMDTP stream structure * @s: the AMDTP stream to initialize @@ -107,7 +105,6 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, s->flags = flags; s->context = ERR_PTR(-1); mutex_init(&s->mutex); - INIT_WORK(&s->period_work, pcm_period_work); s->packet_index = 0; init_waitqueue_head(&s->ready_wait); @@ -346,7 +343,6 @@ EXPORT_SYMBOL(amdtp_stream_get_max_payload); */ void amdtp_stream_pcm_prepare(struct amdtp_stream *s) { - cancel_work_sync(&s->period_work); s->pcm_buffer_pointer = 0; s->pcm_period_pointer = 0; } @@ -626,16 +622,6 @@ static void update_pcm_pointers(struct amdtp_stream *s, } } -static void pcm_period_work(struct work_struct *work) -{ - struct amdtp_stream *s = container_of(work, struct amdtp_stream, - period_work); - struct snd_pcm_substream *pcm = READ_ONCE(s->pcm); - - if (pcm) - snd_pcm_period_elapsed(pcm); -} - static int queue_packet(struct amdtp_stream *s, struct fw_iso_packet *params, bool sched_irq) { @@ -1808,7 +1794,6 @@ static void amdtp_stream_stop(struct amdtp_stream *s) return; } - cancel_work_sync(&s->period_work); fw_iso_context_stop(s->context); fw_iso_context_destroy(s->context); s->context = ERR_PTR(-1); diff --git a/sound/firewire/amdtp-stream.h b/sound/firewire/amdtp-stream.h index b25592d5f6af..1f957c946c95 100644 --- a/sound/firewire/amdtp-stream.h +++ b/sound/firewire/amdtp-stream.h @@ -186,7 +186,6 @@ struct amdtp_stream { /* For a PCM substream processing. */ struct snd_pcm_substream *pcm; - struct work_struct period_work; snd_pcm_uframes_t pcm_buffer_pointer; unsigned int pcm_period_pointer;