Skip to contentSkip to conversation

perf/urgent fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 7 messages Sep 17, 2015 – Sep 18, 2015 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit f6cf87f748ff9480f97ff9c5caf6d6faacf52aa1:

Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2015-09-16 09:06:54 +0200)

are available in the git repository at:

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

for you to fetch changes up to bf6445631c6f00882b25516a174d5073ce0c6f81:

perf tools: Bool functions shouldn't return -1 (2015-09-17 15:31:52 -0300)

----------------------------------------------------------------
perf/urgent fixes:

User visible:

- When handling perf_event_open() returning EBUSY and not being able to opendir the procfs mount point we would tell the user that the oprofile daemon was found by returning -1 on as the return for a bool function, oops, fix it, found with Coccinelle (Peter Senna Tschudin).

- Fix per-pkg event reporting bug in 'perf stat' (Stephane Eranian)

Developer visible:

- Fix missing prototype for function provided when it isn't present in the libelf present, fixing the build on RHEL/CentOS 5.1 systems, for instance (Arnaldo Carvalho de Melo)

- Detect if the gcc and libnuma have the features needed to avoid requiring the use of NO_LIBNUMA and/or NO_AUXTRACE to build on older systems (Arnaldo Carvalho de Melo)

----------------------------------------------------------------
Arnaldo Carvalho de Melo (3):
Revert "perf symbols: Fix mismatched declarations for elf_getphdrnum" tools build: Add test for presence of numa_num_possible_cpus() in libnuma tools build: Add test for presence of __get_cpuid() gcc builtin

Peter Senna Tschudin (1):
perf tools: Bool functions shouldn't return -1

Stephane Eranian (1):
perf stat: Fix per-pkg event reporting bug

 tools/build/Makefile.feature                      |  8 ++++++--
 tools/build/feature/Makefile                      | 10 +++++++++-
 tools/build/feature/test-all.c                    | 10 ++++++++++
 tools/build/feature/test-get_cpuid.c              |  7 +++++++
 tools/build/feature/test-numa_num_possible_cpus.c |  6 ++++++
 tools/perf/config/Makefile                        | 20 +++++++++++++++-----
 tools/perf/util/stat.c                            | 16 ++++++++++++++--
 tools/perf/util/symbol-elf.c                      |  2 +-
 tools/perf/util/util.c                            |  2 +-
 9 files changed, 69 insertions(+), 12 deletions(-)
 create mode 100644 tools/build/feature/test-get_cpuid.c
 create mode 100644 tools/build/feature/test-numa_num_possible_cpus.c
author maintainer
#1 lore raw

PATCH 1/5 perf stat: Fix per-pkg event reporting bug

From: Stephane Eranian <[email protected]>

Per-pkg events need to be captured once per processor socket. The code in check_per_pkg() ensures only one value per processor package is used. However there is a problem with this function in case the first CPU of the package does not measure anything for the per-pkg event, but other CPUs do.

Consider the following:

  $ create cgroup FOO; echo $$ >FOO/tasks; taskset -c 1 noploop &
  $ perf stat -a -I 1000 -e intel_cqm/llc_occupancy/ -G FOO sleep 100
    1.00000 <not counted> Bytes intel_cqm/llc_occupancy/  FOO

The reason for this is that CPU0 in the cgroup has nothing running on it. Yet check_per_plg() will mark socket0 as processed and no other event value will be considered for the socket.

This patch fixes the problem by having check_per_pkg() only consider events which actually ran.

---
 tools/perf/util/stat.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/perf/util/stat.c +14 -2
index 415c359de465..2d065d065b67 100644
@@ -196,7 +196,8 @@ static void zero_per_pkg(struct perf_evsel *counter)
 		memset(counter->per_pkg_mask, 0, MAX_NR_CPUS);
 }
 
-static int check_per_pkg(struct perf_evsel *counter, int cpu, bool *skip)
+static int check_per_pkg(struct perf_evsel *counter,
+			 struct perf_counts_values *vals, int cpu, bool *skip)
 {
 	unsigned long *mask = counter->per_pkg_mask;
 	struct cpu_map *cpus = perf_evsel__cpus(counter);
@@ -218,6 +219,17 @@ static int check_per_pkg(struct perf_evsel *counter, int cpu, bool *skip)
 		counter->per_pkg_mask = mask;
 	}
 
+	/*
+	 * we do not consider an event that has not run as a good
+	 * instance to mark a package as used (skip=1). Otherwise
+	 * we may run into a situation where the first CPU in a package
+	 * is not running anything, yet the second is, and this function
+	 * would mark the package as used after the first CPU and would
+	 * not read the values from the second CPU.
+	 */
+	if (!(vals->run && vals->ena))
+		return 0;
+
 	s = cpu_map__get_socket(cpus, cpu);
 	if (s < 0)
 		return -1;
@@ -235,7 +247,7 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel
 	static struct perf_counts_values zero;
 	bool skip = false;
 
-	if (check_per_pkg(evsel, cpu, &skip)) {
+	if (check_per_pkg(evsel, count, cpu, &skip)) {
 		pr_err("failed to read per-pkg counter\n");
 		return -1;
 	}
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/5 Revert "perf symbols: Fix mismatched declarations for elf_getphdrnum"

In reply to Arnaldo Carvalho de Melo

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

This reverts commit f785f2357673d520a0b7b468973cdd197f336494.

We have a test to check if elf_getphdrnum() is present, so, if it fails, we'll get:

[acme@rhel5 linux]$ cat /tmp/build/perf/feature/test-libelf-getphdrnum.make.output
cc1: warnings being treated as errors
test-libelf-getphdrnum.c: In function ‘main’:
test-libelf-getphdrnum.c:7: warning: implicit declaration of function ‘elf_getphdrnum’ [acme@rhel5 linux]$

And this block will not be compiled:

  #ifndef HAVE_ELF_GETPHDRNUM_SUPPORT
  static int elf_getphdrnum(Elf *elf, size_t *dst)
  ...
  #endif

So, if elf_getphdrnum() is being defined somewhere, there is a problem with the test that is not detecting that function, go fix it.

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc "Naveen N. Rao" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Victor Kamensky <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/util/symbol-elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +1 -1
index 53bb5f59ec58..f78ea3dc4c08 100644
@@ -38,7 +38,7 @@ static inline char *bfd_demangle(void __maybe_unused *v,
 #endif
 
 #ifndef HAVE_ELF_GETPHDRNUM_SUPPORT
-int elf_getphdrnum(Elf *elf, size_t *dst)
+static int elf_getphdrnum(Elf *elf, size_t *dst)
 {
 	GElf_Ehdr gehdr;
 	GElf_Ehdr *ehdr;
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 3/5 tools build: Add test for presence of numa_num_possible_cpus() in libnuma

In reply to Arnaldo Carvalho de Melo

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

The existing numa test checks only if numa.h and numa_available() are present, but that can be satisfied with an old libnuma that is not enough for the 'perf bench numa' entry, so add a test to check for that:

[acme@rhel5 linux]$ make NO_AUXTRACE=1 NO_LIBPERL=1 -C tools/perf O=/tmp/build/perf install-bin
make: Entering directory `/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j2' parallel build

Auto-detecting system features:
... libelf: [ on ]
... libnuma: [ on ]
... numa_num_possible_cpus: [ OFF ]
... libperl: [ on ]

<SNIP>
config/Makefile:577: Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8
INSTALL binaries
<SNIP>

This fixes the build on old systems such as RHEL/CentOS 5.11.

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc "Naveen N. Rao" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Victor Kamensky <[email protected]>
Cc Vinson Lee <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/build/Makefile.feature                      |  2 ++
 tools/build/feature/Makefile                      |  4 ++++
 tools/build/feature/test-all.c                    |  5 +++++
 tools/build/feature/test-numa_num_possible_cpus.c |  6 ++++++
 tools/perf/config/Makefile                        | 11 ++++++++---
 5 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 tools/build/feature/test-numa_num_possible_cpus.c
tools/build/Makefile.feature +2 -0
index 2975632d51e2..970242098a7c 100644
@@ -41,6 +41,7 @@ FEATURE_TESTS ?=			\
 	libelf-getphdrnum		\
 	libelf-mmap			\
 	libnuma				\
+	numa_num_possible_cpus		\
 	libperl				\
 	libpython			\
 	libpython-version		\
@@ -61,6 +62,7 @@ FEATURE_DISPLAY ?=			\
 	libbfd				\
 	libelf				\
 	libnuma				\
+	numa_num_possible_cpus		\
 	libperl				\
 	libpython			\
 	libslang			\
tools/build/feature/Makefile +4 -0
index 74ca42093d70..e13a42bd0274 100644
@@ -19,6 +19,7 @@ FILES=					\
 	test-libelf-getphdrnum.bin	\
 	test-libelf-mmap.bin		\
 	test-libnuma.bin		\
+	test-numa_num_possible_cpus.bin	\
 	test-libperl.bin		\
 	test-libpython.bin		\
 	test-libpython-version.bin	\
@@ -87,6 +88,9 @@ test-libelf-getphdrnum.bin:
 test-libnuma.bin:
 	$(BUILD) -lnuma
 
+test-numa_num_possible_cpus.bin:
+	$(BUILD) -lnuma
+
 test-libunwind.bin:
 	$(BUILD) -lelf
 
tools/build/feature/test-all.c +5 -0
index 84689a67814a..7a8cdbad3e1b 100644
@@ -77,6 +77,10 @@
 # include "test-libnuma.c"
 #undef main
 
+#define main main_test_numa_num_possible_cpus
+# include "test-numa_num_possible_cpus.c"
+#undef main
+
 #define main main_test_timerfd
 # include "test-timerfd.c"
 #undef main
@@ -136,6 +140,7 @@ int main(int argc, char *argv[])
 	main_test_libbfd();
 	main_test_backtrace();
 	main_test_libnuma();
+	main_test_numa_num_possible_cpus();
 	main_test_timerfd();
 	main_test_stackprotector_all();
 	main_test_libdw_dwarf_unwind();
tools/build/feature/test-numa_num_possible_cpus.c new file +6 -0
new file mode 100644
index 000000000000..2606e94b0659
@@ -0,0 +1,6 @@
+#include <numa.h>
+
+int main(void)
+{
+	return numa_num_possible_cpus();
+}
tools/perf/config/Makefile +8 -3
index 827557fc7511..053e65b04dc3 100644
@@ -573,9 +573,14 @@ ifndef NO_LIBNUMA
     msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
     NO_LIBNUMA := 1
   else
-    CFLAGS += -DHAVE_LIBNUMA_SUPPORT
-    EXTLIBS += -lnuma
-    $(call detected,CONFIG_NUMA)
+    ifeq ($(feature-numa_num_possible_cpus), 0)
+      msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
+      NO_LIBNUMA := 1
+    else
+      CFLAGS += -DHAVE_LIBNUMA_SUPPORT
+      EXTLIBS += -lnuma
+      $(call detected,CONFIG_NUMA)
+    endif
   endif
 endif
 
Signature · 1 line
2.1.0
author maintainer
#4 lore raw

PATCH 4/5 tools build: Add test for presence of __get_cpuid() gcc builtin

In reply to Arnaldo Carvalho de Melo

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

The auxtrace code needed by Intel PT uses the __get_cpuid() gcc builtin, that is not present in old systems, breaking the build.

Add a test to check for that builtin and disable AUXTRACE in those systems.

[acme@rhel5 linux]$ make NO_LIBPERL=1 -C tools/perf O=/tmp/build/perf install-bin
make: Entering directory `/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j2' parallel build

Auto-detecting system features:
<SNIP>
... lzma: [ on ]
... get_cpuid: [ OFF ]
<SNIP>
config/Makefile:630: Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc
MKDIR /tmp/build/perf/util/
<SNIP>

This fixes the build on old systems such as RHEL/CentOS 5.11.

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc "Naveen N. Rao" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Victor Kamensky <[email protected]>
Cc Vinson Lee <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/build/Makefile.feature         | 6 ++++--
 tools/build/feature/Makefile         | 6 +++++-
 tools/build/feature/test-all.c       | 5 +++++
 tools/build/feature/test-get_cpuid.c | 7 +++++++
 tools/perf/config/Makefile           | 9 +++++++--
 5 files changed, 28 insertions(+), 5 deletions(-)
 create mode 100644 tools/build/feature/test-get_cpuid.c
tools/build/Makefile.feature +4 -2
index 970242098a7c..c8fe6d177119 100644
@@ -52,7 +52,8 @@ FEATURE_TESTS ?=			\
 	timerfd				\
 	libdw-dwarf-unwind		\
 	zlib				\
-	lzma
+	lzma				\
+	get_cpuid
 
 FEATURE_DISPLAY ?=			\
 	dwarf				\
@@ -69,7 +70,8 @@ FEATURE_DISPLAY ?=			\
 	libunwind			\
 	libdw-dwarf-unwind		\
 	zlib				\
-	lzma
+	lzma				\
+	get_cpuid
 
 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
 # If in the future we need per-feature checks/flags for features not
tools/build/feature/Makefile +5 -1
index e13a42bd0274..e43a2971bf56 100644
@@ -35,7 +35,8 @@ FILES=					\
 	test-compile-x32.bin		\
 	test-zlib.bin			\
 	test-lzma.bin			\
-	test-bpf.bin
+	test-bpf.bin			\
+	test-get_cpuid.bin
 
 CC := $(CROSS_COMPILE)gcc -MD
 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
@@ -166,6 +167,9 @@ test-zlib.bin:
 test-lzma.bin:
 	$(BUILD) -llzma
 
+test-get_cpuid.bin:
+	$(BUILD)
+
 test-bpf.bin:
 	$(BUILD)
 
tools/build/feature/test-all.c +5 -0
index 7a8cdbad3e1b..33cf6f20bd4e 100644
@@ -121,6 +121,10 @@
 # include "test-lzma.c"
 #undef main
 
+#define main main_test_get_cpuid
+# include "test-get_cpuid.c"
+#undef main
+
 int main(int argc, char *argv[])
 {
 	main_test_libpython();
@@ -148,6 +152,7 @@ int main(int argc, char *argv[])
 	main_test_zlib();
 	main_test_pthread_attr_setaffinity_np();
 	main_test_lzma();
+	main_test_get_cpuid();
 
 	return 0;
 }
tools/build/feature/test-get_cpuid.c new file +7 -0
new file mode 100644
index 000000000000..d7a2c407130d
@@ -0,0 +1,7 @@
+#include <cpuid.h>
+
+int main(void)
+{
+	unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
+	return __get_cpuid(0x15, &eax, &ebx, &ecx, &edx);
+}
tools/perf/config/Makefile +7 -2
index 053e65b04dc3..38a08539f4bf 100644
@@ -626,8 +626,13 @@ ifdef LIBBABELTRACE
 endif
 
 ifndef NO_AUXTRACE
-  $(call detected,CONFIG_AUXTRACE)
-  CFLAGS += -DHAVE_AUXTRACE_SUPPORT
+  ifeq ($(feature-get_cpuid), 0)
+    msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
+    NO_AUXTRACE := 1
+  else
+    $(call detected,CONFIG_AUXTRACE)
+    CFLAGS += -DHAVE_AUXTRACE_SUPPORT
+  endif
 endif
 
 # Among the variables below, these:
Signature · 1 line
2.1.0
author maintainer
#5 lore raw

PATCH 5/5 perf tools: Bool functions shouldn't return -1

In reply to Arnaldo Carvalho de Melo

From: Peter Senna Tschudin <[email protected]>

Returning a negative value for a boolean function seem to have the undesired effect of returning true. Replace -1 by false in a bool-returning function.

The diff of the .s file before and after the change (for x86_64):

3907c3907
< movl $1, %ebx
---

Quoted 1 line
	xorl	%ebx, %ebx

while if -1 is replaced by true, the diff is empty.

This issue was found by the following Coccinelle semantic patch:

  <smpl>
  @@
  identifier f;
  constant C;
  typedef bool;
  @@
  bool f (...){
  <+...
  * return -C;
  ...+>
  }
  </smpl>
---
 tools/perf/util/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/util.c +1 -1
index 7acafb3c5592..c2cd9bf2348b 100644
@@ -709,7 +709,7 @@ bool find_process(const char *name)
 
 	dir = opendir(procfs__mountpoint());
 	if (!dir)
-		return -1;
+		return false;
 
 	/* Walk through the directory. */
 	while (ret && (d = readdir(dir)) != NULL) {
Signature · 1 line
2.1.0
#6 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 54 lines · Arnaldo Carvalho de Melo

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit f6cf87f748ff9480f97ff9c5caf6d6faacf52aa1:

Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2015-09-16 09:06:54 +0200)

are available in the git repository at:

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

for you to fetch changes up to bf6445631c6f00882b25516a174d5073ce0c6f81:

perf tools: Bool functions shouldn't return -1 (2015-09-17 15:31:52 -0300)

----------------------------------------------------------------
perf/urgent fixes:

User visible:

- When handling perf_event_open() returning EBUSY and not being able to opendir the procfs mount point we would tell the user that the oprofile daemon was found by returning -1 on as the return for a bool function, oops, fix it, found with Coccinelle (Peter Senna Tschudin).

- Fix per-pkg event reporting bug in 'perf stat' (Stephane Eranian)

Developer visible:

- Fix missing prototype for function provided when it isn't present in the libelf present, fixing the build on RHEL/CentOS 5.1 systems, for instance (Arnaldo Carvalho de Melo)

- Detect if the gcc and libnuma have the features needed to avoid requiring the use of NO_LIBNUMA and/or NO_AUXTRACE to build on older systems (Arnaldo Carvalho de Melo)

----------------------------------------------------------------
Arnaldo Carvalho de Melo (3):
Revert "perf symbols: Fix mismatched declarations for elf_getphdrnum" tools build: Add test for presence of numa_num_possible_cpus() in libnuma tools build: Add test for presence of __get_cpuid() gcc builtin

Peter Senna Tschudin (1):
perf tools: Bool functions shouldn't return -1

Stephane Eranian (1):
perf stat: Fix per-pkg event reporting bug

Quoted 12 lines
 tools/build/Makefile.feature                      |  8 ++++++--
 tools/build/feature/Makefile                      | 10 +++++++++-
 tools/build/feature/test-all.c                    | 10 ++++++++++
 tools/build/feature/test-get_cpuid.c              |  7 +++++++
 tools/build/feature/test-numa_num_possible_cpus.c |  6 ++++++
 tools/perf/config/Makefile                        | 20 +++++++++++++++-----
 tools/perf/util/stat.c                            | 16 ++++++++++++++--
 tools/perf/util/symbol-elf.c                      |  2 +-
 tools/perf/util/util.c                            |  2 +-
 9 files changed, 69 insertions(+), 12 deletions(-)
 create mode 100644 tools/build/feature/test-get_cpuid.c
 create mode 100644 tools/build/feature/test-numa_num_possible_cpus.c

Pulled, thanks Arnaldo!

Ingo