Skip to content

Commit ae7af7d

Browse files
kwachowsjlawryno
authored andcommitted
accel/ivpu: Use xa_alloc_cyclic() instead of custom function
Remove custom ivpu_id_alloc() wrapper used for ID allocations and replace it with standard xa_alloc_cyclic() API. The idea behind ivpu_id_alloc() was to have monotonic IDs, so the driver is easier to debug because same IDs are not reused all over. The same can be achieved just by using appropriate Linux API. Signed-off-by: Karol Wachowski <[email protected]> Reviewed-by: Jacek Lawrynowicz <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Signed-off-by: Jacek Lawrynowicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 1fc65fa commit ae7af7d

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

drivers/accel/ivpu/ivpu_drv.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,8 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file)
256256

257257
ivpu_mmu_context_init(vdev, &file_priv->ctx, ctx_id);
258258

259-
file_priv->default_job_limit.min = FIELD_PREP(IVPU_JOB_ID_CONTEXT_MASK,
260-
(file_priv->ctx.id - 1));
261-
file_priv->default_job_limit.max = file_priv->default_job_limit.min | IVPU_JOB_ID_JOB_MASK;
262-
file_priv->job_limit = file_priv->default_job_limit;
259+
file_priv->job_limit.min = FIELD_PREP(IVPU_JOB_ID_CONTEXT_MASK, (file_priv->ctx.id - 1));
260+
file_priv->job_limit.max = file_priv->job_limit.min | IVPU_JOB_ID_JOB_MASK;
263261

264262
mutex_unlock(&vdev->context_list_lock);
265263
drm_dev_exit(idx);
@@ -618,9 +616,8 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
618616
lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);
619617
INIT_LIST_HEAD(&vdev->bo_list);
620618

621-
vdev->default_db_limit.min = IVPU_MIN_DB;
622-
vdev->default_db_limit.max = IVPU_MAX_DB;
623-
vdev->db_limit = vdev->default_db_limit;
619+
vdev->db_limit.min = IVPU_MIN_DB;
620+
vdev->db_limit.max = IVPU_MAX_DB;
624621

625622
ret = drmm_mutex_init(&vdev->drm, &vdev->context_list_lock);
626623
if (ret)

drivers/accel/ivpu/ivpu_drv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct ivpu_device {
137137

138138
struct xarray db_xa;
139139
struct xa_limit db_limit;
140-
struct xa_limit default_db_limit;
140+
u32 db_next;
141141

142142
struct mutex bo_list_lock; /* Protects bo_list */
143143
struct list_head bo_list;
@@ -174,7 +174,7 @@ struct ivpu_file_priv {
174174
struct list_head ms_instance_list;
175175
struct ivpu_bo *ms_info_bo;
176176
struct xa_limit job_limit;
177-
struct xa_limit default_job_limit;
177+
u32 job_id_next;
178178
bool has_mmu_faults;
179179
bool bound;
180180
bool aborted;

drivers/accel/ivpu/ivpu_job.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,6 @@ static void ivpu_preemption_buffers_free(struct ivpu_device *vdev,
7272
ivpu_bo_free(cmdq->secondary_preempt_buf);
7373
}
7474

75-
static int ivpu_id_alloc(struct xarray *xa, u32 *id, void *entry, struct xa_limit *limit,
76-
const struct xa_limit default_limit)
77-
{
78-
int ret;
79-
80-
ret = __xa_alloc(xa, id, entry, *limit, GFP_KERNEL);
81-
if (ret) {
82-
limit->min = default_limit.min;
83-
ret = __xa_alloc(xa, id, entry, *limit, GFP_KERNEL);
84-
if (ret)
85-
return ret;
86-
}
87-
88-
limit->min = *id + 1;
89-
if (limit->min > limit->max)
90-
limit->min = default_limit.min;
91-
92-
return ret;
93-
}
94-
9575
static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
9676
{
9777
struct ivpu_device *vdev = file_priv->vdev;
@@ -102,11 +82,9 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
10282
if (!cmdq)
10383
return NULL;
10484

105-
xa_lock(&vdev->db_xa); /* lock here to protect db_limit */
106-
ret = ivpu_id_alloc(&vdev->db_xa, &cmdq->db_id, NULL, &vdev->db_limit,
107-
vdev->default_db_limit);
108-
xa_unlock(&vdev->db_xa);
109-
if (ret) {
85+
ret = xa_alloc_cyclic(&vdev->db_xa, &cmdq->db_id, NULL, vdev->db_limit, &vdev->db_next,
86+
GFP_KERNEL);
87+
if (ret < 0) {
11088
ivpu_err(vdev, "Failed to allocate doorbell id: %d\n", ret);
11189
goto err_free_cmdq;
11290
}
@@ -554,9 +532,9 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
554532

555533
xa_lock(&vdev->submitted_jobs_xa);
556534
is_first_job = xa_empty(&vdev->submitted_jobs_xa);
557-
ret = ivpu_id_alloc(&vdev->submitted_jobs_xa, &job->job_id, job, &file_priv->job_limit,
558-
file_priv->default_job_limit);
559-
if (ret) {
535+
ret = __xa_alloc_cyclic(&vdev->submitted_jobs_xa, &job->job_id, job, file_priv->job_limit,
536+
&file_priv->job_id_next, GFP_KERNEL);
537+
if (ret < 0) {
560538
ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
561539
file_priv->ctx.id);
562540
ret = -EBUSY;

0 commit comments

Comments
 (0)