]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf mem: Fix missed p-core mem events on ADL and RPL
authorKan Liang <kan.liang@linux.intel.com>
Thu, 5 Sep 2024 17:07:36 +0000 (10:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:33:01 +0000 (16:33 +0200)
[ Upstream commit 5ad7db2c3f941cde3045ce38a9c4c40b0c7d56b9 ]

The p-core mem events are missed when launching 'perf mem record' on ADL
and RPL.

  root@number:~# perf mem record sleep 1
  Memory events are enabled on a subset of CPUs: 16-27
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.032 MB perf.data ]
  root@number:~# perf evlist
  cpu_atom/mem-loads,ldlat=30/P
  cpu_atom/mem-stores/P
  dummy:u

A variable 'record' in the 'struct perf_mem_event' is to indicate
whether a mem event in a mem_events[] should be recorded. The current
code only configure the variable for the first eligible PMU.

It's good enough for a non-hybrid machine or a hybrid machine which has
the same mem_events[].

However, if a different mem_events[] is used for different PMUs on a
hybrid machine, e.g., ADL or RPL, the 'record' for the second PMU never
get a chance to be set.

The mem_events[] of the second PMU are always ignored.

'perf mem' doesn't support the per-PMU configuration now. A per-PMU
mem_events[] 'record' variable doesn't make sense. Make it global.

That could also avoid searching for the per-PMU mem_events[] via
perf_pmu__mem_events_ptr every time.

Committer testing:

  root@number:~# perf evlist -g
  cpu_atom/mem-loads,ldlat=30/P
  cpu_atom/mem-stores/P
  {cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}
  cpu_core/mem-stores/P
  dummy:u
  root@number:~#

The :S for '{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}' is
not being added by 'perf evlist -g', to be checked.

Fixes: abbdd79b786e036e ("perf mem: Clean up perf_mem_events__name()")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/lkml/Zthu81fA3kLC2CS2@x1/
Link: https://lore.kernel.org/r/20240905170737.4070743-2-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/perf/builtin-c2c.c
tools/perf/builtin-mem.c
tools/perf/util/mem-events.c
tools/perf/util/mem-events.h

index 0b2cb59212938f99b2db3e8c7b2f3ad948e8559b..7298f360706220ad8d0ed93bd5b2f2569ce1342b 100644 (file)
@@ -3290,19 +3290,15 @@ static int perf_c2c__record(int argc, const char **argv)
                 * PERF_MEM_EVENTS__LOAD_STORE if it is supported.
                 */
                if (e->tag) {
-                       e->record = true;
+                       perf_mem_record[PERF_MEM_EVENTS__LOAD_STORE] = true;
                        rec_argv[i++] = "-W";
                } else {
-                       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD);
-                       e->record = true;
-
-                       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__STORE);
-                       e->record = true;
+                       perf_mem_record[PERF_MEM_EVENTS__LOAD] = true;
+                       perf_mem_record[PERF_MEM_EVENTS__STORE] = true;
                }
        }
 
-       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD);
-       if (e->record)
+       if (perf_mem_record[PERF_MEM_EVENTS__LOAD])
                rec_argv[i++] = "-W";
 
        rec_argv[i++] = "-d";
index 7fdbaaed14af2cc5325038de7bd25eb4274cbb44..08724fa508e14c1b176fd2c7a3890a50a497e020 100644 (file)
@@ -126,22 +126,17 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
        if (e->tag &&
            (mem->operation & MEM_OPERATION_LOAD) &&
            (mem->operation & MEM_OPERATION_STORE)) {
-               e->record = true;
+               perf_mem_record[PERF_MEM_EVENTS__LOAD_STORE] = true;
                rec_argv[i++] = "-W";
        } else {
-               if (mem->operation & MEM_OPERATION_LOAD) {
-                       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD);
-                       e->record = true;
-               }
+               if (mem->operation & MEM_OPERATION_LOAD)
+                       perf_mem_record[PERF_MEM_EVENTS__LOAD] = true;
 
-               if (mem->operation & MEM_OPERATION_STORE) {
-                       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__STORE);
-                       e->record = true;
-               }
+               if (mem->operation & MEM_OPERATION_STORE)
+                       perf_mem_record[PERF_MEM_EVENTS__STORE] = true;
        }
 
-       e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD);
-       if (e->record)
+       if (perf_mem_record[PERF_MEM_EVENTS__LOAD])
                rec_argv[i++] = "-W";
 
        rec_argv[i++] = "-d";
index c844aca0726ceb7f515ccfbf62bca3d1aea729fd..1f1e1063efe3786a542568b8d6f0956fdaab5281 100644 (file)
@@ -28,6 +28,8 @@ struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
 };
 #undef E
 
+bool perf_mem_record[PERF_MEM_EVENTS__MAX] = { 0 };
+
 static char mem_loads_name[100];
 static char mem_stores_name[100];
 
@@ -162,7 +164,7 @@ int perf_pmu__mem_events_parse(struct perf_pmu *pmu, const char *str)
                                continue;
 
                        if (strstr(e->tag, tok))
-                               e->record = found = true;
+                               perf_mem_record[j] = found = true;
                }
 
                tok = strtok_r(NULL, ",", &saveptr);
@@ -259,7 +261,7 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr)
                for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
                        e = perf_pmu__mem_events_ptr(pmu, j);
 
-                       if (!e->record)
+                       if (!perf_mem_record[j])
                                continue;
 
                        if (!e->supported) {
index a6fc2a593938820ca503e0ebde1626344c788519..8dc27db9fd52f48ac925730e554199efd371b569 100644 (file)
@@ -6,7 +6,6 @@
 #include <linux/types.h>
 
 struct perf_mem_event {
-       bool            record;
        bool            supported;
        bool            ldlat;
        u32             aux_event;
@@ -28,6 +27,7 @@ struct perf_pmu;
 
 extern unsigned int perf_mem_events__loads_ldlat;
 extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
+extern bool perf_mem_record[PERF_MEM_EVENTS__MAX];
 
 int perf_pmu__mem_events_parse(struct perf_pmu *pmu, const char *str);
 int perf_pmu__mem_events_init(void);