* [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device
@ 2016-07-14 9:10 Qiang Yu
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
0 siblings, 2 replies; 4+ messages in thread
From: Qiang Yu @ 2016-07-14 9:10 UTC (permalink / raw)
To: amd-gfx; +Cc: Qiang Yu, Emil Velikov, dri-devel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [libdrm][PATCH v2 2/2] drm: fix multi GPU drmFreeDevices memory leak
2016-07-14 9:10 [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Qiang Yu
@ 2016-07-14 9:10 ` Qiang Yu
2016-07-14 17:20 ` [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Emil Velikov
1 sibling, 0 replies; 4+ messages in thread
From: Qiang Yu @ 2016-07-14 9:10 UTC (permalink / raw)
To: amd-gfx; +Cc: Qiang Yu, Emil Velikov, dri-devel
When in multi GPU case, devices array may have some
NULL "hole" in between two devices. So check all
array elements and free non-NULL device.
Change-Id: Ifc32d240f895059bc4b19138cb81de38d99fb88a
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
---
xf86drm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 19001db..32bedeb 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2992,8 +2992,9 @@ void drmFreeDevices(drmDevicePtr devices[], int count)
if (devices == NULL)
return;
- for (i = 0; i < count && devices[i] != NULL; i++)
- drmFreeDevice(&devices[i]);
+ for (i = 0; i < count; i++)
+ if (devices[i])
+ drmFreeDevice(&devices[i]);
}
static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
--
1.9.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device
2016-07-14 9:10 [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Qiang Yu
2016-07-14 9:10 ` [libdrm][PATCH v2 2/2] drm: fix multi GPU drmFreeDevices memory leak Qiang Yu
@ 2016-07-14 17:20 ` Emil Velikov
2016-07-15 1:19 ` Yu, Qiang
1 sibling, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2016-07-14 17:20 UTC (permalink / raw)
To: Qiang Yu; +Cc: ML dri-devel, amd-gfx
On 14 July 2016 at 10:10, Qiang Yu <Qiang.Yu@amd.com> wrote:
> drmGetDevice will always return the first device it find
> under /dev/dri/. This is not true for multi GPU situation.
>
> Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Hope you don't mind if I drop the change-id lines before committing ?
If anyone beats be to it, for the series:
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Thanks
Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device
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
0 siblings, 0 replies; 4+ messages in thread
From: Yu, Qiang @ 2016-07-15 1:19 UTC (permalink / raw)
To: Emil Velikov; +Cc: ML dri-devel, amd-gfx
On 14 July 2016 at 10:10, Qiang Yu <Qiang.Yu@amd.com> wrote:
> drmGetDevice will always return the first device it find
> under /dev/dri/. This is not true for multi GPU situation.
>
> Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Hope you don't mind if I drop the change-id lines before committing ?
[yuq] Oh, I forgot remove this line. Please go ahead remove it, thanks.
Regards,
Qiang
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-07-15 1:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14 9:10 [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Qiang Yu
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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.