From patchwork Wed Jun 9 01:22:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 12308531 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 CCA91C48BCF for ; Wed, 9 Jun 2021 01:24:52 +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 0F772610C7 for ; Wed, 9 Jun 2021 01:24:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F772610C7 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 7B16A16DA; Wed, 9 Jun 2021 03:24:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7B16A16DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1623201890; bh=00x0CN41ahaYwxLs8M3SupV4QQ6UTSBeDrV3h99miyY=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=e6Ys330lWj8GlM30Erm2OuCoYpZiQulxk9G/C1Ua0GD3rGbXG8xlfzrfnrYZaNdeU GdpydXqnnqWuZEtZm2zT3mGuW0vldjAUJhpy9AO1KPu5u1rVqiC6/IZebhFXb1Sizo azW3/AC89dZuzt7hzvQFWLsf+vE5KAiczEkMkUeI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id EE3E1F804B2; Wed, 9 Jun 2021 03:23:12 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 881FEF80256; Wed, 9 Jun 2021 03:23:05 +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 943CBF800FD for ; Wed, 9 Jun 2021 03:22:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 943CBF800FD Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="NsO9sjL7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wkOBlw6Z" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 10F01731; Tue, 8 Jun 2021 21:22:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 08 Jun 2021 21:22:53 -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=drUWGIv84SvOS UrGsi1C8/xe6FEjNTi4/cXmYoY+wYI=; b=NsO9sjL7KcItZPIhJV7nfWVJ74/8m L4ROgYd/IIZkH4mTVDlF4A6R6L4VxeqCTj9E2DMhHTzU8m2M5hq8L9jTggQDW4Lq 6OYe/x9mz9lLSq1OuAEy/lgGuAfywevHX+JvOFRMd/sE9sULMSZlQQEYKosWTTlQ Lq7hMq3yVMwKa41WzWfwyQswukYkjrDn3wwF/ZQlr2dBz8wq4RX47/avVWIGubu4 cvNqPDMIqgD00fu4PHhIrzT9knOOE7lOh2z56tyZ9IiH5ZySlCXrGNIZvTHUN7gO p+sTcSmGjLN2gkDjMu9/al68p3AQro+rhk9iZwo6NExTWl9zN1DYL2GjA== 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=drUWGIv84SvOSUrGsi1C8/xe6FEjNTi4/cXmYoY+wYI=; b=wkOBlw6Z mHXQh3DZwm64id4qZuxCpE2vICENId4X9qqsOgu2rEk3/Aulm8mNGyAXzA0fLklE tpXKk3K00umAoPcZrlkpZ1mMu8wlcJLVrl/xVCDUyiJOZYRU5JYDA1X7dMpYm6ss 8dDfihpZnWvrGCPC7w6Kh+UJi4XslkTMGwXs53SlHfI+R0BPIUqORjlClk8UONu8 Rp+dbasg57Q1ZZo6qx0tnNHYVEmtAC4NwSKRNNDkcVq73KbcB2l04BlJYStEOeVy Ysi2OvZr60S+L0yuqd9t6IUcMsoayQsF/26ScMlG7X+uPlD9wb70AJhNPhS5Ioo9 eKiu2Y6/HIQ7Vg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedutddgfeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Jun 2021 21:22:50 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH 1/3] ALSA: pcm: add snd_pcm_period_elapsed() variant without acquiring lock of PCM substream Date: Wed, 9 Jun 2021 10:22:42 +0900 Message-Id: <20210609012244.24296-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210609012244.24296-1-o-takashi@sakamocchi.jp> References: <20210609012244.24296-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" Current implementation of ALSA PCM core has a kernel API, snd_pcm_period_elapsed(), for drivers to awaken processes from waiting for available frames. The function voluntarily acquires lock of PCM substream, therefore it is not called in process context for any PCM operation since the lock is already acquired. The call in process context is convenient for packet-oriented driver, at least for drivers to audio and music unit in IEEE 1394 bus. The drivers are allowed by Linux FireWire subsystem to process isochronous packets queued till recent isochronous cycle in process context in any time. This commit adds snd_pcm_period_elapsed() variant, snd_pcm_period_elapsed_under_stream_lock(), for drivers to queue the event in the process context. Signed-off-by: Takashi Sakamoto --- include/sound/pcm.h | 1 + sound/core/pcm_lib.c | 68 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2e1200d17d0c..bae90696cd06 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -1066,6 +1066,7 @@ void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, void snd_pcm_set_sync(struct snd_pcm_substream *substream); int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); +void snd_pcm_period_elapsed_under_stream_lock(struct snd_pcm_substream *substream); void snd_pcm_period_elapsed(struct snd_pcm_substream *substream); snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream, void *buf, bool interleaved, diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index b7e3d8f44511..6f01b0c805ca 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1778,27 +1778,40 @@ int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream, EXPORT_SYMBOL(snd_pcm_lib_ioctl); /** - * snd_pcm_period_elapsed - update the pcm status for the next period - * @substream: the pcm substream instance + * snd_pcm_period_elapsed_under_stream_lock() - update the status of runtime for the next period + * under acquired lock of PCM substream. + * @substream: the instance of pcm substream. + * + * The function is called when the batch of audio data frames as the same size as the period of + * buffer is already processed in audio data transmission. + * + * The call of function updates the status of runtime with the latest position of audio data + * transmission, checks overrun and underrun over buffer, awaken user processes from waiting for + * available audio data frames, sampling audio timestamp, and performs stop or drain the PCM + * substream according to configured threshold. + * + * The function is intended to use for the case that PCM driver operates audio data frames under + * acquired lock of PCM substream; e.g. in callback of any operation of &snd_pcm_ops in process + * context. In any interrupt context, it's preferable to use ``snd_pcm_period_elapsed()`` instead + * since lock of PCM substream should be acquired in advance. * - * This function is called from the interrupt handler when the - * PCM has processed the period size. It will update the current - * pointer, wake up sleepers, etc. + * Developer should pay enough attention that some callbacks in &snd_pcm_ops are done by the call of + * function: * - * Even if more than one periods have elapsed since the last call, you - * have to call this only once. + * - .pointer - to retrieve current position of audio data transmission by frame count or XRUN state. + * - .trigger - with SNDRV_PCM_TRIGGER_STOP at XRUN or DRAINING state. + * - .get_time_info - to retrieve audio time stamp if needed. + * + * Even if more than one periods have elapsed since the last call, you have to call this only once. + * + * Context: Any context under acquired lock of PCM substream. This function may not sleep. */ -void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) +void snd_pcm_period_elapsed_under_stream_lock(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; - unsigned long flags; - - if (snd_BUG_ON(!substream)) - return; - snd_pcm_stream_lock_irqsave(substream, flags); if (PCM_RUNTIME_CHECK(substream)) - goto _unlock; + return; runtime = substream->runtime; if (!snd_pcm_running(substream) || @@ -1811,7 +1824,32 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) #endif _end: kill_fasync(&runtime->fasync, SIGIO, POLL_IN); - _unlock: +} +EXPORT_SYMBOL(snd_pcm_period_elapsed_under_stream_lock); + +/** + * snd_pcm_period_elapsed() - update the status of runtime for the next period by acquiring lock of + * PCM substream. + * @substream: the instance of PCM substream. + * + * The function is mostly similar to ``snd_pcm_period_elapsed_under_stream_lock()`` except for + * acquiring lock of PCM substream voluntarily. + * + * It's typically called by any type of IRQ handler when hardware IRQ occurs to notify event that + * the batch of audio data frames as the same size as the period of buffer is already processed in + * audio data transmission. + * + * Context: Interrupt context without acquired lock of PCM substream. This function may not sleep. + */ +void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) +{ + unsigned long flags; + + if (snd_BUG_ON(!substream)) + return; + + snd_pcm_stream_lock_irqsave(substream, flags); + snd_pcm_period_elapsed_under_stream_lock(substream); snd_pcm_stream_unlock_irqrestore(substream, flags); } EXPORT_SYMBOL(snd_pcm_period_elapsed); From patchwork Wed Jun 9 01:22:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 12308533 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 7D4BEC4743D for ; Wed, 9 Jun 2021 01:25:01 +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 7B59660FF0 for ; Wed, 9 Jun 2021 01:25:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B59660FF0 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 1BE4716E1; Wed, 9 Jun 2021 03:24:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1BE4716E1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1623201899; bh=+wOH7ysXvSX9e3eVeuuM0umACJu138L1Otu7HhQXXQA=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=h7joC7f/7EqGG2XQA/avNmJCYzHeyrr+72u0UdomKrOenFIrY/Ur42HVF3dwPNM9P 9j2PWMd2Z9KCOQSYIlFUQJayxV93bOQHi9rzcMyp1hs/kP7w/5jLFIo1+3D6lkJcHT XKmZ6s3Xb1Rty3sPtoCXeRK4aRMiGTmkd3+GMJRQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9FF74F804CB; Wed, 9 Jun 2021 03:23:13 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 264F0F804AD; Wed, 9 Jun 2021 03:23:08 +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 2D0B6F80218 for ; Wed, 9 Jun 2021 03:22:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2D0B6F80218 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="csPjiAAg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iQsuSXbw" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 779802084; Tue, 8 Jun 2021 21:22:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 08 Jun 2021 21:22: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=14m1Hwu1CXt0X +QjGXAt7PTOivEsvg0ce9HLAZhlOG8=; b=csPjiAAgvNjI2tR+8E8UBXn38REw8 A1Esdk99eLq65SDIgwQHLzOA1T9AXIvaDXXjnGtyhlp5VCu+s5/wDuV+Sc2qexqD vnB9Nxm2+pADUlD66qnu2UaqbYE5C0VTO9t5oMquKg7jFv1PWkjPmVlPRIqHd9ab f76EWJmMVGQsU+J/crMmjQcgbvgqLZl0XD/OVrlmN2BmvyjttrM1GbF3TbqWLyor nj2iUNsF0xH3LDH9hl5aSFCKi6eryoFXsxOrr3HseGnsf7LYjYeD+gxrr9RBAHt0 yHLKufX99NyPtzYILHplYkr0Jo6Xb2puuvVTQX7bS5KoDOSYiloohfk6Q== 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=14m1Hwu1CXt0X+QjGXAt7PTOivEsvg0ce9HLAZhlOG8=; b=iQsuSXbw vnVEyIFHleyvf1WaNQW2vuSiv4o5FNd319m+mGP0OftrMqAtNJce3PGND3zxAHyV 2SUQZtnJCybdA78hm9fgs7hQcAzl9+HVke66aNlbydq10tV3lhVFaw+J4s23gw7x JTJXZZEP8KKO74nXlyELsIQmz4cIMn8m7cZffI0pg6DTns0hPS0Y/hngfN6+fUQd G9+os/icDW1EQWQ+eVqlGblMbmVwZ+hl8IOwFoiWfZAUz3ecBRWgORHZQP6+ALfd p6FM1x6a17qRqP+GoSnQcWJVaxm2jmC3GwjQNl1QlSbJbKasqc+Kb0pRSkNq52NZ RsmtpTuFM4g9gw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedutddgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Jun 2021 21:22:53 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH 2/3] ALSA: firewire-lib: operate for period elapse event in process context Date: Wed, 9 Jun 2021 10:22:43 +0900 Message-Id: <20210609012244.24296-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210609012244.24296-1-o-takashi@sakamocchi.jp> References: <20210609012244.24296-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 of 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 01:22: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: 12308535 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 5E827C48BCD for ; Wed, 9 Jun 2021 01:25:32 +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 782466108D for ; Wed, 9 Jun 2021 01:25:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 782466108D 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 156A816D8; Wed, 9 Jun 2021 03:24:40 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 156A816D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1623201930; 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=gp2Wnzr7qMIDx8mZaiK9qKcG16jA2t33NWG8LeJVZJfvOChPA7awQbo6NKBz06p1i o9+sm8jCk0lKFefOI47SYx6d4QR0mDoRG5u1joRimwOxbhc2InYsNtugd8V00R3f+H ZhdEG+4eaMQe8bFoGWr+QdUDYaRZtH6Zq/KDlgt4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8D14DF804D1; Wed, 9 Jun 2021 03:23:14 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E50A1F80218; Wed, 9 Jun 2021 03:23:09 +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 30AE0F801EC for ; Wed, 9 Jun 2021 03:23:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 30AE0F801EC Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="OpDzqIWk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oVjB6iDi" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 820D62092; Tue, 8 Jun 2021 21:22:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 08 Jun 2021 21:22: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=OpDzqIWkb0lnvOUZW4VJMJ3a4x48G 8r3CI8hQN6dTf/2GlM/r3PkLflgwPXw7nPbEKix45hZkjKE1CBfRCXp6LjQzHuCG NdAXWLdwyGpCjMk9bLZoU2I7D0BmieGuYo4WN490t8rSiStE+OAnhWJJVk0KIqwG i0UP8qPpuWCOQXDiha6ez+pT4up73TO4yrLb4OfKwlLT/30joBwd4VCVC1xZZrJe r2R/SXWIkb5LYUq9XanM5qS4G+B7Qe31fRXBz4ETS0OYipLiqD83GCf3YY3Dp2gd f6opRVuxPq1wlpLHqeJ+mukkjA5XaQVWdkYdDyLxGGvXxgNZNWHVM7uWQ== 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=oVjB6iDi ry4ny2UNxl/oG6IwPDd4yHL9MwrFzOb+bDUFP0OG9060IKawPwL510WfF5S3TTuF EEtRThZvvgPjmENQAx4YnckijfS1IytgyNVKHLKp/e5+d0ni7CmlEECE1qGCIf+C Kr3AxFbuxIF+RmkZipEmNGp6QCnLr1dPlZwLqrt6aqd3Jy6WAU/FMEbq1xbhUU8g JqRxgTDl+PL/9fUn13T87YIb3EmzBVHxz4qIcdbim8dSQ5wW75NprC4EmNXIz3ji JBwkvtsGpwJcaqROdzGERE6AMKs7KFAqVTuhAT8C3hhOaRb2VbOkAKl10mP9P7f1 PkKPLKJzCvpp1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedutddgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Jun 2021 21:22:57 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH 3/3] ALSA: firewire-lib: obsolete workqueue for period update Date: Wed, 9 Jun 2021 10:22:44 +0900 Message-Id: <20210609012244.24296-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210609012244.24296-1-o-takashi@sakamocchi.jp> References: <20210609012244.24296-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;