Skip to contentSkip to conversation

perf/urgent fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 15 messages Jan 4, 2017 – Jan 5, 2017

Subsystems (2)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

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)

----------------------------------------------------------------
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'
  $
author maintainer
#1 lore raw

PATCH 1/12 perf sched timehist: Show total scheduling time

From: Namhyung Kim <[email protected]>

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)
---
 tools/perf/builtin-sched.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
tools/perf/builtin-sched.c +14 -3
index d53e706a6f17..5b134b0d1ff3 100644
@@ -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,
Signature · 1 line
2.9.3
author maintainer
#2 lore raw

PATCH 2/12 samples/bpf sock_example: Avoid getting ethhdr from two includes

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

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.

---
 samples/bpf/sock_example.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/bpf/sock_example.h +1 -1
index 09f7fe7e5fd7..d8014065d479 100644
@@ -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>
Signature · 1 line
2.9.3
author maintainer
#3 lore raw

PATCH 3/12 samples/bpf trace_output_user: Remove duplicate sys/ioctl.h include

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

---
 samples/bpf/trace_output_user.c | 1 -
 1 file changed, 1 deletion(-)
samples/bpf/trace_output_user.c +0 -1
index f4fa6af22def..ccca1e348017 100644
@@ -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>
Signature · 1 line
2.9.3
author maintainer
#4 lore raw

PATCH 4/12 perf probe: Fix to get correct modname from elf header

In reply to Arnaldo Carvalho de Melo

From: Masami Hiramatsu <[email protected]>

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
---
 tools/perf/util/probe-event.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
tools/perf/util/probe-event.c +16 -16
index d281ae2b54e8..8f810961ec78 100644
@@ -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);
Signature · 1 line
2.9.3
author maintainer
#5 lore raw

PATCH 5/12 tools lib subcmd: Add OPT_STRING_OPTARG_SET option

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

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

---
 tools/lib/subcmd/parse-options.c | 3 +++
 tools/lib/subcmd/parse-options.h | 5 +++++
 2 files changed, 8 insertions(+)
tools/lib/subcmd/parse-options.c +3 -0
index 3284bb14ae78..8aad81151d50 100644
@@ -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;
tools/lib/subcmd/parse-options.h +5 -0
index 8866ac438b34..11c3be3bcce7 100644
@@ -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 }
Signature · 1 line
2.9.3
author maintainer
#6 lore raw

PATCH 6/12 perf record: Make __record_options static

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

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

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
index 74d6a035133a..31cf0ce12a65 100644
@@ -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),
Signature · 1 line
2.9.3
author maintainer
#7 lore raw

PATCH 7/12 perf record: Fix --switch-output documentation and comment

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

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

---
 tools/perf/Documentation/perf-record.txt | 4 ++++
 tools/perf/builtin-record.c              | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +4 -0
index 27fc3617c6a4..5054d9147f0f 100644
@@ -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
tools/perf/builtin-record.c +1 -1
index 31cf0ce12a65..4ec10e9427d9 100644
@@ -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:
Signature · 1 line
2.9.3
author maintainer
#8 lore raw

PATCH 8/12 tools lib traceevent: Fix prev/next_prio for deadline tasks

In reply to Arnaldo Carvalho de Melo

From: Daniel Bristot de Oliveira <[email protected]>

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.

---
 tools/lib/traceevent/plugin_sched_switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/traceevent/plugin_sched_switch.c +2 -2
index f1ce60065258..ec30c2fcbac0 100644
@@ -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;
 }
Signature · 1 line
2.9.3
author maintainer
#9 lore raw

PATCH 9/12 perf tools: Install tools/lib/traceevent plugins with install-bin

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

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

make -C tools/perf install-bin'

too.

Cc Alexander Shishkin <[email protected]>
Cc Daniel Bristot de Oliveira <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 tools/perf/Makefile.perf | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +2 -2
index e9ec531131ca..4db68aec9913 100644
@@ -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)'
Signature · 1 line
2.9.3
author maintainer
#10 lore raw

PATCH 10/12 perf symbols: Robustify reading of build-id from sysfs

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

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.

Report-Link: http://lkml.kernel.org/r/20161219161821.GA294@x4

---
 tools/perf/util/symbol-elf.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/util/symbol-elf.c +6 -0
index 99400b0e8f2a..adbc6c02c3aa 100644
@@ -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;
 		}
Signature · 1 line
2.9.3
author maintainer
#11 lore raw

PATCH 11/12 perf probe: Fix --funcs to show correct symbols for offline module

In reply to Arnaldo Carvalho de Melo

From: Masami Hiramatsu <[email protected]>

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.

---
 tools/perf/util/probe-event.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)
tools/perf/util/probe-event.c +6 -19
index 8f810961ec78..542e6472c4d7 100644
@@ -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;
Signature · 1 line
2.9.3
author maintainer
#12 lore raw

PATCH 12/12 perf probe: Fix to probe on gcc generated symbols for offline kernel

In reply to Arnaldo Carvalho de Melo

From: Masami Hiramatsu <[email protected]>

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
---
 tools/perf/util/probe-event.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +47 -1
index 542e6472c4d7..4a57c8a60bd9 100644
@@ -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) {
Signature · 1 line
2.9.3
#13 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 75 lines · 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)

----------------------------------------------------------------
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

Quoted 12 lines
 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

author maintainer
#14 lore raw

Em Thu, Jan 05, 2017 at 08:36:36AM +0100, Ingo Molnar escreveu:

Quoted 96 lines · Arnaldo Carvalho de Melo
Quoted 76 lines

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)

----------------------------------------------------------------
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

Quoted 12 lines
 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:

Quoted 6 lines

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