From: Andrey Grodzovsky <andrey.grodzovsky@amd.com> To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Alexander.Deucher@amd.com, ckoenig.leichtzumerken@gmail.com Subject: [PATCH 5/7] test/amdgpu/hotunplug: Add basic test Date: Tue, 1 Jun 2021 16:17:00 -0400 [thread overview] Message-ID: <20210601201702.23316-6-andrey.grodzovsky@amd.com> (raw) In-Reply-To: <20210601201702.23316-1-andrey.grodzovsky@amd.com> Add plug/unplug device and open/close device file infrastrucutre. Add basic test - unplug device while device file still open. Close device file afterwards and replug the device. Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> --- tests/amdgpu/hotunplug_tests.c | 135 +++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 30 deletions(-) diff --git a/tests/amdgpu/hotunplug_tests.c b/tests/amdgpu/hotunplug_tests.c index 9d11dae4..c2bc1cf2 100644 --- a/tests/amdgpu/hotunplug_tests.c +++ b/tests/amdgpu/hotunplug_tests.c @@ -21,9 +21,11 @@ * */ -#include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #if HAVE_ALLOCA_H # include <alloca.h> #endif @@ -33,40 +35,40 @@ #include "amdgpu_test.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" - +#include "xf86drm.h" #include <pthread.h> static amdgpu_device_handle device_handle; static uint32_t major_version; static uint32_t minor_version; - -static uint32_t family_id; -static uint32_t chip_rev; -static uint32_t chip_id; +static char *sysfs_remove = NULL; CU_BOOL suite_hotunplug_tests_enable(void) { CU_BOOL enable = CU_TRUE; + drmDevicePtr device; + + if (drmGetDevice2(drm_amdgpu[0], DRM_DEVICE_GET_PCI_REVISION, &device)) { + printf("\n\nGPU Failed to get DRM device PCI info!\n"); + return CU_FALSE; + } + + if (device->bustype != DRM_BUS_PCI) { + printf("\n\nGPU device is not on PCI bus!\n"); + amdgpu_device_deinitialize(device_handle); + return CU_FALSE; + } + + /* Disable until the hot-unplug support in kernel gets into drm-next */ + if (major_version < 0xff) + enable = false; if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, &minor_version, &device_handle)) return CU_FALSE; - family_id = device_handle->info.family_id; - chip_id = device_handle->info.chip_external_rev; - chip_rev = device_handle->info.chip_rev; - - /* - * Only enable for ASICs supporting GPU reset and for which it's enabled - * by default (currently GFX8/9 dGPUS) - */ - if (family_id != AMDGPU_FAMILY_VI && - family_id != AMDGPU_FAMILY_AI && - family_id != AMDGPU_FAMILY_CI) { - printf("\n\nGPU reset is not enabled for the ASIC, hotunplug suite disabled\n"); - enable = CU_FALSE; - } + /* TODO Once DRM version for unplug feature ready compare here agains it*/ if (amdgpu_device_deinitialize(device_handle)) return CU_FALSE; @@ -75,8 +77,46 @@ CU_BOOL suite_hotunplug_tests_enable(void) } int suite_hotunplug_tests_init(void) +{ + /* We need to open/close device at each test manually */ + amdgpu_close_devices(); + + return CUE_SUCCESS; +} + +int suite_hotunplug_tests_clean(void) +{ + + + return CUE_SUCCESS; +} + +static int amdgpu_hotunplug_trigger(const char *pathname) +{ + int fd, len; + + fd = open(pathname, O_WRONLY); + if (fd < 0) + return -errno; + + len = write(fd, "1", 1); + close(fd); + + return len; +} + +static int amdgpu_hotunplug_setup_test() { int r; + char *tmp_str; + + if (amdgpu_open_device_on_test_index(open_render_node) <= 0) { + printf("\n\n Failed to reopen device file!\n"); + return CUE_SINIT_FAILED; + + + + } r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, &minor_version, &device_handle); @@ -89,27 +129,62 @@ int suite_hotunplug_tests_init(void) return CUE_SINIT_FAILED; } - return CUE_SUCCESS; + tmp_str = drmGetCharDeviceFromFd(drm_amdgpu[0]); + if (!tmp_str){ + printf("\n\n Device path not found!\n"); + return CUE_SINIT_FAILED; + } + + sysfs_remove = realloc(tmp_str, strlen(tmp_str) * 2); + strcat(sysfs_remove, "/device/remove"); + + return 0; + } -int suite_hotunplug_tests_clean(void) +static int amdgpu_hotunplug_teardown_test() { - int r = amdgpu_device_deinitialize(device_handle); - - if (r == 0) - return CUE_SUCCESS; - else + if (amdgpu_device_deinitialize(device_handle)) return CUE_SCLEAN_FAILED; + + amdgpu_close_devices(); + + if (sysfs_remove) + free(sysfs_remove); + + return 0; +} + +static inline int amdgpu_hotunplug_remove() +{ + return amdgpu_hotunplug_trigger(sysfs_remove); +} + +static inline int amdgpu_hotunplug_rescan() +{ + return amdgpu_hotunplug_trigger("/sys/bus/pci/rescan"); } -static void amdgpu_hotunplug_gfx(void) +static void amdgpu_hotunplug_simple(void) { - printf("Hello!\n"); + int r; + + r = amdgpu_hotunplug_setup_test(); + CU_ASSERT_EQUAL(r , 0); + + r = amdgpu_hotunplug_remove(); + CU_ASSERT_EQUAL(r > 0, 1); + + r = amdgpu_hotunplug_teardown_test(); + CU_ASSERT_EQUAL(r , 0); + + r = amdgpu_hotunplug_rescan(); + CU_ASSERT_EQUAL(r > 0, 1); } CU_TestInfo hotunplug_tests[] = { - { "gfx ring block test (set amdgpu.lockup_timeout=50)", amdgpu_hotunplug_gfx }, + { "Unplug card and rescan the bus to plug it back", amdgpu_hotunplug_simple }, CU_TEST_INFO_NULL, }; -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Andrey Grodzovsky <andrey.grodzovsky@amd.com> To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Alexander.Deucher@amd.com, ckoenig.leichtzumerken@gmail.com, Andrey Grodzovsky <andrey.grodzovsky@amd.com> Subject: [PATCH 5/7] test/amdgpu/hotunplug: Add basic test Date: Tue, 1 Jun 2021 16:17:00 -0400 [thread overview] Message-ID: <20210601201702.23316-6-andrey.grodzovsky@amd.com> (raw) In-Reply-To: <20210601201702.23316-1-andrey.grodzovsky@amd.com> Add plug/unplug device and open/close device file infrastrucutre. Add basic test - unplug device while device file still open. Close device file afterwards and replug the device. Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> --- tests/amdgpu/hotunplug_tests.c | 135 +++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 30 deletions(-) diff --git a/tests/amdgpu/hotunplug_tests.c b/tests/amdgpu/hotunplug_tests.c index 9d11dae4..c2bc1cf2 100644 --- a/tests/amdgpu/hotunplug_tests.c +++ b/tests/amdgpu/hotunplug_tests.c @@ -21,9 +21,11 @@ * */ -#include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #if HAVE_ALLOCA_H # include <alloca.h> #endif @@ -33,40 +35,40 @@ #include "amdgpu_test.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" - +#include "xf86drm.h" #include <pthread.h> static amdgpu_device_handle device_handle; static uint32_t major_version; static uint32_t minor_version; - -static uint32_t family_id; -static uint32_t chip_rev; -static uint32_t chip_id; +static char *sysfs_remove = NULL; CU_BOOL suite_hotunplug_tests_enable(void) { CU_BOOL enable = CU_TRUE; + drmDevicePtr device; + + if (drmGetDevice2(drm_amdgpu[0], DRM_DEVICE_GET_PCI_REVISION, &device)) { + printf("\n\nGPU Failed to get DRM device PCI info!\n"); + return CU_FALSE; + } + + if (device->bustype != DRM_BUS_PCI) { + printf("\n\nGPU device is not on PCI bus!\n"); + amdgpu_device_deinitialize(device_handle); + return CU_FALSE; + } + + /* Disable until the hot-unplug support in kernel gets into drm-next */ + if (major_version < 0xff) + enable = false; if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, &minor_version, &device_handle)) return CU_FALSE; - family_id = device_handle->info.family_id; - chip_id = device_handle->info.chip_external_rev; - chip_rev = device_handle->info.chip_rev; - - /* - * Only enable for ASICs supporting GPU reset and for which it's enabled - * by default (currently GFX8/9 dGPUS) - */ - if (family_id != AMDGPU_FAMILY_VI && - family_id != AMDGPU_FAMILY_AI && - family_id != AMDGPU_FAMILY_CI) { - printf("\n\nGPU reset is not enabled for the ASIC, hotunplug suite disabled\n"); - enable = CU_FALSE; - } + /* TODO Once DRM version for unplug feature ready compare here agains it*/ if (amdgpu_device_deinitialize(device_handle)) return CU_FALSE; @@ -75,8 +77,46 @@ CU_BOOL suite_hotunplug_tests_enable(void) } int suite_hotunplug_tests_init(void) +{ + /* We need to open/close device at each test manually */ + amdgpu_close_devices(); + + return CUE_SUCCESS; +} + +int suite_hotunplug_tests_clean(void) +{ + + + return CUE_SUCCESS; +} + +static int amdgpu_hotunplug_trigger(const char *pathname) +{ + int fd, len; + + fd = open(pathname, O_WRONLY); + if (fd < 0) + return -errno; + + len = write(fd, "1", 1); + close(fd); + + return len; +} + +static int amdgpu_hotunplug_setup_test() { int r; + char *tmp_str; + + if (amdgpu_open_device_on_test_index(open_render_node) <= 0) { + printf("\n\n Failed to reopen device file!\n"); + return CUE_SINIT_FAILED; + + + + } r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, &minor_version, &device_handle); @@ -89,27 +129,62 @@ int suite_hotunplug_tests_init(void) return CUE_SINIT_FAILED; } - return CUE_SUCCESS; + tmp_str = drmGetCharDeviceFromFd(drm_amdgpu[0]); + if (!tmp_str){ + printf("\n\n Device path not found!\n"); + return CUE_SINIT_FAILED; + } + + sysfs_remove = realloc(tmp_str, strlen(tmp_str) * 2); + strcat(sysfs_remove, "/device/remove"); + + return 0; + } -int suite_hotunplug_tests_clean(void) +static int amdgpu_hotunplug_teardown_test() { - int r = amdgpu_device_deinitialize(device_handle); - - if (r == 0) - return CUE_SUCCESS; - else + if (amdgpu_device_deinitialize(device_handle)) return CUE_SCLEAN_FAILED; + + amdgpu_close_devices(); + + if (sysfs_remove) + free(sysfs_remove); + + return 0; +} + +static inline int amdgpu_hotunplug_remove() +{ + return amdgpu_hotunplug_trigger(sysfs_remove); +} + +static inline int amdgpu_hotunplug_rescan() +{ + return amdgpu_hotunplug_trigger("/sys/bus/pci/rescan"); } -static void amdgpu_hotunplug_gfx(void) +static void amdgpu_hotunplug_simple(void) { - printf("Hello!\n"); + int r; + + r = amdgpu_hotunplug_setup_test(); + CU_ASSERT_EQUAL(r , 0); + + r = amdgpu_hotunplug_remove(); + CU_ASSERT_EQUAL(r > 0, 1); + + r = amdgpu_hotunplug_teardown_test(); + CU_ASSERT_EQUAL(r , 0); + + r = amdgpu_hotunplug_rescan(); + CU_ASSERT_EQUAL(r > 0, 1); } CU_TestInfo hotunplug_tests[] = { - { "gfx ring block test (set amdgpu.lockup_timeout=50)", amdgpu_hotunplug_gfx }, + { "Unplug card and rescan the bus to plug it back", amdgpu_hotunplug_simple }, CU_TEST_INFO_NULL, }; -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2021-06-01 20:17 UTC|newest] Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-01 20:16 [PATCH 0/7] libdrm tests for hot-unplug feature Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 1/7] tests/amdgpu: Fix valgrind warning Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 2/7] xf86drm: Add function to retrieve char device path Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-02 9:16 ` Simon Ser 2021-06-02 9:16 ` Simon Ser 2021-06-02 14:25 ` Andrey Grodzovsky 2021-06-02 14:25 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 3/7] test/amdgpu: Add helper functions for hot unplug Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 4/7] test/amdgpu/hotunplug: Add test suite for GPU unplug Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky [this message] 2021-06-01 20:17 ` [PATCH 5/7] test/amdgpu/hotunplug: Add basic test Andrey Grodzovsky 2021-06-01 20:17 ` [PATCH 6/7] tests/amdgpu/hotunplug: Add unplug with cs test Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky 2021-06-01 20:17 ` [PATCH 7/7] tests/amdgpu/hotunplug: Add hotunplug with exported bo test Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky 2021-06-02 7:59 ` [PATCH 0/7] libdrm tests for hot-unplug feature Daniel Vetter 2021-06-02 7:59 ` Daniel Vetter 2021-06-02 14:20 ` Andrey Grodzovsky 2021-06-02 14:20 ` Andrey Grodzovsky 2021-06-03 14:22 ` Andrey Grodzovsky 2021-06-03 14:22 ` Andrey Grodzovsky 2021-06-03 21:11 ` Daniel Vetter 2021-06-03 21:11 ` Daniel Vetter 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 22:02 ` [PATCH 0/7] libdrm tests for hot-unplug fe goature Grodzovsky, Andrey 2021-06-03 22:02 ` Grodzovsky, Andrey 2021-06-04 2:26 ` Alex Deucher 2021-06-04 2:26 ` Alex Deucher 2021-06-07 14:29 ` Andrey Grodzovsky 2021-06-07 14:29 ` Andrey Grodzovsky 2021-06-04 1:37 ` [PATCH 0/7] libdrm tests for hot-unplug feature Dave Airlie 2021-06-04 1:37 ` Dave Airlie 2021-06-04 2:53 ` Alex Deucher 2021-06-04 2:53 ` Alex Deucher 2021-06-04 3:31 ` Andrey Grodzovsky 2021-06-04 3:31 ` Andrey Grodzovsky
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=20210601201702.23316-6-andrey.grodzovsky@amd.com \ --to=andrey.grodzovsky@amd.com \ --cc=Alexander.Deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=ckoenig.leichtzumerken@gmail.com \ --cc=dri-devel@lists.freedesktop.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.