Commit 99d6141d authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf evsel: Add functions to close evsel on a CPU

Refactor the existing all CPU function to use the per CPU close
internally.

Export APIs to close per CPU.
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191121001522.180827-7-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a8cbe40f
...@@ -114,16 +114,23 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, ...@@ -114,16 +114,23 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
return err; return err;
} }
static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu)
{
int thread;
for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1;
}
}
void perf_evsel__close_fd(struct perf_evsel *evsel) void perf_evsel__close_fd(struct perf_evsel *evsel)
{ {
int cpu, thread; int cpu;
for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) { perf_evsel__close_fd_cpu(evsel, cpu);
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1;
}
} }
void perf_evsel__free_fd(struct perf_evsel *evsel) void perf_evsel__free_fd(struct perf_evsel *evsel)
...@@ -141,6 +148,14 @@ void perf_evsel__close(struct perf_evsel *evsel) ...@@ -141,6 +148,14 @@ void perf_evsel__close(struct perf_evsel *evsel)
perf_evsel__free_fd(evsel); perf_evsel__free_fd(evsel);
} }
void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu)
{
if (evsel->fd == NULL)
return;
perf_evsel__close_fd_cpu(evsel, cpu);
}
int perf_evsel__read_size(struct perf_evsel *evsel) int perf_evsel__read_size(struct perf_evsel *evsel)
{ {
u64 read_format = evsel->attr.read_format; u64 read_format = evsel->attr.read_format;
......
...@@ -26,6 +26,7 @@ LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel); ...@@ -26,6 +26,7 @@ LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
struct perf_thread_map *threads); struct perf_thread_map *threads);
LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel); LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu);
LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
struct perf_counts_values *count); struct perf_counts_values *count);
LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
......
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