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=1796386037; b=Nyysp81hUuL+s9aJ280oXZajk7p2rm/jKpK9xUxtJ6QzrSrYMGSN278vkvsM8cBr9C4i GgNg92WcbHSxJwoUAJ91/tdpGeuNIy0pitOn2VKt+WqTYeuzjEJBr0VvdS2hci+7tT/CL iXUsitqHuRvxuQl1+Y/pF0f4zgMPR5WDrB2sQgA44aSD1CRQUL4CRGJrAYkFli1sLxaN7 bWxPP15QUuGZdef66hrQVeAGbvYNJyf4Kg5SbVscC8zzzQ84/GOvJP4PAMtZ9MVfhtZ0z UiXF/l+4KzkpnwmW0ckQMiWhjR5gizSddpqsKpPesrLPkT76jNvmTunMjb38MekNMlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386037; 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=MVMXzXWvrxv4lDPNBdVOXoN/0de7J3pZDP92jXt0zGo=; b=eI3ExhrJtLl626H4qDMpsMsXoXDmrb3RjhpqjBKvoWNTu7Sd3mgSg7qJmbVx8z+e21NL lPc4KM6T/ongS4f6j0IqD/U8Id7S7IrWuIUFrWt1hACpM1e/f1wmJgQoviW1p07zww9Ym V8pAnY8yA8zl8Ghs55GVopGqwMN7DC+5bltSbxCoejAoAXVIfyU6Kph6w2rYE121MepGW SXkwveb/ms9LlUJH7Zf8nD4UAerX1g2ebzaa2zXTNwVUHLtBgww3vO2J6NZ3CkyngRHtO XWrq/VuepckmhDDy4yQJ4+tSYMZr4N2kz1YcFNSODJnppV46XbyCCtOLVwK9TaCwmBw== 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=F52MFbJE; 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 E98E5606A322; Fri, 4 Dec 2026 12:07:16 +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=F52MFbJE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C8CE1F000C2; Fri, 4 Dec 2026 12:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386036; bh=MVMXzXWvrxv4lDPNBdVOXoN/0de7J3pZDP92jXt0zGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F52MFbJE2GgcOIym1kAeZR+icCc/S+fyvuc0kK4+St0zweWrrvjgqN71GD6M7GsoA flMjJ8fhxH0LOAlTnyQ8+1YI5H5zZzB4gn4ewYJ6Rp66yM2MAavJUtDEqY36hVxvtd objracj1Bk9DLDKdw5ADnAMD9oM9yuMtcGm4YWrw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Viresh Kumar , Lifeng Zheng , Zhongqiu Han , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.6 0798/1167] cpufreq: Avoid redundant target() calls for unchanged limits Date: Fri, 4 Dec 2026 19:03:45 +0900 Message-ID: <20261204100722.912232224@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Viresh Kumar [ Upstream commit 9801be8bef65dbcbc40c1a9c2f03d70ed67a5d30 ] Drivers setting CPUFREQ_NEED_UPDATE_LIMITS expect target() to be invoked even if the target frequency remains unchanged, so they can update their internal policy limits state. Currently the core invokes target() unconditionally whenever the requested frequency matches policy->cur for such drivers, even if policy->min and policy->max haven't changed since the previous update. Track pending policy limit updates explicitly and skip redundant target() invocations when neither the target frequency nor the effective limits changed. Signed-off-by: Viresh Kumar Reviewed-by: Lifeng Zheng Reviewed-by: Zhongqiu Han Link: https://patch.msgid.link/d0107c364b709abca21acf88072220bc05478594.1779423281.git.viresh.kumar@linaro.org Signed-off-by: Rafael J. Wysocki Stable-dep-of: 75120f31aed0 ("cpufreq: Fix updates of cached resolved frequency and index") Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq.c | 31 ++++++++++++++++++++++--------- include/linux/cpufreq.h | 3 +++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8fc5f1fb62bdd..735dd4803ef99 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2404,9 +2404,13 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, * exactly same freq is called again and so we can save on few function * calls. */ - if (target_freq == policy->cur && - !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) - return 0; + if (target_freq == policy->cur) { + if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) || + !policy->update_limits) + return 0; + + policy->update_limits = false; + } if (cpufreq_driver->target) { /* @@ -2661,6 +2665,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, { struct cpufreq_policy_data new_data; struct cpufreq_governor *old_gov; + unsigned int freq; int ret; memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); @@ -2693,12 +2698,20 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, * compiler optimizations around them because they may be accessed * concurrently by cpufreq_driver_resolve_freq() during the update. */ - WRITE_ONCE(policy->max, __resolve_freq(policy, new_data.max, - new_data.min, new_data.max, - CPUFREQ_RELATION_H)); - new_data.min = __resolve_freq(policy, new_data.min, new_data.min, - new_data.max, CPUFREQ_RELATION_L); - WRITE_ONCE(policy->min, new_data.min > policy->max ? policy->max : new_data.min); + freq = __resolve_freq(policy, new_data.max, new_data.min, new_data.max, + CPUFREQ_RELATION_H); + if (freq != policy->max) { + WRITE_ONCE(policy->max, freq); + policy->update_limits = true; + } + + freq = __resolve_freq(policy, new_data.min, new_data.min, new_data.max, + CPUFREQ_RELATION_L); + freq = min(freq, policy->max); + if (freq != policy->min) { + WRITE_ONCE(policy->min, freq); + policy->update_limits = true; + } trace_cpu_frequency_limits(policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 7a74140d7aa8a..03ea59ad0b2dc 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -150,6 +150,9 @@ struct cpufreq_policy { /* Per policy boost supported flag. */ bool boost_supported; + /* Pending policy->min/max update for the driver */ + bool update_limits; + /* The policy has been suspended. */ bool suspended; -- 2.53.0