Commit 99eea4df authored by Alex Xie's avatar Alex Xie Committed by Alex Deucher

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.
Signed-off-by: default avatarAlex Xie <AlexBin.Xie@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
parent 660e8558
...@@ -35,33 +35,45 @@ ...@@ -35,33 +35,45 @@
#define AMDGPU_BO_LIST_MAX_PRIORITY 32u #define AMDGPU_BO_LIST_MAX_PRIORITY 32u
#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1) #define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1)
static int amdgpu_bo_list_create(struct amdgpu_fpriv *fpriv, static int amdgpu_bo_list_set(struct amdgpu_device *adev,
struct amdgpu_bo_list **result, 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 *id)
{ {
int r; int r;
struct amdgpu_fpriv *fpriv = filp->driver_priv;
struct amdgpu_bo_list *list;
*result = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL); list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
if (!*result) if (!list)
return -ENOMEM; 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); mutex_lock(&fpriv->bo_list_lock);
r = idr_alloc(&fpriv->bo_list_handles, *result, r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
1, 0, GFP_KERNEL);
if (r < 0) {
mutex_unlock(&fpriv->bo_list_lock); mutex_unlock(&fpriv->bo_list_lock);
kfree(*result); if (r < 0) {
kfree(list);
return r; return r;
} }
*id = 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; return 0;
} }
...@@ -77,6 +89,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id) ...@@ -77,6 +89,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
mutex_unlock(&list->lock); mutex_unlock(&list->lock);
amdgpu_bo_list_free(list); amdgpu_bo_list_free(list);
} }
mutex_unlock(&fpriv->bo_list_lock); mutex_unlock(&fpriv->bo_list_lock);
} }
...@@ -273,16 +286,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, ...@@ -273,16 +286,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
switch (args->in.operation) { switch (args->in.operation) {
case AMDGPU_BO_LIST_OP_CREATE: 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) if (r)
goto error_free; 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; break;
case AMDGPU_BO_LIST_OP_DESTROY: case AMDGPU_BO_LIST_OP_DESTROY:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment