Re: [PATCH v2 6/6] drm/amdgpu: do not allocate entries separately

2021-05-28 Thread Das, Nirmoy


On 5/28/2021 4:09 PM, Christian König wrote:



Am 28.05.21 um 12:56 schrieb Nirmoy Das:

Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

v2: create a new var for num entries.

Signed-off-by: Nirmoy Das 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 +++---
  1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 223c63342ecd..7e478ffb7fdf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -877,6 +877,7 @@ static int amdgpu_vm_pt_create(struct 
amdgpu_device *adev,

  struct amdgpu_bo *bo;
  struct dma_resv *resv;
  int r;
+    unsigned int num_entries;


Move that a more up, variables like r and i should be always declared 
last.




Thanks, I will keep this in my mind next time.



Apart from that Reviewed-by: Christian König 

Next step should probably be to remove entry->entries.



Right, I will do that.


Regards,

Nirmoy



Regards,
Christian.



  memset(, 0, sizeof(bp));

@@ -886,7 +887,14 @@ static int amdgpu_vm_pt_create(struct 
amdgpu_device *adev,

  bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
  bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
  AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-    bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+
+    if (level < AMDGPU_VM_PTB)
+    num_entries = amdgpu_vm_num_entries(adev, level);
+    else
+    num_entries = 0;
+
+    bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
+
  if (vm->use_cpu_for_update)
  bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;

@@ -957,19 +965,14 @@ static int amdgpu_vm_alloc_pts(struct 
amdgpu_device *adev,

  struct amdgpu_bo_vm *pt;
  int r;

-    if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
-    unsigned num_entries;
-
-    num_entries = amdgpu_vm_num_entries(adev, cursor->level);
-    entry->entries = kvmalloc_array(num_entries,
-    sizeof(*entry->entries),
-    GFP_KERNEL | __GFP_ZERO);
-    if (!entry->entries)
-    return -ENOMEM;
-    }
-
-    if (entry->base.bo)
+    if (entry->base.bo) {
+    if (cursor->level < AMDGPU_VM_PTB)
+    entry->entries =
+    to_amdgpu_bo_vm(entry->base.bo)->entries;
+    else
+    entry->entries = NULL;
  return 0;
+    }

  r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, );
  if (r)
@@ -981,6 +984,10 @@ static int amdgpu_vm_alloc_pts(struct 
amdgpu_device *adev,

  pt_bo = >bo;
  pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
  amdgpu_vm_bo_base_init(>base, vm, pt_bo);
+    if (cursor->level < AMDGPU_VM_PTB)
+    entry->entries = pt->entries;
+    else
+    entry->entries = NULL;

  r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
  if (r)
@@ -1010,7 +1017,6 @@ static void amdgpu_vm_free_table(struct 
amdgpu_vm_pt *entry)

  amdgpu_bo_unref();
  amdgpu_bo_unref(>base.bo);
  }
-    kvfree(entry->entries);
  entry->entries = NULL;
  }

--
2.31.1




___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH v2 6/6] drm/amdgpu: do not allocate entries separately

2021-05-28 Thread Christian König



Am 28.05.21 um 12:56 schrieb Nirmoy Das:

Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

v2: create a new var for num entries.

Signed-off-by: Nirmoy Das 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 +++---
  1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 223c63342ecd..7e478ffb7fdf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -877,6 +877,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
struct amdgpu_bo *bo;
struct dma_resv *resv;
int r;
+   unsigned int num_entries;


Move that a more up, variables like r and i should be always declared last.

Apart from that Reviewed-by: Christian König 

Next step should probably be to remove entry->entries.

Regards,
Christian.



memset(, 0, sizeof(bp));

@@ -886,7 +887,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-   bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+
+   if (level < AMDGPU_VM_PTB)
+   num_entries = amdgpu_vm_num_entries(adev, level);
+   else
+   num_entries = 0;
+
+   bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
+
if (vm->use_cpu_for_update)
bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;

@@ -957,19 +965,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
struct amdgpu_bo_vm *pt;
int r;

-   if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
-   unsigned num_entries;
-
-   num_entries = amdgpu_vm_num_entries(adev, cursor->level);
-   entry->entries = kvmalloc_array(num_entries,
-   sizeof(*entry->entries),
-   GFP_KERNEL | __GFP_ZERO);
-   if (!entry->entries)
-   return -ENOMEM;
-   }
-
-   if (entry->base.bo)
+   if (entry->base.bo) {
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries =
+   to_amdgpu_bo_vm(entry->base.bo)->entries;
+   else
+   entry->entries = NULL;
return 0;
+   }

r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, );
if (r)
@@ -981,6 +984,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
pt_bo = >bo;
pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
amdgpu_vm_bo_base_init(>base, vm, pt_bo);
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries = pt->entries;
+   else
+   entry->entries = NULL;

r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
if (r)
@@ -1010,7 +1017,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt 
*entry)
amdgpu_bo_unref();
amdgpu_bo_unref(>base.bo);
}
-   kvfree(entry->entries);
entry->entries = NULL;
  }

--
2.31.1



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2 6/6] drm/amdgpu: do not allocate entries separately

2021-05-28 Thread Nirmoy Das
Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

v2: create a new var for num entries.

Signed-off-by: Nirmoy Das 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 +++---
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 223c63342ecd..7e478ffb7fdf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -877,6 +877,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
struct amdgpu_bo *bo;
struct dma_resv *resv;
int r;
+   unsigned int num_entries;

memset(, 0, sizeof(bp));

@@ -886,7 +887,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-   bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+
+   if (level < AMDGPU_VM_PTB)
+   num_entries = amdgpu_vm_num_entries(adev, level);
+   else
+   num_entries = 0;
+
+   bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
+
if (vm->use_cpu_for_update)
bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;

@@ -957,19 +965,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
struct amdgpu_bo_vm *pt;
int r;

-   if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
-   unsigned num_entries;
-
-   num_entries = amdgpu_vm_num_entries(adev, cursor->level);
-   entry->entries = kvmalloc_array(num_entries,
-   sizeof(*entry->entries),
-   GFP_KERNEL | __GFP_ZERO);
-   if (!entry->entries)
-   return -ENOMEM;
-   }
-
-   if (entry->base.bo)
+   if (entry->base.bo) {
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries =
+   to_amdgpu_bo_vm(entry->base.bo)->entries;
+   else
+   entry->entries = NULL;
return 0;
+   }

r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, );
if (r)
@@ -981,6 +984,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
pt_bo = >bo;
pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
amdgpu_vm_bo_base_init(>base, vm, pt_bo);
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries = pt->entries;
+   else
+   entry->entries = NULL;

r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
if (r)
@@ -1010,7 +1017,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt 
*entry)
amdgpu_bo_unref();
amdgpu_bo_unref(>base.bo);
}
-   kvfree(entry->entries);
entry->entries = NULL;
 }

--
2.31.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2 6/6] drm/amdgpu: do not allocate entries separately

2021-05-27 Thread Nirmoy Das
Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

v2: create a new var for num entries.

Signed-off-by: Nirmoy Das 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 +++---
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index d723873df765..70df453863cb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -876,6 +876,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
struct amdgpu_bo *bo;
struct dma_resv *resv;
int r;
+   unsigned int num_entries;

memset(, 0, sizeof(bp));

@@ -885,7 +886,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-   bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+
+   if (level < AMDGPU_VM_PTB)
+   num_entries = amdgpu_vm_num_entries(adev, level);
+   else
+   num_entries = 0;
+
+   bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
+
if (vm->use_cpu_for_update)
bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;

@@ -956,19 +964,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
struct amdgpu_bo_vm *pt;
int r;

-   if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
-   unsigned num_entries;
-
-   num_entries = amdgpu_vm_num_entries(adev, cursor->level);
-   entry->entries = kvmalloc_array(num_entries,
-   sizeof(*entry->entries),
-   GFP_KERNEL | __GFP_ZERO);
-   if (!entry->entries)
-   return -ENOMEM;
-   }
-
-   if (entry->base.bo)
+   if (entry->base.bo) {
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries =
+   to_amdgpu_bo_vm(entry->base.bo)->entries;
+   else
+   entry->entries = NULL;
return 0;
+   }

r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, );
if (r)
@@ -980,6 +983,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
pt_bo = >bo;
pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
amdgpu_vm_bo_base_init(>base, vm, pt_bo);
+   if (cursor->level < AMDGPU_VM_PTB)
+   entry->entries = pt->entries;
+   else
+   entry->entries = NULL;

r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate);
if (r)
@@ -1009,7 +1016,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt 
*entry)
amdgpu_bo_unref();
amdgpu_bo_unref(>base.bo);
}
-   kvfree(entry->entries);
entry->entries = NULL;
 }

--
2.31.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx