[igt-dev] [V3 i-g-t 02/23] lib: Cache xe_device at driver open/close level
Bhanuprakash Modem
bhanuprakash.modem at intel.com
Thu Jun 22 06:54:01 UTC 2023
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 at intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at 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
More information about the igt-dev
mailing list