All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Falkowski <maciej.falkowski@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: oded.gabbay@gmail.com, quic_jhugo@quicinc.com,
	jacek.lawrynowicz@linux.intel.com,
	Karol Wachowski <karol.wachowski@intel.com>,
	Maciej Falkowski <maciej.falkowski@linux.intel.com>
Subject: [PATCH 01/14] accel/ivpu: Separate DB ID and CMDQ ID allocations from CMDQ allocation
Date: Tue,  7 Jan 2025 18:32:24 +0100	[thread overview]
Message-ID: <20250107173238.381120-2-maciej.falkowski@linux.intel.com> (raw)
In-Reply-To: <20250107173238.381120-1-maciej.falkowski@linux.intel.com>

From: Karol Wachowski <karol.wachowski@intel.com>

Move doorbell ID and command queue ID XArray allocations from command
queue memory allocation function. This will allows IDs allocations to be
done without the need for actual memory allocation.

Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
Signed-off-by: Maciej Falkowski <maciej.falkowski@linux.intel.com>
---
 drivers/accel/ivpu/ivpu_job.c | 88 +++++++++++++++++++++++++----------
 1 file changed, 64 insertions(+), 24 deletions(-)

diff --git a/drivers/accel/ivpu/ivpu_job.c b/drivers/accel/ivpu/ivpu_job.c
index 7149312f16e1..98e53cb38ecd 100644
--- a/drivers/accel/ivpu/ivpu_job.c
+++ b/drivers/accel/ivpu/ivpu_job.c
@@ -83,23 +83,9 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
 	if (!cmdq)
 		return NULL;
 
-	ret = xa_alloc_cyclic(&vdev->db_xa, &cmdq->db_id, NULL, vdev->db_limit, &vdev->db_next,
-			      GFP_KERNEL);
-	if (ret < 0) {
-		ivpu_err(vdev, "Failed to allocate doorbell id: %d\n", ret);
-		goto err_free_cmdq;
-	}
-
-	ret = xa_alloc_cyclic(&file_priv->cmdq_xa, &cmdq->id, cmdq, file_priv->cmdq_limit,
-			      &file_priv->cmdq_id_next, GFP_KERNEL);
-	if (ret < 0) {
-		ivpu_err(vdev, "Failed to allocate command queue id: %d\n", ret);
-		goto err_erase_db_xa;
-	}
-
 	cmdq->mem = ivpu_bo_create_global(vdev, SZ_4K, DRM_IVPU_BO_WC | DRM_IVPU_BO_MAPPABLE);
 	if (!cmdq->mem)
-		goto err_erase_cmdq_xa;
+		goto err_free_cmdq;
 
 	ret = ivpu_preemption_buffers_create(vdev, file_priv, cmdq);
 	if (ret)
@@ -107,10 +93,6 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
 
 	return cmdq;
 
-err_erase_cmdq_xa:
-	xa_erase(&file_priv->cmdq_xa, cmdq->id);
-err_erase_db_xa:
-	xa_erase(&vdev->db_xa, cmdq->db_id);
 err_free_cmdq:
 	kfree(cmdq);
 	return NULL;
@@ -233,30 +215,88 @@ static int ivpu_cmdq_fini(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cm
 	return 0;
 }
 
+static int ivpu_db_id_alloc(struct ivpu_device *vdev, u32 *db_id)
+{
+	int ret;
+	u32 id;
+
+	ret = xa_alloc_cyclic(&vdev->db_xa, &id, NULL, vdev->db_limit, &vdev->db_next, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+
+	*db_id = id;
+	return 0;
+}
+
+static int ivpu_cmdq_id_alloc(struct ivpu_file_priv *file_priv, u32 *cmdq_id)
+{
+	int ret;
+	u32 id;
+
+	ret = xa_alloc_cyclic(&file_priv->cmdq_xa, &id, NULL, file_priv->cmdq_limit,
+			      &file_priv->cmdq_id_next, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+
+	*cmdq_id = id;
+	return 0;
+}
+
 static struct ivpu_cmdq *ivpu_cmdq_acquire(struct ivpu_file_priv *file_priv, u8 priority)
 {
+	struct ivpu_device *vdev = file_priv->vdev;
 	struct ivpu_cmdq *cmdq;
-	unsigned long cmdq_id;
+	unsigned long id;
 	int ret;
 
 	lockdep_assert_held(&file_priv->lock);
 
-	xa_for_each(&file_priv->cmdq_xa, cmdq_id, cmdq)
+	xa_for_each(&file_priv->cmdq_xa, id, cmdq)
 		if (cmdq->priority == priority)
 			break;
 
 	if (!cmdq) {
 		cmdq = ivpu_cmdq_alloc(file_priv);
-		if (!cmdq)
+		if (!cmdq) {
+			ivpu_err(vdev, "Failed to allocate command queue\n");
 			return NULL;
+		}
+
+		ret = ivpu_db_id_alloc(vdev, &cmdq->db_id);
+		if (ret) {
+			ivpu_err(file_priv->vdev, "Failed to allocate doorbell ID: %d\n", ret);
+			goto err_free_cmdq;
+		}
+
+		ret = ivpu_cmdq_id_alloc(file_priv, &cmdq->id);
+		if (ret) {
+			ivpu_err(vdev, "Failed to allocate command queue ID: %d\n", ret);
+			goto err_erase_db_id;
+		}
+
 		cmdq->priority = priority;
+		ret = xa_err(xa_store(&file_priv->cmdq_xa, cmdq->id, cmdq, GFP_KERNEL));
+		if (ret) {
+			ivpu_err(vdev, "Failed to store command queue in cmdq_xa: %d\n", ret);
+			goto err_erase_cmdq_id;
+		}
 	}
 
 	ret = ivpu_cmdq_init(file_priv, cmdq, priority);
-	if (ret)
-		return NULL;
+	if (ret) {
+		ivpu_err(vdev, "Failed to initialize command queue: %d\n", ret);
+		goto err_free_cmdq;
+	}
 
 	return cmdq;
+
+err_erase_cmdq_id:
+	xa_erase(&file_priv->cmdq_xa, cmdq->id);
+err_erase_db_id:
+	xa_erase(&vdev->db_xa, cmdq->db_id);
+err_free_cmdq:
+	ivpu_cmdq_free(file_priv, cmdq);
+	return NULL;
 }
 
 void ivpu_cmdq_release_all_locked(struct ivpu_file_priv *file_priv)
-- 
2.43.0


  reply	other threads:[~2025-01-07 14:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 17:32 [PATCH 00/14] accel/ivpu: Changes for 6.14 Maciej Falkowski
2025-01-07 17:32 ` Maciej Falkowski [this message]
2025-01-09  8:22   ` [PATCH 01/14] accel/ivpu: Separate DB ID and CMDQ ID allocations from CMDQ allocation Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 02/14] accel/ivpu: Add API for command queue create/destroy/submit Maciej Falkowski
2025-01-09  8:22   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 03/14] accel/ivpu: Abort all jobs after command queue unregister Maciej Falkowski
2025-01-09  8:23   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 04/14] accel/ivpu: Expose NPU memory utilization info in sysfs Maciej Falkowski
2025-01-08 19:53   ` Lizhi Hou
2025-01-09  8:19     ` Jacek Lawrynowicz
2025-01-09  8:24   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 05/14] accel/ivpu: Use workqueue for IRQ handling Maciej Falkowski
2025-01-09  8:26   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 06/14] accel/ivpu: Dump only first MMU fault from single context Maciej Falkowski
2025-01-09  8:26   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 07/14] accel/ivpu: Move parts of MMU event IRQ handling to thread handler Maciej Falkowski
2025-01-09  8:27   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 08/14] accel/ivpu: Fix missing MMU events from reserved SSID Maciej Falkowski
2025-01-09  8:27   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 09/14] accel/ivpu: Set command queue management capability based on HWS Maciej Falkowski
2025-01-09  8:28   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 10/14] accel/ivpu: Fix locking order in ivpu_cmdq_destroy_ioctl Maciej Falkowski
2025-01-09  8:28   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 11/14] accel/ivpu: Fix locking order in ivpu_job_submit Maciej Falkowski
2025-01-09  8:28   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 12/14] accel/ivpu: Add handling of VPU_JSM_STATUS_MVNCI_CONTEXT_VIOLATION_HW Maciej Falkowski
2025-01-09  8:29   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 13/14] accel/ivpu: Add platform detection for presilicon Maciej Falkowski
2025-01-09  8:29   ` Jacek Lawrynowicz
2025-01-07 17:32 ` [PATCH 14/14] accel/ivpu: Enable HWS by default on all platforms Maciej Falkowski
2025-01-08 18:19 ` [PATCH 00/14] accel/ivpu: Changes for 6.14 Simona Vetter
2025-01-09  8:14   ` Jacek Lawrynowicz
2025-01-09  8:43 ` Jacek Lawrynowicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250107173238.381120-2-maciej.falkowski@linux.intel.com \
    --to=maciej.falkowski@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jacek.lawrynowicz@linux.intel.com \
    --cc=karol.wachowski@intel.com \
    --cc=oded.gabbay@gmail.com \
    --cc=quic_jhugo@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.