accel/ivpu: Use lazy allocation for doorbell IDs
authorWachowski, Karol <karol.wachowski@intel.com>
Wed, 14 Feb 2024 08:13:02 +0000 (09:13 +0100)
committerJacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Mon, 19 Feb 2024 09:52:35 +0000 (10:52 +0100)
Reserve/allocate and free doorbells for command queues when needed
using xarray. This allows to avoid reserving a doorbell for
a contexts that never issues a job.

Signed-off-by: Wachowski, Karol <karol.wachowski@intel.com>
Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240214081305.290108-6-jacek.lawrynowicz@linux.intel.com
drivers/accel/ivpu/ivpu_drv.c
drivers/accel/ivpu/ivpu_drv.h
drivers/accel/ivpu/ivpu_job.c

index 9418c73ee8ef8ba025ef896ffe218b61b8058f75..a0461e3caeeccc44b3e90748b99edfe4bcbc4c31 100644 (file)
@@ -533,6 +533,7 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
        atomic64_set(&vdev->unique_id_counter, 0);
        xa_init_flags(&vdev->context_xa, XA_FLAGS_ALLOC);
        xa_init_flags(&vdev->submitted_jobs_xa, XA_FLAGS_ALLOC1);
+       xa_init_flags(&vdev->db_xa, XA_FLAGS_ALLOC1);
        lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);
        INIT_LIST_HEAD(&vdev->bo_list);
 
@@ -606,6 +607,7 @@ err_power_down:
        if (IVPU_WA(d3hot_after_power_off))
                pci_set_power_state(to_pci_dev(vdev->drm.dev), PCI_D3hot);
 err_xa_destroy:
+       xa_destroy(&vdev->db_xa);
        xa_destroy(&vdev->submitted_jobs_xa);
        xa_destroy(&vdev->context_xa);
        return ret;
@@ -641,6 +643,8 @@ static void ivpu_dev_fini(struct ivpu_device *vdev)
        ivpu_mmu_reserved_context_fini(vdev);
        ivpu_mmu_global_context_fini(vdev);
 
+       drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->db_xa));
+       xa_destroy(&vdev->db_xa);
        drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa));
        xa_destroy(&vdev->submitted_jobs_xa);
        drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->context_xa));
index 069ace4adb2d19c1a0544333d0da65632c524ea7..03454f16a535bba0fbf256be679b34eb8adc1caa 100644 (file)
@@ -36,6 +36,9 @@
 #define IVPU_USER_CONTEXT_MIN_SSID     2
 #define IVPU_USER_CONTEXT_MAX_SSID     (IVPU_USER_CONTEXT_MIN_SSID + 63)
 
+#define IVPU_MIN_DB 1
+#define IVPU_MAX_DB 255
+
 #define IVPU_NUM_ENGINES 2
 
 #define IVPU_PLATFORM_SILICON 0
@@ -119,6 +122,8 @@ struct ivpu_device {
        struct xarray context_xa;
        struct xa_limit context_xa_limit;
 
+       struct xarray db_xa;
+
        struct mutex bo_list_lock; /* Protects bo_list */
        struct list_head bo_list;
 
index 0440bee3ecafd567da6cbf47584f3daa688b618d..d01a1a5a272d79387118f2e516a5fbeb6347f709 100644 (file)
@@ -30,19 +30,26 @@ static void ivpu_cmdq_ring_db(struct ivpu_device *vdev, struct ivpu_cmdq *cmdq)
 
 static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv, u16 engine)
 {
+       struct xa_limit db_xa_limit = {.max = IVPU_MAX_DB, .min = IVPU_MIN_DB};
        struct ivpu_device *vdev = file_priv->vdev;
        struct vpu_job_queue_header *jobq_header;
        struct ivpu_cmdq *cmdq;
+       int ret;
 
        cmdq = kzalloc(sizeof(*cmdq), GFP_KERNEL);
        if (!cmdq)
                return NULL;
 
+       ret = xa_alloc(&vdev->db_xa, &cmdq->db_id, NULL, db_xa_limit, GFP_KERNEL);
+       if (ret) {
+               ivpu_err(vdev, "Failed to allocate doorbell id: %d\n", ret);
+               goto err_free_cmdq;
+       }
+
        cmdq->mem = ivpu_bo_alloc_internal(vdev, 0, SZ_4K, DRM_IVPU_BO_WC);
        if (!cmdq->mem)
-               goto cmdq_free;
+               goto err_erase_xa;
 
-       cmdq->db_id = file_priv->ctx.id + engine * ivpu_get_context_count(vdev);
        cmdq->entry_count = (u32)((ivpu_bo_size(cmdq->mem) - sizeof(struct vpu_job_queue_header)) /
                                  sizeof(struct vpu_job_queue_entry));
 
@@ -55,7 +62,9 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv, u16 e
 
        return cmdq;
 
-cmdq_free:
+err_erase_xa:
+       xa_erase(&vdev->db_xa, cmdq->db_id);
+err_free_cmdq:
        kfree(cmdq);
        return NULL;
 }
@@ -66,6 +75,7 @@ static void ivpu_cmdq_free(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *c
                return;
 
        ivpu_bo_free_internal(cmdq->mem);
+       xa_erase(&file_priv->vdev->db_xa, cmdq->db_id);
        kfree(cmdq);
 }