From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795015019; b=jRM0HJFn46XE1BfmP4nigyepVJTdY0jZk8+J6Is2EZjLVlJKwEBXiPJl4KJN9AhIwD3Y T7fo7sXIn1RwiilT0aa/plRUNUs8stoxWBa4GR4SgW4zjXUGOn/GRLjrQUVwyls2a6F77 dVKbJ9OvdCcgrry+0pY33jBQAu9vQ51I2gbmce6JiTefMwgatOCQU3wf+xb2d12P6ezcT 5bYr6vckZtMVvtbCOlsISrSQFn5H+1QTVc5qvmAh9VHzkKhzZ4hAxMb5kvtdIjyCyDmfm PKYIK61nWf9y4JZyIEjTX+PqzbVZNb33gYvkASr44drTKXqnjEHZTK0U19Z7ihAnuTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795015019; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FpbflN9c2J0rwUTpq2msjVqW5fPCW3YxQ7epwnbDxG0=; b=sAqh14do6KYA/OKmb3G2bUT8iXfYAUD/ZL6NYPzPHu6eaTkwrPvt0Z9j2VKtG5jXFshk LCpRk/oJJaaDTCNBQFIbNCa2KdD5oCAmdURCnj89B/+zch0gOnY2UQGnPWjcwmiTamAcU FBztyvB5h8TkWIkDqfWM7StMjJzP+mprMB113InYHH6E+CD0mRrVVvj1Hss0U5l90YWBh BR9YBXhKng/bDqAEcnYa6fCHnkDqHMc3LxyCY4NZnaY/2bZaKZJHeMpDjgFQXZIL/YoIT DceWimBoSC3j5w5X7c99PX5Dh2kqFFhe8oSC/JFeSN5nlxKMn25n22HBe8fU0f4YJtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tAQCY976; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3514D606A32F; Wed, 18 Nov 2026 15:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tAQCY976 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85F211F000C6; Wed, 18 Nov 2026 15:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795015019; bh=FpbflN9c2J0rwUTpq2msjVqW5fPCW3YxQ7epwnbDxG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tAQCY976WRTWrXYDPjYyzbRAvB1ATGoh9DGERfIfpkMVrRZF25GYc37YanBEtQNSI inXuKBbuEXiXVvoPPWjg+yej+V8puUvkUHk1bbtGURC8UEFbplG9+gXF+dC4xX7CEH TnUKH5VmR5kZsdLOYDoC+6EtmRYL+4VIZgvfXYV8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Takashi Iwai , Sasha Levin Subject: [PATCH 7.3 0023/2651] ALSA: pcm: Optimize cpu_latency_qos_*() calls Date: Wed, 18 Nov 2026 15:21:03 +0100 Message-ID: <20261118150248.819594840@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai [ Upstream commit 9f6f4e97fd53908aecb0979507d9ff10a22288eb ] We have a few cpu_latency_qos_*() calls in PCM callbacks, but they seem suboptimal in a few aspects: - We call them at each time when the hw_params changed, but explicitly do remove and (re-)add; this could be cpu_latency_qos_update_request(), instead - The setup of cpu_latency_qos_*() doesn't have to be in hw_params at all; it's not the place where the actual parameters are set up, but rather better at the prepare callback. - The hw_free calls cpu_latency_qos_remove_request() unconditionally, which may be poking a WARNING when it wasn't queued. For addressing the issues above, this patch cleans up and reorganize the cpu_latency_qos_*() calls in the PCM core by a couple helper functions. Now, they are set up at prepare callback, and cleared at hw_free and release callbacks via the new helpers. Link: https://patch.msgid.link/20261002150420.879056-1-tiwai@suse.de Signed-off-by: Takashi Iwai Stable-dep-of: 9017bc3d13da ("ALSA: pcm: Prevent O_APPEND open on OSS streams") Signed-off-by: Sasha Levin --- sound/core/pcm_native.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 6d32c12fb79bd..c9e80617f508b 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -778,11 +778,32 @@ EXPORT_SYMBOL_GPL(snd_pcm_runtime_buffer_set_silence); #define is_oss_stream(substream) false #endif +static void pcm_qos_req_clear(struct snd_pcm_substream *substream) +{ + if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) + cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); +} + +static void pcm_qos_req_update(struct snd_pcm_substream *substream, int usecs) +{ + if (usecs < 0) { + pcm_qos_req_clear(substream); + return; + } + + if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) + cpu_latency_qos_update_request(&substream->latency_pm_qos_req, + usecs); + else + cpu_latency_qos_add_request(&substream->latency_pm_qos_req, + usecs); +} + static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; - int err, usecs; + int err; unsigned int bits; snd_pcm_uframes_t frames; @@ -889,12 +910,6 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); - if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) - cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); - usecs = period_to_usecs(runtime); - if (usecs >= 0) - cpu_latency_qos_add_request(&substream->latency_pm_qos_req, - usecs); err = 0; _error: if (err) { @@ -971,7 +986,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) goto unlock; result = do_hw_free(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); - cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); + pcm_qos_req_clear(substream); unlock: snd_pcm_buffer_access_unlock(runtime); return result; @@ -2005,6 +2020,7 @@ static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, err = substream->ops->prepare(substream); if (err < 0) return err; + pcm_qos_req_update(substream, period_to_usecs(substream->runtime)); return snd_pcm_do_reset(substream, state); } @@ -2795,8 +2811,7 @@ void snd_pcm_release_substream(struct snd_pcm_substream *substream) substream->ops->close(substream); substream->hw_opened = 0; } - if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) - cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); + pcm_qos_req_clear(substream); if (substream->pcm_release) { substream->pcm_release(substream); substream->pcm_release = NULL; -- 2.53.0