Skip to content

Commit 98ff639

Browse files
zhang-ruirafaeljw
authored andcommitted
powercap: intel_rapl: Support per Interface primitive information
RAPL primitive information is Interface specific. Although current MSR and MMIO Interface share the same RAPL primitives, new Interface like TPMI has its own RAPL primitive information. Save the primitive information in the Interface private structure. Plus, using variant name "rp" for struct rapl_primitive_info is confusing because "rp" is also used for struct rapl_package. Use "rpi" as the variant name for struct rapl_primitive_info, and rename the previous rpi[] array to avoid conflict. 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 e8e28c2 commit 98ff639

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
654654
}
655655

656656
/* in the order of enum rapl_primitives */
657-
static struct rapl_primitive_info rpi[] = {
657+
static struct rapl_primitive_info rpi_default[] = {
658658
/* name, mask, shift, msr index, unit divisor */
659659
PRIMITIVE_INFO_INIT(ENERGY_COUNTER, ENERGY_STATUS_MASK, 0,
660660
RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
@@ -710,9 +710,20 @@ static struct rapl_primitive_info rpi[] = {
710710
{NULL, 0, 0, 0},
711711
};
712712

713+
static struct rapl_primitive_info *get_rpi(struct rapl_package *rp, int prim)
714+
{
715+
struct rapl_primitive_info *rpi = rp->priv->rpi;
716+
717+
if (prim < 0 || prim > NR_RAPL_PRIMITIVES || !rpi)
718+
return NULL;
719+
720+
return &rpi[prim];
721+
}
722+
713723
static int rapl_config(struct rapl_package *rp)
714724
{
715725
rp->priv->defaults = (void *)rapl_defaults;
726+
rp->priv->rpi = (void *)rpi_default;
716727
return 0;
717728
}
718729

@@ -763,41 +774,41 @@ static int rapl_read_data_raw(struct rapl_domain *rd,
763774
{
764775
u64 value;
765776
enum rapl_primitives prim_fixed = prim_fixups(rd, prim);
766-
struct rapl_primitive_info *rp = &rpi[prim_fixed];
777+
struct rapl_primitive_info *rpi = get_rpi(rd->rp, prim_fixed);
767778
struct reg_action ra;
768779
int cpu;
769780

770-
if (!rp->name || rp->flag & RAPL_PRIMITIVE_DUMMY)
781+
if (!rpi || !rpi->name || rpi->flag & RAPL_PRIMITIVE_DUMMY)
771782
return -EINVAL;
772783

773-
ra.reg = rd->regs[rp->id];
784+
ra.reg = rd->regs[rpi->id];
774785
if (!ra.reg)
775786
return -EINVAL;
776787

777788
cpu = rd->rp->lead_cpu;
778789

779790
/* domain with 2 limits has different bit */
780791
if (prim == FW_LOCK && rd->rp->priv->limits[rd->id] == 2) {
781-
rp->mask = POWER_HIGH_LOCK;
782-
rp->shift = 63;
792+
rpi->mask = POWER_HIGH_LOCK;
793+
rpi->shift = 63;
783794
}
784795
/* non-hardware data are collected by the polling thread */
785-
if (rp->flag & RAPL_PRIMITIVE_DERIVED) {
796+
if (rpi->flag & RAPL_PRIMITIVE_DERIVED) {
786797
*data = rd->rdd.primitives[prim];
787798
return 0;
788799
}
789800

790-
ra.mask = rp->mask;
801+
ra.mask = rpi->mask;
791802

792803
if (rd->rp->priv->read_raw(cpu, &ra)) {
793804
pr_debug("failed to read reg 0x%llx on cpu %d\n", ra.reg, cpu);
794805
return -EIO;
795806
}
796807

797-
value = ra.value >> rp->shift;
808+
value = ra.value >> rpi->shift;
798809

799810
if (xlate)
800-
*data = rapl_unit_xlate(rd, rp->unit, value, 0);
811+
*data = rapl_unit_xlate(rd, rpi->unit, value, 0);
801812
else
802813
*data = value;
803814

@@ -810,21 +821,24 @@ static int rapl_write_data_raw(struct rapl_domain *rd,
810821
unsigned long long value)
811822
{
812823
enum rapl_primitives prim_fixed = prim_fixups(rd, prim);
813-
struct rapl_primitive_info *rp = &rpi[prim_fixed];
824+
struct rapl_primitive_info *rpi = get_rpi(rd->rp, prim_fixed);
814825
int cpu;
815826
u64 bits;
816827
struct reg_action ra;
817828
int ret;
818829

830+
if (!rpi || !rpi->name || rpi->flag & RAPL_PRIMITIVE_DUMMY)
831+
return -EINVAL;
832+
819833
cpu = rd->rp->lead_cpu;
820-
bits = rapl_unit_xlate(rd, rp->unit, value, 1);
821-
bits <<= rp->shift;
822-
bits &= rp->mask;
834+
bits = rapl_unit_xlate(rd, rpi->unit, value, 1);
835+
bits <<= rpi->shift;
836+
bits &= rpi->mask;
823837

824838
memset(&ra, 0, sizeof(ra));
825839

826-
ra.reg = rd->regs[rp->id];
827-
ra.mask = rp->mask;
840+
ra.reg = rd->regs[rpi->id];
841+
ra.mask = rpi->mask;
828842
ra.value = bits;
829843

830844
ret = rd->rp->priv->write_raw(cpu, &ra);
@@ -1176,8 +1190,10 @@ static void rapl_update_domain_data(struct rapl_package *rp)
11761190
rp->domains[dmn].name);
11771191
/* exclude non-raw primitives */
11781192
for (prim = 0; prim < NR_RAW_PRIMITIVES; prim++) {
1193+
struct rapl_primitive_info *rpi = get_rpi(rp, prim);
1194+
11791195
if (!rapl_read_data_raw(&rp->domains[dmn], prim,
1180-
rpi[prim].unit, &val))
1196+
rpi->unit, &val))
11811197
rp->domains[dmn].rdd.primitives[prim] = val;
11821198
}
11831199
}

include/linux/intel_rapl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct reg_action {
122122
* @write_raw: Callback for writing RAPL interface specific
123123
* registers.
124124
* @defaults: internal pointer to interface default settings
125+
* @rpi: internal pointer to interface primitive info
125126
*/
126127
struct rapl_if_priv {
127128
struct powercap_control_type *control_type;
@@ -132,6 +133,7 @@ struct rapl_if_priv {
132133
int (*read_raw)(int cpu, struct reg_action *ra);
133134
int (*write_raw)(int cpu, struct reg_action *ra);
134135
void *defaults;
136+
void *rpi;
135137
};
136138

137139
/* maximum rapl package domain name: package-%d-die-%d */

0 commit comments

Comments
 (0)