Skip to content

Commit

Permalink
perf evlist: Auto unmap on destructor
Browse files Browse the repository at this point in the history
Removing further boilerplate after making sure perf_evlist__munmap can
be called multiple times for the same evlist.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jan 13, 2014
1 parent f26e1c7 commit 983874d
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 24 deletions.
2 changes: 0 additions & 2 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
}

err = __cmd_record(&record, argc, argv);

perf_evlist__munmap(rec->evlist);
out_symbol_exit:
symbol__exit();
return err;
Expand Down
1 change: 0 additions & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
}
}

perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
out:
Expand Down
1 change: 0 additions & 1 deletion tools/perf/tests/code-reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ static int do_test_code_reading(bool try_kcore)
err = TEST_CODE_READING_OK;
out_err:
if (evlist) {
perf_evlist__munmap(evlist);
perf_evlist__delete(evlist);
} else {
cpu_map__delete(cpus);
Expand Down
1 change: 0 additions & 1 deletion tools/perf/tests/keep-tracking.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ int test__keep_tracking(void)
out_err:
if (evlist) {
perf_evlist__disable(evlist);
perf_evlist__munmap(evlist);
perf_evlist__delete(evlist);
} else {
cpu_map__delete(cpus);
Expand Down
10 changes: 4 additions & 6 deletions tools/perf/tests/mmap-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ int test__basic_mmap(void)
if (event->header.type != PERF_RECORD_SAMPLE) {
pr_debug("unexpected %s event\n",
perf_event__name(event->header.type));
goto out_munmap;
goto out_delete_evlist;
}

err = perf_evlist__parse_sample(evlist, event, &sample);
if (err) {
pr_err("Can't parse sample, err = %d\n", err);
goto out_munmap;
goto out_delete_evlist;
}

err = -1;
evsel = perf_evlist__id2evsel(evlist, sample.id);
if (evsel == NULL) {
pr_debug("event with id %" PRIu64
" doesn't map to an evsel\n", sample.id);
goto out_munmap;
goto out_delete_evlist;
}
nr_events[evsel->idx]++;
perf_evlist__mmap_consume(evlist, 0);
Expand All @@ -132,12 +132,10 @@ int test__basic_mmap(void)
expected_nr_events[evsel->idx],
perf_evsel__name(evsel), nr_events[evsel->idx]);
err = -1;
goto out_munmap;
goto out_delete_evlist;
}
}

out_munmap:
perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
cpus = NULL;
Expand Down
8 changes: 3 additions & 5 deletions tools/perf/tests/open-syscall-tp-fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ int test__syscall_open_tp_fields(void)
err = perf_evsel__parse_sample(evsel, event, &sample);
if (err) {
pr_err("Can't parse sample, err = %d\n", err);
goto out_munmap;
goto out_delete_evlist;
}

tp_flags = perf_evsel__intval(evsel, &sample, "flags");

if (flags != tp_flags) {
pr_debug("%s: Expected flags=%#x, got %#x\n",
__func__, flags, tp_flags);
goto out_munmap;
goto out_delete_evlist;
}

goto out_ok;
Expand All @@ -105,13 +105,11 @@ int test__syscall_open_tp_fields(void)

if (++nr_polls > 5) {
pr_debug("%s: no events!\n", __func__);
goto out_munmap;
goto out_delete_evlist;
}
}
out_ok:
err = 0;
out_munmap:
perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
out:
Expand Down
4 changes: 1 addition & 3 deletions tools/perf/tests/perf-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int test__PERF_RECORD(void)
if (verbose)
perf_event__fprintf(event, stderr);
pr_debug("Couldn't parse sample\n");
goto out_err;
goto out_delete_evlist;
}

if (verbose) {
Expand Down Expand Up @@ -302,8 +302,6 @@ int test__PERF_RECORD(void)
pr_debug("PERF_RECORD_MMAP for %s missing!\n", "[vdso]");
++errs;
}
out_err:
perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
out:
Expand Down
1 change: 0 additions & 1 deletion tools/perf/tests/perf-time-to-tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ int test__perf_time_to_tsc(void)
out_err:
if (evlist) {
perf_evlist__disable(evlist);
perf_evlist__munmap(evlist);
perf_evlist__delete(evlist);
}

Expand Down
4 changes: 1 addition & 3 deletions tools/perf/tests/sw-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
err = perf_evlist__parse_sample(evlist, event, &sample);
if (err < 0) {
pr_debug("Error during parse sample\n");
goto out_unmap_evlist;
goto out_delete_evlist;
}

total_periods += sample.period;
Expand All @@ -105,8 +105,6 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
err = -1;
}

out_unmap_evlist:
perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
return err;
Expand Down
1 change: 0 additions & 1 deletion tools/perf/tests/task-exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ int test__task_exit(void)
err = -1;
}

perf_evlist__munmap(evlist);
out_delete_evlist:
perf_evlist__delete(evlist);
return err;
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)

void perf_evlist__delete(struct perf_evlist *evlist)
{
perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
cpu_map__delete(evlist->cpus);
thread_map__delete(evlist->threads);
Expand Down Expand Up @@ -587,6 +588,9 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
{
int i;

if (evlist->mmap == NULL)
return;

for (i = 0; i < evlist->nr_mmaps; i++)
__perf_evlist__munmap(evlist, i);

Expand Down

0 comments on commit 983874d

Please sign in to comment.