RAPL (Running Average Power Limit) driver
v3 cover RAPL (Running Average Power Limit) driver
Changes since V3:
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 V2:
- 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 | 764 +++++++++++++++++++++++++++++++++++++ drivers/platform/x86/intel_rapl.h | 176 +++++++++ 4 files changed, 950 insertions(+) create mode 100644 drivers/platform/x86/intel_rapl.c create mode 100644 drivers/platform/x86/intel_rapl.h
Signature · 1 line
1.7.9.5
PATCH v3 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 | 764 +++++++++++++++++++++++++++++++++++++ drivers/platform/x86/intel_rapl.h | 176 +++++++++ 4 files changed, 950 insertions(+) create mode 100644 drivers/platform/x86/intel_rapl.c create mode 100644 drivers/platform/x86/intel_rapl.h
drivers/platform/x86/Kconfig +9 -0
@@ -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 y + ---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
@@ -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 +764 -0
764 lines not on this page · raw message
drivers/platform/x86/intel_rapl.h new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
drivers/platform/x86/Kconfig config APPLE_GMUX · line 787
Quoted 4 lines · Jacob Pan
drivers/platform/x86/Kconfig +4
-0+config INTEL_RAPL + tristate "Intel RAPL Support" + depends on THERMAL + default y
Unless you can not boot your machine without this, you should never default to y. Just delete this line.
Quoted 1 line
+#define DEBUG
Why? I think you need to remove this line :)
drivers/platform/x86/intel_rapl.c line 218
Quoted 9 lines
drivers/platform/x86/intel_rapl.c new file +9
-0+static int rapl_read_data_raw (struct rapl_domain *domain, +struct rapl_primitive_info *rp,bool xlate,u64 *data) +{ +u32 msr_l, msr_h; +u64 value, final; +u32 msr; +u32 mask_h, mask_l; + +BUG_ON (!domain || !rp);
How nice, you just crashed a machine, rendering it useless to get the bug report out of. Never do that in a driver. This is a static function, that you control the values being sent to it, you should never have to do such strict parameter checking with this line, or all of the other lines you have in this function. You _know_ that they will never be hit, so don't even check for them.
drivers/platform/x86/intel_rapl.c line 219
Quoted 1 line
drivers/platform/x86/intel_rapl.c new file +1
-0+if (NULL == rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )
In Linux we do (rp->name == NULL), or even better yet (!rp->name), please fix that up here and elsewhere in the driver.
drivers/platform/x86/intel_rapl.c line 292
Quoted 8 lines
drivers/platform/x86/intel_rapl.c new file +8
-0+static int rapl_check_unit (void ) +{ +u64 output; +u32 value; + +if (rdmsrl_safe (MSR_RAPL_POWER_UNIT , &output)) { +pr_err ("Failed to read power unit MSR 0x%x, exit.\n" , +MSR_RAPL_POWER_UNIT );
dev_err() instead? Same with the other pr_* calls, almost all of them can be dev_*.
Quoted 13 lines
drivers/platform/x86/intel_rapl.c new file +13
-0+static int intel_rapl_probe (struct platform_device *pdev) +{ +int i; +int ret =0 ; +struct thermal_cooling_device *cdev; +struct rapl_domain *rd; + +/* read the initial data */ +rapl_update_domain_data (); + +for (i =0 ; i < rg_data.nr_domains; i++) { + rd = &rapl_domains[i]; + cdev = thermal_cooling_device_register(DRIVER_NAME,
drivers/platform/x86/intel_rapl.c line 507
Quoted 10 lines
drivers/platform/x86/intel_rapl.c new file +10
-0+ &rapl_domains[i], + &rapl_cdev_ops); +if (IS_ERR (cdev)) { + ret =PTR_ERR (cdev); + goto err_cleanup; + } + + rd->cool_dev = cdev; +pr_info ("registered RAPL domain %d %s as cooling device\n" , i, + rd->name);
No one cares. If a driver is working properly, it should NEVER print anything out, even the "I'm now loaded, look at ME!" lines.
drivers/platform/x86/intel_rapl.c line 624
Quoted 4 lines
drivers/platform/x86/intel_rapl.c new file +4
-0+static void intel_rapl_dev_release (struct device *dev) +{ +return ; +}
You didn't just do this...
{sign}
As per the documentation in the kernel tree, I get to publicly mock you and this code, in which you feel you are somehow smarter than the kernel by having to 'trick' it by providing an empty release function, thereby shutting the message it used to give you up.
Do you really think I just put that error message in there for fun? You need to think that it was trying to tell you something, and providing an empty function is NOT what it is trying to tell you, that would be flat out stupid of it to do.
Surely this didn't pass any internal Intel review, did it?
Fix this now, it's totally unacceptable.
Quoted 1 line
+MODULE_VERSION("0.1");
No one cares about the module version, just delete it.
Quoted 1 line
+#define
DRIVER_NAME"intel_rapl"
Not needed, use MODULE_BUILD_NAME or some such thing.
drivers/platform/x86/intel_rapl.h line 39
Quoted 4 lines
drivers/platform/x86/intel_rapl.h new file +4
-0+#define POWER_LIMIT2_ENABLE (0x1ULL<<47) +#define POWER_LIMIT2_CLAMP (0x1ULL<<48) +#define POWER_PKG_LOCK (0x1ULL<<63) +#define POWER_PP_LOCK (0x1<<31)
We have BIT definitions, why not use them?
The only thing in this platform data .h file, should be platform data, not structures and definitions and enums, they should all be within the .c file as no one else cares about them.
drivers/platform/x86/intel_rapl.h line 175
Quoted 11 lines
drivers/platform/x86/intel_rapl.h new file +11
-0+struct rapl_primitive_info { +const char *name; +u64 mask; +int shift; +enum rapl_domain_msr_id id; +enum unit_type unit; +enum rapl_primitives pm_id; +u32 flag; +}; + +#define PRIMITIVE_INFO_INIT (p, m, s, i, u, f) {#p, m, s, i, u, p, f}
C has named initializers, use them please.
greg k-h
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 3 lines · Greg Kroah-Hartman
Quoted 1 line · Jacob Pan
+#define DEBUG
Why? I think you need to remove this line :)
Some people like their dev_dbg statements to
be emitted all the time.
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 7 lines · Joe Perches
Quoted 3 lines · Greg Kroah-Hartman
Quoted 1 line · Jacob Pan
+#define DEBUG
Why? I think you need to remove this line :)
Some people like their
dev_dbgstatements to
be emitted all the time.
Those people should not be submitting new drivers for inclusion in the kernel tree.
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines · Joe Perches
Quoted 3 lines · Greg Kroah-Hartman
Quoted 1 line · Jacob Pan
+#define DEBUG
Why? I think you need to remove this line :)
Some people like their
dev_dbgstatements to
be emitted all the time.Those people should not be submitting new drivers for inclusion in the kernel tree.
I think age of code (with some obvious exceptions) isn't too much of a reliable indicator and adding new CONFIG_<foo>_DEBUG controls isn't all that great a way to enable debugging.
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
In reply to Greg Kroah-HartmanQuoted 5 lines · On Tue, 9 Apr 2013 08:26:38 -0700 Greg Kroah-Hartman…
drivers/platform/x86/intel_rapl.c line 219
Quoted 1 line
drivers/platform/x86/intel_rapl.c new file +1
-0+if (NULL == rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )In Linux we do (
rp->name== NULL), or even better yet (!rp->name), please fix that up here and elsewhere in the driver.
I can fix that. I did that because checkpatch does not complain about it. also it avoids common mistake as:rp->name = NULL
Quoted 6 lines
Quoted 3 lines
(quoted diff) +2
-0+ +#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) {#p, m, s, i, u, p,f}
C has named initializers, use them please.
this macro can save lots of repeated text.
Quoted 6 lines
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
[Jacob Pan]
Signature · 3 lines
Thanks, Jacob
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 11 lines · Jacob Pan
Quoted 5 lines · On Tue, 9 Apr 2013 08:26:38 -0700 Greg Kroah-Hartman…
drivers/platform/x86/intel_rapl.c line 219
Quoted 1 line
drivers/platform/x86/intel_rapl.c new file +1
-0+if (NULL == rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )In Linux we do (
rp->name== NULL), or even better yet (!rp->name), please fix that up here and elsewhere in the driver.I can fix that. I did that because checkpatch does not complain about it. also it avoids common mistake as:
rp->name= NULL
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
(quoted diff) +2
-0+ +#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) {#p, m, s, i, u, p,f}
C has named initializers, use them please.
this macro can save lots of repeated text.
Use the macro. Use named initializers in the macro.
#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) \
{ \
.name = #p, \
.mask = m, \
.shift = s, \
.id = i, \
.unit = u, \
/* \
(hmm looks like a bug ?) \
enum rapl_primitives pm_id; \
*/ \
.flag = f, \
}Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 33 lines · On Tue, 09 Apr 2013 09:26:55 -0700 Joe Perches <[email protected]> wrote:
Quoted 12 lines · Jacob Pan
Quoted 6 lines · On Tue, 9 Apr 2013 08:26:38 -0700 Greg Kroah-Hartman…
Quoted 2 lines
(quoted diff) +1
-0+ if (NULL == rp->name || rp->flag &
RAPL_PRIMITIVE_DUMMY)In Linux we do (
rp->name== NULL), or even better yet (!rp->name), please fix that up here and elsewhere in the driver.I can fix that. I did that because checkpatch does not complain about it. also it avoids common mistake as:
rp->name= NULLQuoted 7 lines
Quoted 6 lines
Quoted 3 lines
(quoted diff) +2
-0+ +#define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) {#p, m, s, i, u,p, f}
C has named initializers, use them please.
this macro can save lots of repeated text.
Use the macro. Use named initializers in the macro.
#define
PRIMITIVE_INFO_INIT(p, m, s, i, u, f)\{ \ .name = #p, \ .mask = m, \ .shift = s, \ .id = i, \ .unit = u, \ /* \ (hmm looks like a bug ?) \ enum rapl_primitives pm_id; \
Quoted 1 line
*/ \
not a bug but you are right i can remove pm_id.
Signature · 3 lines
Thanks, Jacob
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
In reply to Jacob PanQuoted 9 lines · Jacob Pan
Quoted 5 lines · On Tue, 9 Apr 2013 08:26:38 -0700 Greg Kroah-Hartman…
drivers/platform/x86/intel_rapl.c line 219
Quoted 1 line
drivers/platform/x86/intel_rapl.c new file +1
-0+if (NULL == rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )In Linux we do (
rp->name== NULL), or even better yet (!rp->name), please fix that up here and elsewhere in the driver.I can fix that. I did that because checkpatch does not complain about it.
checkpatch doesn't catch everything.
Quoted 1 line
also it avoids common mistake as:
rp->name= NULL
The compiler catches mistakes like that, and has for many years.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
+#define
PRIMITIVE_INFO_INIT(p, m, s, i, u, f){#p, m, s, i, u, p, f}C has named initializers, use them please.
this macro can save lots of repeated text.
text is free.
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
In reply to Jacob PanQuoted 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:
drivers/platform/x86/intel_rapl.c
Quoted 1 line
drivers/platform/x86/intel_rapl.c +0
-0
[]
drivers/platform/x86/intel_rapl.c line 351
Quoted 3 lines
drivers/platform/x86/intel_rapl.c +3
-0+static bool rapl_polling_should_cont (void ) +{ +unsigned int all_state =0 ;
[]
drivers/platform/x86/intel_rapl.c line 357
Quoted 1 line
drivers/platform/x86/intel_rapl.c +1
-0+return !!all_state;
The !! isn't needed.
!! should only be done when you are returning
int and you need to make sure it's 0 or 1.
It's not here. The return is bool.
return all_state;
The compiler, even icc, will do this internally.
drivers/platform/x86/intel_rapl.c line 604
Quoted 6 lines
drivers/platform/x86/intel_rapl.c +6
-0+static int start_periodic_polling (void ) +{ +if (polling_started) + goto out; +schedule_delayed_work (&rapl_polling_work,0 ); + polling_started = true;
Should polling_started be device specific (in struct rapl_data ?) instead of a single instance static?
Re: [PATCH v3 1/1] Introduce Intel RAPL cooling device driver
Quoted 9 lines · On Tue, 09 Apr 2013 09:00:37 -0700 Joe Perches <[email protected]> wrote:
drivers/platform/x86/intel_rapl.c line 604
Quoted 6 lines
drivers/platform/x86/intel_rapl.c new file +6
-0+static int start_periodic_polling (void ) +{ +if (polling_started) + goto out; +schedule_delayed_work (&rapl_polling_work,0 ); + polling_started = true;Should
polling_startedbe device specific (in structrapl_data?) instead of a single instance static?
hmmm, one of the future improvements is to add support for multi package CPUs. I intend to use rapl_data for per package common data across different domains but use a single polling thread to reduce wakeups if we were to poll on multiple packages. So in that sense, I want to keep the polling_started flag as a single instance within the driver.
Signature · 3 lines
Thanks, Jacob