drm/amdgpu: Optimization of AMDGPU_BO_LIST_OP_CREATE (v2)
Subsystems (2)
PATCH 1/2 drm/amdgpu: Optimization of AMDGPU_BO_LIST_OP_CREATE (v2)
v2: Remove duplication of zeroing of bo list (Christian König)
Move idr_alloc function to end of ioctl (Christian König) Call kfree bo_list when amdgpu_bo_list_set return error. Combine the previous two patches into this patch. Add amdgpu_bo_list_set function prototype.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 53 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +30 -23
@@ -35,33 +35,45 @@#define AMDGPU_BO_LIST_MAX_PRIORITY 32u#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1) -static int amdgpu_bo_list_create (struct amdgpu_fpriv *fpriv, -struct amdgpu_bo_list **result, +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 int amdgpu_bo_list_create (struct amdgpu_device *adev, +struct drm_file *filp, +struct drm_amdgpu_bo_list_entry *info, +unsigned num_entries,int *id) {int r; +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_bo_list *list; - *result =kzalloc (sizeof (struct amdgpu_bo_list ),GFP_KERNEL ); -if (!*result) + list =kzalloc (sizeof (struct amdgpu_bo_list ),GFP_KERNEL ); +if (!list)return -ENOMEM ; +/* initialize bo list*/ +mutex_init (&list->lock); + + r =amdgpu_bo_list_set (adev, filp, list, info, num_entries); +if (r) { +kfree (list); +return r; + } + +/* idr alloc should be called only after initialization of bo list. */ mutex_lock (&fpriv->bo_list_lock); - r =idr_alloc (&fpriv->bo_list_handles, *result, -1 ,0 ,GFP_KERNEL ); + r =idr_alloc (&fpriv->bo_list_handles, list,1 ,0 ,GFP_KERNEL ); +mutex_unlock (&fpriv->bo_list_lock);if (r <0 ) { -mutex_unlock (&fpriv->bo_list_lock); -kfree (*result); +kfree (list);return r; } *id = r; -mutex_init (&(*result)->lock); - (*result)->num_entries =0 ; - (*result)->array =NULL ; - -mutex_lock (&(*result)->lock); -mutex_unlock (&fpriv->bo_list_lock); -return 0 ; }
@@ -77,6 +89,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)mutex_unlock (&list->lock);amdgpu_bo_list_free (list); } +mutex_unlock (&fpriv->bo_list_lock); }
@@ -273,16 +286,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,switch (args->in.operation) {case AMDGPU_BO_LIST_OP_CREATE : - r =amdgpu_bo_list_create (fpriv, &list, &handle); + r =amdgpu_bo_list_create (adev, filp, info, args->in.bo_number, + &handle);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) - goto error_free; -break ;case AMDGPU_BO_LIST_OP_DESTROY :
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1497589410-17779-1-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdgpu: Optimize mutex usage (v2)
Use rw_semaphore instead of mutex for bo_lists.
In original function amdgpu_bo_list_get, the waiting for result->lock can be quite long while mutex bo_list_lock was holding. It can make other tasks waiting for bo_list_lock for long period too. Change bo_list_lock to rw_semaphore can avoid most of such long waiting.
Secondly, this patch allows several tasks(readers of idr) to proceed at the same time.
v2: use rcu and kref (Dave Airlie and Christian König)
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 40 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -871,6 +871,8 @@ struct amdgpu_fpriv {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;
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +28 -12
@@ -41,6 +41,20 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,struct drm_amdgpu_bo_list_entry *info, unsigned num_entries); +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); + +for (i =0 ; i < list->num_entries; ++i) +amdgpu_bo_unref (&list->array[i].robj); + +mutex_destroy (&list->lock); +drm_free_large (list->array); +kfree_rcu (list, rhead); +} + static int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, struct drm_amdgpu_bo_list_entry *info,
@@ -57,7 +71,7 @@ static int amdgpu_bo_list_create(struct amdgpu_device *adev,/* initialize bo list*/ mutex_init (&list->lock); - +kref_init (&list->refcount); r =amdgpu_bo_list_set (adev, filp, list, info, num_entries);if (r) {kfree (list);
@@ -83,14 +97,9 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)mutex_lock (&fpriv->bo_list_lock); list =idr_remove (&fpriv->bo_list_handles, id); -if (list) { -/* Another user may have a reference to this list still */ -mutex_lock (&list->lock); -mutex_unlock (&list->lock); -amdgpu_bo_list_free (list); - } -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,
@@ -185,11 +194,17 @@ amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) {struct amdgpu_bo_list *result; -mutex_lock (&fpriv->bo_list_lock); +rcu_read_lock (); result =idr_find (&fpriv->bo_list_handles, id); -if (result) -mutex_lock (&result->lock); -mutex_unlock (&fpriv->bo_list_lock); + +if (result) { +if (kref_get_unless_zero (&result->refcount)) +mutex_lock (&result->lock); +else + result =NULL ; + } +rcu_read_unlock (); +return result; }
@@ -227,6 +242,7 @@ 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); }void amdgpu_bo_list_free (struct amdgpu_bo_list *list)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1497589410-17779-2-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: Optimize mutex usage (v2)
Quoted 9 lines · Alex Xie
Use
rw_semaphoreinstead of mutex forbo_lists.In original function
amdgpu_bo_list_get, the waiting forresult->lockcan be quite long while mutexbo_list_lockwas holding. It can make other tasks waiting forbo_list_lockfor long period too. Changebo_list_locktorw_semaphorecan avoid most of such long waiting.
Quoted 4 lines
Secondly, this patch allows several tasks(readers of idr) to proceed at the same time.
v2: use rcu and kref (Dave Airlie and Christian König)
At least the first two paragraphs above are inaccurate and confusing in v2. Please modify the commit log to reflect what the patch actually does now.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/2] drm/amdgpu: Optimize mutex usage (v2)
In reply to a message not in the archiveAm 16.06.2017 um 07:03 schrieb Alex Xie:
Quoted 45 lines
Use
rw_semaphoreinstead of mutex forbo_lists.In original function
amdgpu_bo_list_get, the waiting forresult->lockcan be quite long while mutexbo_list_lockwas holding. It can make other tasks waiting forbo_list_lockfor long period too. Changebo_list_locktorw_semaphorecan avoid most of such long waiting.Secondly, this patch allows several tasks(readers of idr) to proceed at the same time.
v2: use rcu and kref (Dave Airlie and Christian König)
Signed-off-by Alex Xie <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 40 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -871,6 +871,8 @@ struct amdgpu_fpriv {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;drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +4
-0@@ -41,6 +41,20 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,struct drm_amdgpu_bo_list_entry *info, unsigned num_entries); +static void amdgpu_bo_list_release_rcu (struct kref *ref) +{ +unsigned i; + struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c static int amdgpu_bo_list_set(struct amdgpu_device *adev, · line 57
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +10
-0+ refcount); + +for (i =0 ; i < list->num_entries; ++i) +amdgpu_bo_unref (&list->array[i].robj); + +mutex_destroy (&list->lock); +drm_free_large (list->array); +kfree_rcu (list, rhead); +} +
I'm probably missing something here: Why a new function and not change the existing amdgpu_bo_list_free() to use kfree_rcu instead?
Apart from that the patch looks good to me,
Christian.
Quoted 52 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +13
-12static int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, struct drm_amdgpu_bo_list_entry *info,@@ -57,7 +71,7 @@ static int amdgpu_bo_list_create(struct amdgpu_device *adev,/* initialize bo list*/ mutex_init (&list->lock); - +kref_init (&list->refcount); r =amdgpu_bo_list_set (adev, filp, list, info, num_entries);if (r) {kfree (list);@@ -83,14 +97,9 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)mutex_lock (&fpriv->bo_list_lock); list =idr_remove (&fpriv->bo_list_handles, id); -if (list) { -/* Another user may have a reference to this list still */ -mutex_lock (&list->lock); -mutex_unlock (&list->lock); -amdgpu_bo_list_free (list); - } -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,@@ -185,11 +194,17 @@ amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) {struct amdgpu_bo_list *result; -mutex_lock (&fpriv->bo_list_lock); +rcu_read_lock (); result =idr_find (&fpriv->bo_list_handles, id); -if (result) -mutex_lock (&result->lock); -mutex_unlock (&fpriv->bo_list_lock); + +if (result) { +if (kref_get_unless_zero (&result->refcount)) +mutex_lock (&result->lock); +else + result =NULL ; + } +rcu_read_unlock (); +return result; }
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, · line 248
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +1
-0@@ -227,6 +242,7 @@ 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); }void amdgpu_bo_list_free (struct amdgpu_bo_list *list)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 86ceaa66-955d-ada4-358b-24334193a169-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: Optimize mutex usage (v2)
Quoted 60 lines · Christian König
Am 16.06.2017 um 07:03 schrieb Alex Xie:
Quoted 46 lines
Use
rw_semaphoreinstead of mutex forbo_lists.In original function
amdgpu_bo_list_get, the waiting forresult->lockcan be quite long while mutexbo_list_lockwas holding. It can make other tasks waiting forbo_list_lockfor long period too. Changebo_list_locktorw_semaphorecan avoid most of such long waiting.Secondly, this patch allows several tasks(readers of idr) to proceed at the same time.
v2: use rcu and kref (Dave Airlie and Christian König)
Signed-off-by Alex Xie <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 40 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -871,6 +871,8 @@ struct amdgpu_fpriv {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;drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +3
-0@@ -41,6 +41,20 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev, struct drm_amdgpu_bo_list_entry *info, unsigned num_entries); +static void amdgpu_bo_list_release_rcu(struct kref *ref) +{ +unsigned i; + struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c static int amdgpu_bo_list_set(struct amdgpu_device · line 58
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +10
-0+ refcount); + +for (i =0 ; i < list->num_entries; ++i) +amdgpu_bo_unref (&list->array[i].robj); + +mutex_destroy (&list->lock); +drm_free_large (list->array); +kfree_rcu (list, rhead); +} +I'm probably missing something here: Why a new function and not change the existing
amdgpu_bo_list_free()to usekfree_rcuinstead?
Quoted 2 lines
Apart from that the patch looks good to me,
Christian.
amdgpu_bo_list_free() is called by amdgpu_driver_postclose_kms in file amdgpu_kms.c too. For amdgpu_driver_postclose_kms, there is no need to call kfree_rcu. It is more suitable to call kfree.
So we need two different release/free functions. Then I created a new function for kref_put.
Quoted 50 lines
Quoted 50 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +13
-11static int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, struct drm_amdgpu_bo_list_entry *info,@@ -57,7 +71,7 @@ static int amdgpu_bo_list_create(struct amdgpu_device *adev,/* initialize bo list*/ mutex_init (&list->lock); - +kref_init (&list->refcount); r =amdgpu_bo_list_set (adev, filp, list, info, num_entries);if (r) {kfree (list);@@ -83,14 +97,9 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id) mutex_lock(&fpriv->bo_list_lock); list =idr_remove (&fpriv->bo_list_handles, id); -if (list) { -/* Another user may have a reference to this list still */ -mutex_lock (&list->lock); -mutex_unlock (&list->lock); -amdgpu_bo_list_free (list); - } -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,@@ -185,11 +194,17 @@ amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) {struct amdgpu_bo_list *result; -mutex_lock (&fpriv->bo_list_lock); +rcu_read_lock (); result =idr_find (&fpriv->bo_list_handles, id); -if (result) -mutex_lock (&result->lock); -mutex_unlock (&fpriv->bo_list_lock); + +if (result) { +if (kref_get_unless_zero (&result->refcount)) +mutex_lock (&result->lock); +else + result =NULL ; + } +rcu_read_unlock (); +return result; }
Quoted 10 lines
Quoted 8 lines
@@ -227,6 +242,7 @@ void amdgpu_bo_list_get_list(struct
amdgpu_bo_list*list,
voidamdgpu_bo_list_put(struct amdgpu_bo_list *list){ mutex_unlock(&list->lock);+
kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
}
voidamdgpu_bo_list_free(struct amdgpu_bo_list *list)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 07c69549-9ec8-572a-797d-b8fc477f4aa8-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: Optimize mutex usage (v2)
Am 17.06.2017 um 00:00 schrieb axie:
Quoted 63 lines · Christian König
Quoted 60 lines
Am 16.06.2017 um 07:03 schrieb Alex Xie:
Quoted 46 lines
Use
rw_semaphoreinstead of mutex forbo_lists.In original function
amdgpu_bo_list_get, the waiting forresult->lockcan be quite long while mutexbo_list_lockwas holding. It can make other tasks waiting forbo_list_lockfor long period too. Changebo_list_locktorw_semaphorecan avoid most of such long waiting.Secondly, this patch allows several tasks(readers of idr) to proceed at the same time.
v2: use rcu and kref (Dave Airlie and Christian König)
Signed-off-by Alex Xie <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 40 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -871,6 +871,8 @@ struct amdgpu_fpriv {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;drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +3
-0@@ -41,6 +41,20 @@ static int amdgpu_bo_list_set(structamdgpu_device *adev, struct drm_amdgpu_bo_list_entry *info, unsigned num_entries); +static void amdgpu_bo_list_release_rcu(struct kref *ref) +{ +unsigned i; + struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c static int amdgpu_bo_list_set(struct · line 58
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +10
-0+ refcount); + +for (i =0 ; i < list->num_entries; ++i) +amdgpu_bo_unref (&list->array[i].robj); + +mutex_destroy (&list->lock); +drm_free_large (list->array); +kfree_rcu (list, rhead); +} +I'm probably missing something here: Why a new function and not change the existing
amdgpu_bo_list_free()to usekfree_rcuinstead?
Quoted 7 lines
Quoted 2 lines
Apart from that the patch looks good to me,
Christian.
amdgpu_bo_list_free()is called byamdgpu_driver_postclose_kmsin fileamdgpu_kms.ctoo. Foramdgpu_driver_postclose_kms, there is no need to callkfree_rcu. It is more suitable to call kfree.So we need two different release/free functions. Then I created a new function for
kref_put.
Ah, I see. Well call from amdgpu_driver_postclose_kms() is only used when the application crashes and doesn't clean up properly after itself.
Not sure if it's a good idea to duplicate the code because of this. Waiting for an RCU grace period is a no-op in most cases (it's very likely that all other CPUs are doing something in userspace), so kfree_rcu is rather cheap.
Either way the patch is Reviewed-by: Christian König <[email protected]>.
Quoted 62 lines
Quoted 51 lines
Quoted 51 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +13
-11static int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, struct drm_amdgpu_bo_list_entry *info,@@ -57,7 +71,7 @@ static int amdgpu_bo_list_create(struct amdgpu_device *adev,/* initialize bo list*/ mutex_init (&list->lock); - +kref_init (&list->refcount); r =amdgpu_bo_list_set (adev, filp, list, info, num_entries);if (r) {kfree (list);@@ -83,14 +97,9 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id) mutex_lock(&fpriv->bo_list_lock); list =idr_remove (&fpriv->bo_list_handles, id); -if (list) { -/* Another user may have a reference to this list still */ -mutex_lock (&list->lock); -mutex_unlock (&list->lock); -amdgpu_bo_list_free (list); - } -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,@@ -185,11 +194,17 @@ amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) {struct amdgpu_bo_list *result; -mutex_lock (&fpriv->bo_list_lock); +rcu_read_lock (); result =idr_find (&fpriv->bo_list_handles, id); -if (result) -mutex_lock (&result->lock); -mutex_unlock (&fpriv->bo_list_lock); + +if (result) { +if (kref_get_unless_zero (&result->refcount)) +mutex_lock (&result->lock); +else + result =NULL ; + } +rcu_read_unlock (); +return result; }Quoted 10 lines
Quoted 8 lines
@@ -227,6 +242,7 @@ void amdgpu_bo_list_get_list(struct
amdgpu_bo_list*list,
voidamdgpu_bo_list_put(struct amdgpu_bo_list *list){ mutex_unlock(&list->lock);+
kref_put(&list->refcount, amdgpu_bo_list_release_rcu);
}
voidamdgpu_bo_list_free(struct amdgpu_bo_list *list)
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
Reviewed-byAm 16.06.2017 um 07:03 schrieb Alex Xie:
Quoted 7 lines
v2: Remove duplication of zeroing of bo list (Christian König)
Moveidr_allocfunction to end of ioctl (Christian König) Call kfreebo_listwhenamdgpu_bo_list_setreturn error. Combine the previous two patches into this patch. Addamdgpu_bo_list_setfunction prototype.Signed-off-by Alex Xie <[email protected]>
Quoted 86 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 53 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +30
-16@@ -35,33 +35,45 @@#define AMDGPU_BO_LIST_MAX_PRIORITY 32u#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1) -static int amdgpu_bo_list_create (struct amdgpu_fpriv *fpriv, -struct amdgpu_bo_list **result, +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 int amdgpu_bo_list_create (struct amdgpu_device *adev, +struct drm_file *filp, +struct drm_amdgpu_bo_list_entry *info, +unsigned num_entries,int *id) {int r; +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_bo_list *list; - *result =kzalloc (sizeof (struct amdgpu_bo_list ),GFP_KERNEL ); -if (!*result) + list =kzalloc (sizeof (struct amdgpu_bo_list ),GFP_KERNEL ); +if (!list)return -ENOMEM ; +/* initialize bo list*/ +mutex_init (&list->lock); + + r =amdgpu_bo_list_set (adev, filp, list, info, num_entries); +if (r) { +kfree (list); +return r; + } + +/* idr alloc should be called only after initialization of bo list. */ mutex_lock (&fpriv->bo_list_lock); - r =idr_alloc (&fpriv->bo_list_handles, *result, -1 ,0 ,GFP_KERNEL ); + r =idr_alloc (&fpriv->bo_list_handles, list,1 ,0 ,GFP_KERNEL ); +mutex_unlock (&fpriv->bo_list_lock);if (r <0 ) { -mutex_unlock (&fpriv->bo_list_lock); -kfree (*result); +kfree (list);return r; } *id = r; -mutex_init (&(*result)->lock); - (*result)->num_entries =0 ; - (*result)->array =NULL ; - -mutex_lock (&(*result)->lock); -mutex_unlock (&fpriv->bo_list_lock); -return 0 ; }@@ -77,6 +89,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)mutex_unlock (&list->lock);amdgpu_bo_list_free (list); } +mutex_unlock (&fpriv->bo_list_lock); }@@ -273,16 +286,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,switch (args->in.operation) {case AMDGPU_BO_LIST_OP_CREATE : - r =amdgpu_bo_list_create (fpriv, &list, &handle); + r =amdgpu_bo_list_create (adev, filp, info, args->in.bo_number, + &handle);if (r) goto error_free;
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, · line 295
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0
-7- - r =amdgpu_bo_list_set (adev, filp, list, info, - args->in.bo_number); -amdgpu_bo_list_put (list); -if (r) - goto error_free; -break ;case AMDGPU_BO_LIST_OP_DESTROY :
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx