From mboxrd@z Thu Jan 1 00:00:00 1970 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 3938AC77B75 for ; Fri, 12 May 2023 11:25:14 +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 7F2B610E; Fri, 12 May 2023 13:24:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7F2B610E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1683890712; bh=9kNN7VQbZHZlfaz7n9NFudreMJvBZmodr+T0xRaAQ6Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=m3hM+lyQ232mDEcO9N+1X/yBo3HTUgfJM9MqKOpFmHp8JKjWHdFqf2MwL0cb3GS7w RvvabfNtuyo4S+9xw3P0WVrEFB7t8E2r6h1X1FgZWUh7b5TX/c7G9kO8XdDj0fUIUm S+C/EFStCKLe9Ae5D7NhI6Wgkjo7HiehbcbLm0+o= Received: by alsa1.perex.cz (Postfix, from userid 50401) id DCFFEF8053D; Fri, 12 May 2023 13:23:59 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 2FFD6F8052E; Fri, 12 May 2023 13:23:59 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 117F7F8052E; Fri, 12 May 2023 13:23:55 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3D8F6F802E8 for ; Fri, 12 May 2023 13:23:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3D8F6F802E8 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=j5yhLtKc; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5Xr3S+Wl Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 766A720511; Fri, 12 May 2023 11:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683890630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7VPp2sgfqtJM5ApyNaoqBRnQdlBxO8OFNo3vEV5Wbuk=; b=j5yhLtKckDi6bfDB38qiUpLLe3GQwtPQe41xtPT85+rwTNOxBuJrcc+6OTYVa21lD/qyXR VHkLPR1Wd06UA9HHXz7x7357IVaJpm4P1+3AzQd+9iRnxufIPN9ccDiQEoLb/zIiJRd9tc r8Fc6TjohVYzjdEBSkBRhooNVtvo2O4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683890630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7VPp2sgfqtJM5ApyNaoqBRnQdlBxO8OFNo3vEV5Wbuk=; b=5Xr3S+WlEGaNHL3Bj9CwoXSBM3yo3t26D2admpo0oQOqbTY/hPBDvFJ3KMMHfbLurbm3Q9 Cwv7hk2bOdwYgjBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4C7C113499; Fri, 12 May 2023 11:23:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id M/AYEcYhXmQzfQAAMHmgww (envelope-from ); Fri, 12 May 2023 11:23:50 +0000 Date: Fri, 12 May 2023 13:23:49 +0200 Message-ID: <87ilcxaj3u.wl-tiwai@suse.de> From: Takashi Iwai To: Amadeusz =?ISO-8859-2?Q?S=B3awi=F1ski?= Cc: Cezary Rojewski , "alsa-devel@alsa-project.org" Subject: Re: HDA, power saving and recording In-Reply-To: <41417b90-1881-0cbb-52e1-d63923dd8cd6@linux.intel.com> References: <878rdwjs1s.wl-tiwai@suse.de> <87jzxe5084.wl-tiwai@suse.de> <41417b90-1881-0cbb-52e1-d63923dd8cd6@linux.intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 8bit Message-ID-Hash: RIOTSYWQR4KL5NYF5VLRC65D7BATWOBZ X-Message-ID-Hash: RIOTSYWQR4KL5NYF5VLRC65D7BATWOBZ X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 11 May 2023 19:20:17 +0200, Amadeusz Sławiński wrote: > > On 5/11/2023 5:58 PM, Takashi Iwai wrote: > > On Thu, 11 May 2023 17:31:37 +0200, > > Amadeusz Sławiński wrote: > >> > >> On 5/10/2023 2:21 PM, Takashi Iwai wrote: > >>> On Tue, 09 May 2023 12:10:06 +0200, > >>> Amadeusz Sławiński wrote: > >> Then capture stream starts and seems to assume that > >> registers were already set, so it doesn't write them to hw. > > > > ... it seems this didn't happen, and that's the inconsistency. > > > > So the further question is: > > At the point just before you start recording, is the codec in runtime > > suspended? Or it's running? > > > > If it's runtime-suspended, snd_hda_regmap_sync() must be called from > > alc269_resume() via runtime-resume, and this must write out the > > cached values. Then the bug can be along with that line. > > > > Or if it's running, it means that the previous check of > > snd_hdac_keep_power_up() was bogus (or racy). > > > > Well, it is in... let's call it semi powered state. When snd_hda_intel > driver is loaded with power_save=X option it sets timeout to X seconds > and problem only happens when I start the stream before those X > seconds pass and it runs first runtime suspend. After it suspends it > then uses standard pm_runtime_resume and works correctly. That's why > the pm_runtime_force_suspend(&codec->core.dev); mentioned in first > email in thread "fixes" the problem, as it forces it to be instantly > suspended instead of waiting for timeout and then later normal > resume-play/record-suspend flow can be followed. Hm, then maybe it's a bad idea to rely on the usage count there. Even if the usage is 0, the device can be still active, and the update can be missed. How about the patch like below? thanks, Takashi --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -610,8 +610,12 @@ EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm); */ int snd_hdac_keep_power_up(struct hdac_device *codec) { + int ret; + if (!atomic_inc_not_zero(&codec->in_pm)) { - int ret = pm_runtime_get_if_in_use(&codec->dev); + if (pm_runtime_active(&codec->dev)) + return pm_runtime_get_sync(&codec->dev); + ret = pm_runtime_get_if_in_use(&codec->dev); if (!ret) return -1; if (ret < 0)