[Intel-gfx] [PATCH i-g-t 3/8] lib/igt_drm_clients: Record client drm minor
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Mon Apr 17 10:57:29 UTC 2023
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Prepare for supporting clients belonging to multiple DRM cards by storing
the DRM minor in the client record.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
lib/igt_drm_clients.c | 22 ++++++++++++++--------
lib/igt_drm_clients.h | 1 +
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/lib/igt_drm_clients.c b/lib/igt_drm_clients.c
index d06fcb0942a1..b837450301dc 100644
--- a/lib/igt_drm_clients.c
+++ b/lib/igt_drm_clients.c
@@ -124,7 +124,7 @@ igt_drm_client_update(struct igt_drm_client *c, unsigned int pid, char *name,
static void
igt_drm_client_add(struct igt_drm_clients *clients,
const struct drm_client_fdinfo *info,
- unsigned int pid, char *name)
+ unsigned int pid, char *name, unsigned int drm_minor)
{
struct igt_drm_client *c;
@@ -149,6 +149,7 @@ igt_drm_client_add(struct igt_drm_clients *clients,
}
c->id = info->id;
+ c->drm_minor = drm_minor;
c->clients = clients;
c->val = calloc(clients->num_classes, sizeof(c->val));
c->last = calloc(clients->num_classes, sizeof(c->last));
@@ -295,16 +296,21 @@ static bool get_task_name(const char *buffer, char *out, unsigned long sz)
return true;
}
-static bool is_drm_fd(int fd_dir, const char *name)
+static bool is_drm_fd(int fd_dir, const char *name, unsigned int *minor)
{
struct stat stat;
int ret;
ret = fstatat(fd_dir, name, &stat, 0);
- return ret == 0 &&
- (stat.st_mode & S_IFMT) == S_IFCHR &&
- major(stat.st_rdev) == 226;
+ if (ret == 0 &&
+ (stat.st_mode & S_IFMT) == S_IFCHR &&
+ major(stat.st_rdev) == 226) {
+ *minor = minor(stat.st_rdev);
+ return true;
+ }
+
+ return false;
}
static void clients_update_max_lengths(struct igt_drm_clients *clients)
@@ -382,10 +388,10 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,
return clients;
while ((proc_dent = readdir(proc_dir)) != NULL) {
+ unsigned int client_pid, minor = 0;
int pid_dir = -1, fd_dir = -1;
struct dirent *fdinfo_dent;
char client_name[64] = { };
- unsigned int client_pid;
DIR *fdinfo_dir = NULL;
char buf[4096];
size_t count;
@@ -427,7 +433,7 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,
if (!isdigit(fdinfo_dent->d_name[0]))
continue;
- if (!is_drm_fd(fd_dir, fdinfo_dent->d_name))
+ if (!is_drm_fd(fd_dir, fdinfo_dent->d_name, &minor))
continue;
if (!__igt_parse_drm_fdinfo(dirfd(fdinfo_dir),
@@ -446,7 +452,7 @@ igt_drm_clients_scan(struct igt_drm_clients *clients,
info.id);
if (!c)
igt_drm_client_add(clients, &info, client_pid,
- client_name);
+ client_name, minor);
else
igt_drm_client_update(c, client_pid,
client_name, &info);
diff --git a/lib/igt_drm_clients.h b/lib/igt_drm_clients.h
index 431bf5bbd335..591725b8c059 100644
--- a/lib/igt_drm_clients.h
+++ b/lib/igt_drm_clients.h
@@ -44,6 +44,7 @@ struct igt_drm_client {
enum igt_drm_client_status status;
unsigned int id; /* DRM client id from fdinfo. */
+ unsigned int drm_minor; /* DRM minor of this client. */
unsigned int pid; /* PID which has this DRM fd open. */
char pid_str[10]; /* Cached PID representation. */
char name[24]; /* Process name of the owning PID. */
--
2.37.2
More information about the Intel-gfx
mailing list