Skip to content

Commit 57ddb9c

Browse files
captain5050namhyung
authored andcommitted
perf evlist: Change env variable to session
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent c3e5b9e commit 57ddb9c

File tree

17 files changed

+35
-22
lines changed

17 files changed

+35
-22
lines changed

tools/perf/builtin-report.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,
12741274
union perf_event *event,
12751275
struct evlist **pevlist)
12761276
{
1277+
struct perf_session *session;
1278+
struct perf_env *env;
12771279
u64 sample_type;
12781280
int err;
12791281

@@ -1286,7 +1288,9 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,
12861288
* on events sample_type.
12871289
*/
12881290
sample_type = evlist__combined_sample_type(*pevlist);
1289-
callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
1291+
session = (*pevlist)->session;
1292+
env = perf_session__env(session);
1293+
callchain_param_setup(sample_type, perf_env__arch(env));
12901294
return 0;
12911295
}
12921296

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,
25342534
* on events sample_type.
25352535
*/
25362536
sample_type = evlist__combined_sample_type(evlist);
2537-
callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
2537+
callchain_param_setup(sample_type, perf_env__arch(perf_session__env(scr->session)));
25382538

25392539
/* Enable fields for callchain entries */
25402540
if (symbol_conf.use_callchain &&

tools/perf/builtin-top.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,6 @@ int cmd_top(int argc, const char **argv)
16541654
"Couldn't read the cpuid for this machine: %s\n",
16551655
str_error_r(errno, errbuf, sizeof(errbuf)));
16561656
}
1657-
top.evlist->env = &perf_env;
16581657

16591658
argc = parse_options(argc, argv, options, top_usage, 0);
16601659
if (argc)
@@ -1830,6 +1829,7 @@ int cmd_top(int argc, const char **argv)
18301829
perf_top__update_print_entries(&top);
18311830
signal(SIGWINCH, winch_sig);
18321831
}
1832+
top.session->env = &perf_env;
18331833

18341834
top.session = perf_session__new(NULL, NULL);
18351835
if (IS_ERR(top.session)) {

tools/perf/tests/topology.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static int session_write_header(char *path)
4343

4444
session->evlist = evlist__new_default();
4545
TEST_ASSERT_VAL("can't get evlist", session->evlist);
46+
session->evlist->session = session;
4647

4748
perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
4849
perf_header__set_feat(&session->header, HEADER_NRCPUS);

tools/perf/ui/browser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ int ui_browser__help_window(struct ui_browser *browser, const char *text);
7171
bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
7272
int ui_browser__input_window(const char *title, const char *text, char *input,
7373
const char *exit_msg, int delay_sec);
74-
struct perf_env;
75-
int tui__header_window(struct perf_env *env);
74+
struct perf_session;
75+
int tui__header_window(struct perf_session *session);
7676

7777
void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
7878
unsigned int ui_browser__argv_refresh(struct ui_browser *browser);

tools/perf/ui/browsers/header.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,14 @@ static int ui__list_menu(int argc, char * const argv[])
9393
return list_menu__run(&menu);
9494
}
9595

96-
int tui__header_window(struct perf_env *env)
96+
int tui__header_window(struct perf_session *session)
9797
{
9898
int i, argc = 0;
9999
char **argv;
100-
struct perf_session *session;
101100
char *ptr, *pos;
102101
size_t size;
103102
FILE *fp = open_memstream(&ptr, &size);
104103

105-
session = container_of(env, struct perf_session, header.env);
106104
perf_header__fprintf_info(session, fp, true);
107105
fclose(fp);
108106

tools/perf/ui/browsers/hists.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
32333233
case 'i':
32343234
/* env->arch is NULL for live-mode (i.e. perf top) */
32353235
if (env->arch)
3236-
tui__header_window(env);
3236+
tui__header_window(evsel__session(evsel));
32373237
continue;
32383238
case 'F':
32393239
symbol_conf.filter_relative ^= 1;

tools/perf/util/amd-sample-raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static void parse_cpuid(struct perf_env *env)
354354
*/
355355
bool evlist__has_amd_ibs(struct evlist *evlist)
356356
{
357-
struct perf_env *env = evlist->env;
357+
struct perf_env *env = perf_session__env(evlist->session);
358358
int ret, nr_pmu_mappings = perf_env__nr_pmu_mappings(env);
359359
const char *pmu_mapping = perf_env__pmu_mappings(env);
360360
char name[sizeof("ibs_fetch")];

tools/perf/util/arm-spe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
856856
const char *cpuid;
857857

858858
pr_warning_once("Old SPE metadata, re-record to improve decode accuracy\n");
859-
cpuid = perf_env__cpuid(spe->session->evlist->env);
859+
cpuid = perf_env__cpuid(perf_session__env(spe->session));
860860
midr = strtol(cpuid, NULL, 16);
861861
} else {
862862
/* CPU ID is -1 for per-thread mode */

tools/perf/util/evlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct evlist {
7171
struct mmap *overwrite_mmap;
7272
struct evsel *selected;
7373
struct events_stats stats;
74-
struct perf_env *env;
74+
struct perf_session *session;
7575
void (*trace_event_sample_raw)(struct evlist *evlist,
7676
union perf_event *event,
7777
struct perf_sample *sample);

0 commit comments

Comments
 (0)