[PATCH 7/7] parisc: perf: add PA-8800/PA-8900 memory and branch events

From: Matt Turner

Date: Fri Nov 27 2026 - 00:03:37 EST


RDR0_0 bits 0-4 select what ctr2 counts: instructions, loads and stores,
or loads and stores that miss the D-cache. The loads and stores count
leaves out most of the accesses that miss: a loop of loads or stores
that all miss counts about 0.2 of them. Bit 13 narrows the D-cache miss
count to stores. It narrows the loads and stores count too, but that
count leaves out the stores that miss, so plain stores are counted on
ctr0 instead, where RDR0_0 bit 11 makes the instruction count count
stores.

The PCX-W branch images carry over to ctr2: their match filter, opcodes
0x20-0x3f with RDR4_0 bit 247 clear and bits 266, 268 and 271-276 set,
counts branches, and their RDR4_0 qualifier bytes count taken branches.

Add the events mem-accesses, dcache-misses, stores, store-dcache-misses,
branches and taken-branches, and map the generic branch-instructions
event.

Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
---
arch/parisc/kernel/perf_event_mako.c | 55 +++++++++++++++++++++++++---
arch/parisc/kernel/perf_mako.c | 71 ++++++++++++++++++++++++++++++++----
arch/parisc/kernel/perf_mako.h | 14 ++++++-
3 files changed, 126 insertions(+), 14 deletions(-)

diff --git a/arch/parisc/kernel/perf_event_mako.c b/arch/parisc/kernel/perf_event_mako.c
index 50171267f98b..5898d1c032cd 100644
--- a/arch/parisc/kernel/perf_event_mako.c
+++ b/arch/parisc/kernel/perf_event_mako.c
@@ -5,12 +5,17 @@
* Each core has four 31-bit counters, which count fixed events chosen by
* an event set (see perf_mako.c):
*
- * ctr0: TLB misses, instruction and data, or only one kind, or
- * instructions retired and not nullified
+ * ctr0: TLB misses, instruction and data, or only one kind,
+ * instructions retired and not nullified, or stores
* ctr1, ctr3: cycles, stall cycles, non-stall cycles or, on the first
* core of a processor, cycles handling TLB misses
- * ctr2: instructions retired, optionally filtered by instruction, or
- * instructions retired in non-stall cycles
+ * ctr2: instructions retired, optionally filtered by instruction,
+ * instructions retired in non-stall cycles, loads and stores,
+ * D-cache misses, store D-cache misses, branches or taken branches
+ *
+ * ctr2's loads and stores count leaves out most of the accesses that miss
+ * the D-cache: a loop of loads or stores that all miss counts about 0.2
+ * of them.
*
* The counters do not interrupt, so only counting is supported, and they
* count in all privilege levels. A counter wraps from 0x7fffffff to 0 and
@@ -56,6 +61,12 @@ enum {
MAKO_EV_ITLB_MISSES,
MAKO_EV_NONNULLIFIED_INSTRUCTIONS,
MAKO_EV_TLB_HANDLER_CYCLES,
+ MAKO_EV_MEM_ACCESSES,
+ MAKO_EV_DCACHE_MISSES,
+ MAKO_EV_STORES,
+ MAKO_EV_STORE_DCACHE_MISSES,
+ MAKO_EV_BRANCHES,
+ MAKO_EV_TAKEN_BRANCHES,
MAKO_EV_MAX,
};

@@ -76,6 +87,21 @@ static const struct {
[MAKO_EV_ITLB_MISSES] = { BIT(0), MAKO_EVENTS_DEFAULT },
[MAKO_EV_NONNULLIFIED_INSTRUCTIONS] = { BIT(0), MAKO_EVENTS_DEFAULT },
[MAKO_EV_TLB_HANDLER_CYCLES] = { BIT(1) | BIT(3), MAKO_EVENTS_TLB_HANDLER },
+ [MAKO_EV_MEM_ACCESSES] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_DCACHE_MISSES] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_STORES] = { BIT(0), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_STORE_DCACHE_MISSES] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_BRANCHES] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_TAKEN_BRANCHES] = { BIT(2), MAKO_EVENTS_DEFAULT },
+};
+
+/* What ctr2 counts for each event that ctr2 can count. */
+static const u8 mako_ctr2[MAKO_EV_MAX] = {
+ [MAKO_EV_MEM_ACCESSES] = MAKO_CTR2_MEMOPS,
+ [MAKO_EV_DCACHE_MISSES] = MAKO_CTR2_DMISSES,
+ [MAKO_EV_STORE_DCACHE_MISSES] = MAKO_CTR2_STORE_DMISSES,
+ [MAKO_EV_BRANCHES] = MAKO_CTR2_BRANCHES,
+ [MAKO_EV_TAKEN_BRANCHES] = MAKO_CTR2_TAKEN,
};

#define MAKO_CONFIG_EVENT GENMASK_ULL(7, 0)
@@ -141,7 +167,12 @@ static bool mako_schedule(struct perf_event **events, int n, int *idx,
idx[i] = __ffs(free);
used |= BIT(idx[i]);

- if (code == MAKO_EV_DTLB_MISSES)
+ if (mako_ctr2[code])
+ cfg->ctr2 = mako_ctr2[code];
+
+ if (code == MAKO_EV_STORES)
+ cfg->ctr0 = MAKO_CTR0_STORES;
+ else if (code == MAKO_EV_DTLB_MISSES)
cfg->ctr0 = MAKO_CTR0_DTLB;
else if (code == MAKO_EV_ITLB_MISSES)
cfg->ctr0 = MAKO_CTR0_ITLB;
@@ -382,6 +413,8 @@ static int mako_map_hw(u64 config)
return MAKO_EV_CYCLES;
case PERF_COUNT_HW_INSTRUCTIONS:
return MAKO_EV_INSTRUCTIONS;
+ case PERF_COUNT_HW_BRANCH_INSTRUCTIONS:
+ return MAKO_EV_BRANCHES;
default:
return -ENOENT;
}
@@ -479,6 +512,12 @@ MAKO_EVENT_ATTR(dtlb-misses, 7);
MAKO_EVENT_ATTR(itlb-misses, 8);
MAKO_EVENT_ATTR(nonnullified-instructions, 9);
MAKO_EVENT_ATTR(tlb-handler-cycles, 10);
+MAKO_EVENT_ATTR(mem-accesses, 11);
+MAKO_EVENT_ATTR(dcache-misses, 12);
+MAKO_EVENT_ATTR(stores, 13);
+MAKO_EVENT_ATTR(store-dcache-misses, 14);
+MAKO_EVENT_ATTR(branches, 15);
+MAKO_EVENT_ATTR(taken-branches, 16);

static struct attribute *mako_event_attrs[] = {
&mako_attr_0.attr.attr,
@@ -491,6 +530,12 @@ static struct attribute *mako_event_attrs[] = {
&mako_attr_8.attr.attr,
&mako_attr_9.attr.attr,
&mako_attr_10.attr.attr,
+ &mako_attr_11.attr.attr,
+ &mako_attr_12.attr.attr,
+ &mako_attr_13.attr.attr,
+ &mako_attr_14.attr.attr,
+ &mako_attr_15.attr.attr,
+ &mako_attr_16.attr.attr,
NULL,
};

diff --git a/arch/parisc/kernel/perf_mako.c b/arch/parisc/kernel/perf_mako.c
index da8ffcdaa5eb..a93bcb332c9e 100644
--- a/arch/parisc/kernel/perf_mako.c
+++ b/arch/parisc/kernel/perf_mako.c
@@ -15,6 +15,7 @@
* are only started on a CPU once the image has been loaded there.
*/

+#include <linux/bitfield.h>
#include <linux/bug.h>
#include <linux/errno.h>
#include <linux/iopoll.h>
@@ -63,7 +64,18 @@
* misses; bit 6 leaves out the data TLB misses and bit 7 the instruction
* TLB misses. With bit 3 set it counts retired instructions that are not
* nullified, and bits 4-7 each leave out the instructions at one of the
- * four word offsets in an aligned 16-byte block.
+ * four word offsets in an aligned 16-byte block. With bit 3 set, RDR0_0
+ * bit 11 makes it count stores instead.
+ *
+ * RDR0_0 bits 0-4 select what ctr2 counts: instructions (the image's
+ * 01000), loads and stores (00100) or loads and stores that miss the
+ * D-cache (00101). The loads and stores count leaves out most of the
+ * accesses that miss. Bit 13 narrows either count to stores.
+ *
+ * The match filter set to opcodes 0x20-0x3f, with RDR4_0 bit 247 clear and
+ * bits 266, 268 and 271-276 set, counts branches on ctr2. RDR4_0 bytes
+ * 0-3 set to a0 80 80 a0 count taken branches. Both settings come from the
+ * PCX-W (PA-8500 to PA-8700) branch images.
*
* RDR bits are numbered from the most significant bit of the first
* doubleword.
@@ -79,10 +91,22 @@
#define MAKO_RDR4_0_CTR0_INSNS 3
#define MAKO_RDR4_0_CTR0_NO_DTLB 6
#define MAKO_RDR4_0_CTR0_NO_ITLB 7
+#define MAKO_RDR4_0_BRANCH 247
+#define MAKO_RDR4_0_TAKEN 0xa08080a0U
+#define MAKO_RDR0_0_CLASS GENMASK_ULL(63, 59)
+#define MAKO_RDR0_0_MEMOPS 0x04
+#define MAKO_RDR0_0_DMISSES 0x05
+#define MAKO_RDR0_0_CTR0_STORES 11
+#define MAKO_RDR0_0_CTR2_STORES 13
+
+static const unsigned int perf_mako_rdr4_0_branch_set[] = {
+ 266, 268, 271, 272, 273, 274, 275, 276,
+};

struct perf_mako_cpu {
bool loaded;
struct perf_mako_config cfg;
+ uint64_t rdr0_0[ARRAY_SIZE(perf_mako_rdr0_0)];
uint64_t rdr4_0[ARRAY_SIZE(perf_mako_rdr4_0)];
uint64_t rdr16_1[ARRAY_SIZE(perf_mako_rdr16_1)];
};
@@ -190,33 +214,62 @@ static void perf_mako_set_bit(uint64_t *buf, unsigned int bit, bool val)
buf[bit / 64] &= ~m;
}

-/* Build this CPU's copies of RDR4_0 and RDR16_1 for cfg. */
+/* Build this CPU's copies of RDR0_0, RDR4_0 and RDR16_1 for cfg. */
static int perf_mako_build(struct perf_mako_cpu *pc,
const struct perf_mako_config *cfg)
{
bool core_b = perf_mako_core_b();
+ bool filter = cfg->filter;
+ uint32_t mask = cfg->mask, match = cfg->match;
unsigned int j;

if (cfg->set == MAKO_EVENTS_TLB_HANDLER && core_b)
return -EOPNOTSUPP;

+ memcpy(pc->rdr0_0, perf_mako_rdr0_0, sizeof(pc->rdr0_0));
+ if (cfg->ctr2 == MAKO_CTR2_MEMOPS) {
+ pc->rdr0_0[0] &= ~MAKO_RDR0_0_CLASS;
+ pc->rdr0_0[0] |= FIELD_PREP(MAKO_RDR0_0_CLASS, MAKO_RDR0_0_MEMOPS);
+ } else if (cfg->ctr2 == MAKO_CTR2_DMISSES ||
+ cfg->ctr2 == MAKO_CTR2_STORE_DMISSES) {
+ pc->rdr0_0[0] &= ~MAKO_RDR0_0_CLASS;
+ pc->rdr0_0[0] |= FIELD_PREP(MAKO_RDR0_0_CLASS, MAKO_RDR0_0_DMISSES);
+ }
+ if (cfg->ctr2 == MAKO_CTR2_STORE_DMISSES)
+ perf_mako_set_bit(pc->rdr0_0, MAKO_RDR0_0_CTR2_STORES, true);
+ if (cfg->ctr0 == MAKO_CTR0_STORES)
+ perf_mako_set_bit(pc->rdr0_0, MAKO_RDR0_0_CTR0_STORES, true);
+
memcpy(pc->rdr4_0, perf_mako_rdr4_0, sizeof(pc->rdr4_0));
+ if (cfg->ctr2 == MAKO_CTR2_TAKEN) {
+ pc->rdr4_0[0] &= ~GENMASK_ULL(63, 32);
+ pc->rdr4_0[0] |= (uint64_t)MAKO_RDR4_0_TAKEN << 32;
+ }
if (cfg->ctr0 == MAKO_CTR0_DTLB)
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_NO_ITLB, true);
else if (cfg->ctr0 == MAKO_CTR0_ITLB)
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_NO_DTLB, true);
- else if (cfg->ctr0 == MAKO_CTR0_INSNS)
+ else if (cfg->ctr0 == MAKO_CTR0_INSNS || cfg->ctr0 == MAKO_CTR0_STORES)
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_INSNS, true);
- if (cfg->filter) {
+ if (cfg->ctr2 == MAKO_CTR2_BRANCHES) {
+ filter = true;
+ mask = match = 0x80000000;
+ perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_BRANCH, false);
+ for (j = 0; j < ARRAY_SIZE(perf_mako_rdr4_0_branch_set); j++)
+ perf_mako_set_bit(pc->rdr4_0,
+ perf_mako_rdr4_0_branch_set[j], true);
+ }
+ if (filter) {
for (j = 0; j < 32; j++) {
uint32_t b = 1U << (31 - j);

perf_mako_set_bit(pc->rdr4_0, j <= 18 ? 145 - j : 282 - j,
- !(cfg->mask & b));
+ !(mask & b));
perf_mako_set_bit(pc->rdr4_0, j <= 18 ? 108 + j : 205 + j,
- cfg->match & b);
+ match & b);
}
- perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_INVERT, cfg->invert);
+ perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_INVERT,
+ cfg->filter && cfg->invert);
}

memcpy(pc->rdr16_1, perf_mako_rdr16_1, sizeof(pc->rdr16_1));
@@ -368,6 +421,8 @@ int perf_mako_load(const struct perf_mako_config *cfg)
*/
if (r->chain == 1 && r->rdr == 15)
perf_mako_ctrs_rw(ctrs, true);
+ else if (r->chain == 0 && r->rdr == 0)
+ perf_mako_rdr_merge(r, pc->rdr0_0);
else if (r->chain == 0 && r->rdr == 4)
perf_mako_rdr_merge(r, pc->rdr4_0);
else if (r->chain == 1 && r->rdr == 16)
@@ -436,7 +491,7 @@ void perf_mako_disable(void)
static bool perf_mako_cfg_equal(const struct perf_mako_config *a,
const struct perf_mako_config *b)
{
- return a->set == b->set && a->ctr0 == b->ctr0 &&
+ return a->set == b->set && a->ctr0 == b->ctr0 && a->ctr2 == b->ctr2 &&
a->filter == b->filter &&
(!a->filter || (a->invert == b->invert &&
a->mask == b->mask && a->match == b->match));
diff --git a/arch/parisc/kernel/perf_mako.h b/arch/parisc/kernel/perf_mako.h
index 15311b9d770c..424e90cd0583 100644
--- a/arch/parisc/kernel/perf_mako.h
+++ b/arch/parisc/kernel/perf_mako.h
@@ -37,6 +37,17 @@ enum {
MAKO_CTR0_DTLB, /* data TLB misses */
MAKO_CTR0_ITLB, /* instruction TLB misses */
MAKO_CTR0_INSNS, /* instructions retired and not nullified */
+ MAKO_CTR0_STORES, /* stores retired */
+};
+
+/* What ctr2 counts, in the default event set */
+enum {
+ MAKO_CTR2_INSNS, /* instructions retired, maybe filtered */
+ MAKO_CTR2_MEMOPS, /* loads and stores, few of those that miss */
+ MAKO_CTR2_DMISSES, /* loads and stores that miss the D-cache */
+ MAKO_CTR2_STORE_DMISSES, /* stores that miss the D-cache */
+ MAKO_CTR2_BRANCHES, /* branches retired */
+ MAKO_CTR2_TAKEN, /* taken branches retired */
};

/*
@@ -47,7 +58,8 @@ enum {
struct perf_mako_config {
unsigned int set; /* MAKO_EVENTS_* */
unsigned int ctr0; /* MAKO_CTR0_* */
- bool filter;
+ unsigned int ctr2; /* MAKO_CTR2_* */
+ bool filter; /* filter MAKO_CTR2_INSNS */
bool invert;
uint32_t mask;
uint32_t match;

--
2.56.1