libperf: Move 'page_size' global variable to libperf
authorJiri Olsa <jolsa@kernel.org>
Tue, 6 Aug 2019 13:25:25 +0000 (15:25 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 25 Sep 2019 12:51:48 +0000 (09:51 -0300)
We need the 'page_size' variable in libperf, so move it there.

Add a libperf_init() as a global libperf init function to obtain this
value via sysconf() at tool start.

Committer notes:

Add internal/lib.h to tools/perf/ files using 'page_size', sometimes
replacing util.h with it if that was the only reason for having util.h
included.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lore.kernel.org/lkml/20190913132355.21634-33-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
28 files changed:
tools/perf/arch/arm/util/cs-etm.c
tools/perf/arch/arm64/util/arm-spe.c
tools/perf/arch/s390/util/machine.c
tools/perf/arch/x86/tests/intel-cqm.c
tools/perf/arch/x86/tests/rdpmc.c
tools/perf/arch/x86/util/intel-bts.c
tools/perf/arch/x86/util/intel-pt.c
tools/perf/arch/x86/util/machine.c
tools/perf/lib/core.c
tools/perf/lib/include/internal/lib.h
tools/perf/lib/include/perf/core.h
tools/perf/lib/lib.c
tools/perf/lib/libperf.map
tools/perf/perf.c
tools/perf/tests/mmap-thread-lookup.c
tools/perf/tests/vmlinux-kallsyms.c
tools/perf/util/auxtrace.c
tools/perf/util/evlist.c
tools/perf/util/header.c
tools/perf/util/machine.c
tools/perf/util/mmap.c
tools/perf/util/python.c
tools/perf/util/session.c
tools/perf/util/srccode.c
tools/perf/util/synthetic-events.c
tools/perf/util/trace-event-info.c
tools/perf/util/util.c
tools/perf/util/util.h

index 6654bcfc12247ecaba0af786bcfb5e755be21a98..2e4de211d8813a58a3a5c2e7e639c1469f9b1375 100644 (file)
@@ -25,7 +25,7 @@
 #include "../../util/evsel.h"
 #include "../../util/pmu.h"
 #include "../../util/cs-etm.h"
-#include "../../util/util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "../../util/session.h"
 
 #include <errno.h>
index 745f2d50ee828ec3dcba7a4988b2a8a12a695aaa..eba6541ec0f12ca8250c3c7d6e33aab1ecf89c1b 100644 (file)
@@ -16,7 +16,7 @@
 #include "../../util/evsel.h"
 #include "../../util/evlist.h"
 #include "../../util/session.h"
-#include "../../util/util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "../../util/pmu.h"
 #include "../../util/debug.h"
 #include "../../util/auxtrace.h"
index df099d6cc3f5d7df24c9c52c8cf4be5084127f62..724efb2d842d72aa2d0b853fd7fd1e6775a576ce 100644 (file)
@@ -2,7 +2,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "machine.h"
 #include "api/fs/fs.h"
 #include "debug.h"
index 0329b9168faeb1df3d8b430d066226478dcee3b5..3ec562a2aabaa99c7df881a5b0b9d7dee12698fd 100644 (file)
@@ -5,6 +5,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "arch-tests.h"
+#include <internal/lib.h> // page_size
 
 #include <signal.h>
 #include <sys/mman.h>
index e7640fb047de43666bbc6607d7b08fff4e855ebd..1ea916656a2dd45ad62ffa1db2803f10e60fca8b 100644 (file)
@@ -13,7 +13,7 @@
 #include "tests/tests.h"
 #include "cloexec.h"
 #include "event.h"
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "arch-tests.h"
 
 static u64 rdpmc(unsigned int counter)
index e2c7095327db4c6f9ecc3103399da7e798ca053f..f7f68a50a5cd54ed99ebeeb9f86b26321a5cae79 100644 (file)
@@ -23,7 +23,7 @@
 #include "../../util/tsc.h"
 #include "../../util/auxtrace.h"
 #include "../../util/intel-bts.h"
-#include "../../util/util.h" // page_size
+#include <internal/lib.h> // page_size
 
 #define KiB(x) ((x) * 1024)
 #define MiB(x) ((x) * 1024 * 1024)
index 84a65524c418efb2be2c5f873aeb3f67f0a4dadd..d6d26256915f89e6ce5ff6adebfa8f1e97ff5ad9 100644 (file)
@@ -27,7 +27,7 @@
 #include "../../util/record.h"
 #include "../../util/target.h"
 #include "../../util/tsc.h"
-#include "../../util/util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "../../util/intel-pt.h"
 
 #define KiB(x) ((x) * 1024)
index f0c289862f9f5cff476ca6c9ffc96051c6a9a412..e17e080e76f49b1ed1bcf3415f473e2d1b21ebb1 100644 (file)
@@ -4,7 +4,7 @@
 #include <limits.h>
 #include <stdlib.h>
 
-#include "../../util/util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "../../util/machine.h"
 #include "../../util/map.h"
 #include "../../util/symbol.h"
index 29d5e3348718f04c175c390d435a38f97812c1d1..6689d593c2d1fbe3f8c1718dd9a4356fed1a390e 100644 (file)
@@ -4,7 +4,9 @@
 
 #include <stdio.h>
 #include <stdarg.h>
+#include <unistd.h>
 #include <perf/core.h>
+#include <internal/lib.h>
 #include "internal.h"
 
 static int __base_pr(enum libperf_print_level level, const char *format,
@@ -32,3 +34,8 @@ void libperf_print(enum libperf_print_level level, const char *format, ...)
        __libperf_pr(level, format, args);
        va_end(args);
 }
+
+void libperf_init(void)
+{
+       page_size = sysconf(_SC_PAGE_SIZE);
+}
index 0b56f1201dc92de08727e9d8ff6feeb65303f107..9168b7d2a7e1e11af9a0ed612510290c3a172fce 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <unistd.h>
 
+extern unsigned int page_size;
+
 ssize_t readn(int fd, void *buf, size_t n);
 ssize_t writen(int fd, const void *buf, size_t n);
 
index c341a7b2c8747ab5425744ec1dfe7642885cf878..ba2f4e76a3e287c484586894d8e60436c9b95a63 100644 (file)
@@ -18,5 +18,6 @@ typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
                                  const char *, va_list ap);
 
 LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
+LIBPERF_API void libperf_init(void);
 
 #endif /* __LIBPERF_CORE_H */
index 2a81819c3b8c984618c7e86d5b341d66d40219da..18658931fc7145f9788ca27279a381591c68e12e 100644 (file)
@@ -5,6 +5,8 @@
 #include <linux/kernel.h>
 #include <internal/lib.h>
 
+unsigned int page_size;
+
 static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
 {
        void *buf_start = buf;
index cd0d17b996c8c203e0b657cb8df936d63f343a52..724da66776ef5deb80253dad9c282a117eff5a8f 100644 (file)
@@ -1,5 +1,6 @@
 LIBPERF_0.0.1 {
        global:
+               libperf_init;
                libperf_set_print;
                perf_cpu_map__dummy_new;
                perf_cpu_map__get;
index bb40a108b8f7c02c8dc358c1b6fd366efae70b2e..c012ceb64ff9b440755339689d0b7143a043a04d 100644 (file)
@@ -12,6 +12,7 @@
 #include "util/build-id.h"
 #include "util/cache.h"
 #include "util/env.h"
+#include <internal/lib.h> // page_size
 #include <subcmd/exec-cmd.h>
 #include "util/config.h"
 #include <subcmd/run-command.h>
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include "util/event.h"
-#include "util/util.h" // page_size, usage()
+#include "util/util.h" // usage()
 #include "ui/ui.h"
 #include "perf-sys.h"
 #include <api/fs/fs.h>
 #include <api/fs/tracing_path.h>
+#include <perf/core.h>
 #include <errno.h>
 #include <pthread.h>
 #include <signal.h>
@@ -438,8 +440,7 @@ int main(int argc, const char **argv)
        exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
        pager_init(PERF_PAGER_ENVIRONMENT);
 
-       /* The page_size is placed in util object. */
-       page_size = sysconf(_SC_PAGE_SIZE);
+       libperf_init();
 
        cmd = extract_argv0_path(argv[0]);
        if (!cmd)
index 33b496d194f495e059543bd0b01341d86306edf0..8d9d4cbff76d17d5f54d78c0aa8eb75011ac3175 100644 (file)
@@ -16,7 +16,7 @@
 #include "symbol.h"
 #include "util/synthetic-events.h"
 #include "thread.h"
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 
 #define THREADS 4
 
index 7f28775875c2cfce68d92c49548cee86c6b6a71c..aa296ffea6d13b7d048467dd2be9ad517ad87e57 100644 (file)
@@ -7,7 +7,7 @@
 #include "dso.h"
 #include "map.h"
 #include "symbol.h"
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "tests.h"
 #include "debug.h"
 #include "machine.h"
index 4bd92f5bfb5fd0334916b379188a5999cccbd559..8470dfe9fe97b714b5c5f77749f6abe38beb9915 100644 (file)
@@ -50,7 +50,6 @@
 #include "intel-bts.h"
 #include "arm-spe.h"
 #include "s390-cpumsf.h"
-#include "util.h" // page_size
 #include "util/mmap.h"
 
 #include <linux/ctype.h>
index a37eccf65eaeaeb4224f77f1c857b5c0e801a7f8..6069fb52661fbe4d4d830f58eeed34629218da21 100644 (file)
@@ -17,7 +17,7 @@
 #include "evsel.h"
 #include "debug.h"
 #include "units.h"
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 #include "../perf.h"
 #include "asm/bug.h"
 #include "bpf-event.h"
index 02602bc8cabf38bc46c97bfb769919403bbb32a9..3b24b4974c5f1a2066bba8ec593b241bfe52ebbe 100644 (file)
@@ -42,7 +42,7 @@
 #include "tool.h"
 #include "time-utils.h"
 #include "units.h"
-#include "util.h" // page_size, perf_exe()
+#include "util/util.h" // perf_exe()
 #include "cputopo.h"
 #include "bpf-event.h"
 
index 0535338f2d7a747881e9731ffcbe304d193df918..70a9f8716a4b4639a39e16244145ef4b8956984f 100644 (file)
@@ -32,6 +32,7 @@
 #include "linux/hash.h"
 #include "asm/bug.h"
 #include "bpf-event.h"
+#include <internal/lib.h> // page_size
 
 #include <linux/ctype.h>
 #include <symbol/kallsyms.h>
index 4cc3b54b2f73f20b4f689ebff91998685aa8d446..12671d0897486327dbc7960d3f91f25e3424ebc8 100644 (file)
@@ -20,7 +20,7 @@
 #include "event.h"
 #include "mmap.h"
 #include "../perf.h"
-#include "util.h" /* page_size */
+#include <internal/lib.h> /* page_size */
 
 size_t perf_mmap__mmap_len(struct mmap *map)
 {
index fcbafb1e8d9de7b3f541cd09c07364a1e43558d7..6c46d7dbd263048af67d88888417f57317ed2965 100644 (file)
@@ -14,7 +14,7 @@
 #include "thread_map.h"
 #include "trace-event.h"
 #include "mmap.h"
-#include "util.h"
+#include <internal/lib.h>
 #include "../perf-sys.h"
 
 #if PY_MAJOR_VERSION < 3
index 84a30ff3968a1eca7e35c7ef6c840d80ac71a057..061bb4d6a3f5ab21b0570b9a4c12ed6bebc053dd 100644 (file)
@@ -29,7 +29,6 @@
 #include "thread-stack.h"
 #include "sample-raw.h"
 #include "stat.h"
-#include "util.h"
 #include "ui/progress.h"
 #include "../perf.h"
 #include "arch/common.h"
index b402f9ca89abf25808ddd2f620af271075bff3d4..d84ed8b6caaa21bd5c32b937b099cb53e3007cec 100644 (file)
@@ -15,7 +15,7 @@
 #include <string.h>
 #include "srccode.h"
 #include "debug.h"
-#include "util.h" // page_size
+#include <internal/lib.h> // page_size
 
 #define MAXSRCCACHE (32*1024*1024)
 #define MAXSRCFILES     64
index 96ed008c277575564b585d1bcfc2e1b41e42b8ef..807cbca403a7d55140953b1397c6877e3ca2d1b2 100644 (file)
@@ -16,7 +16,6 @@
 #include "util/synthetic-events.h"
 #include "util/target.h"
 #include "util/time-utils.h"
-#include "util/util.h"
 #include <linux/bitops.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -26,6 +25,7 @@
 #include <perf/evsel.h>
 #include <internal/cpumap.h>
 #include <perf/cpumap.h>
+#include <internal/lib.h> // page_size
 #include <internal/threadmap.h>
 #include <perf/threadmap.h>
 #include <symbol/kallsyms.h>
index fe07e755093047eab7cb07cb0ae24604143c3d3b..086e98ff42a374af7c9bed86a85b31b4bcae3a64 100644 (file)
@@ -2,7 +2,6 @@
 /*
  * Copyright (C) 2008,2009, Steven Rostedt <srostedt@redhat.com>
  */
-#include "util.h" // page_size
 #include <dirent.h>
 #include <mntent.h>
 #include <stdio.h>
@@ -19,6 +18,7 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
+#include <internal/lib.h> // page_size
 
 #include "trace-event.h"
 #include <api/fs/tracing_path.h>
index 32322a20a68be4fb7774008474e6fd2205df3b93..cb6fa4c9847024dd48ae5940acdb810906278188 100644 (file)
@@ -3,6 +3,7 @@
 #include "debug.h"
 #include "event.h"
 #include "namespaces.h"
+#include <internal/lib.h>
 #include <api/fs/fs.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -41,8 +42,6 @@ void perf_set_multithreaded(void)
        perf_singlethreaded = false;
 }
 
-unsigned int page_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 45a5c6f201976a0b54283f0a515725f921d1c62d..d6ae394e67c4764cbbc79b673530efcfa2f3f4b5 100644 (file)
@@ -33,8 +33,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 sysctl__max_stack(void);
 
 int fetch_kernel_version(unsigned int *puint,