From: Qiang Yu <Qiang.Yu@amd.com>
To: amd-gfx@lists.freedesktop.org
Cc: Qiang Yu <Qiang.Yu@amd.com>,
Emil Velikov <emil.l.velikov@gmail.com>,
dri-devel@lists.freedesktop.org
Subject: [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device
Date: Thu, 14 Jul 2016 17:10:55 +0800 [thread overview]
Message-ID: <1468487456-28666-1-git-send-email-Qiang.Yu@amd.com> (raw)
drmGetDevice will always return the first device it find
under /dev/dri/. This is not true for multi GPU situation.
Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
---
xf86drm.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 6689f7c..19001db 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3087,6 +3087,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
int maj, min;
int ret, i, node_count;
int max_count = 16;
+ dev_t find_rdev;
if (fd == -1 || device == NULL)
return -EINVAL;
@@ -3094,6 +3095,7 @@ int drmGetDevice(int fd, drmDevicePtr *device)
if (fstat(fd, &sbuf))
return -errno;
+ find_rdev = sbuf.st_rdev;
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
@@ -3154,17 +3156,24 @@ int drmGetDevice(int fd, drmDevicePtr *device)
local_devices = temp;
}
- local_devices[i] = d;
+ /* store target at local_devices[0] for ease to use below */
+ if (find_rdev == sbuf.st_rdev && i) {
+ local_devices[i] = local_devices[0];
+ local_devices[0] = d;
+ }
+ else
+ local_devices[i] = d;
i++;
}
node_count = i;
- /* Fold nodes into a single device if they share the same bus info */
+ /* Fold nodes into a single device if they share the same bus info
+ * and nodes with same bus info will be merged into the first node
+ * position in local_devices */
drmFoldDuplicatedDevices(local_devices, node_count);
*device = local_devices[0];
- for (i = 1; i < node_count && local_devices[i]; i++)
- drmFreeDevice(&local_devices[i]);
+ drmFreeDevices(&local_devices[1], node_count - 1);
closedir(sysdir);
free(local_devices);
--
1.9.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2016-07-14 8:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-14 9:10 Qiang Yu [this message]
2016-07-14 9:10 ` [libdrm][PATCH v2 2/2] drm: fix multi GPU drmFreeDevices memory leak Qiang Yu
2016-07-14 17:20 ` [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Emil Velikov
2016-07-15 1:19 ` Yu, Qiang
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=1468487456-28666-1-git-send-email-Qiang.Yu@amd.com \
--to=qiang.yu@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
/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