Skip to content

Commit a38f300

Browse files
zhang-ruirafaeljw
authored andcommitted
powercap: intel_rapl: Use bitmap for Power Limits
Currently, a RAPL package is registered with the number of Power Limits supported in each RAPL domain. But this doesn't tell which Power Limits are available. Using the number of Power Limits supported to guess the availability of each Power Limit is fragile. Use bitmap to represent the availability of each Power Limit. Note that PL1 is mandatory thus it does not need to be set explicitly by the RAPL Interface drivers. No functional change intended. Signed-off-by: Zhang Rui <[email protected]> Tested-by: Wang Wendy <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 045610c commit a38f300

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,20 +574,18 @@ static void rapl_init_domains(struct rapl_package *rp)
574574
rapl_domain_names[i]);
575575

576576
rd->id = i;
577+
578+
/* PL1 is supported by default */
579+
rp->priv->limits[i] |= BIT(POWER_LIMIT1);
577580
rd->rpl[0].prim_id = PL1_ENABLE;
578581
rd->rpl[0].name = pl1_name;
579582

580-
/*
581-
* The PL2 power domain is applicable for limits two
582-
* and limits three
583-
*/
584-
if (rp->priv->limits[i] >= 2) {
583+
if (rp->priv->limits[i] & BIT(POWER_LIMIT2)) {
585584
rd->rpl[1].prim_id = PL2_ENABLE;
586585
rd->rpl[1].name = pl2_name;
587586
}
588587

589-
/* Enable PL4 domain if the total power limits are three */
590-
if (rp->priv->limits[i] == 3) {
588+
if (rp->priv->limits[i] & BIT(POWER_LIMIT4)) {
591589
rd->rpl[2].prim_id = PL4_ENABLE;
592590
rd->rpl[2].name = pl4_name;
593591
}
@@ -762,7 +760,7 @@ static int rapl_read_data_raw(struct rapl_domain *rd,
762760
cpu = rd->rp->lead_cpu;
763761

764762
/* domain with 2 limits has different bit */
765-
if (prim == FW_LOCK && rd->rp->priv->limits[rd->id] == 2) {
763+
if (prim == FW_LOCK && (rd->rp->priv->limits[rd->id] & BIT(POWER_LIMIT2))) {
766764
rpi->mask = POWER_HIGH_LOCK;
767765
rpi->shift = 63;
768766
}

drivers/powercap/intel_rapl_msr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static struct rapl_if_priv rapl_msr_priv_intel = {
4545
MSR_DRAM_POWER_LIMIT, MSR_DRAM_ENERGY_STATUS, MSR_DRAM_PERF_STATUS, 0, MSR_DRAM_POWER_INFO },
4646
.regs[RAPL_DOMAIN_PLATFORM] = {
4747
MSR_PLATFORM_POWER_LIMIT, MSR_PLATFORM_ENERGY_STATUS, 0, 0, 0},
48-
.limits[RAPL_DOMAIN_PACKAGE] = 2,
49-
.limits[RAPL_DOMAIN_PLATFORM] = 2,
48+
.limits[RAPL_DOMAIN_PACKAGE] = BIT(POWER_LIMIT2),
49+
.limits[RAPL_DOMAIN_PLATFORM] = BIT(POWER_LIMIT2),
5050
};
5151

5252
static struct rapl_if_priv rapl_msr_priv_amd = {
@@ -169,7 +169,7 @@ static int rapl_msr_probe(struct platform_device *pdev)
169169
rapl_msr_priv->write_raw = rapl_msr_write_raw;
170170

171171
if (id) {
172-
rapl_msr_priv->limits[RAPL_DOMAIN_PACKAGE] = 3;
172+
rapl_msr_priv->limits[RAPL_DOMAIN_PACKAGE] |= BIT(POWER_LIMIT4);
173173
rapl_msr_priv->regs[RAPL_DOMAIN_PACKAGE][RAPL_DOMAIN_REG_PL4] =
174174
MSR_VR_CURRENT_CONFIG;
175175
pr_info("PL4 support detected.\n");

drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ static const struct rapl_mmio_regs rapl_mmio_default = {
1515
.reg_unit = 0x5938,
1616
.regs[RAPL_DOMAIN_PACKAGE] = { 0x59a0, 0x593c, 0x58f0, 0, 0x5930},
1717
.regs[RAPL_DOMAIN_DRAM] = { 0x58e0, 0x58e8, 0x58ec, 0, 0},
18-
.limits[RAPL_DOMAIN_PACKAGE] = 2,
19-
.limits[RAPL_DOMAIN_DRAM] = 2,
18+
.limits[RAPL_DOMAIN_PACKAGE] = BIT(POWER_LIMIT2),
19+
.limits[RAPL_DOMAIN_DRAM] = BIT(POWER_LIMIT2),
2020
};
2121

2222
static int rapl_mmio_cpu_online(unsigned int cpu)

0 commit comments

Comments
 (0)