Skip to content

Commit 74f41ad

Browse files
zhang-ruiIngo Molnar
authored andcommitted
perf/x86/rapl: Support multiple RAPL unit quirks
There will be more platforms with different fixed energy units. Enhance the code to support different RAPL unit quirks for different platforms. Signed-off-by: Zhang Rui <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Kan Liang <[email protected]> Reviewed-by: Len Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4bb5fcb commit 74f41ad

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

arch/x86/events/rapl.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ struct rapl_pmus {
130130
struct rapl_pmu *pmus[];
131131
};
132132

133+
enum rapl_unit_quirk {
134+
RAPL_UNIT_QUIRK_NONE,
135+
RAPL_UNIT_QUIRK_INTEL_HSW,
136+
};
137+
133138
struct rapl_model {
134139
struct perf_msr *rapl_msrs;
135140
unsigned long events;
136141
unsigned int msr_power_unit;
137-
bool apply_quirk;
142+
enum rapl_unit_quirk unit_quirk;
138143
};
139144

140145
/* 1/2^hw_unit Joule */
@@ -612,14 +617,20 @@ static int rapl_check_hw_unit(struct rapl_model *rm)
612617
for (i = 0; i < NR_RAPL_DOMAINS; i++)
613618
rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL;
614619

620+
switch (rm->unit_quirk) {
615621
/*
616622
* DRAM domain on HSW server and KNL has fixed energy unit which can be
617623
* different than the unit from power unit MSR. See
618624
* "Intel Xeon Processor E5-1600 and E5-2600 v3 Product Families, V2
619625
* of 2. Datasheet, September 2014, Reference Number: 330784-001 "
620626
*/
621-
if (rm->apply_quirk)
627+
case RAPL_UNIT_QUIRK_INTEL_HSW:
622628
rapl_hw_unit[PERF_RAPL_RAM] = 16;
629+
break;
630+
default:
631+
break;
632+
}
633+
623634

624635
/*
625636
* Calculate the timer rate:
@@ -698,7 +709,6 @@ static struct rapl_model model_snb = {
698709
.events = BIT(PERF_RAPL_PP0) |
699710
BIT(PERF_RAPL_PKG) |
700711
BIT(PERF_RAPL_PP1),
701-
.apply_quirk = false,
702712
.msr_power_unit = MSR_RAPL_POWER_UNIT,
703713
.rapl_msrs = intel_rapl_msrs,
704714
};
@@ -707,7 +717,6 @@ static struct rapl_model model_snbep = {
707717
.events = BIT(PERF_RAPL_PP0) |
708718
BIT(PERF_RAPL_PKG) |
709719
BIT(PERF_RAPL_RAM),
710-
.apply_quirk = false,
711720
.msr_power_unit = MSR_RAPL_POWER_UNIT,
712721
.rapl_msrs = intel_rapl_msrs,
713722
};
@@ -717,7 +726,6 @@ static struct rapl_model model_hsw = {
717726
BIT(PERF_RAPL_PKG) |
718727
BIT(PERF_RAPL_RAM) |
719728
BIT(PERF_RAPL_PP1),
720-
.apply_quirk = false,
721729
.msr_power_unit = MSR_RAPL_POWER_UNIT,
722730
.rapl_msrs = intel_rapl_msrs,
723731
};
@@ -726,15 +734,15 @@ static struct rapl_model model_hsx = {
726734
.events = BIT(PERF_RAPL_PP0) |
727735
BIT(PERF_RAPL_PKG) |
728736
BIT(PERF_RAPL_RAM),
729-
.apply_quirk = true,
737+
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW,
730738
.msr_power_unit = MSR_RAPL_POWER_UNIT,
731739
.rapl_msrs = intel_rapl_msrs,
732740
};
733741

734742
static struct rapl_model model_knl = {
735743
.events = BIT(PERF_RAPL_PKG) |
736744
BIT(PERF_RAPL_RAM),
737-
.apply_quirk = true,
745+
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW,
738746
.msr_power_unit = MSR_RAPL_POWER_UNIT,
739747
.rapl_msrs = intel_rapl_msrs,
740748
};
@@ -745,14 +753,12 @@ static struct rapl_model model_skl = {
745753
BIT(PERF_RAPL_RAM) |
746754
BIT(PERF_RAPL_PP1) |
747755
BIT(PERF_RAPL_PSYS),
748-
.apply_quirk = false,
749756
.msr_power_unit = MSR_RAPL_POWER_UNIT,
750757
.rapl_msrs = intel_rapl_msrs,
751758
};
752759

753760
static struct rapl_model model_amd_fam17h = {
754761
.events = BIT(PERF_RAPL_PKG),
755-
.apply_quirk = false,
756762
.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
757763
.rapl_msrs = amd_rapl_msrs,
758764
};

0 commit comments

Comments
 (0)