net/hns3: fix max packet size rollback in PF
[dpdk.git] / app / test-gpudev / main.c
index c647e30..4500a86 100644 (file)
@@ -68,12 +68,13 @@ alloc_gpu_memory(uint16_t gpu_id)
        void *ptr_1 = NULL;
        void *ptr_2 = NULL;
        size_t buf_bytes = 1024;
+       unsigned int align = 4096;
        int ret;
 
        printf("\n=======> TEST: Allocate GPU memory\n\n");
 
-       /* Alloc memory on GPU 0 */
-       ptr_1 = rte_gpu_mem_alloc(gpu_id, buf_bytes);
+       /* Alloc memory on GPU 0 without any specific alignment */
+       ptr_1 = rte_gpu_mem_alloc(gpu_id, buf_bytes, 0);
        if (ptr_1 == NULL) {
                fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned error\n");
                goto error;
@@ -81,7 +82,8 @@ alloc_gpu_memory(uint16_t gpu_id)
        printf("GPU memory allocated at 0x%p size is %zd bytes\n",
                        ptr_1, buf_bytes);
 
-       ptr_2 = rte_gpu_mem_alloc(gpu_id, buf_bytes);
+       /* Alloc memory on GPU 0 with 4kB alignment */
+       ptr_2 = rte_gpu_mem_alloc(gpu_id, buf_bytes, align);
        if (ptr_2 == NULL) {
                fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned error\n");
                goto error;
@@ -89,6 +91,11 @@ alloc_gpu_memory(uint16_t gpu_id)
        printf("GPU memory allocated at 0x%p size is %zd bytes\n",
                        ptr_2, buf_bytes);
 
+       if (((uintptr_t)ptr_2) % align) {
+               fprintf(stderr, "Memory address 0x%p is not aligned to %u\n", ptr_2, align);
+               goto error;
+       }
+
        ret = rte_gpu_mem_free(gpu_id, (uint8_t *)(ptr_1)+0x700);
        if (ret < 0) {
                printf("GPU memory 0x%p NOT freed: GPU driver didn't find this memory address internally.\n",
@@ -117,6 +124,10 @@ alloc_gpu_memory(uint16_t gpu_id)
        return 0;
 
 error:
+
+       rte_gpu_mem_free(gpu_id, ptr_1);
+       rte_gpu_mem_free(gpu_id, ptr_2);
+
        printf("\n=======> TEST: FAILED\n");
        return -1;
 }
@@ -161,10 +172,15 @@ register_cpu_memory(uint16_t gpu_id)
        }
        printf("CPU memory 0x%p unregistered\n", ptr);
 
+       rte_free(ptr);
+
        printf("\n=======> TEST: PASSED\n");
        return 0;
 
 error:
+
+       rte_gpu_mem_unregister(gpu_id, ptr);
+       rte_free(ptr);
        printf("\n=======> TEST: FAILED\n");
        return -1;
 }
@@ -227,6 +243,8 @@ create_update_comm_flag(uint16_t gpu_id)
        return 0;
 
 error:
+
+       rte_gpu_comm_destroy_flag(&devflag);
        printf("\n=======> TEST: FAILED\n");
        return -1;
 }
@@ -254,7 +272,7 @@ create_update_comm_list(uint16_t gpu_id)
 {
        int ret = 0;
        int i = 0;
-       struct rte_gpu_comm_list *comm_list;
+       struct rte_gpu_comm_list *comm_list = NULL;
        uint32_t num_comm_items = 1024;
        struct rte_mbuf *mbufs[10];
 
@@ -327,6 +345,10 @@ create_update_comm_list(uint16_t gpu_id)
        return 0;
 
 error:
+
+       rte_gpu_comm_destroy_list(comm_list, num_comm_items);
+       for (i = 0; i < 10; i++)
+               rte_free(mbufs[i]);
        printf("\n=======> TEST: FAILED\n");
        return -1;
 }