Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf env: Remove global perf_env

The global perf_env was used for the host, but if a perf_env wasn't
easy to come by it was used in a lot of places where potentially
recorded and host data could be confused. Remove the global variable
as now the majority of accesses retrieve the perf_env for the host
from the session.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-20-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
525a599b 003a86bc

+4 -10
-3
tools/perf/perf.c
··· 346 346 use_pager = 1; 347 347 commit_pager_choice(); 348 348 349 - perf_env__init(&perf_env); 350 - perf_env__set_cmdline(&perf_env, argc, argv); 351 349 status = p->fn(argc, argv); 352 350 perf_config__exit(); 353 351 exit_browser(status); 354 - perf_env__exit(&perf_env); 355 352 356 353 if (status) 357 354 return status & 0xff;
+1 -1
tools/perf/util/bpf-event.c
··· 549 549 * for perf-record and perf-report use header.env; 550 550 * otherwise, use global perf_env. 551 551 */ 552 - env = session->data ? perf_session__env(session) : &perf_env; 552 + env = perf_session__env(session); 553 553 554 554 arrays = 1UL << PERF_BPIL_JITED_KSYMS; 555 555 arrays |= 1UL << PERF_BPIL_JITED_FUNC_LENS;
-2
tools/perf/util/env.c
··· 19 19 #include "strbuf.h" 20 20 #include "trace/beauty/beauty.h" 21 21 22 - struct perf_env perf_env; 23 - 24 22 #ifdef HAVE_LIBBPF_SUPPORT 25 23 #include "bpf-event.h" 26 24 #include "bpf-utils.h"
-2
tools/perf/util/env.h
··· 150 150 struct bpf_prog_info_node; 151 151 struct btf_node; 152 152 153 - extern struct perf_env perf_env; 154 - 155 153 int perf_env__read_core_pmu_caps(struct perf_env *env); 156 154 void perf_env__exit(struct perf_env *env); 157 155
+1 -1
tools/perf/util/evsel.c
··· 3882 3882 { 3883 3883 struct perf_session *session = evsel__session(evsel); 3884 3884 3885 - return session ? perf_session__env(session) : &perf_env; 3885 + return session ? perf_session__env(session) : NULL; 3886 3886 } 3887 3887 3888 3888 static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
+2 -1
tools/perf/util/session.c
··· 192 192 symbol_conf.kallsyms_name = perf_data__kallsyms_name(data); 193 193 } 194 194 } else { 195 - session->machines.host.env = host_env ?: &perf_env; 195 + assert(host_env != NULL); 196 + session->machines.host.env = host_env; 196 197 } 197 198 if (session->evlist) 198 199 session->evlist->session = session;