From patchwork Fri Nov 11 15:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13040580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36E8FC43217 for ; Fri, 11 Nov 2022 15:59:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4AA7D10E899; Fri, 11 Nov 2022 15:59:20 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1FF7C10E871; Fri, 11 Nov 2022 15:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668182349; x=1699718349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gJQpVSG9dZVHayAdIbR7SbqppXSv9xRlV3BEeeUUNgo=; b=oIy8VTTLD8Mvi0kFQRJ2Jk5pm3aZ7bqoh+yWatAWf13v5hTuAF3f6q2w hIE4/aDs1mHW303ruOJ7VIPcDkTdiGqdCnkC0++fZbfKYQ0neCy2GPeER /sHJzyo/qoLFU1/aU9p/5c4p8wikOY4j+OEnZ6wZkKudcQyUGO9zA6AIZ DPhF2K181zYFclbKkrdpdpi9EMoTtqIa9C9RFACXR+Sy6hBdULkdr2uzN Moy5peIgtRd+ACEFCz5prl2IYoUefu6O6W+yIHlEuEL29gV7Csvqccbcg h1amw1rvYJZDl3YfFXbrJc9w4c5Dtf0D7Csw4S2NWxoHq3Y1BSYGaZx5G g==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="375883646" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="375883646" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 07:59:08 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="706577563" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="706577563" Received: from eharkin-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.208.27]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 07:59:07 -0800 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH i-g-t 3/8] libdrmclients: Record client drm minor Date: Fri, 11 Nov 2022 15:58:39 +0000 Message-Id: <20221111155844.3290531-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221111155844.3290531-1-tvrtko.ursulin@linux.intel.com> References: <20221111155844.3290531-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin Prepare for supporting clients belonging to multiple DRM cards by storing the DRM minor in the client record. Signed-off-by: Tvrtko Ursulin --- 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 eabd43773f2d..c23a3fae9793 100644 --- a/lib/igt_drm_clients.c +++ b/lib/igt_drm_clients.c @@ -115,7 +115,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; @@ -140,6 +140,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)); @@ -286,16 +287,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; } /** @@ -348,10 +354,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; @@ -393,7 +399,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), @@ -412,7 +418,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 bced19adb055..ffa219c9c9fd 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 name[24]; /* Process name of the owning PID. */ char print_name[24]; /* Name without any non-printable characters. */