lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sat,  5 May 2018 19:53:22 +0800
From:   Chen Yu <yu.c.chen@...el.com>
To:     "Rafael J. Wysocki" <rjw@...ysocki.net>,
        Len Brown <lenb@...nel.org>
Cc:     linux-kernel@...r.kernel.org, Chen Yu <yu.c.chen@...el.com>,
        Lenny Szubowicz <lszubowi@...hat.com>,
        Jacob Pan <jacob.jun.pan@...ux.intel.com>,
        Rui Zhang <rui.zhang@...el.com>, linux-acpi@...r.kernel.org
Subject: [PATCH][RFC v2] 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 is met.
This is applicable due to round-robin attribute of the
power saving threads, otherwise ignore the setting/ACPI
notification.

Suggested-by: Lenny Szubowicz <lszubowi@...hat.com>
Suggested-by: Len Brown <lenb@...nel.org>
Cc: "Rafael J. Wysocki" <rjw@...ysocki.net>
Cc: Lenny Szubowicz <lszubowi@...hat.com>
Cc: Len Brown <lenb@...nel.org>
Cc: Jacob Pan <jacob.jun.pan@...ux.intel.com>
Cc: Rui Zhang <rui.zhang@...el.com>
Cc: linux-acpi@...r.kernel.org
Signed-off-by: Chen Yu <yu.c.chen@...el.com>
---
 drivers/acpi/acpi_pad.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 552c1f7..515e60e 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -254,12 +254,62 @@ static void set_power_saving_task_num(unsigned int num)
 	}
 }
 
+/*
+ * 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.
+ */
+#define SAMPLE_INTERVAL_JIF	20
+
+static u64 get_idle_time(int cpu)
+{
+	u64 idle, idle_usecs = -1ULL;
+
+	idle_usecs = get_cpu_idle_time_us(cpu, NULL);
+
+	if (idle_usecs == -1ULL)
+		idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE];
+	else
+		idle = idle_usecs * NSEC_PER_USEC;
+
+	return idle;
+}
+
+static bool idle_nr_valid(unsigned int num_cpus)
+{
+	int busy_nr = 0, i = 0, load_thresh = 100 - idle_pct;
+
+	if (!num_cpus)
+		return true;
+
+	for_each_online_cpu(i) {
+		u64 wall_time, idle_time;
+		unsigned int elapsed_delta, idle_delta, load;
+
+		wall_time = jiffies64_to_nsecs(get_jiffies_64());
+		idle_time = get_idle_time(i);
+		/* Wait and see... */
+		schedule_timeout_uninterruptible(SAMPLE_INTERVAL_JIF);
+
+		idle_delta = get_idle_time(i) - idle_time;
+		elapsed_delta = jiffies64_to_nsecs(get_jiffies_64()) - wall_time;
+		idle_delta = (idle_delta > elapsed_delta) ? elapsed_delta : idle_delta;
+		load = 100 * (elapsed_delta - idle_delta) / elapsed_delta;
+		if (load >= load_thresh)
+			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_nr_valid(num_cpus))
+		set_power_saving_task_num(num_cpus);
 
 	put_online_cpus();
 }
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ