Commit eaf6aaee authored by Leo Yan's avatar Leo Yan Committed by Arnaldo Carvalho de Melo

perf mem: Introduce weak function perf_mem_events__ptr()

Different architectures might use different event or different event
parameters for memory profiling, this patch introduces a weak
perf_mem_events__ptr() function which allows to return back a
architecture specific memory event.

Since the variable 'perf_mem_events' can be only accessed by the
perf_mem_events__ptr() function, mark the variable as 'static', this
allows the architectures to define its own memory event array.
Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20201106094853.21082-3-leo.yan@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f9f16dfb
...@@ -2867,6 +2867,7 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -2867,6 +2867,7 @@ static int perf_c2c__record(int argc, const char **argv)
int ret; int ret;
bool all_user = false, all_kernel = false; bool all_user = false, all_kernel = false;
bool event_set = false; bool event_set = false;
struct perf_mem_event *e;
struct option options[] = { struct option options[] = {
OPT_CALLBACK('e', "event", &event_set, "event", OPT_CALLBACK('e', "event", &event_set, "event",
"event selector. Use 'perf c2c record -e list' to list available events", "event selector. Use 'perf c2c record -e list' to list available events",
...@@ -2894,11 +2895,15 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -2894,11 +2895,15 @@ static int perf_c2c__record(int argc, const char **argv)
rec_argv[i++] = "record"; rec_argv[i++] = "record";
if (!event_set) { if (!event_set) {
perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
perf_mem_events[PERF_MEM_EVENTS__STORE].record = true; e->record = true;
e = perf_mem_events__ptr(PERF_MEM_EVENTS__STORE);
e->record = true;
} }
if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
if (e->record)
rec_argv[i++] = "-W"; rec_argv[i++] = "-W";
rec_argv[i++] = "-d"; rec_argv[i++] = "-d";
...@@ -2906,12 +2911,13 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -2906,12 +2911,13 @@ static int perf_c2c__record(int argc, const char **argv)
rec_argv[i++] = "--sample-cpu"; rec_argv[i++] = "--sample-cpu";
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
if (!perf_mem_events[j].record) e = perf_mem_events__ptr(j);
if (!e->record)
continue; continue;
if (!perf_mem_events[j].supported) { if (!e->supported) {
pr_err("failed: event '%s' not supported\n", pr_err("failed: event '%s' not supported\n",
perf_mem_events[j].name); perf_mem_events__name(j));
free(rec_argv); free(rec_argv);
return -1; return -1;
} }
......
...@@ -64,6 +64,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -64,6 +64,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
const char **rec_argv; const char **rec_argv;
int ret; int ret;
bool all_user = false, all_kernel = false; bool all_user = false, all_kernel = false;
struct perf_mem_event *e;
struct option options[] = { struct option options[] = {
OPT_CALLBACK('e', "event", &mem, "event", OPT_CALLBACK('e', "event", &mem, "event",
"event selector. use 'perf mem record -e list' to list available events", "event selector. use 'perf mem record -e list' to list available events",
...@@ -86,13 +87,18 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -86,13 +87,18 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
rec_argv[i++] = "record"; rec_argv[i++] = "record";
if (mem->operation & MEM_OPERATION_LOAD) if (mem->operation & MEM_OPERATION_LOAD) {
perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
e->record = true;
}
if (mem->operation & MEM_OPERATION_STORE) if (mem->operation & MEM_OPERATION_STORE) {
perf_mem_events[PERF_MEM_EVENTS__STORE].record = true; e = perf_mem_events__ptr(PERF_MEM_EVENTS__STORE);
e->record = true;
}
if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
if (e->record)
rec_argv[i++] = "-W"; rec_argv[i++] = "-W";
rec_argv[i++] = "-d"; rec_argv[i++] = "-d";
...@@ -101,10 +107,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -101,10 +107,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
rec_argv[i++] = "--phys-data"; rec_argv[i++] = "--phys-data";
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
if (!perf_mem_events[j].record) e = perf_mem_events__ptr(j);
if (!e->record)
continue; continue;
if (!perf_mem_events[j].supported) { if (!e->supported) {
pr_err("failed: event '%s' not supported\n", pr_err("failed: event '%s' not supported\n",
perf_mem_events__name(j)); perf_mem_events__name(j));
free(rec_argv); free(rec_argv);
......
...@@ -17,7 +17,7 @@ unsigned int perf_mem_events__loads_ldlat = 30; ...@@ -17,7 +17,7 @@ unsigned int perf_mem_events__loads_ldlat = 30;
#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s } #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = { static struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
E("ldlat-loads", "cpu/mem-loads,ldlat=%u/P", "cpu/events/mem-loads"), E("ldlat-loads", "cpu/mem-loads,ldlat=%u/P", "cpu/events/mem-loads"),
E("ldlat-stores", "cpu/mem-stores/P", "cpu/events/mem-stores"), E("ldlat-stores", "cpu/mem-stores/P", "cpu/events/mem-stores"),
}; };
...@@ -28,19 +28,31 @@ struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = { ...@@ -28,19 +28,31 @@ struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
static char mem_loads_name[100]; static char mem_loads_name[100];
static bool mem_loads_name__init; static bool mem_loads_name__init;
struct perf_mem_event * __weak perf_mem_events__ptr(int i)
{
if (i >= PERF_MEM_EVENTS__MAX)
return NULL;
return &perf_mem_events[i];
}
char * __weak perf_mem_events__name(int i) char * __weak perf_mem_events__name(int i)
{ {
struct perf_mem_event *e = perf_mem_events__ptr(i);
if (!e)
return NULL;
if (i == PERF_MEM_EVENTS__LOAD) { if (i == PERF_MEM_EVENTS__LOAD) {
if (!mem_loads_name__init) { if (!mem_loads_name__init) {
mem_loads_name__init = true; mem_loads_name__init = true;
scnprintf(mem_loads_name, sizeof(mem_loads_name), scnprintf(mem_loads_name, sizeof(mem_loads_name),
perf_mem_events[i].name, e->name, perf_mem_events__loads_ldlat);
perf_mem_events__loads_ldlat);
} }
return mem_loads_name; return mem_loads_name;
} }
return (char *)perf_mem_events[i].name; return (char *)e->name;
} }
int perf_mem_events__parse(const char *str) int perf_mem_events__parse(const char *str)
...@@ -61,7 +73,7 @@ int perf_mem_events__parse(const char *str) ...@@ -61,7 +73,7 @@ int perf_mem_events__parse(const char *str)
while (tok) { while (tok) {
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
struct perf_mem_event *e = &perf_mem_events[j]; struct perf_mem_event *e = perf_mem_events__ptr(j);
if (strstr(e->tag, tok)) if (strstr(e->tag, tok))
e->record = found = true; e->record = found = true;
...@@ -90,7 +102,7 @@ int perf_mem_events__init(void) ...@@ -90,7 +102,7 @@ int perf_mem_events__init(void)
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
char path[PATH_MAX]; char path[PATH_MAX];
struct perf_mem_event *e = &perf_mem_events[j]; struct perf_mem_event *e = perf_mem_events__ptr(j);
struct stat st; struct stat st;
scnprintf(path, PATH_MAX, "%s/devices/%s", scnprintf(path, PATH_MAX, "%s/devices/%s",
...@@ -108,7 +120,7 @@ void perf_mem_events__list(void) ...@@ -108,7 +120,7 @@ void perf_mem_events__list(void)
int j; int j;
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
struct perf_mem_event *e = &perf_mem_events[j]; struct perf_mem_event *e = perf_mem_events__ptr(j);
fprintf(stderr, "%-13s%-*s%s\n", fprintf(stderr, "%-13s%-*s%s\n",
e->tag, e->tag,
......
...@@ -31,13 +31,13 @@ enum { ...@@ -31,13 +31,13 @@ enum {
PERF_MEM_EVENTS__MAX, PERF_MEM_EVENTS__MAX,
}; };
extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
extern unsigned int perf_mem_events__loads_ldlat; extern unsigned int perf_mem_events__loads_ldlat;
int perf_mem_events__parse(const char *str); int perf_mem_events__parse(const char *str);
int perf_mem_events__init(void); int perf_mem_events__init(void);
char *perf_mem_events__name(int i); char *perf_mem_events__name(int i);
struct perf_mem_event *perf_mem_events__ptr(int i);
void perf_mem_events__list(void); void perf_mem_events__list(void);
......
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