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

perf auxtrace: Support for perf report -D for s390

Add initial support for s390 auxiliary traces using the CPU-Measurement
Sampling Facility.

Support and ignore PERF_REPORT_AUXTRACE_INFO records in the perf data
file. Later patches will show the contents of the auxiliary traces.

Setup the auxtrace queues and data structures for s390. A raw dump of
the perf.data file now does not show an error when an auxtrace event is
encountered.

Output before:

[root@s35lp76 perf]# ./perf report -D -i perf.data.auxtrace
0x128 [0x10]: failed to process type: 70
Error:
failed to process sample

0x128 [0x10]: event: 70
.
. ... raw event: size 16 bytes
. 0000: 00 00 00 46 00 00 00 10 00 00 00 00 00 00 00 00 ...F............

0x128 [0x10]: PERF_RECORD_AUXTRACE_INFO type: 0
[root@s35lp76 perf]#

Output after:

# ./perf report -D -i perf.data.auxtrace |fgrep PERF_RECORD_AUXTRACE
0 0 0x128 [0x10]: PERF_RECORD_AUXTRACE_INFO type: 5
0 0 0x25a66 [0x30]: PERF_RECORD_AUXTRACE size: 0x40000
offset: 0 ref: 0 idx: 4 tid: -1 cpu: 4
....

Additional notes about the underlying hardware and software
implementation, provided by Hendrik Brueckner (see Link: below).

=============================================================================

The CPU-Measurement Facility (CPU-MF) provides a set of functions to obtain
performance information on the mainframe. Basically, it was introduced
with System z10 years ago for the z/Architecture, that means, 64-bit.
For Linux, there are two facilities of interest, counter facility and sampling
facility. The counter facility provides hardware counters for instructions,
cycles, crypto-activities, and many more.

The sampling facility is a hardware sampler that when started will write
samples at a particular interval into a sampling buffer. At some point,
for example, if a sample block is full, it generates an interrupt to collect
samples (while the sampler continues to run).

Few years ago, I started to provide the a perf PMU to use the counter
and sampling facilities. Recently, the device driver was updated to also
"export" the sampling buffer into the AUX area. Thomas now completed the
related perf work to interpret and process these AUX data.

If people are more interested in the sampling facility, they can have a
look into:

- The Load-Program-Parameter and the CPU-Measurement Facilities, SA23-2260-05
http://www-01.ibm.com/support/docview.wss?uid=isg26fcd1cc32246f4c8852574ce0044734a

and to learn how-to use it for Linux on Z, have look at chapter 54,
"Using the CPU-measurement facilities" in the:

- Device Drivers, Features, and Commands, SC33-8411-34
http://public.dhe.ibm.com/software/dw/linux390/docu/l416dd34.pdf

=============================================================================

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Link: http://lkml.kernel.org/r/20180803100758.GA28475@linux.ibm.com
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Link: http://lkml.kernel.org/r/20180802074622.13641-2-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
b96e6615 f3acd886

+150
+1
tools/perf/arch/s390/util/auxtrace.c
··· 30 30 struct auxtrace_info_event *auxtrace_info __maybe_unused, 31 31 size_t priv_size __maybe_unused) 32 32 { 33 + auxtrace_info->type = PERF_AUXTRACE_S390_CPUMSF; 33 34 return 0; 34 35 } 35 36
+1
tools/perf/util/Build
··· 87 87 libperf-$(CONFIG_AUXTRACE) += intel-bts.o 88 88 libperf-$(CONFIG_AUXTRACE) += arm-spe.o 89 89 libperf-$(CONFIG_AUXTRACE) += arm-spe-pkt-decoder.o 90 + libperf-$(CONFIG_AUXTRACE) += s390-cpumsf.o 90 91 91 92 ifdef CONFIG_LIBOPENCSD 92 93 libperf-$(CONFIG_AUXTRACE) += cs-etm.o
+3
tools/perf/util/auxtrace.c
··· 56 56 #include "intel-pt.h" 57 57 #include "intel-bts.h" 58 58 #include "arm-spe.h" 59 + #include "s390-cpumsf.h" 59 60 60 61 #include "sane_ctype.h" 61 62 #include "symbol/kallsyms.h" ··· 921 920 return arm_spe_process_auxtrace_info(event, session); 922 921 case PERF_AUXTRACE_CS_ETM: 923 922 return cs_etm__process_auxtrace_info(event, session); 923 + case PERF_AUXTRACE_S390_CPUMSF: 924 + return s390_cpumsf_process_auxtrace_info(event, session); 924 925 case PERF_AUXTRACE_UNKNOWN: 925 926 default: 926 927 return -EINVAL;
+1
tools/perf/util/auxtrace.h
··· 44 44 PERF_AUXTRACE_INTEL_BTS, 45 45 PERF_AUXTRACE_CS_ETM, 46 46 PERF_AUXTRACE_ARM_SPE, 47 + PERF_AUXTRACE_S390_CPUMSF, 47 48 }; 48 49 49 50 enum itrace_period_type {
+123
tools/perf/util/s390-cpumsf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright IBM Corp. 2018 4 + * Auxtrace support for s390 CPU-Measurement Sampling Facility 5 + * 6 + * Author(s): Thomas Richter <tmricht@linux.ibm.com> 7 + */ 8 + 9 + #include <endian.h> 10 + #include <errno.h> 11 + #include <byteswap.h> 12 + #include <inttypes.h> 13 + #include <linux/kernel.h> 14 + #include <linux/types.h> 15 + #include <linux/bitops.h> 16 + #include <linux/log2.h> 17 + 18 + #include "cpumap.h" 19 + #include "color.h" 20 + #include "evsel.h" 21 + #include "evlist.h" 22 + #include "machine.h" 23 + #include "session.h" 24 + #include "util.h" 25 + #include "thread.h" 26 + #include "debug.h" 27 + #include "auxtrace.h" 28 + #include "s390-cpumsf.h" 29 + 30 + struct s390_cpumsf { 31 + struct auxtrace auxtrace; 32 + struct auxtrace_queues queues; 33 + struct auxtrace_heap heap; 34 + struct perf_session *session; 35 + struct machine *machine; 36 + u32 auxtrace_type; 37 + u32 pmu_type; 38 + }; 39 + 40 + static int 41 + s390_cpumsf_process_event(struct perf_session *session __maybe_unused, 42 + union perf_event *event __maybe_unused, 43 + struct perf_sample *sample __maybe_unused, 44 + struct perf_tool *tool __maybe_unused) 45 + { 46 + return 0; 47 + } 48 + 49 + static int 50 + s390_cpumsf_process_auxtrace_event(struct perf_session *session __maybe_unused, 51 + union perf_event *event __maybe_unused, 52 + struct perf_tool *tool __maybe_unused) 53 + { 54 + return 0; 55 + } 56 + 57 + static int s390_cpumsf_flush(struct perf_session *session __maybe_unused, 58 + struct perf_tool *tool __maybe_unused) 59 + { 60 + return 0; 61 + } 62 + 63 + static void s390_cpumsf_free_events(struct perf_session *session) 64 + { 65 + struct s390_cpumsf *sf = container_of(session->auxtrace, 66 + struct s390_cpumsf, 67 + auxtrace); 68 + struct auxtrace_queues *queues = &sf->queues; 69 + unsigned int i; 70 + 71 + for (i = 0; i < queues->nr_queues; i++) 72 + zfree(&queues->queue_array[i].priv); 73 + auxtrace_queues__free(queues); 74 + } 75 + 76 + static void s390_cpumsf_free(struct perf_session *session) 77 + { 78 + struct s390_cpumsf *sf = container_of(session->auxtrace, 79 + struct s390_cpumsf, 80 + auxtrace); 81 + 82 + auxtrace_heap__free(&sf->heap); 83 + s390_cpumsf_free_events(session); 84 + session->auxtrace = NULL; 85 + free(sf); 86 + } 87 + 88 + int s390_cpumsf_process_auxtrace_info(union perf_event *event, 89 + struct perf_session *session) 90 + { 91 + struct auxtrace_info_event *auxtrace_info = &event->auxtrace_info; 92 + struct s390_cpumsf *sf; 93 + int err; 94 + 95 + if (auxtrace_info->header.size < sizeof(struct auxtrace_info_event)) 96 + return -EINVAL; 97 + 98 + sf = zalloc(sizeof(struct s390_cpumsf)); 99 + if (sf == NULL) 100 + return -ENOMEM; 101 + 102 + err = auxtrace_queues__init(&sf->queues); 103 + if (err) 104 + goto err_free; 105 + 106 + sf->session = session; 107 + sf->machine = &session->machines.host; /* No kvm support */ 108 + sf->auxtrace_type = auxtrace_info->type; 109 + sf->pmu_type = PERF_TYPE_RAW; 110 + 111 + sf->auxtrace.process_event = s390_cpumsf_process_event; 112 + sf->auxtrace.process_auxtrace_event = s390_cpumsf_process_auxtrace_event; 113 + sf->auxtrace.flush_events = s390_cpumsf_flush; 114 + sf->auxtrace.free_events = s390_cpumsf_free_events; 115 + sf->auxtrace.free = s390_cpumsf_free; 116 + session->auxtrace = &sf->auxtrace; 117 + 118 + return 0; 119 + 120 + err_free: 121 + free(sf); 122 + return err; 123 + }
+21
tools/perf/util/s390-cpumsf.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright IBM Corp. 2018 4 + * Auxtrace support for s390 CPU-Measurement Sampling Facility 5 + * 6 + * Author(s): Thomas Richter <tmricht@linux.ibm.com> 7 + */ 8 + 9 + #ifndef INCLUDE__PERF_S390_CPUMSF_H 10 + #define INCLUDE__PERF_S390_CPUMSF_H 11 + 12 + union perf_event; 13 + struct perf_session; 14 + struct perf_pmu; 15 + 16 + struct auxtrace_record * 17 + s390_cpumsf_recording_init(int *err, struct perf_pmu *s390_cpumsf_pmu); 18 + 19 + int s390_cpumsf_process_auxtrace_info(union perf_event *event, 20 + struct perf_session *session); 21 + #endif