[igt-dev] [PATCH i-g-t 17/29] lib/igt_perf: add null implementation

D Scott Phillips d.scott.phillips at intel.com
Wed Dec 11 00:52:23 UTC 2019


perf is only availble on Linux. Add a do-nothing implementation of
the same API for inclusion on other platforms.

Signed-off-by: D Scott Phillips <d.scott.phillips at intel.com>
---
 lib/igt_perf.h      | 23 +++++++++++++++++++++++
 lib/igt_perf_null.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/meson.build     | 12 ++++++++++--
 3 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 lib/igt_perf_null.c

diff --git a/lib/igt_perf.h b/lib/igt_perf.h
index e00718f4..1e27b3cf 100644
--- a/lib/igt_perf.h
+++ b/lib/igt_perf.h
@@ -27,10 +27,13 @@
 
 #include <stdint.h>
 
+#if defined(__linux__)
 #include <linux/perf_event.h>
+#endif
 
 #include "igt_gt.h"
 
+#if defined(__linux__)
 static inline int
 perf_event_open(struct perf_event_attr *attr,
 		pid_t pid,
@@ -50,6 +53,26 @@ perf_event_open(struct perf_event_attr *attr,
     attr->size = sizeof(*attr);
     return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
 }
+#else
+#include <errno.h>
+
+struct perf_event_attr {
+	uint64_t config;
+	uint64_t type;
+	uint64_t sample_period;
+};
+
+static inline int
+perf_event_open(struct perf_event_attr *attr,
+		pid_t pid,
+		int cpu,
+		int group_fd,
+		unsigned long flags)
+{
+   errno = ENXIO;
+   return -1;
+}
+#endif
 
 uint64_t i915_type_id(void);
 int perf_i915_open(uint64_t config);
diff --git a/lib/igt_perf_null.c b/lib/igt_perf_null.c
new file mode 100644
index 00000000..6fef33c9
--- /dev/null
+++ b/lib/igt_perf_null.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "igt_perf.h"
+
+uint64_t i915_type_id(void) {
+	return 0;
+}
+
+int perf_i915_open(uint64_t config) {
+	return 0;
+}
+
+int perf_i915_open_group(uint64_t config, int group) {
+	return 0;
+}
+
+int igt_perf_open(uint64_t type, uint64_t config) {
+	return 0;
+}
+
+int igt_perf_open_group(uint64_t type, uint64_t config, int group) {
+	return 0;
+}
diff --git a/lib/meson.build b/lib/meson.build
index 4a58d9cf..2cb944e2 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -14,7 +14,6 @@ lib_sources = [
 	'igt_gt.c',
 	'igt_halffloat.c',
 	'igt_matrix.c',
-	'igt_perf.c',
 	'igt_primes.c',
 	'igt_rand.c',
 	'igt_rapl.c',
@@ -69,11 +68,13 @@ if host_machine.system() == 'linux'
 	lib_sources += [
 		'igt_aux.c',
 		'igt_kmod.c',
+		'igt_perf.c',
 	]
 else
 	lib_sources += [
 		'igt_aux_null.c',
 		'igt_kmod_null.c',
+		'igt_perf_null.c',
 	]
 endif
 
@@ -170,8 +171,15 @@ lin_igt_chipset_build = static_library('igt_chipset',
 lib_igt_chipset = declare_dependency(link_with : lin_igt_chipset_build,
                                      include_directories : inc)
 
+
+if host_machine.system() == 'linux'
+	igt_perf_sources = ['igt_perf.c']
+else
+	igt_perf_sources = ['igt_perf_null.c']
+endif
+
 lib_igt_perf_build = static_library('igt_perf',
-	['igt_perf.c'],
+	igt_perf_sources,
 	include_directories : inc)
 
 lib_igt_perf = declare_dependency(link_with : lib_igt_perf_build,
-- 
2.23.0



More information about the igt-dev mailing list