perf cacheline: Move cacheline related routines to separate files
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 22 Aug 2019 19:58:29 +0000 (16:58 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 26 Aug 2019 14:58:29 +0000 (11:58 -0300)
To disentangle util/sort.h a bit more.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-6kbf2cauas06rbqp15pyter5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-c2c.c
tools/perf/util/Build
tools/perf/util/cacheline.c [new file with mode: 0644]
tools/perf/util/cacheline.h [new file with mode: 0644]
tools/perf/util/sort.c
tools/perf/util/sort.h
tools/perf/util/util.c
tools/perf/util/util.h

index 2111437200781d830030bfa944d41fddee85205e..73782d99ee5a0f47ecd2ccb9ea75844f3b52a106 100644 (file)
@@ -26,6 +26,7 @@
 #include "hist.h"
 #include "sort.h"
 #include "tool.h"
+#include "cacheline.h"
 #include "data.h"
 #include "event.h"
 #include "evlist.h"
index b922c8c297ca501ea25d96a7c731a744542ed8a0..2e3856471e61cb2beddff6a8566cc60c05df83fa 100644 (file)
@@ -1,6 +1,7 @@
 perf-y += annotate.o
 perf-y += block-range.o
 perf-y += build-id.o
+perf-y += cacheline.o
 perf-y += config.o
 perf-y += ctype.o
 perf-y += db-export.o
diff --git a/tools/perf/util/cacheline.c b/tools/perf/util/cacheline.c
new file mode 100644 (file)
index 0000000..9361d3f
--- /dev/null
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cacheline.h"
+#include "../perf.h"
+#include <unistd.h>
+
+#ifdef _SC_LEVEL1_DCACHE_LINESIZE
+#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
+#else
+#include <api/fs/fs.h>
+#include "debug.h"
+static void cache_line_size(int *cacheline_sizep)
+{
+       if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
+               pr_debug("cannot determine cache line size");
+}
+#endif
+
+int cacheline_size(void)
+{
+       static int size;
+
+       if (!size)
+               cache_line_size(&size);
+
+       return size;
+}
diff --git a/tools/perf/util/cacheline.h b/tools/perf/util/cacheline.h
new file mode 100644 (file)
index 0000000..dec8c0f
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef PERF_CACHELINE_H
+#define PERF_CACHELINE_H
+
+#include <linux/compiler.h>
+
+int __pure cacheline_size(void);
+
+static inline u64 cl_address(u64 address)
+{
+       /* return the cacheline of the address */
+       return (address & ~(cacheline_size() - 1));
+}
+
+static inline u64 cl_offset(u64 address)
+{
+       /* return the cacheline of the address */
+       return (address & (cacheline_size() - 1));
+}
+
+#endif // PERF_CACHELINE_H
index f9a38a1dd4d1d8966e5aa8607ce50f10a5744948..904ff4b2f57f6da50ec53672b24f972db21d5518 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/time64.h>
 #include "sort.h"
 #include "hist.h"
+#include "cacheline.h"
 #include "comm.h"
 #include "map.h"
 #include "symbol.h"
index 5e34676a98e8eed2c3791fec8ca6730de72f484e..4ae155c6a808efd9a065d84c8afc56a253710a76 100644 (file)
@@ -204,18 +204,6 @@ static inline float hist_entry__get_percent_limit(struct hist_entry *he)
        return period * 100.0 / total_period;
 }
 
-static inline u64 cl_address(u64 address)
-{
-       /* return the cacheline of the address */
-       return (address & ~(cacheline_size() - 1));
-}
-
-static inline u64 cl_offset(u64 address)
-{
-       /* return the cacheline of the address */
-       return (address & (cacheline_size() - 1));
-}
-
 enum sort_mode {
        SORT_MODE__NORMAL,
        SORT_MODE__BRANCH,
index 6fd130a5d8f273633023dcfc429c1eb4f253362c..44211e483fbf2ad7622b05f12a4e874b7e4c15be 100644 (file)
@@ -43,26 +43,6 @@ void perf_set_multithreaded(void)
 
 unsigned int page_size;
 
-#ifdef _SC_LEVEL1_DCACHE_LINESIZE
-#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
-#else
-static void cache_line_size(int *cacheline_sizep)
-{
-       if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
-               pr_debug("cannot determine cache line size");
-}
-#endif
-
-int cacheline_size(void)
-{
-       static int size;
-
-       if (!size)
-               cache_line_size(&size);
-
-       return size;
-}
-
 int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH;
 int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK;
 
index 0dab140c65170b897ea9a1c0cb0de78e700c1433..45a5c6f201976a0b54283f0a515725f921d1c62d 100644 (file)
@@ -34,7 +34,6 @@ int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
 size_t hex_width(u64 v);
 
 extern unsigned int page_size;
-int __pure cacheline_size(void);
 
 int sysctl__max_stack(void);