Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [V3 i-g-t 02/23] lib: Cache xe_device at driver open/close level
Date: Thu, 22 Jun 2023 12:24:01 +0530	[thread overview]
Message-ID: <20230622065422.2235134-3-bhanuprakash.modem@intel.com> (raw)
In-Reply-To: <20230622065422.2235134-1-bhanuprakash.modem@intel.com>

Instead of caching the xe_device struct at subtest level, cache
just after opening the driver. And remove from the cache just
before closing the driver.

V2: - Place the logic in correct helpers (Zbigniew)

Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
---
 lib/drmtest.c   | 24 +++++++++++++++++++++---
 lib/igt_types.c |  6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index a226ebd91..5cdb0196d 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -64,6 +64,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_dummyload.h"
+#include "xe/xe_query.h"
 
 /**
  * SECTION:drmtest
@@ -497,9 +498,14 @@ int __drm_open_driver_another(int idx, int chipset)
 		fd = __open_driver("/dev/dri/card", 0, chipset, idx);
 	}
 
-	if (fd >= 0)
+	if (fd >= 0) {
 		_set_opened_fd(idx, fd);
 
+		/* Cache xe_device struct. */
+		if (is_xe_device(fd))
+			xe_device_get(fd);
+	}
+
 	return fd;
 }
 
@@ -523,6 +529,8 @@ int __drm_open_driver(int chipset)
 
 int __drm_open_driver_render(int chipset)
 {
+	int fd;
+
 	if (chipset != DRIVER_VGEM && igt_device_filter_count() > 0) {
 		struct igt_device_card card;
 		bool found;
@@ -532,10 +540,16 @@ int __drm_open_driver_render(int chipset)
 		if (!found || !strlen(card.render))
 			return -1;
 
-		return __open_driver_exact(card.render, chipset);
+		fd = __open_driver_exact(card.render, chipset);
+	} else {
+		fd = __open_driver("/dev/dri/renderD", 128, chipset, 0);
 	}
 
-	return __open_driver("/dev/dri/renderD", 128, chipset, 0);
+	/* Cache xe_device struct. */
+	if (fd >= 0 && is_xe_device(fd))
+		xe_device_get(fd);
+
+	return fd;
 }
 
 static int at_exit_drm_fd = -1;
@@ -677,6 +691,10 @@ int drm_close_driver(int fd)
 		return -1;
 	}
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(fd))
+		xe_device_put(fd);
+
 	return close(fd);
 }
 
diff --git a/lib/igt_types.c b/lib/igt_types.c
index 392f30fca..d5d444889 100644
--- a/lib/igt_types.c
+++ b/lib/igt_types.c
@@ -5,13 +5,19 @@
 
 #include <unistd.h>
 
+#include "drmtest.h"
 #include "igt_types.h"
+#include "xe/xe_query.h"
 
 void igt_cleanup_fd(volatile int *fd)
 {
 	if (!fd || *fd < 0)
 		return;
 
+	/* Remove xe_device from cache. */
+	if (is_xe_device(*fd))
+		xe_device_put(*fd);
+
 	close(*fd);
 	*fd = -1;
 }
-- 
2.40.0

  parent reply	other threads:[~2023-06-22  7:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  6:53 [igt-dev] [V3 i-g-t 00/23] XE test cleanup to handle xe_device Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 01/23] lib: Interface to close the drm fd Bhanuprakash Modem
2023-06-22  6:54 ` Bhanuprakash Modem [this message]
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 03/23] lib/xe/xe_query: Add xe_config() interface Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 04/23] lib/igt_msm: Use drm_close_driver() to close the drm fd Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 05/23] tests/amdgpu: Close the fd before exit Bhanuprakash Modem
2023-06-22  7:22   ` Christian König
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 06/23] tests/i915: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 07/23] tests/kms: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 08/23] tests/nouveau_crc: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 09/23] tests/xe/xe_gpgpu_fill: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 10/23] tests/i915/kms_mmap_write_crc: Avoid closing the closed fd Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 11/23] tests: Use drm_close_driver() to close the drm fd Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 12/23] tests/amdgpu: " Bhanuprakash Modem
2023-06-22  7:22   ` Christian König
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 13/23] tests/chamelium: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 14/23] tests/panfrost: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 15/23] tests/v3d: " Bhanuprakash Modem
2023-06-22 11:55   ` Maira Canal
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 16/23] tests/vc4: " Bhanuprakash Modem
2023-06-22 11:56   ` Maira Canal
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 17/23] tests/vmwgfx: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 18/23] tests/kms: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 19/23] tests/xe: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 20/23] tests/i915: " Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 21/23] tests/xe/xe_debugfs: Use xe_config() helper to get the config Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 22/23] tests: Drop xe_device get/put from test level Bhanuprakash Modem
2023-06-22  6:54 ` [igt-dev] [V3 i-g-t 23/23] Revert "lib/igt_kms: Cache xe_device info for kms tests" Bhanuprakash Modem
2023-06-22  8:02 ` [igt-dev] ✗ Fi.CI.BAT: failure for XE test cleanup to handle xe_device (rev6) 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=20230622065422.2235134-3-bhanuprakash.modem@intel.com \
    --to=bhanuprakash.modem@intel.com \
    --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