* [PATCH 1/7] parisc: perf: swap the PCX-U and PCX-W RDR tables
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:02 ` [PATCH 2/7] parisc: perf: add an RDR table for PCX-W2 (PA-8700) Matt Turner
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
perf_rdr_tbl_W holds the PCX-U (PA-8000/PA-8200) RDR widths and
perf_rdr_tbl_U holds the PCX-W (PA-8500/PA-8600) widths, and it has been
that way since the driver was added. The driver's own code and data
show it:
- The CUDA (PCX-W) counter read takes four 32-bit counters, two
doublewords, from RDR15. perf_rdr_tbl_W says RDR15 is 8 bits wide;
perf_rdr_tbl_U says 128.
- The ONYX (PCX-U) counter read takes the counters from bits 1398 to
1529 of RDR16, which needs RDR16 to be 1530 bits wide as in
perf_rdr_tbl_W. perf_rdr_tbl_U says 1494.
- perf_rdr_shift_in_W does nothing for RDR3, RDR7, RDR8, RDR9, RDR12
and RDR19, which are absent in perf_rdr_tbl_U. perf_rdr_tbl_W gives
RDR3, RDR7, RDR9 and RDR12 non-zero widths.
- The ONYX images write RDR7, which is absent in perf_rdr_tbl_U, and the
CUDA images write RDR15, which is 8 bits in perf_rdr_tbl_W.
- The images are laid out for the swapped tables. RDR data is
left-justified, so the bits past each RDR's width are zero. Read
with perf_rdr_tbl_U, none of the 22 cuda_images sets a bit past the
width of any RDR; read with perf_rdr_tbl_W, every image does in about
two thirds of its RDRs. The same holds the other way round for the 44
onyx_images. With the swapped tables both image families end in the
same 9 Runway doublewords, and the CUDA images' Runway STATUS word
then carries bits inside the 0x0013000000000000 mask that
perf_write_image() applies.
- The PA-8500/PA-8600 PDC firmware (from HP-UX 11.11 patch PHSS_25983)
has an RDR description table whose widths equal perf_rdr_tbl_U in
every entry.
As a result every CUDA image write shifts each RDR by the wrong amount
and loads RDR16 one doubleword early, the CUDA counter read returns 8
bits, and on PCX-U RDR7 is never written and the counters are taken
from a misaligned RDR16.
Swap the two tables' names, and correct the RDR20/21 and RDR22/23 widths
in the perf_bitmasks comments. The RDR20/21 mask already covers 158
bits.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/perf.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index 5e10f98ce7b5..8f9ae67270bd 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -67,8 +67,8 @@ static const int perf_rdrs_W[] =
static const int perf_rdrs_U[] =
{ 0, 1, 4, 5, 6, 7, 16, 17, 18, 20, 21, 22, 23, 24, 25, -1 };
-/* RDR register descriptions for PCX-W */
-static const struct rdr_tbl_ent perf_rdr_tbl_W[] = {
+/* RDR register descriptions for PCX-U */
+static const struct rdr_tbl_ent perf_rdr_tbl_U[] = {
{ 19, 1, 8 }, /* RDR 0 */
{ 16, 1, 16 }, /* RDR 1 */
{ 72, 2, 0 }, /* RDR 2 */
@@ -103,8 +103,8 @@ static const struct rdr_tbl_ent perf_rdr_tbl_W[] = {
{ 16, 1, 0 }, /* RDR 31 */
};
-/* RDR register descriptions for PCX-U */
-static const struct rdr_tbl_ent perf_rdr_tbl_U[] = {
+/* RDR register descriptions for PCX-W */
+static const struct rdr_tbl_ent perf_rdr_tbl_W[] = {
{ 19, 1, 8 }, /* RDR 0 */
{ 32, 1, 16 }, /* RDR 1 */
{ 20, 1, 0 }, /* RDR 2 */
@@ -147,10 +147,10 @@ static const uint64_t perf_bitmasks[] = {
0x0000000000000000ul, /* first dbl word must be zero */
0xfdffe00000000000ul, /* RDR0 bitmask */
0x003f000000000000ul, /* RDR1 bitmask */
- 0x00fffffffffffffful, /* RDR20-RDR21 bitmask (152 bits) */
+ 0x00fffffffffffffful, /* RDR20-RDR21 bitmask (158 bits) */
0xfffffffffffffffful,
0xfffffffc00000000ul,
- 0xfffffffffffffffful, /* RDR22-RDR23 bitmask (233 bits) */
+ 0xfffffffffffffffful, /* RDR22-RDR23 bitmask (194 bits) */
0xfffffffffffffffful,
0xfffffffffffffffcul,
0xff00000000000000ul
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 2/7] parisc: perf: add an RDR table for PCX-W2 (PA-8700)
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
2026-11-27 5:02 ` [PATCH 1/7] parisc: perf: swap the PCX-U and PCX-W RDR tables Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:02 ` [PATCH 3/7] parisc: perf: add PA-8800/PA-8900 RDR and DR2 access Matt Turner
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
PCX-W2 uses the PCX-W RDR table, but several of its RDRs have different
widths. The C3650/C3700/C3750/J6700/J6750 PDC firmware (from HP-UX
11.11 patch PHSS_29342) describes RDR11, RDR27 and RDR30 as 32 bits,
RDR12 and RDR13 as 704 bits, and RDR22 and RDR23 as 210 bits.
The RDR22 and RDR23 widths matter: perf_write_image() writes both, and
perf_rdr_read_ubuf() realigns what it shifts out by the RDR width, so
with 194 bits the data comes back misaligned. perf_bitmasks_piranha
already describes RDR22 and RDR23 as 210 bits.
Add perf_rdr_tbl_piranha with the firmware's widths and use it on
PCX-W2.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/perf.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index 8f9ae67270bd..2494f16bb8fd 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -139,6 +139,45 @@ static const struct rdr_tbl_ent perf_rdr_tbl_W[] = {
{ 16, 1, 0 }, /* RDR 31 */
};
+/*
+ * RDR register descriptions for PCX-W2 (PA-8700). RDR11, RDR12, RDR13,
+ * RDR22, RDR23, RDR27 and RDR30 differ from PCX-W.
+ */
+static const struct rdr_tbl_ent perf_rdr_tbl_piranha[] = {
+ { 19, 1, 8 }, /* RDR 0 */
+ { 32, 1, 16 }, /* RDR 1 */
+ { 20, 1, 0 }, /* RDR 2 */
+ { 0, 0, 0 }, /* RDR 3 */
+ { 344, 6, 0 }, /* RDR 4 */
+ { 176, 3, 0 }, /* RDR 5 */
+ { 336, 6, 0 }, /* RDR 6 */
+ { 0, 0, 0 }, /* RDR 7 */
+ { 0, 0, 0 }, /* RDR 8 */
+ { 0, 0, 0 }, /* RDR 9 */
+ { 28, 1, 0 }, /* RDR 10 */
+ { 32, 1, 0 }, /* RDR 11 */
+ { 704, 11, 0 }, /* RDR 12 */
+ { 704, 11, 0 }, /* RDR 13 */
+ { 32, 1, 0 }, /* RDR 14 */
+ { 128, 2, 0 }, /* RDR 15 */
+ { 1494, 24, 0 }, /* RDR 16 */
+ { 18, 1, 0 }, /* RDR 17 */
+ { 4, 1, 0 }, /* RDR 18 */
+ { 0, 0, 0 }, /* RDR 19 */
+ { 158, 3, 24 }, /* RDR 20 */
+ { 158, 3, 24 }, /* RDR 21 */
+ { 210, 4, 48 }, /* RDR 22 */
+ { 210, 4, 48 }, /* RDR 23 */
+ { 71, 2, 0 }, /* RDR 24 */
+ { 71, 2, 0 }, /* RDR 25 */
+ { 28, 1, 0 }, /* RDR 26 */
+ { 32, 1, 0 }, /* RDR 27 */
+ { 88, 2, 0 }, /* RDR 28 */
+ { 32, 1, 0 }, /* RDR 29 */
+ { 32, 1, 0 }, /* RDR 30 */
+ { 16, 1, 0 }, /* RDR 31 */
+};
+
/*
* A non-zero write_control in the above tables is a byte offset into
* this array.
@@ -174,6 +213,7 @@ static const uint64_t perf_bitmasks_piranha[] = {
};
static const uint64_t *bitmask_array; /* array of bitmasks to use */
+static const struct rdr_tbl_ent *perf_rdr_tbl_cuda __ro_after_init;
/******************************************************************************
* Function Prototypes
@@ -499,6 +539,9 @@ static int __init perf_init(void)
boot_cpu_data.cpu_type == mako ||
boot_cpu_data.cpu_type == mako2) {
perf_processor_interface = CUDA_INTF;
+ perf_rdr_tbl_cuda = perf_rdr_tbl_W;
+ if (boot_cpu_data.cpu_type == pcxw2)
+ perf_rdr_tbl_cuda = perf_rdr_tbl_piranha;
if (boot_cpu_data.cpu_type == pcxw2 ||
boot_cpu_data.cpu_type == mako ||
boot_cpu_data.cpu_type == mako2)
@@ -643,7 +686,7 @@ static const struct rdr_tbl_ent * perf_rdr_get_entry(uint32_t rdr_num)
if (perf_processor_interface == ONYX_INTF) {
return &perf_rdr_tbl_U[rdr_num];
} else {
- return &perf_rdr_tbl_W[rdr_num];
+ return &perf_rdr_tbl_cuda[rdr_num];
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 3/7] parisc: perf: add PA-8800/PA-8900 RDR and DR2 access
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
2026-11-27 5:02 ` [PATCH 1/7] parisc: perf: swap the PCX-U and PCX-W RDR tables Matt Turner
2026-11-27 5:02 ` [PATCH 2/7] parisc: perf: add an RDR table for PCX-W2 (PA-8700) Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:02 ` [PATCH 4/7] parisc: perf: program the PA-8800/PA-8900 counters Matt Turner
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
The PA-8800 and PA-8900 (Mako) performance counters are in RDR15 on the
second of two RDR chains, which perf_asm.S cannot reach: its STDIAG and
SFDIAG forms only address chain 0. Chain 1 is shared by the two cores
of a processor, and a core must request it through diagnose register 2
before shifting it.
Add perf_get_dr2() and perf_set_dr2(), and perf_mako_rdr_read() and
perf_mako_rdr_write(), which shift 64 bits out of or into any RDR on
either chain. The access sequences, including which RDRs take a leading
sync and that RDR10 and RDR11 are written together with RDR26 and RDR27,
are the ones the C8000 PDC 2.13 firmware uses (tables at 0x1d6fc0 and
0x1d8000 in the PDC0213 image). Both functions jump into a table of
64-byte entries indexed by rdr + 32 * chain, because the RDR number is
encoded in the DIAG instruction.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/perf_asm.S | 163 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 163 insertions(+)
diff --git a/arch/parisc/kernel/perf_asm.S b/arch/parisc/kernel/perf_asm.S
index 8fceabb1a832..ad240706750e 100644
--- a/arch/parisc/kernel/perf_asm.S
+++ b/arch/parisc/kernel/perf_asm.S
@@ -32,6 +32,169 @@
;
.text
+;
+; Read diagnose register 2
+;
+ENTRY(perf_get_dr2)
+ .proc
+ .callinfo frame=0,NO_CALLS
+ .entry
+ MFDIAG_2 (28)
+ bve (%r2)
+ nop
+ .exit
+ .procend
+ENDPROC(perf_get_dr2)
+
+;
+; Write diagnose register 2
+;
+ENTRY(perf_set_dr2)
+ .proc
+ .callinfo frame=0,NO_CALLS
+ .entry
+ bve (%r2)
+ MTDIAG_2 (26)
+ .exit
+ .procend
+ENDPROC(perf_set_dr2)
+
+;***********************************************************************
+;*
+;* PA-8800/PA-8900 (Mako) RDR access
+;*
+;* Mako has two RDR chains, selected by bit 0x10000 of the STDIAG and
+;* SFDIAG instructions. Chain 0 is private to each core and chain 1 is
+;* shared by the two cores of a processor. The sequences below are the
+;* ones the C8000 PDC 2.13 firmware uses (tables at 0x1d6fc0 and 0x1d8000
+;* in the PDC0213 image), one 64-byte entry per RDR, indexed by
+;* rdr + 32 * chain. The caller must hold the DR2 chain 1 handshake for
+;* chain 1 accesses.
+;*
+;***********************************************************************
+
+#define MAKO_STDIAG(dr, ch) .word 0x14000AA0 + (dr)*0x200000 + (ch)*0x10000
+#define MAKO_SFDIAG(dr, ch) .word 0x14000BA0 + (dr)*0x200000 + (ch)*0x10000
+
+ .macro mako_sfdiag_ent rdr, ch
+ MAKO_SFDIAG(\rdr, \ch)
+ ssm 0,%r0
+ MFDIAG_1 (28)
+ ssm 0,%r0
+ b,n perf_mako_rdr_read_leave
+ .rept 11
+ nop
+ .endr
+ .endm
+
+ .macro mako_stdiag_ent rdr, ch
+ .if (\ch == 0 && (\rdr == 3 || (\rdr >= 7 && \rdr <= 9))) || \
+ (\ch == 1 && (\rdr == 4 || \rdr == 10 || \rdr == 11))
+ ssm 0,%r0 ; no leading sync for these
+ nop
+ nop
+ nop
+ MAKO_STDIAG(\rdr, \ch)
+ .elseif \ch == 0 && (\rdr == 10 || \rdr == 11)
+ sync ; RDR10/11 are written with RDR26/27
+ ssm 0,%r0
+ nop
+ MAKO_STDIAG(\rdr, 0)
+ MAKO_STDIAG(\rdr + 16, 0)
+ .elseif \ch == 0 && (\rdr == 26 || \rdr == 27)
+ sync
+ ssm 0,%r0
+ nop
+ MAKO_STDIAG(\rdr, 0)
+ MAKO_STDIAG(\rdr - 16, 0)
+ .else
+ sync
+ ssm 0,%r0
+ nop
+ nop
+ MAKO_STDIAG(\rdr, \ch)
+ .endif
+ ssm 0,%r0
+ b,n perf_mako_rdr_write_leave
+ .rept 9
+ nop
+ .endr
+ .endm
+
+;
+; uint64_t perf_mako_rdr_read(unsigned long index)
+;
+; Shift the next 64 bits out of RDR (index & 31) on chain (index >> 5)
+; and return them.
+;
+ .align 64
+ENTRY(perf_mako_rdr_read)
+ .proc
+ .callinfo frame=0,NO_CALLS
+ .entry
+ depdi,z 1,DR2_SLOW_RET,1,%r29
+ MFDIAG_2 (24)
+ or %r24,%r29,%r29
+ MTDIAG_2 (29) ; set DR2_SLOW_RET
+ extrd,u arg0,63,6,%r1
+ shladd %r1,3,%r0,%r1 ; 64 bytes per entry
+ .rept 8
+ nop
+ .endr
+ blr %r1,%r0
+ nop
+
+ ; 64-byte aligned here
+ .irp ch, 0, 1
+ .irp rdr, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
+ mako_sfdiag_ent \rdr, \ch
+ .endr
+ .endr
+
+perf_mako_rdr_read_leave:
+ bve (%r2)
+ .exit
+ MTDIAG_2 (24) ; restore DR2
+ .procend
+ENDPROC(perf_mako_rdr_read)
+
+;
+; void perf_mako_rdr_write(unsigned long index, uint64_t value)
+;
+; Shift value into RDR (index & 31) on chain (index >> 5).
+;
+ .align 64
+ENTRY(perf_mako_rdr_write)
+ .proc
+ .callinfo frame=0,NO_CALLS
+ .entry
+ depdi,z 1,DR2_SLOW_RET,1,%r24
+ MFDIAG_2 (23)
+ or %r24,%r23,%r24
+ MTDIAG_2 (24) ; set DR2_SLOW_RET
+ MTDIAG_1 (25) ; data to the staging register
+ extrd,u arg0,63,6,%r1
+ shladd %r1,3,%r0,%r1 ; 64 bytes per entry
+ .rept 7
+ nop
+ .endr
+ blr %r1,%r0
+ nop
+
+ ; 64-byte aligned here
+ .irp ch, 0, 1
+ .irp rdr, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
+ mako_stdiag_ent \rdr, \ch
+ .endr
+ .endr
+
+perf_mako_rdr_write_leave:
+ bve (%r2)
+ .exit
+ MTDIAG_2 (23) ; restore DR2
+ .procend
+ENDPROC(perf_mako_rdr_write)
+
ENTRY(perf_intrigue_enable_perf_counters)
.proc
.callinfo frame=0,NO_CALLS
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 4/7] parisc: perf: program the PA-8800/PA-8900 counters
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
` (2 preceding siblings ...)
2026-11-27 5:02 ` [PATCH 3/7] parisc: perf: add PA-8800/PA-8900 RDR and DR2 access Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:02 ` [PATCH 5/7] parisc: perf: add a perf events PMU for PA-8800/PA-8900 Matt Turner
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
On PA-8800 and PA-8900 (Mako) /dev/perf uses the PCX-W2 bitmasks and the
PCX-W images, which do not match Mako's RDRs, and reads the counters from
chain 0 RDR15, which does not exist there. PA_PERF_OFF fails and writing
an image shifts the wrong number of bits into the wrong RDRs.
Add a separate Mako path that loads the first built-in image of the C8000
PDC 2.13 firmware, in the order and with the masks the firmware's
PDC_INTRIGUE implementation uses. Masked RDRs are merged with their
current contents, so the RDRs that hold live state are kept.
The image is changed in RDR16_1 so that every core counts TLB misses on
ctr0, cycles on ctr1 and ctr3, and instructions retired on ctr2. The
firmware's image enables only ctr0 and ctr1 of the first core.
RDR15_1 holds the counters of both cores of a processor, four each in
32-bit words, and reading it shifts it out. Read it and write it back,
clearing only the half of the running core (DR2 bit 54), so that loading
on one core does not reset the other one.
pmenb before an image has been loaded takes an HPMC, so PA_PERF_ON loads
the image the first time it is used on a CPU and only runs pmenb after
that.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/Makefile | 4 +-
arch/parisc/kernel/perf.c | 33 +++--
arch/parisc/kernel/perf_mako.c | 260 +++++++++++++++++++++++++++++++++++
arch/parisc/kernel/perf_mako.h | 20 +++
arch/parisc/kernel/perf_mako_image.h | 208 ++++++++++++++++++++++++++++
5 files changed, 512 insertions(+), 13 deletions(-)
diff --git a/arch/parisc/kernel/Makefile b/arch/parisc/kernel/Makefile
index 49f937c2abbe..90140593be54 100644
--- a/arch/parisc/kernel/Makefile
+++ b/arch/parisc/kernel/Makefile
@@ -32,8 +32,8 @@ obj-$(CONFIG_64BIT) += sys_parisc32.o signal32.o
obj-$(CONFIG_STACKTRACE)+= stacktrace.o
obj-$(CONFIG_AUDIT) += audit.o
obj64-$(CONFIG_AUDIT) += compat_audit.o
-# only supported for PCX-W/U in 64-bit mode at the moment
-obj-$(CONFIG_64BIT) += perf.o perf_asm.o $(obj64-y)
+# only supported in 64-bit mode at the moment
+obj-$(CONFIG_64BIT) += perf.o perf_mako.o perf_asm.o $(obj64-y)
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += topology.o
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index 2494f16bb8fd..0b9619d18766 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -43,6 +43,7 @@
#include <asm/io.h> /* for __raw_read() */
#include "perf_images.h"
+#include "perf_mako.h"
#define MAX_RDR_WORDS 24
#define PERF_VERSION 2 /* derived from hpux's PI v2 interface */
@@ -56,6 +57,7 @@ struct rdr_tbl_ent {
static int perf_processor_interface __read_mostly = UNKNOWN_INTF;
static int perf_enabled __read_mostly;
+static bool perf_mako __ro_after_init;
static DEFINE_SPINLOCK(perf_lock);
static struct parisc_device *cpu_device __read_mostly;
@@ -140,7 +142,7 @@ static const struct rdr_tbl_ent perf_rdr_tbl_W[] = {
};
/*
- * RDR register descriptions for PCX-W2 (PA-8700). RDR11, RDR12, RDR13,
+ * RDR register descriptions for PCX-W2 (PA-8700). RDR11, RDR12, RDR13,
* RDR22, RDR23, RDR27 and RDR30 differ from PCX-W.
*/
static const struct rdr_tbl_ent perf_rdr_tbl_piranha[] = {
@@ -213,7 +215,7 @@ static const uint64_t perf_bitmasks_piranha[] = {
};
static const uint64_t *bitmask_array; /* array of bitmasks to use */
-static const struct rdr_tbl_ent *perf_rdr_tbl_cuda __ro_after_init;
+static const struct rdr_tbl_ent *perf_rdr_tbl_cuda __read_mostly;
/******************************************************************************
* Function Prototypes
@@ -333,6 +335,12 @@ static ssize_t perf_write(struct file *file, const char __user *buf,
uint32_t interface_type;
uint32_t test;
+ if (!perfmon_capable())
+ return -EACCES;
+
+ if (perf_mako)
+ return perf_mako_write(buf, count);
+
if (perf_processor_interface == ONYX_INTF)
image_size = PCXU_IMAGE_SIZE;
else if (perf_processor_interface == CUDA_INTF)
@@ -340,9 +348,6 @@ static ssize_t perf_write(struct file *file, const char __user *buf,
else
return -EFAULT;
- if (!perfmon_capable())
- return -EACCES;
-
if (count != sizeof(uint32_t))
return -EIO;
@@ -474,11 +479,17 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case PA_PERF_ON:
/* Start the counters */
- perf_start_counters();
+ if (perf_mako)
+ error = perf_mako_start();
+ else
+ perf_start_counters();
break;
case PA_PERF_OFF:
- error_start = perf_stop_counters(raddr);
+ if (perf_mako)
+ error_start = perf_mako_stop(raddr);
+ else
+ error_start = perf_stop_counters(raddr);
if (error_start != 0) {
printk(KERN_ERR "perf_off: perf_stop_counters = %ld\n", error_start);
error = -EFAULT;
@@ -540,12 +551,12 @@ static int __init perf_init(void)
boot_cpu_data.cpu_type == mako2) {
perf_processor_interface = CUDA_INTF;
perf_rdr_tbl_cuda = perf_rdr_tbl_W;
- if (boot_cpu_data.cpu_type == pcxw2)
+ if (boot_cpu_data.cpu_type == pcxw2) {
perf_rdr_tbl_cuda = perf_rdr_tbl_piranha;
- if (boot_cpu_data.cpu_type == pcxw2 ||
- boot_cpu_data.cpu_type == mako ||
- boot_cpu_data.cpu_type == mako2)
bitmask_array = perf_bitmasks_piranha;
+ }
+ perf_mako = boot_cpu_data.cpu_type == mako ||
+ boot_cpu_data.cpu_type == mako2;
} else {
perf_processor_interface = UNKNOWN_INTF;
printk("Performance monitoring counters not supported on this processor\n");
diff --git a/arch/parisc/kernel/perf_mako.c b/arch/parisc/kernel/perf_mako.c
new file mode 100644
index 000000000000..e717ac0c97c8
--- /dev/null
+++ b/arch/parisc/kernel/perf_mako.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * PA-8800/PA-8900 (Mako) performance counters
+ *
+ * Each core has four counters in RDR15 of RDR chain 1, which the two cores
+ * of a processor share: the first four 32-bit words belong to the core
+ * with DR2 bit 54 clear. A counter is 31 bits wide; bit 31 is set when it
+ * wraps and stays set. Before shifting chain 1, a core requests it by setting
+ * DR2 bit 48 and waits for the grant in DR2 bit 53. Writes to both chains
+ * are bracketed by setting and clearing bit 56 of RDR9 on chain 1. The
+ * order and the image are those of the C8000 PDC 2.13 firmware's
+ * PDC_INTRIGUE implementation.
+ *
+ * pmenb before an image has been written takes an HPMC, so the counters
+ * are only started on a CPU once the image has been loaded there.
+ */
+
+#include <linux/bug.h>
+#include <linux/errno.h>
+#include <linux/iopoll.h>
+#include <linux/irqflags.h>
+#include <linux/kernel.h>
+#include <linux/percpu.h>
+#include <linux/uaccess.h>
+#include <asm/perf.h>
+#include <asm/special_insns.h>
+
+#include "perf_mako.h"
+#include "perf_mako_image.h"
+
+#define MAKO_RDR(rdr, chain) ((rdr) | (chain) << 5)
+#define MAKO_DR2_CHAIN1_REQ (1UL << 48)
+#define MAKO_DR2_CHAIN1_GRANT (1UL << 53)
+#define MAKO_DR2_CORE (1UL << 54)
+#define MAKO_RDR9_1_CONFIG (1ULL << 56)
+#define MAKO_CCR_PERF 0x20
+
+static DEFINE_PER_CPU(bool, perf_mako_loaded);
+
+/* The second core of a processor, which owns the second half of RDR15_1. */
+static bool perf_mako_core_b(void)
+{
+ return perf_get_dr2() & MAKO_DR2_CORE;
+}
+
+/*
+ * The other core holds chain 1 only while it loads or reads its counters,
+ * with interrupts off.
+ */
+static int perf_mako_chain1_get(void)
+{
+ unsigned long dr2;
+ int ret;
+
+ perf_set_dr2(perf_get_dr2() | MAKO_DR2_CHAIN1_REQ);
+ ret = read_poll_timeout_atomic(perf_get_dr2, dr2,
+ dr2 & MAKO_DR2_CHAIN1_GRANT, 1,
+ USEC_PER_MSEC, false);
+ if (ret)
+ perf_set_dr2(perf_get_dr2() & ~MAKO_DR2_CHAIN1_REQ);
+
+ return ret;
+}
+
+static void perf_mako_chain1_put(void)
+{
+ perf_set_dr2(perf_get_dr2() & ~MAKO_DR2_CHAIN1_REQ);
+}
+
+/* The last doubleword is shifted first, for both reads and writes. */
+static void perf_mako_rdr_read_buf(unsigned int index, uint64_t *buf,
+ unsigned int n)
+{
+ while (n--)
+ buf[n] = perf_mako_rdr_read(index);
+}
+
+static void perf_mako_rdr_write_buf(unsigned int index, const uint64_t *buf,
+ unsigned int n)
+{
+ while (n--)
+ perf_mako_rdr_write(index, buf[n]);
+}
+
+/*
+ * Write one RDR of the image. Where the image has a mask, merge it with
+ * the current contents the way the firmware does, new = (image & ~mask) |
+ * (current & mask). A read returns the RDR's bits right-justified in
+ * num_words doublewords, while the image and the mask are left-justified,
+ * so the read is shifted left by the unused bits.
+ */
+static void perf_mako_rdr_merge(const struct perf_mako_rdr *r,
+ const uint64_t *data)
+{
+ unsigned int idx = MAKO_RDR(r->rdr, r->chain), n = r->num_words, s, j;
+ uint64_t buf[4];
+
+ if (!r->mask || WARN_ON_ONCE(n > ARRAY_SIZE(buf))) {
+ perf_mako_rdr_write_buf(idx, data, n);
+ return;
+ }
+
+ s = r->width % 64 ? 64 - r->width % 64 : 0;
+ perf_mako_rdr_read_buf(idx, buf, n);
+ for (j = 0; s && j < n; j++)
+ buf[j] = buf[j] << s | (j + 1 < n ? buf[j + 1] >> (64 - s) : 0);
+ for (j = 0; j < n; j++)
+ buf[j] = (data[j] & ~r->mask[j]) | (buf[j] & r->mask[j]);
+ perf_mako_rdr_write_buf(idx, buf, n);
+}
+
+static void perf_mako_config_bit(bool on)
+{
+ uint64_t val = perf_mako_rdr_read(MAKO_RDR(9, 1));
+
+ if (on)
+ val |= MAKO_RDR9_1_CONFIG;
+ else
+ val &= ~MAKO_RDR9_1_CONFIG;
+ perf_mako_rdr_write(MAKO_RDR(9, 1), val);
+}
+
+/*
+ * Read RDR15_1, optionally clearing this core's counters, and write it
+ * back. Reads shift the RDR out, and the other core's counters must be
+ * kept.
+ */
+static void perf_mako_ctrs_rw(uint64_t *buf, bool clear)
+{
+ perf_mako_rdr_read_buf(MAKO_RDR(15, 1), buf, 4);
+ if (clear) {
+ unsigned int h = perf_mako_core_b() ? 2 : 0;
+
+ buf[h] = 0;
+ buf[h + 1] = 0;
+ }
+ perf_mako_rdr_write_buf(MAKO_RDR(15, 1), buf, 4);
+}
+
+/*
+ * Write the image and start the counters on this CPU, from zero. Called
+ * with interrupts off. Like the firmware's boot-time load, this holds
+ * chain 1 across the image write and pmenb.
+ */
+static int perf_mako_load(void)
+{
+ unsigned long ccr = mfctl(10);
+ uint64_t ctrs[4];
+ int i, ret;
+
+ mtctl(ccr | MAKO_CCR_PERF, 10);
+ ret = perf_mako_chain1_get();
+ if (ret)
+ goto out;
+
+ perf_mako_config_bit(true);
+ for (i = 0; i < ARRAY_SIZE(perf_mako_image); i++) {
+ const struct perf_mako_rdr *r = &perf_mako_image[i];
+
+ /*
+ * The firmware presets the first counter to 0x7fffffec.
+ * Start this core's counters from zero instead, and keep
+ * the other core's.
+ */
+ if (r->chain == 1 && r->rdr == 15)
+ perf_mako_ctrs_rw(ctrs, true);
+ else
+ perf_mako_rdr_merge(r, r->data);
+ }
+ perf_mako_config_bit(false);
+
+ asm volatile("pmenb" ::: "memory");
+ perf_mako_chain1_put();
+ this_cpu_write(perf_mako_loaded, true);
+out:
+ mtctl(ccr, 10);
+ return ret;
+}
+
+/* Read this CPU's four counters. Called with interrupts off. */
+static int perf_mako_read(uint32_t *c)
+{
+ unsigned long ccr = mfctl(10);
+ uint64_t buf[4];
+ int i, w, ret;
+
+ mtctl(ccr | MAKO_CCR_PERF, 10);
+ ret = perf_mako_chain1_get();
+ if (ret)
+ goto out;
+
+ perf_mako_config_bit(true);
+ perf_mako_ctrs_rw(buf, false);
+ perf_mako_config_bit(false);
+ perf_mako_chain1_put();
+
+ w = perf_mako_core_b() ? 4 : 0;
+ for (i = 0; i < 4; i++, w++)
+ c[i] = buf[w / 2] >> (w % 2 ? 0 : 32);
+out:
+ mtctl(ccr, 10);
+ return ret;
+}
+
+int perf_mako_start(void)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ local_irq_save(flags);
+ if (this_cpu_read(perf_mako_loaded))
+ perf_intrigue_enable_perf_counters();
+ else
+ ret = perf_mako_load();
+ local_irq_restore(flags);
+
+ return ret;
+}
+
+int perf_mako_stop(uint32_t *raddr)
+{
+ unsigned long flags;
+ int ret = -EINVAL;
+
+ local_irq_save(flags);
+ if (this_cpu_read(perf_mako_loaded)) {
+ perf_intrigue_disable_perf_counters();
+ ret = perf_mako_read(raddr);
+ }
+ local_irq_restore(flags);
+
+ return ret;
+}
+
+/*
+ * The only image is (CUDA_INTF << 16) | 0: ctr0 counts TLB misses, ctr1
+ * and ctr3 cycles, and ctr2 instructions retired. Writing it loads the
+ * image on this CPU and restarts its counters from zero.
+ */
+ssize_t perf_mako_write(const char __user *buf, size_t count)
+{
+ unsigned long flags;
+ uint32_t image;
+ int ret;
+
+ if (count != sizeof(image))
+ return -EIO;
+ if (copy_from_user(&image, buf, sizeof(image)))
+ return -EFAULT;
+ if (image != CUDA_INTF << 16)
+ return -EINVAL;
+
+ local_irq_save(flags);
+ if (this_cpu_read(perf_mako_loaded))
+ perf_intrigue_disable_perf_counters();
+ ret = perf_mako_load();
+ local_irq_restore(flags);
+
+ return ret ? ret : count;
+}
diff --git a/arch/parisc/kernel/perf_mako.h b/arch/parisc/kernel/perf_mako.h
new file mode 100644
index 000000000000..88ca6cef988f
--- /dev/null
+++ b/arch/parisc/kernel/perf_mako.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef PERF_MAKO_H
+#define PERF_MAKO_H
+
+#include <linux/types.h>
+
+/* perf_asm.S */
+unsigned long perf_get_dr2(void);
+void perf_set_dr2(unsigned long dr2);
+uint64_t perf_mako_rdr_read(unsigned long index);
+void perf_mako_rdr_write(unsigned long index, uint64_t value);
+void perf_intrigue_enable_perf_counters(void);
+void perf_intrigue_disable_perf_counters(void);
+
+/* perf_mako.c, for /dev/perf */
+ssize_t perf_mako_write(const char __user *buf, size_t count);
+int perf_mako_start(void);
+int perf_mako_stop(uint32_t *raddr);
+
+#endif
diff --git a/arch/parisc/kernel/perf_mako_image.h b/arch/parisc/kernel/perf_mako_image.h
new file mode 100644
index 000000000000..099df7e42e0d
--- /dev/null
+++ b/arch/parisc/kernel/perf_mako_image.h
@@ -0,0 +1,208 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef PERF_MAKO_IMAGE_H
+#define PERF_MAKO_IMAGE_H
+
+/*
+ * PA-8800/PA-8900 (Mako) image: the RDRs to write, in order, each with its
+ * chain and data. data[0] is the most significant doubleword and is shifted
+ * in last. This is the first built-in image of the C8000 PDC 2.13 firmware
+ * (0x29c920 in the PDC0213 image), which the firmware's PDC_INTRIGUE calls
+ * also load. RDR15 on chain 1 holds the counters.
+ */
+struct perf_mako_rdr {
+ uint8_t rdr;
+ uint8_t chain;
+ uint8_t num_words;
+ uint16_t width;
+ const uint64_t *data;
+ const uint64_t *mask;
+};
+
+#define PERF_MAKO_RDR(r, c, d) \
+ { .rdr = (r), .chain = (c), .num_words = ARRAY_SIZE(d), .data = (d) }
+#define PERF_MAKO_RDR_MASK(r, c, w, d, m) \
+ { .rdr = (r), .chain = (c), .num_words = ARRAY_SIZE(d), .width = (w), \
+ .data = (d), .mask = (m) }
+
+static const uint64_t perf_mako_rdr0_0[] = {
+ 0x4001800000000000ULL,
+};
+static const uint64_t perf_mako_rdr1_0[] = {
+ 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr4_0[] = {
+ 0x0000001000001fffULL, 0x0010007ffc000001ULL, 0xffffffffffffffffULL,
+ 0xffffffff0007ffffULL, 0xffd607ffff846007ULL, 0xffffa00000000000ULL,
+};
+static const uint64_t perf_mako_rdr5_0[] = {
+ 0xc0ffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL,
+ 0xffffffffffff0000ULL,
+};
+static const uint64_t perf_mako_rdr17_0[] = {
+ 0xc000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr18_0[] = {
+ 0xc000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr20_0[] = {
+ 0x00ffffffff3fffffULL, 0xffffffffffcfffffULL, 0xfff7fbfc00000000ULL,
+};
+static const uint64_t perf_mako_rdr21_0[] = {
+ 0x00ffffffff3fffffULL, 0xffffffffffcfffffULL, 0xfff7fbfc00000000ULL,
+};
+static const uint64_t perf_mako_rdr22_0[] = {
+ 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL,
+ 0xfffc000000000000ULL,
+};
+static const uint64_t perf_mako_rdr23_0[] = {
+ 0xffffffffffffffffULL, 0xffffffffffffffffULL, 0xffffffffffffffffULL,
+ 0xfffc000000000000ULL,
+};
+static const uint64_t perf_mako_rdr24_0[] = {
+ 0xfffffffffffff9ffULL, 0xfe00000000000000ULL,
+};
+static const uint64_t perf_mako_rdr25_0[] = {
+ 0xfffffffffffff9ffULL, 0xfe00000000000000ULL,
+};
+static const uint64_t perf_mako_rdr0_1[] = {
+ 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr1_1[] = {
+ 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr5_1[] = {
+ 0x65ffffffffffffffULL, 0xf500000000000000ULL, 0xffffffffffffffffULL,
+ 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr6_1[] = {
+ 0xfff6fff6ffff0c20ULL, 0x000000000000c200ULL, 0x00000000000ee000ULL,
+ 0x0000000000ee0000ULL, 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr9_1[] = {
+ 0x0000000000000001ULL,
+};
+static const uint64_t perf_mako_rdr15_1[] = {
+ 0x7fffffec00000000ULL, 0x0000000000000000ULL, 0x0000000000000000ULL,
+ 0x0000000000000000ULL,
+};
+/*
+ * RDR16_1 selects what the counters count. The firmware's image enables
+ * only ctr0 and ctr1 of the first core. Bytes are numbered from the most
+ * significant byte of the first doubleword; changed from the firmware:
+ *
+ * - Byte 14 (event selects, bits 7..4 for the first core's ctr0..ctr3,
+ * bits 3..0 for the second core's) = 0xaa: ctr0 counts the TLB miss
+ * event, ctr2 the instructions retired event.
+ * - Byte 58 bits 1:0 = 3: count on the first core's ctr1.
+ * - Byte 59 = 0xfa: bits 7 and 5 enable the first core's ctr2 and ctr3,
+ * bits 3 and 1 the second core's ctr0 and ctr1.
+ * - Byte 60 = 0xa0: bits 7 and 5 enable the second core's ctr2 and ctr3.
+ *
+ * Counters without an event selected count cycles, so on every CPU ctr0
+ * counts TLB misses, ctr1 and ctr3 cycles and ctr2 instructions retired.
+ */
+static const uint64_t perf_mako_rdr16_1[] = {
+ 0x00020200a0000000ULL, 0x000aa4444110aa00ULL, 0x000000000009000fULL,
+ 0xf000000000000000ULL, 0x0000000005a12000ULL, 0x0000000000000000ULL,
+ 0x0000000500010555ULL, 0x100003faa0000000ULL, 0x00000ffff0fff000ULL,
+ 0x0000000000000000ULL, 0x0005000f2f0f0f0fULL, 0x0f0f0f0f0f0f0f30ULL,
+ 0xfaf0f08000000000ULL, 0x0000000000000000ULL, 0x900ff00000000000ULL,
+ 0x000000000005a000ULL, 0x0000012000000000ULL, 0x0000000000000005ULL,
+ 0x0015550400000100ULL, 0x00000000000fffffULL, 0xf0f0000000000000ULL,
+ 0x0000050000000f0fULL, 0x0f2f0f0f0f0f0f0fULL, 0x0f0f30f0faf00800ULL,
+ 0x0000000000000000ULL, 0x0000000090000ff0ULL, 0x0000005000050000ULL,
+ 0x0000000000000000ULL, 0x0020000200000000ULL, 0x0500001000000000ULL,
+ 0x0800040401000055ULL, 0x500c0000ff000000ULL, 0x0000ff0000aa00aaULL,
+ 0x0000000000000000ULL, 0x00000000005af000ULL, 0x0b00555000040101ULL,
+ 0x000000000000ffffULL, 0xfffff00000000000ULL, 0x0000000000000fffULL,
+ 0xffffffffffffffffULL, 0xfffffffffffffff0ULL, 0x0000000000000000ULL,
+ 0x0000000fffffffffULL, 0x0000000000000000ULL, 0x00000000ffffffffULL,
+ 0xffffffffffffffffULL, 0xffffffffff000000ULL, 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr20_1[] = {
+ 0xfffffffffffff800ULL, 0x00000000003fffffULL, 0xfffffffe00000000ULL,
+ 0x00000fffffffffffULL, 0xff80000000000003ULL, 0xffffffffffffe000ULL,
+ 0x0000000000000000ULL,
+};
+static const uint64_t perf_mako_rdr24_1[] = {
+ 0x0000000000000000ULL, 0x0000000000000000ULL,
+};
+
+/*
+ * The firmware does not store the image verbatim. It merges each RDR with
+ * the current contents, new = (image & ~mask) | (current & mask), using
+ * the mask table at 0x29ba90 in the PDC0213 image. A set mask bit keeps the
+ * current bit. RDR0, RDR1, RDR9 and RDR24 on chain 1 hold live state, and
+ * overwriting them hangs the machine or takes an HPMC. The masks below are
+ * the firmware's, clipped to the width of each RDR, and are given only for
+ * the RDRs where they keep a bit that exists. Those entries also give the
+ * width of the RDR in bits, which the merge needs to align what it reads.
+ */
+static const uint64_t perf_mako_mask0_0[] = {
+ 0x0200000000000000ULL,
+};
+static const uint64_t perf_mako_mask1_0[] = {
+ 0xffc0ffffffffffffULL,
+};
+static const uint64_t perf_mako_mask20_0[] = {
+ 0xff00000000c00000ULL, 0x0000000000300000ULL, 0x0008040000000000ULL,
+};
+static const uint64_t perf_mako_mask21_0[] = {
+ 0xff00000000c00000ULL, 0x0000000000300000ULL, 0x0008040000000000ULL,
+};
+static const uint64_t perf_mako_mask22_0[] = {
+ 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0000000000000000ULL,
+ 0x0003c00000000000ULL,
+};
+static const uint64_t perf_mako_mask23_0[] = {
+ 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0000000000000000ULL,
+ 0x0003c00000000000ULL,
+};
+static const uint64_t perf_mako_mask0_1[] = {
+ 0xfffffbfffffffffeULL,
+};
+static const uint64_t perf_mako_mask1_1[] = {
+ 0xffffffcfffffffffULL,
+};
+static const uint64_t perf_mako_mask9_1[] = {
+ 0xfffffefffffffffcULL,
+};
+static const uint64_t perf_mako_mask24_1[] = {
+ 0xffffffffc3ffffffULL, 0xffffffffffffffffULL,
+};
+
+static const struct perf_mako_rdr perf_mako_image[] = {
+ PERF_MAKO_RDR_MASK(0, 0, 19, perf_mako_rdr0_0,
+ perf_mako_mask0_0),
+ PERF_MAKO_RDR_MASK(1, 0, 64, perf_mako_rdr1_0,
+ perf_mako_mask1_0),
+ PERF_MAKO_RDR(4, 0, perf_mako_rdr4_0),
+ PERF_MAKO_RDR(5, 0, perf_mako_rdr5_0),
+ PERF_MAKO_RDR(17, 0, perf_mako_rdr17_0),
+ PERF_MAKO_RDR(18, 0, perf_mako_rdr18_0),
+ PERF_MAKO_RDR_MASK(20, 0, 158, perf_mako_rdr20_0,
+ perf_mako_mask20_0),
+ PERF_MAKO_RDR_MASK(21, 0, 158, perf_mako_rdr21_0,
+ perf_mako_mask21_0),
+ PERF_MAKO_RDR_MASK(22, 0, 210, perf_mako_rdr22_0,
+ perf_mako_mask22_0),
+ PERF_MAKO_RDR_MASK(23, 0, 210, perf_mako_rdr23_0,
+ perf_mako_mask23_0),
+ PERF_MAKO_RDR(24, 0, perf_mako_rdr24_0),
+ PERF_MAKO_RDR(25, 0, perf_mako_rdr25_0),
+ PERF_MAKO_RDR_MASK(0, 1, 64, perf_mako_rdr0_1,
+ perf_mako_mask0_1),
+ PERF_MAKO_RDR_MASK(1, 1, 64, perf_mako_rdr1_1,
+ perf_mako_mask1_1),
+ PERF_MAKO_RDR(5, 1, perf_mako_rdr5_1),
+ PERF_MAKO_RDR(6, 1, perf_mako_rdr6_1),
+ PERF_MAKO_RDR_MASK(9, 1, 64, perf_mako_rdr9_1,
+ perf_mako_mask9_1),
+ PERF_MAKO_RDR(15, 1, perf_mako_rdr15_1),
+ PERF_MAKO_RDR(16, 1, perf_mako_rdr16_1),
+ PERF_MAKO_RDR(20, 1, perf_mako_rdr20_1),
+ PERF_MAKO_RDR_MASK(24, 1, 128, perf_mako_rdr24_1,
+ perf_mako_mask24_1),
+};
+
+#endif
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 5/7] parisc: perf: add a perf events PMU for PA-8800/PA-8900
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
` (3 preceding siblings ...)
2026-11-27 5:02 ` [PATCH 4/7] parisc: perf: program the PA-8800/PA-8900 counters Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:02 ` [PATCH 6/7] parisc: perf: add PA-8800/PA-8900 event sets and an instruction filter Matt Turner
2026-11-27 5:03 ` [PATCH 7/7] parisc: perf: add PA-8800/PA-8900 memory and branch events Matt Turner
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
Expose the PA-8800/PA-8900 counters to perf as the "cpu" PMU, so that
perf stat works. The generic cycles and instructions events map to the
counters of the default image, and raw events select what ctr0 counts:
event=0 cycles ctr1 or ctr3
event=1 instructions ctr2
event=2 tlb-misses ctr0
event=7 dtlb-misses ctr0
event=8 itlb-misses ctr0
event=9 nonnullified-instructions ctr0
The first byte of RDR4_0, which each core has its own copy of, selects
what ctr0 counts. Bit 6 leaves out the data TLB misses and bit 7 the
instruction TLB misses, and bit 3 makes it count retired instructions
that are not nullified. The other event codes are left for the events
that need more of the image changed.
The counters cannot interrupt and do not tell privilege levels apart, so
sampling and the exclude bits are not supported. They are 31 bits wide:
a counter wraps from 0x7fffffff to 0 and sets bit 31, which stays set.
At four instructions a cycle ctr2 wraps in about half a second, so a
per-CPU hrtimer reads them every 200 ms while events are active. Reading
needs the counters stopped and shifts RDR15_1 out and back in.
The image is loaded again, which restarts the counters from zero, only
when what ctr0 counts changes.
/dev/perf programs the same counters, so it cannot be opened while perf
events exist, and the other way around.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/Makefile | 1 +
arch/parisc/kernel/perf.c | 4 +-
arch/parisc/kernel/perf_event_mako.c | 414 +++++++++++++++++++++++++++++++++++
arch/parisc/kernel/perf_mako.c | 183 ++++++++++++++--
arch/parisc/kernel/perf_mako.h | 25 +++
5 files changed, 605 insertions(+), 22 deletions(-)
diff --git a/arch/parisc/kernel/Makefile b/arch/parisc/kernel/Makefile
index 90140593be54..2dcd74fe5cbc 100644
--- a/arch/parisc/kernel/Makefile
+++ b/arch/parisc/kernel/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_64BIT) += sys_parisc32.o signal32.o
obj-$(CONFIG_STACKTRACE)+= stacktrace.o
obj-$(CONFIG_AUDIT) += audit.o
obj64-$(CONFIG_AUDIT) += compat_audit.o
+obj64-$(CONFIG_PERF_EVENTS) += perf_event_mako.o
# only supported in 64-bit mode at the moment
obj-$(CONFIG_64BIT) += perf.o perf_mako.o perf_asm.o $(obj64-y)
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += topology.o
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index 0b9619d18766..113fe97e6c5f 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -290,7 +290,7 @@ printk("Preparing to start counters\n");
static int perf_open(struct inode *inode, struct file *file)
{
spin_lock(&perf_lock);
- if (perf_enabled) {
+ if (perf_enabled || (perf_mako && !perf_mako_dev_get())) {
spin_unlock(&perf_lock);
return -EBUSY;
}
@@ -307,6 +307,8 @@ static int perf_release(struct inode *inode, struct file *file)
{
spin_lock(&perf_lock);
perf_enabled = 0;
+ if (perf_mako)
+ perf_mako_dev_put();
spin_unlock(&perf_lock);
return 0;
diff --git a/arch/parisc/kernel/perf_event_mako.c b/arch/parisc/kernel/perf_event_mako.c
new file mode 100644
index 000000000000..f43c8a6cf13d
--- /dev/null
+++ b/arch/parisc/kernel/perf_event_mako.c
@@ -0,0 +1,414 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * perf events for the PA-8800/PA-8900 (Mako) performance counters
+ *
+ * Each core has four 31-bit counters (see perf_mako.c):
+ *
+ * ctr0: TLB misses, instruction and data, or only one kind, or
+ * instructions retired and not nullified
+ * ctr1, ctr3: cycles
+ * ctr2: instructions retired
+ *
+ * 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
+ * sets bit 31, which stays set. At four instructions a cycle ctr2 wraps
+ * in under half a second, so a per-CPU hrtimer reads the counters every
+ * 200 ms.
+ */
+
+#define pr_fmt(fmt) "perf: " fmt
+
+#include <linux/bits.h>
+#include <linux/hrtimer.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/perf_event.h>
+#include <asm/processor.h>
+
+#include "perf_mako.h"
+
+#define MAKO_NUM_CTRS 4
+#define MAKO_POLL_NS (200 * NSEC_PER_MSEC)
+#define MAKO_CTR_MASK GENMASK(30, 0)
+
+enum {
+ MAKO_EV_CYCLES,
+ MAKO_EV_INSTRUCTIONS,
+ MAKO_EV_TLB_MISSES,
+ MAKO_EV_DTLB_MISSES = 7,
+ MAKO_EV_ITLB_MISSES,
+ MAKO_EV_NONNULLIFIED_INSTRUCTIONS,
+ MAKO_EV_MAX,
+};
+
+/* The counters that can count each event, none for unused codes. */
+static const u8 mako_ctrs[MAKO_EV_MAX] = {
+ [MAKO_EV_CYCLES] = BIT(1) | BIT(3),
+ [MAKO_EV_INSTRUCTIONS] = BIT(2),
+ [MAKO_EV_TLB_MISSES] = BIT(0),
+ [MAKO_EV_DTLB_MISSES] = BIT(0),
+ [MAKO_EV_ITLB_MISSES] = BIT(0),
+ [MAKO_EV_NONNULLIFIED_INSTRUCTIONS] = BIT(0),
+};
+
+#define MAKO_CONFIG_EVENT GENMASK_ULL(7, 0)
+
+struct mako_pmu_cpu {
+ struct perf_event *events[MAKO_NUM_CTRS];
+ u32 ctrs[MAKO_NUM_CTRS]; /* last read */
+ bool running; /* counters enabled */
+ struct hrtimer timer;
+};
+
+static DEFINE_PER_CPU(struct mako_pmu_cpu, mako_pmu_cpu);
+
+/* The event code, which event_init() leaves in hw.config. */
+static unsigned int mako_event_code(struct perf_event *event)
+{
+ return event->hw.config;
+}
+
+/*
+ * Assign counters to the events, and work out the configuration they
+ * need. Returns false if they do not fit together on one core.
+ */
+static bool mako_schedule(struct perf_event **events, int n, int *idx,
+ struct perf_mako_config *cfg)
+{
+ u8 used = 0;
+ int i;
+
+ memset(cfg, 0, sizeof(*cfg));
+ for (i = 0; i < n; i++) {
+ unsigned int code = mako_event_code(events[i]);
+ u8 free = mako_ctrs[code] & ~used;
+
+ if (!free)
+ return false;
+ idx[i] = __ffs(free);
+ used |= BIT(idx[i]);
+
+ if (code == MAKO_EV_DTLB_MISSES)
+ cfg->ctr0 = MAKO_CTR0_DTLB;
+ else if (code == MAKO_EV_ITLB_MISSES)
+ cfg->ctr0 = MAKO_CTR0_ITLB;
+ else if (code == MAKO_EV_NONNULLIFIED_INSTRUCTIONS)
+ cfg->ctr0 = MAKO_CTR0_INSNS;
+ }
+
+ return true;
+}
+
+/* Gather the events on this CPU, plus extra if not NULL. */
+static int mako_collect(struct mako_pmu_cpu *pc, struct perf_event *extra,
+ struct perf_event **events)
+{
+ int i, n = 0;
+
+ for (i = 0; i < MAKO_NUM_CTRS; i++)
+ if (pc->events[i])
+ events[n++] = pc->events[i];
+ if (extra)
+ events[n++] = extra;
+
+ return n;
+}
+
+static void mako_event_update(struct perf_event *event, u32 now)
+{
+ struct hw_perf_event *hwc = &event->hw;
+ u32 prev = local64_read(&hwc->prev_count);
+
+ local64_set(&hwc->prev_count, now);
+ local64_add((now - prev) & MAKO_CTR_MASK, &event->count);
+}
+
+/*
+ * Read the counters, and if they are running for perf, update every
+ * started event. The counters have to be stopped to be read. They may
+ * have been left running by /dev/perf, so this always reads them. Called
+ * with interrupts off.
+ */
+static void mako_read_all(struct mako_pmu_cpu *pc)
+{
+ int i;
+
+ perf_mako_disable();
+ if (perf_mako_read(pc->ctrs) == 0 && pc->running) {
+ for (i = 0; i < MAKO_NUM_CTRS; i++) {
+ struct perf_event *event = pc->events[i];
+
+ if (event && !(event->hw.state & PERF_HES_STOPPED))
+ mako_event_update(event, pc->ctrs[i]);
+ }
+ }
+ if (pc->running)
+ perf_mako_enable();
+}
+
+static enum hrtimer_restart mako_poll(struct hrtimer *timer)
+{
+ struct mako_pmu_cpu *pc = container_of(timer, struct mako_pmu_cpu, timer);
+
+ mako_read_all(pc);
+ hrtimer_forward_now(timer, ns_to_ktime(MAKO_POLL_NS));
+
+ return HRTIMER_RESTART;
+}
+
+static void mako_pmu_disable(struct pmu *pmu)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+
+ mako_read_all(pc);
+ perf_mako_disable();
+ pc->running = false;
+}
+
+static void mako_pmu_enable(struct pmu *pmu)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+ struct perf_event *events[MAKO_NUM_CTRS];
+ struct perf_mako_config cfg;
+ int idx[MAKO_NUM_CTRS];
+ int i, n;
+
+ if (pc->running)
+ return;
+
+ n = mako_collect(pc, NULL, events);
+ if (!n) {
+ hrtimer_try_to_cancel(&pc->timer);
+ return;
+ }
+
+ /* add() placed the events, this only recomputes the configuration. */
+ if (WARN_ON_ONCE(!mako_schedule(events, n, idx, &cfg)))
+ return;
+
+ if (perf_mako_is_loaded(&cfg)) {
+ perf_mako_enable();
+ } else {
+ int ret = perf_mako_load(&cfg);
+
+ if (ret) {
+ pr_warn_once("cannot load the counter image: %d\n", ret);
+ return;
+ }
+ memset(pc->ctrs, 0, sizeof(pc->ctrs));
+ for (i = 0; i < n; i++)
+ local64_set(&events[i]->hw.prev_count, 0);
+ }
+ pc->running = true;
+
+ if (!hrtimer_active(&pc->timer))
+ hrtimer_start(&pc->timer, ns_to_ktime(MAKO_POLL_NS),
+ HRTIMER_MODE_REL_PINNED_HARD);
+}
+
+static void mako_pmu_start(struct perf_event *event, int flags)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+ struct hw_perf_event *hwc = &event->hw;
+
+ mako_read_all(pc);
+ local64_set(&hwc->prev_count, pc->ctrs[hwc->idx]);
+ hwc->state = 0;
+}
+
+static void mako_pmu_stop(struct perf_event *event, int flags)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+ struct hw_perf_event *hwc = &event->hw;
+
+ if (hwc->state & PERF_HES_STOPPED)
+ return;
+
+ mako_read_all(pc);
+ hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE;
+}
+
+static int mako_pmu_add(struct perf_event *event, int flags)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+ struct perf_event *events[MAKO_NUM_CTRS + 1];
+ unsigned int code = mako_event_code(event);
+ struct perf_mako_config cfg;
+ int idx[MAKO_NUM_CTRS + 1];
+ unsigned long free = 0;
+ int i, n;
+
+ n = mako_collect(pc, event, events);
+ if (n > MAKO_NUM_CTRS || !mako_schedule(events, n, idx, &cfg))
+ return -EAGAIN;
+
+ /*
+ * Keep the events already here on their counters. Each event can
+ * use either only one counter or only ctr1 and ctr3, so if the
+ * events fit together, one of this event's counters is free.
+ */
+ for (i = 0; i < MAKO_NUM_CTRS; i++)
+ if (!pc->events[i] && (mako_ctrs[code] & BIT(i)))
+ free |= BIT(i);
+
+ event->hw.idx = __ffs(free);
+ pc->events[event->hw.idx] = event;
+
+ event->hw.state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
+ if (flags & PERF_EF_START)
+ mako_pmu_start(event, PERF_EF_RELOAD);
+
+ return 0;
+}
+
+static void mako_pmu_del(struct perf_event *event, int flags)
+{
+ struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+
+ mako_pmu_stop(event, PERF_EF_UPDATE);
+ pc->events[event->hw.idx] = NULL;
+ perf_event_update_userpage(event);
+}
+
+static void mako_pmu_read(struct perf_event *event)
+{
+ mako_read_all(this_cpu_ptr(&mako_pmu_cpu));
+}
+
+static int mako_map_hw(u64 config)
+{
+ switch (config) {
+ case PERF_COUNT_HW_CPU_CYCLES:
+ return MAKO_EV_CYCLES;
+ case PERF_COUNT_HW_INSTRUCTIONS:
+ return MAKO_EV_INSTRUCTIONS;
+ default:
+ return -ENOENT;
+ }
+}
+
+static void mako_event_destroy(struct perf_event *event)
+{
+ perf_mako_pmu_put();
+}
+
+static int mako_pmu_event_init(struct perf_event *event)
+{
+ struct perf_event *leader = event->group_leader, *sibling;
+ struct perf_event *events[MAKO_NUM_CTRS + 1];
+ struct perf_mako_config cfg;
+ int idx[MAKO_NUM_CTRS + 1];
+ int code, n = 0;
+
+ switch (event->attr.type) {
+ case PERF_TYPE_HARDWARE:
+ code = mako_map_hw(event->attr.config);
+ break;
+ case PERF_TYPE_RAW:
+ if (event->attr.config & ~MAKO_CONFIG_EVENT)
+ return -EINVAL;
+ code = event->attr.config;
+ break;
+ default:
+ return -ENOENT;
+ }
+ if (code < 0)
+ return code;
+ if (code >= MAKO_EV_MAX || !mako_ctrs[code])
+ return -EINVAL;
+
+ event->hw.config = code;
+
+ /* The whole group has to fit on one core. */
+ if (leader != event && leader->pmu == event->pmu)
+ events[n++] = leader;
+ for_each_sibling_event(sibling, leader) {
+ if (sibling->pmu != event->pmu)
+ continue;
+ if (n >= MAKO_NUM_CTRS)
+ return -EINVAL;
+ events[n++] = sibling;
+ }
+ events[n++] = event;
+ if (!mako_schedule(events, n, idx, &cfg))
+ return -EINVAL;
+
+ if (!perf_mako_pmu_get())
+ return -EBUSY;
+ event->destroy = mako_event_destroy;
+ event->hw.idx = -1;
+
+ return 0;
+}
+
+PMU_FORMAT_ATTR(event, "config:0-7");
+
+static struct attribute *mako_format_attrs[] = {
+ &format_attr_event.attr,
+ NULL,
+};
+
+static const struct attribute_group mako_format_group = {
+ .name = "format",
+ .attrs = mako_format_attrs,
+};
+
+#define MAKO_EVENT_ATTR(_name, _code) \
+ PMU_EVENT_ATTR_STRING(_name, mako_attr_##_code, "event=" __stringify(_code))
+
+MAKO_EVENT_ATTR(cycles, 0);
+MAKO_EVENT_ATTR(instructions, 1);
+MAKO_EVENT_ATTR(tlb-misses, 2);
+MAKO_EVENT_ATTR(dtlb-misses, 7);
+MAKO_EVENT_ATTR(itlb-misses, 8);
+MAKO_EVENT_ATTR(nonnullified-instructions, 9);
+
+static struct attribute *mako_event_attrs[] = {
+ &mako_attr_0.attr.attr,
+ &mako_attr_1.attr.attr,
+ &mako_attr_2.attr.attr,
+ &mako_attr_7.attr.attr,
+ &mako_attr_8.attr.attr,
+ &mako_attr_9.attr.attr,
+ NULL,
+};
+
+static const struct attribute_group mako_events_group = {
+ .name = "events",
+ .attrs = mako_event_attrs,
+};
+
+static const struct attribute_group *mako_attr_groups[] = {
+ &mako_format_group,
+ &mako_events_group,
+ NULL,
+};
+
+static struct pmu mako_pmu = {
+ .task_ctx_nr = perf_hw_context,
+ .capabilities = PERF_PMU_CAP_NO_INTERRUPT | PERF_PMU_CAP_NO_EXCLUDE,
+ .attr_groups = mako_attr_groups,
+ .event_init = mako_pmu_event_init,
+ .pmu_enable = mako_pmu_enable,
+ .pmu_disable = mako_pmu_disable,
+ .add = mako_pmu_add,
+ .del = mako_pmu_del,
+ .start = mako_pmu_start,
+ .stop = mako_pmu_stop,
+ .read = mako_pmu_read,
+};
+
+static int __init mako_pmu_init(void)
+{
+ int cpu;
+
+ if (boot_cpu_data.cpu_type != mako && boot_cpu_data.cpu_type != mako2)
+ return 0;
+
+ for_each_possible_cpu(cpu)
+ hrtimer_setup(&per_cpu(mako_pmu_cpu, cpu).timer, mako_poll,
+ CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED_HARD);
+
+ return perf_pmu_register(&mako_pmu, "cpu", PERF_TYPE_RAW);
+}
+device_initcall(mako_pmu_init);
diff --git a/arch/parisc/kernel/perf_mako.c b/arch/parisc/kernel/perf_mako.c
index e717ac0c97c8..626163c0b0ce 100644
--- a/arch/parisc/kernel/perf_mako.c
+++ b/arch/parisc/kernel/perf_mako.c
@@ -20,7 +20,10 @@
#include <linux/iopoll.h>
#include <linux/irqflags.h>
#include <linux/kernel.h>
+#include <linux/lockdep.h>
#include <linux/percpu.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <asm/perf.h>
#include <asm/special_insns.h>
@@ -35,7 +38,75 @@
#define MAKO_RDR9_1_CONFIG (1ULL << 56)
#define MAKO_CCR_PERF 0x20
-static DEFINE_PER_CPU(bool, perf_mako_loaded);
+/*
+ * RDR4_0 bits 0-7 select what ctr0 counts. With bit 3 clear it counts TLB
+ * 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.
+ *
+ * RDR bits are numbered from the most significant bit of the first
+ * doubleword.
+ */
+#define MAKO_RDR4_0_CTR0_INSNS 3
+#define MAKO_RDR4_0_CTR0_NO_DTLB 6
+#define MAKO_RDR4_0_CTR0_NO_ITLB 7
+
+struct perf_mako_cpu {
+ bool loaded;
+ struct perf_mako_config cfg;
+ uint64_t rdr4_0[ARRAY_SIZE(perf_mako_rdr4_0)];
+};
+
+static DEFINE_PER_CPU(struct perf_mako_cpu, perf_mako_cpu);
+
+/* /dev/perf loads the default configuration. */
+static const struct perf_mako_config perf_mako_dev_cfg;
+
+/* /dev/perf and perf events must not program the counters at once. */
+static DEFINE_SPINLOCK(perf_mako_owner_lock);
+static bool perf_mako_dev_open;
+static unsigned int perf_mako_pmu_users;
+
+bool perf_mako_dev_get(void)
+{
+ bool ok;
+
+ spin_lock(&perf_mako_owner_lock);
+ ok = !perf_mako_pmu_users;
+ if (ok)
+ perf_mako_dev_open = true;
+ spin_unlock(&perf_mako_owner_lock);
+
+ return ok;
+}
+
+void perf_mako_dev_put(void)
+{
+ spin_lock(&perf_mako_owner_lock);
+ perf_mako_dev_open = false;
+ spin_unlock(&perf_mako_owner_lock);
+}
+
+bool perf_mako_pmu_get(void)
+{
+ bool ok;
+
+ spin_lock(&perf_mako_owner_lock);
+ ok = !perf_mako_dev_open;
+ if (ok)
+ perf_mako_pmu_users++;
+ spin_unlock(&perf_mako_owner_lock);
+
+ return ok;
+}
+
+void perf_mako_pmu_put(void)
+{
+ spin_lock(&perf_mako_owner_lock);
+ perf_mako_pmu_users--;
+ spin_unlock(&perf_mako_owner_lock);
+}
/* The second core of a processor, which owns the second half of RDR15_1. */
static bool perf_mako_core_b(void)
@@ -43,6 +114,29 @@ static bool perf_mako_core_b(void)
return perf_get_dr2() & MAKO_DR2_CORE;
}
+static void perf_mako_set_bit(uint64_t *buf, unsigned int bit, bool val)
+{
+ uint64_t m = 1ULL << (63 - bit % 64);
+
+ if (val)
+ buf[bit / 64] |= m;
+ else
+ buf[bit / 64] &= ~m;
+}
+
+/* Build this CPU's copy of RDR4_0 for cfg. */
+static void perf_mako_build(struct perf_mako_cpu *pc,
+ const struct perf_mako_config *cfg)
+{
+ memcpy(pc->rdr4_0, perf_mako_rdr4_0, sizeof(pc->rdr4_0));
+ 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)
+ perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_INSNS, true);
+}
+
/*
* The other core holds chain 1 only while it loads or reads its counters,
* with interrupts off.
@@ -138,16 +232,24 @@ static void perf_mako_ctrs_rw(uint64_t *buf, bool clear)
}
/*
- * Write the image and start the counters on this CPU, from zero. Called
- * with interrupts off. Like the firmware's boot-time load, this holds
- * chain 1 across the image write and pmenb.
+ * Write the image for cfg and start the counters on this CPU, from zero.
+ * Called with interrupts off. Like the firmware, this holds chain 1 across
+ * the image write and pmenb.
*/
-static int perf_mako_load(void)
+int perf_mako_load(const struct perf_mako_config *cfg)
{
- unsigned long ccr = mfctl(10);
+ struct perf_mako_cpu *pc = this_cpu_ptr(&perf_mako_cpu);
+ unsigned long ccr;
uint64_t ctrs[4];
int i, ret;
+ lockdep_assert_irqs_disabled();
+ perf_mako_build(pc, cfg);
+ if (pc->loaded)
+ perf_intrigue_disable_perf_counters();
+ pc->loaded = false;
+
+ ccr = mfctl(10);
mtctl(ccr | MAKO_CCR_PERF, 10);
ret = perf_mako_chain1_get();
if (ret)
@@ -164,6 +266,8 @@ static int perf_mako_load(void)
*/
if (r->chain == 1 && r->rdr == 15)
perf_mako_ctrs_rw(ctrs, true);
+ else if (r->chain == 0 && r->rdr == 4)
+ perf_mako_rdr_merge(r, pc->rdr4_0);
else
perf_mako_rdr_merge(r, r->data);
}
@@ -171,19 +275,28 @@ static int perf_mako_load(void)
asm volatile("pmenb" ::: "memory");
perf_mako_chain1_put();
- this_cpu_write(perf_mako_loaded, true);
+ pc->cfg = *cfg;
+ pc->loaded = true;
out:
mtctl(ccr, 10);
return ret;
}
-/* Read this CPU's four counters. Called with interrupts off. */
-static int perf_mako_read(uint32_t *c)
+/*
+ * Read this CPU's four counters. Called with interrupts off and the
+ * counters stopped.
+ */
+int perf_mako_read(uint32_t *c)
{
- unsigned long ccr = mfctl(10);
+ unsigned long ccr;
uint64_t buf[4];
int i, w, ret;
+ lockdep_assert_irqs_disabled();
+ if (!this_cpu_read(perf_mako_cpu.loaded))
+ return -EINVAL;
+
+ ccr = mfctl(10);
mtctl(ccr | MAKO_CCR_PERF, 10);
ret = perf_mako_chain1_get();
if (ret)
@@ -202,31 +315,61 @@ static int perf_mako_read(uint32_t *c)
return ret;
}
+/* Start or stop the counters of a loaded CPU. Called with interrupts off. */
+void perf_mako_enable(void)
+{
+ if (this_cpu_read(perf_mako_cpu.loaded))
+ perf_intrigue_enable_perf_counters();
+}
+
+void perf_mako_disable(void)
+{
+ if (this_cpu_read(perf_mako_cpu.loaded))
+ perf_intrigue_disable_perf_counters();
+}
+
+static bool perf_mako_cfg_equal(const struct perf_mako_config *a,
+ const struct perf_mako_config *b)
+{
+ return a->ctr0 == b->ctr0;
+}
+
+/*
+ * Whether cfg is loaded on this CPU and still in effect, so that the
+ * counters can be restarted without loading it again.
+ */
+bool perf_mako_is_loaded(const struct perf_mako_config *cfg)
+{
+ struct perf_mako_cpu *pc = this_cpu_ptr(&perf_mako_cpu);
+
+ return pc->loaded && perf_mako_cfg_equal(&pc->cfg, cfg);
+}
+
+/* PA_PERF_ON: load the default configuration, or restart. */
int perf_mako_start(void)
{
unsigned long flags;
int ret = 0;
local_irq_save(flags);
- if (this_cpu_read(perf_mako_loaded))
- perf_intrigue_enable_perf_counters();
+ if (perf_mako_is_loaded(&perf_mako_dev_cfg))
+ perf_mako_enable();
else
- ret = perf_mako_load();
+ ret = perf_mako_load(&perf_mako_dev_cfg);
local_irq_restore(flags);
return ret;
}
+/* PA_PERF_OFF */
int perf_mako_stop(uint32_t *raddr)
{
unsigned long flags;
- int ret = -EINVAL;
+ int ret;
local_irq_save(flags);
- if (this_cpu_read(perf_mako_loaded)) {
- perf_intrigue_disable_perf_counters();
- ret = perf_mako_read(raddr);
- }
+ perf_mako_disable();
+ ret = perf_mako_read(raddr);
local_irq_restore(flags);
return ret;
@@ -251,9 +394,7 @@ ssize_t perf_mako_write(const char __user *buf, size_t count)
return -EINVAL;
local_irq_save(flags);
- if (this_cpu_read(perf_mako_loaded))
- perf_intrigue_disable_perf_counters();
- ret = perf_mako_load();
+ ret = perf_mako_load(&perf_mako_dev_cfg);
local_irq_restore(flags);
return ret ? ret : count;
diff --git a/arch/parisc/kernel/perf_mako.h b/arch/parisc/kernel/perf_mako.h
index 88ca6cef988f..5a5ba83c893f 100644
--- a/arch/parisc/kernel/perf_mako.h
+++ b/arch/parisc/kernel/perf_mako.h
@@ -12,6 +12,31 @@ void perf_mako_rdr_write(unsigned long index, uint64_t value);
void perf_intrigue_enable_perf_counters(void);
void perf_intrigue_disable_perf_counters(void);
+/* What ctr0 counts */
+enum {
+ MAKO_CTR0_TLB, /* TLB misses, instruction and data */
+ MAKO_CTR0_DTLB, /* data TLB misses */
+ MAKO_CTR0_ITLB, /* instruction TLB misses */
+ MAKO_CTR0_INSNS, /* instructions retired and not nullified */
+};
+
+struct perf_mako_config {
+ unsigned int ctr0; /* MAKO_CTR0_* */
+};
+
+/* perf_mako.c, with interrupts off */
+int perf_mako_load(const struct perf_mako_config *cfg);
+int perf_mako_read(uint32_t *c);
+void perf_mako_enable(void);
+void perf_mako_disable(void);
+bool perf_mako_is_loaded(const struct perf_mako_config *cfg);
+
+/* Exclusion between /dev/perf and perf events */
+bool perf_mako_dev_get(void);
+void perf_mako_dev_put(void);
+bool perf_mako_pmu_get(void);
+void perf_mako_pmu_put(void);
+
/* perf_mako.c, for /dev/perf */
ssize_t perf_mako_write(const char __user *buf, size_t count);
int perf_mako_start(void);
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 6/7] parisc: perf: add PA-8800/PA-8900 event sets and an instruction filter
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
` (4 preceding siblings ...)
2026-11-27 5:02 ` [PATCH 5/7] parisc: perf: add a perf events PMU for PA-8800/PA-8900 Matt Turner
@ 2026-11-27 5:02 ` Matt Turner
2026-11-27 5:03 ` [PATCH 7/7] parisc: perf: add PA-8800/PA-8900 memory and branch events Matt Turner
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:02 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
Add perf events that need the shared RDR16_1 changed, which selects what
ctr1, ctr2 and ctr3 count, and an instruction filter on ctr2:
event=3 stall-cycles ctr1 or ctr3
event=4 nonstall-cycles ctr1 or ctr3
event=5 nonstall-instructions ctr2
event=6 filtered instructions ctr2, with mask, match and invert
event=10 tlb-handler-cycles ctr1 or ctr3, first core only
Stall cycles set one bit of RDR16_1 per core, bit 291 on the first core
of a processor and bit 275 on the second, and ctr2 then reads zero.
Non-stall cycles clear bit 559 on the first core. On the second core
that stops all four counters, so bit 275 is set there instead, together
with bit 324, which turns its stall qualifier into a non-stall one, and
bit 21, which does the same for ctr2. Setting bit 408 and clearing bit
415 makes ctr1 and ctr3 count the cycles spent handling TLB misses and
ctr2 about one per miss. This works only on the first core; on the
second it stops all four counters, so event 10 is not scheduled there.
The filter restricts ctr2 to the retired instructions that match a value
under a mask, or with invert to the others. RDR4_0 holds the mask and
match bits in two runs each, split after instruction bit 18.
The stall and non-stall qualifiers gate ctr0 as well (on the second core
they stop it), so all ctr0 events belong to the default set.
None of this is documented. The bits were found by setting and clearing
RDR bits one at a time on a C8000 and comparing the counts against known
workloads.
RDR16_1 is shared by both cores of a processor, and the stall bit of one
core garbles the other core's counts. All events on a core have to agree
on the event set, and the stall, non-stall and TLB handler sets are used
only while the other core has no events. Events that do not fit are left
to perf to multiplex. The image is also loaded again when the other core
has since loaded a different set into RDR16_1.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/parisc/kernel/perf_event_mako.c | 183 +++++++++++++++++++++++++++++------
arch/parisc/kernel/perf_mako.c | 123 +++++++++++++++++++++--
arch/parisc/kernel/perf_mako.h | 31 ++++++
3 files changed, 302 insertions(+), 35 deletions(-)
diff --git a/arch/parisc/kernel/perf_event_mako.c b/arch/parisc/kernel/perf_event_mako.c
index f43c8a6cf13d..50171267f98b 100644
--- a/arch/parisc/kernel/perf_event_mako.c
+++ b/arch/parisc/kernel/perf_event_mako.c
@@ -2,27 +2,40 @@
/*
* perf events for the PA-8800/PA-8900 (Mako) performance counters
*
- * Each core has four 31-bit counters (see perf_mako.c):
+ * 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
- * ctr1, ctr3: cycles
- * ctr2: instructions retired
+ * 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
*
* 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
* sets bit 31, which stays set. At four instructions a cycle ctr2 wraps
* in under half a second, so a per-CPU hrtimer reads the counters every
* 200 ms.
+ *
+ * The stall and non-stall qualifiers gate ctr0 as well, so the ctr0
+ * events belong to the default set.
+ *
+ * All events on a CPU must agree on the event set. The stall, non-stall
+ * and TLB handler sets also disturb the other core of the processor, so
+ * they are only used while that core has no events, and while one core
+ * uses them the other core can not add any. perf multiplexes the events
+ * that do not fit.
*/
#define pr_fmt(fmt) "perf: " fmt
-#include <linux/bits.h>
+#include <linux/bitfield.h>
#include <linux/hrtimer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/perf_event.h>
+#include <linux/spinlock.h>
#include <asm/processor.h>
#include "perf_mako.h"
@@ -35,23 +48,40 @@ enum {
MAKO_EV_CYCLES,
MAKO_EV_INSTRUCTIONS,
MAKO_EV_TLB_MISSES,
- MAKO_EV_DTLB_MISSES = 7,
+ MAKO_EV_STALL_CYCLES,
+ MAKO_EV_NONSTALL_CYCLES,
+ MAKO_EV_NONSTALL_INSTRUCTIONS,
+ MAKO_EV_FILTERED_INSTRUCTIONS,
+ MAKO_EV_DTLB_MISSES,
MAKO_EV_ITLB_MISSES,
MAKO_EV_NONNULLIFIED_INSTRUCTIONS,
+ MAKO_EV_TLB_HANDLER_CYCLES,
MAKO_EV_MAX,
};
-/* The counters that can count each event, none for unused codes. */
-static const u8 mako_ctrs[MAKO_EV_MAX] = {
- [MAKO_EV_CYCLES] = BIT(1) | BIT(3),
- [MAKO_EV_INSTRUCTIONS] = BIT(2),
- [MAKO_EV_TLB_MISSES] = BIT(0),
- [MAKO_EV_DTLB_MISSES] = BIT(0),
- [MAKO_EV_ITLB_MISSES] = BIT(0),
- [MAKO_EV_NONNULLIFIED_INSTRUCTIONS] = BIT(0),
+#define MAKO_SET_ANY -1
+
+static const struct {
+ u8 ctrs; /* counters that can count it */
+ s8 set; /* MAKO_EVENTS_* */
+} mako_events[MAKO_EV_MAX] = {
+ [MAKO_EV_CYCLES] = { BIT(1) | BIT(3), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_INSTRUCTIONS] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_TLB_MISSES] = { BIT(0), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_STALL_CYCLES] = { BIT(1) | BIT(3), MAKO_EVENTS_STALL },
+ [MAKO_EV_NONSTALL_CYCLES] = { BIT(1) | BIT(3), MAKO_EVENTS_NONSTALL },
+ [MAKO_EV_NONSTALL_INSTRUCTIONS] = { BIT(2), MAKO_EVENTS_NONSTALL },
+ [MAKO_EV_FILTERED_INSTRUCTIONS] = { BIT(2), MAKO_EVENTS_DEFAULT },
+ [MAKO_EV_DTLB_MISSES] = { BIT(0), MAKO_EVENTS_DEFAULT },
+ [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 },
};
#define MAKO_CONFIG_EVENT GENMASK_ULL(7, 0)
+#define MAKO_CONFIG_INVERT BIT_ULL(8)
+#define MAKO_CONFIG1_MASK GENMASK_ULL(31, 0)
+#define MAKO_CONFIG1_MATCH GENMASK_ULL(63, 32)
struct mako_pmu_cpu {
struct perf_event *events[MAKO_NUM_CTRS];
@@ -62,29 +92,52 @@ struct mako_pmu_cpu {
static DEFINE_PER_CPU(struct mako_pmu_cpu, mako_pmu_cpu);
-/* The event code, which event_init() leaves in hw.config. */
-static unsigned int mako_event_code(struct perf_event *event)
+/*
+ * The event set each core of a processor uses, MAKO_SET_ANY when it has no
+ * events. Kept at perf_mako_chip_cpu() and indexed by perf_mako_core_b().
+ */
+struct mako_chip {
+ raw_spinlock_t lock;
+ int set[2];
+};
+
+static DEFINE_PER_CPU(struct mako_chip, mako_chip);
+
+static struct mako_chip *mako_this_chip(void)
{
- return event->hw.config;
+ return per_cpu_ptr(&mako_chip, perf_mako_chip_cpu(smp_processor_id()));
}
/*
- * Assign counters to the events, and work out the configuration they
- * need. Returns false if they do not fit together on one core.
+ * The event code, after event_init(), which leaves it and the invert flag in
+ * hw.config.
+ */
+static unsigned int mako_event_code(struct perf_event *event)
+{
+ return FIELD_GET(MAKO_CONFIG_EVENT, event->hw.config);
+}
+
+/*
+ * Assign counters to the events, and work out the event set and filter
+ * they need. Returns false if they do not fit together on one core.
*/
static bool mako_schedule(struct perf_event **events, int n, int *idx,
struct perf_mako_config *cfg)
{
u8 used = 0;
- int i;
+ int i, set = MAKO_SET_ANY;
memset(cfg, 0, sizeof(*cfg));
for (i = 0; i < n; i++) {
unsigned int code = mako_event_code(events[i]);
- u8 free = mako_ctrs[code] & ~used;
+ u8 free = mako_events[code].ctrs & ~used;
+ int s = mako_events[code].set;
if (!free)
return false;
+ if (set != MAKO_SET_ANY && set != s)
+ return false;
+ set = s;
idx[i] = __ffs(free);
used |= BIT(idx[i]);
@@ -94,7 +147,17 @@ static bool mako_schedule(struct perf_event **events, int n, int *idx,
cfg->ctr0 = MAKO_CTR0_ITLB;
else if (code == MAKO_EV_NONNULLIFIED_INSTRUCTIONS)
cfg->ctr0 = MAKO_CTR0_INSNS;
+
+ if (code == MAKO_EV_FILTERED_INSTRUCTIONS) {
+ u64 c1 = events[i]->attr.config1;
+
+ cfg->filter = true;
+ cfg->invert = events[i]->hw.config & MAKO_CONFIG_INVERT;
+ cfg->mask = FIELD_GET(MAKO_CONFIG1_MASK, c1);
+ cfg->match = FIELD_GET(MAKO_CONFIG1_MATCH, c1);
+ }
}
+ cfg->set = set == MAKO_SET_ANY ? MAKO_EVENTS_DEFAULT : set;
return true;
}
@@ -182,7 +245,7 @@ static void mako_pmu_enable(struct pmu *pmu)
return;
}
- /* add() placed the events, this only recomputes the configuration. */
+ /* add() placed the events, this only recomputes the set. */
if (WARN_ON_ONCE(!mako_schedule(events, n, idx, &cfg)))
return;
@@ -228,6 +291,24 @@ static void mako_pmu_stop(struct perf_event *event, int flags)
hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE;
}
+/* Record the event set this core needs, if the other core allows it. */
+static bool mako_chip_claim(int set)
+{
+ struct mako_chip *chip = mako_this_chip();
+ int core = perf_mako_core_b(), other;
+ bool ok;
+
+ raw_spin_lock(&chip->lock);
+ other = chip->set[!core];
+ ok = other == MAKO_SET_ANY ||
+ (other == MAKO_EVENTS_DEFAULT && set == MAKO_EVENTS_DEFAULT);
+ if (ok)
+ chip->set[core] = set;
+ raw_spin_unlock(&chip->lock);
+
+ return ok;
+}
+
static int mako_pmu_add(struct perf_event *event, int flags)
{
struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
@@ -241,6 +322,11 @@ static int mako_pmu_add(struct perf_event *event, int flags)
n = mako_collect(pc, event, events);
if (n > MAKO_NUM_CTRS || !mako_schedule(events, n, idx, &cfg))
return -EAGAIN;
+ /* A task's events can move to the second core, which cannot count it. */
+ if (cfg.set == MAKO_EVENTS_TLB_HANDLER && perf_mako_core_b())
+ return -EAGAIN;
+ if (!mako_chip_claim(cfg.set))
+ return -EAGAIN;
/*
* Keep the events already here on their counters. Each event can
@@ -248,7 +334,7 @@ static int mako_pmu_add(struct perf_event *event, int flags)
* events fit together, one of this event's counters is free.
*/
for (i = 0; i < MAKO_NUM_CTRS; i++)
- if (!pc->events[i] && (mako_ctrs[code] & BIT(i)))
+ if (!pc->events[i] && (mako_events[code].ctrs & BIT(i)))
free |= BIT(i);
event->hw.idx = __ffs(free);
@@ -264,10 +350,24 @@ static int mako_pmu_add(struct perf_event *event, int flags)
static void mako_pmu_del(struct perf_event *event, int flags)
{
struct mako_pmu_cpu *pc = this_cpu_ptr(&mako_pmu_cpu);
+ struct mako_chip *chip = mako_this_chip();
+ struct perf_event *events[MAKO_NUM_CTRS];
+ int core = perf_mako_core_b();
+ struct perf_mako_config cfg;
+ int idx[MAKO_NUM_CTRS];
+ int n;
mako_pmu_stop(event, PERF_EF_UPDATE);
pc->events[event->hw.idx] = NULL;
perf_event_update_userpage(event);
+
+ n = mako_collect(pc, NULL, events);
+ raw_spin_lock(&chip->lock);
+ if (!n)
+ chip->set[core] = MAKO_SET_ANY;
+ else if (mako_schedule(events, n, idx, &cfg))
+ chip->set[core] = cfg.set;
+ raw_spin_unlock(&chip->lock);
}
static void mako_pmu_read(struct perf_event *event)
@@ -299,25 +399,32 @@ static int mako_pmu_event_init(struct perf_event *event)
struct perf_mako_config cfg;
int idx[MAKO_NUM_CTRS + 1];
int code, n = 0;
+ u64 config;
switch (event->attr.type) {
case PERF_TYPE_HARDWARE:
code = mako_map_hw(event->attr.config);
break;
case PERF_TYPE_RAW:
- if (event->attr.config & ~MAKO_CONFIG_EVENT)
- return -EINVAL;
- code = event->attr.config;
+ code = FIELD_GET(MAKO_CONFIG_EVENT, event->attr.config);
break;
default:
return -ENOENT;
}
if (code < 0)
return code;
- if (code >= MAKO_EV_MAX || !mako_ctrs[code])
+ if (code >= MAKO_EV_MAX)
return -EINVAL;
- event->hw.config = code;
+ /* The filter fields are only valid on filtered instructions. */
+ config = event->attr.type == PERF_TYPE_RAW ? event->attr.config : code;
+ if (code != MAKO_EV_FILTERED_INSTRUCTIONS &&
+ ((config & MAKO_CONFIG_INVERT) || event->attr.config1))
+ return -EINVAL;
+ if (config & ~(MAKO_CONFIG_EVENT | MAKO_CONFIG_INVERT))
+ return -EINVAL;
+
+ event->hw.config = code | (config & MAKO_CONFIG_INVERT);
/* The whole group has to fit on one core. */
if (leader != event && leader->pmu == event->pmu)
@@ -342,9 +449,15 @@ static int mako_pmu_event_init(struct perf_event *event)
}
PMU_FORMAT_ATTR(event, "config:0-7");
+PMU_FORMAT_ATTR(invert, "config:8");
+PMU_FORMAT_ATTR(mask, "config1:0-31");
+PMU_FORMAT_ATTR(match, "config1:32-63");
static struct attribute *mako_format_attrs[] = {
&format_attr_event.attr,
+ &format_attr_invert.attr,
+ &format_attr_mask.attr,
+ &format_attr_match.attr,
NULL,
};
@@ -359,17 +472,25 @@ static const struct attribute_group mako_format_group = {
MAKO_EVENT_ATTR(cycles, 0);
MAKO_EVENT_ATTR(instructions, 1);
MAKO_EVENT_ATTR(tlb-misses, 2);
+MAKO_EVENT_ATTR(stall-cycles, 3);
+MAKO_EVENT_ATTR(nonstall-cycles, 4);
+MAKO_EVENT_ATTR(nonstall-instructions, 5);
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);
static struct attribute *mako_event_attrs[] = {
&mako_attr_0.attr.attr,
&mako_attr_1.attr.attr,
&mako_attr_2.attr.attr,
+ &mako_attr_3.attr.attr,
+ &mako_attr_4.attr.attr,
+ &mako_attr_5.attr.attr,
&mako_attr_7.attr.attr,
&mako_attr_8.attr.attr,
&mako_attr_9.attr.attr,
+ &mako_attr_10.attr.attr,
NULL,
};
@@ -405,9 +526,15 @@ static int __init mako_pmu_init(void)
if (boot_cpu_data.cpu_type != mako && boot_cpu_data.cpu_type != mako2)
return 0;
- for_each_possible_cpu(cpu)
+ for_each_possible_cpu(cpu) {
+ struct mako_chip *chip = per_cpu_ptr(&mako_chip, cpu);
+
+ raw_spin_lock_init(&chip->lock);
+ chip->set[0] = MAKO_SET_ANY;
+ chip->set[1] = MAKO_SET_ANY;
hrtimer_setup(&per_cpu(mako_pmu_cpu, cpu).timer, mako_poll,
CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED_HARD);
+ }
return perf_pmu_register(&mako_pmu, "cpu", PERF_TYPE_RAW);
}
diff --git a/arch/parisc/kernel/perf_mako.c b/arch/parisc/kernel/perf_mako.c
index 626163c0b0ce..da8ffcdaa5eb 100644
--- a/arch/parisc/kernel/perf_mako.c
+++ b/arch/parisc/kernel/perf_mako.c
@@ -24,6 +24,7 @@
#include <linux/percpu.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/topology.h>
#include <linux/uaccess.h>
#include <asm/perf.h>
#include <asm/special_insns.h>
@@ -39,6 +40,25 @@
#define MAKO_CCR_PERF 0x20
/*
+ * The cycle signal of ctr1, ctr3 and ctr2 can be qualified by stall
+ * cycles: RDR16_1 bit 291 does this for the first core of a processor and
+ * bit 275 for the second. Each garbles the other core's counts, so only
+ * the bit of the core being programmed is set. Clearing bit 559 qualifies
+ * the signal by non-stall cycles on the first core; on the second it stops
+ * all four counters. There, setting bit 324 together with bit 275 turns
+ * the stall qualifier of ctr1 and ctr3 into a non-stall one, and bit 21
+ * then qualifies ctr2 the same way.
+ *
+ * Setting RDR16_1 bit 408 and clearing bit 415 makes ctr1 and ctr3 count
+ * the cycles spent handling TLB misses, and ctr2 about one per miss. This
+ * works only on the first core; on the second it stops all four counters.
+ *
+ * RDR4_0 compares each retiring instruction against a match value under a
+ * mask and gates ctr2 with the result. Instruction bit j (0 is the most
+ * significant) has its mask bit at 145 - j and its match bit at 108 + j
+ * for j <= 18, and at 282 - j and 205 + j above that. A set mask bit
+ * means don't care. Bit 19 inverts the comparison.
+ *
* RDR4_0 bits 0-7 select what ctr0 counts. With bit 3 clear it counts TLB
* 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
@@ -48,6 +68,14 @@
* RDR bits are numbered from the most significant bit of the first
* doubleword.
*/
+#define MAKO_RDR16_1_STALL_A 291
+#define MAKO_RDR16_1_STALL_B 275
+#define MAKO_RDR16_1_NONSTALL 559
+#define MAKO_RDR16_1_NONSTALL_B 324
+#define MAKO_RDR16_1_NONSTALL_B_CTR2 21
+#define MAKO_RDR16_1_TLB_HANDLER 408
+#define MAKO_RDR16_1_TLB_HANDLER_CLR 415
+#define MAKO_RDR4_0_INVERT 19
#define MAKO_RDR4_0_CTR0_INSNS 3
#define MAKO_RDR4_0_CTR0_NO_DTLB 6
#define MAKO_RDR4_0_CTR0_NO_ITLB 7
@@ -56,6 +84,7 @@ struct perf_mako_cpu {
bool loaded;
struct perf_mako_config cfg;
uint64_t rdr4_0[ARRAY_SIZE(perf_mako_rdr4_0)];
+ uint64_t rdr16_1[ARRAY_SIZE(perf_mako_rdr16_1)];
};
static DEFINE_PER_CPU(struct perf_mako_cpu, perf_mako_cpu);
@@ -63,6 +92,15 @@ static DEFINE_PER_CPU(struct perf_mako_cpu, perf_mako_cpu);
/* /dev/perf loads the default configuration. */
static const struct perf_mako_config perf_mako_dev_cfg;
+/*
+ * RDR16_1 is shared by the two cores of a processor, and each load writes
+ * all of it, so a load on one core undoes the event set the other core
+ * selected. Record per processor, at perf_mako_chip_cpu(), which core's
+ * set RDR16_1 holds: the default set is the same for both cores. Loads
+ * are serialized by the chain 1 handshake.
+ */
+static DEFINE_PER_CPU(int, perf_mako_rdr16_1_key);
+
/* /dev/perf and perf events must not program the counters at once. */
static DEFINE_SPINLOCK(perf_mako_owner_lock);
static bool perf_mako_dev_open;
@@ -109,11 +147,39 @@ void perf_mako_pmu_put(void)
}
/* The second core of a processor, which owns the second half of RDR15_1. */
-static bool perf_mako_core_b(void)
+bool perf_mako_core_b(void)
{
return perf_get_dr2() & MAKO_DR2_CORE;
}
+/*
+ * The first CPU of cpu's processor, where data shared by the processor's
+ * cores is kept. The package id stays the same while a CPU is offline.
+ */
+int perf_mako_chip_cpu(int cpu)
+{
+ int id = topology_physical_package_id(cpu), c;
+
+ for_each_possible_cpu(c)
+ if (topology_physical_package_id(c) == id)
+ return c;
+
+ return cpu;
+}
+
+static int perf_mako_key(const struct perf_mako_config *cfg)
+{
+ if (cfg->set == MAKO_EVENTS_DEFAULT)
+ return 0;
+ return cfg->set | perf_mako_core_b() << 4;
+}
+
+static int *perf_mako_chip_key(void)
+{
+ return per_cpu_ptr(&perf_mako_rdr16_1_key,
+ perf_mako_chip_cpu(smp_processor_id()));
+}
+
static void perf_mako_set_bit(uint64_t *buf, unsigned int bit, bool val)
{
uint64_t m = 1ULL << (63 - bit % 64);
@@ -124,10 +190,16 @@ static void perf_mako_set_bit(uint64_t *buf, unsigned int bit, bool val)
buf[bit / 64] &= ~m;
}
-/* Build this CPU's copy of RDR4_0 for cfg. */
-static void perf_mako_build(struct perf_mako_cpu *pc,
- const struct perf_mako_config *cfg)
+/* Build this CPU's copies of 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();
+ unsigned int j;
+
+ if (cfg->set == MAKO_EVENTS_TLB_HANDLER && core_b)
+ return -EOPNOTSUPP;
+
memcpy(pc->rdr4_0, perf_mako_rdr4_0, sizeof(pc->rdr4_0));
if (cfg->ctr0 == MAKO_CTR0_DTLB)
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_NO_ITLB, true);
@@ -135,6 +207,34 @@ static void perf_mako_build(struct perf_mako_cpu *pc,
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_NO_DTLB, true);
else if (cfg->ctr0 == MAKO_CTR0_INSNS)
perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_CTR0_INSNS, true);
+ if (cfg->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));
+ perf_mako_set_bit(pc->rdr4_0, j <= 18 ? 108 + j : 205 + j,
+ cfg->match & b);
+ }
+ perf_mako_set_bit(pc->rdr4_0, MAKO_RDR4_0_INVERT, cfg->invert);
+ }
+
+ memcpy(pc->rdr16_1, perf_mako_rdr16_1, sizeof(pc->rdr16_1));
+ if (cfg->set == MAKO_EVENTS_STALL) {
+ perf_mako_set_bit(pc->rdr16_1, core_b ? MAKO_RDR16_1_STALL_B :
+ MAKO_RDR16_1_STALL_A, true);
+ } else if (cfg->set == MAKO_EVENTS_NONSTALL && core_b) {
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_STALL_B, true);
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_NONSTALL_B, true);
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_NONSTALL_B_CTR2, true);
+ } else if (cfg->set == MAKO_EVENTS_NONSTALL) {
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_NONSTALL, false);
+ } else if (cfg->set == MAKO_EVENTS_TLB_HANDLER) {
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_TLB_HANDLER, true);
+ perf_mako_set_bit(pc->rdr16_1, MAKO_RDR16_1_TLB_HANDLER_CLR, false);
+ }
+
+ return 0;
}
/*
@@ -244,7 +344,9 @@ int perf_mako_load(const struct perf_mako_config *cfg)
int i, ret;
lockdep_assert_irqs_disabled();
- perf_mako_build(pc, cfg);
+ ret = perf_mako_build(pc, cfg);
+ if (ret)
+ return ret;
if (pc->loaded)
perf_intrigue_disable_perf_counters();
pc->loaded = false;
@@ -268,12 +370,15 @@ int perf_mako_load(const struct perf_mako_config *cfg)
perf_mako_ctrs_rw(ctrs, true);
else if (r->chain == 0 && r->rdr == 4)
perf_mako_rdr_merge(r, pc->rdr4_0);
+ else if (r->chain == 1 && r->rdr == 16)
+ perf_mako_rdr_merge(r, pc->rdr16_1);
else
perf_mako_rdr_merge(r, r->data);
}
perf_mako_config_bit(false);
asm volatile("pmenb" ::: "memory");
+ WRITE_ONCE(*perf_mako_chip_key(), perf_mako_key(cfg));
perf_mako_chain1_put();
pc->cfg = *cfg;
pc->loaded = true;
@@ -331,7 +436,10 @@ 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->ctr0 == b->ctr0;
+ return a->set == b->set && a->ctr0 == b->ctr0 &&
+ a->filter == b->filter &&
+ (!a->filter || (a->invert == b->invert &&
+ a->mask == b->mask && a->match == b->match));
}
/*
@@ -342,7 +450,8 @@ bool perf_mako_is_loaded(const struct perf_mako_config *cfg)
{
struct perf_mako_cpu *pc = this_cpu_ptr(&perf_mako_cpu);
- return pc->loaded && perf_mako_cfg_equal(&pc->cfg, cfg);
+ return pc->loaded && perf_mako_cfg_equal(&pc->cfg, cfg) &&
+ READ_ONCE(*perf_mako_chip_key()) == perf_mako_key(cfg);
}
/* PA_PERF_ON: load the default configuration, or restart. */
diff --git a/arch/parisc/kernel/perf_mako.h b/arch/parisc/kernel/perf_mako.h
index 5a5ba83c893f..15311b9d770c 100644
--- a/arch/parisc/kernel/perf_mako.h
+++ b/arch/parisc/kernel/perf_mako.h
@@ -12,6 +12,25 @@ void perf_mako_rdr_write(unsigned long index, uint64_t value);
void perf_intrigue_enable_perf_counters(void);
void perf_intrigue_disable_perf_counters(void);
+/*
+ * Event sets, which select what ctr1, ctr2 and ctr3 count. Counters are
+ * listed ctr0 to ctr3.
+ *
+ * DEFAULT: TLB misses, cycles, instructions retired, cycles
+ * STALL: TLB misses, stall cycles, 0, stall cycles
+ * NONSTALL: TLB misses, non-stall cycles, instructions retired in
+ * non-stall cycles, non-stall cycles
+ * TLB_HANDLER: TLB misses, cycles in TLB miss handling, about one per
+ * miss, cycles in TLB miss handling. Only on the first core
+ * of a processor.
+ */
+enum {
+ MAKO_EVENTS_DEFAULT,
+ MAKO_EVENTS_STALL,
+ MAKO_EVENTS_NONSTALL,
+ MAKO_EVENTS_TLB_HANDLER,
+};
+
/* What ctr0 counts */
enum {
MAKO_CTR0_TLB, /* TLB misses, instruction and data */
@@ -20,8 +39,18 @@ enum {
MAKO_CTR0_INSNS, /* instructions retired and not nullified */
};
+/*
+ * With filter set, ctr2 counts only the retired instructions whose bits
+ * selected by mask equal those of match, or with invert all other
+ * instructions. Nullified instructions count.
+ */
struct perf_mako_config {
+ unsigned int set; /* MAKO_EVENTS_* */
unsigned int ctr0; /* MAKO_CTR0_* */
+ bool filter;
+ bool invert;
+ uint32_t mask;
+ uint32_t match;
};
/* perf_mako.c, with interrupts off */
@@ -30,6 +59,8 @@ int perf_mako_read(uint32_t *c);
void perf_mako_enable(void);
void perf_mako_disable(void);
bool perf_mako_is_loaded(const struct perf_mako_config *cfg);
+bool perf_mako_core_b(void);
+int perf_mako_chip_cpu(int cpu);
/* Exclusion between /dev/perf and perf events */
bool perf_mako_dev_get(void);
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 7/7] parisc: perf: add PA-8800/PA-8900 memory and branch events
2026-11-27 5:02 [PATCH 0/7] parisc: perf: fix the RDR tables and add PA-8800/PA-8900 counters Matt Turner
` (5 preceding siblings ...)
2026-11-27 5:02 ` [PATCH 6/7] parisc: perf: add PA-8800/PA-8900 event sets and an instruction filter Matt Turner
@ 2026-11-27 5:03 ` Matt Turner
6 siblings, 0 replies; 8+ messages in thread
From: Matt Turner @ 2026-11-27 5:03 UTC (permalink / raw)
To: James E.J. Bottomley, Helge Deller, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark
Cc: linux-parisc, linux-kernel, linux-perf-users, Matt Turner
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 8+ messages in thread