From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: rafael@kernel.org, viresh.kumar@linaro.org
Cc: linux-pm@vger.kernel.org,
Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH] cpufreq: acpi-cpufreq: Optimize SMP calls in drv_write() function
Date: Thu, 4 Sep 2025 13:46:00 +0530 [thread overview]
Message-ID: <20250904081600.2706572-1-kaushlendra.kumar@intel.com> (raw)
The current drv_write() implementation performs redundant work by calling
do_drv_write() on the current CPU and then issuing smp_call_function_many()
to all CPUs in the mask, including the current CPU again. This results in
duplicate MSR writes on the current CPU and unnecessary IPI overhead.
Optimize the function by:
- Executing do_drv_write() locally when current CPU is
in the target mask
- Use a temporary mask to exclude the current CPU from
smp_call_function_many.
- Falling back to smp_call_function_many() for the target
CPUs when current CPU is not in the target mask
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
drivers/cpufreq/acpi-cpufreq.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 4f7f9201598d..081d2d8a13da 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -330,6 +330,7 @@ static void drv_write(struct acpi_cpufreq_data *data,
const struct cpumask *mask, u32 val)
{
struct acpi_processor_performance *perf = to_perf_data(data);
+ struct cpumask tmp_mask;
struct drv_cmd cmd = {
.reg = &perf->control_register,
.val = val,
@@ -338,10 +339,14 @@ static void drv_write(struct acpi_cpufreq_data *data,
int this_cpu;
this_cpu = get_cpu();
- if (cpumask_test_cpu(this_cpu, mask))
+ if (cpumask_test_cpu(this_cpu, mask)) {
do_drv_write(&cmd);
+ cpumask_andnot(&tmp_mask, mask, cpumask_of(this_cpu));
+ smp_call_function_many(&tmp_mask, do_drv_write, &cmd, 1);
+ } else {
+ smp_call_function_many(mask, do_drv_write, &cmd, 1);
+ }
- smp_call_function_many(mask, do_drv_write, &cmd, 1);
put_cpu();
}
--
2.34.1
next reply other threads:[~2025-09-04 8:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 8:16 Kaushlendra Kumar [this message]
2025-09-05 19:14 ` [PATCH] cpufreq: acpi-cpufreq: Optimize SMP calls in drv_write() function Rafael J. Wysocki
2025-09-06 4:22 ` Kumar, Kaushlendra
2025-09-08 19:00 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250904081600.2706572-1-kaushlendra.kumar@intel.com \
--to=kaushlendra.kumar@intel.com \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox