2018-05-04 08:04:30

by Chen Yu

[permalink] [raw]
Subject: [PATCH][RFC] ACPI: acpi_pad: Do not launch acpi_pad threads on idle cpus

According to current implementation of acpi_pad driver,
it does not make sense to spawn any power saving threads
on the cpus which are already idle - it might bring
unnecessary overhead on these idle cpus and causes power
waste. So verify the condition that if the number of 'busy'
cpus exceeds the amount of the 'forced idle' cpus - This is
applicable due to round-robin attribute of the power saving
threads, otherwise ignore the setting/ACPI notification.

Suggested-by: Lenny Szubowicz <[email protected]>
Suggested-by: Len Brown <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Jacob Pan <[email protected]>
Cc: Rui Zhang <[email protected]>
Cc: [email protected]
Signed-off-by: Chen Yu <[email protected]>
---
drivers/acpi/acpi_pad.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 552c1f7..190aa36 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -253,13 +253,36 @@ static void set_power_saving_task_num(unsigned int num)
destroy_power_saving_task();
}
}
+/*
+ * Extra acpi_pad threads should not be created until
+ * the requested idle count is less than/equals to the
+ * number of the busy cpus - it does not make sense to
+ * throttle the idle cpus.
+ */
+static bool idle_cpu_valid(unsigned int num_cpus)
+{
+ int busy_nr = 0, i = 0;
+
+ for_each_online_cpu(i) {
+ /*
+ * In case the acpi_pad threads are treated as
+ * idle in the future(as intel_powerclamp),
+ * the pad_busy_cpus_bits should be checked too.
+ */
+ if (!idle_cpu(i))
+ busy_nr++;
+ }
+
+ return (busy_nr >= num_cpus) ? true : false;
+}

static void acpi_pad_idle_cpus(unsigned int num_cpus)
{
get_online_cpus();

num_cpus = min_t(unsigned int, num_cpus, num_online_cpus());
- set_power_saving_task_num(num_cpus);
+ if (idle_cpu_valid(num_cpus))
+ set_power_saving_task_num(num_cpus);

put_online_cpus();
}
--
2.7.4



2018-05-05 11:48:00

by Chen Yu

[permalink] [raw]
Subject: Re: [PATCH][RFC] ACPI: acpi_pad: Do not launch acpi_pad threads on idle cpus

On Fri, May 04, 2018 at 04:08:42PM +0800, Chen Yu wrote:
> According to current implementation of acpi_pad driver,
> it does not make sense to spawn any power saving threads
> on the cpus which are already idle - it might bring
> unnecessary overhead on these idle cpus and causes power
> waste. So verify the condition that if the number of 'busy'
> cpus exceeds the amount of the 'forced idle' cpus - This is
> applicable due to round-robin attribute of the power saving
> threads, otherwise ignore the setting/ACPI notification.
>
> Suggested-by: Lenny Szubowicz <[email protected]>
> Suggested-by: Len Brown <[email protected]>
> Cc: "Rafael J. Wysocki" <[email protected]>
> Cc: Jacob Pan <[email protected]>
> Cc: Rui Zhang <[email protected]>
> Cc: [email protected]
> Signed-off-by: Chen Yu <[email protected]>
> ---
>
Please ignore this one, I'm sending out another version.
Thanks,
Yu