]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf evlist: Change env variable to session
authorIan Rogers <irogers@google.com>
Thu, 24 Jul 2025 16:32:50 +0000 (09:32 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 25 Jul 2025 17:37:56 +0000 (10:37 -0700)
The session holds a perf_env pointer env. In UI code container_of is
used to turn the env to a session, but this assumes the session
header's env is in use. Rather than a dubious container_of, hold the
session in the evlist and derive the env from the session with
evsel__env, perf_session__env, etc.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-11-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
17 files changed:
tools/perf/builtin-report.c
tools/perf/builtin-script.c
tools/perf/builtin-top.c
tools/perf/tests/topology.c
tools/perf/ui/browser.h
tools/perf/ui/browsers/header.c
tools/perf/ui/browsers/hists.c
tools/perf/util/amd-sample-raw.c
tools/perf/util/arm-spe.c
tools/perf/util/evlist.h
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/header.c
tools/perf/util/s390-cpumsf.c
tools/perf/util/sample-raw.c
tools/perf/util/sample-raw.h
tools/perf/util/session.c

index 704576e46e4bfadbbca987ad882bd3367d92a695..ada8e0166c781010089f721401d91b9d2325b8c9 100644 (file)
@@ -1274,6 +1274,8 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,
                        union perf_event *event,
                        struct evlist **pevlist)
 {
+       struct perf_session *session;
+       struct perf_env *env;
        u64 sample_type;
        int err;
 
@@ -1286,7 +1288,9 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,
         * on events sample_type.
         */
        sample_type = evlist__combined_sample_type(*pevlist);
-       callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
+       session = (*pevlist)->session;
+       env = perf_session__env(session);
+       callchain_param_setup(sample_type, perf_env__arch(env));
        return 0;
 }
 
index 31cce67217b02f0e9bd38642ec20bdc36975f85a..f2b5620165b4246b6004bffb6e2b214ff4bf3602 100644 (file)
@@ -2534,7 +2534,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,
         * on events sample_type.
         */
        sample_type = evlist__combined_sample_type(evlist);
-       callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
+       callchain_param_setup(sample_type, perf_env__arch(perf_session__env(scr->session)));
 
        /* Enable fields for callchain entries */
        if (symbol_conf.use_callchain &&
index 87d5742b7eb71a97f7f13ca741a49060acfb33dc..2760971d4c97c275aaf6f23f8297d346c9b43f6f 100644 (file)
@@ -1654,7 +1654,6 @@ int cmd_top(int argc, const char **argv)
                        "Couldn't read the cpuid for this machine: %s\n",
                        str_error_r(errno, errbuf, sizeof(errbuf)));
        }
-       top.evlist->env = &perf_env;
 
        argc = parse_options(argc, argv, options, top_usage, 0);
        if (argc)
@@ -1830,6 +1829,7 @@ int cmd_top(int argc, const char **argv)
                perf_top__update_print_entries(&top);
                signal(SIGWINCH, winch_sig);
        }
+       top.session->env = &perf_env;
 
        top.session = perf_session__new(NULL, NULL);
        if (IS_ERR(top.session)) {
index bc7d10630dadd83ed632eb8c5d30a8e31e5a70a1..ec01150d208de798c565a6fd4156aec72b54c5b1 100644 (file)
@@ -43,6 +43,7 @@ static int session_write_header(char *path)
 
        session->evlist = evlist__new_default();
        TEST_ASSERT_VAL("can't get evlist", session->evlist);
+       session->evlist->session = session;
 
        perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
        perf_header__set_feat(&session->header, HEADER_NRCPUS);
index f59ad4f14d33a4213fd6b95680ee140de840f477..9d4404f9b87fcdc4925d9ac616ad7d1903f1be31 100644 (file)
@@ -71,8 +71,8 @@ int ui_browser__help_window(struct ui_browser *browser, const char *text);
 bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
 int ui_browser__input_window(const char *title, const char *text, char *input,
                             const char *exit_msg, int delay_sec);
-struct perf_env;
-int tui__header_window(struct perf_env *env);
+struct perf_session;
+int tui__header_window(struct perf_session *session);
 
 void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
 unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
index 2213b46616002a04a0d47d7192e129e301d7fa29..5b5ca32e3eef9d616a403e312b3e79f787c6214a 100644 (file)
@@ -93,16 +93,14 @@ static int ui__list_menu(int argc, char * const argv[])
        return list_menu__run(&menu);
 }
 
-int tui__header_window(struct perf_env *env)
+int tui__header_window(struct perf_session *session)
 {
        int i, argc = 0;
        char **argv;
-       struct perf_session *session;
        char *ptr, *pos;
        size_t size;
        FILE *fp = open_memstream(&ptr, &size);
 
-       session = container_of(env, struct perf_session, header.env);
        perf_header__fprintf_info(session, fp, true);
        fclose(fp);
 
index d26b925e3d7f46afad89b08ebb38a6cae34e9479..d9d3fb44477ac6d5d7108a663f21bab760c01613 100644 (file)
@@ -3233,7 +3233,7 @@ do_hotkey:                 // key came straight from options ui__popup_menu()
                case 'i':
                        /* env->arch is NULL for live-mode (i.e. perf top) */
                        if (env->arch)
-                               tui__header_window(env);
+                               tui__header_window(evsel__session(evsel));
                        continue;
                case 'F':
                        symbol_conf.filter_relative ^= 1;
index 4b540e6fb42d30dc5fc14a7104636aab0cd58127..b084dee76b1a758ed66ea0d3321916c86dfc57fd 100644 (file)
@@ -354,7 +354,7 @@ static void parse_cpuid(struct perf_env *env)
  */
 bool evlist__has_amd_ibs(struct evlist *evlist)
 {
-       struct perf_env *env = evlist->env;
+       struct perf_env *env = perf_session__env(evlist->session);
        int ret, nr_pmu_mappings = perf_env__nr_pmu_mappings(env);
        const char *pmu_mapping = perf_env__pmu_mappings(env);
        char name[sizeof("ibs_fetch")];
index d46e0cccac99a36148b4daa37f2bf2342e6b47ef..8942fa598a84fb70f8c66649395bfbedcd42d380 100644 (file)
@@ -856,7 +856,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
                const char *cpuid;
 
                pr_warning_once("Old SPE metadata, re-record to improve decode accuracy\n");
-               cpuid = perf_env__cpuid(spe->session->evlist->env);
+               cpuid = perf_env__cpuid(perf_session__env(spe->session));
                midr = strtol(cpuid, NULL, 16);
        } else {
                /* CPU ID is -1 for per-thread mode */
index 1472d2179be18b207d89ea77c5fb7b2b13058b03..5e71e3dc604230797933fdbc356d623525a894e8 100644 (file)
@@ -71,7 +71,7 @@ struct evlist {
        struct mmap *overwrite_mmap;
        struct evsel *selected;
        struct events_stats stats;
-       struct perf_env *env;
+       struct perf_session *session;
        void (*trace_event_sample_raw)(struct evlist *evlist,
                                       union perf_event *event,
                                       struct perf_sample *sample);
index ae11df1e79020b6076bf719153f8e879af741abf..3f766f240cc7f9181aa4aedbfcf782862d835e98 100644 (file)
@@ -48,6 +48,7 @@
 #include "record.h"
 #include "debug.h"
 #include "trace-event.h"
+#include "session.h"
 #include "stat.h"
 #include "string2.h"
 #include "memswap.h"
@@ -3872,11 +3873,16 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
                         err, str_error_r(err, sbuf, sizeof(sbuf)), evsel__name(evsel));
 }
 
+struct perf_session *evsel__session(struct evsel *evsel)
+{
+       return evsel && evsel->evlist ? evsel->evlist->session : NULL;
+}
+
 struct perf_env *evsel__env(struct evsel *evsel)
 {
-       if (evsel && evsel->evlist && evsel->evlist->env)
-               return evsel->evlist->env;
-       return &perf_env;
+       struct perf_session *session = evsel__session(evsel);
+
+       return session ? perf_session__env(session) : &perf_env;
 }
 
 static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
index 8e79eb6d41b3de1325b1848468d8f6a208c0b0b1..5797a02e5d6a9e0691896ba2b6f7e3267c42b042 100644 (file)
@@ -542,6 +542,7 @@ static inline bool evsel__is_dummy_event(struct evsel *evsel)
               (evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
 }
 
+struct perf_session *evsel__session(struct evsel *evsel);
 struct perf_env *evsel__env(struct evsel *evsel);
 
 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
index 4f8133a183126330fab2bfa7118cd06fc209d741..ce0fe7879ab073e8b518eae16da13264255d0b66 100644 (file)
@@ -4225,7 +4225,7 @@ int perf_session__read_header(struct perf_session *session)
        if (session->evlist == NULL)
                return -ENOMEM;
 
-       session->evlist->env = &header->env;
+       session->evlist->session = session;
        session->machines.host.env = &header->env;
 
        /*
index 0ce52f0280b8349f398f20c35e321997d85da7a2..c17dbe232c54e1052562d2a7528bb800c51316b9 100644 (file)
@@ -1142,7 +1142,7 @@ int s390_cpumsf_process_auxtrace_info(union perf_event *event,
        sf->machine = &session->machines.host; /* No kvm support */
        sf->auxtrace_type = auxtrace_info->type;
        sf->pmu_type = PERF_TYPE_RAW;
-       sf->machine_type = s390_cpumsf_get_type(session->evlist->env->cpuid);
+       sf->machine_type = s390_cpumsf_get_type(perf_session__env(session)->cpuid);
 
        sf->auxtrace.process_event = s390_cpumsf_process_event;
        sf->auxtrace.process_auxtrace_event = s390_cpumsf_process_auxtrace_event;
index f3f6bd9d290eb448f255a7bf04fac31ec360692b..bcf442574d6eb606059f2d3c945a09ec3fd40dd8 100644 (file)
@@ -6,15 +6,16 @@
 #include "env.h"
 #include "header.h"
 #include "sample-raw.h"
+#include "session.h"
 
 /*
  * Check platform the perf data file was created on and perform platform
  * specific interpretation.
  */
-void evlist__init_trace_event_sample_raw(struct evlist *evlist)
+void evlist__init_trace_event_sample_raw(struct evlist *evlist, struct perf_env *env)
 {
-       const char *arch_pf = perf_env__arch(evlist->env);
-       const char *cpuid = perf_env__cpuid(evlist->env);
+       const char *arch_pf = perf_env__arch(env);
+       const char *cpuid = perf_env__cpuid(env);
 
        if (arch_pf && !strcmp("s390", arch_pf))
                evlist->trace_event_sample_raw = evlist__s390_sample_raw;
index ea01c581150306067305a8de6c290e22f321bcd8..896e9a87e373dc3a0c510b104388c0ae6a728884 100644 (file)
@@ -11,5 +11,5 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,
 bool evlist__has_amd_ibs(struct evlist *evlist);
 void evlist__amd_sample_raw(struct evlist *evlist, union perf_event *event,
                            struct perf_sample *sample);
-void evlist__init_trace_event_sample_raw(struct evlist *evlist);
+void evlist__init_trace_event_sample_raw(struct evlist *evlist, struct perf_env *env);
 #endif /* __PERF_EVLIST_H */
index b09d157f7d04e742e4536ee42c23cfc13855a132..a851d9130abd607e2963524b114f212faf233020 100644 (file)
@@ -177,7 +177,7 @@ struct perf_session *__perf_session__new(struct perf_data *data,
                                perf_session__set_comm_exec(session);
                        }
 
-                       evlist__init_trace_event_sample_raw(session->evlist);
+                       evlist__init_trace_event_sample_raw(session->evlist, &session->header.env);
 
                        /* Open the directory data. */
                        if (data->is_dir) {
@@ -193,6 +193,8 @@ struct perf_session *__perf_session__new(struct perf_data *data,
        } else  {
                session->machines.host.env = &perf_env;
        }
+       if (session->evlist)
+               session->evlist->session = session;
 
        session->machines.host.single_address_space =
                perf_env__single_address_space(session->machines.host.env);