From 47fef4731e0f0f77b35a09e091b11c56669feb1b Mon Sep 17 00:00:00 2001 From: Tvrtko Ursulin Date: Wed, 13 Sep 2017 18:08:02 +0100 Subject: intel-gpu-overlay: Consolidate perf PMU access to library Various tool modules implement their owm PMU open wrapper which can be replaced by calling the library one. v2: * Remove extra newline. (Chris Wilson) * Commit msg. Signed-off-by: Tvrtko Ursulin Reviewed-by: Chris Wilson --- lib/igt_perf.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/igt_perf.c') diff --git a/lib/igt_perf.c b/lib/igt_perf.c index 45cccff0..961a858a 100644 --- a/lib/igt_perf.c +++ b/lib/igt_perf.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "igt_perf.h" @@ -24,3 +26,33 @@ uint64_t i915_type_id(void) return strtoull(buf, 0, 0); } +static int _perf_open(int config, int group, int format) +{ + struct perf_event_attr attr; + + memset(&attr, 0, sizeof (attr)); + + attr.type = i915_type_id(); + if (attr.type == 0) + return -ENOENT; + + attr.config = config; + + if (group >= 0) + format &= ~PERF_FORMAT_GROUP; + + attr.read_format = format; + + return perf_event_open(&attr, -1, 0, group, 0); +} + +int perf_i915_open(int config) +{ + return _perf_open(config, -1, PERF_FORMAT_TOTAL_TIME_ENABLED); +} + +int perf_i915_open_group(int config, int group) +{ + return _perf_open(config, group, + PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); +} -- cgit v1.2.3