linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Thomas Richter <tmricht@linux.ibm.com>,
	Hendrik Brueckner <brueckner@linux.ibm.com>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/24] perf report: Display names in s390 diagnostic counter sets
Date: Mon, 21 Jan 2019 20:56:53 -0300	[thread overview]
Message-ID: <20190121235706.20005-12-acme@kernel.org> (raw)
In-Reply-To: <20190121235706.20005-1-acme@kernel.org>

From: Thomas Richter <tmricht@linux.ibm.com>

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>
---
 tools/perf/util/s390-sample-raw.c | 59 ++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c
index 7b4879625f01..14db2da855b7 100644
--- a/tools/perf/util/s390-sample-raw.c
+++ b/tools/perf/util/s390-sample-raw.c
@@ -29,6 +29,7 @@
 #include "color.h"
 #include "sample-raw.h"
 #include "s390-cpumcf-kernel.h"
+#include "pmu-events/pmu-events.h"
 
 static size_t ctrset_size(struct cf_ctrset_entry *set)
 {
@@ -112,14 +113,61 @@ static void s390_cpumcfdg_dumptrail(const char *color, size_t offset,
 		      te.tod_base, te.mach_type);
 }
 
+/* Return starting number of a counter set */
+static int get_counterset_start(int setnr)
+{
+	switch (setnr) {
+	case CPUMF_CTR_SET_BASIC:		/* Basic counter set */
+		return 0;
+	case CPUMF_CTR_SET_USER:		/* Problem state counter set */
+		return 32;
+	case CPUMF_CTR_SET_CRYPTO:		/* Crypto counter set */
+		return 64;
+	case CPUMF_CTR_SET_EXT:			/* Extended counter set */
+		return 128;
+	case CPUMF_CTR_SET_MT_DIAG:		/* Diagnostic counter set */
+		return 448;
+	default:
+		return -1;
+	}
+}
+
+/* Scan the PMU table and extract the logical name of a counter from the
+ * PMU events table. Input is the counter set and counter number with in the
+ * set. Construct the event number and use this as key. If they match return
+ * the name of this counter.
+ * If no match is found a NULL pointer is returned.
+ */
+static const char *get_counter_name(int set, int nr, struct pmu_events_map *map)
+{
+	int rc, event_nr, wanted = get_counterset_start(set) + nr;
+
+	if (map) {
+		struct pmu_event *evp = map->table;
+
+		for (; evp->name || evp->event || evp->desc; ++evp) {
+			if (evp->name == NULL || evp->event == NULL)
+				continue;
+			rc = sscanf(evp->event, "event=%x", &event_nr);
+			if (rc == 1 && event_nr == wanted)
+				return evp->name;
+		}
+	}
+	return NULL;
+}
+
 static void s390_cpumcfdg_dump(struct perf_sample *sample)
 {
 	size_t i, len = sample->raw_size, offset = 0;
 	unsigned char *buf = sample->raw_data;
 	const char *color = PERF_COLOR_BLUE;
 	struct cf_ctrset_entry *cep, ce;
+	struct pmu_events_map *map;
+	struct perf_pmu pmu;
 	u64 *p;
 
+	memset(&pmu, 0, sizeof(pmu));
+	map = perf_pmu__find_map(&pmu);
 	while (offset < len) {
 		cep = (struct cf_ctrset_entry *)(buf + offset);
 
@@ -136,12 +184,13 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
 
 		color_fprintf(stdout, color, "    [%#08zx] Counterset:%d"
 			      " Counters:%d\n", offset, ce.set, ce.ctr);
-		for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; i += 2, p += 2)
+		for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) {
+			const char *ev_name = get_counter_name(ce.set, i, map);
+
 			color_fprintf(stdout, color,
-				      "\tCounter:%03d Value:%#018lx"
-				      " Counter:%03d Value:%#018lx\n",
-				      i, be64_to_cpu(*p),
-				      i + 1, be64_to_cpu(*(p + 1)));
+				      "\tCounter:%03d %s Value:%#018lx\n", i,
+				      ev_name ?: "<unknown>", be64_to_cpu(*p));
+		}
 		offset += ctrset_size(&ce);
 	}
 }
-- 
2.20.1


  parent reply	other threads:[~2019-01-21 23:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-21 23:56 [GIT PULL 00/24] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 01/24] perf tools: Replace automatic const char[] variables by statics Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 02/24] perf session: Rearrange perf_session__process_events function Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 03/24] perf session: Get rid of file_size variable Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 04/24] perf session: Add reader object Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 05/24] perf session: Add 'data_size' member to " Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 06/24] perf session: Add 'data_offset' " Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 07/24] perf session: Add reader__process_events function Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 08/24] perf: Remove duplicated workqueue.h include from perf_event.h Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 09/24] perf tools: Remove duplicate headers Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 10/24] perf report: Display arch specific diagnostic counter sets, starting with s390 Arnaldo Carvalho de Melo
2019-01-21 23:56 ` Arnaldo Carvalho de Melo [this message]
2019-01-21 23:56 ` [PATCH 12/24] perf report: Dump s390 counter set data to file Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 13/24] perf: Make perf_event_output() propagate the output() return Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 14/24] perf, bpf: Introduce PERF_RECORD_KSYMBOL Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 15/24] tools headers uapi: Sync tools/include/uapi/linux/perf_event.h Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 16/24] perf, bpf: Introduce PERF_RECORD_BPF_EVENT Arnaldo Carvalho de Melo
2019-01-21 23:56 ` [PATCH 17/24] tools headers uapi: Sync tools/include/uapi/linux/perf_event.h Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 18/24] perf tools: Handle PERF_RECORD_KSYMBOL Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 19/24] perf tools: Handle PERF_RECORD_BPF_EVENT Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 20/24] perf tools: Synthesize PERF_RECORD_* for loaded BPF programs Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 21/24] perf top: Synthesize BPF events for pre-existing " Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 22/24] bpf: Add module name [bpf] to ksymbols for bpf programs Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 23/24] perf python: Remove -fstack-clash-protection when building with some clang versions Arnaldo Carvalho de Melo
2019-01-21 23:57 ` [PATCH 24/24] perf utils: Move perf_config using routines from color.c to separate object Arnaldo Carvalho de Melo
2019-01-22 10:07 ` [GIT PULL 00/24] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190121235706.20005-12-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=brueckner@linux.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=tmricht@linux.ibm.com \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).