public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: acpi-cpufreq: Optimize SMP calls in drv_write() function
@ 2025-09-04  8:16 Kaushlendra Kumar
  2025-09-05 19:14 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Kaushlendra Kumar @ 2025-09-04  8:16 UTC (permalink / raw)
  To: rafael, viresh.kumar; +Cc: linux-pm, Kaushlendra Kumar

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-08 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04  8:16 [PATCH] cpufreq: acpi-cpufreq: Optimize SMP calls in drv_write() function Kaushlendra Kumar
2025-09-05 19:14 ` Rafael J. Wysocki
2025-09-06  4:22   ` Kumar, Kaushlendra
2025-09-08 19:00     ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox