Skip to content

Commit 7ea5416

Browse files
kwachowsjfvogel
authored andcommitted
accel/ivpu: Use xa_alloc_cyclic() instead of custom function
commit ae7af7d upstream. 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] Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit a735c9205dc9a63dd6327f80d589e4555815dde5) Signed-off-by: Jack Vogel <[email protected]>
1 parent fe7b436 commit 7ea5416

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
@@ -260,10 +260,8 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file)
260260
if (ret)
261261
goto err_xa_erase;
262262

263-
file_priv->default_job_limit.min = FIELD_PREP(IVPU_JOB_ID_CONTEXT_MASK,
264-
(file_priv->ctx.id - 1));
265-
file_priv->default_job_limit.max = file_priv->default_job_limit.min | IVPU_JOB_ID_JOB_MASK;
266-
file_priv->job_limit = file_priv->default_job_limit;
263+
file_priv->job_limit.min = FIELD_PREP(IVPU_JOB_ID_CONTEXT_MASK, (file_priv->ctx.id - 1));
264+
file_priv->job_limit.max = file_priv->job_limit.min | IVPU_JOB_ID_JOB_MASK;
267265

268266
mutex_unlock(&vdev->context_list_lock);
269267
drm_dev_exit(idx);
@@ -612,9 +610,8 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
612610
lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);
613611
INIT_LIST_HEAD(&vdev->bo_list);
614612

615-
vdev->default_db_limit.min = IVPU_MIN_DB;
616-
vdev->default_db_limit.max = IVPU_MAX_DB;
617-
vdev->db_limit = vdev->default_db_limit;
613+
vdev->db_limit.min = IVPU_MIN_DB;
614+
vdev->db_limit.max = IVPU_MAX_DB;
618615

619616
ret = drmm_mutex_init(&vdev->drm, &vdev->context_list_lock);
620617
if (ret)

drivers/accel/ivpu/ivpu_drv.h

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

141141
struct xarray db_xa;
142142
struct xa_limit db_limit;
143-
struct xa_limit default_db_limit;
143+
u32 db_next;
144144

145145
struct mutex bo_list_lock; /* Protects bo_list */
146146
struct list_head bo_list;
@@ -177,7 +177,7 @@ struct ivpu_file_priv {
177177
struct list_head ms_instance_list;
178178
struct ivpu_bo *ms_info_bo;
179179
struct xa_limit job_limit;
180-
struct xa_limit default_job_limit;
180+
u32 job_id_next;
181181
bool has_mmu_faults;
182182
bool bound;
183183
bool aborted;

drivers/accel/ivpu/ivpu_job.c

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

78-
static int ivpu_id_alloc(struct xarray *xa, u32 *id, void *entry, struct xa_limit *limit,
79-
const struct xa_limit default_limit)
80-
{
81-
int ret;
82-
83-
ret = __xa_alloc(xa, id, entry, *limit, GFP_KERNEL);
84-
if (ret) {
85-
limit->min = default_limit.min;
86-
ret = __xa_alloc(xa, id, entry, *limit, GFP_KERNEL);
87-
if (ret)
88-
return ret;
89-
}
90-
91-
limit->min = *id + 1;
92-
if (limit->min > limit->max)
93-
limit->min = default_limit.min;
94-
95-
return ret;
96-
}
97-
9878
static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
9979
{
10080
struct ivpu_device *vdev = file_priv->vdev;
@@ -105,11 +85,9 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
10585
if (!cmdq)
10686
return NULL;
10787

108-
xa_lock(&vdev->db_xa); /* lock here to protect db_limit */
109-
ret = ivpu_id_alloc(&vdev->db_xa, &cmdq->db_id, NULL, &vdev->db_limit,
110-
vdev->default_db_limit);
111-
xa_unlock(&vdev->db_xa);
112-
if (ret) {
88+
ret = xa_alloc_cyclic(&vdev->db_xa, &cmdq->db_id, NULL, vdev->db_limit, &vdev->db_next,
89+
GFP_KERNEL);
90+
if (ret < 0) {
11391
ivpu_err(vdev, "Failed to allocate doorbell id: %d\n", ret);
11492
goto err_free_cmdq;
11593
}
@@ -559,9 +537,9 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
559537

560538
xa_lock(&vdev->submitted_jobs_xa);
561539
is_first_job = xa_empty(&vdev->submitted_jobs_xa);
562-
ret = ivpu_id_alloc(&vdev->submitted_jobs_xa, &job->job_id, job, &file_priv->job_limit,
563-
file_priv->default_job_limit);
564-
if (ret) {
540+
ret = __xa_alloc_cyclic(&vdev->submitted_jobs_xa, &job->job_id, job, file_priv->job_limit,
541+
&file_priv->job_id_next, GFP_KERNEL);
542+
if (ret < 0) {
565543
ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
566544
file_priv->ctx.id);
567545
ret = -EBUSY;

0 commit comments

Comments
 (0)