From patchwork Sat Jan 7 02:32:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 640091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 454A6C5479D for ; Sat, 7 Jan 2023 02:34:39 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 44C764583; Sat, 7 Jan 2023 03:33:47 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 44C764583 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1673058877; bh=1x4bT1lkLE907Zo+qa/khNYtIeEFNn1tC1+F8pvAfaw=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=K9ju/SMt53TgFinRhbSuPdSoVj2coXNCK5OKER6Oh4Oi15+MeuWka6IAWvlEwX/A6 wMS19Y7ALc3DEoOFX9Vl+f5Z6tMR6exMDhwlOC5K0BCzGGjzEv5xed0YyeUuUSaY77 uSqbzSvu1ym9d3OKcdXWEa4vtcWPURd4IzlJ1VwM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AD224F80553; Sat, 7 Jan 2023 03:32:37 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 385D8F804CB; Sat, 7 Jan 2023 03:32:36 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C0F00F8032D for ; Sat, 7 Jan 2023 03:32:30 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C0F00F8032D Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.a=rsa-sha256 header.s=fm2 header.b=p7Xe3+V9; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=bdXnuB1t Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 48542320091E; Fri, 6 Jan 2023 21:32:29 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 06 Jan 2023 21:32:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1673058748; x= 1673145148; bh=6PeTBmkUJc3MWBcNdJSpibsbGmpVsW/F2mHx6yIK8I0=; b=p 7Xe3+V96Er5Hzc0QgIwWdOYmy5I06tN47koQlq/zBN3uw+rNTzYvUCHOh3hDobqV YIKWxvVLAT5DMIUcAJQePH67WF1zK77YbzMb0EH1ELQHrAaRMgntd47wnRftEIMm 2insRKMFBPubjlempPzjiO4+W/nl8PPQyFRQBnBTu/V7CNJgsVk+yShb0Esi/Zbo 3YGyKKjkclnjvG11RgcoCiMhyz//thywaQjI92NsetJlIQ7LcS2r4ah2yQZisP10 pJOl8FBC6EDXm7446p7np1RFPrgZOwgnJ0W5oDbVKs3k3Z4aDsrFDIrclcLdpBaN hswtz5j0qaXlU59E+PqZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1673058748; x=1673145148; bh=6PeTBmkUJc3MW BcNdJSpibsbGmpVsW/F2mHx6yIK8I0=; b=bdXnuB1tH75YNbYBST++MFPMKhVS5 WCMOFl1oX9bGoyVWt1r8NskRPmi+o6R6DQIRGkO5bMzEnqa6N/910wQ7PCm2A1Wu zcwNG2b47p08jsxYvo8EolV5HNhtVSJqE4pCVS9Sluo8e7KGxf57F/lzf7wzZWh+ HXArTMlWUvuwLk5XGzfDBTjguQLG4260pwXPMzpGQOV7r5VYs6s2juzFOSDLifW7 tQ9qX5Z8uoanE+J881H7RyA/iS+LXyRu6g26rO2x9L7xyEMF6+IDRJD7mgwQxfJh lSQFJuTRGj/rwE5Pva6DnAL7jqOFFhbqauvaxVslC+txJ6xklf7goAeMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrkedugdegkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 6 Jan 2023 21:32:27 -0500 (EST) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH 4/4] ALSA: firewire-lib: code refactoring for cache position in sequence replay Date: Sat, 7 Jan 2023 11:32:14 +0900 Message-Id: <20230107023214.29132-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230107023214.29132-1-o-takashi@sakamocchi.jp> References: <20230107023214.29132-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: alsa-devel@alsa-project.org, clemens@ladisch.de Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" When sequence replay is enabled for media clock recovery, current implementation refers to cache of sequence descriptors in tx packets, then fulfil sequence descriptors for rx packets. The initialization for rx packets is done before starting packet streaming, while it can be postponed till the cache has enough entries for the replay. This commit refactors for the purpose as well as minor code change for renaming of structure member. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp-stream.c | 16 +++++++++------- sound/firewire/amdtp-stream.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 08fd61a06e2e..5ecb449ff6fa 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c @@ -546,16 +546,16 @@ static void pool_replayed_seq(struct amdtp_stream *s, struct seq_desc *descs, un struct amdtp_stream *target = s->ctx_data.rx.replay_target; const struct seq_desc *cache = target->ctx_data.tx.cache.descs; const unsigned int cache_size = target->ctx_data.tx.cache.size; - unsigned int cache_head = s->ctx_data.rx.cache_head; + unsigned int cache_pos = s->ctx_data.rx.cache_pos; int i; for (i = 0; i < count; ++i) { - descs[pos] = cache[cache_head]; - cache_head = (cache_head + 1) % cache_size; + descs[pos] = cache[cache_pos]; + cache_pos = (cache_pos + 1) % cache_size; pos = (pos + 1) % size; } - s->ctx_data.rx.cache_head = cache_head; + s->ctx_data.rx.cache_pos = cache_pos; } static void pool_seq_descs(struct amdtp_stream *s, struct seq_desc *descs, unsigned int size, @@ -573,8 +573,8 @@ static void pool_seq_descs(struct amdtp_stream *s, struct seq_desc *descs, unsig } else { struct amdtp_stream *tx = s->ctx_data.rx.replay_target; const unsigned int cache_size = tx->ctx_data.tx.cache.size; - const unsigned int cache_head = s->ctx_data.rx.cache_head; - unsigned int cached_cycles = calculate_cached_cycle_count(tx, cache_head); + const unsigned int cache_pos = s->ctx_data.rx.cache_pos; + unsigned int cached_cycles = calculate_cached_cycle_count(tx, cache_pos); if (cached_cycles > count && cached_cycles > cache_size / 2) pool_seq_descs = pool_replayed_seq; @@ -1181,6 +1181,9 @@ static void process_rx_packets_intermediately(struct fw_iso_context *context, u3 s->ready_processing = true; wake_up(&s->ready_wait); + if (d->replay.enable) + s->ctx_data.rx.cache_pos = 0; + process_rx_packets(context, tstamp, header_length, ctx_header, private_data); if (amdtp_streaming_error(s)) return; @@ -1909,7 +1912,6 @@ static int make_association(struct amdtp_domain *d) } rx->ctx_data.rx.replay_target = tx; - rx->ctx_data.rx.cache_head = 0; ++dst_index; } diff --git a/sound/firewire/amdtp-stream.h b/sound/firewire/amdtp-stream.h index 094a140baa19..f021c1f49137 100644 --- a/sound/firewire/amdtp-stream.h +++ b/sound/firewire/amdtp-stream.h @@ -167,7 +167,7 @@ struct amdtp_stream { unsigned int last_syt_offset; struct amdtp_stream *replay_target; - unsigned int cache_head; + unsigned int cache_pos; } rx; } ctx_data;