Skip to contentSkip to conversation

RAPL (Running Average Power Limit) driver

PATCH In review Jacob Pan 3 participants 4 messages Apr 9, 2013 – Apr 10, 2013 x86 platform drivers

lore
Share & tools
lore

Jacob Pan

author
#0 lore raw

v4 cover RAPL (Running Average Power Limit) driver

Changes since V3:
- Removed dependency on platform_device/platform_driver. I initially used platform bus for the purpose of linking RAPL domain device objects to thermal sysfs. For this simplified version we don't need this anymore nor do we need any resources/platform data. This simplified version only needs MSR access. (not to avoid .release() :). I should be freeing device data after it gets called from driver core)

- merged header file into .c file, there is no public data nor APIs.

- misc. cleanups based on reviews

Changes since V2:
This is a simpler version which only exposes interface via the generic thermal layer. No new ABI introduced.

RAPL driver does some automatic settings to the related power parameters based on user's single input from thermal cooling device interface.

On the other side, more work needed to fully use RAPL interface. This is likely result in adding more knobs in the generic thermal sysfs.

- deleted event notifications
- deleted per domain device and RAPL class and their private sysfs
- added more logic to do some automatic settings based on user input. e.g. will enable clamping by default and set a reasonable time window for long term power limits.

Changes since V1:
- use 'struct device' instead of raw kobject to represent RAPL domains
- changed eventfd control interface to use event string instead of passing file descriptors that cannot be authenticated in sysfs directory
- clean ups based on v1 reviews
- use kcalloc for arrays
- drop dependencies on X86
- misc cleanups

Jacob Pan (1):
Introduce Intel RAPL cooling device driver

 drivers/platform/x86/Kconfig      |    9 +
 drivers/platform/x86/Makefile     |    1 +
 drivers/platform/x86/intel_rapl.c |  889 +++++++++++++++++++++++++++++++++++++
 3 files changed, 899 insertions(+)
 create mode 100644 drivers/platform/x86/intel_rapl.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v4 1/1 Introduce Intel RAPL cooling device driver

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 generic thermal layer in that platform level power capping and monitoring are mainly used for thermal management and thermal layer provides the abstracted interface needed to have portable applications.

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/platform/x86/Kconfig      |    9 +
 drivers/platform/x86/Makefile     |    1 +
 drivers/platform/x86/intel_rapl.c |  889 +++++++++++++++++++++++++++++++++++++
 3 files changed, 899 insertions(+)
 create mode 100644 drivers/platform/x86/intel_rapl.c
drivers/platform/x86/Kconfig +9 -0
index 3338437..34585b7 100644
@@ -781,4 +781,13 @@ config APPLE_GMUX
 	  graphics as well as the backlight. Currently only backlight
 	  control is supported by the driver.
 
+config INTEL_RAPL
+	tristate "Intel RAPL Support"
+	depends on THERMAL
+	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 # X86_PLATFORM_DEVICES
drivers/platform/x86/Makefile +1 -0
index ace2b38..a80c0f4 100644
@@ -51,3 +51,4 @@ obj-$(CONFIG_INTEL_OAKTRAIL)	+= intel_oaktrail.o
 obj-$(CONFIG_SAMSUNG_Q10)	+= samsung-q10.o
 obj-$(CONFIG_APPLE_GMUX)	+= apple-gmux.o
 obj-$(CONFIG_CHROMEOS_LAPTOP)	+= chromeos_laptop.o
+obj-$(CONFIG_INTEL_RAPL)	+= intel_rapl.o
drivers/platform/x86/intel_rapl.c new file +889 -0

889 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v4 1/1] Introduce Intel RAPL cooling device driver

Quoted 5 lines · Jacob Pan

+ *

+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
+ *  USA

I'm getting real tired of reminding Intel developers that they don't want to be responsible for tracking the office movements of the FSF for the next 40+ years.

Arjan, can you please get the "default" Intel GPL header that you all use changed so I don't have to make this request for every single new file that is submitted by Intel developers?

thanks,

greg k-h

#3 lore raw

Re: [PATCH v4 1/1] Introduce Intel RAPL cooling device driver

In reply to Jacob Pan
Quoted 3 lines · Jacob Pan

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

yet more trivia and style quibbles.

drivers/platform/x86/intel_rapl.c

Quoted 1 line
drivers/platform/x86/intel_rapl.c +0 -0

[]

drivers/platform/x86/intel_rapl.c line 463

Quoted 7 lines
drivers/platform/x86/intel_rapl.c +7 -0
+static int rapl_get_max_state(struct thermal_cooling_device *cdev,
+			unsigned long *state)
+{
+	int ret;
+	u64 val;
+
+	struct rapl_domain *rd = (struct rapl_domain *)cdev->devdata;

Don't need to cast void *

	struct rapl_domain *rd = cdev->devdata;

is just fine.

drivers/platform/x86/intel_rapl.c line 485

Quoted 4 lines
drivers/platform/x86/intel_rapl.c +4 -0
+static int rapl_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
+			     *state)
+{
+	struct rapl_domain *rd = (struct rapl_domain *)cdev->devdata;

etc

drivers/platform/x86/intel_rapl.c

Quoted 2 lines
drivers/platform/x86/intel_rapl.c +2 -0
+static void set_pkg_thermal_irq(bool enable)
+{

[]

drivers/platform/x86/intel_rapl.c line 524

Quoted 4 lines
drivers/platform/x86/intel_rapl.c +4 -0
+	if (boot_cpu_has(X86_FEATURE_PTS))
+		rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	else
+		return;
	if (!boot_cpu_has(X86_FEATURE_PTS))
		return;

	rdmsc(etc...)

drivers/platform/x86/intel_rapl.c line 526

Quoted 2 lines
drivers/platform/x86/intel_rapl.c +2 -0
+
+	if (enable == false)

Don't test for == false

drivers/platform/x86/intel_rapl.c line 532

Quoted 6 lines
drivers/platform/x86/intel_rapl.c +6 -0
+		l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+	else
+		l |= PACKAGE_THERM_INT_PLN_ENABLE;
+
+	if (boot_cpu_has(X86_FEATURE_PLN))
+		wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
	if (boot_cpu_has(X86_FEATURE_PTS)) {
		if (enable)
			l |= PACKAGE_THERM_INT_PLN_ENABLE;
		else
			l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
		wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
	}