Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread Zhang, Jerry (Junwei)

On 05/11/2018 10:26 AM, zhoucm1 wrote:



On 2018年05月11日 10:19, Zhang, Jerry (Junwei) wrote:

On 05/11/2018 10:11 AM, zhoucm1 wrote:



On 2018年05月11日 09:21, Zhang, Jerry (Junwei) wrote:

On 05/10/2018 10:40 PM, Christian König wrote:

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can we just
remove
and readd the BO to the LRU?

A call to ttm_bo_move_to_lru_tail() after setting the priority should be
sufficient.


Yeah, at that moment, I thought setting a priority for tbo at initialization
is a general way, which may help all associated modules to get out of
potential pain if more priorities are adopted.

Agree.
The most simple way is to move the bo back to expected lru after priority
setting. Going to prepare a patch.

No, there is more simpler way.  see inline...


(in this case, include amd-gfx mail only)

Regards,
Jerry



Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c|  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c|  2 +-
  drivers/gpu/drm/qxl/qxl_object.c|  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c|  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c|  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c|  2 +-
  include/drm/ttm/ttm_bo_api.h|  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device
*adev,
  };
  struct amdgpu_bo *bo;
  unsigned long page_align, size = bp->size;
+uint32_t prio = 0;
  size_t acc_size;
  int r;
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device
*adev,
  bo->tbo.bdev = >mman.bdev;
  amdgpu_ttm_placement_from_domain(bo, bp->domain);
+if (bp->type == ttm_bo_type_kernel)
+prio = 1;

Why not just bo->tbo.priority = 1? In that case, you don't need to add more
parameter to ttm_bo_init_reserved.
In fact, this change is already in my per-vm-lru patch set.


Do you mean specify 1 before ttm_bo_init_reserved()?

ttm_bo_init_reserved() will overwrite it to 0 again inside.

If it can set outside of ttm, you can remove that overwriting. tbo allocation is
from kzalloc.


Yeah, that bases on different coding idea, I think.
1) always to clear the tbo memory before tbo init (mostly, we do so)
2) make sure the key(all) members are initialized as expected always inside init 
function.


anyway, I will sent it out firstly and RFC.

Jerry



Regards,
David Zhou


Jerry



Regards,
David Zhou

  r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, bp->type,
- >placement, page_align, , acc_size,
- NULL, bp->resv, _ttm_bo_destroy);
+ prio, >placement, page_align, ,
+ acc_size, NULL, bp->resv,
+ _ttm_bo_destroy);
  if (unlikely(r != 0))
  return r;
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device
*adev,
  else
  amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
-if (bp->type == ttm_bo_type_kernel)
-bo->tbo.priority = 1;
-
  if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int size, int
align,
 sizeof(struct ast_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, ast_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c
b/drivers/gpu/drm/bochs/bochs_mm.c
index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device *dev, int
size, int align,
 sizeof(struct bochs_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  

Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread zhoucm1



On 2018年05月11日 10:19, Zhang, Jerry (Junwei) wrote:

On 05/11/2018 10:11 AM, zhoucm1 wrote:



On 2018年05月11日 09:21, Zhang, Jerry (Junwei) wrote:

On 05/10/2018 10:40 PM, Christian König wrote:

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can 
we just remove

and readd the BO to the LRU?

A call to ttm_bo_move_to_lru_tail() after setting the priority 
should be

sufficient.


Yeah, at that moment, I thought setting a priority for tbo at 
initialization

is a general way, which may help all associated modules to get out of
potential pain if more priorities are adopted.

Agree.
The most simple way is to move the bo back to expected lru after 
priority

setting. Going to prepare a patch.

No, there is more simpler way.  see inline...


(in this case, include amd-gfx mail only)

Regards,
Jerry



Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c    |  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c    |  2 +-
  drivers/gpu/drm/qxl/qxl_object.c    |  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c    |  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c    |  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c    |  2 +-
  include/drm/ttm/ttm_bo_api.h    |  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device *adev,

  };
  struct amdgpu_bo *bo;
  unsigned long page_align, size = bp->size;
+    uint32_t prio = 0;
  size_t acc_size;
  int r;
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device

*adev,
  bo->tbo.bdev = >mman.bdev;
  amdgpu_ttm_placement_from_domain(bo, bp->domain);
+    if (bp->type == ttm_bo_type_kernel)
+    prio = 1;
Why not just bo->tbo.priority = 1? In that case, you don't need to 
add more

parameter to ttm_bo_init_reserved.
In fact, this change is already in my per-vm-lru patch set.


Do you mean specify 1 before ttm_bo_init_reserved()?

ttm_bo_init_reserved() will overwrite it to 0 again inside.
If it can set outside of ttm, you can remove that overwriting. tbo 
allocation is from kzalloc.


Regards,
David Zhou


Jerry



Regards,
David Zhou
  r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, 
bp->type,

- >placement, page_align, , acc_size,
- NULL, bp->resv, _ttm_bo_destroy);
+ prio, >placement, page_align, ,
+ acc_size, NULL, bp->resv,
+ _ttm_bo_destroy);
  if (unlikely(r != 0))
  return r;
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device *adev,

  else
  amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
-    if (bp->type == ttm_bo_type_kernel)
-    bo->tbo.priority = 1;
-
  if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c 
b/drivers/gpu/drm/ast/ast_ttm.c

index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int 
size, int

align,
 sizeof(struct ast_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
    align >> PAGE_SHIFT, false, acc_size,
    NULL, NULL, ast_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c
b/drivers/gpu/drm/bochs/bochs_mm.c
index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device 
*dev, int

size, int align,
 sizeof(struct bochs_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
    align >> PAGE_SHIFT, false, acc_size,
    NULL, NULL, bochs_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c
b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index 

Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread Zhang, Jerry (Junwei)

On 05/11/2018 10:11 AM, zhoucm1 wrote:



On 2018年05月11日 09:21, Zhang, Jerry (Junwei) wrote:

On 05/10/2018 10:40 PM, Christian König wrote:

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can we just remove
and readd the BO to the LRU?

A call to ttm_bo_move_to_lru_tail() after setting the priority should be
sufficient.


Yeah, at that moment, I thought setting a priority for tbo at initialization
is a general way, which may help all associated modules to get out of
potential pain if more priorities are adopted.

Agree.
The most simple way is to move the bo back to expected lru after priority
setting. Going to prepare a patch.

No, there is more simpler way.  see inline...


(in this case, include amd-gfx mail only)

Regards,
Jerry



Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c|  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c|  2 +-
  drivers/gpu/drm/qxl/qxl_object.c|  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c|  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c|  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c|  2 +-
  include/drm/ttm/ttm_bo_api.h|  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  };
  struct amdgpu_bo *bo;
  unsigned long page_align, size = bp->size;
+uint32_t prio = 0;
  size_t acc_size;
  int r;
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device
*adev,
  bo->tbo.bdev = >mman.bdev;
  amdgpu_ttm_placement_from_domain(bo, bp->domain);
+if (bp->type == ttm_bo_type_kernel)
+prio = 1;

Why not just bo->tbo.priority = 1? In that case, you don't need to add more
parameter to ttm_bo_init_reserved.
In fact, this change is already in my per-vm-lru patch set.


Do you mean specify 1 before ttm_bo_init_reserved()?

ttm_bo_init_reserved() will overwrite it to 0 again inside.

Jerry



Regards,
David Zhou

  r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, bp->type,
- >placement, page_align, , acc_size,
- NULL, bp->resv, _ttm_bo_destroy);
+ prio, >placement, page_align, ,
+ acc_size, NULL, bp->resv,
+ _ttm_bo_destroy);
  if (unlikely(r != 0))
  return r;
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  else
  amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
-if (bp->type == ttm_bo_type_kernel)
-bo->tbo.priority = 1;
-
  if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int size, int
align,
 sizeof(struct ast_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, ast_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c
b/drivers/gpu/drm/bochs/bochs_mm.c
index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device *dev, int
size, int align,
 sizeof(struct bochs_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, bochs_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c
b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index f219532..c1d85f8 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -327,7 +327,7 @@ int cirrus_bo_create(struct drm_device *dev, int size, int
align,
   

Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread zhoucm1



On 2018年05月11日 09:21, Zhang, Jerry (Junwei) wrote:

On 05/10/2018 10:40 PM, Christian König wrote:

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can we 
just remove

and readd the BO to the LRU?

A call to ttm_bo_move_to_lru_tail() after setting the priority should be
sufficient.


Yeah, at that moment, I thought setting a priority for tbo at 
initialization is a general way, which may help all associated modules 
to get out of potential pain if more priorities are adopted.


Agree.
The most simple way is to move the bo back to expected lru after 
priority setting. Going to prepare a patch.

No, there is more simpler way.  see inline...


(in this case, include amd-gfx mail only)

Regards,
Jerry



Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c    |  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c    |  2 +-
  drivers/gpu/drm/qxl/qxl_object.c    |  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c    |  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c    |  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c    |  2 +-
  include/drm/ttm/ttm_bo_api.h    |  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device *adev,

  };
  struct amdgpu_bo *bo;
  unsigned long page_align, size = bp->size;
+    uint32_t prio = 0;
  size_t acc_size;
  int r;
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device *adev,

  bo->tbo.bdev = >mman.bdev;
  amdgpu_ttm_placement_from_domain(bo, bp->domain);
+    if (bp->type == ttm_bo_type_kernel)
+    prio = 1;
Why not just bo->tbo.priority = 1? In that case, you don't need to add 
more parameter to ttm_bo_init_reserved.

In fact, this change is already in my per-vm-lru patch set.

Regards,
David Zhou
  r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, 
bp->type,

- >placement, page_align, , acc_size,
- NULL, bp->resv, _ttm_bo_destroy);
+ prio, >placement, page_align, ,
+ acc_size, NULL, bp->resv,
+ _ttm_bo_destroy);
  if (unlikely(r != 0))
  return r;
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct 
amdgpu_device *adev,

  else
  amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
-    if (bp->type == ttm_bo_type_kernel)
-    bo->tbo.priority = 1;
-
  if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c 
b/drivers/gpu/drm/ast/ast_ttm.c

index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int 
size, int

align,
 sizeof(struct ast_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
    align >> PAGE_SHIFT, false, acc_size,
    NULL, NULL, ast_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c 
b/drivers/gpu/drm/bochs/bochs_mm.c

index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device 
*dev, int

size, int align,
 sizeof(struct bochs_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
    align >> PAGE_SHIFT, false, acc_size,
    NULL, NULL, bochs_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c
b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index f219532..c1d85f8 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -327,7 +327,7 @@ int cirrus_bo_create(struct drm_device *dev, int 
size, int

align,
 sizeof(struct cirrus_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  

Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread Zhang, Jerry (Junwei)

On 05/10/2018 10:40 PM, Christian König wrote:

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can we just remove
and readd the BO to the LRU?

A call to ttm_bo_move_to_lru_tail() after setting the priority should be
sufficient.


Yeah, at that moment, I thought setting a priority for tbo at initialization is 
a general way, which may help all associated modules to get out of potential 
pain if more priorities are adopted.


Agree.
The most simple way is to move the bo back to expected lru after priority 
setting. Going to prepare a patch.

(in this case, include amd-gfx mail only)

Regards,
Jerry



Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c|  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c|  2 +-
  drivers/gpu/drm/qxl/qxl_object.c|  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c|  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c|  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c|  2 +-
  include/drm/ttm/ttm_bo_api.h|  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  };
  struct amdgpu_bo *bo;
  unsigned long page_align, size = bp->size;
+uint32_t prio = 0;
  size_t acc_size;
  int r;
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  bo->tbo.bdev = >mman.bdev;
  amdgpu_ttm_placement_from_domain(bo, bp->domain);
+if (bp->type == ttm_bo_type_kernel)
+prio = 1;
  r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, bp->type,
- >placement, page_align, , acc_size,
- NULL, bp->resv, _ttm_bo_destroy);
+ prio, >placement, page_align, ,
+ acc_size, NULL, bp->resv,
+ _ttm_bo_destroy);
  if (unlikely(r != 0))
  return r;
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  else
  amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
-if (bp->type == ttm_bo_type_kernel)
-bo->tbo.priority = 1;
-
  if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int size, int
align,
 sizeof(struct ast_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, ast_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device *dev, int
size, int align,
 sizeof(struct bochs_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, bochs_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c
b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index f219532..c1d85f8 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -327,7 +327,7 @@ int cirrus_bo_create(struct drm_device *dev, int size, int
align,
 sizeof(struct cirrus_bo));
  ret = ttm_bo_init(>ttm.bdev, >bo, size,
-  ttm_bo_type_device, >placement,
+  ttm_bo_type_device, 0, >placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, cirrus_bo_ttm_destroy);
  if (ret)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 4871025..8c24731 100644
--- 

Re: [PATCH] drm/ttm: specify bo priority when initializing ttm bo

2018-05-10 Thread Christian König

Am 10.05.2018 um 07:01 schrieb Junwei Zhang:

Expect to add an evitable bo who has reservation object
to the correct lru[bo->priority] list


Nice catch, but since this affects only a very small use case can we 
just remove and readd the BO to the LRU?


A call to ttm_bo_move_to_lru_tail() after setting the priority should be 
sufficient.


Thanks,
Christian.



Signed-off-by: Junwei Zhang 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  | 11 ++-
  drivers/gpu/drm/ast/ast_ttm.c   |  2 +-
  drivers/gpu/drm/bochs/bochs_mm.c|  2 +-
  drivers/gpu/drm/cirrus/cirrus_ttm.c |  2 +-
  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |  2 +-
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  2 +-
  drivers/gpu/drm/nouveau/nouveau_bo.c|  2 +-
  drivers/gpu/drm/qxl/qxl_object.c|  2 +-
  drivers/gpu/drm/radeon/radeon_object.c  |  2 +-
  drivers/gpu/drm/ttm/ttm_bo.c|  8 +---
  drivers/gpu/drm/virtio/virtgpu_object.c |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c|  2 +-
  drivers/staging/vboxvideo/vbox_ttm.c|  2 +-
  include/drm/ttm/ttm_bo_api.h|  5 -
  14 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e62153a..9a25ecb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -360,6 +360,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
};
struct amdgpu_bo *bo;
unsigned long page_align, size = bp->size;
+   uint32_t prio = 0;
size_t acc_size;
int r;
  
@@ -419,10 +420,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  
  	bo->tbo.bdev = >mman.bdev;

amdgpu_ttm_placement_from_domain(bo, bp->domain);
+   if (bp->type == ttm_bo_type_kernel)
+   prio = 1;
  
  	r = ttm_bo_init_reserved(>mman.bdev, >tbo, size, bp->type,

->placement, page_align, , acc_size,
-NULL, bp->resv, _ttm_bo_destroy);
+prio, >placement, page_align, ,
+acc_size, NULL, bp->resv,
+_ttm_bo_destroy);
if (unlikely(r != 0))
return r;
  
@@ -434,9 +438,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,

else
amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
  
-	if (bp->type == ttm_bo_type_kernel)

-   bo->tbo.priority = 1;
-
if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
struct dma_fence *fence;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index fe354eb..aabb96a 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -320,7 +320,7 @@ int ast_bo_create(struct drm_device *dev, int size, int 
align,
   sizeof(struct ast_bo));
  
  	ret = ttm_bo_init(>ttm.bdev, >bo, size,

- ttm_bo_type_device, >placement,
+ ttm_bo_type_device, 0, >placement,
  align >> PAGE_SHIFT, false, acc_size,
  NULL, NULL, ast_bo_ttm_destroy);
if (ret)
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 39cd084..9693109 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -366,7 +366,7 @@ static int bochs_bo_create(struct drm_device *dev, int 
size, int align,
   sizeof(struct bochs_bo));
  
  	ret = ttm_bo_init(>ttm.bdev, >bo, size,

- ttm_bo_type_device, >placement,
+ ttm_bo_type_device, 0, >placement,
  align >> PAGE_SHIFT, false, acc_size,
  NULL, NULL, bochs_bo_ttm_destroy);
if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c 
b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index f219532..c1d85f8 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -327,7 +327,7 @@ int cirrus_bo_create(struct drm_device *dev, int size, int 
align,
   sizeof(struct cirrus_bo));
  
  	ret = ttm_bo_init(>ttm.bdev, >bo, size,

- ttm_bo_type_device, >placement,
+ ttm_bo_type_device, 0, >placement,
  align >> PAGE_SHIFT, false, acc_size,
  NULL, NULL, cirrus_bo_ttm_destroy);
if (ret)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 4871025..8c24731 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
@@ -315,7