* [PATCH libdrm] amdgpu: dynamically detect number of drm devices
@ 2018-04-19 10:12 Xiaojie Yuan
[not found] ` <20180419101228.29306-1-Xiaojie.Yuan-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Xiaojie Yuan @ 2018-04-19 10:12 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Xiaojie Yuan
Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100
Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com>
---
tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++----------
tests/amdgpu/amdgpu_test.h | 7 +-----
2 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c
index 96fcd687..f7ac4ab4 100644
--- a/tests/amdgpu/amdgpu_test.c
+++ b/tests/amdgpu/amdgpu_test.c
@@ -61,7 +61,8 @@
* Open handles for amdgpu devices
*
*/
-int drm_amdgpu[MAX_CARDS_SUPPORTED];
+int *drm_amdgpu;
+size_t num_drm_devices;
/** Open render node to test */
int open_render_node = 0; /* By default run most tests on primary node */
@@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f";
*/
static int amdgpu_open_devices(int open_render_node)
{
- drmDevicePtr devices[MAX_CARDS_SUPPORTED];
+ drmDevicePtr *devices;
int i;
int drm_node;
int amd_index = 0;
int drm_count;
+ int drm_count2;
int fd;
drmVersionPtr version;
- drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);
-
+ drm_count = drmGetDevices2(0, NULL, 0);
if (drm_count < 0) {
fprintf(stderr,
"drmGetDevices2() returned an error %d\n",
@@ -255,6 +256,27 @@ static int amdgpu_open_devices(int open_render_node)
return 0;
}
+ devices = calloc(drm_count, sizeof(drmDevicePtr));
+ if (!devices) {
+ goto end;
+ }
+
+ drm_amdgpu = calloc(drm_count, sizeof(int));
+ if (!drm_amdgpu) {
+ goto end;
+ }
+
+ for (i = 0; i < drm_count; i++)
+ drm_amdgpu[i] = -1;
+
+ drm_count2 = drmGetDevices2(0, devices, drm_count);
+ if (drm_count2 != drm_count) {
+ fprintf(stderr, "number of drm devices changed");
+ goto end;
+ }
+
+ num_drm_devices = drm_count;
+
for (i = 0; i < drm_count; i++) {
/* If this is not PCI device, skip*/
if (devices[i]->bustype != DRM_BUS_PCI)
@@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node)
amd_index++;
}
+end:
drmFreeDevices(devices, drm_count);
+ free(devices);
return amd_index;
}
@@ -311,9 +335,11 @@ static int amdgpu_open_devices(int open_render_node)
static void amdgpu_close_devices()
{
int i;
- for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
+ for (i = 0; i < num_drm_devices; i++)
if (drm_amdgpu[i] >=0)
close(drm_amdgpu[i]);
+
+ free(drm_amdgpu);
}
/* Print AMD devices information */
@@ -339,7 +365,7 @@ static void amdgpu_print_devices()
/* Display information of AMD devices */
printf("Devices:\n");
- for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++)
+ for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++)
if (drmGetDevice2(drm_amdgpu[i],
DRM_DEVICE_GET_PCI_REVISION,
&device) == 0) {
@@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, uint16_t dev)
int i;
drmDevicePtr device;
- for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) {
+ for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) {
if (drmGetDevice2(drm_amdgpu[i],
DRM_DEVICE_GET_PCI_REVISION,
&device) == 0) {
@@ -456,10 +482,6 @@ int main(int argc, char **argv)
int display_list = 0;
int force_run = 0;
- for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
- drm_amdgpu[i] = -1;
-
-
/* Parse command line string */
opterr = 0; /* Do not print error messages from getopt */
while ((c = getopt(argc, argv, options)) != -1) {
diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h
index 62875736..8a604fe4 100644
--- a/tests/amdgpu/amdgpu_test.h
+++ b/tests/amdgpu/amdgpu_test.h
@@ -27,13 +27,8 @@
#include "amdgpu.h"
#include "amdgpu_drm.h"
-/**
- * Define max. number of card in system which we are able to handle
- */
-#define MAX_CARDS_SUPPORTED 4
-
/* Forward reference for array to keep "drm" handles */
-extern int drm_amdgpu[MAX_CARDS_SUPPORTED];
+extern int *drm_amdgpu;
/* Global variables */
extern int open_render_node;
--
2.17.0
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 9+ messages in thread[parent not found: <20180419101228.29306-1-Xiaojie.Yuan-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <20180419101228.29306-1-Xiaojie.Yuan-5C7GfCeVMHo@public.gmane.org> @ 2018-04-19 11:06 ` Christian König [not found] ` <5490ad94-b2b9-c087-d431-ee5ffd4504b0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Christian König @ 2018-04-19 11:06 UTC (permalink / raw) To: Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? Regards, Christian. Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: > Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 > Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> > --- > tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++---------- > tests/amdgpu/amdgpu_test.h | 7 +----- > 2 files changed, 34 insertions(+), 17 deletions(-) > > diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c > index 96fcd687..f7ac4ab4 100644 > --- a/tests/amdgpu/amdgpu_test.c > +++ b/tests/amdgpu/amdgpu_test.c > @@ -61,7 +61,8 @@ > * Open handles for amdgpu devices > * > */ > -int drm_amdgpu[MAX_CARDS_SUPPORTED]; > +int *drm_amdgpu; > +size_t num_drm_devices; > > /** Open render node to test */ > int open_render_node = 0; /* By default run most tests on primary node */ > @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; > */ > static int amdgpu_open_devices(int open_render_node) > { > - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; > + drmDevicePtr *devices; > int i; > int drm_node; > int amd_index = 0; > int drm_count; > + int drm_count2; > int fd; > drmVersionPtr version; > > - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); > - > + drm_count = drmGetDevices2(0, NULL, 0); > if (drm_count < 0) { > fprintf(stderr, > "drmGetDevices2() returned an error %d\n", > @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int open_render_node) > return 0; > } > > + devices = calloc(drm_count, sizeof(drmDevicePtr)); > + if (!devices) { > + goto end; > + } > + > + drm_amdgpu = calloc(drm_count, sizeof(int)); > + if (!drm_amdgpu) { > + goto end; > + } > + > + for (i = 0; i < drm_count; i++) > + drm_amdgpu[i] = -1; > + > + drm_count2 = drmGetDevices2(0, devices, drm_count); > + if (drm_count2 != drm_count) { > + fprintf(stderr, "number of drm devices changed"); > + goto end; > + } > + > + num_drm_devices = drm_count; > + > for (i = 0; i < drm_count; i++) { > /* If this is not PCI device, skip*/ > if (devices[i]->bustype != DRM_BUS_PCI) > @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node) > amd_index++; > } > > +end: > drmFreeDevices(devices, drm_count); > + free(devices); > return amd_index; > } > > @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int open_render_node) > static void amdgpu_close_devices() > { > int i; > - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) > + for (i = 0; i < num_drm_devices; i++) > if (drm_amdgpu[i] >=0) > close(drm_amdgpu[i]); > + > + free(drm_amdgpu); > } > > /* Print AMD devices information */ > @@ -339,7 +365,7 @@ static void amdgpu_print_devices() > > /* Display information of AMD devices */ > printf("Devices:\n"); > - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) > + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) > if (drmGetDevice2(drm_amdgpu[i], > DRM_DEVICE_GET_PCI_REVISION, > &device) == 0) { > @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, uint16_t dev) > int i; > drmDevicePtr device; > > - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { > + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { > if (drmGetDevice2(drm_amdgpu[i], > DRM_DEVICE_GET_PCI_REVISION, > &device) == 0) { > @@ -456,10 +482,6 @@ int main(int argc, char **argv) > int display_list = 0; > int force_run = 0; > > - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) > - drm_amdgpu[i] = -1; > - > - > /* Parse command line string */ > opterr = 0; /* Do not print error messages from getopt */ > while ((c = getopt(argc, argv, options)) != -1) { > diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h > index 62875736..8a604fe4 100644 > --- a/tests/amdgpu/amdgpu_test.h > +++ b/tests/amdgpu/amdgpu_test.h > @@ -27,13 +27,8 @@ > #include "amdgpu.h" > #include "amdgpu_drm.h" > > -/** > - * Define max. number of card in system which we are able to handle > - */ > -#define MAX_CARDS_SUPPORTED 4 > - > /* Forward reference for array to keep "drm" handles */ > -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; > +extern int *drm_amdgpu; > > /* Global variables */ > extern int open_render_node; _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <5490ad94-b2b9-c087-d431-ee5ffd4504b0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <5490ad94-b2b9-c087-d431-ee5ffd4504b0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2018-04-19 13:06 ` xiyuan [not found] ` <2f09c670-000a-90b3-0e1f-5f2f457b5c53-5C7GfCeVMHo@public.gmane.org> 2018-04-20 1:50 ` Zhang, Jerry (Junwei) 1 sibling, 1 reply; 9+ messages in thread From: xiyuan @ 2018-04-19 13:06 UTC (permalink / raw) To: christian.koenig-5C7GfCeVMHo, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW Hi Christian, The problem I encountered is that amdgpu_test throws segment fault on a platform with 1 iGPU + 4 dGPU. The root cause is that 'drm_count' returned by drmGetDevices() is 5 which exceeds MAX_CARDS_SUPPORTED, so I decided to make it more flexible to get the actual number of drm devices. Setting MAX_CARDS_SUPPORTED to 128 is fine to solve my problem but is it a bit large for traversal? Regards, Xiaojie On 04/19/2018 07:06 PM, Christian König wrote: > Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? > > Regards, > Christian. > > Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >> --- >> tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++---------- >> tests/amdgpu/amdgpu_test.h | 7 +----- >> 2 files changed, 34 insertions(+), 17 deletions(-) >> >> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >> index 96fcd687..f7ac4ab4 100644 >> --- a/tests/amdgpu/amdgpu_test.c >> +++ b/tests/amdgpu/amdgpu_test.c >> @@ -61,7 +61,8 @@ >> * Open handles for amdgpu devices >> * >> */ >> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >> +int *drm_amdgpu; >> +size_t num_drm_devices; >> /** Open render node to test */ >> int open_render_node = 0; /* By default run most tests on >> primary node */ >> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >> */ >> static int amdgpu_open_devices(int open_render_node) >> { >> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >> + drmDevicePtr *devices; >> int i; >> int drm_node; >> int amd_index = 0; >> int drm_count; >> + int drm_count2; >> int fd; >> drmVersionPtr version; >> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >> - >> + drm_count = drmGetDevices2(0, NULL, 0); >> if (drm_count < 0) { >> fprintf(stderr, >> "drmGetDevices2() returned an error %d\n", >> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int >> open_render_node) >> return 0; >> } >> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >> + if (!devices) { >> + goto end; >> + } >> + >> + drm_amdgpu = calloc(drm_count, sizeof(int)); >> + if (!drm_amdgpu) { >> + goto end; >> + } >> + >> + for (i = 0; i < drm_count; i++) >> + drm_amdgpu[i] = -1; >> + >> + drm_count2 = drmGetDevices2(0, devices, drm_count); >> + if (drm_count2 != drm_count) { >> + fprintf(stderr, "number of drm devices changed"); >> + goto end; >> + } >> + >> + num_drm_devices = drm_count; >> + >> for (i = 0; i < drm_count; i++) { >> /* If this is not PCI device, skip*/ >> if (devices[i]->bustype != DRM_BUS_PCI) >> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node) >> amd_index++; >> } >> +end: >> drmFreeDevices(devices, drm_count); >> + free(devices); >> return amd_index; >> } >> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int >> open_render_node) >> static void amdgpu_close_devices() >> { >> int i; >> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >> + for (i = 0; i < num_drm_devices; i++) >> if (drm_amdgpu[i] >=0) >> close(drm_amdgpu[i]); >> + >> + free(drm_amdgpu); >> } >> /* Print AMD devices information */ >> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >> /* Display information of AMD devices */ >> printf("Devices:\n"); >> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >> if (drmGetDevice2(drm_amdgpu[i], >> DRM_DEVICE_GET_PCI_REVISION, >> &device) == 0) { >> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, >> uint16_t dev) >> int i; >> drmDevicePtr device; >> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { >> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >> if (drmGetDevice2(drm_amdgpu[i], >> DRM_DEVICE_GET_PCI_REVISION, >> &device) == 0) { >> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >> int display_list = 0; >> int force_run = 0; >> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >> - drm_amdgpu[i] = -1; >> - >> - >> /* Parse command line string */ >> opterr = 0; /* Do not print error messages from getopt */ >> while ((c = getopt(argc, argv, options)) != -1) { >> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >> index 62875736..8a604fe4 100644 >> --- a/tests/amdgpu/amdgpu_test.h >> +++ b/tests/amdgpu/amdgpu_test.h >> @@ -27,13 +27,8 @@ >> #include "amdgpu.h" >> #include "amdgpu_drm.h" >> -/** >> - * Define max. number of card in system which we are able to handle >> - */ >> -#define MAX_CARDS_SUPPORTED 4 >> - >> /* Forward reference for array to keep "drm" handles */ >> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >> +extern int *drm_amdgpu; >> /* Global variables */ >> extern int open_render_node; > _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <2f09c670-000a-90b3-0e1f-5f2f457b5c53-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <2f09c670-000a-90b3-0e1f-5f2f457b5c53-5C7GfCeVMHo@public.gmane.org> @ 2018-04-19 13:11 ` Christian König [not found] ` <3bf3c941-a8e6-b69d-e70f-aacd6b1bc2d2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Christian König @ 2018-04-19 13:11 UTC (permalink / raw) To: xiyuan, christian.koenig-5C7GfCeVMHo, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW Am 19.04.2018 um 15:06 schrieb xiyuan: > Hi Christian, > > The problem I encountered is that amdgpu_test throws segment fault on > a platform with 1 iGPU + 4 dGPU. The root cause is that 'drm_count' > returned by drmGetDevices() is 5 which exceeds MAX_CARDS_SUPPORTED, so > I decided to make it more flexible to get the actual number of drm > devices. > > Setting MAX_CARDS_SUPPORTED to 128 is fine to solve my problem but is > it a bit large for traversal? No, not really. MAX_CARDS_SUPPORTED only affects the size of drm_amdgpu array. And so we would use 128*4=512 bytes at most. 128 is the maximum the kernel can support at the moment, so that should work for a while. Christian. > > Regards, > Xiaojie > > > On 04/19/2018 07:06 PM, Christian König wrote: >> Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? >> >> Regards, >> Christian. >> >> Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >>> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >>> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >>> --- >>> tests/amdgpu/amdgpu_test.c | 44 >>> ++++++++++++++++++++++++++++---------- >>> tests/amdgpu/amdgpu_test.h | 7 +----- >>> 2 files changed, 34 insertions(+), 17 deletions(-) >>> >>> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >>> index 96fcd687..f7ac4ab4 100644 >>> --- a/tests/amdgpu/amdgpu_test.c >>> +++ b/tests/amdgpu/amdgpu_test.c >>> @@ -61,7 +61,8 @@ >>> * Open handles for amdgpu devices >>> * >>> */ >>> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>> +int *drm_amdgpu; >>> +size_t num_drm_devices; >>> /** Open render node to test */ >>> int open_render_node = 0; /* By default run most tests on >>> primary node */ >>> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >>> */ >>> static int amdgpu_open_devices(int open_render_node) >>> { >>> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >>> + drmDevicePtr *devices; >>> int i; >>> int drm_node; >>> int amd_index = 0; >>> int drm_count; >>> + int drm_count2; >>> int fd; >>> drmVersionPtr version; >>> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >>> - >>> + drm_count = drmGetDevices2(0, NULL, 0); >>> if (drm_count < 0) { >>> fprintf(stderr, >>> "drmGetDevices2() returned an error %d\n", >>> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int >>> open_render_node) >>> return 0; >>> } >>> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >>> + if (!devices) { >>> + goto end; >>> + } >>> + >>> + drm_amdgpu = calloc(drm_count, sizeof(int)); >>> + if (!drm_amdgpu) { >>> + goto end; >>> + } >>> + >>> + for (i = 0; i < drm_count; i++) >>> + drm_amdgpu[i] = -1; >>> + >>> + drm_count2 = drmGetDevices2(0, devices, drm_count); >>> + if (drm_count2 != drm_count) { >>> + fprintf(stderr, "number of drm devices changed"); >>> + goto end; >>> + } >>> + >>> + num_drm_devices = drm_count; >>> + >>> for (i = 0; i < drm_count; i++) { >>> /* If this is not PCI device, skip*/ >>> if (devices[i]->bustype != DRM_BUS_PCI) >>> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int >>> open_render_node) >>> amd_index++; >>> } >>> +end: >>> drmFreeDevices(devices, drm_count); >>> + free(devices); >>> return amd_index; >>> } >>> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int >>> open_render_node) >>> static void amdgpu_close_devices() >>> { >>> int i; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>> + for (i = 0; i < num_drm_devices; i++) >>> if (drm_amdgpu[i] >=0) >>> close(drm_amdgpu[i]); >>> + >>> + free(drm_amdgpu); >>> } >>> /* Print AMD devices information */ >>> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >>> /* Display information of AMD devices */ >>> printf("Devices:\n"); >>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >>> if (drmGetDevice2(drm_amdgpu[i], >>> DRM_DEVICE_GET_PCI_REVISION, >>> &device) == 0) { >>> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, >>> uint16_t dev) >>> int i; >>> drmDevicePtr device; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; >>> i++) { >>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >>> if (drmGetDevice2(drm_amdgpu[i], >>> DRM_DEVICE_GET_PCI_REVISION, >>> &device) == 0) { >>> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >>> int display_list = 0; >>> int force_run = 0; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>> - drm_amdgpu[i] = -1; >>> - >>> - >>> /* Parse command line string */ >>> opterr = 0; /* Do not print error messages from getopt */ >>> while ((c = getopt(argc, argv, options)) != -1) { >>> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >>> index 62875736..8a604fe4 100644 >>> --- a/tests/amdgpu/amdgpu_test.h >>> +++ b/tests/amdgpu/amdgpu_test.h >>> @@ -27,13 +27,8 @@ >>> #include "amdgpu.h" >>> #include "amdgpu_drm.h" >>> -/** >>> - * Define max. number of card in system which we are able to handle >>> - */ >>> -#define MAX_CARDS_SUPPORTED 4 >>> - >>> /* Forward reference for array to keep "drm" handles */ >>> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>> +extern int *drm_amdgpu; >>> /* Global variables */ >>> extern int open_render_node; >> > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <3bf3c941-a8e6-b69d-e70f-aacd6b1bc2d2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <3bf3c941-a8e6-b69d-e70f-aacd6b1bc2d2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2018-04-19 13:45 ` xiyuan 0 siblings, 0 replies; 9+ messages in thread From: xiyuan @ 2018-04-19 13:45 UTC (permalink / raw) To: christian.koenig-5C7GfCeVMHo, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW On 04/19/2018 09:11 PM, Christian König wrote: > Am 19.04.2018 um 15:06 schrieb xiyuan: >> Hi Christian, >> >> The problem I encountered is that amdgpu_test throws segment fault on >> a platform with 1 iGPU + 4 dGPU. The root cause is that 'drm_count' >> returned by drmGetDevices() is 5 which exceeds MAX_CARDS_SUPPORTED, >> so I decided to make it more flexible to get the actual number of drm >> devices. >> >> Setting MAX_CARDS_SUPPORTED to 128 is fine to solve my problem but is >> it a bit large for traversal? > > No, not really. MAX_CARDS_SUPPORTED only affects the size of > drm_amdgpu array. And so we would use 128*4=512 bytes at most. Agree. I glanced at code again, traversal for drm_amdgpu array only occurs at amdgpu_print_devices() and amdgpu_find_devices() and neither are hot codepath. > > 128 is the maximum the kernel can support at the moment, so that > should work for a while. Makes more sense. Could you just point out where the 128 limit is set? I'll prepare another patch soon. Regards, Xiaojie > > Christian. > >> >> Regards, >> Xiaojie >> >> >> On 04/19/2018 07:06 PM, Christian König wrote: >>> Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? >>> >>> Regards, >>> Christian. >>> >>> Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >>>> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >>>> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >>>> --- >>>> tests/amdgpu/amdgpu_test.c | 44 >>>> ++++++++++++++++++++++++++++---------- >>>> tests/amdgpu/amdgpu_test.h | 7 +----- >>>> 2 files changed, 34 insertions(+), 17 deletions(-) >>>> >>>> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >>>> index 96fcd687..f7ac4ab4 100644 >>>> --- a/tests/amdgpu/amdgpu_test.c >>>> +++ b/tests/amdgpu/amdgpu_test.c >>>> @@ -61,7 +61,8 @@ >>>> * Open handles for amdgpu devices >>>> * >>>> */ >>>> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>> +int *drm_amdgpu; >>>> +size_t num_drm_devices; >>>> /** Open render node to test */ >>>> int open_render_node = 0; /* By default run most tests on >>>> primary node */ >>>> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >>>> */ >>>> static int amdgpu_open_devices(int open_render_node) >>>> { >>>> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >>>> + drmDevicePtr *devices; >>>> int i; >>>> int drm_node; >>>> int amd_index = 0; >>>> int drm_count; >>>> + int drm_count2; >>>> int fd; >>>> drmVersionPtr version; >>>> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >>>> - >>>> + drm_count = drmGetDevices2(0, NULL, 0); >>>> if (drm_count < 0) { >>>> fprintf(stderr, >>>> "drmGetDevices2() returned an error %d\n", >>>> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> return 0; >>>> } >>>> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >>>> + if (!devices) { >>>> + goto end; >>>> + } >>>> + >>>> + drm_amdgpu = calloc(drm_count, sizeof(int)); >>>> + if (!drm_amdgpu) { >>>> + goto end; >>>> + } >>>> + >>>> + for (i = 0; i < drm_count; i++) >>>> + drm_amdgpu[i] = -1; >>>> + >>>> + drm_count2 = drmGetDevices2(0, devices, drm_count); >>>> + if (drm_count2 != drm_count) { >>>> + fprintf(stderr, "number of drm devices changed"); >>>> + goto end; >>>> + } >>>> + >>>> + num_drm_devices = drm_count; >>>> + >>>> for (i = 0; i < drm_count; i++) { >>>> /* If this is not PCI device, skip*/ >>>> if (devices[i]->bustype != DRM_BUS_PCI) >>>> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> amd_index++; >>>> } >>>> +end: >>>> drmFreeDevices(devices, drm_count); >>>> + free(devices); >>>> return amd_index; >>>> } >>>> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> static void amdgpu_close_devices() >>>> { >>>> int i; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>> + for (i = 0; i < num_drm_devices; i++) >>>> if (drm_amdgpu[i] >=0) >>>> close(drm_amdgpu[i]); >>>> + >>>> + free(drm_amdgpu); >>>> } >>>> /* Print AMD devices information */ >>>> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >>>> /* Display information of AMD devices */ >>>> printf("Devices:\n"); >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >>>> if (drmGetDevice2(drm_amdgpu[i], >>>> DRM_DEVICE_GET_PCI_REVISION, >>>> &device) == 0) { >>>> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, >>>> uint16_t dev) >>>> int i; >>>> drmDevicePtr device; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; >>>> i++) { >>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >>>> if (drmGetDevice2(drm_amdgpu[i], >>>> DRM_DEVICE_GET_PCI_REVISION, >>>> &device) == 0) { >>>> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >>>> int display_list = 0; >>>> int force_run = 0; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>> - drm_amdgpu[i] = -1; >>>> - >>>> - >>>> /* Parse command line string */ >>>> opterr = 0; /* Do not print error messages from getopt */ >>>> while ((c = getopt(argc, argv, options)) != -1) { >>>> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >>>> index 62875736..8a604fe4 100644 >>>> --- a/tests/amdgpu/amdgpu_test.h >>>> +++ b/tests/amdgpu/amdgpu_test.h >>>> @@ -27,13 +27,8 @@ >>>> #include "amdgpu.h" >>>> #include "amdgpu_drm.h" >>>> -/** >>>> - * Define max. number of card in system which we are able to handle >>>> - */ >>>> -#define MAX_CARDS_SUPPORTED 4 >>>> - >>>> /* Forward reference for array to keep "drm" handles */ >>>> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>> +extern int *drm_amdgpu; >>>> /* Global variables */ >>>> extern int open_render_node; >>> >> >> _______________________________________________ >> amd-gfx mailing list >> amd-gfx@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx > _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <5490ad94-b2b9-c087-d431-ee5ffd4504b0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2018-04-19 13:06 ` xiyuan @ 2018-04-20 1:50 ` Zhang, Jerry (Junwei) [not found] ` <5AD94773.6010301-5C7GfCeVMHo@public.gmane.org> 1 sibling, 1 reply; 9+ messages in thread From: Zhang, Jerry (Junwei) @ 2018-04-20 1:50 UTC (permalink / raw) To: christian.koenig-5C7GfCeVMHo, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW On 04/19/2018 07:06 PM, Christian König wrote: > Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? Perhaps it's 64 for card number. Although CONTROL node is not used now, but only 64 slots are reserved for each type. otherwise, we may prepare a patch to update to 128. How do you think that? Jerry > > Regards, > Christian. > > Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >> --- >> tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++---------- >> tests/amdgpu/amdgpu_test.h | 7 +----- >> 2 files changed, 34 insertions(+), 17 deletions(-) >> >> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >> index 96fcd687..f7ac4ab4 100644 >> --- a/tests/amdgpu/amdgpu_test.c >> +++ b/tests/amdgpu/amdgpu_test.c >> @@ -61,7 +61,8 @@ >> * Open handles for amdgpu devices >> * >> */ >> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >> +int *drm_amdgpu; >> +size_t num_drm_devices; >> /** Open render node to test */ >> int open_render_node = 0; /* By default run most tests on primary node */ >> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >> */ >> static int amdgpu_open_devices(int open_render_node) >> { >> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >> + drmDevicePtr *devices; >> int i; >> int drm_node; >> int amd_index = 0; >> int drm_count; >> + int drm_count2; >> int fd; >> drmVersionPtr version; >> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >> - >> + drm_count = drmGetDevices2(0, NULL, 0); >> if (drm_count < 0) { >> fprintf(stderr, >> "drmGetDevices2() returned an error %d\n", >> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int open_render_node) >> return 0; >> } >> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >> + if (!devices) { >> + goto end; >> + } >> + >> + drm_amdgpu = calloc(drm_count, sizeof(int)); >> + if (!drm_amdgpu) { >> + goto end; >> + } >> + >> + for (i = 0; i < drm_count; i++) >> + drm_amdgpu[i] = -1; >> + >> + drm_count2 = drmGetDevices2(0, devices, drm_count); >> + if (drm_count2 != drm_count) { >> + fprintf(stderr, "number of drm devices changed"); >> + goto end; >> + } >> + >> + num_drm_devices = drm_count; >> + >> for (i = 0; i < drm_count; i++) { >> /* If this is not PCI device, skip*/ >> if (devices[i]->bustype != DRM_BUS_PCI) >> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node) >> amd_index++; >> } >> +end: >> drmFreeDevices(devices, drm_count); >> + free(devices); >> return amd_index; >> } >> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int open_render_node) >> static void amdgpu_close_devices() >> { >> int i; >> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >> + for (i = 0; i < num_drm_devices; i++) >> if (drm_amdgpu[i] >=0) >> close(drm_amdgpu[i]); >> + >> + free(drm_amdgpu); >> } >> /* Print AMD devices information */ >> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >> /* Display information of AMD devices */ >> printf("Devices:\n"); >> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >> if (drmGetDevice2(drm_amdgpu[i], >> DRM_DEVICE_GET_PCI_REVISION, >> &device) == 0) { >> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, uint16_t dev) >> int i; >> drmDevicePtr device; >> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { >> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >> if (drmGetDevice2(drm_amdgpu[i], >> DRM_DEVICE_GET_PCI_REVISION, >> &device) == 0) { >> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >> int display_list = 0; >> int force_run = 0; >> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >> - drm_amdgpu[i] = -1; >> - >> - >> /* Parse command line string */ >> opterr = 0; /* Do not print error messages from getopt */ >> while ((c = getopt(argc, argv, options)) != -1) { >> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >> index 62875736..8a604fe4 100644 >> --- a/tests/amdgpu/amdgpu_test.h >> +++ b/tests/amdgpu/amdgpu_test.h >> @@ -27,13 +27,8 @@ >> #include "amdgpu.h" >> #include "amdgpu_drm.h" >> -/** >> - * Define max. number of card in system which we are able to handle >> - */ >> -#define MAX_CARDS_SUPPORTED 4 >> - >> /* Forward reference for array to keep "drm" handles */ >> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >> +extern int *drm_amdgpu; >> /* Global variables */ >> extern int open_render_node; > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <5AD94773.6010301-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <5AD94773.6010301-5C7GfCeVMHo@public.gmane.org> @ 2018-04-20 2:04 ` Zhang, Jerry (Junwei) [not found] ` <5AD94AA4.2010404-5C7GfCeVMHo@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Zhang, Jerry (Junwei) @ 2018-04-20 2:04 UTC (permalink / raw) To: christian.koenig-5C7GfCeVMHo, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW On 04/20/2018 09:50 AM, Zhang, Jerry (Junwei) wrote: > On 04/19/2018 07:06 PM, Christian König wrote: >> Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? > > Perhaps it's 64 for card number. > Although CONTROL node is not used now, but only 64 slots are reserved for each > type. > > otherwise, we may prepare a patch to update to 128. > How do you think that? On second thought, it will touch much code to clean CONTROL node. In current stage, updating the number looks the best way. But 64 seems reasonable for now. Jerry > > Jerry > >> >> Regards, >> Christian. >> >> Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >>> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >>> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >>> --- >>> tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++---------- >>> tests/amdgpu/amdgpu_test.h | 7 +----- >>> 2 files changed, 34 insertions(+), 17 deletions(-) >>> >>> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >>> index 96fcd687..f7ac4ab4 100644 >>> --- a/tests/amdgpu/amdgpu_test.c >>> +++ b/tests/amdgpu/amdgpu_test.c >>> @@ -61,7 +61,8 @@ >>> * Open handles for amdgpu devices >>> * >>> */ >>> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>> +int *drm_amdgpu; >>> +size_t num_drm_devices; >>> /** Open render node to test */ >>> int open_render_node = 0; /* By default run most tests on primary node */ >>> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >>> */ >>> static int amdgpu_open_devices(int open_render_node) >>> { >>> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >>> + drmDevicePtr *devices; >>> int i; >>> int drm_node; >>> int amd_index = 0; >>> int drm_count; >>> + int drm_count2; >>> int fd; >>> drmVersionPtr version; >>> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >>> - >>> + drm_count = drmGetDevices2(0, NULL, 0); >>> if (drm_count < 0) { >>> fprintf(stderr, >>> "drmGetDevices2() returned an error %d\n", >>> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int open_render_node) >>> return 0; >>> } >>> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >>> + if (!devices) { >>> + goto end; >>> + } >>> + >>> + drm_amdgpu = calloc(drm_count, sizeof(int)); >>> + if (!drm_amdgpu) { >>> + goto end; >>> + } >>> + >>> + for (i = 0; i < drm_count; i++) >>> + drm_amdgpu[i] = -1; >>> + >>> + drm_count2 = drmGetDevices2(0, devices, drm_count); >>> + if (drm_count2 != drm_count) { >>> + fprintf(stderr, "number of drm devices changed"); >>> + goto end; >>> + } >>> + >>> + num_drm_devices = drm_count; >>> + >>> for (i = 0; i < drm_count; i++) { >>> /* If this is not PCI device, skip*/ >>> if (devices[i]->bustype != DRM_BUS_PCI) >>> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node) >>> amd_index++; >>> } >>> +end: >>> drmFreeDevices(devices, drm_count); >>> + free(devices); >>> return amd_index; >>> } >>> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int open_render_node) >>> static void amdgpu_close_devices() >>> { >>> int i; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>> + for (i = 0; i < num_drm_devices; i++) >>> if (drm_amdgpu[i] >=0) >>> close(drm_amdgpu[i]); >>> + >>> + free(drm_amdgpu); >>> } >>> /* Print AMD devices information */ >>> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >>> /* Display information of AMD devices */ >>> printf("Devices:\n"); >>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >>> if (drmGetDevice2(drm_amdgpu[i], >>> DRM_DEVICE_GET_PCI_REVISION, >>> &device) == 0) { >>> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, uint16_t dev) >>> int i; >>> drmDevicePtr device; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { >>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >>> if (drmGetDevice2(drm_amdgpu[i], >>> DRM_DEVICE_GET_PCI_REVISION, >>> &device) == 0) { >>> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >>> int display_list = 0; >>> int force_run = 0; >>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>> - drm_amdgpu[i] = -1; >>> - >>> - >>> /* Parse command line string */ >>> opterr = 0; /* Do not print error messages from getopt */ >>> while ((c = getopt(argc, argv, options)) != -1) { >>> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >>> index 62875736..8a604fe4 100644 >>> --- a/tests/amdgpu/amdgpu_test.h >>> +++ b/tests/amdgpu/amdgpu_test.h >>> @@ -27,13 +27,8 @@ >>> #include "amdgpu.h" >>> #include "amdgpu_drm.h" >>> -/** >>> - * Define max. number of card in system which we are able to handle >>> - */ >>> -#define MAX_CARDS_SUPPORTED 4 >>> - >>> /* Forward reference for array to keep "drm" handles */ >>> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>> +extern int *drm_amdgpu; >>> /* Global variables */ >>> extern int open_render_node; >> >> _______________________________________________ >> amd-gfx mailing list >> amd-gfx@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <5AD94AA4.2010404-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <5AD94AA4.2010404-5C7GfCeVMHo@public.gmane.org> @ 2018-04-20 6:58 ` Christian König [not found] ` <6ff1895f-f1e4-e6f6-4b67-bdc967e33a23-5C7GfCeVMHo@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Christian König @ 2018-04-20 6:58 UTC (permalink / raw) To: Zhang, Jerry (Junwei), Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW Am 20.04.2018 um 04:04 schrieb Zhang, Jerry (Junwei): > On 04/20/2018 09:50 AM, Zhang, Jerry (Junwei) wrote: >> On 04/19/2018 07:06 PM, Christian König wrote: >>> Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? >> >> Perhaps it's 64 for card number. >> Although CONTROL node is not used now, but only 64 slots are reserved >> for each >> type. >> >> otherwise, we may prepare a patch to update to 128. >> How do you think that? > > On second thought, it will touch much code to clean CONTROL node. > In current stage, updating the number looks the best way. > But 64 seems reasonable for now. My last status is that control nodes where dropped and so we are back to 128 devices in theory, but I have to admit that I didn't follow the discussion closely. Anyway I've already pushed the patch upstream which changes that to 128 and as far as I can see we waste only around 256bytes even if 64 would be sufficient, so there is no strong reason to change that once more. Christian. > > Jerry > >> >> Jerry >> >>> >>> Regards, >>> Christian. >>> >>> Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >>>> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >>>> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >>>> --- >>>> tests/amdgpu/amdgpu_test.c | 44 >>>> ++++++++++++++++++++++++++++---------- >>>> tests/amdgpu/amdgpu_test.h | 7 +----- >>>> 2 files changed, 34 insertions(+), 17 deletions(-) >>>> >>>> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >>>> index 96fcd687..f7ac4ab4 100644 >>>> --- a/tests/amdgpu/amdgpu_test.c >>>> +++ b/tests/amdgpu/amdgpu_test.c >>>> @@ -61,7 +61,8 @@ >>>> * Open handles for amdgpu devices >>>> * >>>> */ >>>> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>> +int *drm_amdgpu; >>>> +size_t num_drm_devices; >>>> /** Open render node to test */ >>>> int open_render_node = 0; /* By default run most tests on >>>> primary node */ >>>> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >>>> */ >>>> static int amdgpu_open_devices(int open_render_node) >>>> { >>>> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >>>> + drmDevicePtr *devices; >>>> int i; >>>> int drm_node; >>>> int amd_index = 0; >>>> int drm_count; >>>> + int drm_count2; >>>> int fd; >>>> drmVersionPtr version; >>>> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >>>> - >>>> + drm_count = drmGetDevices2(0, NULL, 0); >>>> if (drm_count < 0) { >>>> fprintf(stderr, >>>> "drmGetDevices2() returned an error %d\n", >>>> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> return 0; >>>> } >>>> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >>>> + if (!devices) { >>>> + goto end; >>>> + } >>>> + >>>> + drm_amdgpu = calloc(drm_count, sizeof(int)); >>>> + if (!drm_amdgpu) { >>>> + goto end; >>>> + } >>>> + >>>> + for (i = 0; i < drm_count; i++) >>>> + drm_amdgpu[i] = -1; >>>> + >>>> + drm_count2 = drmGetDevices2(0, devices, drm_count); >>>> + if (drm_count2 != drm_count) { >>>> + fprintf(stderr, "number of drm devices changed"); >>>> + goto end; >>>> + } >>>> + >>>> + num_drm_devices = drm_count; >>>> + >>>> for (i = 0; i < drm_count; i++) { >>>> /* If this is not PCI device, skip*/ >>>> if (devices[i]->bustype != DRM_BUS_PCI) >>>> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> amd_index++; >>>> } >>>> +end: >>>> drmFreeDevices(devices, drm_count); >>>> + free(devices); >>>> return amd_index; >>>> } >>>> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int >>>> open_render_node) >>>> static void amdgpu_close_devices() >>>> { >>>> int i; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>> + for (i = 0; i < num_drm_devices; i++) >>>> if (drm_amdgpu[i] >=0) >>>> close(drm_amdgpu[i]); >>>> + >>>> + free(drm_amdgpu); >>>> } >>>> /* Print AMD devices information */ >>>> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >>>> /* Display information of AMD devices */ >>>> printf("Devices:\n"); >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >>>> if (drmGetDevice2(drm_amdgpu[i], >>>> DRM_DEVICE_GET_PCI_REVISION, >>>> &device) == 0) { >>>> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, >>>> uint16_t dev) >>>> int i; >>>> drmDevicePtr device; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { >>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >>>> if (drmGetDevice2(drm_amdgpu[i], >>>> DRM_DEVICE_GET_PCI_REVISION, >>>> &device) == 0) { >>>> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >>>> int display_list = 0; >>>> int force_run = 0; >>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>> - drm_amdgpu[i] = -1; >>>> - >>>> - >>>> /* Parse command line string */ >>>> opterr = 0; /* Do not print error messages from getopt */ >>>> while ((c = getopt(argc, argv, options)) != -1) { >>>> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >>>> index 62875736..8a604fe4 100644 >>>> --- a/tests/amdgpu/amdgpu_test.h >>>> +++ b/tests/amdgpu/amdgpu_test.h >>>> @@ -27,13 +27,8 @@ >>>> #include "amdgpu.h" >>>> #include "amdgpu_drm.h" >>>> -/** >>>> - * Define max. number of card in system which we are able to handle >>>> - */ >>>> -#define MAX_CARDS_SUPPORTED 4 >>>> - >>>> /* Forward reference for array to keep "drm" handles */ >>>> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>> +extern int *drm_amdgpu; >>>> /* Global variables */ >>>> extern int open_render_node; >>> >>> _______________________________________________ >>> amd-gfx mailing list >>> amd-gfx@lists.freedesktop.org >>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx >> _______________________________________________ >> amd-gfx mailing list >> amd-gfx@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <6ff1895f-f1e4-e6f6-4b67-bdc967e33a23-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH libdrm] amdgpu: dynamically detect number of drm devices [not found] ` <6ff1895f-f1e4-e6f6-4b67-bdc967e33a23-5C7GfCeVMHo@public.gmane.org> @ 2018-04-20 7:40 ` Zhang, Jerry (Junwei) 0 siblings, 0 replies; 9+ messages in thread From: Zhang, Jerry (Junwei) @ 2018-04-20 7:40 UTC (permalink / raw) To: Christian König, Xiaojie Yuan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW On 04/20/2018 02:58 PM, Christian König wrote: > Am 20.04.2018 um 04:04 schrieb Zhang, Jerry (Junwei): >> On 04/20/2018 09:50 AM, Zhang, Jerry (Junwei) wrote: >>> On 04/19/2018 07:06 PM, Christian König wrote: >>>> Wouldn't it be simpler to just set MAX_CARDS_SUPPORTED to 128? >>> >>> Perhaps it's 64 for card number. >>> Although CONTROL node is not used now, but only 64 slots are reserved for each >>> type. >>> >>> otherwise, we may prepare a patch to update to 128. >>> How do you think that? >> >> On second thought, it will touch much code to clean CONTROL node. >> In current stage, updating the number looks the best way. >> But 64 seems reasonable for now. > > My last status is that control nodes where dropped and so we are back to 128 > devices in theory, but I have to admit that I didn't follow the discussion closely. At that time, it only dropped the CONTROL node register, but many cleanup work did not perform, since it's a little bit work to do, waiting for a while to make sure it's really not used anywhere. Anyway, it's fine for current change to extend the number for card. Jerry > > Anyway I've already pushed the patch upstream which changes that to 128 and as > far as I can see we waste only around 256bytes even if 64 would be sufficient, > so there is no strong reason to change that once more. > > Christian. > >> >> Jerry >> >>> >>> Jerry >>> >>>> >>>> Regards, >>>> Christian. >>>> >>>> Am 19.04.2018 um 12:12 schrieb Xiaojie Yuan: >>>>> Change-Id: I36764951bebbcbf06cf84dd43ee946a34ec7b100 >>>>> Signed-off-by: Xiaojie Yuan <Xiaojie.Yuan@amd.com> >>>>> --- >>>>> tests/amdgpu/amdgpu_test.c | 44 ++++++++++++++++++++++++++++---------- >>>>> tests/amdgpu/amdgpu_test.h | 7 +----- >>>>> 2 files changed, 34 insertions(+), 17 deletions(-) >>>>> >>>>> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c >>>>> index 96fcd687..f7ac4ab4 100644 >>>>> --- a/tests/amdgpu/amdgpu_test.c >>>>> +++ b/tests/amdgpu/amdgpu_test.c >>>>> @@ -61,7 +61,8 @@ >>>>> * Open handles for amdgpu devices >>>>> * >>>>> */ >>>>> -int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>>> +int *drm_amdgpu; >>>>> +size_t num_drm_devices; >>>>> /** Open render node to test */ >>>>> int open_render_node = 0; /* By default run most tests on primary node */ >>>>> @@ -238,16 +239,16 @@ static const char options[] = "hlrps:t:b:d:f"; >>>>> */ >>>>> static int amdgpu_open_devices(int open_render_node) >>>>> { >>>>> - drmDevicePtr devices[MAX_CARDS_SUPPORTED]; >>>>> + drmDevicePtr *devices; >>>>> int i; >>>>> int drm_node; >>>>> int amd_index = 0; >>>>> int drm_count; >>>>> + int drm_count2; >>>>> int fd; >>>>> drmVersionPtr version; >>>>> - drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); >>>>> - >>>>> + drm_count = drmGetDevices2(0, NULL, 0); >>>>> if (drm_count < 0) { >>>>> fprintf(stderr, >>>>> "drmGetDevices2() returned an error %d\n", >>>>> @@ -255,6 +256,27 @@ static int amdgpu_open_devices(int open_render_node) >>>>> return 0; >>>>> } >>>>> + devices = calloc(drm_count, sizeof(drmDevicePtr)); >>>>> + if (!devices) { >>>>> + goto end; >>>>> + } >>>>> + >>>>> + drm_amdgpu = calloc(drm_count, sizeof(int)); >>>>> + if (!drm_amdgpu) { >>>>> + goto end; >>>>> + } >>>>> + >>>>> + for (i = 0; i < drm_count; i++) >>>>> + drm_amdgpu[i] = -1; >>>>> + >>>>> + drm_count2 = drmGetDevices2(0, devices, drm_count); >>>>> + if (drm_count2 != drm_count) { >>>>> + fprintf(stderr, "number of drm devices changed"); >>>>> + goto end; >>>>> + } >>>>> + >>>>> + num_drm_devices = drm_count; >>>>> + >>>>> for (i = 0; i < drm_count; i++) { >>>>> /* If this is not PCI device, skip*/ >>>>> if (devices[i]->bustype != DRM_BUS_PCI) >>>>> @@ -302,7 +324,9 @@ static int amdgpu_open_devices(int open_render_node) >>>>> amd_index++; >>>>> } >>>>> +end: >>>>> drmFreeDevices(devices, drm_count); >>>>> + free(devices); >>>>> return amd_index; >>>>> } >>>>> @@ -311,9 +335,11 @@ static int amdgpu_open_devices(int open_render_node) >>>>> static void amdgpu_close_devices() >>>>> { >>>>> int i; >>>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>>> + for (i = 0; i < num_drm_devices; i++) >>>>> if (drm_amdgpu[i] >=0) >>>>> close(drm_amdgpu[i]); >>>>> + >>>>> + free(drm_amdgpu); >>>>> } >>>>> /* Print AMD devices information */ >>>>> @@ -339,7 +365,7 @@ static void amdgpu_print_devices() >>>>> /* Display information of AMD devices */ >>>>> printf("Devices:\n"); >>>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) >>>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >=0; i++) >>>>> if (drmGetDevice2(drm_amdgpu[i], >>>>> DRM_DEVICE_GET_PCI_REVISION, >>>>> &device) == 0) { >>>>> @@ -377,7 +403,7 @@ static int amdgpu_find_device(uint8_t bus, uint16_t dev) >>>>> int i; >>>>> drmDevicePtr device; >>>>> - for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { >>>>> + for (i = 0; i < num_drm_devices && drm_amdgpu[i] >= 0; i++) { >>>>> if (drmGetDevice2(drm_amdgpu[i], >>>>> DRM_DEVICE_GET_PCI_REVISION, >>>>> &device) == 0) { >>>>> @@ -456,10 +482,6 @@ int main(int argc, char **argv) >>>>> int display_list = 0; >>>>> int force_run = 0; >>>>> - for (i = 0; i < MAX_CARDS_SUPPORTED; i++) >>>>> - drm_amdgpu[i] = -1; >>>>> - >>>>> - >>>>> /* Parse command line string */ >>>>> opterr = 0; /* Do not print error messages from getopt */ >>>>> while ((c = getopt(argc, argv, options)) != -1) { >>>>> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h >>>>> index 62875736..8a604fe4 100644 >>>>> --- a/tests/amdgpu/amdgpu_test.h >>>>> +++ b/tests/amdgpu/amdgpu_test.h >>>>> @@ -27,13 +27,8 @@ >>>>> #include "amdgpu.h" >>>>> #include "amdgpu_drm.h" >>>>> -/** >>>>> - * Define max. number of card in system which we are able to handle >>>>> - */ >>>>> -#define MAX_CARDS_SUPPORTED 4 >>>>> - >>>>> /* Forward reference for array to keep "drm" handles */ >>>>> -extern int drm_amdgpu[MAX_CARDS_SUPPORTED]; >>>>> +extern int *drm_amdgpu; >>>>> /* Global variables */ >>>>> extern int open_render_node; >>>> >>>> _______________________________________________ >>>> amd-gfx mailing list >>>> amd-gfx@lists.freedesktop.org >>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx >>> _______________________________________________ >>> amd-gfx mailing list >>> amd-gfx@lists.freedesktop.org >>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx > _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-04-20 7:40 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-19 10:12 [PATCH libdrm] amdgpu: dynamically detect number of drm devices Xiaojie Yuan
[not found] ` <20180419101228.29306-1-Xiaojie.Yuan-5C7GfCeVMHo@public.gmane.org>
2018-04-19 11:06 ` Christian König
[not found] ` <5490ad94-b2b9-c087-d431-ee5ffd4504b0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-19 13:06 ` xiyuan
[not found] ` <2f09c670-000a-90b3-0e1f-5f2f457b5c53-5C7GfCeVMHo@public.gmane.org>
2018-04-19 13:11 ` Christian König
[not found] ` <3bf3c941-a8e6-b69d-e70f-aacd6b1bc2d2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-19 13:45 ` xiyuan
2018-04-20 1:50 ` Zhang, Jerry (Junwei)
[not found] ` <5AD94773.6010301-5C7GfCeVMHo@public.gmane.org>
2018-04-20 2:04 ` Zhang, Jerry (Junwei)
[not found] ` <5AD94AA4.2010404-5C7GfCeVMHo@public.gmane.org>
2018-04-20 6:58 ` Christian König
[not found] ` <6ff1895f-f1e4-e6f6-4b67-bdc967e33a23-5C7GfCeVMHo@public.gmane.org>
2018-04-20 7:40 ` Zhang, Jerry (Junwei)
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.