Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 6 messages Nov 25, 2015 – Nov 26, 2015

Subsystems (4)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

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

Hi,

Please consider pulling, this is on top of my previous
perf-core-for-mingo pull request.

- Arnaldo

The following changes since commit 646a6e846c4dc3812c614fd061603b6db5b8d380:

perf callchain: Add missing parent_val initialization (2015-11-23 18:31:25 -0300)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-2

for you to fetch changes up to d8ad6a15cc3a364de6c8010378adc3fb06ce3ff1:

tools lib bpf: Don't do a feature check when cleaning (2015-11-25 16:38:13 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

User visible:

- Fix to free temporal Dwarf_Frame correctly in 'perf probe', fixing a regression introduced in perf/core that prevented, at least, adding an uprobe collecting function parameter values (Masami Hiramatsu)

- Fix output of %llu for 64 bit values read on 32 bit machines in libtraceevent (Steven Rostedt)

Developer visible:

- Clean CFLAGS and LDFLAGS for fixdep in tools/build (Wang Nan)

- Don't do a feature check when cleaning tools/lib/bpf (Wang Nan)

----------------------------------------------------------------
Masami Hiramatsu (1):
perf probe: Fix to free temporal Dwarf_Frame correctly

Steven Rostedt (1):
tools lib traceevent: Fix output of %llu for 64 bit values read on 32 bit machines

Wang Nan (2):
tools build: Clean CFLAGS and LDFLAGS for fixdep tools lib bpf: Don't do a feature check when cleaning

 tools/build/Makefile.include       |  2 +-
 tools/lib/bpf/Makefile             | 10 ++++++++++
 tools/lib/traceevent/event-parse.c |  5 ++---
 tools/perf/util/probe-finder.c     | 13 ++++++-------
 4 files changed, 19 insertions(+), 11 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 tools lib traceevent: Fix output of %llu for 64 bit values read on 32 bit machines

From: Steven Rostedt <[email protected]>

When a long value is read on 32 bit machines for 64 bit output, the parsing needs to change "%lu" into "%llu", as the value is read natively.

Unfortunately, if "%llu" is already there, the code will add another "l" to it and fail to parse it properly.

---
 tools/lib/traceevent/event-parse.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/lib/traceevent/event-parse.c +2 -3
index 2a912df6771b..68276f35e323 100644
@@ -4968,13 +4968,12 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 				    sizeof(long) != 8) {
 					char *p;
 
-					ls = 2;
 					/* make %l into %ll */
-					p = strchr(format, 'l');
-					if (p)
+					if (ls == 1 && (p = strchr(format, 'l')))
 						memmove(p+1, p, strlen(p)+1);
 					else if (strcmp(format, "%p") == 0)
 						strcpy(format, "0x%llx");
+					ls = 2;
 				}
 				switch (ls) {
 				case -2:
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/4 perf probe: Fix to free temporal Dwarf_Frame correctly

In reply to Arnaldo Carvalho de Melo

From: Masami Hiramatsu <[email protected]>

The commit 05c8d802fa52 ("perf probe: Fix to free temporal Dwarf_Frame") tried to fix the memory leak of Dwarf_Frame, but it released the frame at wrong point. Since the dwarf_frame_cfa(frame, &pf->fb_ops, &nops) can return an address inside the frame data structure to pf->fb_ops, we can not release the frame before using pf->fb_ops.

This reverts the commit and releases the frame afterwards (right before returning from call_probe_finder) correctly.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Wang Nan <[email protected]>
Fixes 05c8d802fa52 ("perf probe: Fix to free temporal Dwarf_Frame")

LPU-Reference: [email protected]

---
 tools/perf/util/probe-finder.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/probe-finder.c +6 -7
index 1cab05a3831e..2be10fb27172 100644
@@ -654,6 +654,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,
 static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)
 {
 	Dwarf_Attribute fb_attr;
+	Dwarf_Frame *frame = NULL;
 	size_t nops;
 	int ret;
 
@@ -683,26 +684,24 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)
 	ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
 	if (ret <= 0 || nops == 0) {
 		pf->fb_ops = NULL;
-		ret = 0;
 #if _ELFUTILS_PREREQ(0, 142)
 	} else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
 		   pf->cfi != NULL) {
-		Dwarf_Frame *frame = NULL;
 		if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 ||
 		    dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) {
 			pr_warning("Failed to get call frame on 0x%jx\n",
 				   (uintmax_t)pf->addr);
-			ret = -ENOENT;
+			free(frame);
+			return -ENOENT;
 		}
-		free(frame);
 #endif
 	}
 
 	/* Call finder's callback handler */
-	if (ret >= 0)
-		ret = pf->callback(sc_die, pf);
+	ret = pf->callback(sc_die, pf);
 
-	/* *pf->fb_ops will be cached in libdw. Don't free it. */
+	/* Since *pf->fb_ops can be a part of frame. we should free it here. */
+	free(frame);
 	pf->fb_ops = NULL;
 
 	return ret;
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 3/4 tools build: Clean CFLAGS and LDFLAGS for fixdep

In reply to Arnaldo Carvalho de Melo

From: Wang Nan <[email protected]>

Sometimes passing variables to tools/build is dangerous. For example, on my platform there is a gcc problem (gcc 4.8.1):

It passes the stackprotector-all feature check:

  $ gcc -fstack-protector-all -c ./test.c
  $ echo $?
  0

But requires LDFLAGS support if separate compiling and linking:

  $ gcc -fstack-protector-all -c ./test.c
  $ gcc ./test.o
  ./test.o: In function `main':
  test.c:(.text+0xb): undefined reference to `__stack_chk_guard'
  test.c:(.text+0x21): undefined reference to `__stack_chk_guard'
  collect2: error: ld returned 1 exit status
  $ gcc -fstack-protector-all ./test.o
  $ echo $?
  0
  $ gcc ./test.o -lssp
  $ echo $?
  0
  $

In this environment building perf throws an error:

  $ make
    BUILD:   Doing 'make -j24' parallel build
  config/Makefile:344: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
  config/Makefile:403: No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev
  config/Makefile:418: slang not found, disables TUI support. Please install slang-devel or libslang-dev
  config/Makefile:432: GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev
  config/Makefile:564: No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling
  config/Makefile:606: No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev
    CC       fixdep.o
    LD       fixdep-in.o
    LINK     fixdep
  fixdep-in.o: In function `parse_dep_file':
  /kernel/tools/build/fixdep.c:47: undefined reference to `__stack_chk_guard'
  /kernel/tools/build/fixdep.c:117: undefined reference to `__stack_chk_guard'
  fixdep-in.o: In function `main':
  /kernel-hydrogen/tools/build/fixdep.c:156: undefined reference to `__stack_chk_guard'
  /kernel/tools/build/fixdep.c:168: undefined reference to `__stack_chk_guard'
  collect2: error: ld returned 1 exit status
  make[2]: *** [fixdep] Error 1
  make[1]: *** [fixdep] Error 2
  make: *** [all] Error 2

This is because the CFLAGS used in building perf pollutes the CFLAGS used for fixdep, passing -fstack-protector-all to buiold fixdep which is obviously not required. Since fixdep is a small host side tool, we should keep its CFLAGS/LDFLAGS simple and clean.

This patch clears the CFLAGS and LDFLAGS passed when building fixdep, so such gcc problem won't block the perf build process.

---
 tools/build/Makefile.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/build/Makefile.include +1 -1
index 4e09ad617a60..6254760290c9 100644
@@ -4,7 +4,7 @@ ifdef CROSS_COMPILE
 fixdep:
 else
 fixdep:
-	$(Q)$(MAKE) -C $(srctree)/tools/build fixdep
+	$(Q)$(MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= fixdep
 endif
 
 .PHONY: fixdep
Signature · 1 line
2.1.0
author maintainer
#4 lore raw

PATCH 4/4 tools lib bpf: Don't do a feature check when cleaning

In reply to Arnaldo Carvalho de Melo

From: Wang Nan <[email protected]>

Before this patch libbpf always do feature check even when cleaning.

For example:

  $ cd kernel/tools/lib/bpf
  $ make

Auto-detecting system features:
... libelf: [ on ]
... bpf: [ on ]

    CC       libbpf.o
    CC       bpf.o
    LD       libbpf-in.o
    LINK     libbpf.a
    LINK     libbpf.so
  $ make clean
    CLEAN    libbpf
    CLEAN    core-gen
  $ make clean

Auto-detecting system features:
... libelf: [ on ]
... bpf: [ on ]

CLEAN libbpf
CLEAN core-gen
$

Although the first 'make clean' doesn't show feature check result, it still does the check. No output because check result is similar to FEATURE-DUMP.libbpf.

This patch uses same method as perf to turn off feature checking when 'make clean'.

---
 tools/lib/bpf/Makefile | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/Makefile +10 -0
index a3caaf3eafbd..636e3ddb93a1 100644
@@ -71,7 +71,17 @@ FEATURE_DISPLAY = libelf bpf
 INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
 FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
 
+check_feat := 1
+NON_CHECK_FEAT_TARGETS := clean TAGS tags cscope help
+ifdef MAKECMDGOALS
+ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
+  check_feat := 0
+endif
+endif
+
+ifeq ($(check_feat),1)
 include $(srctree)/tools/build/Makefile.feature
+endif
 
 export prefix libdir src obj
 
Signature · 1 line
2.1.0
#5 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 52 lines · Arnaldo Carvalho de Melo

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

Hi,

Please consider pulling, this is on top of my previous
perf-core-for-mingo pull request.

- Arnaldo

The following changes since commit 646a6e846c4dc3812c614fd061603b6db5b8d380:

perf callchain: Add missing parent_val initialization (2015-11-23 18:31:25 -0300)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-2

for you to fetch changes up to d8ad6a15cc3a364de6c8010378adc3fb06ce3ff1:

tools lib bpf: Don't do a feature check when cleaning (2015-11-25 16:38:13 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

User visible:

- Fix to free temporal Dwarf_Frame correctly in 'perf probe', fixing a regression introduced in perf/core that prevented, at least, adding an uprobe collecting function parameter values (Masami Hiramatsu)

- Fix output of %llu for 64 bit values read on 32 bit machines in libtraceevent (Steven Rostedt)

Developer visible:

- Clean CFLAGS and LDFLAGS for fixdep in tools/build (Wang Nan)

- Don't do a feature check when cleaning tools/lib/bpf (Wang Nan)

----------------------------------------------------------------
Masami Hiramatsu (1):
perf probe: Fix to free temporal Dwarf_Frame correctly

Steven Rostedt (1):
tools lib traceevent: Fix output of %llu for 64 bit values read on 32 bit machines

Wang Nan (2):
tools build: Clean CFLAGS and LDFLAGS for fixdep tools lib bpf: Don't do a feature check when cleaning

Quoted 5 lines
 tools/build/Makefile.include       |  2 +-
 tools/lib/bpf/Makefile             | 10 ++++++++++
 tools/lib/traceevent/event-parse.c |  5 ++---
 tools/perf/util/probe-finder.c     | 13 ++++++-------
 4 files changed, 19 insertions(+), 11 deletions(-)

Pulled, thanks a lot Arnaldo!

Ingo