Skip to contentSkip to conversation

Power Capping Framework and RAPL Driver

RFC Superseded Srinivas Pandruvada 3 participants 10 messages Aug 7, 2013 – Aug 10, 2013

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Power Capping Framework and RAPL Driver

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
#1 lore raw

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
new file mode 100644
index 0000000..0e5d6e4
@@ -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
#2 lore raw

Re: [RFC v02 1/5] PowerCap: Documentation

Quoted 15 lines · Srinivas Pandruvada

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  

+++++++++++++++++++++++

...

Documentation/powercap/PowerCappingFramework.txt line 7

Quoted 10 lines
Documentation/powercap/PowerCappingFramework.txt new file +7 -0
@@ -0,0 +1,686 @@
+Power Capping Framework
+==================================
+
+The Linux Power Capping Framework provides user-space with a common
+API to kernel-mode power-capping drivers.  At the same time,
+it provides the hardware-specific power-capping drivers with
+a uniform API to user-space.

s/. At the same time, it provides/, and/

Quoted 7 lines
Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+Terminology
+=========================
+The Power Capping framework organizes power capping devices under a  

tree structure.
+At the root level, each device is under some "controller", which is the enabler
+of technology.

A controller is the enabler of technology?

What does that mean?

Quoted 1 line

For example this can be "RAPL".

Ah, clears it right up.

Quoted 1 line

+Under each controllers,

each doesn't take a plural.

Documentation/powercap/PowerCappingFramework.txt line 22

Quoted 11 lines

there are multiple power zones, which can be independently

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+monitored and controlled.
+Each power zone can be organized as a tree with parent, children and  

siblings.
+Each power zone defines attributes to enable power monitoring and constraints.

Documentation/powercap/PowerCappingFramework.txt new file +5 -0
+
+Example sysfs interface tree:
+
+/sys/devices/virtual/power_cap
+└── intel-rapl

... intel intel intel intel...

Quoted 5 lines
Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+For example, above powercap sysfs tree represents RAPL(Running  

Average Power Limit)
+type controls available in the Intel® 64 and IA-32 Processor Architectures. Here

What are the chances of this ever being applied to a non-intel processor? (Should it be under Documentation/x86, or is it presented as something with a nonzero chance of actually ever being generic?)

Quoted 10 lines

+under controller "intel-rapl" there are two CPU packages (package-0/1), which can
+provide power monitoring and controls (intel-rapl:0 and intel-rapl:1). Each power

Documentation/powercap/PowerCappingFramework.txt new file +6 -0
+zone has a name.
+For example:
+cat /sys/class/power_cap/intel-rapl/intel-rapl:0/name
+package-0
+
+In addition to providing monitoring and control at package level,  
Quoted 3 lines

each package
+is further divided into child power zones (called domains in the RAPL specifications).

Where are the RAPL specifications, and is this framework just an implementation of them or is it more generic?

Quoted 70 lines

+Here zones represent controls for core and dram parts. These zones can be represented

Documentation/powercap/PowerCappingFramework.txt new file +7 -0
+as children of package.
+For example:
+cat /sys/class/power_cap/intel-rapl/intel-rapl:0/intel-rapl:0:1/name
+dram
+
+Under RAPL framework there are two constraints, one for
+short term and one for long term, with two different time windows.  

These can be
+represented as two constraints, with different time windows, power limits and names.

Documentation/powercap/PowerCappingFramework.txt new file +14 -0
+For example:
+	constraint_0_name
+	constraint_0_power_limit_uw
+	constraint_0_time_window_us
+	constraint_1_name
+	constraint_1_power_limit_uw
+	constraint_1_time_window_us
+
+Power Zone Attributes
+=================================
+Monitoring attributes
+----------------------
+
+energy_uj (rw): Current energy counter in micro joules. Write "0" to  

reset.

Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+If the counter can not be reset, then this attribute is read only.
+
+max_energy_range_uj (ro): Range of the above energy counter in  

micro-joules.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+power_uw (rw): Current power in micro watts. Write "0" to resets the  

value.

Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+If the value can not be reset, then this attribute is read only.
+
+max_power_range_uw (ro): Range of the above power value in  

micro-watts.

Documentation/powercap/PowerCappingFramework.txt new file +4 -0
+
+name (ro): Name of this power zone.
+
+It is possible that some domains can have both power and energy  

counters and

Documentation/powercap/PowerCappingFramework.txt new file +5 -0
+ranges, but at least one is mandatory.
+
+Constraints
+----------------
+constraint_X_power_limit_uw (rw): Power limit in micro watts, which  

should be
+applicable for the time window specified by
"constraint_X_time_window_us".

Documentation/powercap/PowerCappingFramework.txt new file +10 -0
+
+constraint_X_time_window_us (rw): Time window in micro seconds.
+
+constraint_X_name (ro): An optional name of the constraint
+
+constraint_X_max_power_uw(ro): Maximum allowed power in micro watts.
+
+constraint_X_min_power_uw(ro): Minimum allowed power in micro watts.
+
+constraint_X_max_time_window_us(ro): Maximum allowed time window in  

micro seconds.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+constraint_X_min_time_window_us(ro): Minimum allowed time window in  

micro seconds.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+In addition each node has an attribute "type", which shows, whether  

is a controller
+or power zone. Except power_limit_uw and time_window_us other fields are optional.

Documentation/powercap/PowerCappingFramework.txt line 259

Quoted 9 lines
Documentation/powercap/PowerCappingFramework.txt new file +9 -0
+
+Power Cap Client Driver Interface
+==================================
+The API summary:
+
+Call powercap_allocate_controller to define a controller with a name.
+Call powercap_zone_register for each power zone for this controller.
+power zones can have other power zone as a parent or don't have a
+parent.

Trying not to nitpick "english isn't a first language here", but...

Power zones can have another power zone as a parent or no parent.

Documentation/powercap/PowerCappingFramework.txt line 266

Quoted 8 lines

+During powercap_zone_register defines number of constraints and callbacks.

Documentation/powercap/PowerCappingFramework.txt new file +6 -0
+
+To Free a power zone call powercap_zone_unregister.
+To free a controller call powercap_deallocate_controller.
+
+Rest of this document is generated by using kernel-doc on
+powercap.h

Isn't that what Documentation/DocBook is for? (If powercap.h is modified the need to update this file is nonobvious...)

Rob

#3 lore raw

Re: [RFC v02 1/5] PowerCap: Documentation

Quoted 62 lines · Rob Landley
Quoted 15 lines · Srinivas Pandruvada

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 

+++++++++++++++++++++++

...

Documentation/powercap/PowerCappingFramework.txt line 7

Quoted 10 lines
Documentation/powercap/PowerCappingFramework.txt new file +7 -0
@@ -0,0 +1,686 @@
+Power Capping Framework
+==================================
+
+The Linux Power Capping Framework provides user-space with a common
+API to kernel-mode power-capping drivers.  At the same time,
+it provides the hardware-specific power-capping drivers with
+a uniform API to user-space.

s/. At the same time, it provides/, and/

Quoted 7 lines
Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+Terminology
+=========================
+The Power Capping framework organizes power capping devices under a 

tree structure.
+At the root level, each device is under some "controller", which is the enabler
+of technology.

A controller is the enabler of technology?

What does that mean?

Quoted 1 line

For example this can be "RAPL".

Ah, clears it right up.

Quoted 1 line

+Under each controllers,

each doesn't take a plural.

Documentation/powercap/PowerCappingFramework.txt line 22

Quoted 11 lines

there are multiple power zones, which can be independently

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+monitored and controlled.
+Each power zone can be organized as a tree with parent, children and 

siblings.
+Each power zone defines attributes to enable power monitoring and constraints.

Documentation/powercap/PowerCappingFramework.txt new file +5 -0
+
+Example sysfs interface tree:
+
+/sys/devices/virtual/power_cap
+└── intel-rapl

... intel intel intel intel...

Quoted 8 lines
Quoted 5 lines
Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+For example, above powercap sysfs tree represents RAPL(Running 

Average Power Limit)
+type controls available in the Intel® 64 and IA-32 Processor Architectures. Here

What are the chances of this ever being applied to a non-intel processor? (Should it be under Documentation/x86, or is it presented as something with a nonzero chance of actually ever being generic?)

This framework has nothing to do with Intel processors. This is not processor specific. It can be even used for non processor parts like a wireless module. Any part which allows some configuration of its power budget, can use this framework.

Quoted 7 lines
Quoted 7 lines

+under controller "intel-rapl" there are two CPU packages (package-0/1), which can
+provide power monitoring and controls (intel-rapl:0 and intel-rapl:1). Each power

Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+zone has a name.
+For example:
+cat /sys/class/power_cap/intel-rapl/intel-rapl:0/name
Quoted 8 lines
Quoted 6 lines
Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+package-0
+
+In addition to providing monitoring and control at package level, 

each package
+is further divided into child power zones (called domains in the RAPL specifications).

Where are the RAPL specifications, and is this framework just an implementation of them or is it more generic?

RAPL specifications are part of Intel Software Developer's manual. This can be downloaded from Intel website.

Quoted 81 lines
Quoted 69 lines

+Here zones represent controls for core and dram parts. These zones can be represented

Documentation/powercap/PowerCappingFramework.txt new file +7 -0
+as children of package.
+For example:
+cat /sys/class/power_cap/intel-rapl/intel-rapl:0/intel-rapl:0:1/name
+dram
+
+Under RAPL framework there are two constraints, one for
+short term and one for long term, with two different time windows. 

These can be
+represented as two constraints, with different time windows, power limits and names.

Documentation/powercap/PowerCappingFramework.txt new file +14 -0
+For example:
+    constraint_0_name
+    constraint_0_power_limit_uw
+    constraint_0_time_window_us
+    constraint_1_name
+    constraint_1_power_limit_uw
+    constraint_1_time_window_us
+
+Power Zone Attributes
+=================================
+Monitoring attributes
+----------------------
+
+energy_uj (rw): Current energy counter in micro joules. Write "0" to 

reset.

Documentation/powercap/PowerCappingFramework.txt new file +3 -0
+If the counter can not be reset, then this attribute is read only.
+
+max_energy_range_uj (ro): Range of the above energy counter in 

micro-joules.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+power_uw (rw): Current power in micro watts. Write "0" to resets the 

value.

Documentation/powercap/PowerCappingFramework.txt new file +7 -0
+If the value can not be reset, then this attribute is read only.
+
+max_power_range_uw (ro): Range of the above power value in micro-watts.
+
+name (ro): Name of this power zone.
+
+It is possible that some domains can have both power and energy 

counters and

Documentation/powercap/PowerCappingFramework.txt new file +5 -0
+ranges, but at least one is mandatory.
+
+Constraints
+----------------
+constraint_X_power_limit_uw (rw): Power limit in micro watts, which 

should be
+applicable for the time window specified by
"constraint_X_time_window_us".

Documentation/powercap/PowerCappingFramework.txt new file +10 -0
+
+constraint_X_time_window_us (rw): Time window in micro seconds.
+
+constraint_X_name (ro): An optional name of the constraint
+
+constraint_X_max_power_uw(ro): Maximum allowed power in micro watts.
+
+constraint_X_min_power_uw(ro): Minimum allowed power in micro watts.
+
+constraint_X_max_time_window_us(ro): Maximum allowed time window in 

micro seconds.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+constraint_X_min_time_window_us(ro): Minimum allowed time window in 

micro seconds.

Documentation/powercap/PowerCappingFramework.txt new file +2 -0
+
+In addition each node has an attribute "type", which shows, whether 

is a controller
+or power zone. Except power_limit_uw and time_window_us other fields are optional.

Documentation/powercap/PowerCappingFramework.txt line 259

Quoted 9 lines
Documentation/powercap/PowerCappingFramework.txt new file +9 -0
+
+Power Cap Client Driver Interface
+==================================
+The API summary:
+
+Call powercap_allocate_controller to define a controller with a name.
+Call powercap_zone_register for each power zone for this controller.
+power zones can have other power zone as a parent or don't have a
+parent.

Trying not to nitpick "english isn't a first language here", but...

Quoted 2 lines

Power zones can have another power zone as a parent or no parent.

Thanks for pointing out grammatical errors. I have to let our technical writer reviews this.

Quoted 10 lines

Documentation/powercap/PowerCappingFramework.txt line 266

Quoted 8 lines

+During powercap_zone_register defines number of constraints and callbacks.

Documentation/powercap/PowerCappingFramework.txt new file +6 -0
+
+To Free a power zone call powercap_zone_unregister.
+To free a controller call powercap_deallocate_controller.
+
+Rest of this document is generated by using kernel-doc on
+powercap.h

Isn't that what Documentation/DocBook is for? (If powercap.h is modified the need to update this file is nonobvious...)

Yes. But at RFC stage, it is easy to review, if I paste here.

Quoted 2 lines

Rob

#4 lore raw

RFC v2 2/5 PowerCap: Add class driver

In reply to Srinivas Pandruvada

Added 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
new file mode 100644
index 0000000..f70b7b9
@@ -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
new file mode 100644
index 0000000..f2acfed
@@ -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
#5 lore raw

RFC v2 3/5 PowerCap: Added to drivers build

In reply to Srinivas Pandruvada

Added 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
index 9953a42..89ff2f8 100644
@@ -166,4 +166,6 @@ source "drivers/ipack/Kconfig"
 
 source "drivers/reset/Kconfig"
 
+source "drivers/powercap/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 130abc1..e207b2d 100644
@@ -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
#6 lore raw

RFC v2 4/5 x86/msr: add 64bit _on_cpu access functions

In reply to Srinivas Pandruvada

From: 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
index cb75028..e139b13 100644
@@ -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
#7 lore raw

RFC v2 5/5 Introduce Intel RAPL power capping driver

In reply to Srinivas Pandruvada

From: 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
index f70b7b9..7fd9d48 100644
@@ -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
index f2acfed..a08b8b0 100644
@@ -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
#8 lore raw

Re: [RFC v02 5/5] Introduce Intel RAPL power capping driver

Quoted 3 lines · Srinivas Pandruvada

RAPL(Running Average Power Limit) interface provides platform software with the ability to monitor, control, and get notifications on SOC power consumptions.

trivial notes:

drivers/powercap/intel_rapl.c

Quoted 1 line
drivers/powercap/intel_rapl.c +0 -0

[]

drivers/powercap/intel_rapl.c line 49

Quoted 8 lines
drivers/powercap/intel_rapl.c +8 -0
+#define POWER_LIMIT1_MASK       0x7FFF
+#define POWER_LIMIT1_ENABLE     BIT(15)
+#define POWER_LIMIT1_CLAMP      BIT(16)
+
+#define POWER_LIMIT2_MASK       (0x7FFFULL<<32)
+#define POWER_LIMIT2_ENABLE     (0x1ULL<<47)
+#define POWER_LIMIT2_CLAMP      (0x1ULL<<48)
+#define POWER_PKG_LOCK          (0x1ULL<<63)

Maybe it's time add a generic bitops.h macro

#define BIT_ULL(nr) (1ULL << (nr))

[]

drivers/powercap/intel_rapl.c line 524

Quoted 10 lines
drivers/powercap/intel_rapl.c +10 -0
+/* called after domain detection and package level data are set */
+static void rapl_init_domains(struct rapl_pkg *rp)
+{
+	int i;
+	struct rapl_domain *rd = rp->domains;
+
+	for (i = 0; i < RAPL_DOMAIN_MAX; i++) {
+		unsigned int mask = rp->domain_map & (1 << i);
+		switch (mask) {
+		case 1 << RAPL_DOMAIN_PKG:

Maybe use defines or BIT(RAPL_DOMAIN_PKG)

Other than that the code seems to read pretty easily.

#9 lore raw
In reply to Srinivas Pandruvada
Quoted 24 lines · Srinivas Pandruvada

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.

Quoted 4 lines

Also submitting Intel RAPL driver using power capping framework.

Revisions:

Thanks for everyone for review. I have received enough negative comments, which will require another version. So please hold off your reviews till next version.

Quoted 41 lines

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