tests/amdgpu/hotunplug: Add unplug with cs test.

Same as simple test but while doing cs

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Alex Deucher alexander.deucher@amd.com
main
Andrey Grodzovsky 2021-05-31 14:13:06 -04:00 committed by Alex Deucher
parent d4b780a735
commit b5f611cc37
1 changed files with 124 additions and 2 deletions

View File

@ -38,11 +38,13 @@
#include "xf86drm.h"
#include <pthread.h>
#define GFX_COMPUTE_NOP 0xffff1000
static amdgpu_device_handle device_handle;
static uint32_t major_version;
static uint32_t minor_version;
static char *sysfs_remove = NULL;
static bool do_cs;
CU_BOOL suite_hotunplug_tests_enable(void)
{
@ -110,7 +112,7 @@ static int amdgpu_hotunplug_setup_test()
int r;
char *tmp_str;
if (amdgpu_open_device_on_test_index(open_render_node) <= 0) {
if (amdgpu_open_device_on_test_index(open_render_node) < 0) {
printf("\n\n Failed to reopen device file!\n");
return CUE_SINIT_FAILED;
@ -165,17 +167,126 @@ static inline int amdgpu_hotunplug_rescan()
return amdgpu_hotunplug_trigger("/sys/bus/pci/rescan");
}
static int amdgpu_cs_sync(amdgpu_context_handle context,
unsigned int ip_type,
int ring,
unsigned int seqno)
{
struct amdgpu_cs_fence fence = {
.context = context,
.ip_type = ip_type,
.ring = ring,
.fence = seqno,
};
uint32_t expired;
static void amdgpu_hotunplug_simple(void)
return amdgpu_cs_query_fence_status(&fence,
AMDGPU_TIMEOUT_INFINITE,
0, &expired);
}
static void *amdgpu_nop_cs()
{
amdgpu_bo_handle ib_result_handle;
void *ib_result_cpu;
uint64_t ib_result_mc_address;
uint32_t *ptr;
int i, r;
amdgpu_bo_list_handle bo_list;
amdgpu_va_handle va_handle;
amdgpu_context_handle context;
struct amdgpu_cs_request ibs_request;
struct amdgpu_cs_ib_info ib_info;
r = amdgpu_cs_ctx_create(device_handle, &context);
CU_ASSERT_EQUAL(r, 0);
r = amdgpu_bo_alloc_and_map(device_handle, 4096, 4096,
AMDGPU_GEM_DOMAIN_GTT, 0,
&ib_result_handle, &ib_result_cpu,
&ib_result_mc_address, &va_handle);
CU_ASSERT_EQUAL(r, 0);
ptr = ib_result_cpu;
for (i = 0; i < 16; ++i)
ptr[i] = GFX_COMPUTE_NOP;
r = amdgpu_bo_list_create(device_handle, 1, &ib_result_handle, NULL, &bo_list);
CU_ASSERT_EQUAL(r, 0);
memset(&ib_info, 0, sizeof(struct amdgpu_cs_ib_info));
ib_info.ib_mc_address = ib_result_mc_address;
ib_info.size = 16;
memset(&ibs_request, 0, sizeof(struct amdgpu_cs_request));
ibs_request.ip_type = AMDGPU_HW_IP_GFX;
ibs_request.ring = 0;
ibs_request.number_of_ibs = 1;
ibs_request.ibs = &ib_info;
ibs_request.resources = bo_list;
while (do_cs)
amdgpu_cs_submit(context, 0, &ibs_request, 1);
amdgpu_cs_sync(context, AMDGPU_HW_IP_GFX, 0, ibs_request.seq_no);
amdgpu_bo_list_destroy(bo_list);
amdgpu_bo_unmap_and_free(ib_result_handle, va_handle,
ib_result_mc_address, 4096);
amdgpu_cs_ctx_free(context);
return (void *)0;
}
static pthread_t* amdgpu_create_cs_thread()
{
int r;
pthread_t *thread = malloc(sizeof(*thread));
if (!thread)
return NULL;
do_cs = true;
r = pthread_create(thread, NULL, amdgpu_nop_cs, NULL);
CU_ASSERT_EQUAL(r, 0);
/* Give thread enough time to start*/
usleep(100000);
return thread;
}
static void amdgpu_destroy_cs_thread(pthread_t *thread)
{
void *status;
do_cs = false;
pthread_join(*thread, &status);
CU_ASSERT_EQUAL(status, 0);
free(thread);
}
static void amdgpu_hotunplug_test(bool with_cs)
{
int r;
pthread_t *thread = NULL;
r = amdgpu_hotunplug_setup_test();
CU_ASSERT_EQUAL(r , 0);
if (with_cs) {
thread = amdgpu_create_cs_thread();
CU_ASSERT_NOT_EQUAL(thread, NULL);
}
r = amdgpu_hotunplug_remove();
CU_ASSERT_EQUAL(r > 0, 1);
if (with_cs)
amdgpu_destroy_cs_thread(thread);
r = amdgpu_hotunplug_teardown_test();
CU_ASSERT_EQUAL(r , 0);
@ -183,8 +294,19 @@ static void amdgpu_hotunplug_simple(void)
CU_ASSERT_EQUAL(r > 0, 1);
}
static void amdgpu_hotunplug_simple(void)
{
amdgpu_hotunplug_test(false);
}
static void amdgpu_hotunplug_with_cs(void)
{
amdgpu_hotunplug_test(true);
}
CU_TestInfo hotunplug_tests[] = {
{ "Unplug card and rescan the bus to plug it back", amdgpu_hotunplug_simple },
{ "Same as first test but with command submission", amdgpu_hotunplug_with_cs },
CU_TEST_INFO_NULL,
};