From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH i-g-t 05/11] libdrmfdinfo: Allow specifying custom engine map
Date: Tue, 22 Feb 2022 13:55:59 +0000 [thread overview]
Message-ID: <20220222135605.1120767-6-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20220222135605.1120767-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Instead of hard coding the engine names, allow a map of names to indices
to either be passed in or it gets auto-detected (less efficient) while
parsing.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_drm_clients.c | 7 +++---
lib/igt_drm_clients.h | 3 ++-
lib/igt_drm_fdinfo.c | 47 +++++++++++++++++++++++++++--------------
lib/igt_drm_fdinfo.h | 7 ++++--
tests/i915/drm_fdinfo.c | 16 +++++++++++---
tools/intel_gpu_top.c | 13 ++++++++++--
6 files changed, 66 insertions(+), 27 deletions(-)
diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c
index 58d82648d821..591602f4c9f5 100644
--- a/lib/igt_drm_clients.c
+++ b/lib/igt_drm_clients.c
@@ -269,7 +269,8 @@ static bool is_drm_fd(int fd_dir, const char *name)
struct igt_drm_clients *
igt_drm_clients_scan(struct igt_drm_clients *clients,
bool (*filter_client)(const struct igt_drm_clients *,
- const struct drm_client_fdinfo *))
+ const struct drm_client_fdinfo *),
+ const char **name_map, unsigned int map_entries)
{
struct dirent *proc_dent;
struct igt_drm_client *c;
@@ -343,8 +344,8 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,
memset(&info, 0, sizeof(info));
if (!__igt_parse_drm_fdinfo(dirfd(fdinfo_dir),
- fdinfo_dent->d_name,
- &info))
+ fdinfo_dent->d_name, &info,
+ name_map, map_entries))
continue;
if (filter_client && !filter_client(clients, &info))
diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h
index f52080847291..91e9da4c0733 100644
--- a/lib/igt_drm_clients.h
+++ b/lib/igt_drm_clients.h
@@ -80,7 +80,8 @@ void igt_drm_clients_free(struct igt_drm_clients *clients);
struct igt_drm_clients *
igt_drm_clients_scan(struct igt_drm_clients *clients,
bool (*filter_client)(const struct igt_drm_clients *,
- const struct drm_client_fdinfo *));
+ const struct drm_client_fdinfo *),
+ const char **name_map, unsigned int map_entries);
struct igt_drm_client *
igt_drm_clients_find(struct igt_drm_clients *clients,
diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index 28c1bdbda08e..96a8b768a4b1 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -22,6 +22,7 @@
*
*/
+#include <assert.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -52,14 +53,10 @@ static size_t read_fdinfo(char *buf, const size_t sz, int at, const char *name)
}
static int parse_engine(char *line, struct drm_client_fdinfo *info,
- size_t prefix_len, uint64_t *val)
+ size_t prefix_len,
+ const char **name_map, unsigned int map_entries,
+ uint64_t *val)
{
- static const char *e2class[] = {
- "render",
- "copy",
- "video",
- "video-enhance",
- };
ssize_t name_len;
char *name, *p;
int found = -1;
@@ -75,10 +72,26 @@ static int parse_engine(char *line, struct drm_client_fdinfo *info,
name = line + prefix_len;
- for (i = 0; i < ARRAY_SIZE(e2class); i++) {
- if (!strncmp(name, e2class[i], name_len)) {
- found = i;
- break;
+ if (name_map) {
+ for (i = 0; i < map_entries; i++) {
+ if (!strncmp(name, name_map[i], name_len)) {
+ found = i;
+ break;
+ }
+ }
+ } else {
+ for (i = 0; i < info->num_engines; i++) {
+ if (!strncmp(name, info->names[i], name_len)) {
+ found = i;
+ break;
+ }
+ }
+
+ if (found < 0) {
+ assert((info->num_engines + 1) < ARRAY_SIZE(info->names));
+ assert((strlen(name) + 1) < sizeof(info->names[0]));
+ strncpy(info->names[info->num_engines], name, name_len);
+ found = info->num_engines;
}
}
@@ -109,7 +122,8 @@ static const char *find_kv(const char *buf, const char *key, size_t keylen)
}
bool
-__igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info)
+__igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
+ const char **name_map, unsigned int map_entries)
{
char buf[4096], *_buf = buf;
char *l, *ctx = NULL;
@@ -139,7 +153,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info)
} else if (!strncmp(l, "drm-engine-", 11) &&
strncmp(l, "drm-engine-capacity-", 20)) {
idx = parse_engine(l, info, strlen("drm-engine-"),
- &val);
+ name_map, map_entries, &val);
if (idx >= 0) {
if (!info->capacity[idx])
info->capacity[idx] = 1;
@@ -149,7 +163,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info)
} else if (!strncmp(l, "drm-engine-capacity-", 20)) {
idx = parse_engine(l, info,
strlen("drm-engine-capacity-"),
- &val);
+ name_map, map_entries, &val);
if (idx >= 0)
info->capacity[idx] = val;
}
@@ -161,7 +175,8 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info)
return true;
}
-bool igt_parse_drm_fdinfo(int drm_fd, struct drm_client_fdinfo *info)
+bool igt_parse_drm_fdinfo(int drm_fd, struct drm_client_fdinfo *info,
+ const char **name_map, unsigned int map_entries)
{
char fd[64];
int dir, ret;
@@ -175,7 +190,7 @@ bool igt_parse_drm_fdinfo(int drm_fd, struct drm_client_fdinfo *info)
if (dir < 0)
return false;
- res = __igt_parse_drm_fdinfo(dir, fd, info);
+ res = __igt_parse_drm_fdinfo(dir, fd, info, name_map, map_entries);
close(dir);
diff --git a/lib/igt_drm_fdinfo.h b/lib/igt_drm_fdinfo.h
index c527bab9a204..bea4a6304734 100644
--- a/lib/igt_drm_fdinfo.h
+++ b/lib/igt_drm_fdinfo.h
@@ -37,12 +37,15 @@ struct drm_client_fdinfo {
unsigned int num_engines;
unsigned int capacity[16];
+ char names[16][256];
uint64_t busy[16];
};
-bool igt_parse_drm_fdinfo(int drm_fd, struct drm_client_fdinfo *info);
+bool igt_parse_drm_fdinfo(int drm_fd, struct drm_client_fdinfo *info,
+ const char **name_map, unsigned int map_entries);
bool __igt_parse_drm_fdinfo(int dir, const char *fd,
- struct drm_client_fdinfo *info);
+ struct drm_client_fdinfo *info,
+ const char **name_map, unsigned int map_entries);
#endif /* IGT_DRM_FDINFO_H */
diff --git a/tests/i915/drm_fdinfo.c b/tests/i915/drm_fdinfo.c
index e3b1ebb0f454..d1053a53ae2c 100644
--- a/tests/i915/drm_fdinfo.c
+++ b/tests/i915/drm_fdinfo.c
@@ -34,6 +34,13 @@ IGT_TEST_DESCRIPTION("Test the i915 drm fdinfo data");
const double tolerance = 0.05f;
const unsigned long batch_duration_ns = 500e6;
+static const char *engine_map[] = {
+ "render",
+ "copy",
+ "video",
+ "video-enhance",
+};
+
#define __assert_within_epsilon(x, ref, tol_up, tol_down) \
igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \
(double)(x) >= (1.0 - (tol_down)) * (double)(ref), \
@@ -50,7 +57,8 @@ static void basics(int i915, unsigned int num_classes)
struct drm_client_fdinfo info = { };
bool ret;
- ret = igt_parse_drm_fdinfo(i915, &info);
+ ret = igt_parse_drm_fdinfo(i915, &info, engine_map,
+ ARRAY_SIZE(engine_map));
igt_assert(ret);
igt_assert(!strcmp(info.driver, "i915"));
@@ -181,7 +189,8 @@ static uint64_t read_busy(int i915, unsigned int class)
{
struct drm_client_fdinfo info = { };
- igt_assert(igt_parse_drm_fdinfo(i915, &info));
+ igt_assert(igt_parse_drm_fdinfo(i915, &info, engine_map,
+ ARRAY_SIZE(engine_map)));
return info.busy[class];
}
@@ -267,7 +276,8 @@ static void read_busy_all(int i915, uint64_t *val)
{
struct drm_client_fdinfo info = { };
- igt_assert(igt_parse_drm_fdinfo(i915, &info));
+ igt_assert(igt_parse_drm_fdinfo(i915, &info, engine_map,
+ ARRAY_SIZE(engine_map)));
memcpy(val, info.busy, sizeof(info.busy));
}
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index c4f990b2a7d0..99e8e1d8ffd4 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -2030,6 +2030,12 @@ int main(int argc, char **argv)
{
unsigned int period_us = DEFAULT_PERIOD_MS * 1000;
struct igt_drm_clients *clients = NULL;
+ static const char *engine_map[] = {
+ "render",
+ "copy",
+ "video",
+ "video-enhance",
+ };
int con_w = -1, con_h = -1;
char *output_path = NULL;
struct engines *engines;
@@ -2177,7 +2183,8 @@ int main(int argc, char **argv)
}
pmu_sample(engines);
- igt_drm_clients_scan(clients, client_match);
+ igt_drm_clients_scan(clients, client_match, engine_map,
+ ARRAY_SIZE(engine_map));
codename = igt_device_get_pretty_name(&card, false);
while (!stop_top) {
@@ -2206,7 +2213,9 @@ int main(int argc, char **argv)
disp_clients =
display_clients(igt_drm_clients_scan(clients,
- client_match));
+ client_match,
+ engine_map,
+ ARRAY_SIZE(engine_map)));
if (stop_top)
break;
--
2.32.0
next prev parent reply other threads:[~2022-02-22 13:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 13:55 [Intel-gfx] [PATCH i-g-t 00/11] Per client GPU utilisation Tvrtko Ursulin
2022-02-22 13:55 ` [Intel-gfx] [PATCH i-g-t 01/11] lib: Helper library for parsing i915 fdinfo output Tvrtko Ursulin
2022-03-30 19:52 ` Umesh Nerlige Ramappa
2022-03-31 13:22 ` Tvrtko Ursulin
2022-02-22 13:55 ` [Intel-gfx] [PATCH i-g-t 02/11] tests/i915/drm_fdinfo: Basic and functional tests for GPU busyness exported via fdinfo Tvrtko Ursulin
2022-03-30 20:11 ` [Intel-gfx] [igt-dev] " Umesh Nerlige Ramappa
2022-03-31 13:23 ` Tvrtko Ursulin
2022-02-22 13:55 ` [Intel-gfx] [PATCH i-g-t 03/11] intel-gpu-top: Add support for per client stats Tvrtko Ursulin
2022-03-31 22:08 ` [Intel-gfx] [igt-dev] " Umesh Nerlige Ramappa
2022-04-01 14:19 ` Tvrtko Ursulin
2022-02-22 13:55 ` [Intel-gfx] [PATCH i-g-t 04/11] lib: Extract igt_drm_clients from intel_gpu_top Tvrtko Ursulin
2022-02-22 13:55 ` Tvrtko Ursulin [this message]
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 06/11] libdrmclients: Record client drm minor Tvrtko Ursulin
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 07/11] libdrmclient: Support multiple DRM cards Tvrtko Ursulin
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 08/11] libdrmfdinfo: Track largest engine index Tvrtko Ursulin
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 09/11] libdrmclient/intel_gpu_top: Decouple hardcoded engine assumptions Tvrtko Ursulin
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 10/11] libdrmclient: Enforce client status sort order in the library Tvrtko Ursulin
2022-02-22 13:56 ` [Intel-gfx] [PATCH i-g-t 11/11] gputop: Basic vendor agnostic GPU top tool Tvrtko Ursulin
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=20220222135605.1120767-6-tvrtko.ursulin@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
/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