Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e65312fe authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge tag 'perf-core-for-mingo' of...

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

 into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

  * Add support for the new DWARF unwinder library in elfutils (Jiri Olsa)

  * Fix build race in the generation of bison files (Jiri Olsa)

  * Further streamline the feature detection display, trimming it a bit to
    show just the libraries detected, using VF=1 gets a more verbose output,
    showing the less interesting feature checks as well (Jiri Olsa).

  * Check compatible symtab type before loading dso (Namhyung Kim)

  * Check return value of filename__read_debuglink() (Stephane Eranian)

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 4a234593 1029f9fe
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ include config/utilities.mak

# Define V to have a more verbose compile.
#
# Define VF to have a more verbose feature check output.
#
# Define O to save output files in a separate directory.
#
# Define ARCH as name of target architecture if you want cross-builds.
@@ -55,6 +57,9 @@ include config/utilities.mak
# Define NO_LIBAUDIT if you do not want libaudit support
#
# Define NO_LIBBIONIC if you do not want bionic support
#
# Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support
# for dwarf backtrace post unwind.

ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(shell pwd)))
@@ -404,7 +409,7 @@ endif
LIB_OBJS += $(OUTPUT)tests/code-reading.o
LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
ifndef NO_LIBUNWIND
ifndef NO_DWARF_UNWIND
ifeq ($(ARCH),x86)
LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
endif
@@ -476,6 +481,11 @@ ifndef NO_DWARF
endif # NO_DWARF
endif # NO_LIBELF

ifndef NO_LIBDW_DWARF_UNWIND
  LIB_OBJS += $(OUTPUT)util/unwind-libdw.o
  LIB_H += util/unwind-libdw.h
endif

ifndef NO_LIBUNWIND
  LIB_OBJS += $(OUTPUT)util/unwind-libunwind.o
endif
@@ -712,9 +722,15 @@ $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
# we depend the various files onto their directories.
DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(GTK_OBJS)
DIRECTORY_DEPS += $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
# no need to add flex objects, because they depend on bison ones
DIRECTORY_DEPS += $(OUTPUT)util/parse-events-bison.c
DIRECTORY_DEPS += $(OUTPUT)util/pmu-bison.c

OUTPUT_DIRECTORIES := $(sort $(dir $(DIRECTORY_DEPS)))

$(DIRECTORY_DEPS): | $(OUTPUT_DIRECTORIES)
# In the second step, we make a rule to actually create these directories
$(sort $(dir $(DIRECTORY_DEPS))):
$(OUTPUT_DIRECTORIES):
	$(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null

$(LIB_FILE): $(LIB_OBJS)
@@ -891,7 +907,7 @@ config-clean:
clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean
	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS)
	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf
	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
	$(python-clean)

+5 −0
Original line number Diff line number Diff line
@@ -4,6 +4,11 @@ LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
endif
ifndef NO_LIBUNWIND
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
endif
ifndef NO_LIBDW_DWARF_UNWIND
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libdw.o
endif
ifndef NO_DWARF_UNWIND
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/regs_load.o
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o
endif
+51 −0
Original line number Diff line number Diff line
#include <elfutils/libdwfl.h>
#include "../../util/unwind-libdw.h"
#include "../../util/perf_regs.h"

bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
{
	struct unwind_info *ui = arg;
	struct regs_dump *user_regs = &ui->sample->user_regs;
	Dwarf_Word dwarf_regs[17];
	unsigned nregs;

#define REG(r) ({						\
	Dwarf_Word val = 0;					\
	perf_reg_value(&val, user_regs, PERF_REG_X86_##r);	\
	val;							\
})

	if (user_regs->abi == PERF_SAMPLE_REGS_ABI_32) {
		dwarf_regs[0] = REG(AX);
		dwarf_regs[1] = REG(CX);
		dwarf_regs[2] = REG(DX);
		dwarf_regs[3] = REG(BX);
		dwarf_regs[4] = REG(SP);
		dwarf_regs[5] = REG(BP);
		dwarf_regs[6] = REG(SI);
		dwarf_regs[7] = REG(DI);
		dwarf_regs[8] = REG(IP);
		nregs = 9;
	} else {
		dwarf_regs[0]  = REG(AX);
		dwarf_regs[1]  = REG(DX);
		dwarf_regs[2]  = REG(CX);
		dwarf_regs[3]  = REG(BX);
		dwarf_regs[4]  = REG(SI);
		dwarf_regs[5]  = REG(DI);
		dwarf_regs[6]  = REG(BP);
		dwarf_regs[7]  = REG(SP);
		dwarf_regs[8]  = REG(R8);
		dwarf_regs[9]  = REG(R9);
		dwarf_regs[10] = REG(R10);
		dwarf_regs[11] = REG(R11);
		dwarf_regs[12] = REG(R12);
		dwarf_regs[13] = REG(R13);
		dwarf_regs[14] = REG(R14);
		dwarf_regs[15] = REG(R15);
		dwarf_regs[16] = REG(IP);
		nregs = 17;
	}

	return dwfl_thread_state_registers(thread, 0, nregs, dwarf_regs);
}
+169 −63
Original line number Diff line number Diff line
@@ -59,6 +59,18 @@ ifeq ($(NO_PERF_REGS),0)
  CFLAGS += -DHAVE_PERF_REGS_SUPPORT
endif

ifndef NO_LIBELF
  # for linking with debug library, run like:
  # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  ifdef LIBDW_DIR
    LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
    LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib

    FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
    FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
  endif
endif

# include ARCH specific config
-include $(src-perf)/arch/$(ARCH)/Makefile

@@ -147,7 +159,35 @@ CORE_FEATURE_TESTS = \
	libunwind			\
	on-exit				\
	stackprotector-all		\
	timerfd
	timerfd				\
	libdw-dwarf-unwind

LIB_FEATURE_TESTS =			\
	dwarf				\
	glibc				\
	gtk2				\
	libaudit			\
	libbfd				\
	libelf				\
	libnuma				\
	libperl				\
	libpython			\
	libslang			\
	libunwind			\
	libdw-dwarf-unwind

VF_FEATURE_TESTS =			\
	backtrace			\
	fortify-source			\
	gtk2-infobar			\
	libelf-getphdrnum		\
	libelf-mmap			\
	libpython-version		\
	on-exit				\
	stackprotector-all		\
	timerfd				\
	libunwind-debug-frame		\
	bionic

# Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features.
# If in the future we need per-feature checks/flags for features not
@@ -160,17 +200,6 @@ endef

$(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat)))

#
# So here we detect whether test-all was rebuilt, to be able
# to skip the print-out of the long features list if the file
# existed before and after it was built:
#
ifeq ($(wildcard $(OUTPUT)config/feature-checks/test-all.bin),)
  test-all-failed := 1
else
  test-all-failed := 0
endif

#
# Special fast-path for the 'all features are available' case:
#
@@ -180,15 +209,6 @@ $(call feature_check,all,$(MSG))
# Just in case the build freshly failed, make sure we print the
# feature matrix:
#
ifeq ($(feature-all), 0)
  test-all-failed := 1
endif

ifeq ($(test-all-failed),1)
  $(info )
  $(info Auto-detecting system features:)
endif

ifeq ($(feature-all), 1)
  #
  # test-all.c passed - just set all the core feature flags to 1:
@@ -199,27 +219,6 @@ else
  $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
endif

#
# Print the result of the feature test:
#
feature_print = $(eval $(feature_print_code)) $(info $(MSG))

define feature_print_code
  ifeq ($(feature-$(1)), 1)
    MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
  else
    MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  endif
endef

#
# Only print out our features if we rebuilt the testcases or if a test failed:
#
ifeq ($(test-all-failed), 1)
  $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_print,$(feat)))
  $(info )
endif

ifeq ($(feature-stackprotector-all), 1)
  CFLAGS += -fstack-protector-all
endif
@@ -264,6 +263,7 @@ ifdef NO_LIBELF
  NO_DWARF := 1
  NO_DEMANGLE := 1
  NO_LIBUNWIND := 1
  NO_LIBDW_DWARF_UNWIND := 1
else
  ifeq ($(feature-libelf), 0)
    ifeq ($(feature-glibc), 1)
@@ -282,13 +282,12 @@ else
      msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
    endif
  else
    # for linking with debug library, run like:
    # make DEBUG=1 LIBDW_DIR=/opt/libdw/
    ifdef LIBDW_DIR
      LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
      LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
    ifndef NO_LIBDW_DWARF_UNWIND
      ifneq ($(feature-libdw-dwarf-unwind),1)
        NO_LIBDW_DWARF_UNWIND := 1
        msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
      endif
    endif

    ifneq ($(feature-dwarf), 1)
      msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
      NO_DWARF := 1
@@ -324,9 +323,37 @@ endif # NO_LIBELF

ifndef NO_LIBUNWIND
  ifneq ($(feature-libunwind), 1)
    msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
    msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
    NO_LIBUNWIND := 1
  endif
endif

dwarf-post-unwind := 1
dwarf-post-unwind-text := BUG

# setup DWARF post unwinder
ifdef NO_LIBUNWIND
  ifdef NO_LIBDW_DWARF_UNWIND
    msg := $(warning Disabling post unwind, no support found.);
    dwarf-post-unwind := 0
  else
    dwarf-post-unwind-text := libdw
  endif
else
  dwarf-post-unwind-text := libunwind
  # Enable libunwind support by default.
  ifndef NO_LIBDW_DWARF_UNWIND
    NO_LIBDW_DWARF_UNWIND := 1
  endif
endif

ifeq ($(dwarf-post-unwind),1)
  CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
else
  NO_DWARF_UNWIND := 1
endif

ifndef NO_LIBUNWIND
  ifeq ($(ARCH),arm)
    $(call feature_check,libunwind-debug-frame)
    ifneq ($(feature-libunwind-debug-frame), 1)
@@ -337,12 +364,10 @@ ifndef NO_LIBUNWIND
    # non-ARM has no dwarf_find_debug_frame() function:
    CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
  endif

    CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT -DHAVE_LIBUNWIND_SUPPORT
  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
  EXTLIBS += $(LIBUNWIND_LIBS)
  CFLAGS  += $(LIBUNWIND_CFLAGS)
  LDFLAGS += $(LIBUNWIND_LDFLAGS)
  endif # ifneq ($(feature-libunwind), 1)
endif

ifndef NO_LIBAUDIT
@@ -602,3 +627,84 @@ ifdef DESTDIR
plugindir=$(libdir)/traceevent/plugins
plugindir_SQ= $(subst ','\'',$(plugindir))
endif

#
# Print the result of the feature test:
#
feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))

define feature_print_status_code
  ifeq ($(feature-$(1)), 1)
    MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
  else
    MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  endif
endef

feature_print_var = $(eval $(feature_print_var_code)) $(info $(MSG))
define feature_print_var_code
    MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
endef

feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
define feature_print_text_code
    MSG = $(shell printf '...%30s: %s' $(1) $(2))
endef

PERF_FEATURES := $(foreach feat,$(LIB_FEATURE_TESTS),feature-$(feat)($(feature-$(feat))))
PERF_FEATURES_FILE := $(shell touch $(OUTPUT)PERF-FEATURES; cat $(OUTPUT)PERF-FEATURES)

ifeq ($(dwarf-post-unwind),1)
  PERF_FEATURES += dwarf-post-unwind($(dwarf-post-unwind-text))
endif

# The $(display_lib) controls the default detection message
# output. It's set if:
# - detected features differes from stored features from
#   last build (in PERF-FEATURES file)
# - one of the $(LIB_FEATURE_TESTS) is not detected
# - VF is enabled

ifneq ("$(PERF_FEATURES)","$(PERF_FEATURES_FILE)")
  $(shell echo "$(PERF_FEATURES)" > $(OUTPUT)PERF-FEATURES)
  display_lib := 1
endif

feature_check = $(eval $(feature_check_code))
define feature_check_code
  ifneq ($(feature-$(1)), 1)
    display_lib := 1
  endif
endef

$(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_check,$(feat)))

ifeq ($(VF),1)
  display_lib := 1
  display_vf := 1
endif

ifeq ($(display_lib),1)
  $(info )
  $(info Auto-detecting system features:)
  $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_print_status,$(feat),))

  ifeq ($(dwarf-post-unwind),1)
    $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
  endif
endif

ifeq ($(display_vf),1)
  $(foreach feat,$(VF_FEATURE_TESTS),$(call feature_print_status,$(feat),))
  $(info )
  $(call feature_print_var,prefix)
  $(call feature_print_var,bindir)
  $(call feature_print_var,libdir)
  $(call feature_print_var,sysconfdir)
  $(call feature_print_var,LIBUNWIND_DIR)
  $(call feature_print_var,LIBDW_DIR)
endif

ifeq ($(display_lib),1)
  $(info )
endif
+5 −1
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ FILES= \
	test-libunwind-debug-frame.bin	\
	test-on-exit.bin		\
	test-stackprotector-all.bin	\
	test-timerfd.bin
	test-timerfd.bin		\
	test-libdw-dwarf-unwind.bin

CC := $(CROSS_COMPILE)gcc -MD
PKG_CONFIG := $(CROSS_COMPILE)pkg-config
@@ -141,6 +142,9 @@ test-backtrace.bin:
test-timerfd.bin:
	$(BUILD)

test-libdw-dwarf-unwind.bin:
	$(BUILD)

-include *.d

###############################
Loading