[PATCH 5/8] perf tools: Get precise_ip from the pmu config

From: Jiri Olsa
Date: Tue Mar 05 2019 - 10:25:56 EST


Getting precise_ip field from the perf_pmu::max_precise
config read from sysfs. If it's not available falling
back to current detection function.

This fixes perf c2c usage of 'P' modifier on memory events,
where the standard detection fails, because of way too many
new perf_event_attr features added recently.

Use PYTHON_MOD to distinguish python perf module build
to exclude pmu.o object call being compiled in. There's
the flex/bison (and other) object dependencies, that
we'd need to teach setup.py about.

Link: http://lkml.kernel.org/n/tip-zyegnaq8xlkhh4sgfl4tnvui@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/evsel.c | 28 +++++++++++++++++++++++++++-
tools/perf/util/setup.py | 2 +-
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index dfe2958e6287..eec542bab815 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -870,6 +870,32 @@ static bool is_dummy_event(struct perf_evsel *evsel)
(evsel->attr.config == PERF_COUNT_SW_DUMMY);
}

+#ifndef PYTHON_MOD
+static int pmu_get_precise(const char *pmu_name)
+{
+ struct perf_pmu *pmu = pmu_name ? perf_pmu__find(pmu_name) : NULL;
+
+ /* If unsupported pmu->max_precise is -1. */
+ return pmu ? pmu->max_precise : -1;
+}
+#else
+static int pmu_get_precise(const char *pmu_name __maybe_unused)
+{
+ return 0;
+}
+#endif
+
+static void perf_evsel__set_max_precise_ip(struct perf_evsel *evsel)
+{
+ int max_precise = pmu_get_precise(evsel->pmu_name);
+ struct perf_event_attr *attr = &evsel->attr;
+
+ if (max_precise >= 0)
+ attr->precise_ip = max_precise;
+ else
+ perf_event_attr__set_max_precise_ip(attr);
+}
+
/*
* The enable_on_exec/disabled value strategy:
*
@@ -1091,7 +1117,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
}

if (evsel->precise_max)
- perf_event_attr__set_max_precise_ip(attr);
+ perf_evsel__set_max_precise_ip(evsel);

if (opts->all_user) {
attr->exclude_kernel = 1;
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 5b5a167b43ce..9eee3467ac5d 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -37,7 +37,7 @@ class install_lib(_install_lib):

cflags = getenv('CFLAGS', '').split()
# switch off several checks (need to be at the end of cflags list)
-cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
+cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls', '-DPYTHON_MOD' ]
if cc != "clang":
cflags += ['-Wno-cast-function-type' ]

--
2.17.2