Skip to content

Commit b4288ce

Browse files
zhang-ruirafaeljw
authored andcommitted
powercap: intel_rapl: Introduce RAPL I/F type
Different RAPL Interfaces may have different primitive information and rapl_defaults calls. To better distinguish this difference in the RAPL framework code, introduce a new enum to represent different types of RAPL Interfaces. No functional change. Signed-off-by: Zhang Rui <[email protected]> Tested-by: Wang Wendy <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent bf44b90 commit b4288ce

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct rapl_defaults {
186186
unsigned int psys_domain_energy_unit;
187187
bool spr_psys_bits;
188188
};
189-
static struct rapl_defaults *rapl_defaults;
189+
static struct rapl_defaults *defaults_msr;
190190

191191
static struct rapl_defaults *get_defaults(struct rapl_package *rp)
192192
{
@@ -610,7 +610,7 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
610610
return div64_u64(value, scale);
611611
}
612612

613-
static struct rapl_primitive_info rpi_default[NR_RAPL_PRIMITIVES] = {
613+
static struct rapl_primitive_info rpi_msr[NR_RAPL_PRIMITIVES] = {
614614
/* name, mask, shift, msr index, unit divisor */
615615
[POWER_LIMIT1] = PRIMITIVE_INFO_INIT(POWER_LIMIT1, POWER_LIMIT1_MASK, 0,
616616
RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
@@ -679,8 +679,16 @@ static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
679679

680680
static int rapl_config(struct rapl_package *rp)
681681
{
682-
rp->priv->defaults = (void *)rapl_defaults;
683-
rp->priv->rpi = (void *)rpi_default;
682+
switch (rp->priv->type) {
683+
/* MMIO I/F shares the same register layout as MSR registers */
684+
case RAPL_IF_MMIO:
685+
case RAPL_IF_MSR:
686+
rp->priv->defaults = (void *)defaults_msr;
687+
rp->priv->rpi = (void *)rpi_msr;
688+
break;
689+
default:
690+
return -EINVAL;
691+
}
684692
return 0;
685693
}
686694

@@ -1546,7 +1554,7 @@ static int __init rapl_init(void)
15461554

15471555
id = x86_match_cpu(rapl_ids);
15481556
if (id) {
1549-
rapl_defaults = (struct rapl_defaults *)id->driver_data;
1557+
defaults_msr = (struct rapl_defaults *)id->driver_data;
15501558

15511559
rapl_msr_platdev = platform_device_alloc("intel_rapl_msr", 0);
15521560
if (!rapl_msr_platdev)

drivers/powercap/intel_rapl_msr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
static struct rapl_if_priv *rapl_msr_priv;
3535

3636
static struct rapl_if_priv rapl_msr_priv_intel = {
37+
.type = RAPL_IF_MSR,
3738
.reg_unit = MSR_RAPL_POWER_UNIT,
3839
.regs[RAPL_DOMAIN_PACKAGE] = {
3940
MSR_PKG_POWER_LIMIT, MSR_PKG_ENERGY_STATUS, MSR_PKG_PERF_STATUS, 0, MSR_PKG_POWER_INFO },
@@ -50,6 +51,7 @@ static struct rapl_if_priv rapl_msr_priv_intel = {
5051
};
5152

5253
static struct rapl_if_priv rapl_msr_priv_amd = {
54+
.type = RAPL_IF_MSR,
5355
.reg_unit = MSR_AMD_RAPL_POWER_UNIT,
5456
.regs[RAPL_DOMAIN_PACKAGE] = {
5557
0, MSR_AMD_PKG_ENERGY_STATUS, 0, 0, 0 },

drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int proc_thermal_rapl_add(struct pci_dev *pdev, struct proc_thermal_device *proc
9797
rapl_regs->regs[domain][reg];
9898
rapl_mmio_priv.limits[domain] = rapl_regs->limits[domain];
9999
}
100+
rapl_mmio_priv.type = RAPL_IF_MMIO;
100101
rapl_mmio_priv.reg_unit = (u64)proc_priv->mmio_base + rapl_regs->reg_unit;
101102

102103
rapl_mmio_priv.read_raw = rapl_mmio_read_raw;

include/linux/intel_rapl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include <linux/powercap.h>
1515
#include <linux/cpuhotplug.h>
1616

17+
enum rapl_if_type {
18+
RAPL_IF_MSR, /* RAPL I/F using MSR registers */
19+
RAPL_IF_MMIO, /* RAPL I/F using MMIO registers */
20+
};
21+
1722
enum rapl_domain_type {
1823
RAPL_DOMAIN_PACKAGE, /* entire package/socket */
1924
RAPL_DOMAIN_PP0, /* core power plane */
@@ -130,6 +135,7 @@ struct reg_action {
130135
* @rpi: internal pointer to interface primitive info
131136
*/
132137
struct rapl_if_priv {
138+
enum rapl_if_type type;
133139
struct powercap_control_type *control_type;
134140
enum cpuhp_state pcap_rapl_online;
135141
u64 reg_unit;

0 commit comments

Comments
 (0)