From: Robert Richter <robert.richter@amd.com>
To: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@elte.hu>,
Stephane Eranian <eranian@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Robert Richter <robert.richter@amd.com>
Subject: [PATCH 2/4] perf tools: Add pmu mappings to header information
Date: Thu, 15 Dec 2011 18:23:42 +0100 [thread overview]
Message-ID: <1323969824-9711-3-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1323969824-9711-1-git-send-email-robert.richter@amd.com>
With dynamic pmu allocation there are also dynamically assigned pmu
ids. These ids are used in event->attr.type to describe the pmu to be
used for that event. The information is available in sysfs, e.g:
/sys/bus/event_source/devices/breakpoint/type: 5
/sys/bus/event_source/devices/cpu/type: 4
/sys/bus/event_source/devices/ibs_fetch/type: 6
/sys/bus/event_source/devices/ibs_op/type: 7
/sys/bus/event_source/devices/software/type: 1
/sys/bus/event_source/devices/tracepoint/type: 2
These mappings are needed to know which samples belong to which pmu.
If a pmu is added dynamically like for ibs_fetch or ibs_op the type
value may vary.
Now, when decoding samples from perf.data this information in sysfs
might be no longer available or may have changed. We need to store it
in perf.data. Using the header for this. The header information
created with perf report would contain an additional section looking
like this:
# pmu mappings: ibs_op = 7, ibs_fetch = 6, cpu = 4, breakpoint = 5, tracepoint = 2, software = 1
Signed-off-by: Robert Richter <robert.richter@amd.com>
---
| 99 ++++++++++++++++++++++++++++++++++++++++++++++
| 1 +
2 files changed, 100 insertions(+), 0 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1e38c10..52dd7b4 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -988,6 +988,73 @@ done:
return ret;
}
+#define EVENT_SOURCE_DEVICE_PATH "/sys/bus/event_source/devices/"
+
+/*
+ * File format:
+ *
+ * struct pmu_mappings {
+ * u32 pmu_num;
+ * struct pmu_map {
+ * u32 type;
+ * char name[];
+ * }[pmu_num];
+ * };
+ */
+
+static int write_pmu_mappings(int fd, struct perf_header *h __used,
+ struct perf_evlist *evlist __used)
+{
+ char path[MAXPATHLEN];
+ DIR *dir;
+ struct dirent *dent;
+ FILE *fp;
+ char *line = NULL;
+ off_t offset = lseek(fd, 0, SEEK_CUR);
+ size_t ignore;
+ u32 pmu_num = 0;
+ u32 type;
+
+ dir = opendir(EVENT_SOURCE_DEVICE_PATH);
+ if (!dir)
+ return -1;
+
+ /* write real pmu_num later */
+ do_write(fd, &pmu_num, sizeof(pmu_num));
+
+ while ((dent = readdir(dir))) {
+ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
+ continue;
+ snprintf(path, sizeof(path), "%s%s/type",
+ EVENT_SOURCE_DEVICE_PATH, dent->d_name);
+ fp = fopen(path, "r");
+ if (!fp)
+ continue;
+ if (getline(&line, &ignore, fp) < 0) {
+ fclose(fp);
+ continue;
+ }
+ fclose(fp);
+ type = atoi(line);
+ if (!type)
+ continue;
+ pmu_num++;
+ do_write(fd, &type, sizeof(type));
+ do_write_string(fd, dent->d_name);
+ }
+
+ free(line);
+ closedir(dir);
+
+ if (pwrite(fd, &pmu_num, sizeof(pmu_num), offset) != sizeof(pmu_num)) {
+ /* discard all */
+ lseek(fd, offset, SEEK_SET);
+ return -1;
+ }
+
+ return 0;
+}
+
/*
* default get_cpuid(): nothing gets recorded
* actual implementation must be in arch/$(ARCH)/util/header.c
@@ -1305,6 +1372,37 @@ static void print_cpuid(struct perf_header *ph, int fd, FILE *fp)
free(str);
}
+static void print_pmu_mappings(struct perf_header *ph, int fd, FILE *fp)
+{
+ const char *delimiter = "# pmu mappings: ";
+ char *name;
+ int ret;
+ u32 pmu_num;
+ u32 type;
+
+ ret = read(fd, &pmu_num, sizeof(pmu_num));
+ if (ret != sizeof(pmu_num))
+ goto error;
+
+ if (!pmu_num)
+ goto error;
+
+ while (pmu_num--) {
+ if (read(fd, &type, sizeof(type)) != sizeof(type))
+ goto error;
+ name = do_read_string(fd, ph);
+ fprintf(fp, "%s%s = %" PRIu32, delimiter, name, type);
+ free(name);
+ delimiter = ", ";
+ }
+
+ fprintf(fp, "\n");
+
+ return;
+error:
+ fprintf(fp, "# pmu mappings: not available\n");
+}
+
static int __event_process_build_id(struct build_id_event *bev,
char *filename,
struct perf_session *session)
@@ -1509,6 +1607,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPA(HEADER_CMDLINE, cmdline),
FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology),
FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology),
+ FEAT_OPA(HEADER_PMU_MAPPINGS, pmu_mappings),
};
struct header_print_data {
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index e68f617..9b4d407 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -27,6 +27,7 @@ enum {
HEADER_EVENT_DESC,
HEADER_CPU_TOPOLOGY,
HEADER_NUMA_TOPOLOGY,
+ HEADER_PMU_MAPPINGS,
HEADER_LAST_FEATURE,
HEADER_FEAT_BITS = 256,
--
1.7.7
next prev parent reply other threads:[~2011-12-15 17:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 17:23 [PATCH 0/4] perf tools: Add support for IBS Robert Richter
2011-12-15 17:23 ` [PATCH 1/4] perf tool: Parse general/raw events from sysfs Robert Richter
2011-12-21 16:52 ` Robert Richter
2012-01-02 11:07 ` Stephane Eranian
2011-12-15 17:23 ` Robert Richter [this message]
2011-12-15 17:23 ` [PATCH 3/4] perf script: Add generic perl handler to process events Robert Richter
2011-12-29 20:56 ` [tip:perf/core] " tip-bot for Robert Richter
2011-12-15 17:23 ` [PATCH 4/4] perf script: Add script to collect and display IBS samples Robert Richter
2011-12-15 19:19 ` David Ahern
2011-12-15 23:47 ` Robert Richter
2011-12-23 10:33 ` Ingo Molnar
2011-12-23 11:19 ` Robert Richter
2011-12-23 13:53 ` Ingo Molnar
2011-12-23 14:14 ` Peter Zijlstra
2011-12-23 14:40 ` Ingo Molnar
2011-12-23 16:17 ` Robert Richter
2011-12-23 16:39 ` Ingo Molnar
2011-12-23 16:50 ` Robert Richter
2011-12-30 9:55 ` Ingo Molnar
2012-02-02 11:21 ` Robert Richter
2012-03-08 12:19 ` Ingo Molnar
2012-03-09 11:41 ` Robert Richter
2012-03-21 18:13 ` Robert Richter
2012-03-22 7:51 ` 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=1323969824-9711-3-git-send-email-robert.richter@amd.com \
--to=robert.richter@amd.com \
--cc=acme@redhat.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
/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
Powered by JetHome