diff options
author | Alex Xie | 2017-01-24 16:29:51 -0600 |
---|---|---|
committer | Alex Deucher | 2017-01-27 10:55:28 -0600 |
commit | 12dd7a2e9cfa20a3022cfe091e824b09c0bfb9d1 (patch) | |
tree | 12b9d90d93cef2fbd3565bcf1b9e08da31035424 | |
parent | 5e0f7c5c65ca6714cd7352d72303ec2cbec35cb5 (diff) | |
download | external-libdrm-12dd7a2e9cfa20a3022cfe091e824b09c0bfb9d1.tar.gz external-libdrm-12dd7a2e9cfa20a3022cfe091e824b09c0bfb9d1.tar.xz external-libdrm-12dd7a2e9cfa20a3022cfe091e824b09c0bfb9d1.zip |
amdgpu: A new option to choose which device to run most tests
This can be used to test multiple GPUs
v2: Use PCI bus ID and optional PCI device ID to choose device
Add an option to display information of AMDGPU devices
Tested:
./amdgpu_test -p
./amdgpu_test
./amdgpu_test -b 1 #fail as expected
./amdgpu_test -b 6 #pass
./amdgpu_test -b -d 1 #fail as expected
./amdgpu_test -b -d 0 #pass
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Alex Xie <AlexBin.Xie@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | tests/amdgpu/amdgpu_test.c | 133 |
1 files changed, 116 insertions, 17 deletions
diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c index d2b00d4f..c01ee543 100644 --- a/tests/amdgpu/amdgpu_test.c +++ b/tests/amdgpu/amdgpu_test.c | |||
@@ -108,12 +108,17 @@ static void display_test_suites(void) | |||
108 | 108 | ||
109 | 109 | ||
110 | /** Help string for command line parameters */ | 110 | /** Help string for command line parameters */ |
111 | static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" | 111 | static const char usage[] = |
112 | "where:\n" | 112 | "Usage: %s [-hlp] [<-s <suite id>> [-t <test id>]] " |
113 | " l - Display all suites and their tests\n" | 113 | "[-b <pci_bus_id> [-d <pci_device_id>]]\n" |
114 | " h - Display this help\n"; | 114 | "where:\n" |
115 | " l - Display all suites and their tests\n" | ||
116 | " b - Specify device's PCI bus id to run tests\n" | ||
117 | " d - Specify device's PCI device id to run tests (optional)\n" | ||
118 | " p - Display information of AMDGPU devices in system\n" | ||
119 | " h - Display this help\n"; | ||
115 | /** Specified options strings for getopt */ | 120 | /** Specified options strings for getopt */ |
116 | static const char options[] = "hls:t:"; | 121 | static const char options[] = "hlps:t:b:d:"; |
117 | 122 | ||
118 | /* Open AMD devices. | 123 | /* Open AMD devices. |
119 | * Return the number of AMD device openned. | 124 | * Return the number of AMD device openned. |
@@ -203,21 +208,79 @@ static void amdgpu_close_devices() | |||
203 | static void amdgpu_print_devices() | 208 | static void amdgpu_print_devices() |
204 | { | 209 | { |
205 | int i; | 210 | int i; |
206 | for (i = 0; i < MAX_CARDS_SUPPORTED; i++) | 211 | drmDevicePtr device; |
207 | if (drm_amdgpu[i] >=0) { | 212 | |
208 | /** Display version of DRM driver */ | 213 | /* Open the first AMD devcie to print driver information. */ |
209 | drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]); | 214 | if (drm_amdgpu[0] >=0) { |
215 | /* Display AMD driver version information.*/ | ||
216 | drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]); | ||
217 | |||
218 | if (retval == NULL) { | ||
219 | perror("Cannot get version for AMDGPU device"); | ||
220 | return; | ||
221 | } | ||
210 | 222 | ||
211 | if (retval == NULL) { | 223 | printf("Driver name: %s, Date: %s, Description: %s.\n", |
212 | perror("Cannot get version for AMDGPU device"); | 224 | retval->name, retval->date, retval->desc); |
213 | exit(EXIT_FAILURE); | 225 | drmFreeVersion(retval); |
226 | } | ||
227 | |||
228 | /* Display information of AMD devices */ | ||
229 | printf("Devices:\n"); | ||
230 | for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) | ||
231 | if (drmGetDevice2(drm_amdgpu[i], | ||
232 | DRM_DEVICE_GET_PCI_REVISION, | ||
233 | &device) == 0) { | ||
234 | if (device->bustype == DRM_BUS_PCI) { | ||
235 | printf("PCI "); | ||
236 | printf(" domain:%04x", | ||
237 | device->businfo.pci->domain); | ||
238 | printf(" bus:%02x", | ||
239 | device->businfo.pci->bus); | ||
240 | printf(" device:%02x", | ||
241 | device->businfo.pci->dev); | ||
242 | printf(" function:%01x", | ||
243 | device->businfo.pci->func); | ||
244 | printf(" vendor_id:%04x", | ||
245 | device->deviceinfo.pci->vendor_id); | ||
246 | printf(" device_id:%04x", | ||
247 | device->deviceinfo.pci->device_id); | ||
248 | printf(" subvendor_id:%04x", | ||
249 | device->deviceinfo.pci->subvendor_id); | ||
250 | printf(" subdevice_id:%04x", | ||
251 | device->deviceinfo.pci->subdevice_id); | ||
252 | printf(" revision_id:%02x", | ||
253 | device->deviceinfo.pci->revision_id); | ||
254 | printf("\n"); | ||
214 | } | 255 | } |
256 | drmFreeDevice(&device); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /* Find a match AMD device in PCI bus | ||
261 | * Return the index of the device or -1 if not found | ||
262 | */ | ||
263 | static int amdgpu_find_device(uint8_t bus, uint8_t dev) | ||
264 | { | ||
265 | int i; | ||
266 | drmDevicePtr device; | ||
267 | |||
268 | for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) | ||
269 | if (drmGetDevice2(drm_amdgpu[i], | ||
270 | DRM_DEVICE_GET_PCI_REVISION, | ||
271 | &device) == 0) { | ||
272 | if (device->bustype == DRM_BUS_PCI) | ||
273 | if (device->businfo.pci->bus == bus && | ||
274 | device->businfo.pci->dev == dev) { | ||
275 | |||
276 | drmFreeDevice(&device); | ||
277 | return i; | ||
278 | } | ||
215 | 279 | ||
216 | printf("AMDGPU device #%d: " | 280 | drmFreeDevice(&device); |
217 | "Name: [%s] : Date [%s] : Description [%s]\n", | ||
218 | i, retval->name, retval->date, retval->desc); | ||
219 | drmFreeVersion(retval); | ||
220 | } | 281 | } |
282 | |||
283 | return -1; | ||
221 | } | 284 | } |
222 | 285 | ||
223 | /* The main() function for setting up and running the tests. | 286 | /* The main() function for setting up and running the tests. |
@@ -230,8 +293,12 @@ int main(int argc, char **argv) | |||
230 | int i = 0; | 293 | int i = 0; |
231 | int suite_id = -1; /* By default run everything */ | 294 | int suite_id = -1; /* By default run everything */ |
232 | int test_id = -1; /* By default run all tests in the suite */ | 295 | int test_id = -1; /* By default run all tests in the suite */ |
296 | int pci_bus_id = -1; /* By default PC bus ID is not specified */ | ||
297 | int pci_device_id = 0; /* By default PC device ID is zero */ | ||
298 | int display_devices = 0;/* By default not to display devices' info */ | ||
233 | CU_pSuite pSuite = NULL; | 299 | CU_pSuite pSuite = NULL; |
234 | CU_pTest pTest = NULL; | 300 | CU_pTest pTest = NULL; |
301 | int test_device_index; | ||
235 | 302 | ||
236 | for (i = 0; i < MAX_CARDS_SUPPORTED; i++) | 303 | for (i = 0; i < MAX_CARDS_SUPPORTED; i++) |
237 | drm_amdgpu[i] = -1; | 304 | drm_amdgpu[i] = -1; |
@@ -250,6 +317,15 @@ int main(int argc, char **argv) | |||
250 | case 't': | 317 | case 't': |
251 | test_id = atoi(optarg); | 318 | test_id = atoi(optarg); |
252 | break; | 319 | break; |
320 | case 'b': | ||
321 | pci_bus_id = atoi(optarg); | ||
322 | break; | ||
323 | case 'd': | ||
324 | pci_device_id = atoi(optarg); | ||
325 | break; | ||
326 | case 'p': | ||
327 | display_devices = 1; | ||
328 | break; | ||
253 | case '?': | 329 | case '?': |
254 | case 'h': | 330 | case 'h': |
255 | fprintf(stderr, usage, argv[0]); | 331 | fprintf(stderr, usage, argv[0]); |
@@ -270,7 +346,30 @@ int main(int argc, char **argv) | |||
270 | exit(EXIT_FAILURE); | 346 | exit(EXIT_FAILURE); |
271 | } | 347 | } |
272 | 348 | ||
273 | amdgpu_print_devices(); | 349 | if (display_devices) { |
350 | amdgpu_print_devices(); | ||
351 | amdgpu_close_devices(); | ||
352 | exit(EXIT_SUCCESS); | ||
353 | } | ||
354 | |||
355 | if (pci_bus_id > 0) { | ||
356 | /* A device was specified to run the test */ | ||
357 | test_device_index = amdgpu_find_device((uint8_t)pci_bus_id, | ||
358 | (uint8_t)pci_device_id); | ||
359 | |||
360 | if (test_device_index >= 0) { | ||
361 | /* Most tests run on device of drm_amdgpu[0]. | ||
362 | * Swap the chosen device to drm_amdgpu[0]. | ||
363 | */ | ||
364 | i = drm_amdgpu[0]; | ||
365 | drm_amdgpu[0] = drm_amdgpu[test_device_index]; | ||
366 | drm_amdgpu[test_device_index] = i; | ||
367 | } else { | ||
368 | fprintf(stderr, | ||
369 | "The specified GPU device does not exist.\n"); | ||
370 | exit(EXIT_FAILURE); | ||
371 | } | ||
372 | } | ||
274 | 373 | ||
275 | /* Initialize test suites to run */ | 374 | /* Initialize test suites to run */ |
276 | 375 | ||