diff options
author | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2017-09-13 18:08:02 +0100 |
---|---|---|
committer | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2017-11-22 11:18:14 +0000 |
commit | 47fef4731e0f0f77b35a09e091b11c56669feb1b (patch) | |
tree | 594f5ec62f7d65ac603073ee777c58c1260466ba /lib/igt_perf.c | |
parent | a688deceae195aec863d8de45bdaefb251927c89 (diff) |
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 <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_perf.c')
-rw-r--r-- | lib/igt_perf.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 <fcntl.h> #include <unistd.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #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); +} |