From patchwork Sun Jun 6 09:18:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 455075 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=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 0705BC47096 for ; Sun, 6 Jun 2021 09:21:19 +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 2C2E6613F3 for ; Sun, 6 Jun 2021 09:21:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C2E6613F3 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 C5ECF16EE; Sun, 6 Jun 2021 11:20:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C5ECF16EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1622971276; bh=TXFh93KM8BIjnzQ3YP92bA9BGe/4PKC1Uz5OF4s/zK8=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=slECcQw4ELCStSYYUf0XV91dmKxR8we6n3urylWwrXEV/FsWJWSEEuvGlk4nj5uuN TA68Fvvuj4OYzPyjzcWeeAUjioS5NPG/CyrO2FWSJ9ZlpntzSLowEYF+PSFLjytCLq 1ayGPvq179Yxco4SjAlHGAWo8jtNii3Jh3sWliW0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 24D79F804C3; Sun, 6 Jun 2021 11:19:00 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1664CF804CA; Sun, 6 Jun 2021 11:18:59 +0200 (CEST) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 66F61F8019B for ; Sun, 6 Jun 2021 11:18:47 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 66F61F8019B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="n+Msfr1w"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="esYZjDMS" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C0BD95C01AC; Sun, 6 Jun 2021 05:18:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 06 Jun 2021 05:18:46 -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=HygvQ/JDpRWBo 3NYkfmt7Lt2hI1kyT5Aqf9aT3VLIiA=; b=n+Msfr1w1ZOATj0OM4ttVLW5fsgrI D5tcFVoBpOq9OTOkRKJNqbspuI0Fb25gZEg3Bx3VoftsHpwEDNYW5bqiBnPTgjAj Jj2YTTxvVI/bSwg0ENekdUMLwru4ch+XdBtFvWyhOQOOD2o92SvKtcsT+jJwJ3SD Ym78q5odU0JpjyVDUbzcJ9s8c1jnpVZN/vrJSdT4kx0BsMVFivBozogRhgb/6oV6 NGmTE+/0+OQofJehyxkF7TMBN4ly2UZuqPgwreVTfh9R7Q2eWZo2u94tMNARq/Qs akpJk3AaOzdi+gOryXKj9iKC7NKoNQj1ZtzYGaIDmP5bZtTxQMG40IFCQ== 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=HygvQ/JDpRWBo3NYkfmt7Lt2hI1kyT5Aqf9aT3VLIiA=; b=esYZjDMS BfFGVyKZQSGyCZsm1zpttgz2GrDN0Ts49aEFN5PFb5B65oz6oCLqvJUBsBxAMbMl hgJg0o4YSokV1ZC7UfIPIU4BceGBSXRFwYiJT4dBxuppokjN1OMk+ZgkjHRt0vq3 5O3HJHB3n4eLGhSM3cyMWPTt6KFBdH50+uCa+imIChPk94vhf+nTMBfHCLmOp3qL 4WZpuZ/H5G5RnzZ9kfZbyXVz8VPxIMHKI19qfx/rcUxGn0WxCkIg55jmwijAZEaT Li9H9kbhKk9aC58hGLVSzR0HQl45lb/dmKmsdyMOyelKZvTN/21do4b2EFcho6g9 J7D91KKPWhoX7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedthedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Jun 2021 05:18:45 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [RFC][PATCH 1/3] ALSA: pcm: add snd_pcm_period_elapsed() variant without acquiring lock of PCM substream Date: Sun, 6 Jun 2021 18:18:36 +0900 Message-Id: <20210606091838.80812-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210606091838.80812-1-o-takashi@sakamocchi.jp> References: <20210606091838.80812-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 queue event 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. It 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_without_lock(), for drivers to queue the event in the process context. --- include/sound/pcm.h | 53 +++++++++++++++++++++++++++++++++++++++++++- sound/core/pcm_lib.c | 25 ++++----------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 2e1200d17d0c..a4eaa48584da 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1066,7 +1067,57 @@ 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(struct snd_pcm_substream *substream); + +void __snd_pcm_period_elapsed(struct snd_pcm_substream *substream); + +/** + * snd_pcm_period_elapsed - update the pcm status for the next period + * @substream: the pcm substream instance + * + * This function is called when the batch of PCM frames as the same as period of PCM buffer are + * processed in audio data transmission. It's typically called by any type of IRQ handler when + * hardware IRQ occurs to notify the event. It acquires lock of PCM substream, then 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: + * + * - .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. + * + * Even if more than one periods have elapsed since the last call, you have to call this only once. + */ +static inline 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(substream); + snd_pcm_stream_unlock_irqrestore(substream, flags); +} + +/** + * snd_pcm_period_elapsed_without_lock() - update the pcm status for the next period without + * acquiring lock of PCM substream. + * @substream: the pcm substream instance + * + * This function is variant of ``snd_pcm_period_elapsed()`` without voluntarily acquiring lock of + * PCM substream. It's intended to use for the case that PCM driver operates PCM frames under + * acquiring lock of PCM substream; e.g. in callback of any operation of &snd_pcm_ops in process + * context, then queueing period wakeup event. + */ +static inline void snd_pcm_period_elapsed_without_lock(struct snd_pcm_substream *substream) +{ + if (snd_BUG_ON(!substream)) + return; + + __snd_pcm_period_elapsed(substream); +} + snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream, void *buf, bool interleaved, snd_pcm_uframes_t frames, bool in_kernel); diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index b7e3d8f44511..33ad4ab0ec3a 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1777,28 +1777,13 @@ 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 - * - * 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. - * - * Even if more than one periods have elapsed since the last call, you - * have to call this only once. - */ -void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) +// The pointer to PCM substream should not be NULL as precondition. +void __snd_pcm_period_elapsed(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,10 +1796,8 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) #endif _end: kill_fasync(&runtime->fasync, SIGIO, POLL_IN); - _unlock: - snd_pcm_stream_unlock_irqrestore(substream, flags); } -EXPORT_SYMBOL(snd_pcm_period_elapsed); +EXPORT_SYMBOL(__snd_pcm_period_elapsed); /* * Wait until avail_min data becomes available From patchwork Sun Jun 6 09:18:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 455076 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=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 81FE4C47096 for ; Sun, 6 Jun 2021 09:20:38 +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 C3B986135A for ; Sun, 6 Jun 2021 09:20:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3B986135A 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 5FD6716CC; Sun, 6 Jun 2021 11:19:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5FD6716CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1622971236; bh=65MAz9ZdSmbHVo4X/M6JQjEOwol9B9xmE9zYIOT6mjo=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BdunTrTmm9v2OD1bEuHO1jtHa/uJXIWApMKYJsLldggx9TOKymfZOm4QMbQDBRtkT vwvnhaxu/QvozJUc2DG01yYizp13N/htHb23o+L+C03Jc8iZZZqOUxIj7R2+vZ2DMX CwLQgOftnc7B9arv1bC3LGlXM0D6mUExZscmKOqQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7BA05F804AC; Sun, 6 Jun 2021 11:18:56 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3C640F80256; Sun, 6 Jun 2021 11:18:54 +0200 (CEST) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id F03C3F800C8 for ; Sun, 6 Jun 2021 11:18:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F03C3F800C8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="eL4f8MDS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MyNp7hx5" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2D1B25C01B3; Sun, 6 Jun 2021 05:18:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 06 Jun 2021 05:18:48 -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=mfaXpaM4c4ID3 Ic3X/jCI/AfCYY9GDYh3IAuyWUA+co=; b=eL4f8MDSEvw/OkOd2SBLuWsLAe7qL hzY9Edknw+HVX6zRa6gGpUja0uvdFuS0660HKJvngKVm9GbZVjo20CVVIH1c9GDR FFA4P5oN3CuX+9AqE/EWNI6dKSu3EJt91/WfoTW3np3p2KiFTT6zMt7RMzPNiEVB 12jrC+7/h+0efu41pryoyTTE1p+Z7J76BmS2zMK/Jm+vosbn6j2LEuzI7BD197ud ZitVfM1KDUMCWVQt0lxUPs/cpwtEhxjQIubT2jA/U0HqDS7I+ey9Q+EdYWf9fPJA k6vTzimEQ2A/EkRUeA9phTdWJASEE0U0ZOMuGKsteaYSF7wczpLxe2dlw== 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=mfaXpaM4c4ID3Ic3X/jCI/AfCYY9GDYh3IAuyWUA+co=; b=MyNp7hx5 uIBg1HmXohuXSQo15zHbYWHMkCsmA+DvoDRyh7p4EKRWQdvm6J4P0cLDJQjfioCq Pc8QOXtUqX5z9SKjbj1Mg8y1nf1JmJGxwPRc1Hilh0UAt6D3ZW5oCFYLZk+Hs94h netf/rJ/qelK/svgJHVkvDWwf4r0iE+uSC2QtikHBF3hSYMPRhShltlhLK5uLmuf zyOpd/UeTpnX0p83A3dLf5HxfI2GufRNHgg2LB5xAVAB0kWm+6kX6Kd/wmSrwnbg /+6oci/ee5O7xZ6ZKag4dM6unAl8H5B9BcBdzJnl7y0gYP5YXkJ8Bm7GOnN025Gj dIYRIPpM++qB/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedthedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 6 Jun 2021 05:18:46 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [RFC][PATCH 2/3] ALSA: firewire-lib: queue event of period elapse in process context Date: Sun, 6 Jun 2021 18:18:37 +0900 Message-Id: <20210606091838.80812-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210606091838.80812-1-o-takashi@sakamocchi.jp> References: <20210606091838.80812-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. --- 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..b39328eab67e 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 acquiring lock + // of PCM substream. + snd_pcm_period_elapsed_without_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); }