Intelligent power sharing driver
This patchset adds the core IPS driver to drivers/platform/x86, along with some helper code in the timer subsystem to allow for deferrable on-stack timers.
Note that the deferrable timers don't actually work at this point; I'm probably just doing something silly in the IPS driver in using them, but it's possible the core code is wrong too, I'm hoping for some review there (so testing thus far has been with a fixed sample rate).
Also note that this patchset doesn't include the i915 specific bits for monitoring power consumption; I'm still debugging those (my current platform overreports power by several watts; I'm hoping a production platform will return reasonable values) but expect to be able to post them soon. With the combination of this driver and the i915 code, I expect significant GPU performance gains; early measurements with simple loads show about a 15% improvement, but I've heard reports of even higher.
Anyway, please take a look and let me know what needs fixing or how I might make this a better driver.
Thanks,
Jesse
PATCH 1/2 timer: add on-stack deferrable timer interfaces
In some cases (for instance with kernel threads) it may be desireable to use on-stack deferrable timers to get their power saving benefits. Add interfaces to support this for the IPS driver.
--- include/linux/timer.h | 15 +++++++++++++++ kernel/timer.c | 13 +++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-)
include/linux/timer.h +15 -0
@@ -94,6 +94,13 @@ void init_timer_deferrable_key(struct timer_list *timer, setup_timer_on_stack_key((timer), #timer, &__key, \ (fn), (data)); \ } while (0) +#define setup_deferrable_timer_on_stack (timer, fn, data) \ + do { \ + static struct lock_class_key __key; \ + setup_deferrable_timer_on_stack_key((timer), #timer, \ + &__key, (fn), \ + (data)); \ + } while (0)#else #define init_timer (timer)\ init_timer_key((timer), NULL, NULL)
@@ -105,6 +112,8 @@ void init_timer_deferrable_key(struct timer_list *timer, setup_timer_key((timer), NULL, NULL, (fn), (data))#define setup_timer_on_stack (timer, fn, data)\ setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) +#define setup_deferrable_timer_on_stack (timer, fn, data)\ + setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data))#endif #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
@@ -144,6 +153,12 @@ static inline void setup_timer_on_stack_key(struct timer_list *timer,init_timer_on_stack_key (timer, name, key); } +extern void setup_deferrable_timer_on_stack_key (struct timer_list *timer, +const char *name, +struct lock_class_key *key, +void (*function)(unsigned long ), +unsigned long data); +/** * timer_pending - is a timer pending? * @timer: the timer in question
kernel/timer.c +13 -0
@@ -557,6 +557,19 @@ static void __init_timer(struct timer_list *timer,lockdep_init_map (&timer->lockdep_map, name, key,0 ); } +void setup_deferrable_timer_on_stack_key (struct timer_list *timer, +const char *name, +struct lock_class_key *key, +void (*function)(unsigned long ), +unsigned long data) +{ + timer->function = function; + timer->data = data; +init_timer_on_stack_key (timer, name, key); +timer_set_deferrable (timer); +} +EXPORT_SYMBOL_GPL (setup_deferrable_timer_on_stack_key); +/** * init_timer_key - initialize a timer * @timer: the timer to be initialized
Signature · 1 line
1.6.3.3
PATCH 2/2 x86 platform driver: intelligent power sharing driver
In reply to Jesse BarnesIntel Core i3/5 platforms with integrated graphics support both CPU and GPU turbo mode. CPU turbo mode is opportunistic: the CPU will use any available power to increase core frequencies if thermal headroom is available. The GPU side is more manual however; the graphics driver must monitor GPU power and temperature and coordinate with a core thermal driver to take advantage of available thermal and power headroom in the package.
The intelligent power sharing (IPS) driver is intended to coordinate this activity by monitoring MCP (multi-chip package) temperature and power, allowing the CPU and/or GPU to increase their power consumption, and thus performance, when possible. The goal is to maximize performance within a given platform's TDP (thermal design point).
--- drivers/platform/x86/Kconfig | 10 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ips.c | 1638 ++++++++++++++++++++++++++++++++++++++ include/drm/i915_drm.h | 9 + 4 files changed, 1658 insertions(+), 0 deletions(-) create mode 100644 drivers/platform/x86/intel_ips.c
drivers/platform/x86/Kconfig +10 -0
@@ -505,4 +505,14 @@ config ACPI_CMPC keys as input device, backlight device, tablet and accelerometer devices. +config INTEL_IPS + tristate "Intel Intelligent Power Sharing" + depends on ACPI + ---help--- + Intel Calpella platforms support dynamic power sharing between the + CPU and GPU, maximizing performance in a given TDP. This driver, + along with the CPU frequency and i915 drivers, provides that + functionality. If in doubt, say Y here; it will only load on + supported platforms. + endif # X86_PLATFORM_DEVICES
drivers/platform/x86/Makefile +1 -0
@@ -24,3 +24,4 @@ obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o +obj-$(CONFIG_INTEL_IPS) += intel_ips.o
drivers/platform/x86/intel_ips.c new file +1638 -0
1,638 lines not on this page · raw message
include/drm/i915_drm.h +9 -0
@@ -33,6 +33,15 @@* subject to backwards-compatibility constraints. */ +#ifdef __KERNEL__ +/* For use by IPS driver */ +extern unsigned long i915_read_mch_val (void ); +extern bool i915_gpu_raise (void ); +extern bool i915_gpu_lower (void ); +extern bool i915_gpu_busy (void ); +extern bool i915_gpu_turbo_disable (void ); +#endif +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 1 line
1.6.3.3
Re: [PATCH 2/2] x86 platform driver: intelligent power sharing driver
Hi!
Quoted 7 lines
Intel Core i3/5 platforms with integrated graphics support both CPU and GPU turbo mode. CPU turbo mode is opportunistic: the CPU will use any available power to increase core frequencies if thermal headroom is available. The GPU side is more manual however; the graphics driver must monitor GPU power and temperature and coordinate with a core thermal driver to take advantage of available thermal and power headroom in the package.
Interesting...
Quoted 1 line
+ * Copyright Š 2009-2010 Intel Corporation
AC?
Quoted 6 lines
+ * The basic algorithm is driven by a 5s moving average of tempurature. If
+ * thermal headroom is available, the CPU and/or GPU power clamps may be
+ * adjusted upwards. If we hit the thermal ceiling or a thermal trigger,
+ * we scale back the clamp. Aside from trigger events (when we're critically
+ * close or over our TDP) we don't adjust the clamps more than once every
+ * five seconds.
Ok, if this driver screws up will
a) cpu/gpu protect itself from damage by overheat?
b) cpu/gpu protect itself from incorrect operation resulting from overtemp?
Quoted 6 lines
+ * Related documents:
+ * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2 + * - CDI 401376 - Ibex Peak EDS + * - ref 26037, 26641 - IPS BIOS spec + * - ref 26489 - Nehalem BIOS writer's guide + * - ref 26921 - Ibex Peak BIOS Specification
http references would be nice.
Review
Quoted 1 line
(quoted diff) +1
-0+ int core_temp_limit; /* °C */
AdegreesC? (More then one instance; avoid unicode?)
Quoted 6 lines
drivers/platform/x86/intel_ips.c new file +6
-0+/** +* ips_cpu_busy - is CPU busy? +* @ips: IPS driver struct +* +* Check CPU for load to see whether we should increase its thermal budget. +*
drivers/platform/x86/intel_ips.c line 358
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+* RETURNS: +* True if the CPU could use more power, false otherwise. +*/ +static bool ips_cpu_busy (struct ips_driver *ips) +{ +if ((avenrun[0 ] >>FSHIFT ) >1 ) +return true; + +return false; +}
return (averun > 1); ?
But this is wrong test, anyway. One process waiting for disk, and you have D state and load average > 1, without cpu load.
Quoted 44 lines
drivers/platform/x86/intel_ips.c new file +44
-0+/** +* ips_enable_cpu_turbo - enable turbo mode on all CPUs +* @ips: IPS driver struct +* +* Enable turbo mode by clearing the disable bit in IA32_PERF_CTL on +* all logical threads. +*/ +static void ips_enable_cpu_turbo (struct ips_driver *ips) +{ +/* Already on, no need to mess with MSRs */ +if (ips->__cpu_turbo_on) +return ; + +on_each_cpu (do_enable_cpu_turbo, ips,1 ); + + ips->__cpu_turbo_on = true; +} + +/** +* do_disable_cpu_turbo - internal turbo disable function +* @data: unused +* +* Internal function for actually updating MSRs. When we enable/disable +* turbo, we need to do it on each CPU; this function is the one called +* by on_each_cpu() when needed. +*/ +static void do_disable_cpu_turbo (void *data) +{ +u64 perf_ctl; + +rdmsrl (IA32_PERF_CTL , perf_ctl); +if (!(perf_ctl &IA32_PERF_TURBO_DIS )) { + perf_ctl |=IA32_PERF_TURBO_DIS ; +wrmsrl (IA32_PERF_CTL , perf_ctl); + } +} + +/** +* ips_disable_cpu_turbo - disable turbo mode on all CPUs +* @ips: IPS driver struct +* +* Disable turbo mode by setting the disable bit in IA32_PERF_CTL on +* all logical threads. +*/
drivers/platform/x86/intel_ips.c line 505
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+static void ips_disable_cpu_turbo (struct ips_driver *ips) +{ +/* Already off, leave it */ +if (!ips->__cpu_turbo_on) +return ; + +on_each_cpu (do_disable_cpu_turbo, ips,1 ); + + ips->__cpu_turbo_on = false; +}
Merge above four functions into two, by having 'enable' parameter?
Wha tprotects you against races?
Quoted 4 lines
drivers/platform/x86/intel_ips.c new file +4
-0+/** +* ips_gpu_busy - is GPU busy? +* @ips: IPS driver struct +*
drivers/platform/x86/intel_ips.c line 520
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+* Check GPU for load to see whether we should increase its thermal budget. +* We need to call into the i915 driver in this case. +* +* RETURNS: +* True if the GPU could use more power, false otherwise. +*/ +static bool ips_gpu_busy (struct ips_driver *ips) +{ +return false; +}
Uh ouch :-).
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+/** +* mcp_exceeded - check whether we're outside our thermal & power limits +* @ips: IPS driver struct +* +* Check whether the MCP is over its thermal or power budget. +*/ +static bool mcp_exceeded (struct ips_driver *ips) +{ +unsigned long flags; +bool ret = false;
drivers/platform/x86/intel_ips.c line 608
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+ +spin_lock_irqsave (&ips->turbo_status_lock, flags); +if (ips->mcp_avg_temp > (ips->mcp_temp_limit *100 )) + ret = true; +if (ips->cpu_avg_power + ips->mch_avg_power > ips->mcp_power_limit) + ret = true; +spin_unlock_irqrestore (&ips->turbo_status_lock, flags); + +return ret; +}
...and printk(kern_crit, as this should never happen?)
Quoted 13 lines
drivers/platform/x86/intel_ips.c new file +13
-0+/** +* cpu_exceeded - check whether a CPU core is outside its limits +* @ips: IPS driver struct +* @cpu: CPU number to check +* +* Check a given CPU's average temp or power is over its limit. +*/ +static bool cpu_exceeded (struct ips_driver *ips,int cpu) +{ +unsigned long flags; +int avg; +bool ret = false; +
drivers/platform/x86/intel_ips.c line 632
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+spin_lock_irqsave (&ips->turbo_status_lock, flags); + avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; +if (avg > (ips->limits->core_temp_limit *100 )) + ret = true; +if (ips->cpu_avg_power > ips->core_power_limit) + ret = true; +spin_unlock_irqrestore (&ips->turbo_status_lock, flags); + +return ret; +}
printk?
Does this have hard limit for 2 cores?
drivers/platform/x86/intel_ips.c line 649
Quoted 2 lines
drivers/platform/x86/intel_ips.c new file +2
-0+// if (ips->mch_avg_power > ips->mch_power_limit) +// ret = true;
remove.
drivers/platform/x86/intel_ips.c line 722
Quoted 5 lines
drivers/platform/x86/intel_ips.c new file +5
-0+dev_dbg (&ips->dev->dev,"starting ips-adjust thread\n" ); + +/* +*/ + do {
?
Quoted 8 lines
drivers/platform/x86/intel_ips.c new file +8
-0+static u32 get_cpu_power (struct ips_driver *ips,u32 *last,int period) +{ +u32 val; +u32 ret; + +/* +* CEC is in joules/65535. Take difference over time to +* get watts.
drivers/platform/x86/intel_ips.c line 848
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+*/ + val =thm_readl (THM_CEC ); + +/* period is in ms and we want mW */ + ret = (((val - *last) *1000 ) / period); + ret = (ret *1000 ) /65535 ; + *last = val; + +return ret; +}
I wonder if we should have milliwatt_t, msec_t and similar, to aid with type checking...
drivers/platform/x86/intel_ips.c line 1178
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+static int show_cpu_temp (struct seq_file *m,void *data) +{ +struct ips_driver *ips = m->private; + +seq_printf (m,"%d.%d°C\n" , ips->ctv1_avg_temp /100 , + ips->ctv1_avg_temp %100 ); + +return 0 ; +} +
Please no unicode at least in user interfaces. Ouch and it is subtly wrong. You really want "%d.%02d".
Ok, interesting. What kind of speedup can it bring?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 2/2] x86 platform driver: intelligent power sharing driver
Quoted 10 lines · On Tue, 13 Apr 2010 21:24:53 +0200 Pavel Machek <[email protected]> wrote:
Hi!
Quoted 7 lines
Intel Core i3/5 platforms with integrated graphics support both CPU and GPU turbo mode. CPU turbo mode is opportunistic: the CPU will use any available power to increase core frequencies if thermal headroom is available. The GPU side is more manual however; the graphics driver must monitor GPU power and temperature and coordinate with a core thermal driver to take advantage of available thermal and power headroom in the package.
Quoted 5 lines
Interesting...
Quoted 1 line
+ * Copyright Š 2009-2010 Intel Corporation
AC?
Bad character set I guess. I'll just change it to (c).
Quoted 8 lines
Quoted 7 lines
+ * The basic algorithm is driven by a 5s moving average of tempurature. If
+ * thermal headroom is available, the CPU and/or GPU power clamps may be
+ * adjusted upwards. If we hit the thermal ceiling or a thermal trigger,
+ * we scale back the clamp. Aside from trigger events (when we're critically
+ * close or over our TDP) we don't adjust the clamps more than once every
+ * five seconds.
Quoted 6 lines
Ok, if this driver screws up will
a) cpu/gpu protect itself from damage by overheat?
b) cpu/gpu protect itself from incorrect operation resulting from overtemp?
The CPU will end up throttling itself, reducing performance to keep within its power budget. The GPU will just end up hanging if it overheats, but shouldn't be damaged.
Quoted 9 lines
Quoted 7 lines
+ * Related documents:
+ * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2 + * - CDI 401376 - Ibex Peak EDS + * - ref 26037, 26641 - IPS BIOS spec + * - ref 26489 - Nehalem BIOS writer's guide + * - ref 26921 - Ibex Peak BIOS Specificationhttp references would be nice.
They would be, but these docs are only available under NDA. If you have a sales or technical contact you can use the numbers here to get the right docs.
Quoted 4 lines
return (averun > 1); ?
But this is wrong test, anyway. One process waiting for disk, and you have D state and load average > 1, without cpu load.
Yes, I'm happy to have a better test here. Not that it matters *too* much though; we'll allocate more power budget to the CPU, but it will only use it if needed. Allocating it more power just gives the turbo boost capability additional frequency bins. The CPU won't actually use those bins unless it detects that it can and will provide some benefit.
Quoted 58 lines
Quoted 45 lines
drivers/platform/x86/intel_ips.c new file +44
-0+/** +* ips_enable_cpu_turbo - enable turbo mode on all CPUs +* @ips: IPS driver struct +* +* Enable turbo mode by clearing the disable bit in IA32_PERF_CTL on +* all logical threads. +*/ +static void ips_enable_cpu_turbo (struct ips_driver *ips) +{ +/* Already on, no need to mess with MSRs */ +if (ips->__cpu_turbo_on) +return ; + +on_each_cpu (do_enable_cpu_turbo, ips,1 ); + + ips->__cpu_turbo_on = true; +} + +/** +* do_disable_cpu_turbo - internal turbo disable function +* @data: unused +* +* Internal function for actually updating MSRs. When we enable/disable +* turbo, we need to do it on each CPU; this function is the one called +* by on_each_cpu() when needed. +*/ +static void do_disable_cpu_turbo (void *data) +{ +u64 perf_ctl; + +rdmsrl (IA32_PERF_CTL , perf_ctl); +if (!(perf_ctl &IA32_PERF_TURBO_DIS )) { + perf_ctl |=IA32_PERF_TURBO_DIS ; +wrmsrl (IA32_PERF_CTL , perf_ctl); + } +} + +/** +* ips_disable_cpu_turbo - disable turbo mode on all CPUs +* @ips: IPS driver struct +* +* Disable turbo mode by setting the disable bit in IA32_PERF_CTL on +* all logical threads. +*/ drivers/platform/x86/intel_ips.c line 505
Quoted 10 lines
drivers/platform/x86/intel_ips.c new file +10
-0+static void ips_disable_cpu_turbo (struct ips_driver *ips) +{ +/* Already off, leave it */ +if (!ips->__cpu_turbo_on) +return ; + +on_each_cpu (do_disable_cpu_turbo, ips,1 ); + + ips->__cpu_turbo_on = false; +}Merge above four functions into two, by having 'enable' parameter?
Quoted 1 line
Wha tprotects you against races?
Accesses to these should be protected by the parameter lock. And I have two variables to differentiate between the hardware being enabled vs. the software requesting an enable/disable. They could probably be named more clearly.
Quoted 8 lines
Quoted 8 lines
+/**
+ *ips_gpu_busy- is GPU busy?
+ * @ips: IPS driver struct
+ *
+ * Check GPU for load to see whether we should increase its thermal budget.
+ * We need to call into the i915 driver in this case.
+ *
+ * RETURNS:
Quoted 8 lines
drivers/platform/x86/intel_ips.c line 520
Quoted 6 lines
+ * True if the GPU could use more power, false otherwise.
+ */drivers/platform/x86/intel_ips.c new file +4
-0+static bool ips_gpu_busy (struct ips_driver *ips) +{ +return false; +}Uh ouch :-).
This part is useless without the corresponding GPU power patch; that'll add the proper hooks and callbacks here.
Quoted 14 lines
Quoted 14 lines
drivers/platform/x86/intel_ips.c new file +14
-0+/** +* mcp_exceeded - check whether we're outside our thermal & power limits +* @ips: IPS driver struct +* +* Check whether the MCP is over its thermal or power budget. +*/ +static bool mcp_exceeded (struct ips_driver *ips) +{ +unsigned long flags; +bool ret = false; + +spin_lock_irqsave (&ips->turbo_status_lock, flags); +if (ips->mcp_avg_temp > (ips->mcp_temp_limit *100 )) + ret = true;
Quoted 8 lines
drivers/platform/x86/intel_ips.c line 608
Quoted 6 lines
drivers/platform/x86/intel_ips.c new file +6
-0+if (ips->cpu_avg_power + ips->mch_avg_power > ips->mcp_power_limit) + ret = true; +spin_unlock_irqrestore (&ips->turbo_status_lock, flags); + +return ret; +}...and
printk(kern_crit, as this should never happen?)
Probably wouldn't hurt; but I've given myself some leeway here; if we're near the limit I'd like this check to return true and forcibly throttle things back, just to make extra sure we don't go over budget. On most standard voltage platforms this won't really matter, but on tightly designed ultra-low voltage platforms it's important we never hit the limit.
Quoted 3 lines
printk?
Does this have hard limit for 2 cores?
Yes, I don't believe we'll be doing 4 core Arrandale MCPs. And follow-on chips won't need this driver.
Quoted 7 lines
drivers/platform/x86/intel_ips.c line 649
Quoted 4 lines
drivers/platform/x86/intel_ips.c new file +2
-0+// if (ips->mch_avg_power > ips->mch_power_limit) +// ret = true; remove.
Quoted 7 lines
drivers/platform/x86/intel_ips.c line 722
Quoted 5 lines
drivers/platform/x86/intel_ips.c new file +5
-0+dev_dbg (&ips->dev->dev,"starting ips-adjust thread\n" ); + +/* +*/ + do {?
What my blank comment wasn't clear? :)
Quoted 14 lines
Quoted 14 lines
drivers/platform/x86/intel_ips.c new file +13
-0+static u32 get_cpu_power (struct ips_driver *ips,u32 *last,int period) +{ +u32 val; +u32 ret; + +/* +* CEC is in joules/65535. Take difference over time to +* get watts. +*/ + val =thm_readl (THM_CEC ); + +/* period is in ms and we want mW */ + ret = (((val - *last) *1000 ) / period);
Quoted 8 lines
drivers/platform/x86/intel_ips.c line 848
Quoted 5 lines
drivers/platform/x86/intel_ips.c new file +5
-0+ ret = (ret *1000 ) /65535 ; + *last = val; + +return ret; +}I wonder if we should have
milliwatt_t,msec_tand similar, to aid with type checking...
Yeah, keeping track of units better would be handy.
Quoted 15 lines
drivers/platform/x86/intel_ips.c line 1178
Quoted 11 lines
drivers/platform/x86/intel_ips.c new file +10
-0+static int show_cpu_temp (struct seq_file *m,void *data) +{ +struct ips_driver *ips = m->private; + +seq_printf (m,"%d.%d°C\n" , ips->ctv1_avg_temp /100 , + ips->ctv1_avg_temp %100 ); + +return 0 ; +} +Please no unicode at least in user interfaces. Ouch and it is subtly wrong. You really want "%d.%02d".
Quoted 1 line
Ok, interesting. What kind of speedup can it bring?
For the CPU the perf upside isn't that great, maybe 5% or so, and only with very specific workloads that take advantage of turbo boost. For graphics the upside is significant, at least 15% in my basic tests so far, but Eric and Keith have measured 3x gains in some cases.
Signature · 5 lines
Jesse Barnes, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx