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

perf report: Add s390 raw data interpretation for PAI counters

Commit 39d62336f5c126ad ("s390/pai: add support for cryptography
counters") added support for Processor Activity Instrumentation Facility
(PAI) counters. These counters values are added as raw data with the
perf sample during 'perf record'.

Now add support to display these counters in the 'perf report' command.

The counter number, its assigned name and value is now printed in
addition to the hexadecimal output.

Output before:

# perf report -D

6 514766399626050 0x7b058 [0x48]: PERF_RECORD_SAMPLE(IP, 0x1):
303977/303977: 0 period: 1 addr: 0
... thread: paitest:303977
...... dso: <not found>

0x7b0a0@/root/perf.data.paicrypto [0x48]: event: 9
.
. ... raw event: size 72 bytes
. 0000: 00 00 00 09 00 01 00 48 00 00 00 00 00 00 00 00 .......H........
. 0010: 00 04 a3 69 00 04 a3 69 00 01 d4 2d 76 de a0 bb ...i...i...-v...
. 0020: 00 00 00 00 00 01 5c 53 00 00 00 06 00 00 00 00 ......\S........
. 0030: 00 00 00 00 00 00 00 01 00 00 00 0c 00 07 00 00 ................
. 0040: 00 00 00 53 96 af 00 00 ...S....

Output after:

# perf report -D

6 514766399626050 0x7b058 [0x48]: PERF_RECORD_SAMPLE(IP, 0x1):
303977/303977: 0 period: 1 addr: 0
... thread: paitest:303977
...... dso: <not found>

0x7b0a0@/root/perf.data.paicrypto [0x48]: event: 9
.
. ... raw event: size 72 bytes
. 0000: 00 00 00 09 00 01 00 48 00 00 00 00 00 00 00 00 .......H........
. 0010: 00 04 a3 69 00 04 a3 69 00 01 d4 2d 76 de a0 bb ...i...i...-v...
. 0020: 00 00 00 00 00 01 5c 53 00 00 00 06 00 00 00 00 ......\S........
. 0030: 00 00 00 00 00 00 00 01 00 00 00 0c 00 07 00 00 ................
. 0040: 00 00 00 53 96 af 00 00 ...S....

Counter:007 km_aes_128 Value:0x00000000005396af <--- new

Committer notes:

Had to add ignore pragmas for that __packed function:

+#pragma GCC diagnostic ignored "-Wpacked"
+#pragma GCC diagnostic ignored "-Wattributes"

Otherwise this doesn't build in things like debian experimentao cross
building to mips64, etc.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Tested-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20231110110908.2312308-1-tmricht@linux.ibm.com
[ Corrected non-existent commit referred to the right one: 39d62336f5c126ad ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Thomas Richter and committed by
Arnaldo Carvalho de Melo
b539deaf c06547d0

+105 -10
+2
tools/perf/util/s390-cpumcf-kernel.h
··· 12 12 #define S390_CPUMCF_DIAG_DEF 0xfeef /* Counter diagnostic entry ID */ 13 13 #define PERF_EVENT_CPUM_CF_DIAG 0xBC000 /* Event: Counter sets */ 14 14 #define PERF_EVENT_CPUM_SF_DIAG 0xBD000 /* Event: Combined-sampling */ 15 + #define PERF_EVENT_PAI_CRYPTO_ALL 0x1000 /* Event: CRYPTO_ALL */ 16 + #define PERF_EVENT_PAI_NNPA_ALL 0x1800 /* Event: NNPA_ALL */ 15 17 16 18 struct cf_ctrset_entry { /* CPU-M CF counter set entry (8 byte) */ 17 19 unsigned int def:16; /* 0-15 Data Entry Format */
+103 -10
tools/perf/util/s390-sample-raw.c
··· 125 125 return 128; 126 126 case CPUMF_CTR_SET_MT_DIAG: /* Diagnostic counter set */ 127 127 return 448; 128 + case PERF_EVENT_PAI_NNPA_ALL: /* PAI NNPA counter set */ 129 + case PERF_EVENT_PAI_CRYPTO_ALL: /* PAI CRYPTO counter set */ 130 + return setnr; 128 131 default: 129 132 return -1; 130 133 } ··· 215 212 } 216 213 } 217 214 218 - /* S390 specific trace event function. Check for PERF_RECORD_SAMPLE events 219 - * and if the event was triggered by a counter set diagnostic event display 220 - * its raw data. 221 - * The function is only invoked when the dump flag -D is set. 215 + #pragma GCC diagnostic push 216 + #pragma GCC diagnostic ignored "-Wpacked" 217 + #pragma GCC diagnostic ignored "-Wattributes" 218 + /* 219 + * Check for consistency of PAI_CRYPTO/PAI_NNPA raw data. 222 220 */ 223 - void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) 221 + struct pai_data { /* Event number and value */ 222 + u16 event_nr; 223 + u64 event_val; 224 + } __packed; 225 + 226 + #pragma GCC diagnostic pop 227 + 228 + /* 229 + * Test for valid raw data. At least one PAI event should be in the raw 230 + * data section. 231 + */ 232 + static bool s390_pai_all_test(struct perf_sample *sample) 224 233 { 234 + unsigned char *buf = sample->raw_data; 235 + size_t len = sample->raw_size; 236 + 237 + if (len < 0xa || !buf) 238 + return false; 239 + return true; 240 + } 241 + 242 + static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample) 243 + { 244 + size_t len = sample->raw_size, offset = 0; 245 + unsigned char *p = sample->raw_data; 246 + const char *color = PERF_COLOR_BLUE; 247 + struct pai_data pai_data; 248 + char *ev_name; 249 + 250 + while (offset < len) { 251 + memcpy(&pai_data.event_nr, p, sizeof(pai_data.event_nr)); 252 + pai_data.event_nr = be16_to_cpu(pai_data.event_nr); 253 + p += sizeof(pai_data.event_nr); 254 + offset += sizeof(pai_data.event_nr); 255 + 256 + memcpy(&pai_data.event_val, p, sizeof(pai_data.event_val)); 257 + pai_data.event_val = be64_to_cpu(pai_data.event_val); 258 + p += sizeof(pai_data.event_val); 259 + offset += sizeof(pai_data.event_val); 260 + 261 + ev_name = get_counter_name(evsel->core.attr.config, 262 + pai_data.event_nr, evsel->pmu); 263 + color_fprintf(stdout, color, "\tCounter:%03d %s Value:%#018lx\n", 264 + pai_data.event_nr, ev_name ?: "<unknown>", 265 + pai_data.event_val); 266 + free(ev_name); 267 + 268 + if (offset + 0xa > len) 269 + break; 270 + } 271 + color_fprintf(stdout, color, "\n"); 272 + } 273 + 274 + /* S390 specific trace event function. Check for PERF_RECORD_SAMPLE events 275 + * and if the event was triggered by a 276 + * - counter set diagnostic event 277 + * - processor activity assist (PAI) crypto counter event 278 + * - processor activity assist (PAI) neural network processor assist (NNPA) 279 + * counter event 280 + * display its raw data. 281 + * The function is only invoked when the dump flag -D is set. 282 + * 283 + * Function evlist__s390_sample_raw() is defined as call back after it has 284 + * been verified that the perf.data file was created on s390 platform. 285 + */ 286 + void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, 287 + struct perf_sample *sample) 288 + { 289 + const char *pai_name; 225 290 struct evsel *evsel; 226 291 227 292 if (event->header.type != PERF_RECORD_SAMPLE) 228 293 return; 229 294 230 295 evsel = evlist__event2evsel(evlist, event); 231 - if (evsel == NULL || 232 - evsel->core.attr.config != PERF_EVENT_CPUM_CF_DIAG) 296 + if (!evsel) 233 297 return; 234 298 235 299 /* Display raw data on screen */ 236 - if (!s390_cpumcfdg_testctr(sample)) { 237 - pr_err("Invalid counter set data encountered\n"); 300 + if (evsel->core.attr.config == PERF_EVENT_CPUM_CF_DIAG) { 301 + if (!evsel->pmu) 302 + evsel->pmu = perf_pmus__find("cpum_cf"); 303 + if (!s390_cpumcfdg_testctr(sample)) 304 + pr_err("Invalid counter set data encountered\n"); 305 + else 306 + s390_cpumcfdg_dump(evsel->pmu, sample); 238 307 return; 239 308 } 240 - s390_cpumcfdg_dump(evsel->pmu, sample); 309 + 310 + switch (evsel->core.attr.config) { 311 + case PERF_EVENT_PAI_NNPA_ALL: 312 + pai_name = "NNPA_ALL"; 313 + break; 314 + case PERF_EVENT_PAI_CRYPTO_ALL: 315 + pai_name = "CRYPTO_ALL"; 316 + break; 317 + default: 318 + return; 319 + } 320 + 321 + if (!s390_pai_all_test(sample)) { 322 + pr_err("Invalid %s raw data encountered\n", pai_name); 323 + } else { 324 + if (!evsel->pmu) 325 + evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type); 326 + s390_pai_all_dump(evsel, sample); 327 + } 241 328 }