linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL 00/12] perf/urgent fixes
@ 2017-01-04 17:24 Arnaldo Carvalho de Melo
  2017-01-04 17:24 ` [PATCH 01/12] perf sched timehist: Show total scheduling time Arnaldo Carvalho de Melo
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	Alexander Shishkin, Alexei Starovoitov, Daniel Borkmann,
	Daniel Bristot de Oliveira, David Ahern, Jiri Olsa, Joe Stringer,
	Josh Poimboeuf, Markus Trippelsdorf, Masami Hiramatsu,
	Namhyung Kim, Peter Zijlstra, Steven Rostedt, Wang Nan,
	Arnaldo Carvalho de Melo

Hi Ingo,

	Please consider pulling,

- Arnaldo

Test results at the end of this message, as usual, news about it:

Has two new targets, debian:experimental-x-mipsel and
debian:experimental-x-arm64.

Those use debian's multi-arch packages allowing cross building more than with
the other crossbuild containers.

This still doesn't generate a full featured tool, as there are some buggy
multi-arch packages, such as the devel packages for perl, gtk2, etc.

The following changes since commit 3705b97505bcbf6440f38119c0e7d6058f585b54:

  Merge tag 'perf-urgent-for-mingo-20161222' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2016-12-23 20:23:29 +0100)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo-4.10-20170104

for you to fetch changes up to 8a937a25a7e3c19d5fb3f9d92f605cf5fda219d8:

  perf probe: Fix to probe on gcc generated symbols for offline kernel (2017-01-04 11:44:22 -0300)

----------------------------------------------------------------
perf/urgent fixes and one improvement:

Fixes:

- Fix prev/next_prio formatting for deadline tasks in libtraceevent (Daniel Bristot de Oliveira)

- Robustify reading of build-ids from /sys/kernel/note (Arnaldo Carvalho de Melo)

- Fix building some sample/bpf in Alpine Linux 3.4 (Arnaldo Carvalho de Melo)

- Fix 'make install-bin' to install libtraceevent plugins (Arnaldo Carvalho de Melo)

- Fix 'perf record --switch-output' documentation and comment (Jiri Olsa)

- 'perf probe' fixes for cross arch probing (Masami Hiramatsu)

Improvement:

- Show total scheduling time in 'perf sched timehist' (Namhyumg Kim)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

----------------------------------------------------------------
Arnaldo Carvalho de Melo (4):
      samples/bpf sock_example: Avoid getting ethhdr from two includes
      samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include
      perf tools: Install tools/lib/traceevent plugins with install-bin
      perf symbols: Robustify reading of build-id from sysfs

Daniel Bristot de Oliveira (1):
      tools lib traceevent: Fix prev/next_prio for deadline tasks

Jiri Olsa (3):
      tools lib subcmd: Add OPT_STRING_OPTARG_SET option
      perf record: Make __record_options static
      perf record: Fix --switch-output documentation and comment

Masami Hiramatsu (3):
      perf probe: Fix to get correct modname from elf header
      perf probe: Fix --funcs to show correct symbols for offline module
      perf probe: Fix to probe on gcc generated symbols for offline kernel

Namhyung Kim (1):
      perf sched timehist: Show total scheduling time

 samples/bpf/sock_example.h                 |   2 +-
 samples/bpf/trace_output_user.c            |   1 -
 tools/lib/subcmd/parse-options.c           |   3 +
 tools/lib/subcmd/parse-options.h           |   5 ++
 tools/lib/traceevent/plugin_sched_switch.c |   4 +-
 tools/perf/Documentation/perf-record.txt   |   4 ++
 tools/perf/Makefile.perf                   |   4 +-
 tools/perf/builtin-record.c                |   4 +-
 tools/perf/builtin-sched.c                 |  17 ++++-
 tools/perf/util/probe-event.c              | 105 +++++++++++++++++++----------
 tools/perf/util/symbol-elf.c               |   6 ++
 11 files changed, 108 insertions(+), 47 deletions(-)

  # uname -a
  Linux jouet 4.9.0+ #2 SMP Wed Dec 21 11:54:44 BRT 2016 x86_64 x86_64 x86_64 GNU/Linux
  # perf test
   1: vmlinux symtab matches kallsyms            : Ok
   2: Detect openat syscall event                : Ok
   3: Detect openat syscall event on all cpus    : Ok
   4: Read samples using the mmap interface      : Ok
   5: Parse event definition strings             : Ok
   6: PERF_RECORD_* events & perf_sample fields  : Ok
   7: Parse perf pmu format                      : Ok
   8: DSO data read                              : Ok
   9: DSO data cache                             : Ok
  10: DSO data reopen                            : Ok
  11: Roundtrip evsel->name                      : Ok
  12: Parse sched tracepoints fields             : Ok
  13: syscalls:sys_enter_openat event fields     : Ok
  14: Setup struct perf_event_attr               : Ok
  15: Match and link multiple hists              : Ok
  16: 'import perf' in python                    : Ok
  17: Breakpoint overflow signal handler         : Ok
  18: Breakpoint overflow sampling               : Ok
  19: Number of exit events of a simple workload : Ok
  20: Software clock events period values        : Ok
  21: Object code reading                        : Ok
  22: Sample parsing                             : Ok
  23: Use a dummy software event to keep tracking: Ok
  24: Parse with no sample_id_all bit set        : Ok
  25: Filter hist entries                        : Ok
  26: Lookup mmap thread                         : Ok
  27: Share thread mg                            : Ok
  28: Sort output of hist entries                : Ok
  29: Cumulate child hist entries                : Ok
  30: Track with sched_switch                    : Ok
  31: Filter fds with revents mask in a fdarray  : Ok
  32: Add fd to a fdarray, making it autogrow    : Ok
  33: kmod_path__parse                           : Ok
  34: Thread map                                 : Ok
  35: LLVM search and compile                    :
  35.1: Basic BPF llvm compile                    : Ok
  35.2: kbuild searching                          : Ok
  35.3: Compile source for BPF prologue generation: Ok
  35.4: Compile source for BPF relocation         : Ok
  36: Session topology                           : Ok
  37: BPF filter                                 :
  37.1: Basic BPF filtering                      : Ok
  37.2: BPF prologue generation                  : Ok
  37.3: BPF relocation checker                   : Ok
  38: Synthesize thread map                      : Ok
  39: Remove thread map                          : Ok
  40: Synthesize cpu map                         : Ok
  41: Synthesize stat config                     : Ok
  42: Synthesize stat                            : Ok
  43: Synthesize stat round                      : Ok
  44: Synthesize attr update                     : Ok
  45: Event times                                : Ok
  46: Read backward ring buffer                  : Ok
  47: Print cpu map                              : Ok
  48: Probe SDT events                           : Ok
  49: is_printable_array                         : Ok
  50: Print bitmap                               : Ok
  51: perf hooks                                 : Ok
  52: builtin clang support                      : Skip (not compiled in)
  53: x86 rdpmc                                  : Ok
  54: Convert perf time to TSC                   : Ok
  55: DWARF unwind                               : Ok
  56: x86 instruction decoder - new instructions : Ok
  57: Intel cqm nmi context read                 : Skip
  #
  # time dm
   1 alpine:3.4: Ok
   2 android-ndk:r12b-arm: Ok
   3 archlinux:latest: Ok
   4 centos:5: Ok
   5 centos:6: Ok
   6 centos:7: Ok
   7 debian:7: Ok
   8 debian:8: Ok
   9 debian:experimental: Ok
  10 debian:experimental-x-arm64: Ok
  11 debian:experimental-x-mips64: Ok
  12 debian:experimental-x-mipsel: Ok
  13 fedora:20: Ok
  14 fedora:21: Ok
  15 fedora:22: Ok
  16 fedora:23: Ok
  17 fedora:24: Ok
  18 fedora:24-x-ARC-uClibc: Ok
  19 fedora:25: Ok
  20 fedora:rawhide: Ok
  21 mageia:5: Ok
  22 opensuse:13.2: Ok
  23 opensuse:42.1: Ok
  24 opensuse:tumbleweed: Ok
  25 ubuntu:12.04.5: Ok
  26 ubuntu:14.04.4-x-linaro-arm64: Ok
  27 ubuntu:15.10: Ok
  28 ubuntu:16.04: Ok
  29 ubuntu:16.04-x-arm: Ok
  30 ubuntu:16.04-x-arm64: Ok
  31 ubuntu:16.04-x-powerpc: Ok
  32 ubuntu:16.04-x-powerpc64: Ok
  33 ubuntu:16.04-x-powerpc64el: Ok
  34 ubuntu:16.04-x-s390: Ok
  35 ubuntu:16.10: Ok
  #
  $ uname -a
  Linux zoo 4.7.3-200.fc24.x86_64 #1 SMP Wed Sep 7 17:31:21 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 
  $ make -C tools/perf build-test
  make: Entering directory '/home/git/linux/tools/perf'
  - tarpkg: ./tests/perf-targz-src-pkg .
             make_no_libperl_O: make NO_LIBPERL=1
                  make_debug_O: make DEBUG=1
           make_no_libunwind_O: make NO_LIBUNWIND=1
           make_no_backtrace_O: make NO_BACKTRACE=1
        make_with_babeltrace_O: make LIBBABELTRACE=1
              make_clean_all_O: make clean all
           make_no_libpython_O: make NO_LIBPYTHON=1
                  make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
              make_no_libelf_O: make NO_LIBELF=1
   make_install_prefix_slash_O: make install prefix=/tmp/krava/
              make_no_libbpf_O: make NO_LIBBPF=1
            make_install_bin_O: make install-bin
                make_no_newt_O: make NO_NEWT=1
                   make_pure_O: make
             make_util_map_o_O: make util/map.o
             make_no_libnuma_O: make NO_LIBNUMA=1
                make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1
           make_no_libbionic_O: make NO_LIBBIONIC=1
            make_no_libaudit_O: make NO_LIBAUDIT=1
                make_no_gtk2_O: make NO_GTK2=1
         make_with_clangllvm_O: make LIBCLANGLLVM=1
                   make_tags_O: make tags
             make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
               make_no_slang_O: make NO_SLANG=1
                 make_static_O: make LDFLAGS=-static
            make_no_auxtrace_O: make NO_AUXTRACE=1
            make_no_demangle_O: make NO_DEMANGLE=1
                 make_perf_o_O: make perf.o
                    make_doc_O: make doc
       make_util_pmu_bison_o_O: make util/pmu-bison.o
                make_install_O: make install
                   make_help_O: make help
         make_install_prefix_O: make install prefix=/tmp/krava
  make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
  OK
  make: Leaving directory '/home/git/linux/tools/perf'
  $

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/12] perf sched timehist: Show total scheduling time
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
@ 2017-01-04 17:24 ` Arnaldo Carvalho de Melo
  2017-01-04 17:24 ` [PATCH 02/12] samples/bpf sock_example: Avoid getting ethhdr from two includes Arnaldo Carvalho de Melo
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Jiri Olsa, Peter Zijlstra,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

Show length of analyzed sample time and rate of idle task running.
This also takes care of time range given by --time option.

  $ perf sched timehist -sI | tail
  Samples do not have callchains.
  Idle stats:
      CPU  0 idle for    930.316  msec  ( 92.93%)
      CPU  1 idle for    963.614  msec  ( 96.25%)
      CPU  2 idle for    885.482  msec  ( 88.45%)
      CPU  3 idle for    938.635  msec  ( 93.76%)

      Total number of unique tasks: 118
  Total number of context switches: 2337
             Total run time (msec): 3718.048
      Total scheduling time (msec): 1001.131  (x 4)

Suggested-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20161222060350.17655-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-sched.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d53e706a6f17..5b134b0d1ff3 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -209,6 +209,7 @@ struct perf_sched {
 	u64		skipped_samples;
 	const char	*time_str;
 	struct perf_time_interval ptime;
+	struct perf_time_interval hist_time;
 };
 
 /* per thread run time data */
@@ -2460,6 +2461,11 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 		timehist_print_sample(sched, sample, &al, thread, t);
 
 out:
+	if (sched->hist_time.start == 0 && t >= ptime->start)
+		sched->hist_time.start = t;
+	if (ptime->end == 0 || t <= ptime->end)
+		sched->hist_time.end = t;
+
 	if (tr) {
 		/* time of this sched_switch event becomes last time task seen */
 		tr->last_time = sample->time;
@@ -2624,6 +2630,7 @@ static void timehist_print_summary(struct perf_sched *sched,
 	struct thread *t;
 	struct thread_runtime *r;
 	int i;
+	u64 hist_time = sched->hist_time.end - sched->hist_time.start;
 
 	memset(&totals, 0, sizeof(totals));
 
@@ -2665,7 +2672,7 @@ static void timehist_print_summary(struct perf_sched *sched,
 			totals.sched_count += r->run_stats.n;
 			printf("    CPU %2d idle for ", i);
 			print_sched_time(r->total_run_time, 6);
-			printf(" msec\n");
+			printf(" msec  (%6.2f%%)\n", 100.0 * r->total_run_time / hist_time);
 		} else
 			printf("    CPU %2d idle entire time window\n", i);
 	}
@@ -2701,12 +2708,16 @@ static void timehist_print_summary(struct perf_sched *sched,
 
 	printf("\n"
 	       "    Total number of unique tasks: %" PRIu64 "\n"
-	       "Total number of context switches: %" PRIu64 "\n"
-	       "           Total run time (msec): ",
+	       "Total number of context switches: %" PRIu64 "\n",
 	       totals.task_count, totals.sched_count);
 
+	printf("           Total run time (msec): ");
 	print_sched_time(totals.total_run_time, 2);
 	printf("\n");
+
+	printf("    Total scheduling time (msec): ");
+	print_sched_time(hist_time, 2);
+	printf(" (x %d)\n", sched->max_cpu);
 }
 
 typedef int (*sched_handler)(struct perf_tool *tool,
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/12] samples/bpf sock_example: Avoid getting ethhdr from two includes
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
  2017-01-04 17:24 ` [PATCH 01/12] perf sched timehist: Show total scheduling time Arnaldo Carvalho de Melo
@ 2017-01-04 17:24 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 03/12] samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include Arnaldo Carvalho de Melo
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Alexei Starovoitov,
	Daniel Borkmann, Joe Stringer, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

To avoid the following build failure on Alpine Linux 3.4, that has
clang-3.8 with the bpf target:

    HOSTCC  samples/bpf/sock_example.o
  In file included from /usr/include/net/ethernet.h:10:0,
                   from /git/linux/samples/bpf/sock_example.h:7,
                   from /git/linux/samples/bpf/sock_example.c:30:
  /usr/include/netinet/if_ether.h:96:8: error: redefinition of 'struct
  ethhdr'
   struct ethhdr {
          ^
  In file included from /git/linux/samples/bpf/sock_example.c:26:0:
  ./usr/include/linux/if_ether.h:144:8: note: originally defined here
   struct ethhdr {
          ^
  scripts/Makefile.host:124: recipe for target
  'samples/bpf/sock_example.o' failed
  make[2]: *** [samples/bpf/sock_example.o] Error 1
  /git/linux/Makefile:1658: recipe for target 'samples/bpf/' failed

So include net/if_ether.h for the needs of sock_example.h, using the
same include that sock_example.c uses.

Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Joe Stringer <joe@ovn.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-m9avekl1b651qe1r1zd5tzz9@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 samples/bpf/sock_example.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/bpf/sock_example.h b/samples/bpf/sock_example.h
index 09f7fe7e5fd7..d8014065d479 100644
--- a/samples/bpf/sock_example.h
+++ b/samples/bpf/sock_example.h
@@ -4,7 +4,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
-#include <net/ethernet.h>
+#include <linux/if_ether.h>
 #include <net/if.h>
 #include <linux/if_packet.h>
 #include <arpa/inet.h>
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/12] samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
  2017-01-04 17:24 ` [PATCH 01/12] perf sched timehist: Show total scheduling time Arnaldo Carvalho de Melo
  2017-01-04 17:24 ` [PATCH 02/12] samples/bpf sock_example: Avoid getting ethhdr from two includes Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 04/12] perf probe: Fix to get correct modname from elf header Arnaldo Carvalho de Melo
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Alexei Starovoitov,
	Daniel Borkmann, Joe Stringer, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Joe Stringer <joe@ovn.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-3awp0nv8tpnblatojmwjww7z@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 samples/bpf/trace_output_user.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/samples/bpf/trace_output_user.c b/samples/bpf/trace_output_user.c
index f4fa6af22def..ccca1e348017 100644
--- a/samples/bpf/trace_output_user.c
+++ b/samples/bpf/trace_output_user.c
@@ -9,7 +9,6 @@
 #include <string.h>
 #include <fcntl.h>
 #include <poll.h>
-#include <sys/ioctl.h>
 #include <linux/perf_event.h>
 #include <linux/bpf.h>
 #include <errno.h>
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/12] perf probe: Fix to get correct modname from elf header
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 03/12] samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 05/12] tools lib subcmd: Add OPT_STRING_OPTARG_SET option Arnaldo Carvalho de Melo
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Masami Hiramatsu, Jiri Olsa, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Masami Hiramatsu <mhiramat@kernel.org>

Since 'perf probe' supports cross-arch probes, it is possible to analyze
different arch kernel image which has different bits-per-long.

In that case, it fails to get the module name because it uses the
MOD_NAME_OFFSET macro based on the host machine bits-per-long, instead
of the target arch bits-per-long.

This fixes above issue by changing modname-offset based on the target
archs bit width. This is ok because linux kernel uses LP64 model on
64bit arch.

E.g. without this (on x86_64, and target module is arm32):

  $ perf probe -m build-arm/fs/configfs/configfs.ko -D configfs_lookup
  p:probe/configfs_lookup :configfs_lookup+0
                          ^-Here is an empty module name.

With this fix, you can see correct module name:

  $ perf probe -m build-arm/fs/configfs/configfs.ko -D configfs_lookup
  p:probe/configfs_lookup configfs:configfs_lookup+0

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/148337043836.6752.383495516397005695.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d281ae2b54e8..8f810961ec78 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -268,21 +268,6 @@ static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
 }
 
 /*
- * NOTE:
- * '.gnu.linkonce.this_module' section of kernel module elf directly
- * maps to 'struct module' from linux/module.h. This section contains
- * actual module name which will be used by kernel after loading it.
- * But, we cannot use 'struct module' here since linux/module.h is not
- * exposed to user-space. Offset of 'name' has remained same from long
- * time, so hardcoding it here.
- */
-#ifdef __LP64__
-#define MOD_NAME_OFFSET 24
-#else
-#define MOD_NAME_OFFSET 12
-#endif
-
-/*
  * @module can be module name of module file path. In case of path,
  * inspect elf and find out what is actual module name.
  * Caller has to free mod_name after using it.
@@ -296,6 +281,7 @@ static char *find_module_name(const char *module)
 	Elf_Data *data;
 	Elf_Scn *sec;
 	char *mod_name = NULL;
+	int name_offset;
 
 	fd = open(module, O_RDONLY);
 	if (fd < 0)
@@ -317,7 +303,21 @@ static char *find_module_name(const char *module)
 	if (!data || !data->d_buf)
 		goto ret_err;
 
-	mod_name = strdup((char *)data->d_buf + MOD_NAME_OFFSET);
+	/*
+	 * NOTE:
+	 * '.gnu.linkonce.this_module' section of kernel module elf directly
+	 * maps to 'struct module' from linux/module.h. This section contains
+	 * actual module name which will be used by kernel after loading it.
+	 * But, we cannot use 'struct module' here since linux/module.h is not
+	 * exposed to user-space. Offset of 'name' has remained same from long
+	 * time, so hardcoding it here.
+	 */
+	if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+		name_offset = 12;
+	else	/* expect ELFCLASS64 by default */
+		name_offset = 24;
+
+	mod_name = strdup((char *)data->d_buf + name_offset);
 
 ret_err:
 	elf_end(elf);
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/12] tools lib subcmd: Add OPT_STRING_OPTARG_SET option
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 04/12] perf probe: Fix to get correct modname from elf header Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 06/12] perf record: Make __record_options static Arnaldo Carvalho de Melo
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Josh Poimboeuf,
	Namhyung Kim, Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

To allow string options with a default argument and variable set when
the option is used.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Wang Nan <wangnan0@huawei.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1483431600-19887-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/subcmd/parse-options.c | 3 +++
 tools/lib/subcmd/parse-options.h | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 3284bb14ae78..8aad81151d50 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -213,6 +213,9 @@ static int get_value(struct parse_opt_ctx_t *p,
 		else
 			err = get_arg(p, opt, flags, (const char **)opt->value);
 
+		if (opt->set)
+			*(bool *)opt->set = true;
+
 		/* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */
 		if (opt->flags & PARSE_OPT_NOEMPTY) {
 			const char *val = *(const char **)opt->value;
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h
index 8866ac438b34..11c3be3bcce7 100644
--- a/tools/lib/subcmd/parse-options.h
+++ b/tools/lib/subcmd/parse-options.h
@@ -137,6 +137,11 @@ struct option {
 	{ .type = OPTION_STRING,  .short_name = (s), .long_name = (l), \
 	  .value = check_vtype(v, const char **), (a), .help = (h), \
 	  .flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) }
+#define OPT_STRING_OPTARG_SET(s, l, v, os, a, h, d) \
+	{ .type = OPTION_STRING, .short_name = (s), .long_name = (l), \
+	  .value = check_vtype(v, const char **), (a), .help = (h), \
+	  .flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d), \
+	  .set = check_vtype(os, bool *)}
 #define OPT_STRING_NOEMPTY(s, l, v, a, h)   { .type = OPTION_STRING,  .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h), .flags = PARSE_OPT_NOEMPTY}
 #define OPT_DATE(s, l, v, h) \
 	{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/12] perf record: Make __record_options static
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (4 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 05/12] tools lib subcmd: Add OPT_STRING_OPTARG_SET option Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 07/12] perf record: Fix --switch-output documentation and comment Arnaldo Carvalho de Melo
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

There's no need for this one to be global.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Wang Nan <wangnan0@huawei.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1483431600-19887-3-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 74d6a035133a..31cf0ce12a65 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1405,7 +1405,7 @@ static bool dry_run;
  * perf_evlist__prepare_workload, etc instead of fork+exec'in 'perf record',
  * using pipes, etc.
  */
-struct option __record_options[] = {
+static struct option __record_options[] = {
 	OPT_CALLBACK('e', "event", &record.evlist, "event",
 		     "event selector. use 'perf list' to list available events",
 		     parse_events_option),
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/12] perf record: Fix --switch-output documentation and comment
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (5 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 06/12] perf record: Make __record_options static Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 08/12] tools lib traceevent: Fix prev/next_prio for deadline tasks Arnaldo Carvalho de Melo
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

There's no --signal-trigger option, also adding the code comment into
record man page.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Wang Nan <wangnan0@huawei.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1483431600-19887-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt | 4 ++++
 tools/perf/builtin-record.c              | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 27fc3617c6a4..5054d9147f0f 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -430,6 +430,10 @@ that gets then processed, possibly via a perf script, to decide if that
 particular perf.data snapshot should be kept or not.
 
 Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
+The reason for the latter two is to reduce the data file switching
+overhead. You can still switch them on with:
+
+  --switch-output --no-no-buildid  --no-no-buildid-cache
 
 --dry-run::
 Parse options then exit. --dry-run can be used to detect errors in cmdline
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 31cf0ce12a65..4ec10e9427d9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1636,7 +1636,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 		 * overhead. Still generate buildid if they are required
 		 * explicitly using
 		 *
-		 *  perf record --signal-trigger --no-no-buildid \
+		 *  perf record --switch-output --no-no-buildid \
 		 *              --no-no-buildid-cache
 		 *
 		 * Following code equals to:
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/12] tools lib traceevent: Fix prev/next_prio for deadline tasks
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (6 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 07/12] perf record: Fix --switch-output documentation and comment Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 09/12] perf tools: Install tools/lib/traceevent plugins with install-bin Arnaldo Carvalho de Melo
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Daniel Bristot de Oliveira, Alexander Shishkin,
	Jiri Olsa, Peter Zijlstra, Arnaldo Carvalho de Melo

From: Daniel Bristot de Oliveira <bristot@redhat.com>

Currently, the sched:sched_switch tracepoint reports deadline tasks with
priority -1. But when reading the trace via perf script I've got the
following output:

  # ./d & # (d is a deadline task, see [1])
  # perf record -e sched:sched_switch -a sleep 1
  # perf script
      ...
         swapper     0 [000]  2146.962441: sched:sched_switch: swapper/0:0 [120] R ==> d:2593 [4294967295]
               d  2593 [000]  2146.972472: sched:sched_switch: d:2593 [4294967295] R ==> g:2590 [4294967295]

The task d reports the wrong priority [4294967295]. This happens because
the "int prio" is stored in an unsigned long long val. Although it is
set as a %lld, as int is shorter than unsigned long long,
trace_seq_printf prints it as a positive number.

The fix is just to cast the val as an int, and print it as a %d,
as in the sched:sched_switch tracepoint's "format".

The output with the fix is:

  # ./d &
  # perf record -e sched:sched_switch -a sleep 1
  # perf script
      ...
         swapper     0 [000]  4306.374037: sched:sched_switch: swapper/0:0 [120] R ==> d:10941 [-1]
               d 10941 [000]  4306.383823: sched:sched_switch: d:10941 [-1] R ==> swapper/0:0 [120]

[1] d.c

 ---
  #include <stdio.h>
  #include <unistd.h>
  #include <sys/syscall.h>
  #include <linux/types.h>
  #include <linux/sched.h>

  struct sched_attr {
	__u32 size, sched_policy;
	__u64 sched_flags;
	__s32 sched_nice;
	__u32 sched_priority;
	__u64 sched_runtime, sched_deadline, sched_period;
  };

  int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags)
  {
	return syscall(__NR_sched_setattr, pid, attr, flags);
  }

  int main(void)
  {
	struct sched_attr attr = {
		.size		= sizeof(attr),
		.sched_policy	= SCHED_DEADLINE, /* This creates a 10ms/30ms reservation */
		.sched_runtime	= 10 * 1000 * 1000,
		.sched_period	= attr.sched_deadline = 30 * 1000 * 1000,
	};

	if (sched_setattr(0, &attr, 0) < 0) {
		perror("sched_setattr");
		return -1;
	}

	for(;;);
  }
 ---

Committer notes:

Got the program from the provided URL, http://bristot.me/lkml/d.c,
trimmed it and included in the cset log above, so that we have
everything needed to test it in one place.

Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/866ef75bcebf670ae91c6a96daa63597ba981f0d.1483443552.git.bristot@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/plugin_sched_switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/plugin_sched_switch.c b/tools/lib/traceevent/plugin_sched_switch.c
index f1ce60065258..ec30c2fcbac0 100644
--- a/tools/lib/traceevent/plugin_sched_switch.c
+++ b/tools/lib/traceevent/plugin_sched_switch.c
@@ -111,7 +111,7 @@ static int sched_switch_handler(struct trace_seq *s,
 	trace_seq_printf(s, "%lld ", val);
 
 	if (pevent_get_field_val(s, event, "prev_prio", record, &val, 0) == 0)
-		trace_seq_printf(s, "[%lld] ", val);
+		trace_seq_printf(s, "[%d] ", (int) val);
 
 	if (pevent_get_field_val(s,  event, "prev_state", record, &val, 0) == 0)
 		write_state(s, val);
@@ -129,7 +129,7 @@ static int sched_switch_handler(struct trace_seq *s,
 	trace_seq_printf(s, "%lld", val);
 
 	if (pevent_get_field_val(s, event, "next_prio", record, &val, 0) == 0)
-		trace_seq_printf(s, " [%lld]", val);
+		trace_seq_printf(s, " [%d]", (int) val);
 
 	return 0;
 }
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/12] perf tools: Install tools/lib/traceevent plugins with install-bin
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (7 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 08/12] tools lib traceevent: Fix prev/next_prio for deadline tasks Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 10/12] perf symbols: Robustify reading of build-id from sysfs Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Alexander Shishkin,
	Daniel Bristot de Oliveira, Jiri Olsa, Peter Zijlstra,
	Steven Rostedt

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Those are binaries as well, so should be installed by:

  make -C tools/perf install-bin'

too.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-3841b37u05evxrs1igkyu6ks@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index e9ec531131ca..4db68aec9913 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -704,9 +704,9 @@ install-tests: all install-gtk
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
 		$(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'
 
-install-bin: install-tools install-tests
+install-bin: install-tools install-tests install-traceevent-plugins
 
-install: install-bin try-install-man install-traceevent-plugins
+install: install-bin try-install-man
 
 install-python_ext:
 	$(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/12] perf symbols: Robustify reading of build-id from sysfs
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (8 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 09/12] perf tools: Install tools/lib/traceevent plugins with install-bin Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 11/12] perf probe: Fix --funcs to show correct symbols for offline module Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	David Ahern, Jiri Olsa, Namhyung Kim, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Markus reported that perf segfaults when reading /sys/kernel/notes from
a kernel linked with GNU gold, due to what looks like a gold bug, so do
some bounds checking to avoid crashing in that case.

Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Report-Link: http://lkml.kernel.org/r/20161219161821.GA294@x4
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ryhgs6a6jxvz207j2636w31c@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/symbol-elf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 99400b0e8f2a..adbc6c02c3aa 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -537,6 +537,12 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
 				break;
 		} else {
 			int n = namesz + descsz;
+
+			if (n > (int)sizeof(bf)) {
+				n = sizeof(bf);
+				pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n",
+					 __func__, filename, nhdr.n_namesz, nhdr.n_descsz);
+			}
 			if (read(fd, bf, n) != n)
 				break;
 		}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/12] perf probe: Fix --funcs to show correct symbols for offline module
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (9 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 10/12] perf symbols: Robustify reading of build-id from sysfs Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-04 17:25 ` [PATCH 12/12] perf probe: Fix to probe on gcc generated symbols for offline kernel Arnaldo Carvalho de Melo
  2017-01-05  7:36 ` [GIT PULL 00/12] perf/urgent fixes Ingo Molnar
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Masami Hiramatsu, Jiri Olsa, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Masami Hiramatsu <mhiramat@kernel.org>

Fix --funcs (-F) option to show correct symbols for offline module.
Since previous perf-probe uses machine__findnew_module_map() for offline
module, even if user passes a module file (with full path) which is for
other architecture, perf-probe always tries to load symbol map for
current kernel module.

This fix uses dso__new_map() to load the map from given binary as same
as a map for user applications.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/148350053478.19001.15435255244512631545.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 8f810961ec78..542e6472c4d7 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -163,7 +163,7 @@ static struct map *kernel_get_module_map(const char *module)
 
 	/* A file path -- this is an offline module */
 	if (module && strchr(module, '/'))
-		return machine__findnew_module_map(host_machine, 0, module);
+		return dso__new_map(module);
 
 	if (!module)
 		module = "kernel";
@@ -173,6 +173,7 @@ static struct map *kernel_get_module_map(const char *module)
 		if (strncmp(pos->dso->short_name + 1, module,
 			    pos->dso->short_name_len - 2) == 0 &&
 		    module[pos->dso->short_name_len - 2] == '\0') {
+			map__get(pos);
 			return pos;
 		}
 	}
@@ -188,15 +189,6 @@ struct map *get_target_map(const char *target, bool user)
 		return kernel_get_module_map(target);
 }
 
-static void put_target_map(struct map *map, bool user)
-{
-	if (map && user) {
-		/* Only the user map needs to be released */
-		map__put(map);
-	}
-}
-
-
 static int convert_exec_to_group(const char *exec, char **result)
 {
 	char *ptr1, *ptr2, *exec_copy;
@@ -412,7 +404,7 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
 	}
 
 out:
-	put_target_map(map, uprobes);
+	map__put(map);
 	return ret;
 
 }
@@ -2869,7 +2861,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
 	}
 
 out:
-	put_target_map(map, pev->uprobes);
+	map__put(map);
 	free(syms);
 	return ret;
 
@@ -3362,10 +3354,7 @@ int show_available_funcs(const char *target, struct strfilter *_filter,
 		return ret;
 
 	/* Get a symbol map */
-	if (user)
-		map = dso__new_map(target);
-	else
-		map = kernel_get_module_map(target);
+	map = get_target_map(target, user);
 	if (!map) {
 		pr_err("Failed to get a map for %s\n", (target) ? : "kernel");
 		return -EINVAL;
@@ -3397,9 +3386,7 @@ int show_available_funcs(const char *target, struct strfilter *_filter,
         }
 
 end:
-	if (user) {
-		map__put(map);
-	}
+	map__put(map);
 	exit_probe_symbol_maps();
 
 	return ret;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 12/12] perf probe: Fix to probe on gcc generated symbols for offline kernel
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (10 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 11/12] perf probe: Fix --funcs to show correct symbols for offline module Arnaldo Carvalho de Melo
@ 2017-01-04 17:25 ` Arnaldo Carvalho de Melo
  2017-01-05  7:36 ` [GIT PULL 00/12] perf/urgent fixes Ingo Molnar
  12 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-04 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Masami Hiramatsu, Jiri Olsa, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Masami Hiramatsu <mhiramat@kernel.org>

Fix perf-probe to show probe definition on gcc generated symbols for
offline kernel (including cross-arch kernel image).

gcc sometimes optimizes functions and generate new symbols with suffixes
such as ".constprop.N" or ".isra.N" etc. Since those symbol names are
not recorded in DWARF, we have to find correct generated symbols from
offline ELF binary to probe on it (kallsyms doesn't correct it).  For
online kernel or uprobes we don't need it because those are rebased on
_text, or a section relative address.

E.g. Without this:

  $ perf probe -k build-arm/vmlinux -F __slab_alloc*
  __slab_alloc.constprop.9
  $ perf probe -k build-arm/vmlinux -D __slab_alloc
  p:probe/__slab_alloc __slab_alloc+0

If you put above definition on target machine, it should fail
because there is no __slab_alloc in kallsyms.

With this fix, perf probe shows correct probe definition on
__slab_alloc.constprop.9:

  $ perf probe -k build-arm/vmlinux -D __slab_alloc
  p:probe/__slab_alloc __slab_alloc.constprop.9+0

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/148350060434.19001.11864836288580083501.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 542e6472c4d7..4a57c8a60bd9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -610,6 +610,51 @@ static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp,
 	return ret ? : -ENOENT;
 }
 
+/*
+ * Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions
+ * and generate new symbols with suffixes such as .constprop.N or .isra.N
+ * etc. Since those symbols are not recorded in DWARF, we have to find
+ * correct generated symbols from offline ELF binary.
+ * For online kernel or uprobes we don't need this because those are
+ * rebased on _text, or already a section relative address.
+ */
+static int
+post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
+					int ntevs, const char *pathname)
+{
+	struct symbol *sym;
+	struct map *map;
+	unsigned long stext = 0;
+	u64 addr;
+	int i;
+
+	/* Prepare a map for offline binary */
+	map = dso__new_map(pathname);
+	if (!map || get_text_start_address(pathname, &stext) < 0) {
+		pr_warning("Failed to get ELF symbols for %s\n", pathname);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < ntevs; i++) {
+		addr = tevs[i].point.address + tevs[i].point.offset - stext;
+		sym = map__find_symbol(map, addr);
+		if (!sym)
+			continue;
+		if (!strcmp(sym->name, tevs[i].point.symbol))
+			continue;
+		/* If we have no realname, use symbol for it */
+		if (!tevs[i].point.realname)
+			tevs[i].point.realname = tevs[i].point.symbol;
+		else
+			free(tevs[i].point.symbol);
+		tevs[i].point.symbol = strdup(sym->name);
+		tevs[i].point.offset = addr - sym->start;
+	}
+	map__put(map);
+
+	return 0;
+}
+
 static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
 					  int ntevs, const char *exec)
 {
@@ -671,7 +716,8 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
 
 	/* Skip post process if the target is an offline kernel */
 	if (symbol_conf.ignore_vmlinux_buildid)
-		return 0;
+		return post_process_offline_probe_trace_events(tevs, ntevs,
+						symbol_conf.vmlinux_name);
 
 	reloc_sym = kernel_get_ref_reloc_sym();
 	if (!reloc_sym) {
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [GIT PULL 00/12] perf/urgent fixes
  2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
                   ` (11 preceding siblings ...)
  2017-01-04 17:25 ` [PATCH 12/12] perf probe: Fix to probe on gcc generated symbols for offline kernel Arnaldo Carvalho de Melo
@ 2017-01-05  7:36 ` Ingo Molnar
  2017-01-05 15:02   ` Arnaldo Carvalho de Melo
  12 siblings, 1 reply; 15+ messages in thread
From: Ingo Molnar @ 2017-01-05  7:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Adrian Hunter, Alexander Shishkin,
	Alexei Starovoitov, Daniel Borkmann, Daniel Bristot de Oliveira,
	David Ahern, Jiri Olsa, Joe Stringer, Josh Poimboeuf,
	Markus Trippelsdorf, Masami Hiramatsu, Namhyung Kim,
	Peter Zijlstra, Steven Rostedt, Wang Nan,
	Arnaldo Carvalho de Melo


* Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Hi Ingo,
> 
> 	Please consider pulling,
> 
> - Arnaldo
> 
> Test results at the end of this message, as usual, news about it:
> 
> Has two new targets, debian:experimental-x-mipsel and
> debian:experimental-x-arm64.
> 
> Those use debian's multi-arch packages allowing cross building more than with
> the other crossbuild containers.
> 
> This still doesn't generate a full featured tool, as there are some buggy
> multi-arch packages, such as the devel packages for perl, gtk2, etc.
> 
> The following changes since commit 3705b97505bcbf6440f38119c0e7d6058f585b54:
> 
>   Merge tag 'perf-urgent-for-mingo-20161222' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2016-12-23 20:23:29 +0100)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo-4.10-20170104
> 
> for you to fetch changes up to 8a937a25a7e3c19d5fb3f9d92f605cf5fda219d8:
> 
>   perf probe: Fix to probe on gcc generated symbols for offline kernel (2017-01-04 11:44:22 -0300)
> 
> ----------------------------------------------------------------
> perf/urgent fixes and one improvement:
> 
> Fixes:
> 
> - Fix prev/next_prio formatting for deadline tasks in libtraceevent (Daniel Bristot de Oliveira)
> 
> - Robustify reading of build-ids from /sys/kernel/note (Arnaldo Carvalho de Melo)
> 
> - Fix building some sample/bpf in Alpine Linux 3.4 (Arnaldo Carvalho de Melo)
> 
> - Fix 'make install-bin' to install libtraceevent plugins (Arnaldo Carvalho de Melo)
> 
> - Fix 'perf record --switch-output' documentation and comment (Jiri Olsa)
> 
> - 'perf probe' fixes for cross arch probing (Masami Hiramatsu)
> 
> Improvement:
> 
> - Show total scheduling time in 'perf sched timehist' (Namhyumg Kim)
> 
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> ----------------------------------------------------------------
> Arnaldo Carvalho de Melo (4):
>       samples/bpf sock_example: Avoid getting ethhdr from two includes
>       samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include
>       perf tools: Install tools/lib/traceevent plugins with install-bin
>       perf symbols: Robustify reading of build-id from sysfs
> 
> Daniel Bristot de Oliveira (1):
>       tools lib traceevent: Fix prev/next_prio for deadline tasks
> 
> Jiri Olsa (3):
>       tools lib subcmd: Add OPT_STRING_OPTARG_SET option
>       perf record: Make __record_options static
>       perf record: Fix --switch-output documentation and comment
> 
> Masami Hiramatsu (3):
>       perf probe: Fix to get correct modname from elf header
>       perf probe: Fix --funcs to show correct symbols for offline module
>       perf probe: Fix to probe on gcc generated symbols for offline kernel
> 
> Namhyung Kim (1):
>       perf sched timehist: Show total scheduling time
> 
>  samples/bpf/sock_example.h                 |   2 +-
>  samples/bpf/trace_output_user.c            |   1 -
>  tools/lib/subcmd/parse-options.c           |   3 +
>  tools/lib/subcmd/parse-options.h           |   5 ++
>  tools/lib/traceevent/plugin_sched_switch.c |   4 +-
>  tools/perf/Documentation/perf-record.txt   |   4 ++
>  tools/perf/Makefile.perf                   |   4 +-
>  tools/perf/builtin-record.c                |   4 +-
>  tools/perf/builtin-sched.c                 |  17 ++++-
>  tools/perf/util/probe-event.c              | 105 +++++++++++++++++++----------
>  tools/perf/util/symbol-elf.c               |   6 ++
>  11 files changed, 108 insertions(+), 47 deletions(-)

Pulled, thanks a lot Arnaldo!

JFYI, I noticed these new warnings in the build log, we should probably take care 
of these out of sync headers eventually:

 Warning: arch/x86/include/asm/cpufeatures.h differs from kernel
 Warning: arch/x86/include/uapi/asm/vmx.h differs from kernel
 Warning: arch/powerpc/include/uapi/asm/kvm.h differs from kernel
 Warning: arch/arm/include/uapi/asm/kvm.h differs from kernel

... but it's not a showstopper.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [GIT PULL 00/12] perf/urgent fixes
  2017-01-05  7:36 ` [GIT PULL 00/12] perf/urgent fixes Ingo Molnar
@ 2017-01-05 15:02   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-05 15:02 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Adrian Hunter, Alexander Shishkin,
	Alexei Starovoitov, Daniel Borkmann, Daniel Bristot de Oliveira,
	David Ahern, Jiri Olsa, Joe Stringer, Josh Poimboeuf,
	Markus Trippelsdorf, Masami Hiramatsu, Namhyung Kim,
	Peter Zijlstra, Steven Rostedt, Wang Nan,
	Arnaldo Carvalho de Melo

Em Thu, Jan 05, 2017 at 08:36:36AM +0100, Ingo Molnar escreveu:
> 
> * Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> 
> > Hi Ingo,
> > 
> > 	Please consider pulling,
> > 
> > - Arnaldo
> > 
> > Test results at the end of this message, as usual, news about it:
> > 
> > Has two new targets, debian:experimental-x-mipsel and
> > debian:experimental-x-arm64.
> > 
> > Those use debian's multi-arch packages allowing cross building more than with
> > the other crossbuild containers.
> > 
> > This still doesn't generate a full featured tool, as there are some buggy
> > multi-arch packages, such as the devel packages for perl, gtk2, etc.
> > 
> > The following changes since commit 3705b97505bcbf6440f38119c0e7d6058f585b54:
> > 
> >   Merge tag 'perf-urgent-for-mingo-20161222' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2016-12-23 20:23:29 +0100)
> > 
> > are available in the git repository at:
> > 
> >   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo-4.10-20170104
> > 
> > for you to fetch changes up to 8a937a25a7e3c19d5fb3f9d92f605cf5fda219d8:
> > 
> >   perf probe: Fix to probe on gcc generated symbols for offline kernel (2017-01-04 11:44:22 -0300)
> > 
> > ----------------------------------------------------------------
> > perf/urgent fixes and one improvement:
> > 
> > Fixes:
> > 
> > - Fix prev/next_prio formatting for deadline tasks in libtraceevent (Daniel Bristot de Oliveira)
> > 
> > - Robustify reading of build-ids from /sys/kernel/note (Arnaldo Carvalho de Melo)
> > 
> > - Fix building some sample/bpf in Alpine Linux 3.4 (Arnaldo Carvalho de Melo)
> > 
> > - Fix 'make install-bin' to install libtraceevent plugins (Arnaldo Carvalho de Melo)
> > 
> > - Fix 'perf record --switch-output' documentation and comment (Jiri Olsa)
> > 
> > - 'perf probe' fixes for cross arch probing (Masami Hiramatsu)
> > 
> > Improvement:
> > 
> > - Show total scheduling time in 'perf sched timehist' (Namhyumg Kim)
> > 
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > 
> > ----------------------------------------------------------------
> > Arnaldo Carvalho de Melo (4):
> >       samples/bpf sock_example: Avoid getting ethhdr from two includes
> >       samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include
> >       perf tools: Install tools/lib/traceevent plugins with install-bin
> >       perf symbols: Robustify reading of build-id from sysfs
> > 
> > Daniel Bristot de Oliveira (1):
> >       tools lib traceevent: Fix prev/next_prio for deadline tasks
> > 
> > Jiri Olsa (3):
> >       tools lib subcmd: Add OPT_STRING_OPTARG_SET option
> >       perf record: Make __record_options static
> >       perf record: Fix --switch-output documentation and comment
> > 
> > Masami Hiramatsu (3):
> >       perf probe: Fix to get correct modname from elf header
> >       perf probe: Fix --funcs to show correct symbols for offline module
> >       perf probe: Fix to probe on gcc generated symbols for offline kernel
> > 
> > Namhyung Kim (1):
> >       perf sched timehist: Show total scheduling time
> > 
> >  samples/bpf/sock_example.h                 |   2 +-
> >  samples/bpf/trace_output_user.c            |   1 -
> >  tools/lib/subcmd/parse-options.c           |   3 +
> >  tools/lib/subcmd/parse-options.h           |   5 ++
> >  tools/lib/traceevent/plugin_sched_switch.c |   4 +-
> >  tools/perf/Documentation/perf-record.txt   |   4 ++
> >  tools/perf/Makefile.perf                   |   4 +-
> >  tools/perf/builtin-record.c                |   4 +-
> >  tools/perf/builtin-sched.c                 |  17 ++++-
> >  tools/perf/util/probe-event.c              | 105 +++++++++++++++++++----------
> >  tools/perf/util/symbol-elf.c               |   6 ++
> >  11 files changed, 108 insertions(+), 47 deletions(-)
> 
> Pulled, thanks a lot Arnaldo!
> 
> JFYI, I noticed these new warnings in the build log, we should probably take care 
> of these out of sync headers eventually:
> 
>  Warning: arch/x86/include/asm/cpufeatures.h differs from kernel
>  Warning: arch/x86/include/uapi/asm/vmx.h differs from kernel
>  Warning: arch/powerpc/include/uapi/asm/kvm.h differs from kernel
>  Warning: arch/arm/include/uapi/asm/kvm.h differs from kernel
> 
> ... but it's not a showstopper.

Right, one has to look at the changes, see if they should trigger
changes in tools, do it if needed, then do the copy, checking that all
continues to work as expected.

I've been doing that, and in some cases some other people as well, like
Joe Stringer did for the bpf headers when making samples/bpf/ use
tools/bpf/.

- Arnaldo

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-01-05 15:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-04 17:24 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
2017-01-04 17:24 ` [PATCH 01/12] perf sched timehist: Show total scheduling time Arnaldo Carvalho de Melo
2017-01-04 17:24 ` [PATCH 02/12] samples/bpf sock_example: Avoid getting ethhdr from two includes Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 03/12] samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 04/12] perf probe: Fix to get correct modname from elf header Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 05/12] tools lib subcmd: Add OPT_STRING_OPTARG_SET option Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 06/12] perf record: Make __record_options static Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 07/12] perf record: Fix --switch-output documentation and comment Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 08/12] tools lib traceevent: Fix prev/next_prio for deadline tasks Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 09/12] perf tools: Install tools/lib/traceevent plugins with install-bin Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 10/12] perf symbols: Robustify reading of build-id from sysfs Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 11/12] perf probe: Fix --funcs to show correct symbols for offline module Arnaldo Carvalho de Melo
2017-01-04 17:25 ` [PATCH 12/12] perf probe: Fix to probe on gcc generated symbols for offline kernel Arnaldo Carvalho de Melo
2017-01-05  7:36 ` [GIT PULL 00/12] perf/urgent fixes Ingo Molnar
2017-01-05 15:02   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).