From a688deceae195aec863d8de45bdaefb251927c89 Mon Sep 17 00:00:00 2001 From: Tvrtko Ursulin Date: Wed, 13 Sep 2017 17:38:16 +0100 Subject: intel-gpu-overlay: Move local perf implementation to a library Idea is to avoid duplication across multiple users in upcoming patches. v2: Commit message and use a separate library instead of piggy- backing to libintel_tools. (Chris Wilson) v3: Add Petri's meson build recipe. Signed-off-by: Tvrtko Ursulin Cc: Petri Latvala Reviewed-by: Chris Wilson --- lib/Makefile.am | 6 +++++- lib/igt_perf.c | 26 +++++++++++++++++++++++ lib/igt_perf.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/meson.build | 4 ++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 lib/igt_perf.c create mode 100644 lib/igt_perf.h (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index 9c511dc0..c3c4a7e3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,7 +7,11 @@ include Makefile.sources libintel_tools_la_SOURCES = $(lib_source_list) -noinst_LTLIBRARIES = libintel_tools.la +libigt_perf_la_SOURCES = \ + igt_perf.c \ + igt_perf.h + +noinst_LTLIBRARIES = libintel_tools.la libigt_perf.la noinst_HEADERS = check-ndebug.h if BUILD_VC4 diff --git a/lib/igt_perf.c b/lib/igt_perf.c new file mode 100644 index 00000000..45cccff0 --- /dev/null +++ b/lib/igt_perf.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "igt_perf.h" + +uint64_t i915_type_id(void) +{ + char buf[1024]; + int fd, n; + + fd = open("/sys/bus/event_source/devices/i915/type", 0); + if (fd < 0) { + n = -1; + } else { + n = read(fd, buf, sizeof(buf)-1); + close(fd); + } + if (n < 0) + return 0; + + buf[n] = '\0'; + return strtoull(buf, 0, 0); +} + diff --git a/lib/igt_perf.h b/lib/igt_perf.h new file mode 100644 index 00000000..a80b311c --- /dev/null +++ b/lib/igt_perf.h @@ -0,0 +1,66 @@ +#ifndef I915_PERF_H +#define I915_PERF_H + +#include + +#include + +#define I915_SAMPLE_BUSY 0 +#define I915_SAMPLE_WAIT 1 +#define I915_SAMPLE_SEMA 2 + +#define I915_SAMPLE_RCS 0 +#define I915_SAMPLE_VCS 1 +#define I915_SAMPLE_BCS 2 +#define I915_SAMPLE_VECS 3 + +#define __I915_PERF_COUNT(ring, id) ((ring) << 4 | (id)) + +#define I915_PERF_COUNT_RCS_BUSY __I915_PERF_COUNT(I915_SAMPLE_RCS, I915_SAMPLE_BUSY) +#define I915_PERF_COUNT_RCS_WAIT __I915_PERF_COUNT(I915_SAMPLE_RCS, I915_SAMPLE_WAIT) +#define I915_PERF_COUNT_RCS_SEMA __I915_PERF_COUNT(I915_SAMPLE_RCS, I915_SAMPLE_SEMA) + +#define I915_PERF_COUNT_VCS_BUSY __I915_PERF_COUNT(I915_SAMPLE_VCS, I915_SAMPLE_BUSY) +#define I915_PERF_COUNT_VCS_WAIT __I915_PERF_COUNT(I915_SAMPLE_VCS, I915_SAMPLE_WAIT) +#define I915_PERF_COUNT_VCS_SEMA __I915_PERF_COUNT(I915_SAMPLE_VCS, I915_SAMPLE_SEMA) + +#define I915_PERF_COUNT_BCS_BUSY __I915_PERF_COUNT(I915_SAMPLE_BCS, I915_SAMPLE_BUSY) +#define I915_PERF_COUNT_BCS_WAIT __I915_PERF_COUNT(I915_SAMPLE_BCS, I915_SAMPLE_WAIT) +#define I915_PERF_COUNT_BCS_SEMA __I915_PERF_COUNT(I915_SAMPLE_BCS, I915_SAMPLE_SEMA) + +#define I915_PERF_COUNT_VECS_BUSY __I915_PERF_COUNT(I915_SAMPLE_VECS, I915_SAMPLE_BUSY) +#define I915_PERF_COUNT_VECS_WAIT __I915_PERF_COUNT(I915_SAMPLE_VECS, I915_SAMPLE_WAIT) +#define I915_PERF_COUNT_VECS_SEMA __I915_PERF_COUNT(I915_SAMPLE_VECS, I915_SAMPLE_SEMA) + +#define I915_PERF_ACTUAL_FREQUENCY 32 +#define I915_PERF_REQUESTED_FREQUENCY 33 +#define I915_PERF_ENERGY 34 +#define I915_PERF_INTERRUPTS 35 + +#define I915_PERF_RC6_RESIDENCY 40 +#define I915_PERF_RC6p_RESIDENCY 41 +#define I915_PERF_RC6pp_RESIDENCY 42 + +static inline int +perf_event_open(struct perf_event_attr *attr, + pid_t pid, + int cpu, + int group_fd, + unsigned long flags) +{ +#ifndef __NR_perf_event_open +#if defined(__i386__) +#define __NR_perf_event_open 336 +#elif defined(__x86_64__) +#define __NR_perf_event_open 298 +#else +#define __NR_perf_event_open 0 +#endif +#endif + attr->size = sizeof(*attr); + return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +} + +uint64_t i915_type_id(void); + +#endif /* I915_PERF_H */ diff --git a/lib/meson.build b/lib/meson.build index 253548dc..1b55943b 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -179,4 +179,8 @@ lib_igt = declare_dependency(link_with : lib_igt_build, igt_deps = [ lib_igt ] + lib_deps +lib_igt_perf = static_library('igt_perf', + ['igt_perf.c'] +) + subdir('tests') -- cgit v1.2.3