Power Capping Framework and RAPL Driver
Subsystems (4)
v2 cover Power Capping Framework and RAPL Driver
This series was sent to Linux kernel mailing list on August 7th, 2013. Posting to Linux PM mailing list for wider audience, without any change.
Overview
With the evolution of technologies, which enables power monitoring and limiting, more and more devices are able to constrain their power consumption under certain limits. There are several use cases for such technologies:
- Power monitoring: Each device can report its power consumption.
- Power Limiting: Setting power limits on the devices allows users to guard against platform reaching max system power level.
- Maximize performance: While staying below a power limit, it allows devices to automatically adjust performance to meet demands
- Dynamic control and re-budgeting: If each device can be constrained to some power, extra power can redistributed to other devices, which needs additional performance.
One such example of technology is RAPL (Running Average Power Limit) mechanism available in the latest Intel Processors. Intel is slowly adding many devices under RAPL control. Also there are other technologies available, for power capping various devices. Soon it is very likely that other vendors are also adding or considering such implementation.
Power Capping framework is an effort to have a uniform interface available to Linux drivers, which will enable
- A uniform sysfs interface for all devices which can offer power capping
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.
Also submitting Intel RAPL driver using power capping framework.
Revisions:
v02:
Sign-offs and reviewed-by tags
Stylistic issues suggested by Joe Perches
Removed "counter" from power_uw documentation as pointed by Jonathan Corbet Submitting Intel RAPL driver using power capping framework
v01:
Use device model only to register zones and controllers.
v00:
Presented options
Jacob Pan (2):
x86/msr: add 64bit _on_cpu access functions
Introduce Intel RAPL power capping driver
Srinivas Pandruvada (3):
PowerCap: Documentation
PowerCap: Add class driver
PowerCap: Added to drivers build
Documentation/ABI/testing/sysfs-class-powercap | 165 +++ Documentation/powercap/PowerCappingFramework.txt | 686 ++++++++++++ arch/x86/include/asm/msr.h | 22 + arch/x86/lib/msr-smp.c | 62 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/powercap/Kconfig | 24 + drivers/powercap/Makefile | 6 + drivers/powercap/intel_rapl.c | 1305 ++++++++++++++++++++++ drivers/powercap/powercap_sys.c | 995 +++++++++++++++++ include/linux/powercap.h | 300 +++++ 11 files changed, 3568 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-powercap create mode 100644 Documentation/powercap/PowerCappingFramework.txt create mode 100644 drivers/powercap/Kconfig create mode 100644 drivers/powercap/Makefile create mode 100644 drivers/powercap/intel_rapl.c create mode 100644 drivers/powercap/powercap_sys.c create mode 100644 include/linux/powercap.h
Signature · 1 line
1.8.3.1
RFC v2 1/5 PowerCap: Documentation
Added power cap framework documentation. This explains the use of power capping framework, sysfs and programming interface.
There are two documents:Documentation/powercap/PowerCappingFramework.txt: Explains use case and API in details.Documentation/ABI/testing/sysfs-class-powercap: Explains ABIs.
--- Documentation/ABI/testing/sysfs-class-powercap | 165 ++++++ Documentation/powercap/PowerCappingFramework.txt | 686 +++++++++++++++++++++++ 2 files changed, 851 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-powercap create mode 100644 Documentation/powercap/PowerCappingFramework.txt
Documentation/ABI/testing/sysfs-class-powercap new file +165 -0
@@ -0,0 +1,165 @@ +What: /sys/class/power_cap/ +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + The power_cap/ class sub directory belongs to the power cap + subsystem. Refer to + Documentation/powercap/PowerCappingFramework.txt for details. + +What: /sys/class/power_cap/controller_name +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + The /sys/class/power_cap/controller_name directories correspond + to each controller under power_cap control. Here controller_name + is a unique name under /sys/class_power_cap. Each + controller_name directory contains one or more power zones. + +What: /sys/class/power_cap/controller_name/type +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + For controller type is "controller". This allows user space + to differentiate between a controller device from a power zone + device. + +What: /sys/class/power_cap/controller_name/power_zone +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + A Controller can have one or more power zones. A power zone is + an abstraction of devices, which can be independently monitored + and controlled. + +What: /sys/class/power_cap/controller_name/power_zone/power_zone +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + A power zone can have one or more power zones as children. + This child power zone provides monitoring and control for + a subset of device under parent. E.g. if there is parent + power zone for whole CPU package, each CPU cores in it can be + a child power zone. + +What: /sys/class/power_cap/controller_name/power_zone/name +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Specifies the name of this power zone. + + +What: /sys/class/power_cap/controller_name/power_zone/type +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + For power zone type is "power-zone". + + +What: /sys/class/power_cap/controller_name/power_zone/energy_uj +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Current energy counter in micro-joules. Write "0" to reset. + If the counter can not be reset, then this attribute is + read-only. + +What: /sys/class/power_cap/controller_name/power_zone/ + max_energy_range_uj +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Range of the above energy counter in micro-joules. + + +What: /sys/class/power_cap/controller_name/power_zone/power_uw +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Current power in micro-watts. Write "0" to reset. + If the value can not be reset, then the attribute is read + only. + +What: /sys/class/power_cap/controller_name/power_zone/ + max_power_range_uw +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Range of the above power value in micro-watts. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_name +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Each power zone can define one or more constraints. Each + constraint can have optional name. Here "X" can have values + from 0 to max integer. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_power_limit_uw +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Power limit in micro-watts, which should be applicable for + the time window specified by "constraint_X_time_window_us". + Here "X" can have values from 0 to max integer. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_time_window_us +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Time window in micro seconds. This is used along with + constraint_X_power_limit_uw to define a power constraint. + Here "X" can have values from 0 to max integer. + + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_max_power_uw +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Maximum allowed power in micro watts for this constraint. + Here "X" can have values from 0 to max integer. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_min_power_uw +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Minimum allowed power in micro watts for this constraint. + Here "X" can have values from 0 to max integer. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_max_time_window_us +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Maximum allowed time window in micro seconds for this + constraint. Here "X" can have values from 0 to max integer. + +What: /sys/class/power_cap/controller_name/power_zone/ + constraint_X_min_time_window_us +Date: August 2013 +KernelVersion: 3.12 +Contact: [email protected] +Description: + Minimum allowed time window in micro seconds for this + constraint. Here "X" can have values from 0 to max integer.
Documentation/powercap/PowerCappingFramework.txt new file +686 -0
686 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC v2 2/5 PowerCap: Add class driver
In reply to Srinivas PandruvadaAdded power cap class driver, which provides an API for client drivers to use and provide a consistant sysfs interface to user mode. For details on API refer to PowerCappingFramework.txt under Documentation/powercap.
--- drivers/powercap/Kconfig | 16 + drivers/powercap/Makefile | 5 + drivers/powercap/powercap_sys.c | 995 ++++++++++++++++++++++++++++++++++++++++ include/linux/powercap.h | 300 ++++++++++++ 4 files changed, 1316 insertions(+) create mode 100644 drivers/powercap/Kconfig create mode 100644 drivers/powercap/Makefile create mode 100644 drivers/powercap/powercap_sys.c create mode 100644 include/linux/powercap.h
drivers/powercap/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# +# Generic powercap sysfs drivers configuration +# + +menuconfig POWERCAP_SUPPORT + tristate "Generic powercap sysfs driver" + help + A Power Capping Sysfs driver offers a generic mechanism for + power capping. Usually it's made up of one or more controllers, + power zones and constraints. + If you want this support, you should say Y or M here. + +if POWERCAP_SUPPORT +# Add client driver config here. + +endif
drivers/powercap/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for powercap drivers +# + +obj-$(CONFIG_POWERCAP_SUPPORT) += powercap_sys.o
drivers/powercap/powercap_sys.c new file +995 -0
995 lines not on this page · raw message
include/linux/powercap.h new file +300 -0
300 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC v2 3/5 PowerCap: Added to drivers build
In reply to Srinivas PandruvadaAdded changes to Makefile and Kconfig to include in driver build.
--- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + 2 files changed, 3 insertions(+)
drivers/Kconfig +2 -0
@@ -166,4 +166,6 @@ source "drivers/ipack/Kconfig" source "drivers/reset/Kconfig" +source "drivers/powercap/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -152,3 +152,4 @@ obj-$(CONFIG_IIO) += iio/ obj-$(CONFIG_VME_BUS) += vme/ obj-$(CONFIG_IPACK_BUS) += ipack/ obj-$(CONFIG_NTB) += ntb/ +obj-$(CONFIG_POWERCAP_SUPPORT) += powercap/
Signature · 1 line
1.8.3.1
RFC v2 4/5 x86/msr: add 64bit _on_cpu access functions
In reply to Srinivas PandruvadaFrom: Jacob Pan <[email protected]>
Having 64-bit MSR access methods on given CPU can avoid shifting and simplify MSR content manipulation. We already have other combinations of rdmsrl_xxx and wrmsrl_xxx but missing the _on_cpu version.
--- arch/x86/include/asm/msr.h | 22 ++++++++++++++++ arch/x86/lib/msr-smp.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+)
arch/x86/include/asm/msr.h +22 -0
@@ -218,10 +218,14 @@ void msrs_free(struct msr *msrs);#ifdef CONFIG_SMP int rdmsr_on_cpu (unsigned int cpu,u32 msr_no,u32 *l,u32 *h);int wrmsr_on_cpu (unsigned int cpu,u32 msr_no,u32 l,u32 h); +int rdmsrl_on_cpu (unsigned int cpu,u32 msr_no,u64 *q); +int wrmsrl_on_cpu (unsigned int cpu,u32 msr_no,u64 q);void rdmsr_on_cpus (const struct cpumask *mask,u32 msr_no,struct msr *msrs);void wrmsr_on_cpus (const struct cpumask *mask,u32 msr_no,struct msr *msrs);int rdmsr_safe_on_cpu (unsigned int cpu,u32 msr_no,u32 *l,u32 *h);int wrmsr_safe_on_cpu (unsigned int cpu,u32 msr_no,u32 l,u32 h); +int rdmsrl_safe_on_cpu (unsigned int cpu,u32 msr_no,u64 *q); +int wrmsrl_safe_on_cpu (unsigned int cpu,u32 msr_no,u64 q);int rdmsr_safe_regs_on_cpu (unsigned int cpu,u32 regs[8 ]);int wrmsr_safe_regs_on_cpu (unsigned int cpu,u32 regs[8 ]);#else /* CONFIG_SMP */
@@ -235,6 +239,16 @@ static inline int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)wrmsr (msr_no, l, h);return 0 ; } +static inline int rdmsrl_on_cpu (unsigned int cpu,u32 msr_no,u64 *q) +{ +rdmsrl (msr_no, *q); +return 0 ; +} +static inline int wrmsrl_on_cpu (unsigned int cpu,u32 msr_no,u64 q) +{ +wrmsrl (msr_no, q); +return 0 ; +}static inline void rdmsr_on_cpus (const struct cpumask *m,u32 msr_no,struct msr *msrs) {
@@ -254,6 +268,14 @@ static inline int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) {return wrmsr_safe (msr_no, l, h); } +static inline int rdmsrl_safe_on_cpu (unsigned int cpu,u32 msr_no,u64 *q) +{ +return rdmsrl_safe (msr_no, q); +} +static inline int wrmsrl_safe_on_cpu (unsigned int cpu,u32 msr_no,u64 q) +{ +return wrmsrl_safe (msr_no, q); +}static inline int rdmsr_safe_regs_on_cpu (unsigned int cpu,u32 regs[8 ]) {return rdmsr_safe_regs (regs);
arch/x86/lib/msr-smp.c +62 -0
80 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC v2 5/5 Introduce Intel RAPL power capping driver
In reply to Srinivas PandruvadaFrom: Jacob Pan <[email protected]>
RAPL(Running Average Power Limit) interface provides platform software with the ability to monitor, control, and get notifications on SOC power consumptions. Since its first appearance on Sandy Bridge, more features have being added to extend its usage. In RAPL, platforms are divided into domains for fine grained control. These domains include package, DRAM controller, CPU core (Power Plane 0), graphics uncore (power plane 1), etc.
The purpose of this driver is to expose RAPL for userspace consumption. Overall, RAPL fits in the new powercap class driver in that platform level power capping controls are exposed via this generic interface.
Zhang, Rui's initial RAPL driver was used as a reference and starting point. Many thanks.
https://lkml.org/lkml/2011/5/26/93
Unlike the patch above, which is mainly for monitoring, this driver focus on the control and usability by user applications.
--- drivers/powercap/Kconfig | 8 + drivers/powercap/Makefile | 1 + drivers/powercap/intel_rapl.c | 1319 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1328 insertions(+) create mode 100644 drivers/powercap/intel_rapl.c
drivers/powercap/Kconfig +8 -0
@@ -13,4 +13,12 @@ menuconfig POWERCAP_SUPPORT if POWERCAP_SUPPORT # Add client driver config here. +config INTEL_RAPL + tristate "Intel RAPL Support" + default n + ---help--- + RAPL (Running Average Power Limit) provides mechanisms to enforce + and monitor power limits of supported Intel CPUs. Limits can be + set by RAPL domains such as package, core, graphics, etc. + endif
drivers/powercap/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_POWERCAP_SUPPORT) += powercap_sys.o +obj-$(CONFIG_INTEL_RAPL) += intel_rapl.o
drivers/powercap/intel_rapl.c new file +1319 -0
1,319 lines not on this page · raw message
Signature · 1 line
1.8.3.1