Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libperf: Move 'page_size' global variable to libperf

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
20f2be1d d5a99483

+36 -25
+1 -1
tools/perf/arch/arm/util/cs-etm.c
··· 25 25 #include "../../util/evsel.h" 26 26 #include "../../util/pmu.h" 27 27 #include "../../util/cs-etm.h" 28 - #include "../../util/util.h" // page_size 28 + #include <internal/lib.h> // page_size 29 29 #include "../../util/session.h" 30 30 31 31 #include <errno.h>
+1 -1
tools/perf/arch/arm64/util/arm-spe.c
··· 16 16 #include "../../util/evsel.h" 17 17 #include "../../util/evlist.h" 18 18 #include "../../util/session.h" 19 - #include "../../util/util.h" // page_size 19 + #include <internal/lib.h> // page_size 20 20 #include "../../util/pmu.h" 21 21 #include "../../util/debug.h" 22 22 #include "../../util/auxtrace.h"
+1 -1
tools/perf/arch/s390/util/machine.c
··· 2 2 #include <unistd.h> 3 3 #include <stdio.h> 4 4 #include <string.h> 5 - #include "util.h" // page_size 5 + #include <internal/lib.h> // page_size 6 6 #include "machine.h" 7 7 #include "api/fs/fs.h" 8 8 #include "debug.h"
+1
tools/perf/arch/x86/tests/intel-cqm.c
··· 5 5 #include "evlist.h" 6 6 #include "evsel.h" 7 7 #include "arch-tests.h" 8 + #include <internal/lib.h> // page_size 8 9 9 10 #include <signal.h> 10 11 #include <sys/mman.h>
+1 -1
tools/perf/arch/x86/tests/rdpmc.c
··· 13 13 #include "tests/tests.h" 14 14 #include "cloexec.h" 15 15 #include "event.h" 16 - #include "util.h" // page_size 16 + #include <internal/lib.h> // page_size 17 17 #include "arch-tests.h" 18 18 19 19 static u64 rdpmc(unsigned int counter)
+1 -1
tools/perf/arch/x86/util/intel-bts.c
··· 23 23 #include "../../util/tsc.h" 24 24 #include "../../util/auxtrace.h" 25 25 #include "../../util/intel-bts.h" 26 - #include "../../util/util.h" // page_size 26 + #include <internal/lib.h> // page_size 27 27 28 28 #define KiB(x) ((x) * 1024) 29 29 #define MiB(x) ((x) * 1024 * 1024)
+1 -1
tools/perf/arch/x86/util/intel-pt.c
··· 27 27 #include "../../util/record.h" 28 28 #include "../../util/target.h" 29 29 #include "../../util/tsc.h" 30 - #include "../../util/util.h" // page_size 30 + #include <internal/lib.h> // page_size 31 31 #include "../../util/intel-pt.h" 32 32 33 33 #define KiB(x) ((x) * 1024)
+1 -1
tools/perf/arch/x86/util/machine.c
··· 4 4 #include <limits.h> 5 5 #include <stdlib.h> 6 6 7 - #include "../../util/util.h" // page_size 7 + #include <internal/lib.h> // page_size 8 8 #include "../../util/machine.h" 9 9 #include "../../util/map.h" 10 10 #include "../../util/symbol.h"
+7
tools/perf/lib/core.c
··· 4 4 5 5 #include <stdio.h> 6 6 #include <stdarg.h> 7 + #include <unistd.h> 7 8 #include <perf/core.h> 9 + #include <internal/lib.h> 8 10 #include "internal.h" 9 11 10 12 static int __base_pr(enum libperf_print_level level, const char *format, ··· 33 31 va_start(args, format); 34 32 __libperf_pr(level, format, args); 35 33 va_end(args); 34 + } 35 + 36 + void libperf_init(void) 37 + { 38 + page_size = sysconf(_SC_PAGE_SIZE); 36 39 }
+2
tools/perf/lib/include/internal/lib.h
··· 4 4 5 5 #include <unistd.h> 6 6 7 + extern unsigned int page_size; 8 + 7 9 ssize_t readn(int fd, void *buf, size_t n); 8 10 ssize_t writen(int fd, const void *buf, size_t n); 9 11
+1
tools/perf/lib/include/perf/core.h
··· 18 18 const char *, va_list ap); 19 19 20 20 LIBPERF_API void libperf_set_print(libperf_print_fn_t fn); 21 + LIBPERF_API void libperf_init(void); 21 22 22 23 #endif /* __LIBPERF_CORE_H */
+2
tools/perf/lib/lib.c
··· 5 5 #include <linux/kernel.h> 6 6 #include <internal/lib.h> 7 7 8 + unsigned int page_size; 9 + 8 10 static ssize_t ion(bool is_read, int fd, void *buf, size_t n) 9 11 { 10 12 void *buf_start = buf;
+1
tools/perf/lib/libperf.map
··· 1 1 LIBPERF_0.0.1 { 2 2 global: 3 + libperf_init; 3 4 libperf_set_print; 4 5 perf_cpu_map__dummy_new; 5 6 perf_cpu_map__get;
+4 -3
tools/perf/perf.c
··· 12 12 #include "util/build-id.h" 13 13 #include "util/cache.h" 14 14 #include "util/env.h" 15 + #include <internal/lib.h> // page_size 15 16 #include <subcmd/exec-cmd.h> 16 17 #include "util/config.h" 17 18 #include <subcmd/run-command.h> ··· 21 20 #include "util/bpf-loader.h" 22 21 #include "util/debug.h" 23 22 #include "util/event.h" 24 - #include "util/util.h" // page_size, usage() 23 + #include "util/util.h" // usage() 25 24 #include "ui/ui.h" 26 25 #include "perf-sys.h" 27 26 #include <api/fs/fs.h> 28 27 #include <api/fs/tracing_path.h> 28 + #include <perf/core.h> 29 29 #include <errno.h> 30 30 #include <pthread.h> 31 31 #include <signal.h> ··· 440 438 exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT); 441 439 pager_init(PERF_PAGER_ENVIRONMENT); 442 440 443 - /* The page_size is placed in util object. */ 444 - page_size = sysconf(_SC_PAGE_SIZE); 441 + libperf_init(); 445 442 446 443 cmd = extract_argv0_path(argv[0]); 447 444 if (!cmd)
+1 -1
tools/perf/tests/mmap-thread-lookup.c
··· 16 16 #include "symbol.h" 17 17 #include "util/synthetic-events.h" 18 18 #include "thread.h" 19 - #include "util.h" // page_size 19 + #include <internal/lib.h> // page_size 20 20 21 21 #define THREADS 4 22 22
+1 -1
tools/perf/tests/vmlinux-kallsyms.c
··· 7 7 #include "dso.h" 8 8 #include "map.h" 9 9 #include "symbol.h" 10 - #include "util.h" // page_size 10 + #include <internal/lib.h> // page_size 11 11 #include "tests.h" 12 12 #include "debug.h" 13 13 #include "machine.h"
-1
tools/perf/util/auxtrace.c
··· 50 50 #include "intel-bts.h" 51 51 #include "arm-spe.h" 52 52 #include "s390-cpumsf.h" 53 - #include "util.h" // page_size 54 53 #include "util/mmap.h" 55 54 56 55 #include <linux/ctype.h>
+1 -1
tools/perf/util/evlist.c
··· 17 17 #include "evsel.h" 18 18 #include "debug.h" 19 19 #include "units.h" 20 - #include "util.h" // page_size 20 + #include <internal/lib.h> // page_size 21 21 #include "../perf.h" 22 22 #include "asm/bug.h" 23 23 #include "bpf-event.h"
+1 -1
tools/perf/util/header.c
··· 42 42 #include "tool.h" 43 43 #include "time-utils.h" 44 44 #include "units.h" 45 - #include "util.h" // page_size, perf_exe() 45 + #include "util/util.h" // perf_exe() 46 46 #include "cputopo.h" 47 47 #include "bpf-event.h" 48 48
+1
tools/perf/util/machine.c
··· 32 32 #include "linux/hash.h" 33 33 #include "asm/bug.h" 34 34 #include "bpf-event.h" 35 + #include <internal/lib.h> // page_size 35 36 36 37 #include <linux/ctype.h> 37 38 #include <symbol/kallsyms.h>
+1 -1
tools/perf/util/mmap.c
··· 20 20 #include "event.h" 21 21 #include "mmap.h" 22 22 #include "../perf.h" 23 - #include "util.h" /* page_size */ 23 + #include <internal/lib.h> /* page_size */ 24 24 25 25 size_t perf_mmap__mmap_len(struct mmap *map) 26 26 {
+1 -1
tools/perf/util/python.c
··· 14 14 #include "thread_map.h" 15 15 #include "trace-event.h" 16 16 #include "mmap.h" 17 - #include "util.h" 17 + #include <internal/lib.h> 18 18 #include "../perf-sys.h" 19 19 20 20 #if PY_MAJOR_VERSION < 3
-1
tools/perf/util/session.c
··· 29 29 #include "thread-stack.h" 30 30 #include "sample-raw.h" 31 31 #include "stat.h" 32 - #include "util.h" 33 32 #include "ui/progress.h" 34 33 #include "../perf.h" 35 34 #include "arch/common.h"
+1 -1
tools/perf/util/srccode.c
··· 15 15 #include <string.h> 16 16 #include "srccode.h" 17 17 #include "debug.h" 18 - #include "util.h" // page_size 18 + #include <internal/lib.h> // page_size 19 19 20 20 #define MAXSRCCACHE (32*1024*1024) 21 21 #define MAXSRCFILES 64
+1 -1
tools/perf/util/synthetic-events.c
··· 16 16 #include "util/synthetic-events.h" 17 17 #include "util/target.h" 18 18 #include "util/time-utils.h" 19 - #include "util/util.h" 20 19 #include <linux/bitops.h> 21 20 #include <linux/kernel.h> 22 21 #include <linux/string.h> ··· 25 26 #include <perf/evsel.h> 26 27 #include <internal/cpumap.h> 27 28 #include <perf/cpumap.h> 29 + #include <internal/lib.h> // page_size 28 30 #include <internal/threadmap.h> 29 31 #include <perf/threadmap.h> 30 32 #include <symbol/kallsyms.h>
+1 -1
tools/perf/util/trace-event-info.c
··· 2 2 /* 3 3 * Copyright (C) 2008,2009, Steven Rostedt <srostedt@redhat.com> 4 4 */ 5 - #include "util.h" // page_size 6 5 #include <dirent.h> 7 6 #include <mntent.h> 8 7 #include <stdio.h> ··· 18 19 #include <linux/list.h> 19 20 #include <linux/kernel.h> 20 21 #include <linux/zalloc.h> 22 + #include <internal/lib.h> // page_size 21 23 22 24 #include "trace-event.h" 23 25 #include <api/fs/tracing_path.h>
+1 -2
tools/perf/util/util.c
··· 3 3 #include "debug.h" 4 4 #include "event.h" 5 5 #include "namespaces.h" 6 + #include <internal/lib.h> 6 7 #include <api/fs/fs.h> 7 8 #include <sys/mman.h> 8 9 #include <sys/stat.h> ··· 41 40 { 42 41 perf_singlethreaded = false; 43 42 } 44 - 45 - unsigned int page_size; 46 43 47 44 int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH; 48 45 int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK;
-2
tools/perf/util/util.h
··· 33 33 34 34 size_t hex_width(u64 v); 35 35 36 - extern unsigned int page_size; 37 - 38 36 int sysctl__max_stack(void); 39 37 40 38 int fetch_kernel_version(unsigned int *puint,