intel_rapl: RAPL abstraction and MMIO RAPL support
Subsystems (2)
Zhang Rui
reviewerv2 cover intel_rapl: RAPL abstraction and MMIO RAPL support
Besideis MSR interface, RAPL can also be controlled via the MMIO interface, by accessing the MCHBar registers exposed by the processor thermal device.
Currently, we only have RAPL MSR interface in Linux kernel, this brings problems on some platforms that BIOS performs a low power limits via the MMIO interface by default. This results in poor system performance, and there is no way for us to change the MMIO MSR setting in Linux.
To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the shared code into a separate file, intel_rapl_common.c, so that it can be used by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by the processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.
The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which contains the latest RAPL changes for multi-die support.
Changes in V2:
- add kerneldoc for struct rapl_if_priv.
- use intel_rapl_msr.c for RAPL MSR I/F driver, instead of intel_rapl.c.
- changelog and coding style update.
thanks,
rui
Zhang Rui
reviewerPATCH v2 1/13 intel_rapl: use reg instead of msr
To support both MSR and MMIO Interface, use 'reg' to discribe RAPL registers instead of 'msr'.
--- drivers/powercap/intel_rapl.c | 98 +++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-)
drivers/powercap/intel_rapl.c +49 -49
@@ -83,13 +83,13 @@ enum rapl_domain_type { RAPL_DOMAIN_MAX, }; -enum rapl_domain_msr_id { -RAPL_DOMAIN_MSR_LIMIT , -RAPL_DOMAIN_MSR_STATUS , -RAPL_DOMAIN_MSR_PERF , -RAPL_DOMAIN_MSR_POLICY , -RAPL_DOMAIN_MSR_INFO , -RAPL_DOMAIN_MSR_MAX , +enum rapl_domain_reg_id { +RAPL_DOMAIN_REG_LIMIT , +RAPL_DOMAIN_REG_STATUS , +RAPL_DOMAIN_REG_PERF , +RAPL_DOMAIN_REG_POLICY , +RAPL_DOMAIN_REG_INFO , +RAPL_DOMAIN_REG_MAX , };/* per domain data, some are optional */
@@ -154,7 +154,7 @@ struct rapl_package;struct rapl_domain {const char *name;enum rapl_domain_type id; -int msrs[RAPL_DOMAIN_MSR_MAX ]; +int regs[RAPL_DOMAIN_REG_MAX ];struct powercap_zone power_zone;struct rapl_domain_data rdd;struct rapl_power_limit rpl[NR_POWER_LIMITS ];
@@ -216,7 +216,7 @@ struct rapl_primitive_info {const char *name;u64 mask;int shift; -enum rapl_domain_msr_id id; +enum rapl_domain_reg_id id;enum unit_type unit;u32 flag; };
@@ -642,11 +642,11 @@ static void rapl_init_domains(struct rapl_package *rp)case BIT (RAPL_DOMAIN_PACKAGE ): rd->name = rapl_domain_names[RAPL_DOMAIN_PACKAGE ]; rd->id =RAPL_DOMAIN_PACKAGE ; - rd->msrs[0 ] =MSR_PKG_POWER_LIMIT ; - rd->msrs[1 ] =MSR_PKG_ENERGY_STATUS ; - rd->msrs[2 ] =MSR_PKG_PERF_STATUS ; - rd->msrs[3 ] =0 ; - rd->msrs[4 ] =MSR_PKG_POWER_INFO ; + rd->regs[0 ] =MSR_PKG_POWER_LIMIT ; + rd->regs[1 ] =MSR_PKG_ENERGY_STATUS ; + rd->regs[2 ] =MSR_PKG_PERF_STATUS ; + rd->regs[3 ] =0 ; + rd->regs[4 ] =MSR_PKG_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
@@ -655,33 +655,33 @@ static void rapl_init_domains(struct rapl_package *rp)case BIT (RAPL_DOMAIN_PP0 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP0 ]; rd->id =RAPL_DOMAIN_PP0 ; - rd->msrs[0 ] =MSR_PP0_POWER_LIMIT ; - rd->msrs[1 ] =MSR_PP0_ENERGY_STATUS ; - rd->msrs[2 ] =0 ; - rd->msrs[3 ] =MSR_PP0_POLICY ; - rd->msrs[4 ] =0 ; + rd->regs[0 ] =MSR_PP0_POWER_LIMIT ; + rd->regs[1 ] =MSR_PP0_ENERGY_STATUS ; + rd->regs[2 ] =0 ; + rd->regs[3 ] =MSR_PP0_POLICY ; + rd->regs[4 ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_PP1 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP1 ]; rd->id =RAPL_DOMAIN_PP1 ; - rd->msrs[0 ] =MSR_PP1_POWER_LIMIT ; - rd->msrs[1 ] =MSR_PP1_ENERGY_STATUS ; - rd->msrs[2 ] =0 ; - rd->msrs[3 ] =MSR_PP1_POLICY ; - rd->msrs[4 ] =0 ; + rd->regs[0 ] =MSR_PP1_POWER_LIMIT ; + rd->regs[1 ] =MSR_PP1_ENERGY_STATUS ; + rd->regs[2 ] =0 ; + rd->regs[3 ] =MSR_PP1_POLICY ; + rd->regs[4 ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_DRAM ): rd->name = rapl_domain_names[RAPL_DOMAIN_DRAM ]; rd->id =RAPL_DOMAIN_DRAM ; - rd->msrs[0 ] =MSR_DRAM_POWER_LIMIT ; - rd->msrs[1 ] =MSR_DRAM_ENERGY_STATUS ; - rd->msrs[2 ] =MSR_DRAM_PERF_STATUS ; - rd->msrs[3 ] =0 ; - rd->msrs[4 ] =MSR_DRAM_POWER_INFO ; + rd->regs[0 ] =MSR_DRAM_POWER_LIMIT ; + rd->regs[1 ] =MSR_DRAM_ENERGY_STATUS ; + rd->regs[2 ] =MSR_DRAM_PERF_STATUS ; + rd->regs[3 ] =0 ; + rd->regs[4 ] =MSR_DRAM_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->domain_energy_unit =
@@ -736,37 +736,37 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,static struct rapl_primitive_info rpi[] = {/* name, mask, shift, msr index, unit divisor */ PRIMITIVE_INFO_INIT (ENERGY_COUNTER ,ENERGY_STATUS_MASK ,0 , -RAPL_DOMAIN_MSR_STATUS ,ENERGY_UNIT ,0 ), +RAPL_DOMAIN_REG_STATUS ,ENERGY_UNIT ,0 ),PRIMITIVE_INFO_INIT (POWER_LIMIT1 ,POWER_LIMIT1_MASK ,0 , -RAPL_DOMAIN_MSR_LIMIT ,POWER_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,POWER_UNIT ,0 ),PRIMITIVE_INFO_INIT (POWER_LIMIT2 ,POWER_LIMIT2_MASK ,32 , -RAPL_DOMAIN_MSR_LIMIT ,POWER_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,POWER_UNIT ,0 ),PRIMITIVE_INFO_INIT (FW_LOCK ,POWER_PP_LOCK ,31 , -RAPL_DOMAIN_MSR_LIMIT ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (PL1_ENABLE ,POWER_LIMIT1_ENABLE ,15 , -RAPL_DOMAIN_MSR_LIMIT ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (PL1_CLAMP ,POWER_LIMIT1_CLAMP ,16 , -RAPL_DOMAIN_MSR_LIMIT ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (PL2_ENABLE ,POWER_LIMIT2_ENABLE ,47 , -RAPL_DOMAIN_MSR_LIMIT ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (PL2_CLAMP ,POWER_LIMIT2_CLAMP ,48 , -RAPL_DOMAIN_MSR_LIMIT ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (TIME_WINDOW1 ,TIME_WINDOW1_MASK ,17 , -RAPL_DOMAIN_MSR_LIMIT ,TIME_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,TIME_UNIT ,0 ),PRIMITIVE_INFO_INIT (TIME_WINDOW2 ,TIME_WINDOW2_MASK ,49 , -RAPL_DOMAIN_MSR_LIMIT ,TIME_UNIT ,0 ), +RAPL_DOMAIN_REG_LIMIT ,TIME_UNIT ,0 ),PRIMITIVE_INFO_INIT (THERMAL_SPEC_POWER ,POWER_INFO_THERMAL_SPEC_MASK , -0 ,RAPL_DOMAIN_MSR_INFO ,POWER_UNIT ,0 ), +0 ,RAPL_DOMAIN_REG_INFO ,POWER_UNIT ,0 ),PRIMITIVE_INFO_INIT (MAX_POWER ,POWER_INFO_MAX_MASK ,32 , -RAPL_DOMAIN_MSR_INFO ,POWER_UNIT ,0 ), +RAPL_DOMAIN_REG_INFO ,POWER_UNIT ,0 ),PRIMITIVE_INFO_INIT (MIN_POWER ,POWER_INFO_MIN_MASK ,16 , -RAPL_DOMAIN_MSR_INFO ,POWER_UNIT ,0 ), +RAPL_DOMAIN_REG_INFO ,POWER_UNIT ,0 ),PRIMITIVE_INFO_INIT (MAX_TIME_WINDOW ,POWER_INFO_MAX_TIME_WIN_MASK ,48 , -RAPL_DOMAIN_MSR_INFO ,TIME_UNIT ,0 ), +RAPL_DOMAIN_REG_INFO ,TIME_UNIT ,0 ),PRIMITIVE_INFO_INIT (THROTTLED_TIME ,PERF_STATUS_THROTTLE_TIME_MASK ,0 , -RAPL_DOMAIN_MSR_PERF ,TIME_UNIT ,0 ), +RAPL_DOMAIN_REG_PERF ,TIME_UNIT ,0 ),PRIMITIVE_INFO_INIT (PRIORITY_LEVEL ,PP_POLICY_MASK ,0 , -RAPL_DOMAIN_MSR_POLICY ,ARBITRARY_UNIT ,0 ), +RAPL_DOMAIN_REG_POLICY ,ARBITRARY_UNIT ,0 ),/* non-hardware */ PRIMITIVE_INFO_INIT (AVERAGE_POWER ,0 ,0 ,0 ,POWER_UNIT ,RAPL_PRIMITIVE_DERIVED ),
@@ -798,7 +798,7 @@ static int rapl_read_data_raw(struct rapl_domain *rd,if (!rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )return -EINVAL ; - msr = rd->msrs[rp->id]; + msr = rd->regs[rp->id];if (!msr)return -EINVAL ;
@@ -874,7 +874,7 @@ static int rapl_write_data_raw(struct rapl_domain *rd,memset (&ma,0 ,sizeof (ma)); - ma.msr_no = rd->msrs[rp->id]; + ma.msr_no = rd->regs[rp->id]; ma.clear_mask = rp->mask; ma.set_mask = bits;
@@ -1282,8 +1282,8 @@ static int __init rapl_register_psys(void) rd->name = rapl_domain_names[RAPL_DOMAIN_PLATFORM ]; rd->id =RAPL_DOMAIN_PLATFORM ; - rd->msrs[0 ] =MSR_PLATFORM_POWER_LIMIT ; - rd->msrs[1 ] =MSR_PLATFORM_ENERGY_STATUS ; + rd->regs[0 ] =MSR_PLATFORM_POWER_LIMIT ; + rd->regs[1 ] =MSR_PLATFORM_ENERGY_STATUS ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 2/13 intel_rapl: remove hardcoded register index
In reply to Zhang Ruienum rapl_domain_reg_id is defined for the RAPL registers for each RAPL domain, thus use it whenever possible.
--- drivers/powercap/intel_rapl.c | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/powercap/intel_rapl.c +22 -22
@@ -642,11 +642,11 @@ static void rapl_init_domains(struct rapl_package *rp)case BIT (RAPL_DOMAIN_PACKAGE ): rd->name = rapl_domain_names[RAPL_DOMAIN_PACKAGE ]; rd->id =RAPL_DOMAIN_PACKAGE ; - rd->regs[0 ] =MSR_PKG_POWER_LIMIT ; - rd->regs[1 ] =MSR_PKG_ENERGY_STATUS ; - rd->regs[2 ] =MSR_PKG_PERF_STATUS ; - rd->regs[3 ] =0 ; - rd->regs[4 ] =MSR_PKG_POWER_INFO ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PKG_POWER_LIMIT ; + rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PKG_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_PERF ] =MSR_PKG_PERF_STATUS ; + rd->regs[RAPL_DOMAIN_REG_POLICY ] =0 ; + rd->regs[RAPL_DOMAIN_REG_INFO ] =MSR_PKG_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
@@ -655,33 +655,33 @@ static void rapl_init_domains(struct rapl_package *rp)case BIT (RAPL_DOMAIN_PP0 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP0 ]; rd->id =RAPL_DOMAIN_PP0 ; - rd->regs[0 ] =MSR_PP0_POWER_LIMIT ; - rd->regs[1 ] =MSR_PP0_ENERGY_STATUS ; - rd->regs[2 ] =0 ; - rd->regs[3 ] =MSR_PP0_POLICY ; - rd->regs[4 ] =0 ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PP0_POWER_LIMIT ; + rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PP0_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_PERF ] =0 ; + rd->regs[RAPL_DOMAIN_REG_POLICY ] =MSR_PP0_POLICY ; + rd->regs[RAPL_DOMAIN_REG_INFO ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_PP1 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP1 ]; rd->id =RAPL_DOMAIN_PP1 ; - rd->regs[0 ] =MSR_PP1_POWER_LIMIT ; - rd->regs[1 ] =MSR_PP1_ENERGY_STATUS ; - rd->regs[2 ] =0 ; - rd->regs[3 ] =MSR_PP1_POLICY ; - rd->regs[4 ] =0 ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PP1_POWER_LIMIT ; + rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PP1_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_PERF ] =0 ; + rd->regs[RAPL_DOMAIN_REG_POLICY ] =MSR_PP1_POLICY ; + rd->regs[RAPL_DOMAIN_REG_INFO ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_DRAM ): rd->name = rapl_domain_names[RAPL_DOMAIN_DRAM ]; rd->id =RAPL_DOMAIN_DRAM ; - rd->regs[0 ] =MSR_DRAM_POWER_LIMIT ; - rd->regs[1 ] =MSR_DRAM_ENERGY_STATUS ; - rd->regs[2 ] =MSR_DRAM_PERF_STATUS ; - rd->regs[3 ] =0 ; - rd->regs[4 ] =MSR_DRAM_POWER_INFO ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_DRAM_POWER_LIMIT ; + rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_DRAM_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_PERF ] =MSR_DRAM_PERF_STATUS ; + rd->regs[RAPL_DOMAIN_REG_POLICY ] =0 ; + rd->regs[RAPL_DOMAIN_REG_INFO ] =MSR_DRAM_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->domain_energy_unit =
@@ -1282,8 +1282,8 @@ static int __init rapl_register_psys(void) rd->name = rapl_domain_names[RAPL_DOMAIN_PLATFORM ]; rd->id =RAPL_DOMAIN_PLATFORM ; - rd->regs[0 ] =MSR_PLATFORM_POWER_LIMIT ; - rd->regs[1 ] =MSR_PLATFORM_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PLATFORM_POWER_LIMIT ; + rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PLATFORM_ENERGY_STATUS ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 3/13 intel_rapl: introduce intel_rapl.h
In reply to Zhang RuiCreate a new header file for the common definitions that might be used by different RAPL Interface.
--- MAINTAINERS | 1 + drivers/powercap/intel_rapl.c | 101 +------------------------------------ include/linux/intel_rapl.h | 113 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 99 deletions(-) create mode 100644 include/linux/intel_rapl.h
MAINTAINERS +1 -0
@@ -12601,6 +12601,7 @@ F: drivers/base/power/ F: include/linux/pm.h F: include/linux/pm_* F: include/linux/powercap.h +F: include/linux/intel_rapl.h F: drivers/powercap/ F: kernel/configs/nopm.config
drivers/powercap/intel_rapl.c +2 -99
129 lines not on this page · raw message
include/linux/intel_rapl.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 4/13 intel_rapl: introduce struct rapl_if_private
In reply to Zhang RuiIntroduce a new structure, rapl_if_private, to save the private data for different RAPL Interface.
--- drivers/powercap/intel_rapl.c | 59 +++++++++++++++++++++---------------------- include/linux/intel_rapl.h | 15 +++++++++++ 2 files changed, 44 insertions(+), 30 deletions(-)
drivers/powercap/intel_rapl.c +29 -30
@@ -75,6 +75,9 @@ enum unit_type { TIME_UNIT, }; +/* private data for RAPL MSR Interface */ +static struct rapl_if_priv rapl_msr_priv; +/* per domain data, some are optional */ #define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2)
@@ -155,17 +158,14 @@ static const char * const rapl_domain_names[] = { "psys", }; -static struct powercap_control_type *control_type;/* PowerCap Controller */ -static struct rapl_domain *platform_rapl_domain;/* Platform (PSys) domain */ -/* caller to ensure CPU hotplug lock is held */ -static struct rapl_package *rapl_find_package_domain (int cpu) +static struct rapl_package *rapl_find_package_domain (int cpu,struct rapl_if_priv *priv) {int id =topology_logical_die_id (cpu);struct rapl_package *rp;list_for_each_entry (rp, &rapl_packages, plist) { -if (rp->id == id) +if (rp->id == id && rp->priv->control_type == priv->control_type)return rp; }
@@ -1090,12 +1090,12 @@ static void rapl_update_domain_data(struct rapl_package *rp)static void rapl_unregister_powercap (void ) { -if (platform_rapl_domain) { -powercap_unregister_zone (control_type, - &platform_rapl_domain->power_zone); -kfree (platform_rapl_domain); +if (&rapl_msr_priv.platform_rapl_domain) { +powercap_unregister_zone (rapl_msr_priv.control_type, + &rapl_msr_priv.platform_rapl_domain->power_zone); +kfree (rapl_msr_priv.platform_rapl_domain); } -powercap_unregister_control_type (control_type); +powercap_unregister_control_type (rapl_msr_priv.control_type); }static int rapl_package_register_powercap (struct rapl_package *rp)
@@ -1113,7 +1113,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp) nr_pl =find_nr_power_limit (rd);pr_debug ("register package domain %s\n" , rp->name); power_zone = powercap_register_zone(&rd->power_zone, - control_type, + rp->priv->control_type, rp->name, NULL, &zone_ops[rd->id], nr_pl,
@@ -1140,7 +1140,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp)/* number of power limits per domain varies */ nr_pl =find_nr_power_limit (rd); power_zone =powercap_register_zone (&rd->power_zone, - control_type, rd->name, + rp->priv->control_type, rd->name, rp->power_zone, &zone_ops[rd->id], nr_pl, &constraint_ops);
@@ -1161,7 +1161,7 @@ static int rapl_package_register_powercap(struct rapl_package *rp)*/ while (--rd >= rp->domains) {pr_debug ("unregister %s domain %s\n" , rp->name, rd->name); -powercap_unregister_zone (control_type, &rd->power_zone); +powercap_unregister_zone (rp->priv->control_type, &rd->power_zone); }return ret;
@@ -1191,9 +1191,9 @@ static int __init rapl_register_psys(void) rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ; rd->rpl[1 ].name = pl2_name; - rd->rp =rapl_find_package_domain (0 ); + rd->rp =rapl_find_package_domain (0 , &rapl_msr_priv); - power_zone =powercap_register_zone (&rd->power_zone, control_type, + power_zone =powercap_register_zone (&rd->power_zone, rapl_msr_priv.control_type,"psys" ,NULL , &zone_ops[RAPL_DOMAIN_PLATFORM ],2 , &constraint_ops);
@@ -1203,17 +1203,17 @@ static int __init rapl_register_psys(void)return PTR_ERR (power_zone); } - platform_rapl_domain = rd; + rapl_msr_priv.platform_rapl_domain = rd;return 0 ; }static int __init rapl_register_powercap (void ) { - control_type =powercap_register_control_type (NULL ,"intel-rapl" ,NULL ); -if (IS_ERR (control_type)) { + rapl_msr_priv.control_type =powercap_register_control_type (NULL ,"intel-rapl" ,NULL ); +if (IS_ERR (rapl_msr_priv.control_type)) {pr_debug ("failed to register powercap control_type.\n" ); -return PTR_ERR (control_type); +return PTR_ERR (rapl_msr_priv.control_type); }return 0 ; }
@@ -1338,16 +1338,16 @@ static void rapl_remove_package(struct rapl_package *rp) }pr_debug ("remove package, undo power limit on %s: %s\n" , rp->name, rd->name); -powercap_unregister_zone (control_type, &rd->power_zone); +powercap_unregister_zone (rp->priv->control_type, &rd->power_zone); }/* do parent zone last */ -powercap_unregister_zone (control_type, &rd_package->power_zone); +powercap_unregister_zone (rp->priv->control_type, &rd_package->power_zone);list_del (&rp->plist);kfree (rp); }/* called from CPU hotplug notifier, hotplug lock held */ -static struct rapl_package *rapl_add_package (int cpu) +static struct rapl_package *rapl_add_package (int cpu,struct rapl_if_priv *priv) {int id =topology_logical_die_id (cpu);struct rapl_package *rp;
@@ -1361,6 +1361,7 @@ static struct rapl_package *rapl_add_package(int cpu)/* add the new package to the list */ rp->id = id; rp->lead_cpu = cpu; + rp->priv = priv;if (topology_max_die_per_package () >1 ) snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH,
@@ -1399,9 +1400,9 @@ static int rapl_cpu_online(unsigned int cpu) {struct rapl_package *rp; - rp =rapl_find_package_domain (cpu); + rp =rapl_find_package_domain (cpu, &rapl_msr_priv);if (!rp) { - rp =rapl_add_package (cpu); + rp =rapl_add_package (cpu, &rapl_msr_priv);if (IS_ERR (rp))return PTR_ERR (rp); }
@@ -1414,7 +1415,7 @@ static int rapl_cpu_down_prep(unsigned int cpu)struct rapl_package *rp;int lead_cpu; - rp =rapl_find_package_domain (cpu); + rp =rapl_find_package_domain (cpu, &rapl_msr_priv);if (!rp)return 0 ;
@@ -1427,8 +1428,6 @@ static int rapl_cpu_down_prep(unsigned int cpu)return 0 ; } -static enum cpuhp_state pcap_rapl_online; -static void power_limit_state_save (void ) {struct rapl_package *rp;
@@ -1538,7 +1537,7 @@ static int __init rapl_init(void) rapl_cpu_online, rapl_cpu_down_prep);if (ret <0 ) goto err_unreg; - pcap_rapl_online = ret; + rapl_msr_priv.pcap_rapl_online = ret;/* Don't bail out if PSys is not supported */ rapl_register_psys ();
@@ -1550,7 +1549,7 @@ static int __init rapl_init(void)return 0 ; err_unreg_all: -cpuhp_remove_state (pcap_rapl_online); +cpuhp_remove_state (rapl_msr_priv.pcap_rapl_online); err_unreg:rapl_unregister_powercap ();
@@ -1560,7 +1559,7 @@ static int __init rapl_init(void) static void __exit rapl_exit(void) {unregister_pm_notifier (&rapl_pm_notifier); -cpuhp_remove_state (pcap_rapl_online); +cpuhp_remove_state (rapl_msr_priv.pcap_rapl_online);rapl_unregister_powercap (); }
include/linux/intel_rapl.h +15 -0
@@ -88,6 +88,20 @@ struct rapl_domain {struct rapl_package *rp; }; +/** +* struct rapl_if_priv: private data for different RAPL interfaces +* @control_type: Each RAPL interface must have its own powercap +* control type. +* @platform_rapl_domain: Optional. Some RAPL interface may have platform +* level RAPL control. +* @pcap_rapl_online: CPU hotplug state for each RAPL interface. +*/ +struct rapl_if_priv { +struct powercap_control_type *control_type; +struct rapl_domain *platform_rapl_domain; +enum cpuhp_state pcap_rapl_online; +}; +/* maximum rapl package domain name: package-%d-die-%d */ #define PACKAGE_DOMAIN_NAME_LENGTH 30
@@ -108,6 +122,7 @@ struct rapl_package {/* Track active cpus */ struct cpumask cpumask;char name[PACKAGE_DOMAIN_NAME_LENGTH ]; + struct rapl_if_priv *priv; };#endif /* __INTEL_RAPL_H__ */
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 5/13 intel_rapl: abstract register address
In reply to Zhang RuiMSR and MMIO RAPL interface have different sets of registers, thus the RAPL register address should be obtained from interface specific structure, i.e. struct rapl_if_private, instead.
--- drivers/powercap/intel_rapl.c | 73 +++++++++++++++++++------------------------ include/linux/intel_rapl.h | 4 +++ 2 files changed, 37 insertions(+), 40 deletions(-)
drivers/powercap/intel_rapl.c +33 -40
@@ -76,7 +76,19 @@ enum unit_type { };/* private data for RAPL MSR Interface */ -static struct rapl_if_priv rapl_msr_priv; +static struct rapl_if_priv rapl_msr_priv = { + .reg_unit =MSR_RAPL_POWER_UNIT , + .regs[RAPL_DOMAIN_PACKAGE ] = { +MSR_PKG_POWER_LIMIT ,MSR_PKG_ENERGY_STATUS ,MSR_PKG_PERF_STATUS ,0 ,MSR_PKG_POWER_INFO }, + .regs[RAPL_DOMAIN_PP0 ] = { +MSR_PP0_POWER_LIMIT ,MSR_PP0_ENERGY_STATUS ,0 ,MSR_PP0_POLICY ,0 }, + .regs[RAPL_DOMAIN_PP1 ] = { +MSR_PP1_POWER_LIMIT ,MSR_PP1_ENERGY_STATUS ,0 ,MSR_PP1_POLICY ,0 }, + .regs[RAPL_DOMAIN_DRAM ] = { +MSR_DRAM_POWER_LIMIT ,MSR_DRAM_ENERGY_STATUS ,MSR_DRAM_PERF_STATUS ,0 ,MSR_DRAM_POWER_INFO }, + .regs[RAPL_DOMAIN_PLATFORM ] = { +MSR_PLATFORM_POWER_LIMIT ,MSR_PLATFORM_ENERGY_STATUS ,0 ,0 ,0 }, +};/* per domain data, some are optional */ #define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2)
@@ -541,15 +553,17 @@ static void rapl_init_domains(struct rapl_package *rp)for (i =0 ; i <RAPL_DOMAIN_MAX ; i++) {unsigned int mask = rp->domain_map & (1 << i); + + rd->regs[RAPL_DOMAIN_REG_LIMIT ] = rp->priv->regs[i][RAPL_DOMAIN_REG_LIMIT ]; + rd->regs[RAPL_DOMAIN_REG_STATUS ] = rp->priv->regs[i][RAPL_DOMAIN_REG_STATUS ]; + rd->regs[RAPL_DOMAIN_REG_PERF ] = rp->priv->regs[i][RAPL_DOMAIN_REG_PERF ]; + rd->regs[RAPL_DOMAIN_REG_POLICY ] = rp->priv->regs[i][RAPL_DOMAIN_REG_POLICY ]; + rd->regs[RAPL_DOMAIN_REG_INFO ] = rp->priv->regs[i][RAPL_DOMAIN_REG_INFO ]; +switch (mask) {case BIT (RAPL_DOMAIN_PACKAGE ): rd->name = rapl_domain_names[RAPL_DOMAIN_PACKAGE ]; rd->id =RAPL_DOMAIN_PACKAGE ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PKG_POWER_LIMIT ; - rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PKG_ENERGY_STATUS ; - rd->regs[RAPL_DOMAIN_REG_PERF ] =MSR_PKG_PERF_STATUS ; - rd->regs[RAPL_DOMAIN_REG_POLICY ] =0 ; - rd->regs[RAPL_DOMAIN_REG_INFO ] =MSR_PKG_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
@@ -558,33 +572,18 @@ static void rapl_init_domains(struct rapl_package *rp)case BIT (RAPL_DOMAIN_PP0 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP0 ]; rd->id =RAPL_DOMAIN_PP0 ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PP0_POWER_LIMIT ; - rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PP0_ENERGY_STATUS ; - rd->regs[RAPL_DOMAIN_REG_PERF ] =0 ; - rd->regs[RAPL_DOMAIN_REG_POLICY ] =MSR_PP0_POLICY ; - rd->regs[RAPL_DOMAIN_REG_INFO ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_PP1 ): rd->name = rapl_domain_names[RAPL_DOMAIN_PP1 ]; rd->id =RAPL_DOMAIN_PP1 ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PP1_POWER_LIMIT ; - rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PP1_ENERGY_STATUS ; - rd->regs[RAPL_DOMAIN_REG_PERF ] =0 ; - rd->regs[RAPL_DOMAIN_REG_POLICY ] =MSR_PP1_POLICY ; - rd->regs[RAPL_DOMAIN_REG_INFO ] =0 ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name;break ;case BIT (RAPL_DOMAIN_DRAM ): rd->name = rapl_domain_names[RAPL_DOMAIN_DRAM ]; rd->id =RAPL_DOMAIN_DRAM ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_DRAM_POWER_LIMIT ; - rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_DRAM_ENERGY_STATUS ; - rd->regs[RAPL_DOMAIN_REG_PERF ] =MSR_DRAM_PERF_STATUS ; - rd->regs[RAPL_DOMAIN_REG_POLICY ] =0 ; - rd->regs[RAPL_DOMAIN_REG_INFO ] =MSR_DRAM_POWER_INFO ; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->domain_energy_unit =
@@ -806,9 +805,9 @@ static int rapl_check_unit_core(struct rapl_package *rp, int cpu)u64 msr_val;u32 value; -if (rdmsrl_safe_on_cpu (cpu,MSR_RAPL_POWER_UNIT , &msr_val)) { +if (rdmsrl_safe_on_cpu (cpu, rp->priv->reg_unit, &msr_val)) {pr_err ("Failed to read power unit MSR 0x%x on CPU %d, exit.\n" , -MSR_RAPL_POWER_UNIT , cpu); + rp->priv->reg_unit, cpu);return -ENODEV ; }
@@ -832,9 +831,9 @@ static int rapl_check_unit_atom(struct rapl_package *rp, int cpu)u64 msr_val;u32 value; -if (rdmsrl_safe_on_cpu (cpu,MSR_RAPL_POWER_UNIT , &msr_val)) { +if (rdmsrl_safe_on_cpu (cpu, rp->priv->reg_unit, &msr_val)) {pr_err ("Failed to read power unit MSR 0x%x on CPU %d, exit.\n" , -MSR_RAPL_POWER_UNIT , cpu); + rp->priv->reg_unit, cpu);return -ENODEV ; } value = (msr_val &ENERGY_UNIT_MASK ) >>ENERGY_UNIT_OFFSET ;
@@ -1173,10 +1172,10 @@ static int __init rapl_register_psys(void)struct powercap_zone *power_zone;u64 val; -if (rdmsrl_safe_on_cpu (0 ,MSR_PLATFORM_ENERGY_STATUS , &val) || !val) +if (rdmsrl_safe_on_cpu (0 , rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ], &val) || !val)return -ENODEV ; -if (rdmsrl_safe_on_cpu (0 ,MSR_PLATFORM_POWER_LIMIT , &val) || !val) +if (rdmsrl_safe_on_cpu (0 , rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ], &val) || !val)return -ENODEV ; rd =kzalloc (sizeof (*rd),GFP_KERNEL );
@@ -1185,8 +1184,8 @@ static int __init rapl_register_psys(void) rd->name = rapl_domain_names[RAPL_DOMAIN_PLATFORM ]; rd->id =RAPL_DOMAIN_PLATFORM ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] =MSR_PLATFORM_POWER_LIMIT ; - rd->regs[RAPL_DOMAIN_REG_STATUS ] =MSR_PLATFORM_ENERGY_STATUS ; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] = rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ]; + rd->regs[RAPL_DOMAIN_REG_STATUS ] = rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ]; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ;
@@ -1218,23 +1217,17 @@ static int __init rapl_register_powercap(void)return 0 ; } -static int rapl_check_domain (int cpu,int domain) +static int rapl_check_domain (int cpu,int domain,struct rapl_package *rp) { -unsigned msr; +u32 reg;u64 val =0 ;switch (domain) {case RAPL_DOMAIN_PACKAGE : - msr =MSR_PKG_ENERGY_STATUS ; -break ;case RAPL_DOMAIN_PP0 : - msr =MSR_PP0_ENERGY_STATUS ; -break ;case RAPL_DOMAIN_PP1 : - msr =MSR_PP1_ENERGY_STATUS ; -break ;case RAPL_DOMAIN_DRAM : - msr =MSR_DRAM_ENERGY_STATUS ; + reg = rp->priv->regs[domain][RAPL_DOMAIN_REG_STATUS ];break ;case RAPL_DOMAIN_PLATFORM :/* PSYS(PLATFORM) is not a CPU domain, so avoid printng error */
@@ -1246,7 +1239,7 @@ static int rapl_check_domain(int cpu, int domain)/* make sure domain counters are available and contains non-zero * values, otherwise skip it. */ -if (rdmsrl_safe_on_cpu (cpu, msr, &val) || !val) +if (rdmsrl_safe_on_cpu (cpu, reg, &val) || !val)return -ENODEV ;return 0 ;
@@ -1293,7 +1286,7 @@ static int rapl_detect_domains(struct rapl_package *rp, int cpu)for (i =0 ; i <RAPL_DOMAIN_MAX ; i++) {/* use physical package id to read counters */ -if (!rapl_check_domain (cpu, i)) { +if (!rapl_check_domain (cpu, i, rp)) { rp->domain_map |=1 << i;pr_info ("Found RAPL domain %s\n" , rapl_domain_names[i]); }
include/linux/intel_rapl.h +4 -0
@@ -95,11 +95,15 @@ struct rapl_domain {* @platform_rapl_domain: Optional. Some RAPL interface may have platform * level RAPL control. * @pcap_rapl_online: CPU hotplug state for each RAPL interface. +* @reg_unit: Register for getting energy/power/time unit. +* @regs: Register sets for different RAPL Domains. */ struct rapl_if_priv {struct powercap_control_type *control_type;struct rapl_domain *platform_rapl_domain;enum cpuhp_state pcap_rapl_online; +u32 reg_unit; +u32 regs[RAPL_DOMAIN_MAX ][RAPL_DOMAIN_REG_MAX ]; };/* maximum rapl package domain name: package-%d-die-%d */
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 6/13 intel_rapl: abstract register access operations
In reply to Zhang RuiMSR and MMIO RAPL interfaces have different ways to access the registers, thus in order to abstract the register access operations, two callbacks, .read_raw()/.write_raw() are introduced, and they should be implemented by MSR RAPL and MMIO RAPL interface driver respectly.
This patch implements them for the MSR I/F only.
--- drivers/powercap/intel_rapl.c | 110 ++++++++++++++++++++++-------------------- include/linux/intel_rapl.h | 13 +++++ 2 files changed, 70 insertions(+), 53 deletions(-)
drivers/powercap/intel_rapl.c +57 -53
@@ -93,13 +93,6 @@ static struct rapl_if_priv rapl_msr_priv = {/* per domain data, some are optional */ #define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2) -struct msrl_action { -u32 msr_no; -u64 clear_mask; -u64 set_mask; -int err; -}; -#define DOMAIN_STATE_INACTIVE BIT(0)#define DOMAIN_STATE_POWER_LIMIT_SET BIT(1)#define DOMAIN_STATE_BIOS_LOCKED BIT(2)
@@ -692,16 +685,16 @@ static int rapl_read_data_raw(struct rapl_domain *rd,enum rapl_primitives prim, bool xlate, u64 *data) { - u64 value, final; -u32 msr; + u64 value;struct rapl_primitive_info *rp = &rpi[prim]; +struct reg_action ra;int cpu;if (!rp->name || rp->flag &RAPL_PRIMITIVE_DUMMY )return -EINVAL ; - msr = rd->regs[rp->id]; -if (!msr) + ra.reg = rd->regs[rp->id]; +if (!ra.reg)return -EINVAL ; cpu = rd->rp->lead_cpu;
@@ -717,47 +710,23 @@ static int rapl_read_data_raw(struct rapl_domain *rd,return 0 ; } -if (rdmsrl_safe_on_cpu (cpu, msr, &value)) { -pr_debug ("failed to read msr 0x%x on cpu %d\n" , msr, cpu); + ra.mask = rp->mask; + +if (rd->rp->priv->read_raw (cpu, &ra)) { +pr_debug ("failed to read reg 0x%x on cpu %d\n" , ra.reg, cpu);return -EIO ; } - final = value & rp->mask; - final = final >> rp->shift; + value = ra.value >> rp->shift; +if (xlate) - *data =rapl_unit_xlate (rd, rp->unit, final,0 ); + *data =rapl_unit_xlate (rd, rp->unit, value,0 );else - *data = final; + *data = value;return 0 ; } - -static int msrl_update_safe (u32 msr_no,u64 clear_mask,u64 set_mask) -{ -int err; -u64 val; - - err =rdmsrl_safe (msr_no, &val); -if (err) - goto out; - - val &= ~clear_mask; - val |= set_mask; - - err =wrmsrl_safe (msr_no, val); - -out: -return err; -} - -static void msrl_update_func (void *info) -{ -struct msrl_action *ma = info; - - ma->err =msrl_update_safe (ma->msr_no, ma->clear_mask, ma->set_mask); -} -/* Similar use of primitive info in the read counterpart */ static int rapl_write_data_raw(struct rapl_domain *rd, enum rapl_primitives prim,
@@ -766,7 +735,7 @@ static int rapl_write_data_raw(struct rapl_domain *rd,struct rapl_primitive_info *rp = &rpi[prim];int cpu;u64 bits; -struct msrl_action ma; +struct reg_action ra;int ret; cpu = rd->rp->lead_cpu;
@@ -774,17 +743,13 @@ static int rapl_write_data_raw(struct rapl_domain *rd, bits <<= rp->shift; bits &= rp->mask; -memset (&ma,0 ,sizeof (ma)); +memset (&ra,0 ,sizeof (ra)); - ma.msr_no = rd->regs[rp->id]; - ma.clear_mask = rp->mask; - ma.set_mask = bits; + ra.reg = rd->regs[rp->id]; + ra.mask = rp->mask; + ra.value = bits; - ret =smp_call_function_single (cpu, msrl_update_func, &ma,1 ); -if (ret) -WARN_ON_ONCE (ret); -else - ret = ma.err; + ret = rd->rp->priv->write_raw (cpu, &ra);return ret; }
@@ -1507,6 +1472,43 @@ static struct notifier_block rapl_pm_notifier = { .notifier_call = rapl_pm_callback, }; +static int rapl_msr_read_raw (int cpu,struct reg_action *ra) +{ +if (rdmsrl_safe_on_cpu (cpu, ra->reg, &ra->value)) { +pr_debug ("failed to read msr 0x%x on cpu %d\n" , ra->reg, cpu); +return -EIO ; + } + ra->value &= ra->mask; +return 0 ; +} + +static void rapl_msr_update_func (void *info) +{ +struct reg_action *ra = info; +u64 val; + + ra->err =rdmsrl_safe (ra->reg, &val); +if (ra->err) +return ; + + val &= ~ra->mask; + val |= ra->value; + + ra->err =wrmsrl_safe (ra->reg, val); +} + + +static int rapl_msr_write_raw (int cpu,struct reg_action *ra) +{ +int ret; + + ret =smp_call_function_single (cpu, rapl_msr_update_func, ra,1 ); +if (WARN_ON_ONCE (ret)) +return ret; + +return ra->err; +} +static int __init rapl_init (void ) {const struct x86_cpu_id *id;
@@ -1522,6 +1524,8 @@ static int __init rapl_init(void) rapl_defaults = (struct rapl_defaults *)id->driver_data; + rapl_msr_priv.read_raw = rapl_msr_read_raw; + rapl_msr_priv.write_raw = rapl_msr_write_raw; ret =rapl_register_powercap ();if (ret)return ret;
include/linux/intel_rapl.h +13 -0
@@ -88,6 +88,13 @@ struct rapl_domain {struct rapl_package *rp; }; +struct reg_action { +u32 reg; +u64 mask; +u64 value; +int err; +}; +/** * struct rapl_if_priv: private data for different RAPL interfaces * @control_type: Each RAPL interface must have its own powercap
@@ -97,6 +104,10 @@ struct rapl_domain {* @pcap_rapl_online: CPU hotplug state for each RAPL interface. * @reg_unit: Register for getting energy/power/time unit. * @regs: Register sets for different RAPL Domains. +* @read_raw: Callback for reading RAPL interface specific +* registers. +* @write_raw: Callback for writing RAPL interface specific +* registers. */ struct rapl_if_priv {struct powercap_control_type *control_type;
@@ -104,6 +115,8 @@ struct rapl_if_priv {enum cpuhp_state pcap_rapl_online;u32 reg_unit;u32 regs[RAPL_DOMAIN_MAX ][RAPL_DOMAIN_REG_MAX ]; +int (*read_raw)(int cpu,struct reg_action *ra); +int (*write_raw)(int cpu,struct reg_action *ra); };/* maximum rapl package domain name: package-%d-die-%d */
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 7/13 intel_rapl: cleanup some functions
In reply to Zhang RuiPreviously, there are three functions:rapl_register_psys(), which registers platform rapl domain. rapl_register_powercap(), which registers powercap control type. rapl_unregsiter_powercap(), which unregisters platform rapl domain and powercap control type.
This is confusing as the function name does not describe what it does clearly.
With this patch, the three functions are removed, and two new functions rapl_register_platform_domain()/rapl_unregister_platform_domain() are introduced instead, and they do exactly what their function name describes.
Plus, as part of the common code, hardcoded MSR accesses in these functions are converted to follow the abstracted register access.
--- drivers/powercap/intel_rapl.c | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
drivers/powercap/intel_rapl.c +31 -31
@@ -1052,16 +1052,6 @@ static void rapl_update_domain_data(struct rapl_package *rp) } -static void rapl_unregister_powercap (void ) -{ -if (&rapl_msr_priv.platform_rapl_domain) { -powercap_unregister_zone (rapl_msr_priv.control_type, - &rapl_msr_priv.platform_rapl_domain->power_zone); -kfree (rapl_msr_priv.platform_rapl_domain); - } -powercap_unregister_control_type (rapl_msr_priv.control_type); -} -static int rapl_package_register_powercap (struct rapl_package *rp) {struct rapl_domain *rd;
@@ -1131,16 +1121,23 @@ static int rapl_package_register_powercap(struct rapl_package *rp)return ret; } -static int __init rapl_register_psys (void ) +static int __init rapl_add_platform_domain (struct rapl_if_priv *priv) {struct rapl_domain *rd;struct powercap_zone *power_zone; -u64 val; +struct reg_action ra; +int ret; -if (rdmsrl_safe_on_cpu (0 , rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ], &val) || !val) + ra.reg = priv->regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ]; + ra.mask = ~0 ; + ret = priv->read_raw (0 , &ra); +if (ret || !ra.value)return -ENODEV ; -if (rdmsrl_safe_on_cpu (0 , rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ], &val) || !val) + ra.reg = priv->regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ]; + ra.mask = ~0 ; + ret = priv->read_raw (0 , &ra); +if (ret || !ra.value)return -ENODEV ; rd =kzalloc (sizeof (*rd),GFP_KERNEL );
@@ -1149,15 +1146,15 @@ static int __init rapl_register_psys(void) rd->name = rapl_domain_names[RAPL_DOMAIN_PLATFORM ]; rd->id =RAPL_DOMAIN_PLATFORM ; - rd->regs[RAPL_DOMAIN_REG_LIMIT ] = rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ]; - rd->regs[RAPL_DOMAIN_REG_STATUS ] = rapl_msr_priv.regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ]; + rd->regs[RAPL_DOMAIN_REG_LIMIT ] = priv->regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_LIMIT ]; + rd->regs[RAPL_DOMAIN_REG_STATUS ] = priv->regs[RAPL_DOMAIN_PLATFORM ][RAPL_DOMAIN_REG_STATUS ]; rd->rpl[0 ].prim_id =PL1_ENABLE ; rd->rpl[0 ].name = pl1_name; rd->rpl[1 ].prim_id =PL2_ENABLE ; rd->rpl[1 ].name = pl2_name; - rd->rp =rapl_find_package_domain (0 , &rapl_msr_priv); + rd->rp =rapl_find_package_domain (0 , priv); - power_zone =powercap_register_zone (&rd->power_zone, rapl_msr_priv.control_type, + power_zone =powercap_register_zone (&rd->power_zone, priv->control_type,"psys" ,NULL , &zone_ops[RAPL_DOMAIN_PLATFORM ],2 , &constraint_ops);
@@ -1167,19 +1164,18 @@ static int __init rapl_register_psys(void)return PTR_ERR (power_zone); } - rapl_msr_priv.platform_rapl_domain = rd; + priv->platform_rapl_domain = rd;return 0 ; } -static int __init rapl_register_powercap (void ) +static void rapl_remove_platform_domain (struct rapl_if_priv *priv) { - rapl_msr_priv.control_type =powercap_register_control_type (NULL ,"intel-rapl" ,NULL ); -if (IS_ERR (rapl_msr_priv.control_type)) { -pr_debug ("failed to register powercap control_type.\n" ); -return PTR_ERR (rapl_msr_priv.control_type); +if (priv->platform_rapl_domain) { +powercap_unregister_zone (priv->control_type, + &priv->platform_rapl_domain->power_zone); +kfree (priv->platform_rapl_domain); } -return 0 ; }static int rapl_check_domain (int cpu,int domain,struct rapl_package *rp)
@@ -1526,9 +1522,12 @@ static int __init rapl_init(void) rapl_msr_priv.read_raw = rapl_msr_read_raw; rapl_msr_priv.write_raw = rapl_msr_write_raw; - ret =rapl_register_powercap (); -if (ret) -return ret; + + rapl_msr_priv.control_type =powercap_register_control_type (NULL ,"intel-rapl" ,NULL ); +if (IS_ERR (rapl_msr_priv.control_type)) { +pr_debug ("failed to register powercap control_type.\n" ); +return PTR_ERR (rapl_msr_priv.control_type); + } ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"powercap/rapl:online" , rapl_cpu_online, rapl_cpu_down_prep);
@@ -1537,7 +1536,7 @@ static int __init rapl_init(void) rapl_msr_priv.pcap_rapl_online = ret;/* Don't bail out if PSys is not supported */ -rapl_register_psys (); +rapl_add_platform_domain (&rapl_msr_priv); ret =register_pm_notifier (&rapl_pm_notifier);if (ret)
@@ -1549,7 +1548,7 @@ static int __init rapl_init(void)cpuhp_remove_state (rapl_msr_priv.pcap_rapl_online); err_unreg: -rapl_unregister_powercap (); +powercap_unregister_control_type (rapl_msr_priv.control_type);return ret; }
@@ -1557,7 +1556,8 @@ static void __exit rapl_exit(void) {unregister_pm_notifier (&rapl_pm_notifier);cpuhp_remove_state (rapl_msr_priv.pcap_rapl_online); -rapl_unregister_powercap (); +rapl_remove_platform_domain (&rapl_msr_priv); +powercap_unregister_control_type (rapl_msr_priv.control_type); }module_init (rapl_init);
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 8/13 intel_rapl: cleanup hardcoded MSR access
In reply to Zhang RuiThere are still some places in the common code that have hardcoded MSR access, convert them to follow the abstracted register access.
--- drivers/powercap/intel_rapl.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
drivers/powercap/intel_rapl.c +22 -16
@@ -767,22 +767,24 @@ static int rapl_write_data_raw(struct rapl_domain *rd,*/ static int rapl_check_unit_core (struct rapl_package *rp,int cpu) { -u64 msr_val; +struct reg_action ra;u32 value; -if (rdmsrl_safe_on_cpu (cpu, rp->priv->reg_unit, &msr_val)) { -pr_err ("Failed to read power unit MSR 0x%x on CPU %d, exit.\n" , + ra.reg = rp->priv->reg_unit; + ra.mask = ~0 ; +if (rp->priv->read_raw (cpu, &ra)) { +pr_err ("Failed to read power unit REG 0x%x on CPU %d, exit.\n" , rp->priv->reg_unit, cpu);return -ENODEV ; } - value = (msr_val &ENERGY_UNIT_MASK ) >>ENERGY_UNIT_OFFSET ; + value = (ra.value &ENERGY_UNIT_MASK ) >>ENERGY_UNIT_OFFSET ; rp->energy_unit =ENERGY_UNIT_SCALE *1000000 / (1 << value); - value = (msr_val &POWER_UNIT_MASK ) >>POWER_UNIT_OFFSET ; + value = (ra.value &POWER_UNIT_MASK ) >>POWER_UNIT_OFFSET ; rp->power_unit =1000000 / (1 << value); - value = (msr_val &TIME_UNIT_MASK ) >>TIME_UNIT_OFFSET ; + value = (ra.value &TIME_UNIT_MASK ) >>TIME_UNIT_OFFSET ; rp->time_unit =1000000 / (1 << value); pr_debug("Core CPU %s energy=%dpJ, time=%dus, power=%duW\n",
@@ -793,21 +795,24 @@ static int rapl_check_unit_core(struct rapl_package *rp, int cpu)static int rapl_check_unit_atom (struct rapl_package *rp,int cpu) { -u64 msr_val; +struct reg_action ra;u32 value; -if (rdmsrl_safe_on_cpu (cpu, rp->priv->reg_unit, &msr_val)) { -pr_err ("Failed to read power unit MSR 0x%x on CPU %d, exit.\n" , + ra.reg = rp->priv->reg_unit; + ra.mask = ~0 ; +if (rp->priv->read_raw (cpu, &ra)) { +pr_err ("Failed to read power unit REG 0x%x on CPU %d, exit.\n" , rp->priv->reg_unit, cpu);return -ENODEV ; } - value = (msr_val &ENERGY_UNIT_MASK ) >>ENERGY_UNIT_OFFSET ; + + value = (ra.value &ENERGY_UNIT_MASK ) >>ENERGY_UNIT_OFFSET ; rp->energy_unit =ENERGY_UNIT_SCALE *1 << value; - value = (msr_val &POWER_UNIT_MASK ) >>POWER_UNIT_OFFSET ; + value = (ra.value &POWER_UNIT_MASK ) >>POWER_UNIT_OFFSET ; rp->power_unit = (1 << value) *1000 ; - value = (msr_val &TIME_UNIT_MASK ) >>TIME_UNIT_OFFSET ; + value = (ra.value &TIME_UNIT_MASK ) >>TIME_UNIT_OFFSET ; rp->time_unit =1000000 / (1 << value); pr_debug("Atom %s energy=%dpJ, time=%dus, power=%duW\n",
@@ -1180,15 +1185,14 @@ static void rapl_remove_platform_domain(struct rapl_if_priv *priv)static int rapl_check_domain (int cpu,int domain,struct rapl_package *rp) { -u32 reg; -u64 val =0 ; +struct reg_action ra;switch (domain) {case RAPL_DOMAIN_PACKAGE :case RAPL_DOMAIN_PP0 :case RAPL_DOMAIN_PP1 :case RAPL_DOMAIN_DRAM : - reg = rp->priv->regs[domain][RAPL_DOMAIN_REG_STATUS ]; + ra.reg = rp->priv->regs[domain][RAPL_DOMAIN_REG_STATUS ];break ;case RAPL_DOMAIN_PLATFORM :/* PSYS(PLATFORM) is not a CPU domain, so avoid printng error */
@@ -1200,7 +1204,9 @@ static int rapl_check_domain(int cpu, int domain, struct rapl_package *rp)/* make sure domain counters are available and contains non-zero * values, otherwise skip it. */ -if (rdmsrl_safe_on_cpu (cpu, reg, &val) || !val) + + ra.mask = ~0 ; +if (rp->priv->read_raw (cpu, &ra) || !ra.value)return -ENODEV ;return 0 ;
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 9/13 intel_rapl: abstract RAPL common code
In reply to Zhang RuiSplit intel_rapl.c to intel_rapl_common.c and intel_rapl_msr.c, where intel_rapl_common.c contains the common code that can be used by both MSR and MMIO interface.intel_rapl_msr.c contains the implementation of RAPL MSR interface.
--- drivers/powercap/Kconfig | 11 +- drivers/powercap/Makefile | 3 +- drivers/powercap/intel_rapl.c | 1574 ---------------------------------- drivers/powercap/intel_rapl_common.c | 1469 +++++++++++++++++++++++++++++++ drivers/powercap/intel_rapl_msr.c | 163 ++++ include/linux/intel_rapl.h | 7 + 6 files changed, 1648 insertions(+), 1579 deletions(-) delete mode 100644 drivers/powercap/intel_rapl.c create mode 100644 drivers/powercap/intel_rapl_common.c create mode 100644 drivers/powercap/intel_rapl_msr.c
drivers/powercap/Kconfig +7 -4
@@ -16,14 +16,17 @@ menuconfig POWERCAP if POWERCAP # Client driver configurations go here. +config INTEL_RAPL_CORE + tristate + config INTEL_RAPL - tristate "Intel RAPL Support" + tristate "Intel RAPL Support via MSR Interface" depends on X86 && IOSF_MBI - default n + select INTEL_RAPL_CORE ---help--- This enables support for the Intel Running Average Power Limit (RAPL) - technology which allows power limits to be enforced and monitored on - modern Intel processors (Sandy Bridge and later). + technology via MSR interface, which allows power limits to be enforced + and monitored on modern Intel processors (Sandy Bridge and later). In RAPL, the platform level settings are divided into domains for fine grained control. These domains include processor package, DRAM
drivers/powercap/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_POWERCAP) += powercap_sys.o -obj-$(CONFIG_INTEL_RAPL) += intel_rapl.o +obj-$(CONFIG_INTEL_RAPL_CORE) += intel_rapl_common.o +obj-$(CONFIG_INTEL_RAPL) += intel_rapl_msr.o obj-$(CONFIG_IDLE_INJECT) += idle_inject.o
drivers/powercap/intel_rapl.c deleted +0 -1574
1,574 lines not on this page · raw message
drivers/powercap/intel_rapl_common.c new file +1469 -0
1,399 lines not on this page · raw message
drivers/powercap/intel_rapl_msr.c new file +163 -0
163 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
Zhang Rui
reviewerPATCH v2 10/13 intel_rapl: support 64 bit register
In reply to Zhang RuiRAPL MMIO interface uses 64 bit registers, thus force use 64 bit register for all the RAPL code.
--- drivers/powercap/intel_rapl_common.c | 6 +++--- drivers/powercap/intel_rapl_msr.c | 11 +++++++---- include/linux/intel_rapl.h | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/powercap/intel_rapl_common.c +3 -3
@@ -689,7 +689,7 @@ static int rapl_read_data_raw(struct rapl_domain *rd, ra.mask = rp->mask;if (rd->rp->priv->read_raw (cpu, &ra)) { -pr_debug ("failed to read reg 0x%x on cpu %d\n" , ra.reg, cpu); +pr_debug ("failed to read reg 0x%llx on cpu %d\n" , ra.reg, cpu);return -EIO ; }
@@ -749,7 +749,7 @@ static int rapl_check_unit_core(struct rapl_package *rp, int cpu) ra.reg = rp->priv->reg_unit; ra.mask = ~0 ;if (rp->priv->read_raw (cpu, &ra)) { -pr_err ("Failed to read power unit REG 0x%x on CPU %d, exit.\n" , +pr_err ("Failed to read power unit REG 0x%llx on CPU %d, exit.\n" , rp->priv->reg_unit, cpu);return -ENODEV ; }
@@ -777,7 +777,7 @@ static int rapl_check_unit_atom(struct rapl_package *rp, int cpu) ra.reg = rp->priv->reg_unit; ra.mask = ~0 ;if (rp->priv->read_raw (cpu, &ra)) { -pr_err ("Failed to read power unit REG 0x%x on CPU %d, exit.\n" , +pr_err ("Failed to read power unit REG 0x%llx on CPU %d, exit.\n" , rp->priv->reg_unit, cpu);return -ENODEV ; }
drivers/powercap/intel_rapl_msr.c +7 -4
@@ -84,8 +84,10 @@ static int rapl_cpu_down_prep(unsigned int cpu)static int rapl_msr_read_raw (int cpu,struct reg_action *ra) { -if (rdmsrl_safe_on_cpu (cpu, ra->reg, &ra->value)) { -pr_debug ("failed to read msr 0x%x on cpu %d\n" , ra->reg, cpu); +u32 msr = (u32 )ra->reg; + +if (rdmsrl_safe_on_cpu (cpu, msr, &ra->value)) { +pr_debug ("failed to read msr 0x%x on cpu %d\n" , msr, cpu);return -EIO ; } ra->value &= ra->mask;
@@ -95,16 +97,17 @@ static int rapl_msr_read_raw(int cpu, struct reg_action *ra)static void rapl_msr_update_func (void *info) {struct reg_action *ra = info; +u32 msr = (u32 )ra->reg;u64 val; - ra->err =rdmsrl_safe (ra->reg, &val); + ra->err =rdmsrl_safe (msr, &val);if (ra->err)return ; val &= ~ra->mask; val |= ra->value; - ra->err =wrmsrl_safe (ra->reg, val); + ra->err =wrmsrl_safe (msr, val); }static int rapl_msr_write_raw (int cpu,struct reg_action *ra)
include/linux/intel_rapl.h +4 -4
@@ -78,7 +78,7 @@ struct rapl_package;struct rapl_domain {const char *name;enum rapl_domain_type id; -int regs[RAPL_DOMAIN_REG_MAX ]; +u64 regs[RAPL_DOMAIN_REG_MAX ];struct powercap_zone power_zone;struct rapl_domain_data rdd;struct rapl_power_limit rpl[NR_POWER_LIMITS ];
@@ -89,7 +89,7 @@ struct rapl_domain { };struct reg_action { -u32 reg; +u64 reg;u64 mask;u64 value;int err;
@@ -113,8 +113,8 @@ struct rapl_if_priv {struct powercap_control_type *control_type;struct rapl_domain *platform_rapl_domain;enum cpuhp_state pcap_rapl_online; -u32 reg_unit; -u32 regs[RAPL_DOMAIN_MAX ][RAPL_DOMAIN_REG_MAX ]; +u64 reg_unit; +u64 regs[RAPL_DOMAIN_MAX ][RAPL_DOMAIN_REG_MAX ];int (*read_raw)(int cpu,struct reg_action *ra);int (*write_raw)(int cpu,struct reg_action *ra); };
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 11/13 intel_rapl: support two power limits for every RAPL domain
In reply to Zhang RuiRAPL MSR interface supports 2 power limits for package domain, and 1 power limit for other domains, while RAPL MMIO interface supports 2 power limits for both package and dram domains.
And when 2 power limits are supported, the FW_LOCK bit is in bit 63 of the register, instead of bit 31.
Remove the assumption that only pakcage domain supports 2 power limits. And allow the RAPL interface driver to specify the number of power limits supported, for every single RAPL domain it owns..
--- drivers/powercap/intel_rapl_common.c | 72 +++++++++++++----------------------- drivers/powercap/intel_rapl_msr.c | 1 + include/linux/intel_rapl.h | 2 + 3 files changed, 28 insertions(+), 47 deletions(-)
drivers/powercap/intel_rapl_common.c +25 -47
@@ -38,8 +38,8 @@#define POWER_LIMIT2_MASK (0x7FFFULL<<32)#define POWER_LIMIT2_ENABLE BIT_ULL(47)#define POWER_LIMIT2_CLAMP BIT_ULL(48) -#define POWER_PACKAGE_LOCK BIT_ULL(63) -#define POWER_PP_LOCK BIT(31) +#define POWER_HIGH_LOCK BIT_ULL(63) +#define POWER_LOW_LOCK BIT(31)#define TIME_WINDOW1_MASK (0x7FULL<<17)#define TIME_WINDOW2_MASK (0x7FULL<<49)
@@ -513,60 +513,38 @@ static const struct powercap_zone_constraint_ops constraint_ops = {/* called after domain detection and package level data are set */ static void rapl_init_domains (struct rapl_package *rp) { -int i; +enum rapl_domain_type i; +enum rapl_domain_reg_id j;struct rapl_domain *rd = rp->domains;for (i =0 ; i <RAPL_DOMAIN_MAX ; i++) {unsigned int mask = rp->domain_map & (1 << i); - rd->regs[RAPL_DOMAIN_REG_LIMIT ] = - rp->priv->regs[i][RAPL_DOMAIN_REG_LIMIT ]; - rd->regs[RAPL_DOMAIN_REG_STATUS ] = - rp->priv->regs[i][RAPL_DOMAIN_REG_STATUS ]; - rd->regs[RAPL_DOMAIN_REG_PERF ] = - rp->priv->regs[i][RAPL_DOMAIN_REG_PERF ]; - rd->regs[RAPL_DOMAIN_REG_POLICY ] = - rp->priv->regs[i][RAPL_DOMAIN_REG_POLICY ]; - rd->regs[RAPL_DOMAIN_REG_INFO ] = - rp->priv->regs[i][RAPL_DOMAIN_REG_INFO ]; - -switch (mask) { -case BIT (RAPL_DOMAIN_PACKAGE ): - rd->name = rapl_domain_names[RAPL_DOMAIN_PACKAGE ]; - rd->id =RAPL_DOMAIN_PACKAGE ; - rd->rpl[0 ].prim_id =PL1_ENABLE ; - rd->rpl[0 ].name = pl1_name; +if (!mask) +continue ; + + rd->rp = rp; + rd->name = rapl_domain_names[i]; + rd->id = i; + rd->rpl[0 ].prim_id =PL1_ENABLE ; + rd->rpl[0 ].name = pl1_name; +/* some domain may support two power limits */ +if (rp->priv->limits[i] ==2 ) { rd->rpl[1 ].prim_id =PL2_ENABLE ; rd->rpl[1 ].name = pl2_name; -break ; -case BIT (RAPL_DOMAIN_PP0 ): - rd->name = rapl_domain_names[RAPL_DOMAIN_PP0 ]; - rd->id =RAPL_DOMAIN_PP0 ; - rd->rpl[0 ].prim_id =PL1_ENABLE ; - rd->rpl[0 ].name = pl1_name; -break ; -case BIT (RAPL_DOMAIN_PP1 ): - rd->name = rapl_domain_names[RAPL_DOMAIN_PP1 ]; - rd->id =RAPL_DOMAIN_PP1 ; - rd->rpl[0 ].prim_id =PL1_ENABLE ; - rd->rpl[0 ].name = pl1_name; -break ; -case BIT (RAPL_DOMAIN_DRAM ): - rd->name = rapl_domain_names[RAPL_DOMAIN_DRAM ]; - rd->id =RAPL_DOMAIN_DRAM ; - rd->rpl[0 ].prim_id =PL1_ENABLE ; - rd->rpl[0 ].name = pl1_name; + } + +for (j =0 ; j <RAPL_DOMAIN_REG_MAX ; j++) + rd->regs[j] = rp->priv->regs[i][j]; + +if (i ==RAPL_DOMAIN_DRAM ) { rd->domain_energy_unit = rapl_defaults->dram_domain_energy_unit;if (rd->domain_energy_unit)pr_info ("DRAM domain energy unit %dpj\n" , rd->domain_energy_unit); -break ; - } -if (mask) { - rd->rp = rp; - rd++; } + rd++; } }
@@ -613,7 +591,7 @@ static struct rapl_primitive_info rpi[] = { RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),PRIMITIVE_INFO_INIT (POWER_LIMIT2 ,POWER_LIMIT2_MASK ,32 ,RAPL_DOMAIN_REG_LIMIT ,POWER_UNIT ,0 ), -PRIMITIVE_INFO_INIT (FW_LOCK ,POWER_PP_LOCK ,31 , +PRIMITIVE_INFO_INIT (FW_LOCK ,POWER_LOW_LOCK ,31 ,RAPL_DOMAIN_REG_LIMIT ,ARBITRARY_UNIT ,0 ),PRIMITIVE_INFO_INIT (PL1_ENABLE ,POWER_LIMIT1_ENABLE ,15 , RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
@@ -675,9 +653,9 @@ static int rapl_read_data_raw(struct rapl_domain *rd, cpu = rd->rp->lead_cpu; -/* special-case package domain, which uses a different bit */ -if (prim ==FW_LOCK && rd->id ==RAPL_DOMAIN_PACKAGE ) { - rp->mask =POWER_PACKAGE_LOCK ; +/* domain with 2 limits has different bit */ +if (prim ==FW_LOCK && rd->rp->priv->limits[rd->id] ==2 ) { + rp->mask =POWER_HIGH_LOCK ; rp->shift =63 ; }/* non-hardware data are collected by the polling thread */
drivers/powercap/intel_rapl_msr.c +1 -0
@@ -41,6 +41,7 @@ static struct rapl_if_priv rapl_msr_priv = { MSR_DRAM_POWER_LIMIT, MSR_DRAM_ENERGY_STATUS, MSR_DRAM_PERF_STATUS, 0, MSR_DRAM_POWER_INFO }, .regs[RAPL_DOMAIN_PLATFORM] = {MSR_PLATFORM_POWER_LIMIT ,MSR_PLATFORM_ENERGY_STATUS ,0 ,0 ,0 }, + .limits[RAPL_DOMAIN_PACKAGE] = 2, };/* Handles CPU hotplug on multi-socket systems.
include/linux/intel_rapl.h +2 -0
@@ -104,6 +104,7 @@ struct reg_action {* @pcap_rapl_online: CPU hotplug state for each RAPL interface. * @reg_unit: Register for getting energy/power/time unit. * @regs: Register sets for different RAPL Domains. +* @limits: Number of power limits supported by each domain. * @read_raw: Callback for reading RAPL interface specific * registers. * @write_raw: Callback for writing RAPL interface specific
@@ -115,6 +116,7 @@ struct rapl_if_priv {enum cpuhp_state pcap_rapl_online;u64 reg_unit;u64 regs[RAPL_DOMAIN_MAX ][RAPL_DOMAIN_REG_MAX ]; +int limits[RAPL_DOMAIN_MAX ];int (*read_raw)(int cpu,struct reg_action *ra);int (*write_raw)(int cpu,struct reg_action *ra); };
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 12/13 int340X/processor_thermal_device: add support for MMIO RAPL
In reply to Zhang RuiIntroduce MMIO RAPL support as Intel processor_thermal device exposes the capability to do RAPL control via MMIO registers.
--- drivers/thermal/intel/int340x_thermal/Kconfig | 6 + .../int340x_thermal/processor_thermal_device.c | 173 ++++++++++++++++++++- 2 files changed, 173 insertions(+), 6 deletions(-)
drivers/thermal/intel/int340x_thermal/Kconfig +6 -0
@@ -40,4 +40,10 @@ config INT3406_THERMAL brightness in order to address a thermal condition or to reduce power consumed by display device. +config PROC_THERMAL_MMIO_RAPL + bool + depends on 64BIT + depends on POWERCAP + select INTEL_RAPL_CORE + default y endif
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +167 -6
235 lines not on this page · raw message
Signature · 1 line
2.7.4
Zhang Rui
reviewerPATCH v2 13/13 intel_rapl: Fix module autoloading issue
In reply to Zhang Ruiintel_rapl driver used to have a list of cpuids, which is used to
1. check if the processor support RAPL MSRs
2. do some cpu model specific setting
3. module autoloading
Now, the cpu model specific setting are moved to intel_rapl_common.c as part of the common code, because the setup is also needed by RAPL MMIO interface on those platforms.
But removing the cpuid list from intel_rapl MSR interface driver results in that the driver can not be loaded automatically.
Maintaining another copy of the cpuid list in intel_rapl_msr.c does not make sense because it increases the complexity when enabling RAPL support on a new cpu model.
Fix the problem by creating an "intel_rapl_msr" platform device in the common code, and make RAPL MSR interface driver (intel_rapl_msr.c) probe the platform device directly.
--- drivers/powercap/intel_rapl_common.c | 45 ++++++++++++++++++++++-------------- drivers/powercap/intel_rapl_msr.c | 24 +++++++++++++++---- 2 files changed, 48 insertions(+), 21 deletions(-)
drivers/powercap/intel_rapl_common.c +28 -17
@@ -18,10 +18,11 @@#include <linux/cpu.h> #include <linux/powercap.h> #include <linux/suspend.h> -#include <asm/iosf_mbi.h> #include <linux/intel_rapl.h> -#include <linux/processor.h> +#include <linux/platform_device.h> + +#include <asm/iosf_mbi.h> #include <asm/cpu_device_id.h> #include <asm/intel-family.h>
@@ -136,8 +137,6 @@ static int rapl_write_data_raw(struct rapl_domain *rd,static u64 rapl_unit_xlate (struct rapl_domain *rd,enum unit_type type,u64 value,int to_raw);static void package_power_limit_irq_save (struct rapl_package *rp); -static int rapl_init_core (void ); -static void rapl_remove_core (void );static LIST_HEAD (rapl_packages);/* guarded by CPU hotplug lock */
@@ -1262,8 +1261,6 @@ void rapl_remove_package(struct rapl_package *rp)powercap_unregister_zone (rp->priv->control_type, &rd_package->power_zone);list_del (&rp->plist); -if (list_empty (&rapl_packages)) -rapl_remove_core ();kfree (rp); }EXPORT_SYMBOL_GPL (rapl_remove_package);
@@ -1292,10 +1289,6 @@ struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv)struct cpuinfo_x86 *c = &cpu_data (cpu);int ret; - ret =rapl_init_core (); -if (ret) -return ERR_PTR (ret); - rp =kzalloc (sizeof (struct rapl_package ),GFP_KERNEL );if (!rp)return ERR_PTR (-ENOMEM );
@@ -1413,14 +1406,13 @@ static struct notifier_block rapl_pm_notifier = { .notifier_call = rapl_pm_callback, }; -static int rapl_init_core (void ) +static struct platform_device *rapl_msr_platdev; + +static int __init rapl_init (void ) {const struct x86_cpu_id *id;int ret; -if (rapl_defaults) -return 0 ; - id =x86_match_cpu (rapl_ids);if (!id) { pr_err("driver does not support CPU family %d model %d\n",
@@ -1432,16 +1424,35 @@ static int rapl_init_core(void) rapl_defaults = (struct rapl_defaults *)id->driver_data; ret =register_pm_notifier (&rapl_pm_notifier); +if (ret) +return ret; -return 0 ; + rapl_msr_platdev =platform_device_alloc ("intel_rapl_msr" ,0 ); +if (!rapl_msr_platdev) { + ret = -ENOMEM ; + goto end; + } + + ret =platform_device_add (rapl_msr_platdev); +if (ret) +platform_device_put (rapl_msr_platdev); + +end: +if (ret) +unregister_pm_notifier (&rapl_pm_notifier); + +return ret; } -static void rapl_remove_core (void ) +static void __exit rapl_exit(void) { +platform_device_unregister (rapl_msr_platdev);unregister_pm_notifier (&rapl_pm_notifier); - rapl_defaults =NULL ; } +module_init (rapl_init); +module_exit (rapl_exit); +MODULE_DESCRIPTION ("Intel Runtime Average Power Limit (RAPL) common code" );MODULE_AUTHOR ("Jacob Pan <[email protected]>" );MODULE_LICENSE ("GPL v2" );
drivers/powercap/intel_rapl_msr.c +20 -4
@@ -20,6 +20,7 @@#include <linux/suspend.h> #include <linux/intel_rapl.h> #include <linux/processor.h> +#include <linux/platform_device.h> #include <asm/iosf_mbi.h> #include <asm/cpu_device_id.h>
@@ -122,7 +123,7 @@ static int rapl_msr_write_raw(int cpu, struct reg_action *ra)return ra->err; } -static int __init rapl_msr_init (void ) +static int rapl_msr_probe (struct platform_device *pdev) {int ret;
@@ -152,15 +153,30 @@ static int __init rapl_msr_init(void)return ret; } -static void __exit rapl_msr_exit(void) +static int rapl_msr_remove (struct platform_device *pdev) {cpuhp_remove_state (rapl_msr_priv.pcap_rapl_online);rapl_remove_platform_domain (&rapl_msr_priv);powercap_unregister_control_type (rapl_msr_priv.control_type); +return 0 ; } -module_init (rapl_msr_init); -module_exit (rapl_msr_exit); +static const struct platform_device_id rapl_msr_ids[] = { + { .name ="intel_rapl_msr" , }, + {} +}; +MODULE_DEVICE_TABLE (platform, rapl_msr_ids); + +static struct platform_driver intel_rapl_msr_driver = { + .probe = rapl_msr_probe, + .remove = rapl_msr_remove, + .id_table = rapl_msr_ids, + .driver = { + .name ="intel_rapl_msr" , + }, +}; + +module_platform_driver (intel_rapl_msr_driver);MODULE_DESCRIPTION ("Driver for Intel RAPL (Running Average Power Limit) control via MSR interface" );MODULE_AUTHOR ("Zhang Rui <[email protected]>" );
Signature · 1 line
2.7.4
Rafael J. Wysocki
maintainerQuoted 20 lines · Zhang Rui
Besideis MSR interface, RAPL can also be controlled via the MMIO interface, by accessing the MCHBar registers exposed by the processor thermal device.
Currently, we only have RAPL MSR interface in Linux kernel, this brings problems on some platforms that BIOS performs a low power limits via the MMIO interface by default. This results in poor system performance, and there is no way for us to change the MMIO MSR setting in Linux.
To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the shared code into a separate file,
intel_rapl_common.c, so that it can be used by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by the processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Quoted 7 lines
Note that this patch series are based on the -tip tree, which contains the latest RAPL changes for multi-die support.
Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of 5.2-rc7 for me.
Quoted 39 lines · Rafael J. Wysocki
Quoted 32 lines · Zhang Rui
Besideis MSR interface, RAPL can also be controlled via the MMIO interface,
by accessing the MCHBar registers exposed by the processor thermal device.Currently, we only have RAPL MSR interface in Linux kernel, this brings
problems on some platforms that BIOS performs a low power limits via the
MMIO interface by default. This results in poor system performance, and there is no way for us to change the MMIO MSR setting in Linux.To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the shared
code into a separate file,intel_rapl_common.c, so that it can be used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which contains the
latest RAPL changes for multi-die support.Quoted 5 lines
Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.
Quoted 4 lines
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of 5.2-rc7 for me.
This needs linux tip tree. There are some package/die changes in tip tree, which this patch depends on.
Thanks,
Srinivas
Rafael J. Wysocki
maintainerQuoted 41 lines · Srinivas
Quoted 39 lines · Rafael J. Wysocki
Quoted 37 lines · Zhang Rui
Besideis MSR interface, RAPL can also be controlled via the MMIO interface,
by accessing the MCHBar registers exposed by the processor thermal device.Currently, we only have RAPL MSR interface in Linux kernel, this brings
problems on some platforms that BIOS performs a low power limits via the
MMIO interface by default. This results in poor system performance, and there is no way for us to change the MMIO MSR setting in Linux.To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the shared
code into a separate file,intel_rapl_common.c, so that it can be used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which contains the
latest RAPL changes for multi-die support.Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.
Quoted 6 lines
Quoted 4 lines
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of 5.2-rc7 for me.
This needs linux tip tree. There are some package/die changes in tip tree, which this patch depends on.
OK, so the changes in -tip need to go in first.
Thanks!
Zhang Rui
reviewerQuoted 56 lines · Rafael J. Wysocki
Quoted 54 lines · Srinivas
Quoted 51 lines · Rafael J. Wysocki
Quoted 48 lines · Zhang Rui
Besideis MSR interface, RAPL can also be controlled via the MMIO
interface,
by accessing the MCHBar registers exposed by the processor thermal
device.Currently, we only have RAPL MSR interface in Linux kernel, this
brings
problems on some platforms that BIOS performs a low power limits
via the
MMIO interface by default. This results in poor system performance,
and there is no way for us to change the MMIO MSR setting in Linux.To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the
shared
code into a separate file,intel_rapl_common.c, so that it can be
used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by
the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which contains the
latest RAPL changes for multi-die support.Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of 5.2-rc7 for me.
This needs linux tip tree. There are some package/die changes in tip
tree, which this patch depends on.OK, so the changes in -tip need to go in first.
exactly.
BTW, this patch set also conflicts with the RAPL support patches for icelake platforms. Thus IMO, having a separate rapl branch, and apply the icl rapl patches on top of this patch set will be much easier.
thanks,
rui
Rafael J. Wysocki
maintainerQuoted 62 lines · Zhang Rui
Quoted 60 lines · Rafael J. Wysocki
Quoted 58 lines · Srinivas
Quoted 55 lines · Rafael J. Wysocki
Quoted 43 lines · Zhang Rui
Besideis MSR interface, RAPL can also be controlled via the MMIO
interface,
by accessing the MCHBar registers exposed by the processor thermal
device.Currently, we only have RAPL MSR interface in Linux kernel, this
brings
problems on some platforms that BIOS performs a low power limits
via the
MMIO interface by default. This results in poor system performance,
and there is no way for us to change the MMIO MSR setting in Linux.To fix this, RAPL MMIO interface support is introduced in this patch set.
Patch 1/13 to patch 11/13 abstract the RAPL code, and move all the
shared
code into a separate file,intel_rapl_common.c, so that it can be
used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed by
the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which contains the
latest RAPL changes for multi-die support.Quoted 5 lines
Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of 5.2-rc7 for me.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This needs linux tip tree. There are some package/die changes in tip
tree, which this patch depends on.OK, so the changes in -tip need to go in first.
exactly.
BTW, this patch set also conflicts with the RAPL support patches for icelake platforms.
Do you mean commits
cc3ae777098b..88679b2587a0
in linux-next?
Quoted 2 lines
Thus IMO, having a separate rapl branch, and apply
the icl rapl patches on top of this patch set will be much easier.
OK, I'll do that if that's preferred.
Zhang Rui
reviewerQuoted 87 lines · Rafael J. Wysocki
Quoted 80 lines · Zhang Rui
Quoted 77 lines · Rafael J. Wysocki
Quoted 74 lines · Srinivas
Quoted 61 lines · Rafael J. Wysocki
On Thu, Jul 4, 2019 at 6:34 PM Zhang Rui <[email protected]
Quoted 1 line
Quoted 50 lines · wrote:
Besideis MSR interface, RAPL can also be controlled via the MMIO
interface,
by accessing the MCHBar registers exposed by the processor thermal
device.Currently, we only have RAPL MSR interface in Linux kernel, this
brings
problems on some platforms that BIOS performs a low power limits
via the
MMIO interface by default. This results in poor system performance,
and there is no way for us to change the MMIO MSR setting in
Linux.To fix this, RAPL MMIO interface support is introduced in this
patch set.Patch 1/13 to patch 11/13 abstract the RAPL code, and move all
the
shared
code into a separate file,intel_rapl_common.c, so that it can
be
used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed
by
the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which
contains the
latest RAPL changes for multi-die support.Quoted 6 lines
Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead ofintel_rapl.c.
- changelog and coding style update.Quoted 5 lines
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of
5.2-rc7 for me.This needs linux tip tree. There are some package/die changes in
tip
tree, which this patch depends on.Quoted 6 lines
Quoted 2 lines
OK, so the changes in -tip need to go in first.
exactly.
BTW, this patch set also conflicts with the RAPL support patches for
icelake platforms.
Quoted 6 lines
Do you mean commits
cc3ae777098b..88679b2587a0in linux-next?
yes.
Quoted 4 lines
Quoted 3 lines
Thus IMO, having a separate rapl branch, and apply
the icl rapl patches on top of this patch set will be much easier.OK, I'll do that if that's preferred.
thanks. I think you can apply the ICL RAPL patches by replacing intel_rapl.c with intel_rapl_common.c in the patch files. Or I can resend the ICL RAPL patches rebased on the this patch series.
thanks,
rui
Rafael J. Wysocki
maintainerQuoted 97 lines · Zhang Rui
Quoted 87 lines · Rafael J. Wysocki
Quoted 80 lines · Zhang Rui
Quoted 77 lines · Rafael J. Wysocki
Quoted 74 lines · Srinivas
Quoted 61 lines · Rafael J. Wysocki
On Thu, Jul 4, 2019 at 6:34 PM Zhang Rui <[email protected]
Quoted 1 line
Quoted 50 lines · wrote:
Besideis MSR interface, RAPL can also be controlled via the MMIO
interface,
by accessing the MCHBar registers exposed by the processor thermal
device.Currently, we only have RAPL MSR interface in Linux kernel, this
brings
problems on some platforms that BIOS performs a low power limits
via the
MMIO interface by default. This results in poor system performance,
and there is no way for us to change the MMIO MSR setting in
Linux.To fix this, RAPL MMIO interface support is introduced in this
patch set.Patch 1/13 to patch 11/13 abstract the RAPL code, and move all
the
shared
code into a separate file,intel_rapl_common.c, so that it can
be
used
by both MSR and MMIO interfaces.
Patch 12/13 introduced RAPL support via MMIO registers, exposed
by
the
processor thermal devices.
Patch 13/13 fixes a module autoloading issue found later.The patch series has been tested on Dell XPS 9360, a SKL platform.
Note that this patch series are based on the -tip tree, which
contains the
latest RAPL changes for multi-die support.Quoted 6 lines
Changes in V2:
- add kerneldoc for structrapl_if_priv.
- useintel_rapl_msr.cfor RAPL MSR I/F driver, instead
ofintel_rapl.c.
- changelog and coding style update.Quoted 5 lines
What tree is the series against?
It doesn't apply either on top of my powercap branch or on top of
5.2-rc7 for me.This needs linux tip tree. There are some package/die changes in
tip
tree, which this patch depends on.Quoted 6 lines
Quoted 2 lines
OK, so the changes in -tip need to go in first.
exactly.
BTW, this patch set also conflicts with the RAPL support patches for
icelake platforms.Quoted 6 lines
Do you mean commits
cc3ae777098b..88679b2587a0in linux-next?
yes.
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Thus IMO, having a separate rapl branch, and apply
the icl rapl patches on top of this patch set will be much easier.OK, I'll do that if that's preferred.
thanks. I think you can apply the ICL RAPL patches by replacing
intel_rapl.cwithintel_rapl_common.cin the patch files. Or I can resend the ICL RAPL patches rebased on the this patch series.
It would help if you did that, thanks!