All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/9] drm/amdgpu: fix total size calculation
@ 2018-07-30 14:51 Christian König
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

long might only be 32bit in size and we can easily use more than 4GB
here.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 944868e47119..6728448167ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -105,9 +105,9 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
 	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
 
 	unsigned last_entry = 0, first_userptr = num_entries;
+	uint64_t total_size = 0;
 	unsigned i;
 	int r;
-	unsigned long total_size = 0;
 
 	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
 	if (!array)
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/9] drm/amdgpu: return error if both BOs and bo_list handle is given
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-2-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 3/9] drm/amdgpu: add new amdgpu_vm_bo_trace_cs() function v2 Christian König
                     ` (7 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Return -EINVAL when both the BOs as well as a list handle is provided in
the IOCTL.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 8a49c3b97bd4..d41cea78e4aa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -572,14 +572,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	INIT_LIST_HEAD(&p->validated);
 
 	/* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */
-	if (p->bo_list) {
-		mutex_lock(&p->bo_list->lock);
+	if (cs->in.bo_list_handle) {
+		if (p->bo_list)
+			return -EINVAL;
 
-	} else if (cs->in.bo_list_handle) {
 		r = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle,
 				       &p->bo_list);
 		if (r)
 			return r;
+
+	} else if (p->bo_list) {
+		mutex_lock(&p->bo_list->lock);
 	}
 
 	if (p->bo_list) {
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 3/9] drm/amdgpu: add new amdgpu_vm_bo_trace_cs() function v2
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 2/9] drm/amdgpu: return error if both BOs and bo_list handle is given Christian König
@ 2018-07-30 14:51   ` Christian König
  2018-07-30 14:51   ` [PATCH 4/9] drm/amdgpu: move bo_list defines to amdgpu_bo_list.h Christian König
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This allows us to trace all VM ranges which should be valid inside a CS.

v2: dump mappings without BO as well

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chunming  Zhou <david1.zhou@amd.com> (v1)
Reviewed-and-tested-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> (v1)
Reviewed-by: Huang Rui <ray.huang@amd.com> (v1)
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c    |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    | 29 +++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h    |  1 +
 4 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index d41cea78e4aa..0295666968da 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1223,6 +1223,7 @@ static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
 static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 			    union drm_amdgpu_cs *cs)
 {
+	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
 	struct amdgpu_ring *ring = p->ring;
 	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
 	enum drm_sched_priority priority;
@@ -1275,6 +1276,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	amdgpu_job_free_resources(job);
 
 	trace_amdgpu_cs_ioctl(job);
+	amdgpu_vm_bo_trace_cs(&fpriv->vm, &p->ticket);
 	priority = job->base.s_priority;
 	drm_sched_entity_push_job(&job->base, entity);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
index 11f262f15200..7206a0025b17 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
@@ -314,6 +314,11 @@ DEFINE_EVENT(amdgpu_vm_mapping, amdgpu_vm_bo_mapping,
 	    TP_ARGS(mapping)
 );
 
+DEFINE_EVENT(amdgpu_vm_mapping, amdgpu_vm_bo_cs,
+	    TP_PROTO(struct amdgpu_bo_va_mapping *mapping),
+	    TP_ARGS(mapping)
+);
+
 TRACE_EVENT(amdgpu_vm_set_ptes,
 	    TP_PROTO(uint64_t pe, uint64_t addr, unsigned count,
 		     uint32_t incr, uint64_t flags),
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 5d7d7900ccab..015613b4f98b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2343,6 +2343,35 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
 	return amdgpu_vm_it_iter_first(&vm->va, addr, addr);
 }
 
+/**
+ * amdgpu_vm_bo_trace_cs - trace all reserved mappings
+ *
+ * @vm: the requested vm
+ * @ticket: CS ticket
+ *
+ * Trace all mappings of BOs reserved during a command submission.
+ */
+void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket)
+{
+	struct amdgpu_bo_va_mapping *mapping;
+
+	if (!trace_amdgpu_vm_bo_cs_enabled())
+		return;
+
+	for (mapping = amdgpu_vm_it_iter_first(&vm->va, 0, U64_MAX); mapping;
+	     mapping = amdgpu_vm_it_iter_next(mapping, 0, U64_MAX)) {
+		if (mapping->bo_va && mapping->bo_va->base.bo) {
+			struct amdgpu_bo *bo;
+
+			bo = mapping->bo_va->base.bo;
+			if (READ_ONCE(bo->tbo.resv->lock.ctx) != ticket)
+				continue;
+		}
+
+		trace_amdgpu_vm_bo_cs(mapping);
+	}
+}
+
 /**
  * amdgpu_vm_bo_rmv - remove a bo to a specific vm
  *
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index d416f895233d..67a15d439ac0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -318,6 +318,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
 				uint64_t saddr, uint64_t size);
 struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
 							 uint64_t addr);
+void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
 void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 		      struct amdgpu_bo_va *bo_va);
 void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 4/9] drm/amdgpu: move bo_list defines to amdgpu_bo_list.h
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 2/9] drm/amdgpu: return error if both BOs and bo_list handle is given Christian König
  2018-07-30 14:51   ` [PATCH 3/9] drm/amdgpu: add new amdgpu_vm_bo_trace_cs() function v2 Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 5/9] drm/amdgpu: always recreate bo_list Christian König
                     ` (5 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Further demangle amdgpu.h

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h         | 40 +----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 70 +++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 39 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 4cd20e722d70..95af917007f7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -74,6 +74,7 @@
 #include "amdgpu_gart.h"
 #include "amdgpu_debugfs.h"
 #include "amdgpu_job.h"
+#include "amdgpu_bo_list.h"
 
 /*
  * Modules parameters.
@@ -689,45 +690,6 @@ struct amdgpu_fpriv {
 	struct amdgpu_ctx_mgr	ctx_mgr;
 };
 
-/*
- * residency list
- */
-struct amdgpu_bo_list_entry {
-	struct amdgpu_bo		*robj;
-	struct ttm_validate_buffer	tv;
-	struct amdgpu_bo_va		*bo_va;
-	uint32_t			priority;
-	struct page			**user_pages;
-	int				user_invalidated;
-};
-
-struct amdgpu_bo_list {
-	struct mutex lock;
-	struct rcu_head rhead;
-	struct kref refcount;
-	struct amdgpu_bo *gds_obj;
-	struct amdgpu_bo *gws_obj;
-	struct amdgpu_bo *oa_obj;
-	unsigned first_userptr;
-	unsigned num_entries;
-	struct amdgpu_bo_list_entry *array;
-};
-
-int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
-		       struct amdgpu_bo_list **result);
-void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
-			     struct list_head *validated);
-void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
-void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
-int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
-				      struct drm_amdgpu_bo_list_entry **info_param);
-
-int amdgpu_bo_list_create(struct amdgpu_device *adev,
-				 struct drm_file *filp,
-				 struct drm_amdgpu_bo_list_entry *info,
-				 unsigned num_entries,
-				 struct amdgpu_bo_list **list);
-
 /*
  * GFX stuff
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
new file mode 100644
index 000000000000..833f846bfdad
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef __AMDGPU_BO_LIST_H__
+#define __AMDGPU_BO_LIST_H__
+
+#include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/amdgpu_drm.h>
+
+struct amdgpu_device;
+struct amdgpu_bo;
+struct amdgpu_bo_va;
+struct amdgpu_fpriv;
+
+struct amdgpu_bo_list_entry {
+	struct amdgpu_bo		*robj;
+	struct ttm_validate_buffer	tv;
+	struct amdgpu_bo_va		*bo_va;
+	uint32_t			priority;
+	struct page			**user_pages;
+	int				user_invalidated;
+};
+
+struct amdgpu_bo_list {
+	struct mutex lock;
+	struct rcu_head rhead;
+	struct kref refcount;
+	struct amdgpu_bo *gds_obj;
+	struct amdgpu_bo *gws_obj;
+	struct amdgpu_bo *oa_obj;
+	unsigned first_userptr;
+	unsigned num_entries;
+	struct amdgpu_bo_list_entry *array;
+};
+
+int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
+		       struct amdgpu_bo_list **result);
+void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
+			     struct list_head *validated);
+void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
+void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
+int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
+				      struct drm_amdgpu_bo_list_entry **info_param);
+
+int amdgpu_bo_list_create(struct amdgpu_device *adev,
+				 struct drm_file *filp,
+				 struct drm_amdgpu_bo_list_entry *info,
+				 unsigned num_entries,
+				 struct amdgpu_bo_list **list);
+
+#endif
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 5/9] drm/amdgpu: always recreate bo_list
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (2 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 4/9] drm/amdgpu: move bo_list defines to amdgpu_bo_list.h Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-5-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 6/9] drm/amdgpu: nuke amdgpu_bo_list_free Christian König
                     ` (4 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

When changing a list always completely recreate it. This avoids locking
in the hot path because the list always stays like it is until it is
unreferenced.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 23 ++++++++++++-----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      |  3 ---
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 6728448167ba..556040e45931 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -50,7 +50,6 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
 	for (i = 0; i < list->num_entries; ++i)
 		amdgpu_bo_unref(&list->array[i].robj);
 
-	mutex_destroy(&list->lock);
 	kvfree(list->array);
 	kfree_rcu(list, rhead);
 }
@@ -70,7 +69,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
 		return -ENOMEM;
 
 	/* initialize bo list*/
-	mutex_init(&list->lock);
 	kref_init(&list->refcount);
 	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
 	if (r) {
@@ -188,7 +186,6 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
 
 	if (*result && kref_get_unless_zero(&(*result)->refcount)) {
 		rcu_read_unlock();
-		mutex_lock(&(*result)->lock);
 		return 0;
 	}
 
@@ -231,7 +228,6 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
 
 void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
 {
-	mutex_unlock(&list->lock);
 	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
 }
 
@@ -242,7 +238,6 @@ void amdgpu_bo_list_free(struct amdgpu_bo_list *list)
 	for (i = 0; i < list->num_entries; ++i)
 		amdgpu_bo_unref(&list->array[i].robj);
 
-	mutex_destroy(&list->lock);
 	kvfree(list->array);
 	kfree(list);
 }
@@ -297,7 +292,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 	union drm_amdgpu_bo_list *args = data;
 	uint32_t handle = args->in.list_handle;
 	struct drm_amdgpu_bo_list_entry *info = NULL;
-	struct amdgpu_bo_list *list;
+	struct amdgpu_bo_list *list, *old;
 	int r;
 
 	r = amdgpu_bo_create_list_entry_array(&args->in, &info);
@@ -328,16 +323,22 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 		break;
 
 	case AMDGPU_BO_LIST_OP_UPDATE:
-		r = amdgpu_bo_list_get(fpriv, handle, &list);
+		r = amdgpu_bo_list_create(adev, filp, info, args->in.bo_number,
+					  &list);
 		if (r)
 			goto error_free;
 
-		r = amdgpu_bo_list_set(adev, filp, list, info,
-					      args->in.bo_number);
-		amdgpu_bo_list_put(list);
-		if (r)
+		mutex_lock(&fpriv->bo_list_lock);
+		old = idr_replace(&fpriv->bo_list_handles, list, handle);
+		mutex_unlock(&fpriv->bo_list_lock);
+
+		if (IS_ERR(old)) {
+			amdgpu_bo_list_put(list);
+			r = PTR_ERR(old);
 			goto error_free;
+		}
 
+		amdgpu_bo_list_put(old);
 		break;
 
 	default:
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
index 833f846bfdad..89195fdcb1ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -41,7 +41,6 @@ struct amdgpu_bo_list_entry {
 };
 
 struct amdgpu_bo_list {
-	struct mutex lock;
 	struct rcu_head rhead;
 	struct kref refcount;
 	struct amdgpu_bo *gds_obj;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 0295666968da..f7154f3ed807 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -580,9 +580,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 				       &p->bo_list);
 		if (r)
 			return r;
-
-	} else if (p->bo_list) {
-		mutex_lock(&p->bo_list->lock);
 	}
 
 	if (p->bo_list) {
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 6/9] drm/amdgpu: nuke amdgpu_bo_list_free
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (3 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 5/9] drm/amdgpu: always recreate bo_list Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-6-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 7/9] drm/amdgpu: add bo_list iterators Christian König
                     ` (3 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

The RCU grace period is harmless and avoiding it is not worth the effort
of doubling the implementation.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 13 +------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |  2 +-
 3 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 556040e45931..5335f1b5459f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -231,17 +231,6 @@ void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
 	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
 }
 
-void amdgpu_bo_list_free(struct amdgpu_bo_list *list)
-{
-	unsigned i;
-
-	for (i = 0; i < list->num_entries; ++i)
-		amdgpu_bo_unref(&list->array[i].robj);
-
-	kvfree(list->array);
-	kfree(list);
-}
-
 int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
 				      struct drm_amdgpu_bo_list_entry **info_param)
 {
@@ -310,7 +299,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
 		r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
 		mutex_unlock(&fpriv->bo_list_lock);
 		if (r < 0) {
-			amdgpu_bo_list_free(list);
+			amdgpu_bo_list_put(list);
 			return r;
 		}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
index 89195fdcb1ef..0ce540203db1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -56,7 +56,6 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
 void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
 			     struct list_head *validated);
 void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
-void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
 int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
 				      struct drm_amdgpu_bo_list_entry **info_param);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 7956848ac092..5b26e0447221 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -967,7 +967,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	amdgpu_bo_unref(&pd);
 
 	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
-		amdgpu_bo_list_free(list);
+		amdgpu_bo_list_put(list);
 
 	idr_destroy(&fpriv->bo_list_handles);
 	mutex_destroy(&fpriv->bo_list_lock);
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 7/9] drm/amdgpu: add bo_list iterators
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (4 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 6/9] drm/amdgpu: nuke amdgpu_bo_list_free Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-7-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list Christian König
                     ` (2 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Add helpers to iterate over all entries in a bo_list.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 21 ++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 10 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      | 51 +++++++++++++----------------
 3 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 5335f1b5459f..096bcf4a6334 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -43,12 +43,12 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
 
 static void amdgpu_bo_list_release_rcu(struct kref *ref)
 {
-	unsigned i;
 	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
 						   refcount);
+	struct amdgpu_bo_list_entry *e;
 
-	for (i = 0; i < list->num_entries; ++i)
-		amdgpu_bo_unref(&list->array[i].robj);
+	amdgpu_bo_list_for_each_entry(e, list)
+		amdgpu_bo_unref(&e->robj);
 
 	kvfree(list->array);
 	kfree_rcu(list, rhead);
@@ -103,6 +103,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
 	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
 
 	unsigned last_entry = 0, first_userptr = num_entries;
+	struct amdgpu_bo_list_entry *e;
 	uint64_t total_size = 0;
 	unsigned i;
 	int r;
@@ -156,7 +157,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
 		trace_amdgpu_bo_list_set(list, entry->robj);
 	}
 
-	for (i = 0; i < list->num_entries; ++i)
+	amdgpu_bo_list_for_each_entry(e, list)
 		amdgpu_bo_unref(&list->array[i].robj);
 
 	kvfree(list->array);
@@ -201,6 +202,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
 	 * concatenated in descending order.
 	 */
 	struct list_head bucket[AMDGPU_BO_LIST_NUM_BUCKETS];
+	struct amdgpu_bo_list_entry *e;
 	unsigned i;
 
 	for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
@@ -211,14 +213,13 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
 	 * in the list, the sort mustn't change the ordering of buffers
 	 * with the same priority, i.e. it must be stable.
 	 */
-	for (i = 0; i < list->num_entries; i++) {
-		unsigned priority = list->array[i].priority;
+	amdgpu_bo_list_for_each_entry(e, list) {
+		unsigned priority = e->priority;
 
-		if (!list->array[i].robj->parent)
-			list_add_tail(&list->array[i].tv.head,
-				      &bucket[priority]);
+		if (!e->robj->parent)
+			list_add_tail(&e->tv.head, &bucket[priority]);
 
-		list->array[i].user_pages = NULL;
+		e->user_pages = NULL;
 	}
 
 	/* Connect the sorted buckets in the output list. */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
index 0ce540203db1..3d77abfcd4a6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -65,4 +65,14 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
 				 unsigned num_entries,
 				 struct amdgpu_bo_list **list);
 
+#define amdgpu_bo_list_for_each_entry(e, list) \
+	for (e = &(list)->array[0]; \
+	     e != &(list)->array[(list)->num_entries]; \
+	     ++e)
+
+#define amdgpu_bo_list_for_each_userptr_entry(e, list) \
+	for (e = &(list)->array[(list)->first_userptr]; \
+	     e != &(list)->array[(list)->num_entries]; \
+	     ++e)
+
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index f7154f3ed807..1d7292ab2b62 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -563,10 +563,10 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
 	struct amdgpu_bo_list_entry *e;
 	struct list_head duplicates;
-	unsigned i, tries = 10;
 	struct amdgpu_bo *gds;
 	struct amdgpu_bo *gws;
 	struct amdgpu_bo *oa;
+	unsigned tries = 10;
 	int r;
 
 	INIT_LIST_HEAD(&p->validated);
@@ -596,7 +596,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 
 	while (1) {
 		struct list_head need_pages;
-		unsigned i;
 
 		r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
 					   &duplicates);
@@ -611,12 +610,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 			break;
 
 		INIT_LIST_HEAD(&need_pages);
-		for (i = p->bo_list->first_userptr;
-		     i < p->bo_list->num_entries; ++i) {
-			struct amdgpu_bo *bo;
-
-			e = &p->bo_list->array[i];
-			bo = e->robj;
+		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+			struct amdgpu_bo *bo = e->robj;
 
 			if (amdgpu_ttm_tt_userptr_invalidated(bo->tbo.ttm,
 				 &e->user_invalidated) && e->user_pages) {
@@ -710,16 +705,14 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 
 	if (p->bo_list) {
 		struct amdgpu_vm *vm = &fpriv->vm;
-		unsigned i;
+		struct amdgpu_bo_list_entry *e;
 
 		gds = p->bo_list->gds_obj;
 		gws = p->bo_list->gws_obj;
 		oa = p->bo_list->oa_obj;
-		for (i = 0; i < p->bo_list->num_entries; i++) {
-			struct amdgpu_bo *bo = p->bo_list->array[i].robj;
 
-			p->bo_list->array[i].bo_va = amdgpu_vm_bo_find(vm, bo);
-		}
+		amdgpu_bo_list_for_each_entry(e, p->bo_list)
+			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
 	} else {
 		gds = p->adev->gds.gds_gfx_bo;
 		gws = p->adev->gds.gws_gfx_bo;
@@ -753,10 +746,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 error_free_pages:
 
 	if (p->bo_list) {
-		for (i = p->bo_list->first_userptr;
-		     i < p->bo_list->num_entries; ++i) {
-			e = &p->bo_list->array[i];
-
+		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
 			if (!e->user_pages)
 				continue;
 
@@ -830,7 +820,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	struct amdgpu_vm *vm = &fpriv->vm;
 	struct amdgpu_bo_va *bo_va;
 	struct amdgpu_bo *bo;
-	int i, r;
+	int r;
 
 	r = amdgpu_vm_clear_freed(adev, vm, NULL);
 	if (r)
@@ -861,15 +851,17 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	}
 
 	if (p->bo_list) {
-		for (i = 0; i < p->bo_list->num_entries; i++) {
+		struct amdgpu_bo_list_entry *e;
+
+		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
 			struct dma_fence *f;
 
 			/* ignore duplicates */
-			bo = p->bo_list->array[i].robj;
+			bo = e->robj;
 			if (!bo)
 				continue;
 
-			bo_va = p->bo_list->array[i].bo_va;
+			bo_va = e->bo_va;
 			if (bo_va == NULL)
 				continue;
 
@@ -898,14 +890,15 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 		return r;
 
 	if (amdgpu_vm_debug && p->bo_list) {
+		struct amdgpu_bo_list_entry *e;
+
 		/* Invalidate all BOs to test for userspace bugs */
-		for (i = 0; i < p->bo_list->num_entries; i++) {
+		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
 			/* ignore duplicates */
-			bo = p->bo_list->array[i].robj;
-			if (!bo)
+			if (!e->robj)
 				continue;
 
-			amdgpu_vm_bo_invalidate(adev, bo, false);
+			amdgpu_vm_bo_invalidate(adev, e->robj, false);
 		}
 	}
 
@@ -1225,16 +1218,16 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
 	enum drm_sched_priority priority;
 	struct amdgpu_job *job;
-	unsigned i;
 	uint64_t seq;
 
 	int r;
 
 	amdgpu_mn_lock(p->mn);
 	if (p->bo_list) {
-		for (i = p->bo_list->first_userptr;
-		     i < p->bo_list->num_entries; ++i) {
-			struct amdgpu_bo *bo = p->bo_list->array[i].robj;
+		struct amdgpu_bo_list_entry *e;
+
+		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+			struct amdgpu_bo *bo = e->robj;
 
 			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
 				amdgpu_mn_unlock(p->mn);
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (5 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 7/9] drm/amdgpu: add bo_list iterators Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-8-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-30 14:51   ` [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided Christian König
  2018-07-31  2:34   ` [PATCH 1/9] drm/amdgpu: fix total size calculation Huang Rui
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This avoids multiple allocations for the head and the array.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 114 +++++++++++-----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  17 +++--
 2 files changed, 57 insertions(+), 74 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 096bcf4a6334..d472a2c8399f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -35,13 +35,15 @@
 #define AMDGPU_BO_LIST_MAX_PRIORITY	32u
 #define AMDGPU_BO_LIST_NUM_BUCKETS	(AMDGPU_BO_LIST_MAX_PRIORITY + 1)
 
-static int amdgpu_bo_list_set(struct amdgpu_device *adev,
-				     struct drm_file *filp,
-				     struct amdgpu_bo_list *list,
-				     struct drm_amdgpu_bo_list_entry *info,
-				     unsigned num_entries);
+static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
+{
+	struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
+						   rhead);
+
+	kvfree(list);
+}
 
-static void amdgpu_bo_list_release_rcu(struct kref *ref)
+static void amdgpu_bo_list_free(struct kref *ref)
 {
 	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
 						   refcount);
@@ -50,67 +52,36 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
 	amdgpu_bo_list_for_each_entry(e, list)
 		amdgpu_bo_unref(&e->robj);
 
-	kvfree(list->array);
-	kfree_rcu(list, rhead);
+	call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
 }
 
-int amdgpu_bo_list_create(struct amdgpu_device *adev,
-				 struct drm_file *filp,
-				 struct drm_amdgpu_bo_list_entry *info,
-				 unsigned num_entries,
-				 struct amdgpu_bo_list **list_out)
+int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
+			  struct drm_amdgpu_bo_list_entry *info,
+			  unsigned num_entries, struct amdgpu_bo_list **result)
 {
+	unsigned last_entry = 0, first_userptr = num_entries;
+	struct amdgpu_bo_list_entry *array;
 	struct amdgpu_bo_list *list;
+	uint64_t total_size = 0;
+	size_t size;
+	unsigned i;
 	int r;
 
+	if (num_entries > SIZE_MAX / sizeof(struct amdgpu_bo_list_entry))
+		return -EINVAL;
 
-	list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
+	size = sizeof(struct amdgpu_bo_list);
+	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
+	list = kvmalloc(size, GFP_KERNEL);
 	if (!list)
 		return -ENOMEM;
 
-	/* initialize bo list*/
 	kref_init(&list->refcount);
-	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
-	if (r) {
-		kfree(list);
-		return r;
-	}
-
-	*list_out = list;
-	return 0;
-}
-
-static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
-{
-	struct amdgpu_bo_list *list;
-
-	mutex_lock(&fpriv->bo_list_lock);
-	list = idr_remove(&fpriv->bo_list_handles, id);
-	mutex_unlock(&fpriv->bo_list_lock);
-	if (list)
-		kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
-}
-
-static int amdgpu_bo_list_set(struct amdgpu_device *adev,
-				     struct drm_file *filp,
-				     struct amdgpu_bo_list *list,
-				     struct drm_amdgpu_bo_list_entry *info,
-				     unsigned num_entries)
-{
-	struct amdgpu_bo_list_entry *array;
-	struct amdgpu_bo *gds_obj = adev->gds.gds_gfx_bo;
-	struct amdgpu_bo *gws_obj = adev->gds.gws_gfx_bo;
-	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
-
-	unsigned last_entry = 0, first_userptr = num_entries;
-	struct amdgpu_bo_list_entry *e;
-	uint64_t total_size = 0;
-	unsigned i;
-	int r;
+	list->gds_obj = adev->gds.gds_gfx_bo;
+	list->gws_obj = adev->gds.gws_gfx_bo;
+	list->oa_obj = adev->gds.oa_gfx_bo;
 
-	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
-	if (!array)
-		return -ENOMEM;
+	array = amdgpu_bo_list_array_entry(list, 0);
 	memset(array, 0, num_entries * sizeof(struct amdgpu_bo_list_entry));
 
 	for (i = 0; i < num_entries; ++i) {
@@ -147,36 +118,41 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
 		entry->tv.shared = !entry->robj->prime_shared_count;
 
 		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
-			gds_obj = entry->robj;
+			list->gds_obj = entry->robj;
 		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GWS)
-			gws_obj = entry->robj;
+			list->gws_obj = entry->robj;
 		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_OA)
-			oa_obj = entry->robj;
+			list->oa_obj = entry->robj;
 
 		total_size += amdgpu_bo_size(entry->robj);
 		trace_amdgpu_bo_list_set(list, entry->robj);
 	}
 
-	amdgpu_bo_list_for_each_entry(e, list)
-		amdgpu_bo_unref(&list->array[i].robj);
-
-	kvfree(list->array);
-
-	list->gds_obj = gds_obj;
-	list->gws_obj = gws_obj;
-	list->oa_obj = oa_obj;
 	list->first_userptr = first_userptr;
-	list->array = array;
 	list->num_entries = num_entries;
 
 	trace_amdgpu_cs_bo_status(list->num_entries, total_size);
+
+	*result = list;
 	return 0;
 
 error_free:
 	while (i--)
 		amdgpu_bo_unref(&array[i].robj);
-	kvfree(array);
+	kvfree(list);
 	return r;
+
+}
+
+static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
+{
+	struct amdgpu_bo_list *list;
+
+	mutex_lock(&fpriv->bo_list_lock);
+	list = idr_remove(&fpriv->bo_list_handles, id);
+	mutex_unlock(&fpriv->bo_list_lock);
+	if (list)
+		kref_put(&list->refcount, amdgpu_bo_list_free);
 }
 
 int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
@@ -229,7 +205,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
 
 void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
 {
-	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
+	kref_put(&list->refcount, amdgpu_bo_list_free);
 }
 
 int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
index 3d77abfcd4a6..61b089768e1c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -48,7 +48,6 @@ struct amdgpu_bo_list {
 	struct amdgpu_bo *oa_obj;
 	unsigned first_userptr;
 	unsigned num_entries;
-	struct amdgpu_bo_list_entry *array;
 };
 
 int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
@@ -65,14 +64,22 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
 				 unsigned num_entries,
 				 struct amdgpu_bo_list **list);
 
+static inline struct amdgpu_bo_list_entry *
+amdgpu_bo_list_array_entry(struct amdgpu_bo_list *list, unsigned index)
+{
+	struct amdgpu_bo_list_entry *array = (void *)&list[1];
+
+	return &array[index];
+}
+
 #define amdgpu_bo_list_for_each_entry(e, list) \
-	for (e = &(list)->array[0]; \
-	     e != &(list)->array[(list)->num_entries]; \
+	for (e = amdgpu_bo_list_array_entry(list, 0); \
+	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
 	     ++e)
 
 #define amdgpu_bo_list_for_each_userptr_entry(e, list) \
-	for (e = &(list)->array[(list)->first_userptr]; \
-	     e != &(list)->array[(list)->num_entries]; \
+	for (e = amdgpu_bo_list_array_entry(list, (list)->first_userptr); \
+	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
 	     ++e)
 
 #endif
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (6 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list Christian König
@ 2018-07-30 14:51   ` Christian König
       [not found]     ` <20180730145159.13212-9-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-31  2:34   ` [PATCH 1/9] drm/amdgpu: fix total size calculation Huang Rui
  8 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-30 14:51 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Instead of having extra handling just create an empty bo_list when no
handle is provided.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
 1 file changed, 46 insertions(+), 65 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 1d7292ab2b62..502b94fb116a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 				union drm_amdgpu_cs *cs)
 {
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+	struct amdgpu_vm *vm = &fpriv->vm;
 	struct amdgpu_bo_list_entry *e;
 	struct list_head duplicates;
 	struct amdgpu_bo *gds;
@@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 				       &p->bo_list);
 		if (r)
 			return r;
+	} else if (!p->bo_list) {
+		/* Create a empty bo_list when no handle is provided */
+		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
+					  &p->bo_list);
+		if (r)
+			return r;
 	}
 
-	if (p->bo_list) {
-		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
-		if (p->bo_list->first_userptr != p->bo_list->num_entries)
-			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
-	}
+	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
+	if (p->bo_list->first_userptr != p->bo_list->num_entries)
+		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
 
 	INIT_LIST_HEAD(&duplicates);
 	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
@@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 			goto error_free_pages;
 		}
 
-		/* Without a BO list we don't have userptr BOs */
-		if (!p->bo_list)
-			break;
-
 		INIT_LIST_HEAD(&need_pages);
 		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
 			struct amdgpu_bo *bo = e->robj;
@@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
 				     p->bytes_moved_vis);
 
-	if (p->bo_list) {
-		struct amdgpu_vm *vm = &fpriv->vm;
-		struct amdgpu_bo_list_entry *e;
+	gds = p->bo_list->gds_obj;
+	gws = p->bo_list->gws_obj;
+	oa = p->bo_list->oa_obj;
 
-		gds = p->bo_list->gds_obj;
-		gws = p->bo_list->gws_obj;
-		oa = p->bo_list->oa_obj;
-
-		amdgpu_bo_list_for_each_entry(e, p->bo_list)
-			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
-	} else {
-		gds = p->adev->gds.gds_gfx_bo;
-		gws = p->adev->gds.gws_gfx_bo;
-		oa = p->adev->gds.oa_gfx_bo;
-	}
+	amdgpu_bo_list_for_each_entry(e, p->bo_list)
+		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
 
 	if (gds) {
 		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
@@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 
 error_free_pages:
 
-	if (p->bo_list) {
-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
-			if (!e->user_pages)
-				continue;
+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+		if (!e->user_pages)
+			continue;
 
-			release_pages(e->user_pages,
-				      e->robj->tbo.ttm->num_pages);
-			kvfree(e->user_pages);
-		}
+		release_pages(e->user_pages,
+			      e->robj->tbo.ttm->num_pages);
+		kvfree(e->user_pages);
 	}
 
 	return r;
@@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 
 static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 {
-	struct amdgpu_device *adev = p->adev;
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+	struct amdgpu_device *adev = p->adev;
 	struct amdgpu_vm *vm = &fpriv->vm;
+	struct amdgpu_bo_list_entry *e;
 	struct amdgpu_bo_va *bo_va;
 	struct amdgpu_bo *bo;
 	int r;
@@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 			return r;
 	}
 
-	if (p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
-
-		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
-			struct dma_fence *f;
-
-			/* ignore duplicates */
-			bo = e->robj;
-			if (!bo)
-				continue;
+	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
+		struct dma_fence *f;
 
-			bo_va = e->bo_va;
-			if (bo_va == NULL)
-				continue;
+		/* ignore duplicates */
+		bo = e->robj;
+		if (!bo)
+			continue;
 
-			r = amdgpu_vm_bo_update(adev, bo_va, false);
-			if (r)
-				return r;
+		bo_va = e->bo_va;
+		if (bo_va == NULL)
+			continue;
 
-			f = bo_va->last_pt_update;
-			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
-			if (r)
-				return r;
-		}
+		r = amdgpu_vm_bo_update(adev, bo_va, false);
+		if (r)
+			return r;
 
+		f = bo_va->last_pt_update;
+		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
+		if (r)
+			return r;
 	}
 
 	r = amdgpu_vm_handle_moved(adev, vm);
@@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	if (r)
 		return r;
 
-	if (amdgpu_vm_debug && p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
-
+	if (amdgpu_vm_debug) {
 		/* Invalidate all BOs to test for userspace bugs */
 		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
 			/* ignore duplicates */
@@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	struct amdgpu_ring *ring = p->ring;
 	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
 	enum drm_sched_priority priority;
+	struct amdgpu_bo_list_entry *e;
 	struct amdgpu_job *job;
 	uint64_t seq;
 
 	int r;
 
 	amdgpu_mn_lock(p->mn);
-	if (p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+		struct amdgpu_bo *bo = e->robj;
 
-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
-			struct amdgpu_bo *bo = e->robj;
-
-			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
-				amdgpu_mn_unlock(p->mn);
-				return -ERESTARTSYS;
-			}
+		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
+			amdgpu_mn_unlock(p->mn);
+			return -ERESTARTSYS;
 		}
 	}
 
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* RE: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found]     ` <20180730145159.13212-9-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  1:31       ` Zhou, David(ChunMing)
  2018-07-31  7:51       ` Huang Rui
  1 sibling, 0 replies; 26+ messages in thread
From: Zhou, David(ChunMing) @ 2018-07-31  1:31 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Series is Reviewed-by: Chunming  Zhou <david1.zhou@amd.com>

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Christian K?nig
Sent: Monday, July 30, 2018 10:52 PM
To: amd-gfx@lists.freedesktop.org
Subject: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided

Instead of having extra handling just create an empty bo_list when no handle is provided.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
 1 file changed, 46 insertions(+), 65 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 1d7292ab2b62..502b94fb116a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 				union drm_amdgpu_cs *cs)
 {
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+	struct amdgpu_vm *vm = &fpriv->vm;
 	struct amdgpu_bo_list_entry *e;
 	struct list_head duplicates;
 	struct amdgpu_bo *gds;
@@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 				       &p->bo_list);
 		if (r)
 			return r;
+	} else if (!p->bo_list) {
+		/* Create a empty bo_list when no handle is provided */
+		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
+					  &p->bo_list);
+		if (r)
+			return r;
 	}
 
-	if (p->bo_list) {
-		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
-		if (p->bo_list->first_userptr != p->bo_list->num_entries)
-			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
-	}
+	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
+	if (p->bo_list->first_userptr != p->bo_list->num_entries)
+		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
 
 	INIT_LIST_HEAD(&duplicates);
 	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd); @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 			goto error_free_pages;
 		}
 
-		/* Without a BO list we don't have userptr BOs */
-		if (!p->bo_list)
-			break;
-
 		INIT_LIST_HEAD(&need_pages);
 		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
 			struct amdgpu_bo *bo = e->robj;
@@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
 				     p->bytes_moved_vis);
 
-	if (p->bo_list) {
-		struct amdgpu_vm *vm = &fpriv->vm;
-		struct amdgpu_bo_list_entry *e;
+	gds = p->bo_list->gds_obj;
+	gws = p->bo_list->gws_obj;
+	oa = p->bo_list->oa_obj;
 
-		gds = p->bo_list->gds_obj;
-		gws = p->bo_list->gws_obj;
-		oa = p->bo_list->oa_obj;
-
-		amdgpu_bo_list_for_each_entry(e, p->bo_list)
-			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
-	} else {
-		gds = p->adev->gds.gds_gfx_bo;
-		gws = p->adev->gds.gws_gfx_bo;
-		oa = p->adev->gds.oa_gfx_bo;
-	}
+	amdgpu_bo_list_for_each_entry(e, p->bo_list)
+		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
 
 	if (gds) {
 		p->job->gds_base = amdgpu_bo_gpu_offset(gds); @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 
 error_free_pages:
 
-	if (p->bo_list) {
-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
-			if (!e->user_pages)
-				continue;
+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+		if (!e->user_pages)
+			continue;
 
-			release_pages(e->user_pages,
-				      e->robj->tbo.ttm->num_pages);
-			kvfree(e->user_pages);
-		}
+		release_pages(e->user_pages,
+			      e->robj->tbo.ttm->num_pages);
+		kvfree(e->user_pages);
 	}
 
 	return r;
@@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 
 static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)  {
-	struct amdgpu_device *adev = p->adev;
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+	struct amdgpu_device *adev = p->adev;
 	struct amdgpu_vm *vm = &fpriv->vm;
+	struct amdgpu_bo_list_entry *e;
 	struct amdgpu_bo_va *bo_va;
 	struct amdgpu_bo *bo;
 	int r;
@@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 			return r;
 	}
 
-	if (p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
-
-		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
-			struct dma_fence *f;
-
-			/* ignore duplicates */
-			bo = e->robj;
-			if (!bo)
-				continue;
+	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
+		struct dma_fence *f;
 
-			bo_va = e->bo_va;
-			if (bo_va == NULL)
-				continue;
+		/* ignore duplicates */
+		bo = e->robj;
+		if (!bo)
+			continue;
 
-			r = amdgpu_vm_bo_update(adev, bo_va, false);
-			if (r)
-				return r;
+		bo_va = e->bo_va;
+		if (bo_va == NULL)
+			continue;
 
-			f = bo_va->last_pt_update;
-			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
-			if (r)
-				return r;
-		}
+		r = amdgpu_vm_bo_update(adev, bo_va, false);
+		if (r)
+			return r;
 
+		f = bo_va->last_pt_update;
+		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
+		if (r)
+			return r;
 	}
 
 	r = amdgpu_vm_handle_moved(adev, vm);
@@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
 	if (r)
 		return r;
 
-	if (amdgpu_vm_debug && p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
-
+	if (amdgpu_vm_debug) {
 		/* Invalidate all BOs to test for userspace bugs */
 		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
 			/* ignore duplicates */
@@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	struct amdgpu_ring *ring = p->ring;
 	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
 	enum drm_sched_priority priority;
+	struct amdgpu_bo_list_entry *e;
 	struct amdgpu_job *job;
 	uint64_t seq;
 
 	int r;
 
 	amdgpu_mn_lock(p->mn);
-	if (p->bo_list) {
-		struct amdgpu_bo_list_entry *e;
+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
+		struct amdgpu_bo *bo = e->robj;
 
-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
-			struct amdgpu_bo *bo = e->robj;
-
-			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
-				amdgpu_mn_unlock(p->mn);
-				return -ERESTARTSYS;
-			}
+		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
+			amdgpu_mn_unlock(p->mn);
+			return -ERESTARTSYS;
 		}
 	}
 
--
2.14.1

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/9] drm/amdgpu: fix total size calculation
       [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
                     ` (7 preceding siblings ...)
  2018-07-30 14:51   ` [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided Christian König
@ 2018-07-31  2:34   ` Huang Rui
  8 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  2:34 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:51PM +0200, Christian König wrote:
> long might only be 32bit in size and we can easily use more than 4GB
> here.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Acked-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 944868e47119..6728448167ba 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -105,9 +105,9 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>  	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
>  
>  	unsigned last_entry = 0, first_userptr = num_entries;
> +	uint64_t total_size = 0;
>  	unsigned i;
>  	int r;
> -	unsigned long total_size = 0;
>  
>  	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
>  	if (!array)
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 2/9] drm/amdgpu: return error if both BOs and bo_list handle is given
       [not found]     ` <20180730145159.13212-2-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  2:44       ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  2:44 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:52PM +0200, Christian König wrote:
> Return -EINVAL when both the BOs as well as a list handle is provided in
> the IOCTL.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 8a49c3b97bd4..d41cea78e4aa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -572,14 +572,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  	INIT_LIST_HEAD(&p->validated);
>  
>  	/* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */
> -	if (p->bo_list) {
> -		mutex_lock(&p->bo_list->lock);
> +	if (cs->in.bo_list_handle) {
> +		if (p->bo_list)
> +			return -EINVAL;
>  
> -	} else if (cs->in.bo_list_handle) {
>  		r = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle,
>  				       &p->bo_list);
>  		if (r)
>  			return r;
> +
> +	} else if (p->bo_list) {
> +		mutex_lock(&p->bo_list->lock);
>  	}
>  
>  	if (p->bo_list) {
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 4/9] drm/amdgpu: move bo_list defines to amdgpu_bo_list.h
       [not found]     ` <20180730145159.13212-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  2:52       ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  2:52 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:54PM +0200, Christian König wrote:
> Further demangle amdgpu.h

I also found amdgpu.h is mingled with many things. Moving them to
sub-header is necessary.

Acked-by: Huang Rui <ray.huang@amd.com>

> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h         | 40 +----------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 70 +++++++++++++++++++++++++++++
>  2 files changed, 71 insertions(+), 39 deletions(-)
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 4cd20e722d70..95af917007f7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -74,6 +74,7 @@
>  #include "amdgpu_gart.h"
>  #include "amdgpu_debugfs.h"
>  #include "amdgpu_job.h"
> +#include "amdgpu_bo_list.h"
>  
>  /*
>   * Modules parameters.
> @@ -689,45 +690,6 @@ struct amdgpu_fpriv {
>  	struct amdgpu_ctx_mgr	ctx_mgr;
>  };
>  
> -/*
> - * residency list
> - */
> -struct amdgpu_bo_list_entry {
> -	struct amdgpu_bo		*robj;
> -	struct ttm_validate_buffer	tv;
> -	struct amdgpu_bo_va		*bo_va;
> -	uint32_t			priority;
> -	struct page			**user_pages;
> -	int				user_invalidated;
> -};
> -
> -struct amdgpu_bo_list {
> -	struct mutex lock;
> -	struct rcu_head rhead;
> -	struct kref refcount;
> -	struct amdgpu_bo *gds_obj;
> -	struct amdgpu_bo *gws_obj;
> -	struct amdgpu_bo *oa_obj;
> -	unsigned first_userptr;
> -	unsigned num_entries;
> -	struct amdgpu_bo_list_entry *array;
> -};
> -
> -int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> -		       struct amdgpu_bo_list **result);
> -void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
> -			     struct list_head *validated);
> -void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
> -void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
> -int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
> -				      struct drm_amdgpu_bo_list_entry **info_param);
> -
> -int amdgpu_bo_list_create(struct amdgpu_device *adev,
> -				 struct drm_file *filp,
> -				 struct drm_amdgpu_bo_list_entry *info,
> -				 unsigned num_entries,
> -				 struct amdgpu_bo_list **list);
> -
>  /*
>   * GFX stuff
>   */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> new file mode 100644
> index 000000000000..833f846bfdad
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -0,0 +1,70 @@
> +/*
> + * Copyright 2018 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +#ifndef __AMDGPU_BO_LIST_H__
> +#define __AMDGPU_BO_LIST_H__
> +
> +#include <drm/ttm/ttm_execbuf_util.h>
> +#include <drm/amdgpu_drm.h>
> +
> +struct amdgpu_device;
> +struct amdgpu_bo;
> +struct amdgpu_bo_va;
> +struct amdgpu_fpriv;
> +
> +struct amdgpu_bo_list_entry {
> +	struct amdgpu_bo		*robj;
> +	struct ttm_validate_buffer	tv;
> +	struct amdgpu_bo_va		*bo_va;
> +	uint32_t			priority;
> +	struct page			**user_pages;
> +	int				user_invalidated;
> +};
> +
> +struct amdgpu_bo_list {
> +	struct mutex lock;
> +	struct rcu_head rhead;
> +	struct kref refcount;
> +	struct amdgpu_bo *gds_obj;
> +	struct amdgpu_bo *gws_obj;
> +	struct amdgpu_bo *oa_obj;
> +	unsigned first_userptr;
> +	unsigned num_entries;
> +	struct amdgpu_bo_list_entry *array;
> +};
> +
> +int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> +		       struct amdgpu_bo_list **result);
> +void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
> +			     struct list_head *validated);
> +void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
> +void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
> +int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
> +				      struct drm_amdgpu_bo_list_entry **info_param);
> +
> +int amdgpu_bo_list_create(struct amdgpu_device *adev,
> +				 struct drm_file *filp,
> +				 struct drm_amdgpu_bo_list_entry *info,
> +				 unsigned num_entries,
> +				 struct amdgpu_bo_list **list);
> +
> +#endif
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/9] drm/amdgpu: always recreate bo_list
       [not found]     ` <20180730145159.13212-5-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  5:29       ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  5:29 UTC (permalink / raw)
  To: Christian K�nig; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:55PM +0200, Christian König wrote:
> When changing a list always completely recreate it. This avoids locking
> in the hot path because the list always stays like it is until it is
> unreferenced.

The fpriv->bo_list_handles is allocated by OP_CREATE, so here we just
re-create bo list and replace the handles in OP_UPDATE. Then we don't need
locking to protect amdgpu_bo_list because it always be re-created.

Acked-by: Huang Rui <ray.huang@amd.com>

> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 23 ++++++++++++-----------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  1 -
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      |  3 ---
>  3 files changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 6728448167ba..556040e45931 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -50,7 +50,6 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
>  	for (i = 0; i < list->num_entries; ++i)
>  		amdgpu_bo_unref(&list->array[i].robj);
>  
> -	mutex_destroy(&list->lock);
>  	kvfree(list->array);
>  	kfree_rcu(list, rhead);
>  }
> @@ -70,7 +69,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
>  		return -ENOMEM;
>  
>  	/* initialize bo list*/
> -	mutex_init(&list->lock);
>  	kref_init(&list->refcount);
>  	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
>  	if (r) {
> @@ -188,7 +186,6 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
>  
>  	if (*result && kref_get_unless_zero(&(*result)->refcount)) {
>  		rcu_read_unlock();
> -		mutex_lock(&(*result)->lock);
>  		return 0;
>  	}
>  
> @@ -231,7 +228,6 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>  
>  void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
>  {
> -	mutex_unlock(&list->lock);
>  	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
>  }
>  
> @@ -242,7 +238,6 @@ void amdgpu_bo_list_free(struct amdgpu_bo_list *list)
>  	for (i = 0; i < list->num_entries; ++i)
>  		amdgpu_bo_unref(&list->array[i].robj);
>  
> -	mutex_destroy(&list->lock);
>  	kvfree(list->array);
>  	kfree(list);
>  }
> @@ -297,7 +292,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
>  	union drm_amdgpu_bo_list *args = data;
>  	uint32_t handle = args->in.list_handle;
>  	struct drm_amdgpu_bo_list_entry *info = NULL;
> -	struct amdgpu_bo_list *list;
> +	struct amdgpu_bo_list *list, *old;
>  	int r;
>  
>  	r = amdgpu_bo_create_list_entry_array(&args->in, &info);
> @@ -328,16 +323,22 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
>  		break;
>  
>  	case AMDGPU_BO_LIST_OP_UPDATE:
> -		r = amdgpu_bo_list_get(fpriv, handle, &list);
> +		r = amdgpu_bo_list_create(adev, filp, info, args->in.bo_number,
> +					  &list);
>  		if (r)
>  			goto error_free;
>  
> -		r = amdgpu_bo_list_set(adev, filp, list, info,
> -					      args->in.bo_number);
> -		amdgpu_bo_list_put(list);
> -		if (r)
> +		mutex_lock(&fpriv->bo_list_lock);
> +		old = idr_replace(&fpriv->bo_list_handles, list, handle);
> +		mutex_unlock(&fpriv->bo_list_lock);
> +
> +		if (IS_ERR(old)) {
> +			amdgpu_bo_list_put(list);
> +			r = PTR_ERR(old);
>  			goto error_free;
> +		}
>  
> +		amdgpu_bo_list_put(old);
>  		break;
>  
>  	default:
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 833f846bfdad..89195fdcb1ef 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -41,7 +41,6 @@ struct amdgpu_bo_list_entry {
>  };
>  
>  struct amdgpu_bo_list {
> -	struct mutex lock;
>  	struct rcu_head rhead;
>  	struct kref refcount;
>  	struct amdgpu_bo *gds_obj;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 0295666968da..f7154f3ed807 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -580,9 +580,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  				       &p->bo_list);
>  		if (r)
>  			return r;
> -
> -	} else if (p->bo_list) {
> -		mutex_lock(&p->bo_list->lock);
>  	}
>  
>  	if (p->bo_list) {
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 6/9] drm/amdgpu: nuke amdgpu_bo_list_free
       [not found]     ` <20180730145159.13212-6-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  5:31       ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  5:31 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:56PM +0200, Christian König wrote:
> The RCU grace period is harmless and avoiding it is not worth the effort
> of doubling the implementation.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 13 +------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  1 -
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c     |  2 +-
>  3 files changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 556040e45931..5335f1b5459f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -231,17 +231,6 @@ void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
>  	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
>  }
>  
> -void amdgpu_bo_list_free(struct amdgpu_bo_list *list)
> -{
> -	unsigned i;
> -
> -	for (i = 0; i < list->num_entries; ++i)
> -		amdgpu_bo_unref(&list->array[i].robj);
> -
> -	kvfree(list->array);
> -	kfree(list);
> -}
> -
>  int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
>  				      struct drm_amdgpu_bo_list_entry **info_param)
>  {
> @@ -310,7 +299,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
>  		r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
>  		mutex_unlock(&fpriv->bo_list_lock);
>  		if (r < 0) {
> -			amdgpu_bo_list_free(list);
> +			amdgpu_bo_list_put(list);
>  			return r;
>  		}
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 89195fdcb1ef..0ce540203db1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -56,7 +56,6 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
>  void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>  			     struct list_head *validated);
>  void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
> -void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
>  int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
>  				      struct drm_amdgpu_bo_list_entry **info_param);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 7956848ac092..5b26e0447221 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -967,7 +967,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
>  	amdgpu_bo_unref(&pd);
>  
>  	idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
> -		amdgpu_bo_list_free(list);
> +		amdgpu_bo_list_put(list);
>  
>  	idr_destroy(&fpriv->bo_list_handles);
>  	mutex_destroy(&fpriv->bo_list_lock);
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/9] drm/amdgpu: add bo_list iterators
       [not found]     ` <20180730145159.13212-7-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  6:12       ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31  6:12 UTC (permalink / raw)
  To: Christian K�nig; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:57PM +0200, Christian König wrote:
> Add helpers to iterate over all entries in a bo_list.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Nice wrapper.

Acked-by: Huang Rui <ray.huang@amd.com>

Thanks,
Ray

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 21 ++++++------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 10 ++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      | 51 +++++++++++++----------------
>  3 files changed, 43 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 5335f1b5459f..096bcf4a6334 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -43,12 +43,12 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>  
>  static void amdgpu_bo_list_release_rcu(struct kref *ref)
>  {
> -	unsigned i;
>  	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
>  						   refcount);
> +	struct amdgpu_bo_list_entry *e;
>  
> -	for (i = 0; i < list->num_entries; ++i)
> -		amdgpu_bo_unref(&list->array[i].robj);
> +	amdgpu_bo_list_for_each_entry(e, list)
> +		amdgpu_bo_unref(&e->robj);
>  
>  	kvfree(list->array);
>  	kfree_rcu(list, rhead);
> @@ -103,6 +103,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>  	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
>  
>  	unsigned last_entry = 0, first_userptr = num_entries;
> +	struct amdgpu_bo_list_entry *e;
>  	uint64_t total_size = 0;
>  	unsigned i;
>  	int r;
> @@ -156,7 +157,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>  		trace_amdgpu_bo_list_set(list, entry->robj);
>  	}
>  
> -	for (i = 0; i < list->num_entries; ++i)
> +	amdgpu_bo_list_for_each_entry(e, list)
>  		amdgpu_bo_unref(&list->array[i].robj);
>  
>  	kvfree(list->array);
> @@ -201,6 +202,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>  	 * concatenated in descending order.
>  	 */
>  	struct list_head bucket[AMDGPU_BO_LIST_NUM_BUCKETS];
> +	struct amdgpu_bo_list_entry *e;
>  	unsigned i;
>  
>  	for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
> @@ -211,14 +213,13 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>  	 * in the list, the sort mustn't change the ordering of buffers
>  	 * with the same priority, i.e. it must be stable.
>  	 */
> -	for (i = 0; i < list->num_entries; i++) {
> -		unsigned priority = list->array[i].priority;
> +	amdgpu_bo_list_for_each_entry(e, list) {
> +		unsigned priority = e->priority;
>  
> -		if (!list->array[i].robj->parent)
> -			list_add_tail(&list->array[i].tv.head,
> -				      &bucket[priority]);
> +		if (!e->robj->parent)
> +			list_add_tail(&e->tv.head, &bucket[priority]);
>  
> -		list->array[i].user_pages = NULL;
> +		e->user_pages = NULL;
>  	}
>  
>  	/* Connect the sorted buckets in the output list. */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 0ce540203db1..3d77abfcd4a6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -65,4 +65,14 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
>  				 unsigned num_entries,
>  				 struct amdgpu_bo_list **list);
>  
> +#define amdgpu_bo_list_for_each_entry(e, list) \
> +	for (e = &(list)->array[0]; \
> +	     e != &(list)->array[(list)->num_entries]; \
> +	     ++e)
> +
> +#define amdgpu_bo_list_for_each_userptr_entry(e, list) \
> +	for (e = &(list)->array[(list)->first_userptr]; \
> +	     e != &(list)->array[(list)->num_entries]; \
> +	     ++e)
> +
>  #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index f7154f3ed807..1d7292ab2b62 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -563,10 +563,10 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>  	struct amdgpu_bo_list_entry *e;
>  	struct list_head duplicates;
> -	unsigned i, tries = 10;
>  	struct amdgpu_bo *gds;
>  	struct amdgpu_bo *gws;
>  	struct amdgpu_bo *oa;
> +	unsigned tries = 10;
>  	int r;
>  
>  	INIT_LIST_HEAD(&p->validated);
> @@ -596,7 +596,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  
>  	while (1) {
>  		struct list_head need_pages;
> -		unsigned i;
>  
>  		r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
>  					   &duplicates);
> @@ -611,12 +610,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  			break;
>  
>  		INIT_LIST_HEAD(&need_pages);
> -		for (i = p->bo_list->first_userptr;
> -		     i < p->bo_list->num_entries; ++i) {
> -			struct amdgpu_bo *bo;
> -
> -			e = &p->bo_list->array[i];
> -			bo = e->robj;
> +		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> +			struct amdgpu_bo *bo = e->robj;
>  
>  			if (amdgpu_ttm_tt_userptr_invalidated(bo->tbo.ttm,
>  				 &e->user_invalidated) && e->user_pages) {
> @@ -710,16 +705,14 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  
>  	if (p->bo_list) {
>  		struct amdgpu_vm *vm = &fpriv->vm;
> -		unsigned i;
> +		struct amdgpu_bo_list_entry *e;
>  
>  		gds = p->bo_list->gds_obj;
>  		gws = p->bo_list->gws_obj;
>  		oa = p->bo_list->oa_obj;
> -		for (i = 0; i < p->bo_list->num_entries; i++) {
> -			struct amdgpu_bo *bo = p->bo_list->array[i].robj;
>  
> -			p->bo_list->array[i].bo_va = amdgpu_vm_bo_find(vm, bo);
> -		}
> +		amdgpu_bo_list_for_each_entry(e, p->bo_list)
> +			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>  	} else {
>  		gds = p->adev->gds.gds_gfx_bo;
>  		gws = p->adev->gds.gws_gfx_bo;
> @@ -753,10 +746,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  error_free_pages:
>  
>  	if (p->bo_list) {
> -		for (i = p->bo_list->first_userptr;
> -		     i < p->bo_list->num_entries; ++i) {
> -			e = &p->bo_list->array[i];
> -
> +		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>  			if (!e->user_pages)
>  				continue;
>  
> @@ -830,7 +820,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  	struct amdgpu_vm *vm = &fpriv->vm;
>  	struct amdgpu_bo_va *bo_va;
>  	struct amdgpu_bo *bo;
> -	int i, r;
> +	int r;
>  
>  	r = amdgpu_vm_clear_freed(adev, vm, NULL);
>  	if (r)
> @@ -861,15 +851,17 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  	}
>  
>  	if (p->bo_list) {
> -		for (i = 0; i < p->bo_list->num_entries; i++) {
> +		struct amdgpu_bo_list_entry *e;
> +
> +		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>  			struct dma_fence *f;
>  
>  			/* ignore duplicates */
> -			bo = p->bo_list->array[i].robj;
> +			bo = e->robj;
>  			if (!bo)
>  				continue;
>  
> -			bo_va = p->bo_list->array[i].bo_va;
> +			bo_va = e->bo_va;
>  			if (bo_va == NULL)
>  				continue;
>  
> @@ -898,14 +890,15 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  		return r;
>  
>  	if (amdgpu_vm_debug && p->bo_list) {
> +		struct amdgpu_bo_list_entry *e;
> +
>  		/* Invalidate all BOs to test for userspace bugs */
> -		for (i = 0; i < p->bo_list->num_entries; i++) {
> +		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>  			/* ignore duplicates */
> -			bo = p->bo_list->array[i].robj;
> -			if (!bo)
> +			if (!e->robj)
>  				continue;
>  
> -			amdgpu_vm_bo_invalidate(adev, bo, false);
> +			amdgpu_vm_bo_invalidate(adev, e->robj, false);
>  		}
>  	}
>  
> @@ -1225,16 +1218,16 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>  	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>  	enum drm_sched_priority priority;
>  	struct amdgpu_job *job;
> -	unsigned i;
>  	uint64_t seq;
>  
>  	int r;
>  
>  	amdgpu_mn_lock(p->mn);
>  	if (p->bo_list) {
> -		for (i = p->bo_list->first_userptr;
> -		     i < p->bo_list->num_entries; ++i) {
> -			struct amdgpu_bo *bo = p->bo_list->array[i].robj;
> +		struct amdgpu_bo_list_entry *e;
> +
> +		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> +			struct amdgpu_bo *bo = e->robj;
>  
>  			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>  				amdgpu_mn_unlock(p->mn);
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list
  2018-07-31  7:12       ` Huang Rui
@ 2018-07-31  7:04         ` Christian König
       [not found]           ` <79923ec6-25d0-f80a-d631-79a1faa91a0e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-31  7:04 UTC (permalink / raw)
  To: Huang Rui; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 31.07.2018 um 09:12 schrieb Huang Rui:
> On Mon, Jul 30, 2018 at 04:51:58PM +0200, Christian König wrote:
>> This avoids multiple allocations for the head and the array.
>>
> I am afraid I don't get the point that how to avoid multiple times of
> allocations. Could you please explain more?

Allocating the head and the array separately has more overhead because 
you need to do two allocations.

I should probably update the commit message,
Christian.

>
> Thanks,
> Ray
>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 114 +++++++++++-----------------
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  17 +++--
>>   2 files changed, 57 insertions(+), 74 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>> index 096bcf4a6334..d472a2c8399f 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>> @@ -35,13 +35,15 @@
>>   #define AMDGPU_BO_LIST_MAX_PRIORITY	32u
>>   #define AMDGPU_BO_LIST_NUM_BUCKETS	(AMDGPU_BO_LIST_MAX_PRIORITY + 1)
>>   
>> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>> -				     struct drm_file *filp,
>> -				     struct amdgpu_bo_list *list,
>> -				     struct drm_amdgpu_bo_list_entry *info,
>> -				     unsigned num_entries);
>> +static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
>> +{
>> +	struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
>> +						   rhead);
>> +
>> +	kvfree(list);
>> +}
>>   
>> -static void amdgpu_bo_list_release_rcu(struct kref *ref)
>> +static void amdgpu_bo_list_free(struct kref *ref)
>>   {
>>   	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
>>   						   refcount);
>> @@ -50,67 +52,36 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
>>   	amdgpu_bo_list_for_each_entry(e, list)
>>   		amdgpu_bo_unref(&e->robj);
>>   
>> -	kvfree(list->array);
>> -	kfree_rcu(list, rhead);
>> +	call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
>>   }
>>   
>> -int amdgpu_bo_list_create(struct amdgpu_device *adev,
>> -				 struct drm_file *filp,
>> -				 struct drm_amdgpu_bo_list_entry *info,
>> -				 unsigned num_entries,
>> -				 struct amdgpu_bo_list **list_out)
>> +int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
>> +			  struct drm_amdgpu_bo_list_entry *info,
>> +			  unsigned num_entries, struct amdgpu_bo_list **result)
>>   {
>> +	unsigned last_entry = 0, first_userptr = num_entries;
>> +	struct amdgpu_bo_list_entry *array;
>>   	struct amdgpu_bo_list *list;
>> +	uint64_t total_size = 0;
>> +	size_t size;
>> +	unsigned i;
>>   	int r;
>>   
>> +	if (num_entries > SIZE_MAX / sizeof(struct amdgpu_bo_list_entry))
>> +		return -EINVAL;
>>   
>> -	list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
>> +	size = sizeof(struct amdgpu_bo_list);
>> +	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
>> +	list = kvmalloc(size, GFP_KERNEL);
>>   	if (!list)
>>   		return -ENOMEM;
>>   
>> -	/* initialize bo list*/
>>   	kref_init(&list->refcount);
>> -	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
>> -	if (r) {
>> -		kfree(list);
>> -		return r;
>> -	}
>> -
>> -	*list_out = list;
>> -	return 0;
>> -}
>> -
>> -static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
>> -{
>> -	struct amdgpu_bo_list *list;
>> -
>> -	mutex_lock(&fpriv->bo_list_lock);
>> -	list = idr_remove(&fpriv->bo_list_handles, id);
>> -	mutex_unlock(&fpriv->bo_list_lock);
>> -	if (list)
>> -		kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
>> -}
>> -
>> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>> -				     struct drm_file *filp,
>> -				     struct amdgpu_bo_list *list,
>> -				     struct drm_amdgpu_bo_list_entry *info,
>> -				     unsigned num_entries)
>> -{
>> -	struct amdgpu_bo_list_entry *array;
>> -	struct amdgpu_bo *gds_obj = adev->gds.gds_gfx_bo;
>> -	struct amdgpu_bo *gws_obj = adev->gds.gws_gfx_bo;
>> -	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
>> -
>> -	unsigned last_entry = 0, first_userptr = num_entries;
>> -	struct amdgpu_bo_list_entry *e;
>> -	uint64_t total_size = 0;
>> -	unsigned i;
>> -	int r;
>> +	list->gds_obj = adev->gds.gds_gfx_bo;
>> +	list->gws_obj = adev->gds.gws_gfx_bo;
>> +	list->oa_obj = adev->gds.oa_gfx_bo;
>>   
>> -	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
>> -	if (!array)
>> -		return -ENOMEM;
>> +	array = amdgpu_bo_list_array_entry(list, 0);
>>   	memset(array, 0, num_entries * sizeof(struct amdgpu_bo_list_entry));
>>   
>>   	for (i = 0; i < num_entries; ++i) {
>> @@ -147,36 +118,41 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>>   		entry->tv.shared = !entry->robj->prime_shared_count;
>>   
>>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
>> -			gds_obj = entry->robj;
>> +			list->gds_obj = entry->robj;
>>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GWS)
>> -			gws_obj = entry->robj;
>> +			list->gws_obj = entry->robj;
>>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_OA)
>> -			oa_obj = entry->robj;
>> +			list->oa_obj = entry->robj;
>>   
>>   		total_size += amdgpu_bo_size(entry->robj);
>>   		trace_amdgpu_bo_list_set(list, entry->robj);
>>   	}
>>   
>> -	amdgpu_bo_list_for_each_entry(e, list)
>> -		amdgpu_bo_unref(&list->array[i].robj);
>> -
>> -	kvfree(list->array);
>> -
>> -	list->gds_obj = gds_obj;
>> -	list->gws_obj = gws_obj;
>> -	list->oa_obj = oa_obj;
>>   	list->first_userptr = first_userptr;
>> -	list->array = array;
>>   	list->num_entries = num_entries;
>>   
>>   	trace_amdgpu_cs_bo_status(list->num_entries, total_size);
>> +
>> +	*result = list;
>>   	return 0;
>>   
>>   error_free:
>>   	while (i--)
>>   		amdgpu_bo_unref(&array[i].robj);
>> -	kvfree(array);
>> +	kvfree(list);
>>   	return r;
>> +
>> +}
>> +
>> +static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
>> +{
>> +	struct amdgpu_bo_list *list;
>> +
>> +	mutex_lock(&fpriv->bo_list_lock);
>> +	list = idr_remove(&fpriv->bo_list_handles, id);
>> +	mutex_unlock(&fpriv->bo_list_lock);
>> +	if (list)
>> +		kref_put(&list->refcount, amdgpu_bo_list_free);
>>   }
>>   
>>   int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
>> @@ -229,7 +205,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>>   
>>   void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
>>   {
>> -	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
>> +	kref_put(&list->refcount, amdgpu_bo_list_free);
>>   }
>>   
>>   int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
>> index 3d77abfcd4a6..61b089768e1c 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
>> @@ -48,7 +48,6 @@ struct amdgpu_bo_list {
>>   	struct amdgpu_bo *oa_obj;
>>   	unsigned first_userptr;
>>   	unsigned num_entries;
>> -	struct amdgpu_bo_list_entry *array;
>>   };
>>   
>>   int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
>> @@ -65,14 +64,22 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
>>   				 unsigned num_entries,
>>   				 struct amdgpu_bo_list **list);
>>   
>> +static inline struct amdgpu_bo_list_entry *
>> +amdgpu_bo_list_array_entry(struct amdgpu_bo_list *list, unsigned index)
>> +{
>> +	struct amdgpu_bo_list_entry *array = (void *)&list[1];
>> +
>> +	return &array[index];
>> +}
>> +
>>   #define amdgpu_bo_list_for_each_entry(e, list) \
>> -	for (e = &(list)->array[0]; \
>> -	     e != &(list)->array[(list)->num_entries]; \
>> +	for (e = amdgpu_bo_list_array_entry(list, 0); \
>> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
>>   	     ++e)
>>   
>>   #define amdgpu_bo_list_for_each_userptr_entry(e, list) \
>> -	for (e = &(list)->array[(list)->first_userptr]; \
>> -	     e != &(list)->array[(list)->num_entries]; \
>> +	for (e = amdgpu_bo_list_array_entry(list, (list)->first_userptr); \
>> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
>>   	     ++e)
>>   
>>   #endif
>> -- 
>> 2.14.1
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list
       [not found]     ` <20180730145159.13212-8-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  7:12       ` Huang Rui
  2018-07-31  7:04         ` Christian König
  0 siblings, 1 reply; 26+ messages in thread
From: Huang Rui @ 2018-07-31  7:12 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:58PM +0200, Christian König wrote:
> This avoids multiple allocations for the head and the array.
> 

I am afraid I don't get the point that how to avoid multiple times of
allocations. Could you please explain more?

Thanks,
Ray

> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 114 +++++++++++-----------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  17 +++--
>  2 files changed, 57 insertions(+), 74 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 096bcf4a6334..d472a2c8399f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -35,13 +35,15 @@
>  #define AMDGPU_BO_LIST_MAX_PRIORITY	32u
>  #define AMDGPU_BO_LIST_NUM_BUCKETS	(AMDGPU_BO_LIST_MAX_PRIORITY + 1)
>  
> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
> -				     struct drm_file *filp,
> -				     struct amdgpu_bo_list *list,
> -				     struct drm_amdgpu_bo_list_entry *info,
> -				     unsigned num_entries);
> +static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
> +{
> +	struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
> +						   rhead);
> +
> +	kvfree(list);
> +}
>  
> -static void amdgpu_bo_list_release_rcu(struct kref *ref)
> +static void amdgpu_bo_list_free(struct kref *ref)
>  {
>  	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
>  						   refcount);
> @@ -50,67 +52,36 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
>  	amdgpu_bo_list_for_each_entry(e, list)
>  		amdgpu_bo_unref(&e->robj);
>  
> -	kvfree(list->array);
> -	kfree_rcu(list, rhead);
> +	call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
>  }
>  
> -int amdgpu_bo_list_create(struct amdgpu_device *adev,
> -				 struct drm_file *filp,
> -				 struct drm_amdgpu_bo_list_entry *info,
> -				 unsigned num_entries,
> -				 struct amdgpu_bo_list **list_out)
> +int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
> +			  struct drm_amdgpu_bo_list_entry *info,
> +			  unsigned num_entries, struct amdgpu_bo_list **result)
>  {
> +	unsigned last_entry = 0, first_userptr = num_entries;
> +	struct amdgpu_bo_list_entry *array;
>  	struct amdgpu_bo_list *list;
> +	uint64_t total_size = 0;
> +	size_t size;
> +	unsigned i;
>  	int r;
>  
> +	if (num_entries > SIZE_MAX / sizeof(struct amdgpu_bo_list_entry))
> +		return -EINVAL;
>  
> -	list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
> +	size = sizeof(struct amdgpu_bo_list);
> +	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
> +	list = kvmalloc(size, GFP_KERNEL);
>  	if (!list)
>  		return -ENOMEM;
>  
> -	/* initialize bo list*/
>  	kref_init(&list->refcount);
> -	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
> -	if (r) {
> -		kfree(list);
> -		return r;
> -	}
> -
> -	*list_out = list;
> -	return 0;
> -}
> -
> -static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
> -{
> -	struct amdgpu_bo_list *list;
> -
> -	mutex_lock(&fpriv->bo_list_lock);
> -	list = idr_remove(&fpriv->bo_list_handles, id);
> -	mutex_unlock(&fpriv->bo_list_lock);
> -	if (list)
> -		kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
> -}
> -
> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
> -				     struct drm_file *filp,
> -				     struct amdgpu_bo_list *list,
> -				     struct drm_amdgpu_bo_list_entry *info,
> -				     unsigned num_entries)
> -{
> -	struct amdgpu_bo_list_entry *array;
> -	struct amdgpu_bo *gds_obj = adev->gds.gds_gfx_bo;
> -	struct amdgpu_bo *gws_obj = adev->gds.gws_gfx_bo;
> -	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
> -
> -	unsigned last_entry = 0, first_userptr = num_entries;
> -	struct amdgpu_bo_list_entry *e;
> -	uint64_t total_size = 0;
> -	unsigned i;
> -	int r;
> +	list->gds_obj = adev->gds.gds_gfx_bo;
> +	list->gws_obj = adev->gds.gws_gfx_bo;
> +	list->oa_obj = adev->gds.oa_gfx_bo;
>  
> -	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
> -	if (!array)
> -		return -ENOMEM;
> +	array = amdgpu_bo_list_array_entry(list, 0);
>  	memset(array, 0, num_entries * sizeof(struct amdgpu_bo_list_entry));
>  
>  	for (i = 0; i < num_entries; ++i) {
> @@ -147,36 +118,41 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
>  		entry->tv.shared = !entry->robj->prime_shared_count;
>  
>  		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
> -			gds_obj = entry->robj;
> +			list->gds_obj = entry->robj;
>  		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GWS)
> -			gws_obj = entry->robj;
> +			list->gws_obj = entry->robj;
>  		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_OA)
> -			oa_obj = entry->robj;
> +			list->oa_obj = entry->robj;
>  
>  		total_size += amdgpu_bo_size(entry->robj);
>  		trace_amdgpu_bo_list_set(list, entry->robj);
>  	}
>  
> -	amdgpu_bo_list_for_each_entry(e, list)
> -		amdgpu_bo_unref(&list->array[i].robj);
> -
> -	kvfree(list->array);
> -
> -	list->gds_obj = gds_obj;
> -	list->gws_obj = gws_obj;
> -	list->oa_obj = oa_obj;
>  	list->first_userptr = first_userptr;
> -	list->array = array;
>  	list->num_entries = num_entries;
>  
>  	trace_amdgpu_cs_bo_status(list->num_entries, total_size);
> +
> +	*result = list;
>  	return 0;
>  
>  error_free:
>  	while (i--)
>  		amdgpu_bo_unref(&array[i].robj);
> -	kvfree(array);
> +	kvfree(list);
>  	return r;
> +
> +}
> +
> +static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
> +{
> +	struct amdgpu_bo_list *list;
> +
> +	mutex_lock(&fpriv->bo_list_lock);
> +	list = idr_remove(&fpriv->bo_list_handles, id);
> +	mutex_unlock(&fpriv->bo_list_lock);
> +	if (list)
> +		kref_put(&list->refcount, amdgpu_bo_list_free);
>  }
>  
>  int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> @@ -229,7 +205,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
>  
>  void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
>  {
> -	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
> +	kref_put(&list->refcount, amdgpu_bo_list_free);
>  }
>  
>  int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 3d77abfcd4a6..61b089768e1c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -48,7 +48,6 @@ struct amdgpu_bo_list {
>  	struct amdgpu_bo *oa_obj;
>  	unsigned first_userptr;
>  	unsigned num_entries;
> -	struct amdgpu_bo_list_entry *array;
>  };
>  
>  int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> @@ -65,14 +64,22 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
>  				 unsigned num_entries,
>  				 struct amdgpu_bo_list **list);
>  
> +static inline struct amdgpu_bo_list_entry *
> +amdgpu_bo_list_array_entry(struct amdgpu_bo_list *list, unsigned index)
> +{
> +	struct amdgpu_bo_list_entry *array = (void *)&list[1];
> +
> +	return &array[index];
> +}
> +
>  #define amdgpu_bo_list_for_each_entry(e, list) \
> -	for (e = &(list)->array[0]; \
> -	     e != &(list)->array[(list)->num_entries]; \
> +	for (e = amdgpu_bo_list_array_entry(list, 0); \
> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
>  	     ++e)
>  
>  #define amdgpu_bo_list_for_each_userptr_entry(e, list) \
> -	for (e = &(list)->array[(list)->first_userptr]; \
> -	     e != &(list)->array[(list)->num_entries]; \
> +	for (e = amdgpu_bo_list_array_entry(list, (list)->first_userptr); \
> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
>  	     ++e)
>  
>  #endif
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found]     ` <20180730145159.13212-9-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-31  1:31       ` Zhou, David(ChunMing)
@ 2018-07-31  7:51       ` Huang Rui
  2018-07-31  8:52         ` Christian König
  1 sibling, 1 reply; 26+ messages in thread
From: Huang Rui @ 2018-07-31  7:51 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
> Instead of having extra handling just create an empty bo_list when no
> handle is provided.

Reviewed-by: Huang Rui <ray.huang@amd.com>

In which case, when the command is being submitted, there is no bo list
handle? All BOs are per-VM, no shared BO?

Thanks,
Ray

> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
>  1 file changed, 46 insertions(+), 65 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 1d7292ab2b62..502b94fb116a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  				union drm_amdgpu_cs *cs)
>  {
>  	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> +	struct amdgpu_vm *vm = &fpriv->vm;
>  	struct amdgpu_bo_list_entry *e;
>  	struct list_head duplicates;
>  	struct amdgpu_bo *gds;
> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  				       &p->bo_list);
>  		if (r)
>  			return r;
> +	} else if (!p->bo_list) {
> +		/* Create a empty bo_list when no handle is provided */
> +		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
> +					  &p->bo_list);
> +		if (r)
> +			return r;
>  	}
>  
> -	if (p->bo_list) {
> -		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> -		if (p->bo_list->first_userptr != p->bo_list->num_entries)
> -			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
> -	}
> +	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> +	if (p->bo_list->first_userptr != p->bo_list->num_entries)
> +		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>  
>  	INIT_LIST_HEAD(&duplicates);
>  	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  			goto error_free_pages;
>  		}
>  
> -		/* Without a BO list we don't have userptr BOs */
> -		if (!p->bo_list)
> -			break;
> -
>  		INIT_LIST_HEAD(&need_pages);
>  		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>  			struct amdgpu_bo *bo = e->robj;
> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>  				     p->bytes_moved_vis);
>  
> -	if (p->bo_list) {
> -		struct amdgpu_vm *vm = &fpriv->vm;
> -		struct amdgpu_bo_list_entry *e;
> +	gds = p->bo_list->gds_obj;
> +	gws = p->bo_list->gws_obj;
> +	oa = p->bo_list->oa_obj;
>  
> -		gds = p->bo_list->gds_obj;
> -		gws = p->bo_list->gws_obj;
> -		oa = p->bo_list->oa_obj;
> -
> -		amdgpu_bo_list_for_each_entry(e, p->bo_list)
> -			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
> -	} else {
> -		gds = p->adev->gds.gds_gfx_bo;
> -		gws = p->adev->gds.gws_gfx_bo;
> -		oa = p->adev->gds.oa_gfx_bo;
> -	}
> +	amdgpu_bo_list_for_each_entry(e, p->bo_list)
> +		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>  
>  	if (gds) {
>  		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  
>  error_free_pages:
>  
> -	if (p->bo_list) {
> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> -			if (!e->user_pages)
> -				continue;
> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> +		if (!e->user_pages)
> +			continue;
>  
> -			release_pages(e->user_pages,
> -				      e->robj->tbo.ttm->num_pages);
> -			kvfree(e->user_pages);
> -		}
> +		release_pages(e->user_pages,
> +			      e->robj->tbo.ttm->num_pages);
> +		kvfree(e->user_pages);
>  	}
>  
>  	return r;
> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>  
>  static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  {
> -	struct amdgpu_device *adev = p->adev;
>  	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> +	struct amdgpu_device *adev = p->adev;
>  	struct amdgpu_vm *vm = &fpriv->vm;
> +	struct amdgpu_bo_list_entry *e;
>  	struct amdgpu_bo_va *bo_va;
>  	struct amdgpu_bo *bo;
>  	int r;
> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  			return r;
>  	}
>  
> -	if (p->bo_list) {
> -		struct amdgpu_bo_list_entry *e;
> -
> -		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> -			struct dma_fence *f;
> -
> -			/* ignore duplicates */
> -			bo = e->robj;
> -			if (!bo)
> -				continue;
> +	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> +		struct dma_fence *f;
>  
> -			bo_va = e->bo_va;
> -			if (bo_va == NULL)
> -				continue;
> +		/* ignore duplicates */
> +		bo = e->robj;
> +		if (!bo)
> +			continue;
>  
> -			r = amdgpu_vm_bo_update(adev, bo_va, false);
> -			if (r)
> -				return r;
> +		bo_va = e->bo_va;
> +		if (bo_va == NULL)
> +			continue;
>  
> -			f = bo_va->last_pt_update;
> -			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> -			if (r)
> -				return r;
> -		}
> +		r = amdgpu_vm_bo_update(adev, bo_va, false);
> +		if (r)
> +			return r;
>  
> +		f = bo_va->last_pt_update;
> +		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> +		if (r)
> +			return r;
>  	}
>  
>  	r = amdgpu_vm_handle_moved(adev, vm);
> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>  	if (r)
>  		return r;
>  
> -	if (amdgpu_vm_debug && p->bo_list) {
> -		struct amdgpu_bo_list_entry *e;
> -
> +	if (amdgpu_vm_debug) {
>  		/* Invalidate all BOs to test for userspace bugs */
>  		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>  			/* ignore duplicates */
> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>  	struct amdgpu_ring *ring = p->ring;
>  	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>  	enum drm_sched_priority priority;
> +	struct amdgpu_bo_list_entry *e;
>  	struct amdgpu_job *job;
>  	uint64_t seq;
>  
>  	int r;
>  
>  	amdgpu_mn_lock(p->mn);
> -	if (p->bo_list) {
> -		struct amdgpu_bo_list_entry *e;
> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> +		struct amdgpu_bo *bo = e->robj;
>  
> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> -			struct amdgpu_bo *bo = e->robj;
> -
> -			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> -				amdgpu_mn_unlock(p->mn);
> -				return -ERESTARTSYS;
> -			}
> +		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> +			amdgpu_mn_unlock(p->mn);
> +			return -ERESTARTSYS;
>  		}
>  	}
>  
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
  2018-07-31  7:51       ` Huang Rui
@ 2018-07-31  8:52         ` Christian König
       [not found]           ` <c630d2c3-25c8-b532-1a1c-07626f82ea12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-31  8:52 UTC (permalink / raw)
  To: Huang Rui; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 31.07.2018 um 09:51 schrieb Huang Rui:
> On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
>> Instead of having extra handling just create an empty bo_list when no
>> handle is provided.
> Reviewed-by: Huang Rui <ray.huang@amd.com>
>
> In which case, when the command is being submitted, there is no bo list
> handle? All BOs are per-VM, no shared BO?

Yes, exactly. Or in the future just SVM etc...

Christian.

>
> Thanks,
> Ray
>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
>>   1 file changed, 46 insertions(+), 65 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> index 1d7292ab2b62..502b94fb116a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>   				union drm_amdgpu_cs *cs)
>>   {
>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>> +	struct amdgpu_vm *vm = &fpriv->vm;
>>   	struct amdgpu_bo_list_entry *e;
>>   	struct list_head duplicates;
>>   	struct amdgpu_bo *gds;
>> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>   				       &p->bo_list);
>>   		if (r)
>>   			return r;
>> +	} else if (!p->bo_list) {
>> +		/* Create a empty bo_list when no handle is provided */
>> +		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
>> +					  &p->bo_list);
>> +		if (r)
>> +			return r;
>>   	}
>>   
>> -	if (p->bo_list) {
>> -		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>> -		if (p->bo_list->first_userptr != p->bo_list->num_entries)
>> -			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>> -	}
>> +	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>> +	if (p->bo_list->first_userptr != p->bo_list->num_entries)
>> +		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>   
>>   	INIT_LIST_HEAD(&duplicates);
>>   	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
>> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>   			goto error_free_pages;
>>   		}
>>   
>> -		/* Without a BO list we don't have userptr BOs */
>> -		if (!p->bo_list)
>> -			break;
>> -
>>   		INIT_LIST_HEAD(&need_pages);
>>   		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>   			struct amdgpu_bo *bo = e->robj;
>> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>   	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>>   				     p->bytes_moved_vis);
>>   
>> -	if (p->bo_list) {
>> -		struct amdgpu_vm *vm = &fpriv->vm;
>> -		struct amdgpu_bo_list_entry *e;
>> +	gds = p->bo_list->gds_obj;
>> +	gws = p->bo_list->gws_obj;
>> +	oa = p->bo_list->oa_obj;
>>   
>> -		gds = p->bo_list->gds_obj;
>> -		gws = p->bo_list->gws_obj;
>> -		oa = p->bo_list->oa_obj;
>> -
>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list)
>> -			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>> -	} else {
>> -		gds = p->adev->gds.gds_gfx_bo;
>> -		gws = p->adev->gds.gws_gfx_bo;
>> -		oa = p->adev->gds.oa_gfx_bo;
>> -	}
>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list)
>> +		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>   
>>   	if (gds) {
>>   		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
>> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>   
>>   error_free_pages:
>>   
>> -	if (p->bo_list) {
>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>> -			if (!e->user_pages)
>> -				continue;
>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>> +		if (!e->user_pages)
>> +			continue;
>>   
>> -			release_pages(e->user_pages,
>> -				      e->robj->tbo.ttm->num_pages);
>> -			kvfree(e->user_pages);
>> -		}
>> +		release_pages(e->user_pages,
>> +			      e->robj->tbo.ttm->num_pages);
>> +		kvfree(e->user_pages);
>>   	}
>>   
>>   	return r;
>> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>>   
>>   static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>   {
>> -	struct amdgpu_device *adev = p->adev;
>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>> +	struct amdgpu_device *adev = p->adev;
>>   	struct amdgpu_vm *vm = &fpriv->vm;
>> +	struct amdgpu_bo_list_entry *e;
>>   	struct amdgpu_bo_va *bo_va;
>>   	struct amdgpu_bo *bo;
>>   	int r;
>> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>   			return r;
>>   	}
>>   
>> -	if (p->bo_list) {
>> -		struct amdgpu_bo_list_entry *e;
>> -
>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>> -			struct dma_fence *f;
>> -
>> -			/* ignore duplicates */
>> -			bo = e->robj;
>> -			if (!bo)
>> -				continue;
>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>> +		struct dma_fence *f;
>>   
>> -			bo_va = e->bo_va;
>> -			if (bo_va == NULL)
>> -				continue;
>> +		/* ignore duplicates */
>> +		bo = e->robj;
>> +		if (!bo)
>> +			continue;
>>   
>> -			r = amdgpu_vm_bo_update(adev, bo_va, false);
>> -			if (r)
>> -				return r;
>> +		bo_va = e->bo_va;
>> +		if (bo_va == NULL)
>> +			continue;
>>   
>> -			f = bo_va->last_pt_update;
>> -			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>> -			if (r)
>> -				return r;
>> -		}
>> +		r = amdgpu_vm_bo_update(adev, bo_va, false);
>> +		if (r)
>> +			return r;
>>   
>> +		f = bo_va->last_pt_update;
>> +		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>> +		if (r)
>> +			return r;
>>   	}
>>   
>>   	r = amdgpu_vm_handle_moved(adev, vm);
>> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>   	if (r)
>>   		return r;
>>   
>> -	if (amdgpu_vm_debug && p->bo_list) {
>> -		struct amdgpu_bo_list_entry *e;
>> -
>> +	if (amdgpu_vm_debug) {
>>   		/* Invalidate all BOs to test for userspace bugs */
>>   		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>   			/* ignore duplicates */
>> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>>   	struct amdgpu_ring *ring = p->ring;
>>   	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>>   	enum drm_sched_priority priority;
>> +	struct amdgpu_bo_list_entry *e;
>>   	struct amdgpu_job *job;
>>   	uint64_t seq;
>>   
>>   	int r;
>>   
>>   	amdgpu_mn_lock(p->mn);
>> -	if (p->bo_list) {
>> -		struct amdgpu_bo_list_entry *e;
>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>> +		struct amdgpu_bo *bo = e->robj;
>>   
>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>> -			struct amdgpu_bo *bo = e->robj;
>> -
>> -			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>> -				amdgpu_mn_unlock(p->mn);
>> -				return -ERESTARTSYS;
>> -			}
>> +		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>> +			amdgpu_mn_unlock(p->mn);
>> +			return -ERESTARTSYS;
>>   		}
>>   	}
>>   
>> -- 
>> 2.14.1
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found]           ` <c630d2c3-25c8-b532-1a1c-07626f82ea12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-07-31  9:00             ` Zhang, Jerry (Junwei)
  2018-07-31  9:09             ` Huang Rui
  1 sibling, 0 replies; 26+ messages in thread
From: Zhang, Jerry (Junwei) @ 2018-07-31  9:00 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, Huang Rui
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 07/31/2018 04:52 PM, Christian König wrote:
> Am 31.07.2018 um 09:51 schrieb Huang Rui:
>> On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
>>> Instead of having extra handling just create an empty bo_list when no
>>> handle is provided.
>> Reviewed-by: Huang Rui <ray.huang@amd.com>
>>
>> In which case, when the command is being submitted, there is no bo list
>> handle? All BOs are per-VM, no shared BO?
>
> Yes, exactly. Or in the future just SVM etc...

SVM will not use bo list either?
any perform consideration?

Regards,
Jerry

>
> Christian.
>
>>
>> Thanks,
>> Ray
>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
>>>   1 file changed, 46 insertions(+), 65 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> index 1d7292ab2b62..502b94fb116a 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>                   union drm_amdgpu_cs *cs)
>>>   {
>>>       struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>> +    struct amdgpu_vm *vm = &fpriv->vm;
>>>       struct amdgpu_bo_list_entry *e;
>>>       struct list_head duplicates;
>>>       struct amdgpu_bo *gds;
>>> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>                          &p->bo_list);
>>>           if (r)
>>>               return r;
>>> +    } else if (!p->bo_list) {
>>> +        /* Create a empty bo_list when no handle is provided */
>>> +        r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
>>> +                      &p->bo_list);
>>> +        if (r)
>>> +            return r;
>>>       }
>>> -    if (p->bo_list) {
>>> -        amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>> -        if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>> -            p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>> -    }
>>> +    amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>> +    if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>> +        p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>>       INIT_LIST_HEAD(&duplicates);
>>>       amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
>>> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>               goto error_free_pages;
>>>           }
>>> -        /* Without a BO list we don't have userptr BOs */
>>> -        if (!p->bo_list)
>>> -            break;
>>> -
>>>           INIT_LIST_HEAD(&need_pages);
>>>           amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>               struct amdgpu_bo *bo = e->robj;
>>> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>       amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>>>                        p->bytes_moved_vis);
>>> -    if (p->bo_list) {
>>> -        struct amdgpu_vm *vm = &fpriv->vm;
>>> -        struct amdgpu_bo_list_entry *e;
>>> +    gds = p->bo_list->gds_obj;
>>> +    gws = p->bo_list->gws_obj;
>>> +    oa = p->bo_list->oa_obj;
>>> -        gds = p->bo_list->gds_obj;
>>> -        gws = p->bo_list->gws_obj;
>>> -        oa = p->bo_list->oa_obj;
>>> -
>>> -        amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>> -            e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>> -    } else {
>>> -        gds = p->adev->gds.gds_gfx_bo;
>>> -        gws = p->adev->gds.gws_gfx_bo;
>>> -        oa = p->adev->gds.oa_gfx_bo;
>>> -    }
>>> +    amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>> +        e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>>       if (gds) {
>>>           p->job->gds_base = amdgpu_bo_gpu_offset(gds);
>>> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>   error_free_pages:
>>> -    if (p->bo_list) {
>>> -        amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>> -            if (!e->user_pages)
>>> -                continue;
>>> +    amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>> +        if (!e->user_pages)
>>> +            continue;
>>> -            release_pages(e->user_pages,
>>> -                      e->robj->tbo.ttm->num_pages);
>>> -            kvfree(e->user_pages);
>>> -        }
>>> +        release_pages(e->user_pages,
>>> +                  e->robj->tbo.ttm->num_pages);
>>> +        kvfree(e->user_pages);
>>>       }
>>>       return r;
>>> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>>>   static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>   {
>>> -    struct amdgpu_device *adev = p->adev;
>>>       struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>> +    struct amdgpu_device *adev = p->adev;
>>>       struct amdgpu_vm *vm = &fpriv->vm;
>>> +    struct amdgpu_bo_list_entry *e;
>>>       struct amdgpu_bo_va *bo_va;
>>>       struct amdgpu_bo *bo;
>>>       int r;
>>> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>               return r;
>>>       }
>>> -    if (p->bo_list) {
>>> -        struct amdgpu_bo_list_entry *e;
>>> -
>>> -        amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>> -            struct dma_fence *f;
>>> -
>>> -            /* ignore duplicates */
>>> -            bo = e->robj;
>>> -            if (!bo)
>>> -                continue;
>>> +    amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>> +        struct dma_fence *f;
>>> -            bo_va = e->bo_va;
>>> -            if (bo_va == NULL)
>>> -                continue;
>>> +        /* ignore duplicates */
>>> +        bo = e->robj;
>>> +        if (!bo)
>>> +            continue;
>>> -            r = amdgpu_vm_bo_update(adev, bo_va, false);
>>> -            if (r)
>>> -                return r;
>>> +        bo_va = e->bo_va;
>>> +        if (bo_va == NULL)
>>> +            continue;
>>> -            f = bo_va->last_pt_update;
>>> -            r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>> -            if (r)
>>> -                return r;
>>> -        }
>>> +        r = amdgpu_vm_bo_update(adev, bo_va, false);
>>> +        if (r)
>>> +            return r;
>>> +        f = bo_va->last_pt_update;
>>> +        r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>> +        if (r)
>>> +            return r;
>>>       }
>>>       r = amdgpu_vm_handle_moved(adev, vm);
>>> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>       if (r)
>>>           return r;
>>> -    if (amdgpu_vm_debug && p->bo_list) {
>>> -        struct amdgpu_bo_list_entry *e;
>>> -
>>> +    if (amdgpu_vm_debug) {
>>>           /* Invalidate all BOs to test for userspace bugs */
>>>           amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>               /* ignore duplicates */
>>> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>>>       struct amdgpu_ring *ring = p->ring;
>>>       struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>>>       enum drm_sched_priority priority;
>>> +    struct amdgpu_bo_list_entry *e;
>>>       struct amdgpu_job *job;
>>>       uint64_t seq;
>>>       int r;
>>>       amdgpu_mn_lock(p->mn);
>>> -    if (p->bo_list) {
>>> -        struct amdgpu_bo_list_entry *e;
>>> +    amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>> +        struct amdgpu_bo *bo = e->robj;
>>> -        amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>> -            struct amdgpu_bo *bo = e->robj;
>>> -
>>> -            if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>> -                amdgpu_mn_unlock(p->mn);
>>> -                return -ERESTARTSYS;
>>> -            }
>>> +        if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>> +            amdgpu_mn_unlock(p->mn);
>>> +            return -ERESTARTSYS;
>>>           }
>>>       }
>>> --
>>> 2.14.1
>>>
>>> _______________________________________________
>>> amd-gfx mailing list
>>> amd-gfx@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
  2018-07-31  9:09             ` Huang Rui
@ 2018-07-31  9:00               ` Christian König
       [not found]                 ` <e35b8029-27d0-fc97-64c2-64f4379eeda8-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Christian König @ 2018-07-31  9:00 UTC (permalink / raw)
  To: Huang Rui; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 31.07.2018 um 11:09 schrieb Huang Rui:
> On Tue, Jul 31, 2018 at 10:52:06AM +0200, Christian König wrote:
>> Am 31.07.2018 um 09:51 schrieb Huang Rui:
>>> On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
>>>> Instead of having extra handling just create an empty bo_list when no
>>>> handle is provided.
>>> Reviewed-by: Huang Rui <ray.huang@amd.com>
>>>
>>> In which case, when the command is being submitted, there is no bo list
>>> handle? All BOs are per-VM, no shared BO?
>> Yes, exactly. Or in the future just SVM etc...
>>
> "SVM" means single VM? Only one thread?

Shared Virtual Memory, e.g. the GPU uses the virtual CPU address space.

Can be implemented using the ATC or starting with Vega10 using HMM.

Regards,
Christian.

>
> Thanks,
> Ray
>
>> Christian.
>>
>>> Thanks,
>>> Ray
>>>
>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>> ---
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
>>>>   1 file changed, 46 insertions(+), 65 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>> index 1d7292ab2b62..502b94fb116a 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>   				union drm_amdgpu_cs *cs)
>>>>   {
>>>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>>> +	struct amdgpu_vm *vm = &fpriv->vm;
>>>>   	struct amdgpu_bo_list_entry *e;
>>>>   	struct list_head duplicates;
>>>>   	struct amdgpu_bo *gds;
>>>> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>   				       &p->bo_list);
>>>>   		if (r)
>>>>   			return r;
>>>> +	} else if (!p->bo_list) {
>>>> +		/* Create a empty bo_list when no handle is provided */
>>>> +		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
>>>> +					  &p->bo_list);
>>>> +		if (r)
>>>> +			return r;
>>>>   	}
>>>> -	if (p->bo_list) {
>>>> -		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>>> -		if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>>> -			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>>> -	}
>>>> +	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>>> +	if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>>> +		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>>>   	INIT_LIST_HEAD(&duplicates);
>>>>   	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
>>>> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>   			goto error_free_pages;
>>>>   		}
>>>> -		/* Without a BO list we don't have userptr BOs */
>>>> -		if (!p->bo_list)
>>>> -			break;
>>>> -
>>>>   		INIT_LIST_HEAD(&need_pages);
>>>>   		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>   			struct amdgpu_bo *bo = e->robj;
>>>> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>   	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>>>>   				     p->bytes_moved_vis);
>>>> -	if (p->bo_list) {
>>>> -		struct amdgpu_vm *vm = &fpriv->vm;
>>>> -		struct amdgpu_bo_list_entry *e;
>>>> +	gds = p->bo_list->gds_obj;
>>>> +	gws = p->bo_list->gws_obj;
>>>> +	oa = p->bo_list->oa_obj;
>>>> -		gds = p->bo_list->gds_obj;
>>>> -		gws = p->bo_list->gws_obj;
>>>> -		oa = p->bo_list->oa_obj;
>>>> -
>>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>>> -			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>>> -	} else {
>>>> -		gds = p->adev->gds.gds_gfx_bo;
>>>> -		gws = p->adev->gds.gws_gfx_bo;
>>>> -		oa = p->adev->gds.oa_gfx_bo;
>>>> -	}
>>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>>> +		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>>>   	if (gds) {
>>>>   		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
>>>> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>   error_free_pages:
>>>> -	if (p->bo_list) {
>>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>> -			if (!e->user_pages)
>>>> -				continue;
>>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>> +		if (!e->user_pages)
>>>> +			continue;
>>>> -			release_pages(e->user_pages,
>>>> -				      e->robj->tbo.ttm->num_pages);
>>>> -			kvfree(e->user_pages);
>>>> -		}
>>>> +		release_pages(e->user_pages,
>>>> +			      e->robj->tbo.ttm->num_pages);
>>>> +		kvfree(e->user_pages);
>>>>   	}
>>>>   	return r;
>>>> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>>>>   static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>   {
>>>> -	struct amdgpu_device *adev = p->adev;
>>>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>>> +	struct amdgpu_device *adev = p->adev;
>>>>   	struct amdgpu_vm *vm = &fpriv->vm;
>>>> +	struct amdgpu_bo_list_entry *e;
>>>>   	struct amdgpu_bo_va *bo_va;
>>>>   	struct amdgpu_bo *bo;
>>>>   	int r;
>>>> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>   			return r;
>>>>   	}
>>>> -	if (p->bo_list) {
>>>> -		struct amdgpu_bo_list_entry *e;
>>>> -
>>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>> -			struct dma_fence *f;
>>>> -
>>>> -			/* ignore duplicates */
>>>> -			bo = e->robj;
>>>> -			if (!bo)
>>>> -				continue;
>>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>> +		struct dma_fence *f;
>>>> -			bo_va = e->bo_va;
>>>> -			if (bo_va == NULL)
>>>> -				continue;
>>>> +		/* ignore duplicates */
>>>> +		bo = e->robj;
>>>> +		if (!bo)
>>>> +			continue;
>>>> -			r = amdgpu_vm_bo_update(adev, bo_va, false);
>>>> -			if (r)
>>>> -				return r;
>>>> +		bo_va = e->bo_va;
>>>> +		if (bo_va == NULL)
>>>> +			continue;
>>>> -			f = bo_va->last_pt_update;
>>>> -			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>>> -			if (r)
>>>> -				return r;
>>>> -		}
>>>> +		r = amdgpu_vm_bo_update(adev, bo_va, false);
>>>> +		if (r)
>>>> +			return r;
>>>> +		f = bo_va->last_pt_update;
>>>> +		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>>> +		if (r)
>>>> +			return r;
>>>>   	}
>>>>   	r = amdgpu_vm_handle_moved(adev, vm);
>>>> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>   	if (r)
>>>>   		return r;
>>>> -	if (amdgpu_vm_debug && p->bo_list) {
>>>> -		struct amdgpu_bo_list_entry *e;
>>>> -
>>>> +	if (amdgpu_vm_debug) {
>>>>   		/* Invalidate all BOs to test for userspace bugs */
>>>>   		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>>   			/* ignore duplicates */
>>>> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>>>>   	struct amdgpu_ring *ring = p->ring;
>>>>   	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>>>>   	enum drm_sched_priority priority;
>>>> +	struct amdgpu_bo_list_entry *e;
>>>>   	struct amdgpu_job *job;
>>>>   	uint64_t seq;
>>>>   	int r;
>>>>   	amdgpu_mn_lock(p->mn);
>>>> -	if (p->bo_list) {
>>>> -		struct amdgpu_bo_list_entry *e;
>>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>> +		struct amdgpu_bo *bo = e->robj;
>>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>> -			struct amdgpu_bo *bo = e->robj;
>>>> -
>>>> -			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>>> -				amdgpu_mn_unlock(p->mn);
>>>> -				return -ERESTARTSYS;
>>>> -			}
>>>> +		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>>> +			amdgpu_mn_unlock(p->mn);
>>>> +			return -ERESTARTSYS;
>>>>   		}
>>>>   	}
>>>> -- 
>>>> 2.14.1
>>>>
>>>> _______________________________________________
>>>> amd-gfx mailing list
>>>> amd-gfx@lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found]           ` <c630d2c3-25c8-b532-1a1c-07626f82ea12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-07-31  9:00             ` Zhang, Jerry (Junwei)
@ 2018-07-31  9:09             ` Huang Rui
  2018-07-31  9:00               ` Christian König
  1 sibling, 1 reply; 26+ messages in thread
From: Huang Rui @ 2018-07-31  9:09 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Tue, Jul 31, 2018 at 10:52:06AM +0200, Christian König wrote:
> Am 31.07.2018 um 09:51 schrieb Huang Rui:
> >On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
> >>Instead of having extra handling just create an empty bo_list when no
> >>handle is provided.
> >Reviewed-by: Huang Rui <ray.huang@amd.com>
> >
> >In which case, when the command is being submitted, there is no bo list
> >handle? All BOs are per-VM, no shared BO?
> 
> Yes, exactly. Or in the future just SVM etc...
> 

"SVM" means single VM? Only one thread?

Thanks,
Ray

> Christian.
> 
> >
> >Thanks,
> >Ray
> >
> >>Signed-off-by: Christian König <christian.koenig@amd.com>
> >>---
> >>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
> >>  1 file changed, 46 insertions(+), 65 deletions(-)
> >>
> >>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>index 1d7292ab2b62..502b94fb116a 100644
> >>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>@@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>  				union drm_amdgpu_cs *cs)
> >>  {
> >>  	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> >>+	struct amdgpu_vm *vm = &fpriv->vm;
> >>  	struct amdgpu_bo_list_entry *e;
> >>  	struct list_head duplicates;
> >>  	struct amdgpu_bo *gds;
> >>@@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>  				       &p->bo_list);
> >>  		if (r)
> >>  			return r;
> >>+	} else if (!p->bo_list) {
> >>+		/* Create a empty bo_list when no handle is provided */
> >>+		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
> >>+					  &p->bo_list);
> >>+		if (r)
> >>+			return r;
> >>  	}
> >>-	if (p->bo_list) {
> >>-		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> >>-		if (p->bo_list->first_userptr != p->bo_list->num_entries)
> >>-			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
> >>-	}
> >>+	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> >>+	if (p->bo_list->first_userptr != p->bo_list->num_entries)
> >>+		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
> >>  	INIT_LIST_HEAD(&duplicates);
> >>  	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
> >>@@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>  			goto error_free_pages;
> >>  		}
> >>-		/* Without a BO list we don't have userptr BOs */
> >>-		if (!p->bo_list)
> >>-			break;
> >>-
> >>  		INIT_LIST_HEAD(&need_pages);
> >>  		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>  			struct amdgpu_bo *bo = e->robj;
> >>@@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>  	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
> >>  				     p->bytes_moved_vis);
> >>-	if (p->bo_list) {
> >>-		struct amdgpu_vm *vm = &fpriv->vm;
> >>-		struct amdgpu_bo_list_entry *e;
> >>+	gds = p->bo_list->gds_obj;
> >>+	gws = p->bo_list->gws_obj;
> >>+	oa = p->bo_list->oa_obj;
> >>-		gds = p->bo_list->gds_obj;
> >>-		gws = p->bo_list->gws_obj;
> >>-		oa = p->bo_list->oa_obj;
> >>-
> >>-		amdgpu_bo_list_for_each_entry(e, p->bo_list)
> >>-			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
> >>-	} else {
> >>-		gds = p->adev->gds.gds_gfx_bo;
> >>-		gws = p->adev->gds.gws_gfx_bo;
> >>-		oa = p->adev->gds.oa_gfx_bo;
> >>-	}
> >>+	amdgpu_bo_list_for_each_entry(e, p->bo_list)
> >>+		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
> >>  	if (gds) {
> >>  		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
> >>@@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>  error_free_pages:
> >>-	if (p->bo_list) {
> >>-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>-			if (!e->user_pages)
> >>-				continue;
> >>+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>+		if (!e->user_pages)
> >>+			continue;
> >>-			release_pages(e->user_pages,
> >>-				      e->robj->tbo.ttm->num_pages);
> >>-			kvfree(e->user_pages);
> >>-		}
> >>+		release_pages(e->user_pages,
> >>+			      e->robj->tbo.ttm->num_pages);
> >>+		kvfree(e->user_pages);
> >>  	}
> >>  	return r;
> >>@@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
> >>  static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>  {
> >>-	struct amdgpu_device *adev = p->adev;
> >>  	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> >>+	struct amdgpu_device *adev = p->adev;
> >>  	struct amdgpu_vm *vm = &fpriv->vm;
> >>+	struct amdgpu_bo_list_entry *e;
> >>  	struct amdgpu_bo_va *bo_va;
> >>  	struct amdgpu_bo *bo;
> >>  	int r;
> >>@@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>  			return r;
> >>  	}
> >>-	if (p->bo_list) {
> >>-		struct amdgpu_bo_list_entry *e;
> >>-
> >>-		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>-			struct dma_fence *f;
> >>-
> >>-			/* ignore duplicates */
> >>-			bo = e->robj;
> >>-			if (!bo)
> >>-				continue;
> >>+	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>+		struct dma_fence *f;
> >>-			bo_va = e->bo_va;
> >>-			if (bo_va == NULL)
> >>-				continue;
> >>+		/* ignore duplicates */
> >>+		bo = e->robj;
> >>+		if (!bo)
> >>+			continue;
> >>-			r = amdgpu_vm_bo_update(adev, bo_va, false);
> >>-			if (r)
> >>-				return r;
> >>+		bo_va = e->bo_va;
> >>+		if (bo_va == NULL)
> >>+			continue;
> >>-			f = bo_va->last_pt_update;
> >>-			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> >>-			if (r)
> >>-				return r;
> >>-		}
> >>+		r = amdgpu_vm_bo_update(adev, bo_va, false);
> >>+		if (r)
> >>+			return r;
> >>+		f = bo_va->last_pt_update;
> >>+		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> >>+		if (r)
> >>+			return r;
> >>  	}
> >>  	r = amdgpu_vm_handle_moved(adev, vm);
> >>@@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>  	if (r)
> >>  		return r;
> >>-	if (amdgpu_vm_debug && p->bo_list) {
> >>-		struct amdgpu_bo_list_entry *e;
> >>-
> >>+	if (amdgpu_vm_debug) {
> >>  		/* Invalidate all BOs to test for userspace bugs */
> >>  		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>  			/* ignore duplicates */
> >>@@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
> >>  	struct amdgpu_ring *ring = p->ring;
> >>  	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
> >>  	enum drm_sched_priority priority;
> >>+	struct amdgpu_bo_list_entry *e;
> >>  	struct amdgpu_job *job;
> >>  	uint64_t seq;
> >>  	int r;
> >>  	amdgpu_mn_lock(p->mn);
> >>-	if (p->bo_list) {
> >>-		struct amdgpu_bo_list_entry *e;
> >>+	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>+		struct amdgpu_bo *bo = e->robj;
> >>-		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>-			struct amdgpu_bo *bo = e->robj;
> >>-
> >>-			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> >>-				amdgpu_mn_unlock(p->mn);
> >>-				return -ERESTARTSYS;
> >>-			}
> >>+		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> >>+			amdgpu_mn_unlock(p->mn);
> >>+			return -ERESTARTSYS;
> >>  		}
> >>  	}
> >>-- 
> >>2.14.1
> >>
> >>_______________________________________________
> >>amd-gfx mailing list
> >>amd-gfx@lists.freedesktop.org
> >>https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
       [not found]                 ` <e35b8029-27d0-fc97-64c2-64f4379eeda8-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-31  9:26                   ` Huang Rui
  2018-07-31  9:41                     ` Zhang, Jerry (Junwei)
  0 siblings, 1 reply; 26+ messages in thread
From: Huang Rui @ 2018-07-31  9:26 UTC (permalink / raw)
  To: Koenig, Christian; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Tue, Jul 31, 2018 at 05:00:46PM +0800, Koenig, Christian wrote:
> Am 31.07.2018 um 11:09 schrieb Huang Rui:
> > On Tue, Jul 31, 2018 at 10:52:06AM +0200, Christian König wrote:
> >> Am 31.07.2018 um 09:51 schrieb Huang Rui:
> >>> On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
> >>>> Instead of having extra handling just create an empty bo_list when no
> >>>> handle is provided.
> >>> Reviewed-by: Huang Rui <ray.huang@amd.com>
> >>>
> >>> In which case, when the command is being submitted, there is no bo list
> >>> handle? All BOs are per-VM, no shared BO?
> >> Yes, exactly. Or in the future just SVM etc...
> >>
> > "SVM" means single VM? Only one thread?
> 
> Shared Virtual Memory, e.g. the GPU uses the virtual CPU address space.
> 
> Can be implemented using the ATC or starting with Vega10 using HMM.
> 

Oh, I remembered it should be a proposal for apu such as raven, you know,
the vram is actually carved out from a part of system memory in raven.

Thanks,
Ray

> Regards,
> Christian.
> 
> >
> > Thanks,
> > Ray
> >
> >> Christian.
> >>
> >>> Thanks,
> >>> Ray
> >>>
> >>>> Signed-off-by: Christian König <christian.koenig@amd.com>
> >>>> ---
> >>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
> >>>>   1 file changed, 46 insertions(+), 65 deletions(-)
> >>>>
> >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>>> index 1d7292ab2b62..502b94fb116a 100644
> >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> >>>> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>>>   				union drm_amdgpu_cs *cs)
> >>>>   {
> >>>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> >>>> +	struct amdgpu_vm *vm = &fpriv->vm;
> >>>>   	struct amdgpu_bo_list_entry *e;
> >>>>   	struct list_head duplicates;
> >>>>   	struct amdgpu_bo *gds;
> >>>> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>>>   				       &p->bo_list);
> >>>>   		if (r)
> >>>>   			return r;
> >>>> +	} else if (!p->bo_list) {
> >>>> +		/* Create a empty bo_list when no handle is provided */
> >>>> +		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
> >>>> +					  &p->bo_list);
> >>>> +		if (r)
> >>>> +			return r;
> >>>>   	}
> >>>> -	if (p->bo_list) {
> >>>> -		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> >>>> -		if (p->bo_list->first_userptr != p->bo_list->num_entries)
> >>>> -			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
> >>>> -	}
> >>>> +	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
> >>>> +	if (p->bo_list->first_userptr != p->bo_list->num_entries)
> >>>> +		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
> >>>>   	INIT_LIST_HEAD(&duplicates);
> >>>>   	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
> >>>> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>>>   			goto error_free_pages;
> >>>>   		}
> >>>> -		/* Without a BO list we don't have userptr BOs */
> >>>> -		if (!p->bo_list)
> >>>> -			break;
> >>>> -
> >>>>   		INIT_LIST_HEAD(&need_pages);
> >>>>   		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>>>   			struct amdgpu_bo *bo = e->robj;
> >>>> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>>>   	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
> >>>>   				     p->bytes_moved_vis);
> >>>> -	if (p->bo_list) {
> >>>> -		struct amdgpu_vm *vm = &fpriv->vm;
> >>>> -		struct amdgpu_bo_list_entry *e;
> >>>> +	gds = p->bo_list->gds_obj;
> >>>> +	gws = p->bo_list->gws_obj;
> >>>> +	oa = p->bo_list->oa_obj;
> >>>> -		gds = p->bo_list->gds_obj;
> >>>> -		gws = p->bo_list->gws_obj;
> >>>> -		oa = p->bo_list->oa_obj;
> >>>> -
> >>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list)
> >>>> -			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
> >>>> -	} else {
> >>>> -		gds = p->adev->gds.gds_gfx_bo;
> >>>> -		gws = p->adev->gds.gws_gfx_bo;
> >>>> -		oa = p->adev->gds.oa_gfx_bo;
> >>>> -	}
> >>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list)
> >>>> +		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
> >>>>   	if (gds) {
> >>>>   		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
> >>>> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
> >>>>   error_free_pages:
> >>>> -	if (p->bo_list) {
> >>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>>> -			if (!e->user_pages)
> >>>> -				continue;
> >>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>>> +		if (!e->user_pages)
> >>>> +			continue;
> >>>> -			release_pages(e->user_pages,
> >>>> -				      e->robj->tbo.ttm->num_pages);
> >>>> -			kvfree(e->user_pages);
> >>>> -		}
> >>>> +		release_pages(e->user_pages,
> >>>> +			      e->robj->tbo.ttm->num_pages);
> >>>> +		kvfree(e->user_pages);
> >>>>   	}
> >>>>   	return r;
> >>>> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
> >>>>   static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>>>   {
> >>>> -	struct amdgpu_device *adev = p->adev;
> >>>>   	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
> >>>> +	struct amdgpu_device *adev = p->adev;
> >>>>   	struct amdgpu_vm *vm = &fpriv->vm;
> >>>> +	struct amdgpu_bo_list_entry *e;
> >>>>   	struct amdgpu_bo_va *bo_va;
> >>>>   	struct amdgpu_bo *bo;
> >>>>   	int r;
> >>>> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>>>   			return r;
> >>>>   	}
> >>>> -	if (p->bo_list) {
> >>>> -		struct amdgpu_bo_list_entry *e;
> >>>> -
> >>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>>> -			struct dma_fence *f;
> >>>> -
> >>>> -			/* ignore duplicates */
> >>>> -			bo = e->robj;
> >>>> -			if (!bo)
> >>>> -				continue;
> >>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>>> +		struct dma_fence *f;
> >>>> -			bo_va = e->bo_va;
> >>>> -			if (bo_va == NULL)
> >>>> -				continue;
> >>>> +		/* ignore duplicates */
> >>>> +		bo = e->robj;
> >>>> +		if (!bo)
> >>>> +			continue;
> >>>> -			r = amdgpu_vm_bo_update(adev, bo_va, false);
> >>>> -			if (r)
> >>>> -				return r;
> >>>> +		bo_va = e->bo_va;
> >>>> +		if (bo_va == NULL)
> >>>> +			continue;
> >>>> -			f = bo_va->last_pt_update;
> >>>> -			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> >>>> -			if (r)
> >>>> -				return r;
> >>>> -		}
> >>>> +		r = amdgpu_vm_bo_update(adev, bo_va, false);
> >>>> +		if (r)
> >>>> +			return r;
> >>>> +		f = bo_va->last_pt_update;
> >>>> +		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
> >>>> +		if (r)
> >>>> +			return r;
> >>>>   	}
> >>>>   	r = amdgpu_vm_handle_moved(adev, vm);
> >>>> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
> >>>>   	if (r)
> >>>>   		return r;
> >>>> -	if (amdgpu_vm_debug && p->bo_list) {
> >>>> -		struct amdgpu_bo_list_entry *e;
> >>>> -
> >>>> +	if (amdgpu_vm_debug) {
> >>>>   		/* Invalidate all BOs to test for userspace bugs */
> >>>>   		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
> >>>>   			/* ignore duplicates */
> >>>> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
> >>>>   	struct amdgpu_ring *ring = p->ring;
> >>>>   	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
> >>>>   	enum drm_sched_priority priority;
> >>>> +	struct amdgpu_bo_list_entry *e;
> >>>>   	struct amdgpu_job *job;
> >>>>   	uint64_t seq;
> >>>>   	int r;
> >>>>   	amdgpu_mn_lock(p->mn);
> >>>> -	if (p->bo_list) {
> >>>> -		struct amdgpu_bo_list_entry *e;
> >>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>>> +		struct amdgpu_bo *bo = e->robj;
> >>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
> >>>> -			struct amdgpu_bo *bo = e->robj;
> >>>> -
> >>>> -			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> >>>> -				amdgpu_mn_unlock(p->mn);
> >>>> -				return -ERESTARTSYS;
> >>>> -			}
> >>>> +		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
> >>>> +			amdgpu_mn_unlock(p->mn);
> >>>> +			return -ERESTARTSYS;
> >>>>   		}
> >>>>   	}
> >>>> -- 
> >>>> 2.14.1
> >>>>
> >>>> _______________________________________________
> >>>> amd-gfx mailing list
> >>>> amd-gfx@lists.freedesktop.org
> >>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> >> _______________________________________________
> >> amd-gfx mailing list
> >> amd-gfx@lists.freedesktop.org
> >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> 
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided
  2018-07-31  9:26                   ` Huang Rui
@ 2018-07-31  9:41                     ` Zhang, Jerry (Junwei)
  0 siblings, 0 replies; 26+ messages in thread
From: Zhang, Jerry (Junwei) @ 2018-07-31  9:41 UTC (permalink / raw)
  To: Huang Rui, Koenig, Christian; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 07/31/2018 05:26 PM, Huang Rui wrote:
> On Tue, Jul 31, 2018 at 05:00:46PM +0800, Koenig, Christian wrote:
>> Am 31.07.2018 um 11:09 schrieb Huang Rui:
>>> On Tue, Jul 31, 2018 at 10:52:06AM +0200, Christian König wrote:
>>>> Am 31.07.2018 um 09:51 schrieb Huang Rui:
>>>>> On Mon, Jul 30, 2018 at 04:51:59PM +0200, Christian König wrote:
>>>>>> Instead of having extra handling just create an empty bo_list when no
>>>>>> handle is provided.
>>>>> Reviewed-by: Huang Rui <ray.huang@amd.com>
>>>>>
>>>>> In which case, when the command is being submitted, there is no bo list
>>>>> handle? All BOs are per-VM, no shared BO?
>>>> Yes, exactly. Or in the future just SVM etc...
>>>>
>>> "SVM" means single VM? Only one thread?
>>
>> Shared Virtual Memory, e.g. the GPU uses the virtual CPU address space.
>>
>> Can be implemented using the ATC or starting with Vega10 using HMM.
>>
>
> Oh, I remembered it should be a proposal for apu such as raven, you know,
> the vram is actually carved out from a part of system memory in raven.

That's a feature in OpenCL 2.0

Regards,
Jerry

>
> Thanks,
> Ray
>
>> Regards,
>> Christian.
>>
>>>
>>> Thanks,
>>> Ray
>>>
>>>> Christian.
>>>>
>>>>> Thanks,
>>>>> Ray
>>>>>
>>>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>>>> ---
>>>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 ++++++++++++++-------------------
>>>>>>    1 file changed, 46 insertions(+), 65 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>>>> index 1d7292ab2b62..502b94fb116a 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>>>>> @@ -561,6 +561,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>>>    				union drm_amdgpu_cs *cs)
>>>>>>    {
>>>>>>    	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>>>>> +	struct amdgpu_vm *vm = &fpriv->vm;
>>>>>>    	struct amdgpu_bo_list_entry *e;
>>>>>>    	struct list_head duplicates;
>>>>>>    	struct amdgpu_bo *gds;
>>>>>> @@ -580,13 +581,17 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>>>    				       &p->bo_list);
>>>>>>    		if (r)
>>>>>>    			return r;
>>>>>> +	} else if (!p->bo_list) {
>>>>>> +		/* Create a empty bo_list when no handle is provided */
>>>>>> +		r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
>>>>>> +					  &p->bo_list);
>>>>>> +		if (r)
>>>>>> +			return r;
>>>>>>    	}
>>>>>> -	if (p->bo_list) {
>>>>>> -		amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>>>>> -		if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>>>>> -			p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>>>>> -	}
>>>>>> +	amdgpu_bo_list_get_list(p->bo_list, &p->validated);
>>>>>> +	if (p->bo_list->first_userptr != p->bo_list->num_entries)
>>>>>> +		p->mn = amdgpu_mn_get(p->adev, AMDGPU_MN_TYPE_GFX);
>>>>>>    	INIT_LIST_HEAD(&duplicates);
>>>>>>    	amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
>>>>>> @@ -605,10 +610,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>>>    			goto error_free_pages;
>>>>>>    		}
>>>>>> -		/* Without a BO list we don't have userptr BOs */
>>>>>> -		if (!p->bo_list)
>>>>>> -			break;
>>>>>> -
>>>>>>    		INIT_LIST_HEAD(&need_pages);
>>>>>>    		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>>>    			struct amdgpu_bo *bo = e->robj;
>>>>>> @@ -703,21 +704,12 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>>>    	amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>>>>>>    				     p->bytes_moved_vis);
>>>>>> -	if (p->bo_list) {
>>>>>> -		struct amdgpu_vm *vm = &fpriv->vm;
>>>>>> -		struct amdgpu_bo_list_entry *e;
>>>>>> +	gds = p->bo_list->gds_obj;
>>>>>> +	gws = p->bo_list->gws_obj;
>>>>>> +	oa = p->bo_list->oa_obj;
>>>>>> -		gds = p->bo_list->gds_obj;
>>>>>> -		gws = p->bo_list->gws_obj;
>>>>>> -		oa = p->bo_list->oa_obj;
>>>>>> -
>>>>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>>>>> -			e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>>>>> -	} else {
>>>>>> -		gds = p->adev->gds.gds_gfx_bo;
>>>>>> -		gws = p->adev->gds.gws_gfx_bo;
>>>>>> -		oa = p->adev->gds.oa_gfx_bo;
>>>>>> -	}
>>>>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list)
>>>>>> +		e->bo_va = amdgpu_vm_bo_find(vm, e->robj);
>>>>>>    	if (gds) {
>>>>>>    		p->job->gds_base = amdgpu_bo_gpu_offset(gds);
>>>>>> @@ -745,15 +737,13 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>>>>>>    error_free_pages:
>>>>>> -	if (p->bo_list) {
>>>>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>>> -			if (!e->user_pages)
>>>>>> -				continue;
>>>>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>>> +		if (!e->user_pages)
>>>>>> +			continue;
>>>>>> -			release_pages(e->user_pages,
>>>>>> -				      e->robj->tbo.ttm->num_pages);
>>>>>> -			kvfree(e->user_pages);
>>>>>> -		}
>>>>>> +		release_pages(e->user_pages,
>>>>>> +			      e->robj->tbo.ttm->num_pages);
>>>>>> +		kvfree(e->user_pages);
>>>>>>    	}
>>>>>>    	return r;
>>>>>> @@ -815,9 +805,10 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>>>>>>    static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>>>    {
>>>>>> -	struct amdgpu_device *adev = p->adev;
>>>>>>    	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
>>>>>> +	struct amdgpu_device *adev = p->adev;
>>>>>>    	struct amdgpu_vm *vm = &fpriv->vm;
>>>>>> +	struct amdgpu_bo_list_entry *e;
>>>>>>    	struct amdgpu_bo_va *bo_va;
>>>>>>    	struct amdgpu_bo *bo;
>>>>>>    	int r;
>>>>>> @@ -850,31 +841,26 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>>>    			return r;
>>>>>>    	}
>>>>>> -	if (p->bo_list) {
>>>>>> -		struct amdgpu_bo_list_entry *e;
>>>>>> -
>>>>>> -		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>>>> -			struct dma_fence *f;
>>>>>> -
>>>>>> -			/* ignore duplicates */
>>>>>> -			bo = e->robj;
>>>>>> -			if (!bo)
>>>>>> -				continue;
>>>>>> +	amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>>>> +		struct dma_fence *f;
>>>>>> -			bo_va = e->bo_va;
>>>>>> -			if (bo_va == NULL)
>>>>>> -				continue;
>>>>>> +		/* ignore duplicates */
>>>>>> +		bo = e->robj;
>>>>>> +		if (!bo)
>>>>>> +			continue;
>>>>>> -			r = amdgpu_vm_bo_update(adev, bo_va, false);
>>>>>> -			if (r)
>>>>>> -				return r;
>>>>>> +		bo_va = e->bo_va;
>>>>>> +		if (bo_va == NULL)
>>>>>> +			continue;
>>>>>> -			f = bo_va->last_pt_update;
>>>>>> -			r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>>>>> -			if (r)
>>>>>> -				return r;
>>>>>> -		}
>>>>>> +		r = amdgpu_vm_bo_update(adev, bo_va, false);
>>>>>> +		if (r)
>>>>>> +			return r;
>>>>>> +		f = bo_va->last_pt_update;
>>>>>> +		r = amdgpu_sync_fence(adev, &p->job->sync, f, false);
>>>>>> +		if (r)
>>>>>> +			return r;
>>>>>>    	}
>>>>>>    	r = amdgpu_vm_handle_moved(adev, vm);
>>>>>> @@ -889,9 +875,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
>>>>>>    	if (r)
>>>>>>    		return r;
>>>>>> -	if (amdgpu_vm_debug && p->bo_list) {
>>>>>> -		struct amdgpu_bo_list_entry *e;
>>>>>> -
>>>>>> +	if (amdgpu_vm_debug) {
>>>>>>    		/* Invalidate all BOs to test for userspace bugs */
>>>>>>    		amdgpu_bo_list_for_each_entry(e, p->bo_list) {
>>>>>>    			/* ignore duplicates */
>>>>>> @@ -1217,22 +1201,19 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>>>>>>    	struct amdgpu_ring *ring = p->ring;
>>>>>>    	struct drm_sched_entity *entity = &p->ctx->rings[ring->idx].entity;
>>>>>>    	enum drm_sched_priority priority;
>>>>>> +	struct amdgpu_bo_list_entry *e;
>>>>>>    	struct amdgpu_job *job;
>>>>>>    	uint64_t seq;
>>>>>>    	int r;
>>>>>>    	amdgpu_mn_lock(p->mn);
>>>>>> -	if (p->bo_list) {
>>>>>> -		struct amdgpu_bo_list_entry *e;
>>>>>> +	amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>>> +		struct amdgpu_bo *bo = e->robj;
>>>>>> -		amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
>>>>>> -			struct amdgpu_bo *bo = e->robj;
>>>>>> -
>>>>>> -			if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>>>>> -				amdgpu_mn_unlock(p->mn);
>>>>>> -				return -ERESTARTSYS;
>>>>>> -			}
>>>>>> +		if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
>>>>>> +			amdgpu_mn_unlock(p->mn);
>>>>>> +			return -ERESTARTSYS;
>>>>>>    		}
>>>>>>    	}
>>>>>> --
>>>>>> 2.14.1
>>>>>>
>>>>>> _______________________________________________
>>>>>> amd-gfx mailing list
>>>>>> amd-gfx@lists.freedesktop.org
>>>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>>>> _______________________________________________
>>>> amd-gfx mailing list
>>>> amd-gfx@lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list
       [not found]           ` <79923ec6-25d0-f80a-d631-79a1faa91a0e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-07-31 10:23             ` Huang Rui
  0 siblings, 0 replies; 26+ messages in thread
From: Huang Rui @ 2018-07-31 10:23 UTC (permalink / raw)
  To: Koenig, Christian; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Tue, Jul 31, 2018 at 03:04:42PM +0800, Christian König wrote:
> Am 31.07.2018 um 09:12 schrieb Huang Rui:
> > On Mon, Jul 30, 2018 at 04:51:58PM +0200, Christian König wrote:
> >> This avoids multiple allocations for the head and the array.
> >>
> > I am afraid I don't get the point that how to avoid multiple times of
> > allocations. Could you please explain more?
> 
> Allocating the head and the array separately has more overhead because 
> you need to do two allocations.
> 

I see. You allocated the whole memory include bo_list(head) and all number
of bo_list_entry one time, then use amdgpu_bo_list_array_entry to get the
array.

Acked-by: Huang Rui <ray.huang@amd.com>

> I should probably update the commit message,
> Christian.
> 
> >
> > Thanks,
> > Ray
> >
> >> Signed-off-by: Christian König <christian.koenig@amd.com>
> >> ---
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 114 +++++++++++-----------------
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  17 +++--
> >>   2 files changed, 57 insertions(+), 74 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> >> index 096bcf4a6334..d472a2c8399f 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> >> @@ -35,13 +35,15 @@
> >>   #define AMDGPU_BO_LIST_MAX_PRIORITY	32u
> >>   #define AMDGPU_BO_LIST_NUM_BUCKETS	(AMDGPU_BO_LIST_MAX_PRIORITY + 1)
> >>   
> >> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
> >> -				     struct drm_file *filp,
> >> -				     struct amdgpu_bo_list *list,
> >> -				     struct drm_amdgpu_bo_list_entry *info,
> >> -				     unsigned num_entries);
> >> +static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
> >> +{
> >> +	struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
> >> +						   rhead);
> >> +
> >> +	kvfree(list);
> >> +}
> >>   
> >> -static void amdgpu_bo_list_release_rcu(struct kref *ref)
> >> +static void amdgpu_bo_list_free(struct kref *ref)
> >>   {
> >>   	struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
> >>   						   refcount);
> >> @@ -50,67 +52,36 @@ static void amdgpu_bo_list_release_rcu(struct kref *ref)
> >>   	amdgpu_bo_list_for_each_entry(e, list)
> >>   		amdgpu_bo_unref(&e->robj);
> >>   
> >> -	kvfree(list->array);
> >> -	kfree_rcu(list, rhead);
> >> +	call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
> >>   }
> >>   
> >> -int amdgpu_bo_list_create(struct amdgpu_device *adev,
> >> -				 struct drm_file *filp,
> >> -				 struct drm_amdgpu_bo_list_entry *info,
> >> -				 unsigned num_entries,
> >> -				 struct amdgpu_bo_list **list_out)
> >> +int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
> >> +			  struct drm_amdgpu_bo_list_entry *info,
> >> +			  unsigned num_entries, struct amdgpu_bo_list **result)
> >>   {
> >> +	unsigned last_entry = 0, first_userptr = num_entries;
> >> +	struct amdgpu_bo_list_entry *array;
> >>   	struct amdgpu_bo_list *list;
> >> +	uint64_t total_size = 0;
> >> +	size_t size;
> >> +	unsigned i;
> >>   	int r;
> >>   
> >> +	if (num_entries > SIZE_MAX / sizeof(struct amdgpu_bo_list_entry))
> >> +		return -EINVAL;
> >>   
> >> -	list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
> >> +	size = sizeof(struct amdgpu_bo_list);
> >> +	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
> >> +	list = kvmalloc(size, GFP_KERNEL);
> >>   	if (!list)
> >>   		return -ENOMEM;
> >>   
> >> -	/* initialize bo list*/
> >>   	kref_init(&list->refcount);
> >> -	r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
> >> -	if (r) {
> >> -		kfree(list);
> >> -		return r;
> >> -	}
> >> -
> >> -	*list_out = list;
> >> -	return 0;
> >> -}
> >> -
> >> -static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
> >> -{
> >> -	struct amdgpu_bo_list *list;
> >> -
> >> -	mutex_lock(&fpriv->bo_list_lock);
> >> -	list = idr_remove(&fpriv->bo_list_handles, id);
> >> -	mutex_unlock(&fpriv->bo_list_lock);
> >> -	if (list)
> >> -		kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
> >> -}
> >> -
> >> -static int amdgpu_bo_list_set(struct amdgpu_device *adev,
> >> -				     struct drm_file *filp,
> >> -				     struct amdgpu_bo_list *list,
> >> -				     struct drm_amdgpu_bo_list_entry *info,
> >> -				     unsigned num_entries)
> >> -{
> >> -	struct amdgpu_bo_list_entry *array;
> >> -	struct amdgpu_bo *gds_obj = adev->gds.gds_gfx_bo;
> >> -	struct amdgpu_bo *gws_obj = adev->gds.gws_gfx_bo;
> >> -	struct amdgpu_bo *oa_obj = adev->gds.oa_gfx_bo;
> >> -
> >> -	unsigned last_entry = 0, first_userptr = num_entries;
> >> -	struct amdgpu_bo_list_entry *e;
> >> -	uint64_t total_size = 0;
> >> -	unsigned i;
> >> -	int r;
> >> +	list->gds_obj = adev->gds.gds_gfx_bo;
> >> +	list->gws_obj = adev->gds.gws_gfx_bo;
> >> +	list->oa_obj = adev->gds.oa_gfx_bo;
> >>   
> >> -	array = kvmalloc_array(num_entries, sizeof(struct amdgpu_bo_list_entry), GFP_KERNEL);
> >> -	if (!array)
> >> -		return -ENOMEM;
> >> +	array = amdgpu_bo_list_array_entry(list, 0);
> >>   	memset(array, 0, num_entries * sizeof(struct amdgpu_bo_list_entry));
> >>   
> >>   	for (i = 0; i < num_entries; ++i) {
> >> @@ -147,36 +118,41 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
> >>   		entry->tv.shared = !entry->robj->prime_shared_count;
> >>   
> >>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
> >> -			gds_obj = entry->robj;
> >> +			list->gds_obj = entry->robj;
> >>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_GWS)
> >> -			gws_obj = entry->robj;
> >> +			list->gws_obj = entry->robj;
> >>   		if (entry->robj->preferred_domains == AMDGPU_GEM_DOMAIN_OA)
> >> -			oa_obj = entry->robj;
> >> +			list->oa_obj = entry->robj;
> >>   
> >>   		total_size += amdgpu_bo_size(entry->robj);
> >>   		trace_amdgpu_bo_list_set(list, entry->robj);
> >>   	}
> >>   
> >> -	amdgpu_bo_list_for_each_entry(e, list)
> >> -		amdgpu_bo_unref(&list->array[i].robj);
> >> -
> >> -	kvfree(list->array);
> >> -
> >> -	list->gds_obj = gds_obj;
> >> -	list->gws_obj = gws_obj;
> >> -	list->oa_obj = oa_obj;
> >>   	list->first_userptr = first_userptr;
> >> -	list->array = array;
> >>   	list->num_entries = num_entries;
> >>   
> >>   	trace_amdgpu_cs_bo_status(list->num_entries, total_size);
> >> +
> >> +	*result = list;
> >>   	return 0;
> >>   
> >>   error_free:
> >>   	while (i--)
> >>   		amdgpu_bo_unref(&array[i].robj);
> >> -	kvfree(array);
> >> +	kvfree(list);
> >>   	return r;
> >> +
> >> +}
> >> +
> >> +static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
> >> +{
> >> +	struct amdgpu_bo_list *list;
> >> +
> >> +	mutex_lock(&fpriv->bo_list_lock);
> >> +	list = idr_remove(&fpriv->bo_list_handles, id);
> >> +	mutex_unlock(&fpriv->bo_list_lock);
> >> +	if (list)
> >> +		kref_put(&list->refcount, amdgpu_bo_list_free);
> >>   }
> >>   
> >>   int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> >> @@ -229,7 +205,7 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
> >>   
> >>   void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
> >>   {
> >> -	kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
> >> +	kref_put(&list->refcount, amdgpu_bo_list_free);
> >>   }
> >>   
> >>   int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> >> index 3d77abfcd4a6..61b089768e1c 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> >> @@ -48,7 +48,6 @@ struct amdgpu_bo_list {
> >>   	struct amdgpu_bo *oa_obj;
> >>   	unsigned first_userptr;
> >>   	unsigned num_entries;
> >> -	struct amdgpu_bo_list_entry *array;
> >>   };
> >>   
> >>   int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> >> @@ -65,14 +64,22 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,
> >>   				 unsigned num_entries,
> >>   				 struct amdgpu_bo_list **list);
> >>   
> >> +static inline struct amdgpu_bo_list_entry *
> >> +amdgpu_bo_list_array_entry(struct amdgpu_bo_list *list, unsigned index)
> >> +{
> >> +	struct amdgpu_bo_list_entry *array = (void *)&list[1];
> >> +
> >> +	return &array[index];
> >> +}
> >> +
> >>   #define amdgpu_bo_list_for_each_entry(e, list) \
> >> -	for (e = &(list)->array[0]; \
> >> -	     e != &(list)->array[(list)->num_entries]; \
> >> +	for (e = amdgpu_bo_list_array_entry(list, 0); \
> >> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
> >>   	     ++e)
> >>   
> >>   #define amdgpu_bo_list_for_each_userptr_entry(e, list) \
> >> -	for (e = &(list)->array[(list)->first_userptr]; \
> >> -	     e != &(list)->array[(list)->num_entries]; \
> >> +	for (e = amdgpu_bo_list_array_entry(list, (list)->first_userptr); \
> >> +	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
> >>   	     ++e)
> >>   
> >>   #endif
> >> -- 
> >> 2.14.1
> >>
> >> _______________________________________________
> >> amd-gfx mailing list
> >> amd-gfx@lists.freedesktop.org
> >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> 
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2018-07-31 10:23 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30 14:51 [PATCH 1/9] drm/amdgpu: fix total size calculation Christian König
     [not found] ` <20180730145159.13212-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-30 14:51   ` [PATCH 2/9] drm/amdgpu: return error if both BOs and bo_list handle is given Christian König
     [not found]     ` <20180730145159.13212-2-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  2:44       ` Huang Rui
2018-07-30 14:51   ` [PATCH 3/9] drm/amdgpu: add new amdgpu_vm_bo_trace_cs() function v2 Christian König
2018-07-30 14:51   ` [PATCH 4/9] drm/amdgpu: move bo_list defines to amdgpu_bo_list.h Christian König
     [not found]     ` <20180730145159.13212-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  2:52       ` Huang Rui
2018-07-30 14:51   ` [PATCH 5/9] drm/amdgpu: always recreate bo_list Christian König
     [not found]     ` <20180730145159.13212-5-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  5:29       ` Huang Rui
2018-07-30 14:51   ` [PATCH 6/9] drm/amdgpu: nuke amdgpu_bo_list_free Christian König
     [not found]     ` <20180730145159.13212-6-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  5:31       ` Huang Rui
2018-07-30 14:51   ` [PATCH 7/9] drm/amdgpu: add bo_list iterators Christian König
     [not found]     ` <20180730145159.13212-7-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  6:12       ` Huang Rui
2018-07-30 14:51   ` [PATCH 8/9] drm/amdgpu: allocate the bo_list array after the list Christian König
     [not found]     ` <20180730145159.13212-8-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  7:12       ` Huang Rui
2018-07-31  7:04         ` Christian König
     [not found]           ` <79923ec6-25d0-f80a-d631-79a1faa91a0e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31 10:23             ` Huang Rui
2018-07-30 14:51   ` [PATCH 9/9] drm/amdgpu: create an empty bo_list if no handle is provided Christian König
     [not found]     ` <20180730145159.13212-9-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-31  1:31       ` Zhou, David(ChunMing)
2018-07-31  7:51       ` Huang Rui
2018-07-31  8:52         ` Christian König
     [not found]           ` <c630d2c3-25c8-b532-1a1c-07626f82ea12-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-07-31  9:00             ` Zhang, Jerry (Junwei)
2018-07-31  9:09             ` Huang Rui
2018-07-31  9:00               ` Christian König
     [not found]                 ` <e35b8029-27d0-fc97-64c2-64f4379eeda8-5C7GfCeVMHo@public.gmane.org>
2018-07-31  9:26                   ` Huang Rui
2018-07-31  9:41                     ` Zhang, Jerry (Junwei)
2018-07-31  2:34   ` [PATCH 1/9] drm/amdgpu: fix total size calculation Huang Rui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.