Преглед изворни кода

Merge tag 'perf-core-for-mingo-4.12-20170419' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core cleanups from Arnaldo Carvalho de Melo:

 - Introduce new header files out of the hodge-podge that util/util.h
   became, trying to disentangle the includes hell that all C projects
   end up growing. This should help in build times, as changes to
   seemingly unrelated files (util.h included tons of headers) won't
   trigger a rebuild of most object files.

 - Use equivalent facilities found in the kernel source code base
   originated tools/include/ header files, such as __stringify(),
   ARRAY_SIZE, that has extra checks (__must_be_array()), etc.

 - For that get some more files from the kernel sources, like
   include/linux/bug.h, some just with the bits needed at this time.

 - Use the headers where facilities declared in them are used, such
   as PRIxu(32,64) macros (inttypes.h), errno defines (errno.h), etc.

 - Remove various leftovers from the initial code base we copied from
   git.git: FLEX_ARRAY, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Ingo Molnar пре 8 година
родитељ
комит
07590a7d40
100 измењених фајлова са 229 додато и 35 уклоњено
  1. 10 0
      tools/include/linux/bug.h
  2. 3 0
      tools/include/linux/compiler-gcc.h
  3. 5 0
      tools/include/linux/compiler.h
  4. 0 4
      tools/include/linux/hashtable.h
  5. 3 0
      tools/include/linux/kernel.h
  6. 3 0
      tools/include/linux/log2.h
  7. 1 0
      tools/lib/symbol/kallsyms.c
  8. 1 2
      tools/objtool/builtin-check.c
  9. 1 2
      tools/objtool/objtool.c
  10. 1 0
      tools/perf/MANIFEST
  11. 2 2
      tools/perf/arch/arm/util/dwarf-regs.c
  12. 3 1
      tools/perf/arch/arm64/util/dwarf-regs.c
  13. 1 1
      tools/perf/arch/arm64/util/unwind-libunwind.c
  14. 2 0
      tools/perf/arch/common.c
  15. 3 2
      tools/perf/arch/powerpc/util/dwarf-regs.c
  16. 1 0
      tools/perf/arch/powerpc/util/kvm-stat.c
  17. 1 0
      tools/perf/arch/powerpc/util/perf_regs.c
  18. 1 0
      tools/perf/arch/s390/util/kvm-stat.c
  19. 1 0
      tools/perf/arch/x86/tests/intel-cqm.c
  20. 2 0
      tools/perf/arch/x86/tests/perf-time-to-tsc.c
  21. 1 0
      tools/perf/arch/x86/util/auxtrace.c
  22. 1 0
      tools/perf/arch/x86/util/intel-bts.c
  23. 1 0
      tools/perf/arch/x86/util/intel-pt.c
  24. 1 0
      tools/perf/arch/x86/util/kvm-stat.c
  25. 1 0
      tools/perf/arch/x86/util/perf_regs.c
  26. 1 0
      tools/perf/bench/mem-functions.c
  27. 2 0
      tools/perf/bench/numa.c
  28. 1 0
      tools/perf/builtin-annotate.c
  29. 1 0
      tools/perf/builtin-buildid-cache.c
  30. 1 0
      tools/perf/builtin-buildid-list.c
  31. 2 0
      tools/perf/builtin-c2c.c
  32. 2 0
      tools/perf/builtin-diff.c
  33. 2 0
      tools/perf/builtin-ftrace.c
  34. 4 2
      tools/perf/builtin-help.c
  35. 1 0
      tools/perf/builtin-inject.c
  36. 1 0
      tools/perf/builtin-kallsyms.c
  37. 5 0
      tools/perf/builtin-kmem.c
  38. 4 0
      tools/perf/builtin-kvm.c
  39. 3 0
      tools/perf/builtin-lock.c
  40. 1 0
      tools/perf/builtin-mem.c
  41. 2 0
      tools/perf/builtin-record.c
  42. 3 1
      tools/perf/builtin-report.c
  43. 5 0
      tools/perf/builtin-sched.c
  44. 8 0
      tools/perf/builtin-script.c
  45. 5 0
      tools/perf/builtin-stat.c
  46. 3 1
      tools/perf/builtin-timechart.c
  47. 3 0
      tools/perf/builtin-top.c
  48. 8 0
      tools/perf/builtin-trace.c
  49. 2 10
      tools/perf/perf.c
  50. 2 0
      tools/perf/tests/attr.c
  51. 1 0
      tools/perf/tests/backward-ring-buffer.c
  52. 2 0
      tools/perf/tests/bpf.c
  53. 2 0
      tools/perf/tests/builtin-test.c
  54. 1 0
      tools/perf/tests/clang.c
  55. 5 1
      tools/perf/tests/code-reading.c
  56. 2 0
      tools/perf/tests/dso-data.c
  57. 1 0
      tools/perf/tests/dwarf-unwind.c
  58. 2 0
      tools/perf/tests/event-times.c
  59. 2 0
      tools/perf/tests/evsel-roundtrip-name.c
  60. 2 0
      tools/perf/tests/hists_common.c
  61. 1 0
      tools/perf/tests/hists_cumulate.c
  62. 1 0
      tools/perf/tests/hists_filter.c
  63. 2 0
      tools/perf/tests/hists_link.c
  64. 1 0
      tools/perf/tests/hists_output.c
  65. 2 1
      tools/perf/tests/is_printable_array.c
  66. 3 0
      tools/perf/tests/mmap-basic.c
  67. 2 0
      tools/perf/tests/mmap-thread-lookup.c
  68. 6 0
      tools/perf/tests/openat-syscall-all-cpus.c
  69. 1 0
      tools/perf/tests/openat-syscall-tp-fields.c
  70. 5 0
      tools/perf/tests/openat-syscall.c
  71. 4 1
      tools/perf/tests/parse-events.c
  72. 1 0
      tools/perf/tests/parse-no-sample-id-all.c
  73. 2 0
      tools/perf/tests/perf-record.c
  74. 2 0
      tools/perf/tests/pmu.c
  75. 2 0
      tools/perf/tests/sample-parsing.c
  76. 1 0
      tools/perf/tests/sdt.c
  77. 2 0
      tools/perf/tests/sw-clock.c
  78. 1 0
      tools/perf/tests/switch-tracking.c
  79. 1 0
      tools/perf/tests/task-exit.c
  80. 1 0
      tools/perf/tests/unit_number__scnprintf.c
  81. 1 0
      tools/perf/tests/vmlinux-kallsyms.c
  82. 2 0
      tools/perf/ui/browser.c
  83. 3 0
      tools/perf/ui/browsers/annotate.c
  84. 2 0
      tools/perf/ui/browsers/header.c
  85. 8 0
      tools/perf/ui/browsers/hists.c
  86. 2 0
      tools/perf/ui/browsers/map.c
  87. 1 1
      tools/perf/ui/gtk/annotate.c
  88. 1 0
      tools/perf/ui/gtk/hists.c
  89. 1 0
      tools/perf/ui/hist.c
  90. 1 0
      tools/perf/ui/setup.c
  91. 3 1
      tools/perf/ui/stdio/hist.c
  92. 1 0
      tools/perf/ui/tui/setup.c
  93. 1 0
      tools/perf/util/Build
  94. 6 0
      tools/perf/util/annotate.c
  95. 4 2
      tools/perf/util/auxtrace.c
  96. 1 0
      tools/perf/util/auxtrace.h
  97. 3 0
      tools/perf/util/bpf-loader.c
  98. 2 0
      tools/perf/util/bpf-loader.h
  99. 1 0
      tools/perf/util/bpf-prologue.c
  100. 2 0
      tools/perf/util/bpf-prologue.h

+ 10 - 0
tools/include/linux/bug.h

@@ -0,0 +1,10 @@
+#ifndef _TOOLS_PERF_LINUX_BUG_H
+#define _TOOLS_PERF_LINUX_BUG_H
+
+/* Force a compilation error if condition is true, but also produce a
+   result (of value 0 and type size_t), so the expression can be used
+   e.g. in a structure initializer (or where-ever else comma expressions
+   aren't permitted). */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+
+#endif	/* _TOOLS_PERF_LINUX_BUG_H */

+ 3 - 0
tools/include/linux/compiler-gcc.h

@@ -16,3 +16,6 @@
 #if GCC_VERSION >= 40300
 # define __compiletime_error(message) __attribute__((error(message)))
 #endif /* GCC_VERSION >= 40300 */
+
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))

+ 5 - 0
tools/include/linux/compiler.h

@@ -17,6 +17,11 @@
 # define __always_inline	inline __attribute__((always_inline))
 #endif
 
+/* Are two types/vars the same type (ignoring qualifiers)? */
+#ifndef __same_type
+# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+#endif
+
 #ifdef __ANDROID__
 /*
  * FIXME: Big hammer to get rid of tons of:

+ 0 - 4
tools/include/linux/hashtable.h

@@ -13,10 +13,6 @@
 #include <linux/hash.h>
 #include <linux/log2.h>
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define DEFINE_HASHTABLE(name, bits)						\
 	struct hlist_head name[1 << (bits)] =					\
 			{ [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT }

+ 3 - 0
tools/include/linux/kernel.h

@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <assert.h>
+#include <linux/compiler.h>
 
 #ifndef UINT_MAX
 #define UINT_MAX	(~0U)
@@ -76,6 +77,8 @@
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+
 /*
  * This looks more complex than it should be. But we need to
  * get the type for the ~ right in round_down (it needs to be

+ 3 - 0
tools/include/linux/log2.h

@@ -12,6 +12,9 @@
 #ifndef _TOOLS_LINUX_LOG2_H
 #define _TOOLS_LINUX_LOG2_H
 
+#include <linux/bitops.h>
+#include <linux/types.h>
+
 /*
  * non-constant log of base 2 calculators
  * - the arch may override these in asm/bitops.h if they can be implemented

+ 1 - 0
tools/lib/symbol/kallsyms.c

@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include "symbol/kallsyms.h"
 #include <stdio.h>
 #include <stdlib.h>

+ 1 - 2
tools/objtool/builtin-check.c

@@ -36,8 +36,7 @@
 #include "warn.h"
 
 #include <linux/hashtable.h>
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#include <linux/kernel.h>
 
 #define STATE_FP_SAVED		0x1
 #define STATE_FP_SETUP		0x2

+ 1 - 2
tools/objtool/objtool.c

@@ -31,11 +31,10 @@
 #include <stdlib.h>
 #include <subcmd/exec-cmd.h>
 #include <subcmd/pager.h>
+#include <linux/kernel.h>
 
 #include "builtin.h"
 
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-
 struct cmd_struct {
 	const char *name;
 	int (*fn)(int, const char **);

+ 1 - 0
tools/perf/MANIFEST

@@ -64,6 +64,7 @@ tools/include/linux/bitops.h
 tools/include/linux/compiler.h
 tools/include/linux/compiler-gcc.h
 tools/include/linux/coresight-pmu.h
+tools/include/linux/bug.h
 tools/include/linux/filter.h
 tools/include/linux/hash.h
 tools/include/linux/kernel.h

+ 2 - 2
tools/perf/arch/arm/util/dwarf-regs.c

@@ -9,6 +9,7 @@
  */
 
 #include <stddef.h>
+#include <linux/stringify.h>
 #include <dwarf-regs.h>
 
 struct pt_regs_dwarfnum {
@@ -16,10 +17,9 @@ struct pt_regs_dwarfnum {
 	unsigned int dwarfnum;
 };
 
-#define STR(s) #s
 #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
 #define GPR_DWARFNUM_NAME(num) \
-	{.name = STR(%r##num), .dwarfnum = num}
+	{.name = __stringify(%r##num), .dwarfnum = num}
 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
 
 /*

+ 3 - 1
tools/perf/arch/arm64/util/dwarf-regs.c

@@ -8,9 +8,11 @@
  * published by the Free Software Foundation.
  */
 
+#include <errno.h>
 #include <stddef.h>
 #include <dwarf-regs.h>
 #include <linux/ptrace.h> /* for struct user_pt_regs */
+#include <linux/stringify.h>
 #include "util.h"
 
 struct pt_regs_dwarfnum {
@@ -20,7 +22,7 @@ struct pt_regs_dwarfnum {
 
 #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
 #define GPR_DWARFNUM_NAME(num) \
-	{.name = STR(%x##num), .dwarfnum = num}
+	{.name = __stringify(%x##num), .dwarfnum = num}
 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
 #define DWARFNUM2OFFSET(index) \
 	(index * sizeof((struct user_pt_regs *)0)->regs[0])

+ 1 - 1
tools/perf/arch/arm64/util/unwind-libunwind.c

@@ -1,6 +1,6 @@
+#include <errno.h>
 
 #ifndef REMOTE_UNWIND_LIBUNWIND
-#include <errno.h>
 #include <libunwind.h>
 #include "perf_regs.h"
 #include "../../util/unwind.h"

+ 2 - 0
tools/perf/arch/common.c

@@ -4,6 +4,8 @@
 #include "../util/util.h"
 #include "../util/debug.h"
 
+#include "sane_ctype.h"
+
 const char *const arm_triplets[] = {
 	"arm-eabi-",
 	"arm-linux-androideabi-",

+ 3 - 2
tools/perf/arch/powerpc/util/dwarf-regs.c

@@ -15,6 +15,7 @@
 #include <dwarf-regs.h>
 #include <linux/ptrace.h>
 #include <linux/kernel.h>
+#include <linux/stringify.h>
 #include "util.h"
 
 struct pt_regs_dwarfnum {
@@ -24,10 +25,10 @@ struct pt_regs_dwarfnum {
 };
 
 #define REG_DWARFNUM_NAME(r, num)					\
-		{.name = STR(%)STR(r), .dwarfnum = num,			\
+		{.name = __stringify(%)__stringify(r), .dwarfnum = num,			\
 		.ptregs_offset = offsetof(struct pt_regs, r)}
 #define GPR_DWARFNUM_NAME(num)						\
-		{.name = STR(%gpr##num), .dwarfnum = num,		\
+		{.name = __stringify(%gpr##num), .dwarfnum = num,		\
 		.ptregs_offset = offsetof(struct pt_regs, gpr[num])}
 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
 

+ 1 - 0
tools/perf/arch/powerpc/util/kvm-stat.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include "util/kvm-stat.h"
 #include "util/parse-events.h"
 #include "util/debug.h"

+ 1 - 0
tools/perf/arch/powerpc/util/perf_regs.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <string.h>
 #include <regex.h>
 

+ 1 - 0
tools/perf/arch/s390/util/kvm-stat.c

@@ -9,6 +9,7 @@
  * as published by the Free Software Foundation.
  */
 
+#include <errno.h>
 #include "../../util/kvm-stat.h"
 #include <asm/sie.h>
 

+ 1 - 0
tools/perf/arch/x86/tests/intel-cqm.c

@@ -7,6 +7,7 @@
 #include "arch-tests.h"
 
 #include <sys/mman.h>
+#include <errno.h>
 #include <string.h>
 
 static pid_t spawn(void)

+ 2 - 0
tools/perf/arch/x86/tests/perf-time-to-tsc.c

@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <linux/types.h>

+ 1 - 0
tools/perf/arch/x86/util/auxtrace.c

@@ -13,6 +13,7 @@
  *
  */
 
+#include <errno.h>
 #include <stdbool.h>
 
 #include "../../util/header.h"

+ 1 - 0
tools/perf/arch/x86/util/intel-bts.c

@@ -13,6 +13,7 @@
  *
  */
 
+#include <errno.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/bitops.h>

+ 1 - 0
tools/perf/arch/x86/util/intel-pt.c

@@ -13,6 +13,7 @@
  *
  */
 
+#include <errno.h>
 #include <stdbool.h>
 #include <linux/kernel.h>
 #include <linux/types.h>

+ 1 - 0
tools/perf/arch/x86/util/kvm-stat.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include "../../util/kvm-stat.h"
 #include <asm/svm.h>
 #include <asm/vmx.h>

+ 1 - 0
tools/perf/arch/x86/util/perf_regs.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <string.h>
 #include <regex.h>
 

+ 1 - 0
tools/perf/bench/mem-functions.c

@@ -12,6 +12,7 @@
 #include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "../util/cloexec.h"
+#include "../util/string2.h"
 #include "bench.h"
 #include "mem-memcpy-arch.h"
 #include "mem-memset-arch.h"

+ 2 - 0
tools/perf/bench/numa.c

@@ -4,6 +4,7 @@
  * numa: Simulate NUMA-sensitive workload and measure their NUMA performance
  */
 
+#include <inttypes.h>
 /* For the CLR_() macros */
 #include <pthread.h>
 
@@ -30,6 +31,7 @@
 #include <sys/wait.h>
 #include <sys/prctl.h>
 #include <sys/types.h>
+#include <linux/kernel.h>
 #include <linux/time64.h>
 
 #include <numa.h>

+ 1 - 0
tools/perf/builtin-annotate.c

@@ -33,6 +33,7 @@
 #include "util/block-range.h"
 
 #include <dlfcn.h>
+#include <errno.h>
 #include <linux/bitmap.h>
 
 struct perf_annotate {

+ 1 - 0
tools/perf/builtin-buildid-cache.c

@@ -10,6 +10,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include <dirent.h>
+#include <errno.h>
 #include <unistd.h>
 #include "builtin.h"
 #include "perf.h"

+ 1 - 0
tools/perf/builtin-buildid-list.c

@@ -16,6 +16,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/data.h"
+#include <errno.h>
 
 static int sysfs__fprintf_build_id(FILE *fp)
 {

+ 2 - 0
tools/perf/builtin-c2c.c

@@ -9,6 +9,8 @@
  *   Dick Fowles <fowles@inreach.com>
  *   Joe Mario <jmario@redhat.com>
  */
+#include <errno.h>
+#include <inttypes.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/stringify.h>

+ 2 - 0
tools/perf/builtin-diff.c

@@ -19,6 +19,8 @@
 #include "util/data.h"
 #include "util/config.h"
 
+#include <errno.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <math.h>
 

+ 2 - 0
tools/perf/builtin-ftrace.c

@@ -9,12 +9,14 @@
 #include "builtin.h"
 #include "perf.h"
 
+#include <errno.h>
 #include <unistd.h>
 #include <signal.h>
 #include <fcntl.h>
 
 #include "debug.h"
 #include <subcmd/parse-options.h>
+#include <api/fs/tracing_path.h>
 #include "evlist.h"
 #include "target.h"
 #include "cpumap.h"

+ 4 - 2
tools/perf/builtin-help.c

@@ -12,16 +12,18 @@
 #include <subcmd/run-command.h>
 #include <subcmd/help.h>
 #include "util/debug.h"
+#include <linux/kernel.h>
+#include <errno.h>
 
 static struct man_viewer_list {
 	struct man_viewer_list *next;
-	char name[FLEX_ARRAY];
+	char name[0];
 } *man_viewer_list;
 
 static struct man_viewer_info_list {
 	struct man_viewer_info_list *next;
 	const char *info;
-	char name[FLEX_ARRAY];
+	char name[0];
 } *man_viewer_info_list;
 
 enum help_format {

+ 1 - 0
tools/perf/builtin-inject.c

@@ -22,6 +22,7 @@
 #include <subcmd/parse-options.h>
 
 #include <linux/list.h>
+#include <errno.h>
 
 struct perf_inject {
 	struct perf_tool	tool;

+ 1 - 0
tools/perf/builtin-kallsyms.c

@@ -7,6 +7,7 @@
  *
  * Released under the GPL v2. (and only v2, not any later version)
  */
+#include <inttypes.h>
 #include "builtin.h"
 #include <linux/compiler.h>
 #include <subcmd/parse-options.h>

+ 5 - 0
tools/perf/builtin-kmem.c

@@ -20,11 +20,16 @@
 
 #include "util/debug.h"
 
+#include <linux/kernel.h>
 #include <linux/rbtree.h>
 #include <linux/string.h>
+#include <errno.h>
+#include <inttypes.h>
 #include <locale.h>
 #include <regex.h>
 
+#include "sane_ctype.h"
+
 static int	kmem_slab;
 static int	kmem_page;
 

+ 4 - 0
tools/perf/builtin-kvm.c

@@ -3,6 +3,7 @@
 
 #include "util/evsel.h"
 #include "util/evlist.h"
+#include "util/term.h"
 #include "util/util.h"
 #include "util/cache.h"
 #include "util/symbol.h"
@@ -24,7 +25,10 @@
 #include <sys/timerfd.h>
 #endif
 
+#include <linux/kernel.h>
 #include <linux/time64.h>
+#include <errno.h>
+#include <inttypes.h>
 #include <termios.h>
 #include <semaphore.h>
 #include <pthread.h>

+ 3 - 0
tools/perf/builtin-lock.c

@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <inttypes.h>
 #include "builtin.h"
 #include "perf.h"
 
@@ -26,6 +28,7 @@
 
 #include <linux/list.h>
 #include <linux/hash.h>
+#include <linux/kernel.h>
 
 static struct perf_session *session;
 

+ 1 - 0
tools/perf/builtin-mem.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include "builtin.h"
 #include "perf.h"
 

+ 2 - 0
tools/perf/builtin-record.c

@@ -40,6 +40,8 @@
 #include "util/perf-hooks.h"
 #include "asm/bug.h"
 
+#include <errno.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <sched.h>
 #include <sys/mman.h>

+ 3 - 1
tools/perf/builtin-report.c

@@ -16,7 +16,6 @@
 #include <linux/rbtree.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
-#include "util/strlist.h"
 #include "util/values.h"
 
 #include "perf.h"
@@ -40,6 +39,9 @@
 #include "util/auxtrace.h"
 
 #include <dlfcn.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <regex.h>
 #include <linux/bitmap.h>
 #include <linux/stringify.h>
 

+ 5 - 0
tools/perf/builtin-sched.c

@@ -22,16 +22,21 @@
 
 #include "util/debug.h"
 
+#include <linux/kernel.h>
 #include <linux/log2.h>
 #include <sys/prctl.h>
 #include <sys/resource.h>
+#include <inttypes.h>
 
+#include <errno.h>
 #include <semaphore.h>
 #include <pthread.h>
 #include <math.h>
 #include <api/fs/fs.h>
 #include <linux/time64.h>
 
+#include "sane_ctype.h"
+
 #define PR_SET_NAME		15               /* Set process name */
 #define MAX_CPUS		4096
 #define COMM_LEN		20

+ 8 - 0
tools/perf/builtin-script.c

@@ -21,14 +21,22 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/stat.h"
+#include "util/string2.h"
 #include "util/thread-stack.h"
 #include "util/time-utils.h"
+#include "print_binary.h"
 #include <linux/bitmap.h>
+#include <linux/kernel.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
 #include "asm/bug.h"
 #include "util/mem-events.h"
 #include "util/dump-insn.h"
+#include <dirent.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include "sane_ctype.h"
 
 static char const		*script_name;
 static char const		*generate_script_lang;

+ 5 - 0
tools/perf/builtin-stat.c

@@ -64,15 +64,20 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/group.h"
+#include "util/string2.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
 #include <api/fs/fs.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <sys/prctl.h>
+#include <inttypes.h>
 #include <locale.h>
 #include <math.h>
 
+#include "sane_ctype.h"
+
 #define DEFAULT_SEPARATOR	" "
 #define CNTR_NOT_SUPPORTED	"<not supported>"
 #define CNTR_NOT_COUNTED	"<not counted>"

+ 3 - 1
tools/perf/builtin-timechart.c

@@ -12,6 +12,8 @@
  * of the License.
  */
 
+#include <errno.h>
+#include <inttypes.h>
 #include <traceevent/event-parse.h>
 
 #include "builtin.h"
@@ -23,11 +25,11 @@
 #include "util/cache.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
+#include <linux/kernel.h>
 #include <linux/rbtree.h>
 #include <linux/time64.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
-#include "util/strlist.h"
 
 #include "perf.h"
 #include "util/header.h"

+ 3 - 0
tools/perf/builtin-top.c

@@ -40,6 +40,7 @@
 #include "util/cpumap.h"
 #include "util/xyarray.h"
 #include "util/sort.h"
+#include "util/term.h"
 #include "util/intlist.h"
 #include "util/parse-branch-options.h"
 #include "arch/common.h"
@@ -72,6 +73,8 @@
 #include <linux/time64.h>
 #include <linux/types.h>
 
+#include "sane_ctype.h"
+
 static volatile int done;
 
 #define HEADER_LINE_NR  5

+ 8 - 0
tools/perf/builtin-trace.c

@@ -24,6 +24,7 @@
 #include "util/evlist.h"
 #include <subcmd/exec-cmd.h>
 #include "util/machine.h"
+#include "util/path.h"
 #include "util/session.h"
 #include "util/thread.h"
 #include <subcmd/parse-options.h>
@@ -36,19 +37,26 @@
 #include "util/parse-events.h"
 #include "util/bpf-loader.h"
 #include "callchain.h"
+#include "print_binary.h"
+#include "string2.h"
 #include "syscalltbl.h"
 #include "rb_resort.h"
 
+#include <errno.h>
+#include <inttypes.h>
 #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
 #include <stdlib.h>
 #include <string.h>
 #include <linux/err.h>
 #include <linux/filter.h>
 #include <linux/audit.h>
+#include <linux/kernel.h>
 #include <linux/random.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
 
+#include "sane_ctype.h"
+
 #ifndef O_CLOEXEC
 # define O_CLOEXEC		02000000
 #endif

+ 2 - 10
tools/perf/perf.c

@@ -19,9 +19,11 @@
 #include "util/debug.h"
 #include <api/fs/fs.h>
 #include <api/fs/tracing_path.h>
+#include <errno.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <time.h>
+#include <linux/kernel.h>
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
@@ -327,16 +329,6 @@ static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
 	unsigned int i;
-	static const char ext[] = STRIP_EXTENSION;
-
-	if (sizeof(ext) > 1) {
-		i = strlen(argv[0]) - strlen(ext);
-		if (i > 0 && !strcmp(argv[0] + i, ext)) {
-			char *argv0 = strdup(argv[0]);
-			argv[0] = cmd = argv0;
-			argv0[i] = '\0';
-		}
-	}
 
 	/* Turn "perf cmd --help" into "perf help cmd" */
 	if (argc > 1 && !strcmp(argv[1], "--help")) {

+ 2 - 0
tools/perf/tests/attr.c

@@ -18,6 +18,8 @@
  * permissions. All the event text files are stored there.
  */
 
+#include <errno.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <linux/types.h>

+ 1 - 0
tools/perf/tests/backward-ring-buffer.c

@@ -8,6 +8,7 @@
 #include <sys/prctl.h>
 #include "tests.h"
 #include "debug.h"
+#include <errno.h>
 
 #define NR_ITERS 111
 

+ 2 - 0
tools/perf/tests/bpf.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <stdio.h>
 #include <sys/epoll.h>
 #include <util/util.h>
@@ -5,6 +6,7 @@
 #include <util/evlist.h>
 #include <linux/bpf.h>
 #include <linux/filter.h>
+#include <linux/kernel.h>
 #include <api/fs/fs.h>
 #include <bpf/bpf.h>
 #include "tests.h"

+ 2 - 0
tools/perf/tests/builtin-test.c

@@ -3,6 +3,7 @@
  *
  * Builtin regression testing command: ever growing number of sanity tests
  */
+#include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include "builtin.h"
@@ -13,6 +14,7 @@
 #include "color.h"
 #include <subcmd/parse-options.h>
 #include "symbol.h"
+#include <linux/kernel.h>
 
 static bool dont_fork;
 

+ 1 - 0
tools/perf/tests/clang.c

@@ -2,6 +2,7 @@
 #include "debug.h"
 #include "util.h"
 #include "c++/clang-c.h"
+#include <linux/kernel.h>
 
 static struct {
 	int (*func)(void);

+ 5 - 1
tools/perf/tests/code-reading.c

@@ -1,8 +1,10 @@
+#include <errno.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <ctype.h>
 #include <string.h>
 
 #include "parse-events.h"
@@ -16,6 +18,8 @@
 
 #include "tests.h"
 
+#include "sane_ctype.h"
+
 #define BUFSZ	1024
 #define READLEN	128
 

+ 2 - 0
tools/perf/tests/dso-data.c

@@ -1,4 +1,6 @@
+#include <dirent.h>
 #include <stdlib.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>

+ 1 - 0
tools/perf/tests/dwarf-unwind.c

@@ -1,5 +1,6 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include "tests.h"
 #include "debug.h"

+ 2 - 0
tools/perf/tests/event-times.c

@@ -1,4 +1,6 @@
 #include <linux/compiler.h>
+#include <errno.h>
+#include <inttypes.h>
 #include <string.h>
 #include "tests.h"
 #include "evlist.h"

+ 2 - 0
tools/perf/tests/evsel-roundtrip-name.c

@@ -3,6 +3,8 @@
 #include "parse-events.h"
 #include "tests.h"
 #include "debug.h"
+#include <errno.h>
+#include <linux/kernel.h>
 
 static int perf_evsel__roundtrip_cache_name_test(void)
 {

+ 2 - 0
tools/perf/tests/hists_common.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include "perf.h"
 #include "util/debug.h"
 #include "util/symbol.h"
@@ -7,6 +8,7 @@
 #include "util/machine.h"
 #include "util/thread.h"
 #include "tests/hists_common.h"
+#include <linux/kernel.h>
 
 static struct {
 	u32 pid;

+ 1 - 0
tools/perf/tests/hists_cumulate.c

@@ -9,6 +9,7 @@
 #include "util/parse-events.h"
 #include "tests/tests.h"
 #include "tests/hists_common.h"
+#include <linux/kernel.h>
 
 struct sample {
 	u32 pid;

+ 1 - 0
tools/perf/tests/hists_filter.c

@@ -9,6 +9,7 @@
 #include "util/parse-events.h"
 #include "tests/tests.h"
 #include "tests/hists_common.h"
+#include <linux/kernel.h>
 
 struct sample {
 	u32 pid;

+ 2 - 0
tools/perf/tests/hists_link.c

@@ -9,6 +9,8 @@
 #include "thread.h"
 #include "parse-events.h"
 #include "hists_common.h"
+#include <errno.h>
+#include <linux/kernel.h>
 
 struct sample {
 	u32 pid;

+ 1 - 0
tools/perf/tests/hists_output.c

@@ -9,6 +9,7 @@
 #include "util/parse-events.h"
 #include "tests/tests.h"
 #include "tests/hists_common.h"
+#include <linux/kernel.h>
 
 struct sample {
 	u32 cpu;

+ 2 - 1
tools/perf/tests/is_printable_array.c

@@ -1,7 +1,8 @@
 #include <linux/compiler.h>
+#include <linux/kernel.h>
 #include "tests.h"
 #include "debug.h"
-#include "util.h"
+#include "print_binary.h"
 
 int test__is_printable_array(int subtest __maybe_unused)
 {

+ 3 - 0
tools/perf/tests/mmap-basic.c

@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <inttypes.h>
 /* For the CLR_() macros */
 #include <pthread.h>
 
@@ -7,6 +9,7 @@
 #include "cpumap.h"
 #include "tests.h"
 #include <linux/err.h>
+#include <linux/kernel.h>
 
 /*
  * This test will generate random numbers of calls to some getpid syscalls,

+ 2 - 0
tools/perf/tests/mmap-thread-lookup.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
@@ -11,6 +12,7 @@
 #include "thread_map.h"
 #include "symbol.h"
 #include "thread.h"
+#include "util.h"
 
 #define THREADS 4
 

+ 6 - 0
tools/perf/tests/openat-syscall-all-cpus.c

@@ -1,8 +1,14 @@
+#include <errno.h>
+#include <inttypes.h>
 /* For the CPU_* macros */
 #include <pthread.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <api/fs/fs.h>
 #include <linux/err.h>
+#include <api/fs/tracing_path.h>
 #include "evsel.h"
 #include "tests.h"
 #include "thread_map.h"

+ 1 - 0
tools/perf/tests/openat-syscall-tp-fields.c

@@ -5,6 +5,7 @@
 #include "thread_map.h"
 #include "tests.h"
 #include "debug.h"
+#include <errno.h>
 
 #ifndef O_DIRECTORY
 #define O_DIRECTORY    00200000

+ 5 - 0
tools/perf/tests/openat-syscall.c

@@ -1,5 +1,10 @@
+#include <errno.h>
+#include <inttypes.h>
 #include <api/fs/tracing_path.h>
 #include <linux/err.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include "thread_map.h"
 #include "evsel.h"
 #include "debug.h"

+ 4 - 1
tools/perf/tests/parse-events.c

@@ -1,4 +1,3 @@
-
 #include "parse-events.h"
 #include "evsel.h"
 #include "evlist.h"
@@ -6,8 +5,12 @@
 #include "tests.h"
 #include "debug.h"
 #include "util.h"
+#include <dirent.h>
+#include <errno.h>
+#include <linux/kernel.h>
 #include <linux/hw_breakpoint.h>
 #include <api/fs/fs.h>
+#include <api/fs/tracing_path.h>
 
 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
 			     PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)

+ 1 - 0
tools/perf/tests/parse-no-sample-id-all.c

@@ -1,3 +1,4 @@
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <stddef.h>
 

+ 2 - 0
tools/perf/tests/perf-record.c

@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <inttypes.h>
 /* For the CLR_() macros */
 #include <pthread.h>
 

+ 2 - 0
tools/perf/tests/pmu.c

@@ -2,6 +2,8 @@
 #include "pmu.h"
 #include "util.h"
 #include "tests.h"
+#include <errno.h>
+#include <linux/kernel.h>
 
 /* Simulated format definitions. */
 static struct test_format {

+ 2 - 0
tools/perf/tests/sample-parsing.c

@@ -1,4 +1,6 @@
 #include <stdbool.h>
+#include <inttypes.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
 
 #include "util.h"

+ 1 - 0
tools/perf/tests/sdt.c

@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <stdio.h>
 #include <sys/epoll.h>
 #include <util/util.h>

+ 2 - 0
tools/perf/tests/sw-clock.c

@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <signal.h>

+ 1 - 0
tools/perf/tests/switch-tracking.c

@@ -1,5 +1,6 @@
 #include <sys/time.h>
 #include <sys/prctl.h>
+#include <errno.h>
 #include <time.h>
 #include <stdlib.h>
 

+ 1 - 0
tools/perf/tests/task-exit.c

@@ -4,6 +4,7 @@
 #include "cpumap.h"
 #include "tests.h"
 
+#include <errno.h>
 #include <signal.h>
 
 static int exited;

+ 1 - 0
tools/perf/tests/unit_number__scnprintf.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include "tests.h"

+ 1 - 0
tools/perf/tests/vmlinux-kallsyms.c

@@ -1,5 +1,6 @@
 #include <linux/compiler.h>
 #include <linux/rbtree.h>
+#include <inttypes.h>
 #include <string.h>
 #include "map.h"
 #include "symbol.h"

+ 2 - 0
tools/perf/ui/browser.c

@@ -1,4 +1,5 @@
 #include "../util.h"
+#include "../string2.h"
 #include "../config.h"
 #include "../../perf.h"
 #include "libslang.h"
@@ -13,6 +14,7 @@
 #include "helpline.h"
 #include "keysyms.h"
 #include "../color.h"
+#include "sane_ctype.h"
 
 static int ui_browser__percent_color(struct ui_browser *browser,
 				     double percent, bool current)

+ 3 - 0
tools/perf/ui/browsers/annotate.c

@@ -9,7 +9,10 @@
 #include "../../util/symbol.h"
 #include "../../util/evsel.h"
 #include "../../util/config.h"
+#include <inttypes.h>
 #include <pthread.h>
+#include <linux/kernel.h>
+#include <sys/ttydefaults.h>
 
 struct disasm_line_samples {
 	double		percent;

+ 2 - 0
tools/perf/ui/browsers/header.c

@@ -8,6 +8,8 @@
 #include "util/header.h"
 #include "util/session.h"
 
+#include <sys/ttydefaults.h>
+
 static void ui_browser__argv_write(struct ui_browser *browser,
 				   void *entry, int row)
 {

+ 8 - 0
tools/perf/ui/browsers/hists.c

@@ -1,7 +1,11 @@
+#include <dirent.h>
+#include <errno.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <linux/rbtree.h>
+#include <sys/ttydefaults.h>
 
 #include "../../util/evsel.h"
 #include "../../util/evlist.h"
@@ -18,6 +22,10 @@
 #include "../ui.h"
 #include "map.h"
 #include "annotate.h"
+#include "srcline.h"
+#include "string2.h"
+
+#include "sane_ctype.h"
 
 extern void hist_browser__init_hpp(void);
 

+ 2 - 0
tools/perf/ui/browsers/map.c

@@ -11,6 +11,8 @@
 #include "../keysyms.h"
 #include "map.h"
 
+#include "sane_ctype.h"
+
 struct map_browser {
 	struct ui_browser b;
 	struct map	  *map;

+ 1 - 1
tools/perf/ui/gtk/annotate.c

@@ -3,7 +3,7 @@
 #include "util/annotate.h"
 #include "util/evsel.h"
 #include "ui/helpline.h"
-
+#include <inttypes.h>
 
 enum {
 	ANN_COL__PERCENT,

+ 1 - 0
tools/perf/ui/gtk/hists.c

@@ -4,6 +4,7 @@
 #include "../sort.h"
 #include "../hist.h"
 #include "../helpline.h"
+#include "../string2.h"
 #include "gtk.h"
 
 #define MAX_COLUMNS			32

+ 1 - 0
tools/perf/ui/hist.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <math.h>
 #include <linux/compiler.h>
 

+ 1 - 0
tools/perf/ui/setup.c

@@ -4,6 +4,7 @@
 #include "../util/cache.h"
 #include "../util/debug.h"
 #include "../util/hist.h"
+#include "../util/util.h"
 
 pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
 void *perf_gtk_handle;

+ 3 - 1
tools/perf/ui/stdio/hist.c

@@ -4,7 +4,9 @@
 #include "../../util/hist.h"
 #include "../../util/sort.h"
 #include "../../util/evsel.h"
-
+#include "../../util/srcline.h"
+#include "../../util/string2.h"
+#include "../../util/sane_ctype.h"
 
 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
 {

+ 1 - 0
tools/perf/ui/tui/setup.c

@@ -1,6 +1,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdbool.h>
+#include <linux/kernel.h>
 #ifdef HAVE_BACKTRACE_SUPPORT
 #include <execinfo.h>
 #endif

+ 1 - 0
tools/perf/util/Build

@@ -16,6 +16,7 @@ libperf-y += llvm-utils.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
+libperf-y += print_binary.o
 libperf-y += rbtree.o
 libperf-y += libstring.o
 libperf-y += bitmap.o

+ 6 - 0
tools/perf/util/annotate.c

@@ -7,6 +7,8 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 
+#include <errno.h>
+#include <inttypes.h>
 #include "util.h"
 #include "ui/ui.h"
 #include "sort.h"
@@ -18,12 +20,16 @@
 #include "annotate.h"
 #include "evsel.h"
 #include "block-range.h"
+#include "string2.h"
 #include "arch/common.h"
 #include <regex.h>
 #include <pthread.h>
 #include <linux/bitops.h>
+#include <linux/kernel.h>
 #include <sys/utsname.h>
 
+#include "sane_ctype.h"
+
 const char 	*disassembler_style;
 const char	*objdump_path;
 static regex_t	 file_lineno;

+ 4 - 2
tools/perf/util/auxtrace.c

@@ -13,10 +13,10 @@
  *
  */
 
+#include <inttypes.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <stdbool.h>
-#include <ctype.h>
 #include <string.h>
 #include <limits.h>
 #include <errno.h>
@@ -46,7 +46,6 @@
 #include "cpumap.h"
 #include "thread_map.h"
 #include "asm/bug.h"
-#include "symbol/kallsyms.h"
 #include "auxtrace.h"
 
 #include <linux/hash.h>
@@ -59,6 +58,9 @@
 #include "intel-pt.h"
 #include "intel-bts.h"
 
+#include "sane_ctype.h"
+#include "symbol/kallsyms.h"
+
 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
 			struct auxtrace_mmap_params *mp,
 			void *userpg, int fd)

+ 1 - 0
tools/perf/util/auxtrace.h

@@ -17,6 +17,7 @@
 #define __PERF_AUXTRACE_H
 
 #include <sys/types.h>
+#include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <linux/list.h>

+ 3 - 0
tools/perf/util/bpf-loader.c

@@ -9,7 +9,9 @@
 #include <bpf/libbpf.h>
 #include <bpf/bpf.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
 #include <linux/string.h>
+#include <errno.h>
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
@@ -17,6 +19,7 @@
 #include "probe-event.h"
 #include "probe-finder.h" // for MAX_PROBES
 #include "parse-events.h"
+#include "strfilter.h"
 #include "llvm-utils.h"
 #include "c++/clang-c.h"
 

+ 2 - 0
tools/perf/util/bpf-loader.h

@@ -85,6 +85,8 @@ int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err,
 			       char *buf, size_t size);
 
 #else
+#include <errno.h>
+
 static inline struct bpf_object *
 bpf__prepare_load(const char *filename __maybe_unused,
 		  bool source __maybe_unused)

+ 1 - 0
tools/perf/util/bpf-prologue.c

@@ -12,6 +12,7 @@
 #include "bpf-loader.h"
 #include "bpf-prologue.h"
 #include "probe-finder.h"
+#include <errno.h>
 #include <dwarf-regs.h>
 #include <linux/filter.h>
 

+ 2 - 0
tools/perf/util/bpf-prologue.h

@@ -18,6 +18,8 @@ int bpf__gen_prologue(struct probe_trace_arg *args, int nargs,
 		      struct bpf_insn *new_prog, size_t *new_cnt,
 		      size_t cnt_space);
 #else
+#include <errno.h>
+
 static inline int
 bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused,
 		  int nargs __maybe_unused,

Неке датотеке нису приказане због велике количине промена