OSDN Git Service

amdgpu: vamgr_32 can be a struct instead of a pointer
authorAlex Xie <AlexBin.Xie@amd.com>
Sat, 28 Jan 2017 19:50:36 +0000 (21:50 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 2 Feb 2017 20:22:45 +0000 (15:22 -0500)
vamgr_32 is an integral part of amdgpu_device. We don't need to calloc and free it.
This can save CPU time, reduce heap fragmentation.

Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Alex Xie <AlexBin.Xie@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
[Grazvydas Ignotas: rebase, correct a typo in commit message]
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
amdgpu/amdgpu_device.c
amdgpu/amdgpu_internal.h
amdgpu/amdgpu_vamgr.c

index cad7133..11714e4 100644 (file)
@@ -131,8 +131,7 @@ static int amdgpu_get_auth(int fd, int *auth)
 
 static void amdgpu_device_free_internal(amdgpu_device_handle dev)
 {
-       amdgpu_vamgr_deinit(dev->vamgr_32);
-       free(dev->vamgr_32);
+       amdgpu_vamgr_deinit(&dev->vamgr_32);
        amdgpu_vamgr_deinit(dev->vamgr);
        free(dev->vamgr);
        util_hash_table_destroy(dev->bo_flink_names);
@@ -270,10 +269,7 @@ int amdgpu_device_initialize(int fd,
        if (start > 0xffffffff)
                goto free_va; /* shouldn't get here */
 
-       dev->vamgr_32 =  calloc(1, sizeof(struct amdgpu_bo_va_mgr));
-       if (dev->vamgr_32 == NULL)
-               goto free_va;
-       amdgpu_vamgr_init(dev->vamgr_32, start, max,
+       amdgpu_vamgr_init(&dev->vamgr_32, start, max,
                          dev->dev_info.virtual_address_alignment);
 
        *major_version = dev->major_version;
index 4f039b6..7e237ac 100644 (file)
@@ -87,7 +87,7 @@ struct amdgpu_device {
        /** The global VA manager for the whole virtual address space */
        struct amdgpu_bo_va_mgr *vamgr;
        /** The VA manager for the 32bit address space */
-       struct amdgpu_bo_va_mgr *vamgr_32;
+       struct amdgpu_bo_va_mgr vamgr_32;
 };
 
 struct amdgpu_bo {
index 8a707cb..4dc4253 100644 (file)
@@ -236,7 +236,7 @@ int amdgpu_va_range_alloc(amdgpu_device_handle dev,
        struct amdgpu_bo_va_mgr *vamgr;
 
        if (flags & AMDGPU_VA_RANGE_32_BIT)
-               vamgr = dev->vamgr_32;
+               vamgr = &dev->vamgr_32;
        else
                vamgr = dev->vamgr;
 
@@ -249,7 +249,7 @@ int amdgpu_va_range_alloc(amdgpu_device_handle dev,
        if (!(flags & AMDGPU_VA_RANGE_32_BIT) &&
            (*va_base_allocated == AMDGPU_INVALID_VA_ADDRESS)) {
                /* fallback to 32bit address */
-               vamgr = dev->vamgr_32;
+               vamgr = &dev->vamgr_32;
                *va_base_allocated = amdgpu_vamgr_find_va(vamgr, size,
                                        va_base_alignment, va_base_required);
        }