Skip to content

Commit

Permalink
powercap: intel_rapl: Introduce RAPL I/F type
Browse files Browse the repository at this point in the history
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 <rui.zhang@intel.com>
Tested-by: Wang Wendy <wendy.wang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Zhang Rui authored and Rafael J. Wysocki committed May 24, 2023
1 parent bf44b90 commit b4288ce
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
18 changes: 13 additions & 5 deletions drivers/powercap/intel_rapl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct rapl_defaults {
unsigned int psys_domain_energy_unit;
bool spr_psys_bits;
};
static struct rapl_defaults *rapl_defaults;
static struct rapl_defaults *defaults_msr;

static struct rapl_defaults *get_defaults(struct rapl_package *rp)
{
Expand Down Expand Up @@ -610,7 +610,7 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
return div64_u64(value, scale);
}

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

static int rapl_config(struct rapl_package *rp)
{
rp->priv->defaults = (void *)rapl_defaults;
rp->priv->rpi = (void *)rpi_default;
switch (rp->priv->type) {
/* MMIO I/F shares the same register layout as MSR registers */
case RAPL_IF_MMIO:
case RAPL_IF_MSR:
rp->priv->defaults = (void *)defaults_msr;
rp->priv->rpi = (void *)rpi_msr;
break;
default:
return -EINVAL;
}
return 0;
}

Expand Down Expand Up @@ -1546,7 +1554,7 @@ static int __init rapl_init(void)

id = x86_match_cpu(rapl_ids);
if (id) {
rapl_defaults = (struct rapl_defaults *)id->driver_data;
defaults_msr = (struct rapl_defaults *)id->driver_data;

rapl_msr_platdev = platform_device_alloc("intel_rapl_msr", 0);
if (!rapl_msr_platdev)
Expand Down
2 changes: 2 additions & 0 deletions drivers/powercap/intel_rapl_msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
static struct rapl_if_priv *rapl_msr_priv;

static struct rapl_if_priv rapl_msr_priv_intel = {
.type = RAPL_IF_MSR,
.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 },
Expand All @@ -50,6 +51,7 @@ static struct rapl_if_priv rapl_msr_priv_intel = {
};

static struct rapl_if_priv rapl_msr_priv_amd = {
.type = RAPL_IF_MSR,
.reg_unit = MSR_AMD_RAPL_POWER_UNIT,
.regs[RAPL_DOMAIN_PACKAGE] = {
0, MSR_AMD_PKG_ENERGY_STATUS, 0, 0, 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int proc_thermal_rapl_add(struct pci_dev *pdev, struct proc_thermal_device *proc
rapl_regs->regs[domain][reg];
rapl_mmio_priv.limits[domain] = rapl_regs->limits[domain];
}
rapl_mmio_priv.type = RAPL_IF_MMIO;
rapl_mmio_priv.reg_unit = (u64)proc_priv->mmio_base + rapl_regs->reg_unit;

rapl_mmio_priv.read_raw = rapl_mmio_read_raw;
Expand Down
6 changes: 6 additions & 0 deletions include/linux/intel_rapl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <linux/powercap.h>
#include <linux/cpuhotplug.h>

enum rapl_if_type {
RAPL_IF_MSR, /* RAPL I/F using MSR registers */
RAPL_IF_MMIO, /* RAPL I/F using MMIO registers */
};

enum rapl_domain_type {
RAPL_DOMAIN_PACKAGE, /* entire package/socket */
RAPL_DOMAIN_PP0, /* core power plane */
Expand Down Expand Up @@ -130,6 +135,7 @@ struct reg_action {
* @rpi: internal pointer to interface primitive info
*/
struct rapl_if_priv {
enum rapl_if_type type;
struct powercap_control_type *control_type;
enum cpuhp_state pcap_rapl_online;
u64 reg_unit;
Expand Down

0 comments on commit b4288ce

Please sign in to comment.