Skip to content

Commit c5b15dd

Browse files
rmurphy-armwilldeacon
authored andcommitted
perf/arm-cmn: Make cycle counts less surprising
By default, CMN has automatic clock-gating with the implication that a DTC's cycle counter may not increment while the DTC is sufficiently idle. Given that we may have up to 4 DTCs to choose from when scheduling a cycles event, this may potentially lead to surprising results if trying to measure metrics based on activity in a different DTC domain from where cycles end up being counted. Furthermore, since the details of internal clock gating are not documented, we can't even reason about what "active" cycles for a DTC actually mean relative to the activity of other nodes within the same nominal DTC domain. Make the reasonable assumption that if the user wants to count cycles, they almost certainly want to count all of the cycles, and disable clock gating while a DTC's cycle counter is in use. Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/c47cfdc09e907b1d7753d142a7e659982cceb246.1725296395.git.robin.murphy@arm.com Signed-off-by: Will Deacon <[email protected]>
1 parent ff436ce commit c5b15dd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/perf/arm-cmn.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
/* The DTC node is where the magic happens */
120120
#define CMN_DT_DTC_CTL 0x0a00
121121
#define CMN_DT_DTC_CTL_DT_EN BIT(0)
122+
#define CMN_DT_DTC_CTL_CG_DISABLE BIT(10)
122123

123124
/* DTC counters are paired in 64-bit registers on a 16-byte stride. Yuck */
124125
#define _CMN_DT_CNT_REG(n) ((((n) / 2) * 4 + (n) % 2) * 4)
@@ -1546,9 +1547,12 @@ static void arm_cmn_event_start(struct perf_event *event, int flags)
15461547
int i;
15471548

15481549
if (type == CMN_TYPE_DTC) {
1549-
i = hw->dtc_idx[0];
1550-
writeq_relaxed(CMN_CC_INIT, cmn->dtc[i].base + CMN_DT_PMCCNTR);
1551-
cmn->dtc[i].cc_active = true;
1550+
struct arm_cmn_dtc *dtc = cmn->dtc + hw->dtc_idx[0];
1551+
1552+
writel_relaxed(CMN_DT_DTC_CTL_DT_EN | CMN_DT_DTC_CTL_CG_DISABLE,
1553+
dtc->base + CMN_DT_DTC_CTL);
1554+
writeq_relaxed(CMN_CC_INIT, dtc->base + CMN_DT_PMCCNTR);
1555+
dtc->cc_active = true;
15521556
} else if (type == CMN_TYPE_WP) {
15531557
u64 val = CMN_EVENT_WP_VAL(event);
15541558
u64 mask = CMN_EVENT_WP_MASK(event);
@@ -1577,8 +1581,10 @@ static void arm_cmn_event_stop(struct perf_event *event, int flags)
15771581
int i;
15781582

15791583
if (type == CMN_TYPE_DTC) {
1580-
i = hw->dtc_idx[0];
1581-
cmn->dtc[i].cc_active = false;
1584+
struct arm_cmn_dtc *dtc = cmn->dtc + hw->dtc_idx[0];
1585+
1586+
dtc->cc_active = false;
1587+
writel_relaxed(CMN_DT_DTC_CTL_DT_EN, dtc->base + CMN_DT_DTC_CTL);
15821588
} else if (type == CMN_TYPE_WP) {
15831589
for_each_hw_dn(hw, dn, i) {
15841590
void __iomem *base = dn->pmu_base + CMN_DTM_OFFSET(hw->dtm_offset);

0 commit comments

Comments
 (0)