Skip to contentSkip to conversation

perf tools: add support for libpfm4

PATCH Superseded Ian Rogers 2 participants 4 messages Apr 7, 2020 – Apr 11, 2020

Subsystems (4)

v7 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH v7 1/1 perf tools: add support for libpfm4

From: Stephane Eranian <[email protected]>

This patch links perf with the libpfm4 library if it is available and NO_LIBPFM4 isn't passed to the build. The libpfm4 library contains hardware event tables for all processors supported by perf_events. It is a helper library that helps convert from a symbolic event name to the event encoding required by the underlying kernel interface. This library is open-source and available from: http://perfmon2.sf.net.

With this patch, it is possible to specify full hardware events by name. Hardware filters are also supported. Events must be specified via the --pfm-events and not -e option. Both options are active at the same time and it is possible to mix and match:

$ perf stat --pfm-events inst_retired:any_p:c=1:i -e cycles ....

v7 rebases and adds fallback code for libpfm4 events.
The fallback code is to force user only priv level in case the perf_event_open() syscall failed for permissions reason.
the fallback forces a user privilege level restriction on the event string, so depending on the syntax either u or :u is needed.

But libpfm4 can use a : or . as the separator, so simply searching for ':' vs. '/' is not good enough to determine the syntax needed. Therefore, this patch introduces a new evsel boolean field to mark events coming from libpfm4. The field is then used to adjust the fallback string.
v6 is a rebase.
v5 is a rebase.
v4 is a rebase on git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
branch perf/core and re-adds the tools/build/feature/test-libpfm4.c missed in v3.
v3 is against acme/perf/core and removes a diagnostic warning.
v2 of this patch makes the --pfm-events man page documentation conditional on libpfm4 behing configured. It tidies some of the documentation and adds the feature test missed in the v1 patch.

---
 tools/build/Makefile.feature             |   6 +-
 tools/build/feature/Makefile             |   6 +-
 tools/build/feature/test-libpfm4.c       |   8 +
 tools/perf/Documentation/Makefile        |   4 +-
 tools/perf/Documentation/perf-record.txt |  11 +
 tools/perf/Documentation/perf-stat.txt   |  10 +
 tools/perf/Documentation/perf-top.txt    |  11 +
 tools/perf/Makefile.config               |  12 ++
 tools/perf/Makefile.perf                 |   6 +-
 tools/perf/builtin-list.c                |  16 ++
 tools/perf/builtin-record.c              |  20 ++
 tools/perf/builtin-stat.c                |  21 ++
 tools/perf/builtin-top.c                 |  20 ++
 tools/perf/util/evsel.c                  |   6 +
 tools/perf/util/evsel.h                  |   3 +
 tools/perf/util/parse-events.c           | 247 +++++++++++++++++++++++
 tools/perf/util/parse-events.h           |   5 +
 tools/perf/util/pmu.c                    |  11 +
 tools/perf/util/pmu.h                    |   1 +
 19 files changed, 417 insertions(+), 7 deletions(-)
 create mode 100644 tools/build/feature/test-libpfm4.c
tools/build/Makefile.feature +4 -2
index 3e0c019ef297..0b651171476f 100644
@@ -73,7 +73,8 @@ FEATURE_TESTS_BASIC :=                  \
         libaio				\
         libzstd				\
         disassembler-four-args		\
-        file-handle
+        file-handle			\
+        libpfm4
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
 # of all feature tests
@@ -128,7 +129,8 @@ FEATURE_DISPLAY ?=              \
          bpf			\
          libaio			\
          libzstd		\
-         disassembler-four-args
+         disassembler-four-args	\
+         libpfm4
 
 # 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 621f528f7822..a6eded94a36b 100644
@@ -68,7 +68,8 @@ FILES=                                          \
          test-llvm-version.bin			\
          test-libaio.bin			\
          test-libzstd.bin			\
-         test-file-handle.bin
+         test-file-handle.bin			\
+         test-libpfm4.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -325,6 +326,9 @@ $(OUTPUT)test-libzstd.bin:
 $(OUTPUT)test-file-handle.bin:
 	$(BUILD)
 
+$(OUTPUT)test-libpfm4.bin:
+	$(BUILD) -lpfm
+
 ###############################
 
 clean:
tools/build/feature/test-libpfm4.c new file +8 -0
new file mode 100644
index 000000000000..7f24df86cf09
@@ -0,0 +1,8 @@
+#include <sys/types.h>
+#include <perfmon/pfmlib.h>
+
+int main(void)
+{
+        pfm_initialize();
+        return 0;
+}
tools/perf/Documentation/Makefile +2 -2
index 31824d5269cc..6e54979c2124 100644
@@ -48,7 +48,7 @@ man5dir=$(mandir)/man5
 man7dir=$(mandir)/man7
 
 ASCIIDOC=asciidoc
-ASCIIDOC_EXTRA = --unsafe -f asciidoc.conf
+ASCIIDOC_EXTRA += --unsafe -f asciidoc.conf
 ASCIIDOC_HTML = xhtml11
 MANPAGE_XSL = manpage-normal.xsl
 XMLTO_EXTRA =
@@ -59,7 +59,7 @@ HTML_REF = origin/html
 
 ifdef USE_ASCIIDOCTOR
 ASCIIDOC = asciidoctor
-ASCIIDOC_EXTRA = -a compat-mode
+ASCIIDOC_EXTRA += -a compat-mode
 ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions
 ASCIIDOC_EXTRA += -a mansource="perf" -a manmanual="perf Manual"
 ASCIIDOC_HTML = xhtml5
tools/perf/Documentation/perf-record.txt +11 -0
index b3f3b3f1c161..ad2c41f595c2 100644
@@ -596,6 +596,17 @@ Make a copy of /proc/kcore and place it into a directory with the perf data file
 Limit the sample data max size, <size> is expected to be a number with
 appended unit character - B/K/M/G
 
+ifdef::HAVE_LIBPFM[]
+--pfm-events events::
+Select a PMU event using libpfm4 syntax (see http://perfmon2.sf.net)
+including support for event filters. For example '--pfm-events
+inst_retired:any_p:u:c=1:i'. More than one event can be passed to the
+option using the comma separator. Hardware events and generic hardware
+events cannot be mixed together. The latter must be used with the -e
+option. The -e option and this one can be mixed and matched.  Events
+can be grouped using the {} notation.
+endif::HAVE_LIBPFM[]
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1], linkperf:perf-intel-pt[1]
tools/perf/Documentation/perf-stat.txt +10 -0
index 4d56586b2fb9..536952ad592c 100644
@@ -71,6 +71,16 @@ report::
 --tid=<tid>::
         stat events on existing thread id (comma separated list)
 
+ifdef::HAVE_LIBPFM[]
+--pfm-events events::
+Select a PMU event using libpfm4 syntax (see http://perfmon2.sf.net)
+including support for event filters. For example '--pfm-events
+inst_retired:any_p:u:c=1:i'. More than one event can be passed to the
+option using the comma separator. Hardware events and generic hardware
+events cannot be mixed together. The latter must be used with the -e
+option. The -e option and this one can be mixed and matched.  Events
+can be grouped using the {} notation.
+endif::HAVE_LIBPFM[]
 
 -a::
 --all-cpus::
tools/perf/Documentation/perf-top.txt +11 -0
index 487737a725e9..9858e3640b0c 100644
@@ -319,6 +319,17 @@ Default is to monitor all CPUS.
 	go straight to the histogram browser, just like 'perf top' with no events
 	explicitely specified does.
 
+ifdef::HAVE_LIBPFM[]
+--pfm-events events::
+Select a PMU event using libpfm4 syntax (see http://perfmon2.sf.net)
+including support for event filters. For example '--pfm-events
+inst_retired:any_p:u:c=1:i'. More than one event can be passed to the
+option using the comma separator. Hardware events and generic hardware
+events cannot be mixed together. The latter must be used with the -e
+option. The -e option and this one can be mixed and matched.  Events
+can be grouped using the {} notation.
+endif::HAVE_LIBPFM[]
+
 
 INTERACTIVE PROMPTING KEYS
 --------------------------
tools/perf/Makefile.config +12 -0
index 12a8204d63c6..26167ad38a47 100644
@@ -1012,6 +1012,18 @@ ifdef LIBCLANGLLVM
   endif
 endif
 
+ifndef NO_LIBPFM4
+  ifeq ($(feature-libpfm4), 1)
+    CFLAGS += -DHAVE_LIBPFM
+    EXTLIBS += -lpfm
+    ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
+    $(call detected,CONFIG_LIBPFM4)
+  else
+    msg := $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev);
+    NO_LIBPFM4 := 1
+  endif
+endif
+
 # Among the variables below, these:
 #   perfexecdir
 #   perf_include_dir
tools/perf/Makefile.perf +4 -2
index d15a311408f1..9787eb3ca0a9 100644
@@ -118,6 +118,8 @@ include ../scripts/utilities.mak
 #
 # Define LIBBPF_DYNAMIC to enable libbpf dynamic linking.
 #
+# Define NO_LIBPFM4 to disable libpfm4 extension.
+#
 
 # As per kernel Makefile, avoid funny character set dependencies
 unexport LC_ALL
@@ -188,7 +190,7 @@ AWK     = awk
 # non-config cases
 config := 1
 
-NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
+NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help
 
 ifdef MAKECMDGOALS
 ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
@@ -832,7 +834,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
 
 # 'make doc' should call 'make -C Documentation all'
 $(DOC_TARGETS):
-	$(Q)$(MAKE) -C $(DOC_DIR) O=$(OUTPUT) $(@:doc=all)
+	$(Q)$(MAKE) -C $(DOC_DIR) O=$(OUTPUT) $(@:doc=all) ASCIIDOC_EXTRA=$(ASCIIDOC_EXTRA)
 
 TAG_FOLDERS= . ../lib ../include
 TAG_FILES= ../../include/uapi/linux/perf_event.h
tools/perf/builtin-list.c +16 -0
index 965ef017496f..5edeb428168a 100644
@@ -18,6 +18,10 @@
 #include <subcmd/parse-options.h>
 #include <stdio.h>
 
+#ifdef HAVE_LIBPFM
+#include <perfmon/pfmlib.h>
+#endif
+
 static bool desc_flag = true;
 static bool details_flag;
 
@@ -56,6 +60,18 @@ int cmd_list(int argc, const char **argv)
 	if (!raw_dump && pager_in_use())
 		printf("\nList of pre-defined events (to be used in -e):\n\n");
 
+#ifdef HAVE_LIBPFM
+	{
+		int ret;
+		ret = pfm_initialize();
+		if (ret != PFM_SUCCESS) {
+			fprintf(stderr,
+				"warning libpfm failed to initialize: %s\n",
+				pfm_strerror(ret));
+		}
+	}
+#endif
+
 	if (argc == 0) {
 		print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
 				details_flag, deprecated);
tools/perf/builtin-record.c +20 -0
index 1ab349abe904..5b7f18740ca9 100644
@@ -64,6 +64,10 @@
 #include <linux/zalloc.h>
 #include <linux/bitmap.h>
 
+#ifdef HAVE_LIBPFM
+#include <perfmon/pfmlib.h>
+#endif
+
 struct switch_output {
 	bool		 enabled;
 	bool		 signal;
@@ -2421,6 +2425,11 @@ static struct option __record_options[] = {
 #endif
 	OPT_CALLBACK(0, "max-size", &record.output_max_size,
 		     "size", "Limit the maximum size of the output file", parse_output_max_size),
+#ifdef HAVE_LIBPFM
+	OPT_CALLBACK(0, "pfm-events", &record.evlist, "event",
+		"libpfm4 event selector. use 'perf list' to list available events",
+		parse_libpfm_events_option),
+#endif
 	OPT_END()
 };
 
@@ -2461,6 +2470,17 @@ int cmd_record(int argc, const char **argv)
 	if (rec->evlist == NULL)
 		return -ENOMEM;
 
+#ifdef HAVE_LIBPFM
+	{
+		int ret;
+		ret = pfm_initialize();
+		if (ret != PFM_SUCCESS) {
+			ui__warning("warning libpfm failed to initialize: %s\n",
+				pfm_strerror(ret));
+		}
+	}
+#endif
+
 	err = perf_config(perf_record_config, rec);
 	if (err)
 		return err;
tools/perf/builtin-stat.c +21 -0
index ec053dc1e35c..c47eaf238f0c 100644
@@ -89,6 +89,10 @@
 #include <linux/ctype.h>
 #include <perf/evlist.h>
 
+#ifdef HAVE_LIBPFM
+#include <perfmon/pfmlib.h>
+#endif
+
 #define DEFAULT_SEPARATOR	" "
 #define FREEZE_ON_SMI_PATH	"devices/cpu/freeze_on_smi"
 
@@ -933,6 +937,11 @@ static struct option stat_options[] = {
 		    "Use with 'percore' event qualifier to show the event "
 		    "counts of one hardware thread by sum up total hardware "
 		    "threads of same physical core"),
+#ifdef HAVE_LIBPFM
+	OPT_CALLBACK(0, "pfm-events", &evsel_list, "event",
+		"libpfm4 event selector. use 'perf list' to list available events",
+		parse_libpfm_events_option),
+#endif
 	OPT_END()
 };
 
@@ -1871,6 +1880,18 @@ int cmd_stat(int argc, const char **argv)
 	unsigned int interval, timeout;
 	const char * const stat_subcommands[] = { "record", "report" };
 
+#ifdef HAVE_LIBPFM
+	{
+		int ret;
+		ret = pfm_initialize();
+		if (ret != PFM_SUCCESS) {
+			fprintf(stderr,
+				"warning libpfm failed to initialize: %s\n",
+				pfm_strerror(ret));
+		}
+	}
+#endif
+
 	setlocale(LC_ALL, "");
 
 	evsel_list = evlist__new();
tools/perf/builtin-top.c +20 -0
index 289cf83e658a..5ac9f189c0ab 100644
@@ -84,6 +84,10 @@
 #include <linux/ctype.h>
 #include <perf/mmap.h>
 
+#ifdef HAVE_LIBPFM
+#include <perfmon/pfmlib.h>
+#endif
+
 static volatile int done;
 static volatile int resize;
 
@@ -1571,6 +1575,11 @@ int cmd_top(int argc, const char **argv)
 		    "Sort the output by the event at the index n in group. "
 		    "If n is invalid, sort by the first event. "
 		    "WARNING: should be used on grouped events."),
+#ifdef HAVE_LIBPFM
+	OPT_CALLBACK(0, "pfm-events", &top.evlist, "event",
+		"libpfm4 event selector. use 'perf list' to list available events",
+		parse_libpfm_events_option),
+#endif
 	OPTS_EVSWITCH(&top.evswitch),
 	OPT_END()
 	};
@@ -1584,6 +1593,17 @@ int cmd_top(int argc, const char **argv)
 	if (status < 0)
 		return status;
 
+#ifdef HAVE_LIBPFM
+	{
+		int ret;
+		ret = pfm_initialize();
+		if (ret != PFM_SUCCESS) {
+			ui__warning("warning libpfm failed to initialize: %s\n",
+				pfm_strerror(ret));
+		}
+	}
+#endif
+
 	top.annotation_opts.min_pcnt = 5;
 	top.annotation_opts.context  = 4;
 
tools/perf/util/evsel.c +6 -0
index d23db6755f51..83ad76d3d2be 100644
@@ -2447,9 +2447,15 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
 		const char *sep = ":";
 
 		/* Is there already the separator in the name. */
+#ifndef HAVE_LIBPFM
 		if (strchr(name, '/') ||
 		    strchr(name, ':'))
 			sep = "";
+#else
+		if (strchr(name, '/') ||
+		    (strchr(name, ':') && !evsel->is_libpfm_event))
+			sep = "";
+#endif
 
 		if (asprintf(&new_name, "%s%su", name, sep) < 0)
 			return false;
tools/perf/util/evsel.h +3 -0
index 53187c501ee8..397d335d5e24 100644
@@ -76,6 +76,9 @@ struct evsel {
 	bool			ignore_missing_thread;
 	bool			forced_leader;
 	bool			use_uncore_alias;
+#ifdef HAVE_LIBPFM
+	bool			is_libpfm_event;
+#endif
 	/* parse modifier helper */
 	int			exclude_GH;
 	int			sample_read;
tools/perf/util/parse-events.c +247 -0

262 lines not on this page · raw message

tools/perf/util/parse-events.h +5 -0
index 27596cbd0ba0..84d4799c9a31 100644
@@ -37,6 +37,11 @@ int parse_events_terms(struct list_head *terms, const char *str);
 int parse_filter(const struct option *opt, const char *str, int unset);
 int exclude_perf(const struct option *opt, const char *arg, int unset);
 
+#ifdef HAVE_LIBPFM
+extern int parse_libpfm_events_option(const struct option *opt, const char *str,
+				int unset);
+#endif
+
 #define EVENTS_HELP_MAX (128*1024)
 
 enum perf_pmu_event_symbol_type {
tools/perf/util/pmu.c +11 -0
index ef6a63f3d386..5e918ca740c6 100644
@@ -869,6 +869,17 @@ static struct perf_pmu *pmu_find(const char *name)
 	return NULL;
 }
 
+struct perf_pmu *perf_pmu__find_by_type(unsigned int type)
+{
+	struct perf_pmu *pmu;
+
+	list_for_each_entry(pmu, &pmus, list)
+		if (pmu->type == type)
+			return pmu;
+
+	return NULL;
+}
+
 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu)
 {
 	/*
tools/perf/util/pmu.h +1 -0
index 5fb3f16828df..de3b868d912c 100644
@@ -65,6 +65,7 @@ struct perf_pmu_alias {
 };
 
 struct perf_pmu *perf_pmu__find(const char *name);
+struct perf_pmu *perf_pmu__find_by_type(unsigned int type);
 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
 		     struct list_head *head_terms,
 		     struct parse_events_error *error);
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#1 lore raw
Quoted 22 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

This patch links perf with the libpfm4 library if it is available and NO_LIBPFM4 isn't passed to the build. The libpfm4 library contains hardware event tables for all processors supported by perf_events. It is a helper library that helps convert from a symbolic event name to the event encoding required by the underlying kernel interface. This library is open-source and available from: http://perfmon2.sf.net.

With this patch, it is possible to specify full hardware events by name. Hardware filters are also supported. Events must be specified via the --pfm-events and not -e option. Both options are active at the same time and it is possible to mix and match:

$ perf stat --pfm-events inst_retired:any_p:c=1:i -e cycles ....

v7 rebases and adds fallback code for libpfm4 events.
The fallback code is to force user only priv level in case the perf_event_open() syscall failed for permissions reason.
the fallback forces a user privilege level restriction on the event string, so depending on the syntax either u or :u is needed.

Quoted 4 lines

But libpfm4 can use a : or . as the separator, so simply searching for ':' vs. '/' is not good enough to determine the syntax needed. Therefore, this patch introduces a new evsel boolean field to mark events coming from libpfm4. The field is then used to adjust the fallback string.

heya,
I made bunch of comments for v5, not sure you saw them:
https://lore.kernel.org/lkml/[email protected]/

jirka

Quoted 10 lines

v6 is a rebase.
v5 is a rebase.
v4 is a rebase on git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
branch perf/core and re-adds the tools/build/feature/test-libpfm4.c missed in v3.
v3 is against acme/perf/core and removes a diagnostic warning.
v2 of this patch makes the --pfm-events man page documentation conditional on libpfm4 behing configured. It tidies some of the documentation and adds the feature test missed in the v1 patch.

SNIP

author reviewer
#2 lore raw
Quoted 29 lines · Jiri Olsa
Quoted 22 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

This patch links perf with the libpfm4 library if it is available and NO_LIBPFM4 isn't passed to the build. The libpfm4 library contains hardware event tables for all processors supported by perf_events. It is a helper library that helps convert from a symbolic event name to the event encoding required by the underlying kernel interface. This library is open-source and available from: http://perfmon2.sf.net.

With this patch, it is possible to specify full hardware events by name. Hardware filters are also supported. Events must be specified via the --pfm-events and not -e option. Both options are active at the same time and it is possible to mix and match:

$ perf stat --pfm-events inst_retired:any_p:c=1:i -e cycles ....

v7 rebases and adds fallback code for libpfm4 events.
The fallback code is to force user only priv level in case the perf_event_open() syscall failed for permissions reason.
the fallback forces a user privilege level restriction on the event string, so depending on the syntax either u or :u is needed.

Quoted 4 lines

But libpfm4 can use a : or . as the separator, so simply searching for ':' vs. '/' is not good enough to determine the syntax needed. Therefore, this patch introduces a new evsel boolean field to mark events coming from libpfm4. The field is then used to adjust the fallback string.

Quoted 5 lines

heya,
I made bunch of comments for v5, not sure you saw them:
https://lore.kernel.org/lkml/[email protected]/

jirka

Sorry for missing this, I will work on fixing these and thanks!

Ian

Quoted 13 lines
Quoted 10 lines

v6 is a rebase.
v5 is a rebase.
v4 is a rebase on git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
branch perf/core and re-adds the tools/build/feature/test-libpfm4.c missed in v3.
v3 is against acme/perf/core and removes a diagnostic warning.
v2 of this patch makes the --pfm-events man page documentation conditional on libpfm4 behing configured. It tidies some of the documentation and adds the feature test missed in the v1 patch.

SNIP

author reviewer
#3 lore raw
Quoted 35 lines · Ian Rogers
Quoted 33 lines · Jiri Olsa
Quoted 22 lines · Ian Rogers

From: Stephane Eranian <[email protected]>

This patch links perf with the libpfm4 library if it is available and NO_LIBPFM4 isn't passed to the build. The libpfm4 library contains hardware event tables for all processors supported by perf_events. It is a helper library that helps convert from a symbolic event name to the event encoding required by the underlying kernel interface. This library is open-source and available from: http://perfmon2.sf.net.

With this patch, it is possible to specify full hardware events by name. Hardware filters are also supported. Events must be specified via the --pfm-events and not -e option. Both options are active at the same time and it is possible to mix and match:

$ perf stat --pfm-events inst_retired:any_p:c=1:i -e cycles ....

v7 rebases and adds fallback code for libpfm4 events.
The fallback code is to force user only priv level in case the perf_event_open() syscall failed for permissions reason.
the fallback forces a user privilege level restriction on the event string, so depending on the syntax either u or :u is needed.

Quoted 4 lines

But libpfm4 can use a : or . as the separator, so simply searching for ':' vs. '/' is not good enough to determine the syntax needed. Therefore, this patch introduces a new evsel boolean field to mark events coming from libpfm4. The field is then used to adjust the fallback string.

heya,
I made bunch of comments for v5, not sure you saw them:
https://lore.kernel.org/lkml/[email protected]/

Quoted 5 lines
Quoted 1 line

jirka

Sorry for missing this, I will work on fixing these and thanks!

Ian

v8 is available now:
https://lore.kernel.org/lkml/[email protected]/T/#t

Thanks,
Ian

Quoted 13 lines
Quoted 13 lines
Quoted 10 lines

v6 is a rebase.
v5 is a rebase.
v4 is a rebase on git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
branch perf/core and re-adds the tools/build/feature/test-libpfm4.c missed in v3.
v3 is against acme/perf/core and removes a diagnostic warning.
v2 of this patch makes the --pfm-events man page documentation conditional on libpfm4 behing configured. It tidies some of the documentation and adds the feature test missed in the v1 patch.

SNIP