libperf evsel: Factor out perf_evsel__ioctl()
authorAdrian Hunter <adrian.hunter@intel.com>
Fri, 22 Apr 2022 16:23:42 +0000 (19:23 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 24 Apr 2022 10:50:38 +0000 (07:50 -0300)
Factor out perf_evsel__ioctl() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/20220422162402.147958-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/evsel.c

index 210ea7c..20ae9f5 100644 (file)
@@ -328,6 +328,17 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread,
        return 0;
 }
 
+static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, void *arg,
+                            int cpu_map_idx, int thread)
+{
+       int *fd = FD(evsel, cpu_map_idx, thread);
+
+       if (fd == NULL || *fd < 0)
+               return -1;
+
+       return ioctl(*fd, ioc, arg);
+}
+
 static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
                                 int ioc,  void *arg,
                                 int cpu_map_idx)
@@ -335,13 +346,7 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
        int thread;
 
        for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
-               int err;
-               int *fd = FD(evsel, cpu_map_idx, thread);
-
-               if (fd == NULL || *fd < 0)
-                       return -1;
-
-               err = ioctl(*fd, ioc, arg);
+               int err = perf_evsel__ioctl(evsel, ioc, arg, cpu_map_idx, thread);
 
                if (err)
                        return err;