Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf report: Display names in s390 diagnostic counter sets

On s390 the CPU Measurement Facility diagnostic counter sets are
displayed by counter number and value. Add the logical counter name in
the output (if it is available). Otherwise "unknown" is shown.

Output before:

[root@s35lp76 perf]# ./perf report -D --stdio
[00000000] Counterset:0 Counters:6
Counter:000 Value:0x000000000085ec36 Counter:001 Value:0x0000000000796c94
Counter:002 Value:0x0000000000005ada Counter:003 Value:0x0000000000092460
Counter:004 Value:0x0000000000006073 Counter:005 Value:0x00000000001a9a73
[0x000038] Counterset:1 Counters:2
Counter:000 Value:0x000000000007c59f Counter:001 Value:0x000000000002fad6
[0x000050] Counterset:2 Counters:16
Counter:000 Value:000000000000000000 Counter:001 Value:000000000000000000

Output after:

[root@s35lp76 perf]# ./perf report -D --stdio

[00000000] Counterset:0 Counters:6
Counter:000 cpu_cycles Value:0x000000000085ec36
Counter:001 instructions Value:0x0000000000796c94
Counter:002 l1i_dir_writes Value:0x0000000000005ada
Counter:003 l1i_penalty_cycles Value:0x0000000000092460
Counter:004 l1d_dir_writes Value:0x0000000000006073
Counter:005 l1d_penalty_cycles Value:0x00000000001a9a73
[0x000038] Counterset:1 Counters:2
Counter:000 problem_state_cpu_cycles Value:0x000000000007c59f
Counter:001 problem_state_instructions Value:0x000000000002fad6
[0x000050] Counterset:2 Counters:16
Counter:000 prng_functions Value:000000000000000000

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Link: http://lkml.kernel.org/r/20190117093003.96287-3-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Thomas Richter and committed by
Arnaldo Carvalho de Melo
3e4a1c53 93115d32

+54 -5
+54 -5
tools/perf/util/s390-sample-raw.c
··· 30 30 #include "color.h" 31 31 #include "sample-raw.h" 32 32 #include "s390-cpumcf-kernel.h" 33 + #include "pmu-events/pmu-events.h" 33 34 34 35 static size_t ctrset_size(struct cf_ctrset_entry *set) 35 36 { ··· 113 112 te.tod_base, te.mach_type); 114 113 } 115 114 115 + /* Return starting number of a counter set */ 116 + static int get_counterset_start(int setnr) 117 + { 118 + switch (setnr) { 119 + case CPUMF_CTR_SET_BASIC: /* Basic counter set */ 120 + return 0; 121 + case CPUMF_CTR_SET_USER: /* Problem state counter set */ 122 + return 32; 123 + case CPUMF_CTR_SET_CRYPTO: /* Crypto counter set */ 124 + return 64; 125 + case CPUMF_CTR_SET_EXT: /* Extended counter set */ 126 + return 128; 127 + case CPUMF_CTR_SET_MT_DIAG: /* Diagnostic counter set */ 128 + return 448; 129 + default: 130 + return -1; 131 + } 132 + } 133 + 134 + /* Scan the PMU table and extract the logical name of a counter from the 135 + * PMU events table. Input is the counter set and counter number with in the 136 + * set. Construct the event number and use this as key. If they match return 137 + * the name of this counter. 138 + * If no match is found a NULL pointer is returned. 139 + */ 140 + static const char *get_counter_name(int set, int nr, struct pmu_events_map *map) 141 + { 142 + int rc, event_nr, wanted = get_counterset_start(set) + nr; 143 + 144 + if (map) { 145 + struct pmu_event *evp = map->table; 146 + 147 + for (; evp->name || evp->event || evp->desc; ++evp) { 148 + if (evp->name == NULL || evp->event == NULL) 149 + continue; 150 + rc = sscanf(evp->event, "event=%x", &event_nr); 151 + if (rc == 1 && event_nr == wanted) 152 + return evp->name; 153 + } 154 + } 155 + return NULL; 156 + } 157 + 116 158 static void s390_cpumcfdg_dump(struct perf_sample *sample) 117 159 { 118 160 size_t i, len = sample->raw_size, offset = 0; 119 161 unsigned char *buf = sample->raw_data; 120 162 const char *color = PERF_COLOR_BLUE; 121 163 struct cf_ctrset_entry *cep, ce; 164 + struct pmu_events_map *map; 165 + struct perf_pmu pmu; 122 166 u64 *p; 123 167 168 + memset(&pmu, 0, sizeof(pmu)); 169 + map = perf_pmu__find_map(&pmu); 124 170 while (offset < len) { 125 171 cep = (struct cf_ctrset_entry *)(buf + offset); 126 172 ··· 184 136 185 137 color_fprintf(stdout, color, " [%#08zx] Counterset:%d" 186 138 " Counters:%d\n", offset, ce.set, ce.ctr); 187 - for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; i += 2, p += 2) 139 + for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) { 140 + const char *ev_name = get_counter_name(ce.set, i, map); 141 + 188 142 color_fprintf(stdout, color, 189 - "\tCounter:%03d Value:%#018lx" 190 - " Counter:%03d Value:%#018lx\n", 191 - i, be64_to_cpu(*p), 192 - i + 1, be64_to_cpu(*(p + 1))); 143 + "\tCounter:%03d %s Value:%#018lx\n", i, 144 + ev_name ?: "<unknown>", be64_to_cpu(*p)); 145 + } 193 146 offset += ctrset_size(&ce); 194 147 } 195 148 }