Commit c4ac7f75 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf s390 s390_cpumcfdg_dump: Don't scan all PMUs

Rather than scanning all PMUs for a counter name, scan the PMU
associated with the evsel of the sample. This is done to remove a
dependence on pmu-events.h.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9d31cb93
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "color.h" #include "color.h"
#include "sample-raw.h" #include "sample-raw.h"
#include "s390-cpumcf-kernel.h" #include "s390-cpumcf-kernel.h"
#include "pmu-events/pmu-events.h" #include "util/pmu.h"
#include "util/sample.h" #include "util/sample.h"
static size_t ctrset_size(struct cf_ctrset_entry *set) static size_t ctrset_size(struct cf_ctrset_entry *set)
...@@ -132,56 +132,57 @@ static int get_counterset_start(int setnr) ...@@ -132,56 +132,57 @@ static int get_counterset_start(int setnr)
struct get_counter_name_data { struct get_counter_name_data {
int wanted; int wanted;
const char *result; char *result;
}; };
static int get_counter_name_callback(const struct pmu_event *evp, static int get_counter_name_callback(void *vdata, struct pmu_event_info *info)
const struct pmu_events_table *table __maybe_unused,
void *vdata)
{ {
struct get_counter_name_data *data = vdata; struct get_counter_name_data *data = vdata;
int rc, event_nr; int rc, event_nr;
const char *event_str;
if (evp->name == NULL || evp->event == NULL) if (info->str == NULL)
return 0; return 0;
rc = sscanf(evp->event, "event=%x", &event_nr);
event_str = strstr(info->str, "event=");
if (!event_str)
return 0;
rc = sscanf(event_str, "event=%x", &event_nr);
if (rc == 1 && event_nr == data->wanted) { if (rc == 1 && event_nr == data->wanted) {
data->result = evp->name; data->result = strdup(info->name);
return 1; /* Terminate the search. */ return 1; /* Terminate the search. */
} }
return 0; return 0;
} }
/* Scan the PMU table and extract the logical name of a counter from the /* Scan the PMU and extract the logical name of a counter from the event. Input
* PMU events table. Input is the counter set and counter number with in the * is the counter set and counter number with in the set. Construct the event
* set. Construct the event number and use this as key. If they match return * number and use this as key. If they match return the name of this counter.
* the name of this counter.
* If no match is found a NULL pointer is returned. * If no match is found a NULL pointer is returned.
*/ */
static const char *get_counter_name(int set, int nr, const struct pmu_events_table *table) static char *get_counter_name(int set, int nr, struct perf_pmu *pmu)
{ {
struct get_counter_name_data data = { struct get_counter_name_data data = {
.wanted = get_counterset_start(set) + nr, .wanted = get_counterset_start(set) + nr,
.result = NULL, .result = NULL,
}; };
if (!table) if (!pmu)
return NULL; return NULL;
pmu_events_table__for_each_event(table, get_counter_name_callback, &data); perf_pmu__for_each_event(pmu, &data, get_counter_name_callback);
return data.result; return data.result;
} }
static void s390_cpumcfdg_dump(struct perf_sample *sample) static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample)
{ {
size_t i, len = sample->raw_size, offset = 0; size_t i, len = sample->raw_size, offset = 0;
unsigned char *buf = sample->raw_data; unsigned char *buf = sample->raw_data;
const char *color = PERF_COLOR_BLUE; const char *color = PERF_COLOR_BLUE;
struct cf_ctrset_entry *cep, ce; struct cf_ctrset_entry *cep, ce;
const struct pmu_events_table *table;
u64 *p; u64 *p;
table = pmu_events_table__find();
while (offset < len) { while (offset < len) {
cep = (struct cf_ctrset_entry *)(buf + offset); cep = (struct cf_ctrset_entry *)(buf + offset);
...@@ -199,11 +200,12 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) ...@@ -199,11 +200,12 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
color_fprintf(stdout, color, " [%#08zx] Counterset:%d" color_fprintf(stdout, color, " [%#08zx] Counterset:%d"
" Counters:%d\n", offset, ce.set, ce.ctr); " Counters:%d\n", offset, ce.set, ce.ctr);
for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) { for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) {
const char *ev_name = get_counter_name(ce.set, i, table); char *ev_name = get_counter_name(ce.set, i, pmu);
color_fprintf(stdout, color, color_fprintf(stdout, color,
"\tCounter:%03d %s Value:%#018lx\n", i, "\tCounter:%03d %s Value:%#018lx\n", i,
ev_name ?: "<unknown>", be64_to_cpu(*p)); ev_name ?: "<unknown>", be64_to_cpu(*p));
free(ev_name);
} }
offset += ctrset_size(&ce); offset += ctrset_size(&ce);
} }
...@@ -216,14 +218,14 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) ...@@ -216,14 +218,14 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
*/ */
void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample)
{ {
struct evsel *ev_bc000; struct evsel *evsel;
if (event->header.type != PERF_RECORD_SAMPLE) if (event->header.type != PERF_RECORD_SAMPLE)
return; return;
ev_bc000 = evlist__event2evsel(evlist, event); evsel = evlist__event2evsel(evlist, event);
if (ev_bc000 == NULL || if (evsel == NULL ||
ev_bc000->core.attr.config != PERF_EVENT_CPUM_CF_DIAG) evsel->core.attr.config != PERF_EVENT_CPUM_CF_DIAG)
return; return;
/* Display raw data on screen */ /* Display raw data on screen */
...@@ -231,5 +233,5 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, str ...@@ -231,5 +233,5 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, str
pr_err("Invalid counter set data encountered\n"); pr_err("Invalid counter set data encountered\n");
return; return;
} }
s390_cpumcfdg_dump(sample); s390_cpumcfdg_dump(evsel->pmu, sample);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment