perf evlist: Close fds on destructor

Since it is safe to call perf_evlist__close() multiple times, autoclose
it and remove the calls to the close from existing tools, reducing the
tooling boilerplate.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-2kq9v7p1rude1tqxa0aue2tk@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 03ad9747
...@@ -970,7 +970,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -970,7 +970,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
err = __cmd_record(&record, argc, argv); err = __cmd_record(&record, argc, argv);
perf_evlist__munmap(rec->evlist); perf_evlist__munmap(rec->evlist);
perf_evlist__close(rec->evlist);
out_symbol_exit: out_symbol_exit:
symbol__exit(); symbol__exit();
return err; return err;
......
...@@ -1909,7 +1909,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) ...@@ -1909,7 +1909,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false); err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
if (err < 0) { if (err < 0) {
fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno)); fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
goto out_close_evlist; goto out_delete_evlist;
} }
perf_evlist__enable(evlist); perf_evlist__enable(evlist);
...@@ -1994,8 +1994,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv) ...@@ -1994,8 +1994,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
} }
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_evlist:
perf_evlist__close(evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
out: out:
......
...@@ -541,7 +541,6 @@ static int do_test_code_reading(bool try_kcore) ...@@ -541,7 +541,6 @@ static int do_test_code_reading(bool try_kcore)
out_err: out_err:
if (evlist) { if (evlist) {
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
} else { } else {
cpu_map__delete(cpus); cpu_map__delete(cpus);
......
...@@ -143,7 +143,6 @@ int test__keep_tracking(void) ...@@ -143,7 +143,6 @@ int test__keep_tracking(void)
if (evlist) { if (evlist) {
perf_evlist__disable(evlist); perf_evlist__disable(evlist);
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
} else { } else {
cpu_map__delete(cpus); cpu_map__delete(cpus);
......
...@@ -68,7 +68,7 @@ int test__basic_mmap(void) ...@@ -68,7 +68,7 @@ int test__basic_mmap(void)
evsels[i] = perf_evsel__newtp("syscalls", name); evsels[i] = perf_evsel__newtp("syscalls", name);
if (evsels[i] == NULL) { if (evsels[i] == NULL) {
pr_debug("perf_evsel__new\n"); pr_debug("perf_evsel__new\n");
goto out_free_evlist; goto out_delete_evlist;
} }
evsels[i]->attr.wakeup_events = 1; evsels[i]->attr.wakeup_events = 1;
...@@ -80,7 +80,7 @@ int test__basic_mmap(void) ...@@ -80,7 +80,7 @@ int test__basic_mmap(void)
pr_debug("failed to open counter: %s, " pr_debug("failed to open counter: %s, "
"tweak /proc/sys/kernel/perf_event_paranoid?\n", "tweak /proc/sys/kernel/perf_event_paranoid?\n",
strerror(errno)); strerror(errno));
goto out_close_fd; goto out_delete_evlist;
} }
nr_events[i] = 0; nr_events[i] = 0;
...@@ -90,7 +90,7 @@ int test__basic_mmap(void) ...@@ -90,7 +90,7 @@ int test__basic_mmap(void)
if (perf_evlist__mmap(evlist, 128, true) < 0) { if (perf_evlist__mmap(evlist, 128, true) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno, pr_debug("failed to mmap events: %d (%s)\n", errno,
strerror(errno)); strerror(errno));
goto out_close_fd; goto out_delete_evlist;
} }
for (i = 0; i < nsyscalls; ++i) for (i = 0; i < nsyscalls; ++i)
...@@ -138,10 +138,7 @@ int test__basic_mmap(void) ...@@ -138,10 +138,7 @@ int test__basic_mmap(void)
out_munmap: out_munmap:
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_fd: out_delete_evlist:
for (i = 0; i < nsyscalls; ++i)
perf_evsel__close_fd(evsels[i], 1, threads->nr);
out_free_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
cpus = NULL; cpus = NULL;
threads = NULL; threads = NULL;
......
...@@ -54,7 +54,7 @@ int test__syscall_open_tp_fields(void) ...@@ -54,7 +54,7 @@ int test__syscall_open_tp_fields(void)
err = perf_evlist__mmap(evlist, UINT_MAX, false); err = perf_evlist__mmap(evlist, UINT_MAX, false);
if (err < 0) { if (err < 0) {
pr_debug("perf_evlist__mmap: %s\n", strerror(errno)); pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
goto out_close_evlist; goto out_delete_evlist;
} }
perf_evlist__enable(evlist); perf_evlist__enable(evlist);
...@@ -112,8 +112,6 @@ int test__syscall_open_tp_fields(void) ...@@ -112,8 +112,6 @@ int test__syscall_open_tp_fields(void)
err = 0; err = 0;
out_munmap: out_munmap:
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_evlist:
perf_evlist__close(evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
out: out:
......
...@@ -132,7 +132,7 @@ int test__PERF_RECORD(void) ...@@ -132,7 +132,7 @@ int test__PERF_RECORD(void)
err = perf_evlist__mmap(evlist, opts.mmap_pages, false); err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
if (err < 0) { if (err < 0) {
pr_debug("perf_evlist__mmap: %s\n", strerror(errno)); pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
goto out_close_evlist; goto out_delete_evlist;
} }
/* /*
...@@ -304,8 +304,6 @@ int test__PERF_RECORD(void) ...@@ -304,8 +304,6 @@ int test__PERF_RECORD(void)
} }
out_err: out_err:
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_evlist:
perf_evlist__close(evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
out: out:
......
...@@ -167,7 +167,6 @@ int test__perf_time_to_tsc(void) ...@@ -167,7 +167,6 @@ int test__perf_time_to_tsc(void)
if (evlist) { if (evlist) {
perf_evlist__disable(evlist); perf_evlist__disable(evlist);
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
} }
......
...@@ -70,7 +70,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) ...@@ -70,7 +70,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
if (err < 0) { if (err < 0) {
pr_debug("failed to mmap event: %d (%s)\n", errno, pr_debug("failed to mmap event: %d (%s)\n", errno,
strerror(errno)); strerror(errno));
goto out_close_evlist; goto out_delete_evlist;
} }
perf_evlist__enable(evlist); perf_evlist__enable(evlist);
...@@ -107,8 +107,6 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) ...@@ -107,8 +107,6 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
out_unmap_evlist: out_unmap_evlist:
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_evlist:
perf_evlist__close(evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
return err; return err;
......
...@@ -89,7 +89,7 @@ int test__task_exit(void) ...@@ -89,7 +89,7 @@ int test__task_exit(void)
if (perf_evlist__mmap(evlist, 128, true) < 0) { if (perf_evlist__mmap(evlist, 128, true) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno, pr_debug("failed to mmap events: %d (%s)\n", errno,
strerror(errno)); strerror(errno));
goto out_close_evlist; goto out_delete_evlist;
} }
perf_evlist__start_workload(evlist); perf_evlist__start_workload(evlist);
...@@ -113,8 +113,6 @@ int test__task_exit(void) ...@@ -113,8 +113,6 @@ int test__task_exit(void)
} }
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
out_close_evlist:
perf_evlist__close(evlist);
out_delete_evlist: out_delete_evlist:
perf_evlist__delete(evlist); perf_evlist__delete(evlist);
return err; return err;
......
...@@ -107,6 +107,7 @@ void perf_evlist__exit(struct perf_evlist *evlist) ...@@ -107,6 +107,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
void perf_evlist__delete(struct perf_evlist *evlist) void perf_evlist__delete(struct perf_evlist *evlist)
{ {
perf_evlist__close(evlist);
cpu_map__delete(evlist->cpus); cpu_map__delete(evlist->cpus);
thread_map__delete(evlist->threads); thread_map__delete(evlist->threads);
evlist->cpus = NULL; evlist->cpus = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment