Skip to contentSkip to conversation

Power-aware scheduling v2

RFC PATCH In review Morten Rasmussen 5 participants 29 messages Oct 11, 2013 – Oct 18, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Power-aware scheduling v2

Hi,

I have revised the previous power scheduler proposal[1] trying to address as many of the comments as possible. The overall idea was discussed at LPC[2,3]. The revised design has removed the power scheduler and replaced it with a high level power driver interface. An interface that allows the scheduler to query the power driver for information and provide hints to guide power management decisions in the power driver.

The power driver is going to be a unified platform power driver that can replace cpufreq and cpuidle drivers. Generic power policies will be optional helper functions called from the power driver. Platforms may choose to implement their own policies as part of their power driver.

This RFC series prototypes a part of the power driver interface (cpu capacity hints) and shows how they can be used from the scheduler. More extensive use of the power driver hints and queries is left for later. The focus for now is the power driver interface. The patch series includes a power driver/cpufreq governor that can use existing cpufreq drivers as backend. It has been tested (not thoroughly) on ARM TC2. The cpufreq governor power driver implementation is rather horrible, but it illustrates how the power driver interface can be used. Native power drivers is on the todo list.

The power driver interface is still missing quite a few calls to handle: Idle, adding extra information to the sched_domain hierarchy to guide scheduling decisions (packing), and possibly scaling of tracked load to compensate for frequency changes and asymmetric systems (big.LITTLE).

This set is based on 3.11. I have done ARM TC2 testing based on linux-linaro 2013.08[4] to get cpufreq support for TC2.

Morten

[1] https://lkml.org/lkml/2013/7/9/314

[2] http://etherpad.osuosl.org/lpc2013-power-efficient-scheduling

[3] http://www.linuxplumbersconf.org/2013/ocw//system/presentations/1263/original/Unifying_Power_Policies_LPC.pdf

[4] http://git.linaro.org/gitweb?p=kernel/linux-linaro-tracking.git

Morten Rasmussen (7):
Initial power driver interface infrastructure
sched: power: Power driver late callback interface
sched: power: go_faster/slower power driver hints
sched: power: Remove power capacity hints for kworker threads
sched: power: Increase cpu capacity based on rq tracked load
sched: power: cpufreq: Initial schedpower cpufreq governor/power
driver
sched: power: Let the power driver choose the best wake-up cpu

 arch/arm/Kconfig                     |    4 +
 drivers/cpufreq/Kconfig              |   11 ++
 drivers/cpufreq/Makefile             |    1 +
 drivers/cpufreq/cpufreq_schedpower.c |  218 ++++++++++++++++++++++++++++++++++
 include/linux/sched/power.h          |   37 ++++++
 kernel/sched/Makefile                |    1 +
 kernel/sched/core.c                  |    1 +
 kernel/sched/fair.c                  |   53 ++++++++-
 kernel/sched/power.c                 |   73 ++++++++++++
 kernel/sched/sched.h                 |   32 +++++
 10 files changed, 430 insertions(+), 1 deletion(-)
 create mode 100644 drivers/cpufreq/cpufreq_schedpower.c
 create mode 100644 include/linux/sched/power.h
 create mode 100644 kernel/sched/power.c
Signature · 1 line
1.7.9.5
#1 lore raw

RFC PATCH 1/7 Initial power driver interface infrastructure

Infrastructure for power driver registration and defines three initial power driver interface calls: go_faster(), go_slower(), and at_max_capacity(). The intention is to use these to guide scheduling decisions and frequency state selection in the power driver.

---
 arch/arm/Kconfig            |    4 +++
 include/linux/sched/power.h |   32 ++++++++++++++++++++++++
 kernel/sched/Makefile       |    1 +
 kernel/sched/power.c        |   58 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 include/linux/sched/power.h
 create mode 100644 kernel/sched/power.c
arch/arm/Kconfig +4 -0
index 43594d5..763d147 100644
@@ -1844,6 +1844,10 @@ config XEN
 	help
 	  Say Y if you want to run Linux in a Virtual Machine on Xen on ARM.
 
+config SCHED_POWER
+	bool "(EXPERIMENTAL) Power aware scheduling"
+	default n
+
 endmenu
 
 menu "Boot options"
include/linux/sched/power.h new file +32 -0
new file mode 100644
index 0000000..cb2cf37
@@ -0,0 +1,32 @@
+/*
+ * include/linux/sched/power.h
+ *
+ * Copyright (C) 2013 ARM Limited.
+ * Author: Morten Rasmussen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _LINUX_SCHED_POWER_H
+#define _LINUX_SCHED_POWER_H
+
+struct power_driver {
+
+	/*
+	 * Power driver calls may happen from scheduler context with irq
+	 * disabled and rq locks held. This must be taken into account in the
+	 * power driver.
+	 */
+
+	/* cpu already at max capacity? */
+	int (*at_max_capacity)	(int cpu);
+	/* Increase cpu capacity hint */
+	int (*go_faster)	(int cpu, int hint);
+	/* Decrease cpu capacity hint */
+	int (*go_slower)	(int cpu, int hint);
+};
+
+int power_driver_register(struct power_driver *driver);
+int power_driver_unregister(struct power_driver *driver);
+#endif
kernel/sched/Makefile +1 -0
index 54adcf3..55727b4 100644
@@ -17,3 +17,4 @@ obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
 obj-$(CONFIG_SCHEDSTATS) += stats.o
 obj-$(CONFIG_SCHED_DEBUG) += debug.o
 obj-$(CONFIG_CGROUP_CPUACCT) += cpuacct.o
+obj-$(CONFIG_SCHED_POWER) += power.o
kernel/sched/power.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

RFC PATCH 2/7 sched: power: Power driver late callback interface

In reply to Morten Rasmussen

Adds a late callback to the power driver interface which is called with irq enabled and no locks held. The power driver may postpone work that can't be done in schedule context (irq disabled and rq locks held) and let the late callback handle it.

---
 include/linux/sched/power.h |    3 +++
 kernel/sched/core.c         |    1 +
 kernel/sched/fair.c         |    2 ++
 kernel/sched/power.c        |    6 ++++++
 kernel/sched/sched.h        |    8 ++++++++
 5 files changed, 20 insertions(+)
include/linux/sched/power.h +3 -0
index cb2cf37..aba5f47 100644
@@ -25,6 +25,9 @@ struct power_driver {
 	int (*go_faster)	(int cpu, int hint);
 	/* Decrease cpu capacity hint */
 	int (*go_slower)	(int cpu, int hint);
+
+	/* Scheduler call-back without rq lock held and with irq enabled */
+	void (*late_callback)	(int cpu);
 };
 
 int power_driver_register(struct power_driver *driver);
kernel/sched/core.c +1 -0
index 05c39f0..12b4753 100644
@@ -1913,6 +1913,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
 		put_task_struct(prev);
 	}
 
+	power_late_callback(raw_smp_processor_id());
 	tick_nohz_task_switch(current);
 }
 
kernel/sched/fair.c +2 -0
index 68f1609..edba1bb 100644
@@ -5742,6 +5742,8 @@ static void run_rebalance_domains(struct softirq_action *h)
 	 * stopped.
 	 */
 	nohz_idle_balance(this_cpu, idle);
+
+	power_late_callback(this_cpu);
 }
 
 static inline int on_null_domain(int cpu)
kernel/sched/power.c +6 -0
index b82965a..f70b563 100644
@@ -56,3 +56,9 @@ int go_slower(int cpu, int hint)
 	return power_driver->go_slower(cpu, hint);
 }
 
+void power_late_callback(int cpu)
+{
+	if (!power_driver)
+		return;
+	power_driver->late_callback(cpu);
+}
kernel/sched/sched.h +8 -0
index ef0a7b2..907a967 100644
@@ -1364,3 +1364,11 @@ static inline u64 irq_time_read(int cpu)
 }
 #endif /* CONFIG_64BIT */
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
+
+#ifdef CONFIG_SCHED_POWER
+extern void power_late_callback(int cpu);
+#else
+static inline void power_late_callback(int cpu)
+{
+}
+#endif /* CONFIG_SCHED_POWER */
Signature · 1 line
1.7.9.5
maintainer
#3 lore raw

Re: [RFC][PATCH 2/7] sched: power: Power driver late callback interface

Quoted 4 lines · Morten Rasmussen

Adds a late callback to the power driver interface which is called with irq enabled and no locks held. The power driver may postpone work that can't be done in schedule context (irq disabled and rq locks held) and let the late callback handle it.

What kind of things are we talking about here?

#4 lore raw

RFC PATCH 3/7 sched: power: go_faster/slower power driver hints

In reply to Morten Rasmussen

Adds power driver hints at task enqueue/dequeue and at the sched tick if the new cpu load doesn't match the current cpu capacity. The optional hint argument of go_faster/slower calls is currently unused. It is meant to give the power driver a rough estimate of how much more/less cpu capacity is needed. The power driver may ignore this and the go_faster/slower call completely.

---
 kernel/sched/fair.c  |   30 ++++++++++++++++++++++++++++++
 kernel/sched/sched.h |   18 ++++++++++++++++++
 2 files changed, 48 insertions(+)
kernel/sched/fair.c +30 -0
index edba1bb..50ae0ce 100644
@@ -2852,6 +2852,31 @@ static inline void hrtick_update(struct rq *rq)
 }
 #endif
 
+#ifdef CONFIG_SCHED_POWER
+static unsigned long weighted_cpuload(const int cpu);
+static unsigned long power_of(int cpu);
+
+static inline void inc_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) > power_of(cpu))
+		go_faster(cpu, 0);
+}
+
+static inline void dec_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) < power_of(cpu))
+		go_slower(cpu, 0);
+}
+#else
+static inline void inc_cpu_capacity(int cpu)
+{
+}
+
+static inline void dec_cpu_capacity(int cpu)
+{
+}
+#endif
+
 /*
  * The enqueue_task method is called before nr_running is
  * increased. Here we update the fair scheduling stats and
@@ -2897,6 +2922,8 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 		update_rq_runnable_avg(rq, rq->nr_running);
 		inc_nr_running(rq);
 	}
+
+	inc_cpu_capacity(task_cpu(p));
 	hrtick_update(rq);
 }
 
@@ -2958,6 +2985,8 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 		dec_nr_running(rq);
 		update_rq_runnable_avg(rq, 1);
 	}
+
+	dec_cpu_capacity(task_cpu(p));
 	hrtick_update(rq);
 }
 
@@ -5743,6 +5772,7 @@ static void run_rebalance_domains(struct softirq_action *h)
 	 */
 	nohz_idle_balance(this_cpu, idle);
 
+	inc_cpu_capacity(this_cpu);
 	power_late_callback(this_cpu);
 }
 
kernel/sched/sched.h +18 -0
index 907a967..88e7968 100644
@@ -1367,8 +1367,26 @@ static inline u64 irq_time_read(int cpu)
 
 #ifdef CONFIG_SCHED_POWER
 extern void power_late_callback(int cpu);
+extern int at_max_capacity(int cpu);
+extern int go_faster(int cpu, int hint);
+extern int go_slower(int cpu, int hint);
 #else
 static inline void power_late_callback(int cpu)
 {
 }
+
+static inline int at_max_capacity(int cpu)
+{
+	return 1;
+}
+
+static inline int go_faster(int cpu, int hint)
+{
+	return 0;
+}
+
+static inline int go_slower(int cpu, int hint)
+{
+	return 0;
+}
 #endif /* CONFIG_SCHED_POWER */
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [RFC][PATCH 3/7] sched: power: go_faster/slower power driver hints

Hi, Morten

On 10/12/2013 01:19 AM, Morten Rasmussen wrote:
[snip]

kernel/sched/fair.c static void run_rebalance_domains(struct softirq_action *h) · line 5775

Quoted 6 lines
kernel/sched/fair.c +1 -0
@@ -5743,6 +5772,7 @@ static void run_rebalance_domains(struct softirq_action *h)
 	 */
 	nohz_idle_balance(this_cpu, idle);
 
+	inc_cpu_capacity(this_cpu);

Just wondering is this check necessary here? if rq get more tasks during the balance, enqueue_task() should already do the check each time when we move_task(), isn't it?

Regards,
Michael Wang

Quoted 35 lines
kernel/sched/fair.c +0 -0
 	power_late_callback(this_cpu);
 }
 
kernel/sched/sched.h +18 -0
index 907a967..88e7968 100644
@@ -1367,8 +1367,26 @@ static inline u64 irq_time_read(int cpu)
 
 #ifdef CONFIG_SCHED_POWER
 extern void power_late_callback(int cpu);
+extern int at_max_capacity(int cpu);
+extern int go_faster(int cpu, int hint);
+extern int go_slower(int cpu, int hint);
 #else
 static inline void power_late_callback(int cpu)
 {
 }
+
+static inline int at_max_capacity(int cpu)
+{
+	return 1;
+}
+
+static inline int go_faster(int cpu, int hint)
+{
+	return 0;
+}
+
+static inline int go_slower(int cpu, int hint)
+{
+	return 0;
+}
 #endif /* CONFIG_SCHED_POWER */
#6 lore raw

Re: [RFC][PATCH 3/7] sched: power: go_faster/slower power driver hints

Hi Michael,

Quoted 9 lines · Michael wang

Hi, Morten

On 10/12/2013 01:19 AM, Morten Rasmussen wrote:
[snip]

Quoted 5 lines
kernel/sched/fair.c +0 -0
@@ -5743,6 +5772,7 @@ static void run_rebalance_domains(struct softirq_action *h)
 	 */
 	nohz_idle_balance(this_cpu, idle);
 
Quoted 5 lines

kernel/sched/fair.c static void run_rebalance_domains(struct softirq_action *h) · line 5775

Quoted 1 line
kernel/sched/fair.c +1 -0
+	inc_cpu_capacity(this_cpu);

Just wondering is this check necessary here? if rq get more tasks during the balance, enqueue_task() should already do the check each time when we move_task(), isn't it?

True. enqueue_task() should do the necessary check when we move tasks. Hovewer, the cpu load may change over time without moving tasks if a task changes its behavior. A small task may enter a cpu intensive phase and grow bigger over time while staying on the rq due to the load tracking. That won't be noticed unless we check the cpuload periodically. That is the reason behind this check.

I will look at remove the redundant call to inc_cpu_capacity() when actually did move tasks. More work is needed on the policy for inc/dec_cpu_capacity(). I just added a few easy examples of how they can be used for this post.

Thanks,
Morten

Quoted 41 lines

Regards,
Michael Wang

Quoted 35 lines
kernel/sched/fair.c +0 -0
 	power_late_callback(this_cpu);
 }
 
kernel/sched/sched.h +18 -0
index 907a967..88e7968 100644
@@ -1367,8 +1367,26 @@ static inline u64 irq_time_read(int cpu)
 
 #ifdef CONFIG_SCHED_POWER
 extern void power_late_callback(int cpu);
+extern int at_max_capacity(int cpu);
+extern int go_faster(int cpu, int hint);
+extern int go_slower(int cpu, int hint);
 #else
 static inline void power_late_callback(int cpu)
 {
 }
+
+static inline int at_max_capacity(int cpu)
+{
+	return 1;
+}
+
+static inline int go_faster(int cpu, int hint)
+{
+	return 0;
+}
+
+static inline int go_slower(int cpu, int hint)
+{
+	return 0;
+}
 #endif /* CONFIG_SCHED_POWER */
maintainer
#7 lore raw

Re: [RFC][PATCH 3/7] sched: power: go_faster/slower power driver hints

In reply to Morten Rasmussen

kernel/sched/fair.c static inline void hrtick_update(struct rq *rq) · line 2869

Quoted 11 lines · Morten Rasmussen
kernel/sched/fair.c +11 -0
+static inline void inc_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) > power_of(cpu))
+		go_faster(cpu, 0);
+}
+
+static inline void dec_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) < power_of(cpu))
+		go_slower(cpu, 0);
+}

It seems wrong to me to use weighted_cpuload() here; that contains the task weight, which is irrelevant to power usage. I would expect a pure utilization term here.

Something like:

se->avg.runnable_avg_sum / se->avg.runnable_avg_period

#8 lore raw

Re: [RFC][PATCH 3/7] sched: power: go_faster/slower power driver hints

Quoted 17 lines · Peter Zijlstra

kernel/sched/fair.c static inline void hrtick_update(struct rq *rq) · line 2869

Quoted 11 lines · Morten Rasmussen
kernel/sched/fair.c +11 -0
+static inline void inc_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) > power_of(cpu))
+		go_faster(cpu, 0);
+}
+
+static inline void dec_cpu_capacity(int cpu)
+{
+	if (weighted_cpuload(cpu) < power_of(cpu))
+		go_slower(cpu, 0);
+}

It seems wrong to me to use weighted_cpuload() here; that contains the task weight, which is irrelevant to power usage. I would expect a pure utilization term here.

Quoted 4 lines

Something like:

se->avg.runnable_avg_sum / se->avg.runnable_avg_period

Fully agree. There is no unweighted equivalent to cfs.runnable_load_avg but we could add it. It would be very useful for the power-aware scheduling. It will add some overhead though.

Morten

#9 lore raw

RFC PATCH 4/7 sched: power: Remove power capacity hints for kworker threads

In reply to Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

---
 kernel/sched/fair.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
kernel/sched/fair.c +13 -7
index 50ae0ce..ea8d973 100644
@@ -2856,23 +2856,29 @@ static inline void hrtick_update(struct rq *rq)
 static unsigned long weighted_cpuload(const int cpu);
 static unsigned long power_of(int cpu);
 
-static inline void inc_cpu_capacity(int cpu)
+static inline void inc_cpu_capacity(int cpu, struct task_struct *p)
 {
+	if (p && p->flags & PF_WQ_WORKER)
+		return;
+
 	if (weighted_cpuload(cpu) > power_of(cpu))
 		go_faster(cpu, 0);
 }
 
-static inline void dec_cpu_capacity(int cpu)
+static inline void dec_cpu_capacity(int cpu, struct task_struct *p)
 {
+	if (p && p->flags & PF_WQ_WORKER)
+		return;
+
 	if (weighted_cpuload(cpu) < power_of(cpu))
 		go_slower(cpu, 0);
 }
 #else
-static inline void inc_cpu_capacity(int cpu)
+static inline void inc_cpu_capacity(int cpu, struct task_struct *p)
 {
 }
 
-static inline void dec_cpu_capacity(int cpu)
+static inline void dec_cpu_capacity(int cpu, struct task_struct *p)
 {
 }
 #endif
@@ -2923,7 +2929,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 		inc_nr_running(rq);
 	}
 
-	inc_cpu_capacity(task_cpu(p));
+	inc_cpu_capacity(task_cpu(p), p);
 	hrtick_update(rq);
 }
 
@@ -2986,7 +2992,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 		update_rq_runnable_avg(rq, 1);
 	}
 
-	dec_cpu_capacity(task_cpu(p));
+	dec_cpu_capacity(task_cpu(p), p);
 	hrtick_update(rq);
 }
 
@@ -5772,7 +5778,7 @@ static void run_rebalance_domains(struct softirq_action *h)
 	 */
 	nohz_idle_balance(this_cpu, idle);
 
-	inc_cpu_capacity(this_cpu);
+	inc_cpu_capacity(this_cpu, NULL);
 	power_late_callback(this_cpu);
 }
 
Signature · 1 line
1.7.9.5
maintainer
#10 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

#11 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

.. and likely only for a very few architectures

x86, and I suspect modern ARM, can change frequency synchronously. (using an instruction or maybe two or three for ARM)

#12 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 11 lines · Arjan van de Ven
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Quoted 4 lines

.. and likely only for a very few architectures

x86, and I suspect modern ARM, can change frequency synchronously. (using an instruction or maybe two or three for ARM)

It should be possible to implement synchronous frequency changes on most modern ARM platforms. It is a bit more than a few instructions to change frequency though particularly for the current cpufreq drivers.

cpufreq drivers, like the one for ARM TC2, uses the clock framework to manage clocks. clk_set_rate() is allowed to sleep which won't work if we call it from scheduler context. The clock framework will need a look if it doesn't provide a very fast synchronous alternative to clk_set_rate() to change frequency and we want to use it for scheduler driven frequency scaling.

cpufreq has pre- and post-change notifiers so the current TC2 clock driver waits (yields) in its clk_set_rate() implementation until the change has happened to ensure that the post-change notifier happens at the right time. Since clk_set_rate() is allowed to sleep other tasks may be running while waiting for the change to complete. This may be true for other clock drivers as well.

AFAICT, there is no way to reuse the existing cpufreq drivers in a sensible way for scheduler driven frequency scaling. It should be possible to have very fast frequency changes on ARM but it is not the way it is currently done.

maintainer
#13 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 35 lines · Morten Rasmussen
Quoted 11 lines · Arjan van de Ven
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Quoted 4 lines

.. and likely only for a very few architectures

x86, and I suspect modern ARM, can change frequency synchronously. (using an instruction or maybe two or three for ARM)

It should be possible to implement synchronous frequency changes on most modern ARM platforms. It is a bit more than a few instructions to change frequency though particularly for the current cpufreq drivers.

cpufreq drivers, like the one for ARM TC2, uses the clock framework to manage clocks. clk_set_rate() is allowed to sleep which won't work if we call it from scheduler context. The clock framework will need a look if it doesn't provide a very fast synchronous alternative to clk_set_rate() to change frequency and we want to use it for scheduler driven frequency scaling.

cpufreq has pre- and post-change notifiers so the current TC2 clock driver waits (yields) in its clk_set_rate() implementation until the change has happened to ensure that the post-change notifier happens at the right time. Since clk_set_rate() is allowed to sleep other tasks may be running while waiting for the change to complete. This may be true for other clock drivers as well.

Quoted 4 lines

AFAICT, there is no way to reuse the existing cpufreq drivers in a sensible way for scheduler driven frequency scaling. It should be possible to have very fast frequency changes on ARM but it is not the way it is currently done.

Note that you still have preemption disabled in your late callback from finish_task_switch(). There's no way you can wait/yield/whatever from there. Nor is that really sane.

Just say no to the existing cruft ?

#14 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 2 lines
Quoted 2 lines

cpufreq has pre- and post-change notifiers so the current TC2 clock driver

yeah those are EVIL ;-)

Quoted 8 lines
Quoted 8 lines

waits (yields) in its clk_set_rate() implementation until the change has happened to ensure that the post-change notifier happens at the right time. Since clk_set_rate() is allowed to sleep other tasks may be running while waiting for the change to complete. This may be true for other clock drivers as well.

AFAICT, there is no way to reuse the existing cpufreq drivers in a sensible way for scheduler driven frequency scaling.

that's the conclusion we came to as well about a year ago (and is also why we're no longer using cpufreq core for the Intel pstate driver. the locking/sleeping/callback/cpuhotplug/sysfs/etc stuff is just a MESS for something that ends up being extremely simple if you just code the sequence... for us it's just one register write to change... which shows this as an extreme obviously)

Quoted 4 lines

Note that you still have preemption disabled in your late callback from finish_task_switch(). There's no way you can wait/yield/whatever from there. Nor is that really sane.

the other fun one with this could be that if you have a series of scheduleable tasks for changing stuff.... somehow you want to keep ordering in the requests, and only do the last one/etc.
Not Fun(tm)

#15 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 14 lines · Arjan van de Ven
Quoted 2 lines
Quoted 2 lines

cpufreq has pre- and post-change notifiers so the current TC2 clock driver

yeah those are EVIL ;-)

Quoted 8 lines
Quoted 8 lines

waits (yields) in its clk_set_rate() implementation until the change has happened to ensure that the post-change notifier happens at the right time. Since clk_set_rate() is allowed to sleep other tasks may be running while waiting for the change to complete. This may be true for other clock drivers as well.

AFAICT, there is no way to reuse the existing cpufreq drivers in a sensible way for scheduler driven frequency scaling.

Quoted 6 lines

that's the conclusion we came to as well about a year ago (and is also why we're no longer using cpufreq core for the Intel pstate driver. the locking/sleeping/callback/cpuhotplug/sysfs/etc stuff is just a MESS for something that ends up being extremely simple if you just code the sequence... for us it's just one register write to change... which shows this as an extreme obviously)

We should be able to boil it down to a sequence on ARM as well. But it means dropping cpufreq and looking at the clock framework.

Are you still using the pre- and post-change notifiers on Intel, or can they be ignored safely?

Quoted 11 lines
Quoted 6 lines

Note that you still have preemption disabled in your late callback from finish_task_switch(). There's no way you can wait/yield/whatever from there. Nor is that really sane.

the other fun one with this could be that if you have a series of scheduleable tasks for changing stuff.... somehow you want to keep ordering in the requests, and only do the last one/etc.
Not Fun(tm)

Agreed, I don't want to go there. Also, the overhead will probably kill any benefit that there might be.

#16 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 6 lines

We should be able to boil it down to a sequence on ARM as well. But it means dropping cpufreq and looking at the clock framework.

Are you still using the pre- and post-change notifiers on Intel, or can they be ignored safely?

we do not use change notifiers
(since the hardware changes frequency independently of what "p state" we asked for frequently and in many very common conditions, even if anything depended on being notified on changes... it couldn't possibly work anyway)

#17 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

In reply to Peter Zijlstra
Quoted 42 lines · Peter Zijlstra
Quoted 35 lines · Morten Rasmussen
Quoted 11 lines · Arjan van de Ven
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Quoted 4 lines

.. and likely only for a very few architectures

x86, and I suspect modern ARM, can change frequency synchronously. (using an instruction or maybe two or three for ARM)

It should be possible to implement synchronous frequency changes on most modern ARM platforms. It is a bit more than a few instructions to change frequency though particularly for the current cpufreq drivers.

cpufreq drivers, like the one for ARM TC2, uses the clock framework to manage clocks. clk_set_rate() is allowed to sleep which won't work if we call it from scheduler context. The clock framework will need a look if it doesn't provide a very fast synchronous alternative to clk_set_rate() to change frequency and we want to use it for scheduler driven frequency scaling.

cpufreq has pre- and post-change notifiers so the current TC2 clock driver waits (yields) in its clk_set_rate() implementation until the change has happened to ensure that the post-change notifier happens at the right time. Since clk_set_rate() is allowed to sleep other tasks may be running while waiting for the change to complete. This may be true for other clock drivers as well.

Quoted 4 lines

AFAICT, there is no way to reuse the existing cpufreq drivers in a sensible way for scheduler driven frequency scaling. It should be possible to have very fast frequency changes on ARM but it is not the way it is currently done.

Quoted 3 lines

Note that you still have preemption disabled in your late callback from finish_task_switch(). There's no way you can wait/yield/whatever from there. Nor is that really sane.

No, that is what I have realized after messing around trying to call into cpufreq. It just won't work. A non-waiting/yielding/whatever driver is needed. There is no point in having the late callback it won't solve anything.

Quoted 2 lines

Just say no to the existing cruft ?

That is the only way ahead I think. intel_pstate.c does it. I will into what it takes to do something similar on ARM TC2.

#18 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Agreed that it is not ideal. I will find a better solution for this problem.

Thanks,
Morten

#19 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 6 lines · Morten Rasmussen
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

Quoted 8 lines
Quoted 4 lines

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Agreed that it is not ideal. I will find a better solution for this problem.

can you explain which architectures we're talking about that need this? is it only old stuff, or is there anything current ?

#20 lore raw

Re: [RFC][PATCH 4/7] sched: power: Remove power capacity hints for kworker threads

Quoted 12 lines · Arjan van de Ven
Quoted 11 lines · Morten Rasmussen
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Morten Rasmussen

Removing power hints for kworker threads enables easier use of workqueues in the power driver late callback. That would otherwise lead to an endless loop unless it is prevented in the power driver.

There's many kworker users; some of them actually consume lots of cputime. Therefore how did you come to the conclusion that excepting all users was the better choice of a little added complexity in the one place where it actually matters?

Quoted 7 lines
Quoted 3 lines

Agreed that it is not ideal. I will find a better solution for this problem.

can you explain which architectures we're talking about that need this? is it only old stuff, or is there anything current ?

For now I need it for the cpufreq wrapper governor. I hope it can be avoided for native power drivers, but I don't have a complete overview of all architectures yet.

#21 lore raw

RFC PATCH 5/7 sched: power: Increase cpu capacity based on rq tracked load

In reply to Morten Rasmussen

weighted_cpuload() gives the sum of priority scaled task loads. One NICE 0 task is not be enough load to trigger a cpu capacity increase when cpu_power > 1024. The rq->avg.runnable_avg_sum tracks the actual busy time of the cpu and is therefore a more accurate indication of the cpu load. If the rq tracked load is high the cpu is busy even if the weighted_cpuload() should indicate otherwise.

---
 kernel/sched/fair.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
kernel/sched/fair.c +11 -1
index ea8d973..ee87e65 100644
@@ -2861,7 +2861,17 @@ static inline void inc_cpu_capacity(int cpu, struct task_struct *p)
 	if (p && p->flags & PF_WQ_WORKER)
 		return;
 
-	if (weighted_cpuload(cpu) > power_of(cpu))
+	if (weighted_cpuload(cpu) > power_of(cpu)) {
+		go_faster(cpu, 0);
+		return;
+	}
+
+	/*
+	 * Go faster if the cpu is 80% busy. This threshold should
+	 * be set by the power driver later.
+	 */
+	if (cpu_rq(cpu)->avg.runnable_avg_sum * 100 >
+		80 * cpu_rq(cpu)->avg.runnable_avg_period)
 		go_faster(cpu, 0);
 }
 
Signature · 1 line
1.7.9.5
#22 lore raw

RFC PATCH 6/7 sched: power: cpufreq: Initial schedpower cpufreq governor/power driver

In reply to Morten Rasmussen

Adds a 'schedpower' cpufreq governor that acts as a power driver to cpufreq wrapper. This enables the existing cpufreq drivers to be used as power driver backends initially until native power drivers have been implemented.

schedpower currently uses workqueues as a horrible work-around for calling cpufreq from the late_callback() path. Calling cpufreq from the late_callback() in its current form is not possible and certainly not possible from the scheduler context. Suggestions for better solutions are very welcome.

Native power driver implemented with the locking and context limitations in mind should be able to avoid such work-arounds.

schedpower has been tested (not thoroughly) on ARM TC2.

---
 drivers/cpufreq/Kconfig              |   11 ++
 drivers/cpufreq/Makefile             |    1 +
 drivers/cpufreq/cpufreq_schedpower.c |  207 ++++++++++++++++++++++++++++++++++
 3 files changed, 219 insertions(+)
 create mode 100644 drivers/cpufreq/cpufreq_schedpower.c
drivers/cpufreq/Kconfig +11 -0
index 534fcb8..d832e34 100644
@@ -184,6 +184,17 @@ config CPU_FREQ_GOV_CONSERVATIVE
 
 	  If in doubt, say N.
 
+config CPU_FREQ_GOV_SCHEDPOWER
+	bool "'schedpower' governor/power driver"
+	depends on CPU_FREQ
+	depends on SCHED_POWER
+	help
+	  'schedpower' - this governor allows existing cpufreq drivers to be
+	  used as power driver backend. The governor registers itself as a
+	  power driver with the scheduler and uses the existing cpufreq framework
+	  and drivers to do the actual frequency changes. Frequency selection is
+	  based on scheduler hints provided by the power driver interface.
+
 config GENERIC_CPUFREQ_CPU0
 	tristate "Generic CPU0 cpufreq driver"
 	depends on HAVE_CLK && REGULATOR && PM_OPP && OF
drivers/cpufreq/Makefile +1 -0
index d345b5a..e00a17c 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE)	+= cpufreq_powersave.o
 obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE)	+= cpufreq_userspace.o
 obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND)	+= cpufreq_ondemand.o
 obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE)	+= cpufreq_conservative.o
+obj-$(CONFIG_CPU_FREQ_GOV_SCHEDPOWER)	+= cpufreq_schedpower.o
 obj-$(CONFIG_CPU_FREQ_GOV_COMMON)		+= cpufreq_governor.o
 
 # CPUfreq cross-arch helpers
drivers/cpufreq/cpufreq_schedpower.c new file +207 -0

207 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#23 lore raw

RFC PATCH 7/7 sched: power: Let the power driver choose the best wake-up cpu

In reply to Morten Rasmussen

Adds best_wake_cpu() to the power driver interface allowing the power driver to influence which cpu will be woken up when additional cpus are needed. Currently only a place holder until idle interface is in place.

---
 drivers/cpufreq/cpufreq_schedpower.c |   11 +++++++++++
 include/linux/sched/power.h          |    2 ++
 kernel/sched/fair.c                  |    5 ++++-
 kernel/sched/power.c                 |    9 +++++++++
 kernel/sched/sched.h                 |    6 ++++++
 5 files changed, 32 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq_schedpower.c +11 -0
index 5952c79..62847ca 100644
@@ -187,6 +187,16 @@ int pdriver_go_slower(int cpu, int hint)
 	return 1;
 }
 
+int pdriver_best_wake_cpu(void)
+{
+	/*
+	 * Place holder. Should ideally determine the best cpu to wake up
+	 * when more cpus are needed. This may be based on coupled C-states,
+	 * power domains, and other platform specific factors.
+	 */
+	return nr_cpu_ids;
+}
+
 void pdriver_late_callback(int cpu)
 {
 	struct cpufreq_schedpower_cpuinfo *pcpu_info;
@@ -202,6 +212,7 @@ static struct power_driver pdriver = {
 	.at_max_capacity	= pdriver_at_max_capacity,
 	.go_faster		= pdriver_go_faster,
 	.go_slower		= pdriver_go_slower,
+	.best_wake_cpu		= pdriver_best_wake_cpu,
 	.late_callback		= pdriver_late_callback,
 };
 
include/linux/sched/power.h +2 -0
index aba5f47..5d76f44 100644
@@ -25,6 +25,8 @@ struct power_driver {
 	int (*go_faster)	(int cpu, int hint);
 	/* Decrease cpu capacity hint */
 	int (*go_slower)	(int cpu, int hint);
+	/* Best cpu to wake up */
+	int (*best_wake_cpu)	(void);
 
 	/* Scheduler call-back without rq lock held and with irq enabled */
 	void (*late_callback)	(int cpu);
kernel/sched/fair.c +4 -1
index ee87e65..d32fb97 100644
@@ -5458,7 +5458,10 @@ static struct {
 
 static inline int find_new_ilb(int call_cpu)
 {
-	int ilb = cpumask_first(nohz.idle_cpus_mask);
+	int ilb = best_wake_cpu();
+
+	if (ilb >= nr_cpu_ids)
+		ilb = cpumask_first(nohz.idle_cpus_mask);
 
 	if (ilb < nr_cpu_ids && idle_cpu(ilb))
 		return ilb;
kernel/sched/power.c +9 -0
index f70b563..e1357d2 100644
@@ -11,6 +11,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/cpumask.h>
 #include <linux/sched/power.h>
 
 static struct power_driver *power_driver;
@@ -56,6 +57,14 @@ int go_slower(int cpu, int hint)
 	return power_driver->go_slower(cpu, hint);
 }
 
+int best_wake_cpu(void)
+{
+	if (!power_driver)
+		return nr_cpu_ids;
+
+	return power_driver->best_wake_cpu();
+}
+
 void power_late_callback(int cpu)
 {
 	if (!power_driver)
kernel/sched/sched.h +6 -0
index 88e7968..a368734 100644
@@ -1370,6 +1370,7 @@ extern void power_late_callback(int cpu);
 extern int at_max_capacity(int cpu);
 extern int go_faster(int cpu, int hint);
 extern int go_slower(int cpu, int hint);
+extern int best_wake_cpu(void);
 #else
 static inline void power_late_callback(int cpu)
 {
@@ -1389,4 +1390,9 @@ static inline int go_slower(int cpu, int hint)
 {
 	return 0;
 }
+
+static inline int best_wake_cpu(void)
+{
+	return nr_cpu_ids;
+}
 #endif /* CONFIG_SCHED_POWER */
Signature · 1 line
1.7.9.5
maintainer
#24 lore raw
In reply to Morten Rasmussen
Quoted 23 lines · Morten Rasmussen

Hi,

I have revised the previous power scheduler proposal[1] trying to address as many of the comments as possible. The overall idea was discussed at LPC[2,3]. The revised design has removed the power scheduler and replaced it with a high level power driver interface. An interface that allows the scheduler to query the power driver for information and provide hints to guide power management decisions in the power driver.

The power driver is going to be a unified platform power driver that can replace cpufreq and cpuidle drivers. Generic power policies will be optional helper functions called from the power driver. Platforms may choose to implement their own policies as part of their power driver.

This RFC series prototypes a part of the power driver interface (cpu capacity hints) and shows how they can be used from the scheduler. More extensive use of the power driver hints and queries is left for later. The focus for now is the power driver interface. The patch series includes a power driver/cpufreq governor that can use existing cpufreq drivers as backend. It has been tested (not thoroughly) on ARM TC2. The cpufreq governor power driver implementation is rather horrible, but it illustrates how the power driver interface can be used. Native power drivers is on the todo list.

Quoted 7 lines

The power driver interface is still missing quite a few calls to handle: Idle, adding extra information to the sched_domain hierarchy to guide scheduling decisions (packing), and possibly scaling of tracked load to compensate for frequency changes and asymmetric systems (big.LITTLE).

This set is based on 3.11. I have done ARM TC2 testing based on linux-linaro 2013.08[4] to get cpufreq support for TC2.

What I'm missing is a general overview of why what and how.

In particular; how does this proposal lead to power savings. Is there a mathematical model that supports this framework? Something where if you give it a task set with global utilisation < 1 (ie. there's idle time), it results in less power used.

Also, how does this proposal deal with cpufreq's fundamental broken approach to SMP? Afaict nothing considers the effect of one cpu upon another -- something which isn't true at all.

In fact, I don't see anything except a random bunch of hooks without an over-all picture of how to get less power used.

#25 lore raw
Quoted 32 lines · Peter Zijlstra
Quoted 23 lines · Morten Rasmussen

Hi,

I have revised the previous power scheduler proposal[1] trying to address as many of the comments as possible. The overall idea was discussed at LPC[2,3]. The revised design has removed the power scheduler and replaced it with a high level power driver interface. An interface that allows the scheduler to query the power driver for information and provide hints to guide power management decisions in the power driver.

The power driver is going to be a unified platform power driver that can replace cpufreq and cpuidle drivers. Generic power policies will be optional helper functions called from the power driver. Platforms may choose to implement their own policies as part of their power driver.

This RFC series prototypes a part of the power driver interface (cpu capacity hints) and shows how they can be used from the scheduler. More extensive use of the power driver hints and queries is left for later. The focus for now is the power driver interface. The patch series includes a power driver/cpufreq governor that can use existing cpufreq drivers as backend. It has been tested (not thoroughly) on ARM TC2. The cpufreq governor power driver implementation is rather horrible, but it illustrates how the power driver interface can be used. Native power drivers is on the todo list.

Quoted 7 lines

The power driver interface is still missing quite a few calls to handle: Idle, adding extra information to the sched_domain hierarchy to guide scheduling decisions (packing), and possibly scaling of tracked load to compensate for frequency changes and asymmetric systems (big.LITTLE).

This set is based on 3.11. I have done ARM TC2 testing based on linux-linaro 2013.08[4] to get cpufreq support for TC2.

Quoted 6 lines

What I'm missing is a general overview of why what and how.

In particular; how does this proposal lead to power savings. Is there a mathematical model that supports this framework? Something where if you give it a task set with global utilisation < 1 (ie. there's idle time), it results in less power used.

It is not there yet. What I'm proposing here is just the interface with some very simple examples of how they can be used. It is not the complete set of hooks, but a starting point. In the first round of discussions it was clear that it is quite important to find an interface that can work for everyone. To find a good power optimization model we first need to know what information the platform (represented by the power driver) can provide.

With guidance from the power driver about what level performance we can expect from a cpu, and possibly also the power cost, we can make better load-balancing decisions. We can add task packing support and let the platform decide the degree of packing that meets the power/performance target.

Quoted 4 lines

Also, how does this proposal deal with cpufreq's fundamental broken approach to SMP? Afaict nothing considers the effect of one cpu upon another -- something which isn't true at all.

If you are referring to not doing anything clever with the affected cpus in the power driver then yes. I doesn't do anything clever at the moment. However, the go_faster/slower() interface would allow the power driver to refuse increasing the frequency if the power cost can't be justified for some reason. Using the power driver interface the scheduler will know this and be able to try a different balance. Spread load to other cpus in the same frequency domain that are less loaded, if possible.

Quoted 3 lines

In fact, I don't see anything except a random bunch of hooks without an over-all picture of how to get less power used.

I will follow up with a better description of the overall picture. The slides I linked to are not really self-explaining.

Thanks,
Morten

maintainer
#26 lore raw
Quoted 5 lines · Morten Rasmussen
Quoted 2 lines

In fact, I don't see anything except a random bunch of hooks without an over-all picture of how to get less power used.

I will follow up with a better description of the overall picture. The slides I linked to are not really self-explaining.

I hadn't even noticed there were slides linked. In general I tend to ignore external links -- patches should be descriptive enough to stand on their own.

#27 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 5 lines · Morten Rasmussen
Quoted 2 lines

In fact, I don't see anything except a random bunch of hooks without an over-all picture of how to get less power used.

I will follow up with a better description of the overall picture. The slides I linked to are not really self-explaining.

I hadn't even noticed there were slides linked. In general I tend to ignore external links -- patches should be descriptive enough to stand on their own.

Elaborating a bit more on the big picture and where we can go with this proposal, here are the main requirements:

1. A unified scheduler driven power policy, i.e. the scheduler drives DVFS/idle (as suggested by Ingo and hence this first set of patches).

2. Small task packing. Avoid spreading tasks under light workloads.

In addition for big.LITTLE we need:

3. Task placement based cpu suitability. Associate task load ranges with each cpu to give task placement. Heavy tasks on big, small tasks on little.

This patch set addresses part of 1, while 3 will follow soon. Point 2 is worked on by Vincent in collaboration with us.

The power driver introduced in this set has a role in the solution to all three points. It serves as a unified platform power driver and the interface allows the scheduler to get highlevel feedback which cpufreq and cpuidle do not currently provide.

Decisions about the power/performance trade-off will be made in the power driver guided by the hints from the scheduler. That allow platforms the freedom to do what they want with the hints including ignoring them completely (taking Arjan's previous comments into account). It will make the power driver much powerful than the current cpufreq/cpuidle drivers.

Morten

#28 lore raw
In reply to Peter Zijlstra

Hi,

Quoted 29 lines · Peter Zijlstra
Quoted 28 lines · Morten Rasmussen

Hi,

I have revised the previous power scheduler proposal[1] trying to address as many of the comments as possible. The overall idea was discussed at LPC[2,3]. The revised design has removed the power scheduler and replaced it with a high level power driver interface. An interface that allows the scheduler to query the power driver for information and provide hints to guide power management decisions in the power driver.

The power driver is going to be a unified platform power driver that can replace cpufreq and cpuidle drivers. Generic power policies will be optional helper functions called from the power driver. Platforms may choose to implement their own policies as part of their power driver.

This RFC series prototypes a part of the power driver interface (cpu capacity hints) and shows how they can be used from the scheduler. More extensive use of the power driver hints and queries is left for later. The focus for now is the power driver interface. The patch series includes a power driver/cpufreq governor that can use existing cpufreq drivers as backend. It has been tested (not thoroughly) on ARM TC2. The cpufreq governor power driver implementation is rather horrible, but it illustrates how the power driver interface can be used. Native power drivers is on the todo list.

The power driver interface is still missing quite a few calls to handle: Idle, adding extra information to the sched_domain hierarchy to guide scheduling decisions (packing), and possibly scaling of tracked load to compensate for frequency changes and asymmetric systems (big.LITTLE).

Quoted 4 lines
Quoted 2 lines

This set is based on 3.11. I have done ARM TC2 testing based on linux-linaro 2013.08[4] to get cpufreq support for TC2.

What I'm missing is a general overview of why what and how.

I agree that the "why" needs to be mentioned very clearly since the patchset revolves around it. As far as I understand we need a single controller for deciding the power efficiency of the kernel, who is exposed to all the user policies and the frequency+idle states stats of the CPU to begin with. These stats are being supplied by the power driver.

Having these details and decision making in multiple places like we do today in cpuidle, cpu-frequency and scheduler will probably cause problems. For example, when the power efficiency of the kernel goes wrong we have trouble point out the reason behind it. Where did the problem arise from among the above three power policy decision makers? This is a maintainability concern.
Another reason is the power saving decisions made by say cpuidle may
not complement the power saving decisions made by cpufreq. This can lead to inconsistent results across different workloads.

Thus having a single policy maker for power savings we are hoping to solve the primary concerns of consistent behaviour from the kernel in terms of power efficiency and improved maintainability.

Quoted 5 lines

In particular; how does this proposal lead to power savings. Is there a mathematical model that supports this framework? Something where if you give it a task set with global utilisation < 1 (ie. there's idle time), it results in less power used.

AFAIK, this patchset is an attempt to achieve consistency in the power efficiency of the kernel across workloads with the existing algorithms, in addition to a cleanup involving integration of the power policy making in one place as explained above. In an attempt to do so, *maybe* better power numbers can be obtained or at-least the default power efficiency of the kernel will show up.

However adding the new patchsets like packing small tasks, heterogeneous scheduling, power aware scheduling etc.. *should* then yield good and consistent power savings since they now stand on top of an integrated stable power driver.

Regards
Preeti U Murthy

Quoted 8 lines

Also, how does this proposal deal with cpufreq's fundamental broken approach to SMP? Afaict nothing considers the effect of one cpu upon another -- something which isn't true at all.

In fact, I don't see anything except a random bunch of hooks without an over-all picture of how to get less power used.