Re: [PATCH] powerpc/pmu: Make the generic compat PMU use the architected events

2021-06-26 Thread Michael Ellerman
On Tue, 4 May 2021 17:43:43 +1000, Paul Mackerras wrote:
> This changes generic-compat-pmu.c so that it only uses architected
> events defined in Power ISA v3.0B, rather than event encodings which,
> while common to all the IBM Power Systems implementations, are
> nevertheless implementation-specific rather than architected.  The
> intention is that any CPU implementation designed to conform to Power
> ISA v3.0B or later can use generic-compat-pmu.c.
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/pmu: Make the generic compat PMU use the architected events
  https://git.kernel.org/powerpc/c/d40a82be2f79d16cc18c28c14d267da240659949

cheers


Re: [PATCH] powerpc/pmu: Make the generic compat PMU use the architected events

2021-05-10 Thread Madhavan Srinivasan



On 5/4/21 1:13 PM, Paul Mackerras wrote:

This changes generic-compat-pmu.c so that it only uses architected
events defined in Power ISA v3.0B, rather than event encodings which,
while common to all the IBM Power Systems implementations, are
nevertheless implementation-specific rather than architected.  The



Yeah as you pointed, this was aimed at IBM system implementations.
Thanks for the patch and patch looks fine to me.

Reviewed-by: Madhavan Srinivasan 

I can send a follow up patch to return EINVAL for a non-zero value
other than pmc and pmcsel filed via check_attr_config.


intention is that any CPU implementation designed to conform to Power
ISA v3.0B or later can use generic-compat-pmu.c.

In addition to the existing events for cycles and instructions, this
adds several other architected events, including alternative encodings
for some events.  In order to make it possible to measure cycles and
instructions at the same time as each other, we set the CC5-6RUN bit
in MMCR0, which makes PMC5 and PMC6 count instructions and cycles
regardless of the run bit, so their events are now PM_CYC and
PM_INST_CMPL rather than PM_RUN_CYC and PM_RUN_INST_CMPL (the latter
are still available via other event codes).

Note that POWER9 has an erratum where one architected event
(PM_FLOP_CMPL, floating-point operations completed, code 0x100f4) does
not work correctly.  Given that there is a specific PMU driver for P9
which will be used in preference to generic-compat-pmu.c, that is not
a real problem.

Signed-off-by: Paul Mackerras 
---
  arch/powerpc/perf/generic-compat-pmu.c | 170 +++--
  1 file changed, 134 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/perf/generic-compat-pmu.c 
b/arch/powerpc/perf/generic-compat-pmu.c
index eb8a6aaf4cc1..695975227e60 100644
--- a/arch/powerpc/perf/generic-compat-pmu.c
+++ b/arch/powerpc/perf/generic-compat-pmu.c
@@ -14,45 +14,119 @@
   *
   *2824201612 8 4  
   0
   * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - 
- - - |
- * [ pmc ]   [unit ]   [ ]   m   [pmcxsel  
  ]
- * | |
- * | *- mark
- * |
- * |
- * *- combine
- *
- * Below uses IBM bit numbering.
- *
- * MMCR1[x:y] = unit(PMCxUNIT)
- * MMCR1[24]   = pmc1combine[0]
- * MMCR1[25]   = pmc1combine[1]
- * MMCR1[26]   = pmc2combine[0]
- * MMCR1[27]   = pmc2combine[1]
- * MMCR1[28]   = pmc3combine[0]
- * MMCR1[29]   = pmc3combine[1]
- * MMCR1[30]   = pmc4combine[0]
- * MMCR1[31]   = pmc4combine[1]
- *
+ * [ pmc ]   [pmcxsel  
  ]
   */
  
  /*

- * Some power9 event codes.
+ * Event codes defined in ISA v3.0B
   */
  #define EVENT(_name, _code)   _name = _code,
  
  enum {

-EVENT(PM_CYC,  0x0001e)
-EVENT(PM_INST_CMPL,0x2)
+   /* Cycles, alternate code */
+   EVENT(PM_CYC_ALT,   0x100f0)
+   /* One or more instructions completed in a cycle */
+   EVENT(PM_CYC_INST_CMPL, 0x100f2)
+   /* Floating-point instruction completed */
+   EVENT(PM_FLOP_CMPL, 0x100f4)
+   /* Instruction ERAT/L1-TLB miss */
+   EVENT(PM_L1_ITLB_MISS,  0x100f6)
+   /* All instructions completed and none available */
+   EVENT(PM_NO_INST_AVAIL, 0x100f8)
+   /* A load-type instruction completed (ISA v3.0+) */
+   EVENT(PM_LD_CMPL,   0x100fc)
+   /* Instruction completed, alternate code (ISA v3.0+) */
+   EVENT(PM_INST_CMPL_ALT, 0x100fe)
+   /* A store-type instruction completed */
+   EVENT(PM_ST_CMPL,   0x200f0)
+   /* Instruction Dispatched */
+   EVENT(PM_INST_DISP, 0x200f2)
+   /* Run_cycles */
+   EVENT(PM_RUN_CYC,   0x200f4)
+   /* Data ERAT/L1-TLB miss/reload */
+   EVENT(PM_L1_DTLB_RELOAD,0x200f6)
+   /* Taken branch completed */
+   EVENT(PM_BR_TAKEN_CMPL, 0x200fa)
+   /* Demand iCache Miss */
+   EVENT(PM_L1_ICACHE_MISS,0x200fc)
+   /* L1 Dcache reload from memory */
+   EVENT(PM_L1_RELOAD_FROM_MEM,0x200fe)
+   /* L1 Dcache store miss */
+   EVENT(PM_ST_MISS_L1,0x300f0)
+   /* Alternate code for PM_INST_DISP */
+   EVENT(PM_INST_DISP_ALT, 0x300f2)
+   /* Branch direction or target mispredicted */
+   EVENT(PM_BR_MISPREDICT, 0x300f6)
+   /* Data TLB miss/reload */
+   

[PATCH] powerpc/pmu: Make the generic compat PMU use the architected events

2021-05-04 Thread Paul Mackerras
This changes generic-compat-pmu.c so that it only uses architected
events defined in Power ISA v3.0B, rather than event encodings which,
while common to all the IBM Power Systems implementations, are
nevertheless implementation-specific rather than architected.  The
intention is that any CPU implementation designed to conform to Power
ISA v3.0B or later can use generic-compat-pmu.c.

In addition to the existing events for cycles and instructions, this
adds several other architected events, including alternative encodings
for some events.  In order to make it possible to measure cycles and
instructions at the same time as each other, we set the CC5-6RUN bit
in MMCR0, which makes PMC5 and PMC6 count instructions and cycles
regardless of the run bit, so their events are now PM_CYC and
PM_INST_CMPL rather than PM_RUN_CYC and PM_RUN_INST_CMPL (the latter
are still available via other event codes).

Note that POWER9 has an erratum where one architected event
(PM_FLOP_CMPL, floating-point operations completed, code 0x100f4) does
not work correctly.  Given that there is a specific PMU driver for P9
which will be used in preference to generic-compat-pmu.c, that is not
a real problem.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/perf/generic-compat-pmu.c | 170 +++--
 1 file changed, 134 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/perf/generic-compat-pmu.c 
b/arch/powerpc/perf/generic-compat-pmu.c
index eb8a6aaf4cc1..695975227e60 100644
--- a/arch/powerpc/perf/generic-compat-pmu.c
+++ b/arch/powerpc/perf/generic-compat-pmu.c
@@ -14,45 +14,119 @@
  *
  *2824201612 8 4   
  0
  * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - 
- - |
- * [ pmc ]   [unit ]   [ ]   m   [pmcxsel  
  ]
- * | |
- * | *- mark
- * |
- * |
- * *- combine
- *
- * Below uses IBM bit numbering.
- *
- * MMCR1[x:y] = unit(PMCxUNIT)
- * MMCR1[24]   = pmc1combine[0]
- * MMCR1[25]   = pmc1combine[1]
- * MMCR1[26]   = pmc2combine[0]
- * MMCR1[27]   = pmc2combine[1]
- * MMCR1[28]   = pmc3combine[0]
- * MMCR1[29]   = pmc3combine[1]
- * MMCR1[30]   = pmc4combine[0]
- * MMCR1[31]   = pmc4combine[1]
- *
+ * [ pmc ]   [pmcxsel  
  ]
  */
 
 /*
- * Some power9 event codes.
+ * Event codes defined in ISA v3.0B
  */
 #define EVENT(_name, _code)_name = _code,
 
 enum {
-EVENT(PM_CYC,  0x0001e)
-EVENT(PM_INST_CMPL,0x2)
+   /* Cycles, alternate code */
+   EVENT(PM_CYC_ALT,   0x100f0)
+   /* One or more instructions completed in a cycle */
+   EVENT(PM_CYC_INST_CMPL, 0x100f2)
+   /* Floating-point instruction completed */
+   EVENT(PM_FLOP_CMPL, 0x100f4)
+   /* Instruction ERAT/L1-TLB miss */
+   EVENT(PM_L1_ITLB_MISS,  0x100f6)
+   /* All instructions completed and none available */
+   EVENT(PM_NO_INST_AVAIL, 0x100f8)
+   /* A load-type instruction completed (ISA v3.0+) */
+   EVENT(PM_LD_CMPL,   0x100fc)
+   /* Instruction completed, alternate code (ISA v3.0+) */
+   EVENT(PM_INST_CMPL_ALT, 0x100fe)
+   /* A store-type instruction completed */
+   EVENT(PM_ST_CMPL,   0x200f0)
+   /* Instruction Dispatched */
+   EVENT(PM_INST_DISP, 0x200f2)
+   /* Run_cycles */
+   EVENT(PM_RUN_CYC,   0x200f4)
+   /* Data ERAT/L1-TLB miss/reload */
+   EVENT(PM_L1_DTLB_RELOAD,0x200f6)
+   /* Taken branch completed */
+   EVENT(PM_BR_TAKEN_CMPL, 0x200fa)
+   /* Demand iCache Miss */
+   EVENT(PM_L1_ICACHE_MISS,0x200fc)
+   /* L1 Dcache reload from memory */
+   EVENT(PM_L1_RELOAD_FROM_MEM,0x200fe)
+   /* L1 Dcache store miss */
+   EVENT(PM_ST_MISS_L1,0x300f0)
+   /* Alternate code for PM_INST_DISP */
+   EVENT(PM_INST_DISP_ALT, 0x300f2)
+   /* Branch direction or target mispredicted */
+   EVENT(PM_BR_MISPREDICT, 0x300f6)
+   /* Data TLB miss/reload */
+   EVENT(PM_DTLB_MISS, 0x300fc)
+   /* Demand LD - L3 Miss (not L2 hit and not L3 hit) */
+   EVENT(PM_DATA_FROM_L3MISS,  0x300fe)
+   /* L1 Dcache load miss */
+   EVENT(PM_LD_MISS_L1,0x400f0)
+   /* Cycle when instruction(s) dispatched */
+   EVENT(PM_CYC_INST_DISP,