libperf: Adopt perf_counts_values__scale() from tools/perf/util
authorShunsuke Nakamura <nakamura.shun@fujitsu.com>
Tue, 9 Nov 2021 08:58:29 +0000 (17:58 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Dec 2021 01:18:23 +0000 (22:18 -0300)
Move perf_counts_values__scale() from tools/perf/util to tools/lib/perf
so that it can be used with libperf.

Committer notes:

As noted by Jiri, use __s8 instead of s8 on the exported function.

Signed-off-by: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20211109085831.3770594-2-nakamura.shun@fujitsu.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/evsel.c
tools/lib/perf/include/perf/evsel.h
tools/lib/perf/libperf.map
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 8441e3e1aaac3ece838985c076738f99a30f1087..68f83d2c27c125ff15b98e2d30a1b39dbaca5edd 100644 (file)
@@ -431,3 +431,22 @@ void perf_evsel__free_id(struct perf_evsel *evsel)
        zfree(&evsel->id);
        evsel->ids = 0;
 }
+
+void perf_counts_values__scale(struct perf_counts_values *count,
+                              bool scale, __s8 *pscaled)
+{
+       s8 scaled = 0;
+
+       if (scale) {
+               if (count->run == 0) {
+                       scaled = -1;
+                       count->val = 0;
+               } else if (count->run < count->ena) {
+                       scaled = 1;
+                       count->val = (u64)((double)count->val * count->ena / count->run);
+               }
+       }
+
+       if (pscaled)
+               *pscaled = scaled;
+}
index 60eae25076d3dc83ac6d2d2501e1b88e0942bbca..f401c7484bec273354802d488cce7cec589a58db 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <stdint.h>
 #include <perf/core.h>
+#include <stdbool.h>
+#include <linux/types.h>
 
 struct perf_evsel;
 struct perf_event_attr;
@@ -39,5 +41,7 @@ LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu);
 LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
 LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
 LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
+LIBPERF_API void perf_counts_values__scale(struct perf_counts_values *count,
+                                          bool scale, __s8 *pscaled);
 
 #endif /* __LIBPERF_EVSEL_H */
index 71468606e8a7bdc3b9e71c66d4de93facf6d8715..5979bf92d98ff0b60eb82d2830eec5efc0427bac 100644 (file)
@@ -50,6 +50,7 @@ LIBPERF_0.0.1 {
                perf_mmap__read_init;
                perf_mmap__read_done;
                perf_mmap__read_event;
+               perf_counts_values__scale;
        local:
                *;
 };
index ac0127be0459352acf8364a3bcd520d616ca7726..656c30b988ce61071394c8a088256c6d8c6b3eb1 100644 (file)
@@ -1476,25 +1476,6 @@ void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
        count->run = count->run - tmp.run;
 }
 
-void perf_counts_values__scale(struct perf_counts_values *count,
-                              bool scale, s8 *pscaled)
-{
-       s8 scaled = 0;
-
-       if (scale) {
-               if (count->run == 0) {
-                       scaled = -1;
-                       count->val = 0;
-               } else if (count->run < count->ena) {
-                       scaled = 1;
-                       count->val = (u64)((double) count->val * count->ena / count->run);
-               }
-       }
-
-       if (pscaled)
-               *pscaled = scaled;
-}
-
 static int evsel__read_one(struct evsel *evsel, int cpu, int thread)
 {
        struct perf_counts_values *count = perf_counts(evsel->counts, cpu, thread);
index 29d49a8c1e92ddcbd24df03b33cec454f85b24fe..99aa3363def753b985daa22f415916da102b66bc 100644 (file)
@@ -195,9 +195,6 @@ static inline int evsel__nr_cpus(struct evsel *evsel)
        return evsel__cpus(evsel)->nr;
 }
 
-void perf_counts_values__scale(struct perf_counts_values *count,
-                              bool scale, s8 *pscaled);
-
 void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
                           struct perf_counts_values *count);