From: "Adrián Larumbe" <adrian.larumbe@collabora.com>
To: tursulin@ursulin.net, daniel@ffwll.ch,
boris.brezillon@collabora.com, kamil.konieczny@linux.intel.com,
zbigniew.kempczynski@intel.com, igt-dev@lists.freedesktop.org,
healych@amazon.com
Cc: adrian.larumbe@collabora.com, kernel@collabora.com
Subject: [PATCH v2 1/2] lib: Add DRM driver sysfs profiling knob toggling functions
Date: Tue, 2 Apr 2024 23:27:44 +0100 [thread overview]
Message-ID: <20240402222813.277470-2-adrian.larumbe@collabora.com> (raw)
In-Reply-To: <20240402222813.277470-1-adrian.larumbe@collabora.com>
Some DRM drivers need to have their accounting HW toggled on demand from
user space so that fdinfo's drm-engine and drm-cycles tags can be updated
upon job completion.
A profiler such as gputop should be able to check which DRM devices have
such a sysfs knob, record its original state, toggle-enable it and revert
this operation right before exiting.
A new igt library igt_profiling.c file was added because using igt lib's
sysfs access functions would've triggered a cascade of linking dependencies
in intel_gpu_top, which only statically links a very small subset of the
igt library.
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
lib/igt_device_scan.c | 45 +++++++++++++++++++++++++++++++++++++++++++
lib/igt_device_scan.h | 7 +++++++
lib/igt_profiling.c | 28 +++++++++++++++++++++++++++
lib/igt_profiling.h | 17 ++++++++++++++++
lib/meson.build | 1 +
5 files changed, 98 insertions(+)
create mode 100644 lib/igt_profiling.c
create mode 100644 lib/igt_profiling.h
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index fbf3fa482e21..e5b126cc5448 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -1105,6 +1105,51 @@ void igt_devices_scan(bool force)
igt_devs.devs_scanned = true;
}
+struct igt_profiled_device *igt_devices_profiled(void)
+{
+ struct igt_profiled_device *profiled_devices;
+ struct igt_device *dev;
+ unsigned int devlist_len;
+ unsigned int i = 0;
+
+ if (!igt_devs.devs_scanned)
+ return NULL;
+
+ devlist_len = igt_list_length(&igt_devs.all);
+ if (devlist_len == 0)
+ return NULL;
+
+ profiled_devices = malloc(devlist_len * sizeof(struct igt_profiled_device));
+ if (!profiled_devices)
+ return NULL;
+
+ memset(profiled_devices, 0, devlist_len * sizeof(struct igt_profiled_device));
+
+ igt_list_for_each_entry(dev, &igt_devs.all, link) {
+ char path[PATH_MAX];
+ int sysfs_fd;
+
+ if (!get_attr(dev, "profiling"))
+ continue;
+
+ snprintf(path, sizeof(path), "%s/%s", dev->syspath, "profiling");
+ sysfs_fd = open(path, O_RDONLY);
+ if (sysfs_fd < 0)
+ continue;
+
+ profiled_devices[i].syspath = dev->syspath;
+ profiled_devices[i++].original_state =
+ strtoul(get_attr(dev, "profiling"), NULL, 10);
+ }
+
+ if (i == 0) {
+ free(profiled_devices);
+ profiled_devices = NULL;
+ }
+
+ return profiled_devices;
+}
+
static inline void _pr_simple(const char *k, const char *v)
{
printf(" %-16s: %s\n", k, v);
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index 48690e236c01..6c725d9081b2 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -63,8 +63,15 @@ struct igt_device_card {
uint16_t pci_vendor, pci_device;
};
+struct igt_profiled_device {
+ char *syspath;
+ bool original_state;
+};
+
void igt_devices_scan(bool force);
+struct igt_profiled_device *igt_devices_profiled(void);
+
void igt_devices_print(const struct igt_devices_print_format *fmt);
void igt_devices_print_vendors(void);
void igt_device_print_filter_types(void);
diff --git a/lib/igt_profiling.c b/lib/igt_profiling.c
new file mode 100644
index 000000000000..9ba114b4d78d
--- /dev/null
+++ b/lib/igt_profiling.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2024 Collabora Ltd.
+ * Copyright © 2024 Adrian Larumbe <adrian.larumbe@collabora.com>
+ * Copyright © 2024 Amazon.com, Inc. or its affiliates.
+ *
+ */
+
+#include <fcntl.h>
+
+#include "igt_device_scan.h"
+#include "igt_profiling.h"
+#include "igt_sysfs.h"
+
+void igt_devices_toggle_profiling(struct igt_profiled_device *devices, bool enable)
+{
+ for (unsigned int i = 0; devices[i].syspath; i++) {
+ int sysfs_fd = open(devices[i].syspath, O_RDONLY);
+
+ if (sysfs_fd < 0)
+ continue;
+
+ igt_sysfs_set_boolean(sysfs_fd, "profiling",
+ enable ? true : devices[i].original_state);
+
+ close(sysfs_fd);
+ }
+}
diff --git a/lib/igt_profiling.h b/lib/igt_profiling.h
new file mode 100644
index 000000000000..af0b9366b797
--- /dev/null
+++ b/lib/igt_profiling.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2024 Collabora Ltd.
+ * Copyright © 2024 Adrian Larumbe <adrian.larumbe@collabora.com>
+ * Copyright © 2024 Amazon.com, Inc. or its affiliates.
+ */
+
+#ifndef IGT_PROFILING_H
+#define IGT_PROFILING_H
+
+#include <stdbool.h>
+
+struct igt_profiled_device;
+
+void igt_devices_toggle_profiling(struct igt_profiled_device *devices, bool enable);
+
+#endif /* IGT_PROFILING_H */
diff --git a/lib/meson.build b/lib/meson.build
index 6122861d8b7a..0fcc5f1cf5a1 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -36,6 +36,7 @@ lib_sources = [
'igt_pipe_crc.c',
'igt_power.c',
'igt_primes.c',
+ 'igt_profiling.c',
'igt_pci.c',
'igt_rand.c',
'igt_sriov_device.c',
--
2.44.0
next prev parent reply other threads:[~2024-04-02 22:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 22:27 [PATCH v2 0/2] Add gputop support for sysfs profiling knob Adrián Larumbe
2024-04-02 22:27 ` Adrián Larumbe [this message]
2024-04-02 22:27 ` [PATCH v2 2/2] tools/gputop: toggle sysfs profiling knob if available for device Adrián Larumbe
2024-04-03 17:22 ` Kamil Konieczny
2024-04-15 19:35 ` Adrián Larumbe
2024-04-16 7:49 ` Tvrtko Ursulin
2024-04-16 14:02 ` Lucas De Marchi
2024-04-03 20:46 ` Lucas De Marchi
2024-04-15 19:31 ` Adrián Larumbe
2024-04-16 8:07 ` Tvrtko Ursulin
2024-04-03 0:24 ` ✓ Fi.CI.BAT: success for Add gputop support for sysfs profiling knob Patchwork
2024-04-03 0:42 ` ✓ CI.xeBAT: " Patchwork
2024-04-03 9:11 ` ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240402222813.277470-2-adrian.larumbe@collabora.com \
--to=adrian.larumbe@collabora.com \
--cc=boris.brezillon@collabora.com \
--cc=daniel@ffwll.ch \
--cc=healych@amazon.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=kernel@collabora.com \
--cc=tursulin@ursulin.net \
--cc=zbigniew.kempczynski@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox