Skip to content

Commit fe7b436

Browse files
trusinowiczjfvogel
authored andcommitted
accel/ivpu: Make DB_ID and JOB_ID allocations incremental
commit c3b0ec0 upstream. Save last used ID and use it to limit the possible values for the ID. This should decrease the rate at which the IDs are reused, which will make debugging easier. Signed-off-by: Tomasz Rusinowicz <[email protected]> Reviewed-by: Jacek Lawrynowicz <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Jacek Lawrynowicz <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit aaba59961d4372e3388ec38b73f210b3b8b9346f) Signed-off-by: Jack Vogel <[email protected]>
1 parent cbc891f commit fe7b436

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

drivers/accel/ivpu/ivpu_drv.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ 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;
267+
263268
mutex_unlock(&vdev->context_list_lock);
264269
drm_dev_exit(idx);
265270

@@ -607,6 +612,10 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
607612
lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);
608613
INIT_LIST_HEAD(&vdev->bo_list);
609614

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;
618+
610619
ret = drmm_mutex_init(&vdev->drm, &vdev->context_list_lock);
611620
if (ret)
612621
goto err_xa_destroy;

drivers/accel/ivpu/ivpu_drv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#define IVPU_MIN_DB 1
4747
#define IVPU_MAX_DB 255
4848

49+
#define IVPU_JOB_ID_JOB_MASK GENMASK(7, 0)
50+
#define IVPU_JOB_ID_CONTEXT_MASK GENMASK(31, 8)
51+
4952
#define IVPU_NUM_ENGINES 2
5053
#define IVPU_NUM_PRIORITIES 4
5154
#define IVPU_NUM_CMDQS_PER_CTX (IVPU_NUM_ENGINES * IVPU_NUM_PRIORITIES)
@@ -136,6 +139,8 @@ struct ivpu_device {
136139
struct xa_limit context_xa_limit;
137140

138141
struct xarray db_xa;
142+
struct xa_limit db_limit;
143+
struct xa_limit default_db_limit;
139144

140145
struct mutex bo_list_lock; /* Protects bo_list */
141146
struct list_head bo_list;
@@ -171,6 +176,8 @@ struct ivpu_file_priv {
171176
struct mutex ms_lock; /* Protects ms_instance_list, ms_info_bo */
172177
struct list_head ms_instance_list;
173178
struct ivpu_bo *ms_info_bo;
179+
struct xa_limit job_limit;
180+
struct xa_limit default_job_limit;
174181
bool has_mmu_faults;
175182
bool bound;
176183
bool aborted;

drivers/accel/ivpu/ivpu_job.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "vpu_boot_api.h"
2222

2323
#define CMD_BUF_IDX 0
24-
#define JOB_ID_JOB_MASK GENMASK(7, 0)
25-
#define JOB_ID_CONTEXT_MASK GENMASK(31, 8)
2624
#define JOB_MAX_BUFFER_COUNT 65535
2725

2826
static void ivpu_cmdq_ring_db(struct ivpu_device *vdev, struct ivpu_cmdq *cmdq)
@@ -77,9 +75,28 @@ static void ivpu_preemption_buffers_free(struct ivpu_device *vdev,
7775
ivpu_bo_free(cmdq->secondary_preempt_buf);
7876
}
7977

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+
8098
static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
8199
{
82-
struct xa_limit db_xa_limit = {.max = IVPU_MAX_DB, .min = IVPU_MIN_DB};
83100
struct ivpu_device *vdev = file_priv->vdev;
84101
struct ivpu_cmdq *cmdq;
85102
int ret;
@@ -88,7 +105,10 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
88105
if (!cmdq)
89106
return NULL;
90107

91-
ret = xa_alloc(&vdev->db_xa, &cmdq->db_id, NULL, db_xa_limit, GFP_KERNEL);
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);
92112
if (ret) {
93113
ivpu_err(vdev, "Failed to allocate doorbell id: %d\n", ret);
94114
goto err_free_cmdq;
@@ -519,7 +539,6 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
519539
{
520540
struct ivpu_file_priv *file_priv = job->file_priv;
521541
struct ivpu_device *vdev = job->vdev;
522-
struct xa_limit job_id_range;
523542
struct ivpu_cmdq *cmdq;
524543
bool is_first_job;
525544
int ret;
@@ -530,20 +549,18 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
530549

531550
mutex_lock(&file_priv->lock);
532551

533-
cmdq = ivpu_cmdq_acquire(job->file_priv, job->engine_idx, priority);
552+
cmdq = ivpu_cmdq_acquire(file_priv, job->engine_idx, priority);
534553
if (!cmdq) {
535554
ivpu_warn_ratelimited(vdev, "Failed to get job queue, ctx %d engine %d prio %d\n",
536555
file_priv->ctx.id, job->engine_idx, priority);
537556
ret = -EINVAL;
538557
goto err_unlock_file_priv;
539558
}
540559

541-
job_id_range.min = FIELD_PREP(JOB_ID_CONTEXT_MASK, (file_priv->ctx.id - 1));
542-
job_id_range.max = job_id_range.min | JOB_ID_JOB_MASK;
543-
544560
xa_lock(&vdev->submitted_jobs_xa);
545561
is_first_job = xa_empty(&vdev->submitted_jobs_xa);
546-
ret = __xa_alloc(&vdev->submitted_jobs_xa, &job->job_id, job, job_id_range, GFP_KERNEL);
562+
ret = ivpu_id_alloc(&vdev->submitted_jobs_xa, &job->job_id, job, &file_priv->job_limit,
563+
file_priv->default_job_limit);
547564
if (ret) {
548565
ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
549566
file_priv->ctx.id);

0 commit comments

Comments
 (0)