Skip to contentSkip to conversation

accel/ivpu: Changes for 6.10

PATCH Superseded Jacek Lawrynowicz 3 participants 31 messages May 8, 2024 – May 13, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover accel/ivpu: Changes for 6.10

There are couple of major new features in this patchset:
* Hardware scheduler support (disabled by default)
* Profiling support
* Expose NPU busy time in sysfs

Other then that, there are two small random fixes.

Jacek Lawrynowicz (2):
accel/ivpu: Update VPU FW API headers accel/ivpu: Increase reset counter when warm boot fails

Tomasz Rusinowicz (3):
accel/ivpu: Add NPU profiling support
accel/ivpu: Configure fw logging using debugfs
accel/ivpu: Share NPU busy time in sysfs

Wachowski, Karol (7):
accel/ivpu: Add sched_mode module param accel/ivpu: Create priority based command queues accel/ivpu: Implement support for preemption buffers accel/ivpu: Add HWS JSM messages accel/ivpu: Implement support for hardware scheduler accel/ivpu: Add resume engine support accel/ivpu: Add force snoop module parameter

 drivers/accel/ivpu/Makefile       |   6 +-
 drivers/accel/ivpu/ivpu_debugfs.c |  50 +++++
 drivers/accel/ivpu/ivpu_drv.c     |  44 ++++-
 drivers/accel/ivpu/ivpu_drv.h     |  23 ++-
 drivers/accel/ivpu/ivpu_fw.c      |  12 ++
 drivers/accel/ivpu/ivpu_fw.h      |   2 +
 drivers/accel/ivpu/ivpu_gem.h     |  11 +-
 drivers/accel/ivpu/ivpu_hw.h      |   3 +-
 drivers/accel/ivpu/ivpu_hw_37xx.c |   7 +-
 drivers/accel/ivpu/ivpu_hw_40xx.c |   9 +-
 drivers/accel/ivpu/ivpu_job.c     | 295 ++++++++++++++++++++++------
 drivers/accel/ivpu/ivpu_job.h     |   2 +
 drivers/accel/ivpu/ivpu_jsm_msg.c | 259 ++++++++++++++++++++++++-
 drivers/accel/ivpu/ivpu_jsm_msg.h |  20 +-
 drivers/accel/ivpu/ivpu_mmu.c     |  12 +-
 drivers/accel/ivpu/ivpu_ms.c      | 309 ++++++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_ms.h      |  36 ++++
 drivers/accel/ivpu/ivpu_pm.c      |   5 +
 drivers/accel/ivpu/ivpu_sysfs.c   |  58 ++++++
 drivers/accel/ivpu/ivpu_sysfs.h   |  13 ++
 drivers/accel/ivpu/vpu_jsm_api.h  |  14 +-
 include/uapi/drm/ivpu_accel.h     |  69 ++++++-
 22 files changed, 1175 insertions(+), 84 deletions(-)
 create mode 100644 drivers/accel/ivpu/ivpu_ms.c
 create mode 100644 drivers/accel/ivpu/ivpu_ms.h
 create mode 100644 drivers/accel/ivpu/ivpu_sysfs.c
 create mode 100644 drivers/accel/ivpu/ivpu_sysfs.h

--
2.43.2

#1 lore raw

PATCH 1/12 accel/ivpu: Update VPU FW API headers

Update JSM API to 3.16.0.

---
 drivers/accel/ivpu/vpu_jsm_api.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/accel/ivpu/vpu_jsm_api.h +11 -3
index e46f3531211a..33f462b1a25d 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: MIT */
 /*
- * Copyright (c) 2020-2023, Intel Corporation.
+ * Copyright (c) 2020-2024, Intel Corporation.
  */
 
 /**
@@ -22,12 +22,12 @@
 /*
  * Minor version changes when API backward compatibility is preserved.
  */
-#define VPU_JSM_API_VER_MINOR 15
+#define VPU_JSM_API_VER_MINOR 16
 
 /*
  * API header changed (field names, documentation, formatting) but API itself has not been changed
  */
-#define VPU_JSM_API_VER_PATCH 6
+#define VPU_JSM_API_VER_PATCH 0
 
 /*
  * Index in the API version table
@@ -868,6 +868,14 @@ struct vpu_ipc_msg_payload_hws_set_scheduling_log {
 	 * is generated when an event log is written to this index.
 	 */
 	u64 notify_index;
+	/*
+	 * Enable extra events to be output to log for debug of scheduling algorithm.
+	 * Interpreted by VPU as a boolean to enable or disable, expected values are
+	 * 0 and 1.
+	 */
+	u32 enable_extra_events;
+	/* Zero Padding */
+	u32 reserved_0;
 };
 
 /*
Signature · 1 line
2.43.2
#3 lore raw

PATCH 2/12 accel/ivpu: Add sched_mode module param

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

This param will be used to enable/disable HWS (hardware scheduler). The HWS is a FW side feature and may not be available on all HW generations and FW versions.

---
 drivers/accel/ivpu/ivpu_drv.c     | 4 ++++
 drivers/accel/ivpu/ivpu_drv.h     | 1 +
 drivers/accel/ivpu/ivpu_hw.h      | 3 ++-
 drivers/accel/ivpu/ivpu_hw_37xx.c | 1 +
 drivers/accel/ivpu/ivpu_hw_40xx.c | 3 ++-
 5 files changed, 10 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +4 -0
index 51d3f1a55d02..db47e7ef6322 100644
@@ -51,6 +51,10 @@ u8 ivpu_pll_max_ratio = U8_MAX;
 module_param_named(pll_max_ratio, ivpu_pll_max_ratio, byte, 0644);
 MODULE_PARM_DESC(pll_max_ratio, "Maximum PLL ratio used to set NPU frequency");
 
+bool ivpu_sched_mode;
+module_param_named(sched_mode, ivpu_sched_mode, bool, 0644);
+MODULE_PARM_DESC(sched_mode, "Scheduler mode: 0 - OS scheduler, 1 - HW scheduler");
+
 bool ivpu_disable_mmu_cont_pages;
 module_param_named(disable_mmu_cont_pages, ivpu_disable_mmu_cont_pages, bool, 0644);
 MODULE_PARM_DESC(disable_mmu_cont_pages, "Disable MMU contiguous pages optimization");
drivers/accel/ivpu/ivpu_drv.h +1 -0
index bb4374d0eaec..a3993c93403a 100644
@@ -158,6 +158,7 @@ struct ivpu_file_priv {
 extern int ivpu_dbg_mask;
 extern u8 ivpu_pll_min_ratio;
 extern u8 ivpu_pll_max_ratio;
+extern bool ivpu_sched_mode;
 extern bool ivpu_disable_mmu_cont_pages;
 
 #define IVPU_TEST_MODE_FW_TEST            BIT(0)
drivers/accel/ivpu/ivpu_hw.h +2 -1
index 094c659d2800..d247a2e99496 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_HW_H__
@@ -59,6 +59,7 @@ struct ivpu_hw_info {
 		u32 profiling_freq;
 	} pll;
 	u32 tile_fuse;
+	u32 sched_mode;
 	u32 sku;
 	u16 config;
 	int dma_bits;
drivers/accel/ivpu/ivpu_hw_37xx.c +1 -0
index bd25e2d9fb0f..ce664b6515aa 100644
@@ -589,6 +589,7 @@ static int ivpu_hw_37xx_info_init(struct ivpu_device *vdev)
 	hw->tile_fuse = TILE_FUSE_ENABLE_BOTH;
 	hw->sku = TILE_SKU_BOTH;
 	hw->config = WP_CONFIG_2_TILE_4_3_RATIO;
+	hw->sched_mode = ivpu_sched_mode;
 
 	ivpu_pll_init_frequency_ratios(vdev);
 
drivers/accel/ivpu/ivpu_hw_40xx.c +2 -1
index b0b88d4c8926..186cd87079c2 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #include "ivpu_drv.h"
@@ -724,6 +724,7 @@ static int ivpu_hw_40xx_info_init(struct ivpu_device *vdev)
 	else
 		ivpu_dbg(vdev, MISC, "Fuse: All %d tiles enabled\n", TILE_MAX_NUM);
 
+	hw->sched_mode = ivpu_sched_mode;
 	hw->tile_fuse = tile_disable;
 	hw->pll.profiling_freq = PLL_PROFILING_FREQ_DEFAULT;
 
Signature · 1 line
2.43.2
#4 lore raw

Re: [PATCH 02/12] accel/ivpu: Add sched_mode module param

Quoted 21 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

This param will be used to enable/disable HWS (hardware scheduler). The HWS is a FW side feature and may not be available on all HW generations and FW versions.

---
  drivers/accel/ivpu/ivpu_drv.c     | 4 ++++
  drivers/accel/ivpu/ivpu_drv.h     | 1 +
  drivers/accel/ivpu/ivpu_hw.h      | 3 ++-
  drivers/accel/ivpu/ivpu_hw_37xx.c | 1 +
  drivers/accel/ivpu/ivpu_hw_40xx.c | 3 ++-
  5 files changed, 10 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +0 -0
index 51d3f1a55d02..db47e7ef6322 100644

drivers/accel/ivpu/ivpu_drv.c u8 ivpu_pll_max_ratio = U8_MAX; · line 56

Quoted 6 lines
drivers/accel/ivpu/ivpu_drv.c +3 -0
@@ -51,6 +51,10 @@ u8 ivpu_pll_max_ratio = U8_MAX;
  module_param_named(pll_max_ratio, ivpu_pll_max_ratio, byte, 0644);
  MODULE_PARM_DESC(pll_max_ratio, "Maximum PLL ratio used to set NPU frequency");
 
+bool ivpu_sched_mode;
+module_param_named(sched_mode, ivpu_sched_mode, bool, 0644);
+MODULE_PARM_DESC(sched_mode, "Scheduler mode: 0 - OS scheduler, 1 - HW scheduler");

"OS scheduler"
Host OS (aka Linux) or device side OS? Seems a bit ambiguous.
Also looks like this must be set before the device is initialized, yet it does not look like that is communicated.

-Jeff

#5 lore raw

Re: [PATCH 02/12] accel/ivpu: Add sched_mode module param

Hi,

Quoted 17 lines · Jeffrey Hugo
Quoted 16 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

This param will be used to enable/disable HWS (hardware scheduler). The HWS is a FW side feature and may not be available on all HW generations and FW versions.

---
  drivers/accel/ivpu/ivpu_drv.c     | 4 ++++
  drivers/accel/ivpu/ivpu_drv.h     | 1 +
  drivers/accel/ivpu/ivpu_hw.h      | 3 ++-
  drivers/accel/ivpu/ivpu_hw_37xx.c | 1 +
  drivers/accel/ivpu/ivpu_hw_40xx.c | 3 ++-

  5 files changed, 10 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/accel/ivpu/ivpu_drv.c u8 ivpu_pll_max_ratio = U8_MAX; · line 55

Quoted 10 lines
drivers/accel/ivpu/ivpu_drv.c +2 -0
index 51d3f1a55d02..db47e7ef6322 100644
@@ -51,6 +51,10 @@ u8 ivpu_pll_max_ratio = U8_MAX;
   module_param_named(pll_max_ratio, ivpu_pll_max_ratio, byte, 0644);
   MODULE_PARM_DESC(pll_max_ratio, "Maximum PLL ratio used to set NPU frequency");
   +bool ivpu_sched_mode;
+module_param_named(sched_mode, ivpu_sched_mode, bool, 0644);
+MODULE_PARM_DESC(sched_mode, "Scheduler mode: 0 - OS scheduler, 1 - HW scheduler");

"OS scheduler"
Host OS (aka Linux) or device side OS?  Seems a bit ambiguous.

Yeah, it should be "No scheduler". We actually don't have any OS scheduling for workloads.

Quoted 1 line

Also looks like this must be set before the device is initialized, yet it does not look like that is communicated.

I'm usually try to keep param descriptions short. I will change the mode to 0444, so it won't be possible to change the param after driver is loaded.

#6 lore raw

PATCH 3/12 accel/ivpu: Create priority based command queues

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Create multiple command queues per engine with different priorities. The cmdqs are created on-demand and they support 4 priority levels. These priorities will later be used by the HWS (hardware scheduler).

---
 drivers/accel/ivpu/ivpu_drv.h |  8 +++--
 drivers/accel/ivpu/ivpu_job.c | 61 +++++++++++++++++++++++------------
 2 files changed, 46 insertions(+), 23 deletions(-)
drivers/accel/ivpu/ivpu_drv.h +6 -2
index a3993c93403a..2277718b31f7 100644
@@ -39,7 +39,11 @@
 #define IVPU_MIN_DB 1
 #define IVPU_MAX_DB 255
 
-#define IVPU_NUM_ENGINES 2
+#define IVPU_NUM_ENGINES       2
+#define IVPU_NUM_PRIORITIES    4
+#define IVPU_NUM_CMDQS_PER_CTX (IVPU_NUM_ENGINES * IVPU_NUM_PRIORITIES)
+
+#define IVPU_CMDQ_INDEX(engine, priority) ((engine) * IVPU_NUM_PRIORITIES + (priority))
 
 #define IVPU_PLATFORM_SILICON 0
 #define IVPU_PLATFORM_SIMICS  2
@@ -149,7 +153,7 @@ struct ivpu_file_priv {
 	struct kref ref;
 	struct ivpu_device *vdev;
 	struct mutex lock; /* Protects cmdq */
-	struct ivpu_cmdq *cmdq[IVPU_NUM_ENGINES];
+	struct ivpu_cmdq *cmdq[IVPU_NUM_CMDQS_PER_CTX];
 	struct ivpu_mmu_context ctx;
 	bool has_mmu_faults;
 	bool bound;
drivers/accel/ivpu/ivpu_job.c +40 -21

149 lines not on this page · raw message

Signature · 1 line
2.43.2
Reviewed-by on v1 3/12
#7 lore raw

Re: [PATCH 03/12] accel/ivpu: Create priority based command queues

Quoted 8 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Create multiple command queues per engine with different priorities. The cmdqs are created on-demand and they support 4 priority levels. These priorities will later be used by the HWS (hardware scheduler).

#8 lore raw

PATCH 4/12 accel/ivpu: Implement support for preemption buffers

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Allocate per-context preemption buffers that are required by HWS.

There are two preemption buffers:
* primary - allocated in user memory range (PIOVA accessible)
* secondary - allocated in shave memory range

---
 drivers/accel/ivpu/ivpu_drv.h |  1 +
 drivers/accel/ivpu/ivpu_fw.c  |  3 ++
 drivers/accel/ivpu/ivpu_fw.h  |  2 ++
 drivers/accel/ivpu/ivpu_job.c | 65 +++++++++++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_job.h |  2 ++
 5 files changed, 73 insertions(+)
drivers/accel/ivpu/ivpu_drv.h +1 -0
index 2277718b31f7..fdc4c0561b25 100644
@@ -170,6 +170,7 @@ extern bool ivpu_disable_mmu_cont_pages;
 #define IVPU_TEST_MODE_NULL_SUBMISSION    BIT(2)
 #define IVPU_TEST_MODE_D0I3_MSG_DISABLE   BIT(4)
 #define IVPU_TEST_MODE_D0I3_MSG_ENABLE    BIT(5)
+#define IVPU_TEST_MODE_PREEMPTION_DISABLE BIT(6)
 extern int ivpu_test_mode;
 
 struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv);
drivers/accel/ivpu/ivpu_fw.c +3 -0
index 1457300828bf..29ecf7db238b 100644
@@ -200,6 +200,9 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
 
 	fw->dvfs_mode = 0;
 
+	fw->primary_preempt_buf_size = fw_hdr->preemption_buffer_1_size;
+	fw->secondary_preempt_buf_size = fw_hdr->preemption_buffer_2_size;
+
 	ivpu_dbg(vdev, FW_BOOT, "Size: file %lu image %u runtime %u shavenn %u\n",
 		 fw->file->size, fw->image_size, fw->runtime_size, fw->shave_nn_size);
 	ivpu_dbg(vdev, FW_BOOT, "Address: runtime 0x%llx, load 0x%llx, entry point 0x%llx\n",
drivers/accel/ivpu/ivpu_fw.h +2 -0
index 66b60fa161b5..66fc7da3ab0f 100644
@@ -28,6 +28,8 @@ struct ivpu_fw_info {
 	u32 trace_destination_mask;
 	u64 trace_hw_component_mask;
 	u32 dvfs_mode;
+	u32 primary_preempt_buf_size;
+	u32 secondary_preempt_buf_size;
 };
 
 int ivpu_fw_init(struct ivpu_device *vdev);
drivers/accel/ivpu/ivpu_job.c +65 -0

106 lines not on this page · raw message

drivers/accel/ivpu/ivpu_job.h +2 -0
index ca4984071cc7..e50002b5788c 100644
@@ -24,6 +24,8 @@ struct ivpu_file_priv;
  */
 struct ivpu_cmdq {
 	struct vpu_job_queue *jobq;
+	struct ivpu_bo *primary_preempt_buf;
+	struct ivpu_bo *secondary_preempt_buf;
 	struct ivpu_bo *mem;
 	u32 entry_count;
 	u32 db_id;
Signature · 1 line
2.43.2
Reviewed-by on v1 4/12
#9 lore raw

Re: [PATCH 04/12] accel/ivpu: Implement support for preemption buffers

Quoted 10 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Allocate per-context preemption buffers that are required by HWS.

There are two preemption buffers:
* primary - allocated in user memory range (PIOVA accessible)
* secondary - allocated in shave memory range

#10 lore raw

PATCH 5/12 accel/ivpu: Add HWS JSM messages

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Add JSM messages that will be used to implement hardware scheduler. Most of these messages are used to create and manage HWS specific command queues.

---
 drivers/accel/ivpu/ivpu_drv.h     |   1 +
 drivers/accel/ivpu/ivpu_jsm_msg.c | 161 +++++++++++++++++++++++++++++-
 drivers/accel/ivpu/ivpu_jsm_msg.h |  14 ++-
 3 files changed, 174 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_drv.h +1 -0
index fdc4c0561b25..e0d1f43aad6b 100644
@@ -171,6 +171,7 @@ extern bool ivpu_disable_mmu_cont_pages;
 #define IVPU_TEST_MODE_D0I3_MSG_DISABLE   BIT(4)
 #define IVPU_TEST_MODE_D0I3_MSG_ENABLE    BIT(5)
 #define IVPU_TEST_MODE_PREEMPTION_DISABLE BIT(6)
+#define IVPU_TEST_MODE_HWS_EXTRA_EVENTS	  BIT(7)
 extern int ivpu_test_mode;
 
 struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv);
drivers/accel/ivpu/ivpu_jsm_msg.c +160 -1

169 lines not on this page · raw message

drivers/accel/ivpu/ivpu_jsm_msg.h +13 -1
index ae75e5dbcc41..357728295fe9 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_JSM_MSG_H__
@@ -23,4 +23,16 @@ int ivpu_jsm_trace_set_config(struct ivpu_device *vdev, u32 trace_level, u32 tra
 			      u64 trace_hw_component_mask);
 int ivpu_jsm_context_release(struct ivpu_device *vdev, u32 host_ssid);
 int ivpu_jsm_pwr_d0i3_enter(struct ivpu_device *vdev);
+int ivpu_jsm_hws_create_cmdq(struct ivpu_device *vdev, u32 ctx_id, u32 cmdq_group, u32 cmdq_id,
+			     u32 pid, u32 engine, u64 cmdq_base, u32 cmdq_size);
+int ivpu_jsm_hws_destroy_cmdq(struct ivpu_device *vdev, u32 ctx_id, u32 cmdq_id);
+int ivpu_jsm_hws_register_db(struct ivpu_device *vdev, u32 ctx_id, u32 cmdq_id, u32 db_id,
+			     u64 cmdq_base, u32 cmdq_size);
+int ivpu_jsm_hws_resume_engine(struct ivpu_device *vdev, u32 engine);
+int ivpu_jsm_hws_set_context_sched_properties(struct ivpu_device *vdev, u32 ctx_id, u32 cmdq_id,
+					      u32 priority);
+int ivpu_jsm_hws_set_scheduling_log(struct ivpu_device *vdev, u32 engine_idx, u32 host_ssid,
+				    u64 vpu_log_buffer_va);
+int ivpu_jsm_hws_setup_priority_bands(struct ivpu_device *vdev);
+
 #endif
Signature · 1 line
2.43.2
Reviewed-by on v1 5/12
#11 lore raw

Re: [PATCH 05/12] accel/ivpu: Add HWS JSM messages

Quoted 8 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Add JSM messages that will be used to implement hardware scheduler. Most of these messages are used to create and manage HWS specific command queues.

#12 lore raw

PATCH 6/12 accel/ivpu: Implement support for hardware scheduler

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Add support for HWS (hardware scheduler). It is disabled by default. The sched_mode module param can be used to enable it.

Each context has multiple command queues with different priorities and HWS enables priority based execution on the HW/FW side.

The driver in HWS mode has to send a couple additional messages to initialize HWS and describe command queue priorities.

---
 drivers/accel/ivpu/ivpu_drv.c |  20 ++++-
 drivers/accel/ivpu/ivpu_fw.c  |   9 ++
 drivers/accel/ivpu/ivpu_job.c | 162 ++++++++++++++++++++++++----------
 3 files changed, 144 insertions(+), 47 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +19 -1
index db47e7ef6322..49261fa7c5f4 100644
@@ -78,7 +78,6 @@ static void file_priv_unbind(struct ivpu_device *vdev, struct ivpu_file_priv *fi
 		ivpu_dbg(vdev, FILE, "file_priv unbind: ctx %u\n", file_priv->ctx.id);
 
 		ivpu_cmdq_release_all_locked(file_priv);
-		ivpu_jsm_context_release(vdev, file_priv->ctx.id);
 		ivpu_bo_unbind_all_bos_from_context(vdev, &file_priv->ctx);
 		ivpu_mmu_user_context_fini(vdev, &file_priv->ctx);
 		file_priv->bound = false;
@@ -327,6 +326,21 @@ static int ivpu_wait_for_ready(struct ivpu_device *vdev)
 	return ret;
 }
 
+static int ivpu_hw_sched_init(struct ivpu_device *vdev)
+{
+	int ret = 0;
+
+	if (vdev->hw->sched_mode == VPU_SCHEDULING_MODE_HW) {
+		ret = ivpu_jsm_hws_setup_priority_bands(vdev);
+		if (ret) {
+			ivpu_err(vdev, "Failed to enable hw scheduler: %d", ret);
+			return ret;
+		}
+	}
+
+	return ret;
+}
+
 /**
  * ivpu_boot() - Start VPU firmware
  * @vdev: VPU device
@@ -360,6 +374,10 @@ int ivpu_boot(struct ivpu_device *vdev)
 	enable_irq(vdev->irq);
 	ivpu_hw_irq_enable(vdev);
 	ivpu_ipc_enable(vdev);
+
+	if (ivpu_fw_is_cold_boot(vdev))
+		return ivpu_hw_sched_init(vdev);
+
 	return 0;
 }
 
drivers/accel/ivpu/ivpu_fw.c +9 -0
index 29ecf7db238b..6a33a3193d5c 100644
@@ -44,6 +44,8 @@
 #define IVPU_FW_CHECK_API_VER_LT(vdev, fw_hdr, name, major, minor) \
 	ivpu_fw_check_api_ver_lt(vdev, fw_hdr, #name, VPU_##name##_API_VER_INDEX, major, minor)
 
+#define IVPU_FOCUS_PRESENT_TIMER_MS 1000
+
 static char *ivpu_firmware;
 module_param_named_unsafe(firmware, ivpu_firmware, charp, 0644);
 MODULE_PARM_DESC(firmware, "NPU firmware binary in /lib/firmware/..");
@@ -467,6 +469,10 @@ static void ivpu_fw_boot_params_print(struct ivpu_device *vdev, struct vpu_boot_
 		 boot_params->punit_telemetry_sram_size);
 	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_telemetry_enable = 0x%x\n",
 		 boot_params->vpu_telemetry_enable);
+	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_scheduling_mode = 0x%x\n",
+		 boot_params->vpu_scheduling_mode);
+	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_focus_present_timer_ms = %u\n",
+		 boot_params->vpu_focus_present_timer_ms);
 	ivpu_dbg(vdev, FW_BOOT, "boot_params.dvfs_mode = %u\n",
 		 boot_params->dvfs_mode);
 	ivpu_dbg(vdev, FW_BOOT, "boot_params.d0i3_delayed_entry = %d\n",
@@ -567,6 +573,9 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params
 	boot_params->punit_telemetry_sram_base = ivpu_hw_reg_telemetry_offset_get(vdev);
 	boot_params->punit_telemetry_sram_size = ivpu_hw_reg_telemetry_size_get(vdev);
 	boot_params->vpu_telemetry_enable = ivpu_hw_reg_telemetry_enable_get(vdev);
+	boot_params->vpu_scheduling_mode = vdev->hw->sched_mode;
+	if (vdev->hw->sched_mode == VPU_SCHEDULING_MODE_HW)
+		boot_params->vpu_focus_present_timer_ms = IVPU_FOCUS_PRESENT_TIMER_MS;
 	boot_params->dvfs_mode = vdev->fw->dvfs_mode;
 	if (!IVPU_WA(disable_d0i3_msg))
 		boot_params->d0i3_delayed_entry = 1;
drivers/accel/ivpu/ivpu_job.c +116 -46

231 lines not on this page · raw message

Signature · 1 line
2.43.2
#13 lore raw

Re: [PATCH 06/12] accel/ivpu: Implement support for hardware scheduler

drivers/accel/ivpu/ivpu_fw.c static void ivpu_fw_boot_params_print(struct ivpu_device *vdev, struct vpu_boot_ · line 475

Quoted 13 lines · Jacek Lawrynowicz
drivers/accel/ivpu/ivpu_fw.c +6 -0
+#define IVPU_FOCUS_PRESENT_TIMER_MS 1000
+
  static char *ivpu_firmware;
  module_param_named_unsafe(firmware, ivpu_firmware, charp, 0644);
  MODULE_PARM_DESC(firmware, "NPU firmware binary in /lib/firmware/..");
@@ -467,6 +469,10 @@ static void ivpu_fw_boot_params_print(struct ivpu_device *vdev, struct vpu_boot_
  		 boot_params->punit_telemetry_sram_size);
  	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_telemetry_enable = 0x%x\n",
  		 boot_params->vpu_telemetry_enable);
+	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_scheduling_mode = 0x%x\n",
+		 boot_params->vpu_scheduling_mode);
+	ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_focus_present_timer_ms = %u\n",
+		 boot_params->vpu_focus_present_timer_ms);

The timer value is hard coded. Does that not make this log message redundant?

-Jeff

#14 lore raw

Re: [PATCH 06/12] accel/ivpu: Implement support for hardware scheduler

Hi,

Quoted 16 lines · Jeffrey Hugo

drivers/accel/ivpu/ivpu_fw.c static void ivpu_fw_boot_params_print(struct ivpu_device *vdev, struct vpu_boot_ · line 475

Quoted 13 lines · Jacek Lawrynowicz
drivers/accel/ivpu/ivpu_fw.c +2 -0
+#define IVPU_FOCUS_PRESENT_TIMER_MS 1000
+

  static char *ivpu_firmware; module_param_named_unsafe(firmware, ivpu_firmware, charp, 0644); MODULE_PARM_DESC(firmware, "NPU firmware binary in /lib/firmware/..");

drivers/accel/ivpu/ivpu_fw.c +4 -0
@@ -467,6 +469,10 @@ static void ivpu_fw_boot_params_print(struct ivpu_device *vdev, struct vpu_boot_
            boot_params->punit_telemetry_sram_size);
       ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_telemetry_enable = 0x%x\n",
            boot_params->vpu_telemetry_enable);
+    ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_scheduling_mode = 0x%x\n",
+         boot_params->vpu_scheduling_mode);
+    ivpu_dbg(vdev, FW_BOOT, "boot_params.vpu_focus_present_timer_ms = %u\n",
+         boot_params->vpu_focus_present_timer_ms);

The timer value is hard coded.  Does that not make this log message redundant?

Yes, I will remove it.

#15 lore raw

PATCH 7/12 accel/ivpu: Add resume engine support

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Create debugfs interface that triggers sending resume engine IPC command to VPU.

---
 drivers/accel/ivpu/ivpu_debugfs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/accel/ivpu/ivpu_debugfs.c +24 -0
index e07e447d08d1..6ff967e595cf 100644
@@ -335,6 +335,28 @@ static const struct file_operations ivpu_reset_engine_fops = {
 	.write = ivpu_reset_engine_fn,
 };
 
+static ssize_t
+ivpu_resume_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
+{
+	struct ivpu_device *vdev = file->private_data;
+
+	if (!size)
+		return -EINVAL;
+
+	if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
+		return -ENODEV;
+	if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COPY))
+		return -ENODEV;
+
+	return size;
+}
+
+static const struct file_operations ivpu_resume_engine_fops = {
+	.owner = THIS_MODULE,
+	.open = simple_open,
+	.write = ivpu_resume_engine_fn,
+};
+
 void ivpu_debugfs_init(struct ivpu_device *vdev)
 {
 	struct dentry *debugfs_root = vdev->drm.debugfs_root;
@@ -358,6 +380,8 @@ void ivpu_debugfs_init(struct ivpu_device *vdev)
 
 	debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
 			    &ivpu_reset_engine_fops);
+	debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
+			    &ivpu_resume_engine_fops);
 
 	if (ivpu_hw_gen(vdev) >= IVPU_HW_40XX)
 		debugfs_create_file("fw_profiling_freq_drive", 0200,
Signature · 1 line
2.43.2
#16 lore raw

Re: [PATCH 07/12] accel/ivpu: Add resume engine support

Quoted 4 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Create debugfs interface that triggers sending resume engine IPC command to VPU.

Why? Who would use this and for what purpose?

-Jeff

#17 lore raw

Re: [PATCH 07/12] accel/ivpu: Add resume engine support

Hi,

Quoted 7 lines · Jeffrey Hugo
Quoted 4 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Create debugfs interface that triggers sending resume engine IPC command to VPU.

Why?  Who would use this and for what purpose?

This is used by our user space tests. I will extend the description.

#18 lore raw

PATCH 8/12 accel/ivpu: Add NPU profiling support

In reply to Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

Implement time based Metric Streamer profiling UAPI.

This is a generic mechanism allowing user mode tools to sample NPU metrics. These metrics are defined by the FW and transparent to the driver.

The user space can check for this feature by checking DRM_IVPU_CAP_METRIC_STREAMER driver capability.

---
 drivers/accel/ivpu/Makefile       |   3 +-
 drivers/accel/ivpu/ivpu_drv.c     |  14 +-
 drivers/accel/ivpu/ivpu_drv.h     |   3 +
 drivers/accel/ivpu/ivpu_jsm_msg.c |  98 ++++++++++
 drivers/accel/ivpu/ivpu_jsm_msg.h |   8 +-
 drivers/accel/ivpu/ivpu_ms.c      | 309 ++++++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_ms.h      |  36 ++++
 drivers/accel/ivpu/ivpu_pm.c      |   4 +
 include/uapi/drm/ivpu_accel.h     |  69 ++++++-
 9 files changed, 540 insertions(+), 4 deletions(-)
 create mode 100644 drivers/accel/ivpu/ivpu_ms.c
 create mode 100644 drivers/accel/ivpu/ivpu_ms.h
drivers/accel/ivpu/Makefile +2 -1
index 95ff7ad16338..726cf8f28ea3 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
-# Copyright (C) 2023 Intel Corporation
+# Copyright (C) 2022-2024 Intel Corporation
 
 intel_vpu-y := \
 	ivpu_drv.o \
@@ -13,6 +13,7 @@ intel_vpu-y := \
 	ivpu_jsm_msg.o \
 	ivpu_mmu.o \
 	ivpu_mmu_context.o \
+	ivpu_ms.o \
 	ivpu_pm.o
 
 intel_vpu-$(CONFIG_DEBUG_FS) += ivpu_debugfs.o
drivers/accel/ivpu/ivpu_drv.c +13 -1
index 49261fa7c5f4..ece6b212aaf8 100644
@@ -26,6 +26,7 @@
 #include "ivpu_jsm_msg.h"
 #include "ivpu_mmu.h"
 #include "ivpu_mmu_context.h"
+#include "ivpu_ms.h"
 #include "ivpu_pm.h"
 
 #ifndef DRIVER_VERSION_STR
@@ -100,6 +101,7 @@ static void file_priv_release(struct kref *ref)
 	mutex_unlock(&vdev->context_list_lock);
 	pm_runtime_put_autosuspend(vdev->drm.dev);
 
+	mutex_destroy(&file_priv->ms_lock);
 	mutex_destroy(&file_priv->lock);
 	kfree(file_priv);
 }
@@ -122,7 +124,7 @@ static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param
 {
 	switch (args->index) {
 	case DRM_IVPU_CAP_METRIC_STREAMER:
-		args->value = 0;
+		args->value = 1;
 		break;
 	case DRM_IVPU_CAP_DMA_MEMORY_RANGE:
 		args->value = 1;
@@ -231,10 +233,13 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file)
 		goto err_dev_exit;
 	}
 
+	INIT_LIST_HEAD(&file_priv->ms_instance_list);
+
 	file_priv->vdev = vdev;
 	file_priv->bound = true;
 	kref_init(&file_priv->ref);
 	mutex_init(&file_priv->lock);
+	mutex_init(&file_priv->ms_lock);
 
 	mutex_lock(&vdev->context_list_lock);
 
@@ -263,6 +268,7 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file)
 	xa_erase_irq(&vdev->context_xa, ctx_id);
 err_unlock:
 	mutex_unlock(&vdev->context_list_lock);
+	mutex_destroy(&file_priv->ms_lock);
 	mutex_destroy(&file_priv->lock);
 	kfree(file_priv);
 err_dev_exit:
@@ -278,6 +284,7 @@ static void ivpu_postclose(struct drm_device *dev, struct drm_file *file)
 	ivpu_dbg(vdev, FILE, "file_priv close: ctx %u process %s pid %d\n",
 		 file_priv->ctx.id, current->comm, task_pid_nr(current));
 
+	ivpu_ms_cleanup(file_priv);
 	ivpu_file_priv_put(&file_priv);
 }
 
@@ -288,6 +295,10 @@ static const struct drm_ioctl_desc ivpu_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(IVPU_BO_INFO, ivpu_bo_info_ioctl, 0),
 	DRM_IOCTL_DEF_DRV(IVPU_SUBMIT, ivpu_submit_ioctl, 0),
 	DRM_IOCTL_DEF_DRV(IVPU_BO_WAIT, ivpu_bo_wait_ioctl, 0),
+	DRM_IOCTL_DEF_DRV(IVPU_METRIC_STREAMER_START, ivpu_ms_start_ioctl, 0),
+	DRM_IOCTL_DEF_DRV(IVPU_METRIC_STREAMER_GET_DATA, ivpu_ms_get_data_ioctl, 0),
+	DRM_IOCTL_DEF_DRV(IVPU_METRIC_STREAMER_STOP, ivpu_ms_stop_ioctl, 0),
+	DRM_IOCTL_DEF_DRV(IVPU_METRIC_STREAMER_GET_INFO, ivpu_ms_get_info_ioctl, 0),
 };
 
 static int ivpu_wait_for_ready(struct ivpu_device *vdev)
@@ -638,6 +649,7 @@ static void ivpu_dev_fini(struct ivpu_device *vdev)
 	ivpu_prepare_for_reset(vdev);
 	ivpu_shutdown(vdev);
 
+	ivpu_ms_cleanup_all(vdev);
 	ivpu_jobs_abort_all(vdev);
 	ivpu_job_done_consumer_fini(vdev);
 	ivpu_pm_cancel_recovery(vdev);
drivers/accel/ivpu/ivpu_drv.h +3 -0
index e0d1f43aad6b..0f42a3a9e59c 100644
@@ -155,6 +155,9 @@ struct ivpu_file_priv {
 	struct mutex lock; /* Protects cmdq */
 	struct ivpu_cmdq *cmdq[IVPU_NUM_CMDQS_PER_CTX];
 	struct ivpu_mmu_context ctx;
+	struct mutex ms_lock; /* Protects ms_instance_list, ms_info_bo */
+	struct list_head ms_instance_list;
+	struct ivpu_bo *ms_info_bo;
 	bool has_mmu_faults;
 	bool bound;
 };
drivers/accel/ivpu/ivpu_jsm_msg.c +98 -0

101 lines not on this page · raw message

drivers/accel/ivpu/ivpu_jsm_msg.h +7 -1
index 357728295fe9..060363409fb3 100644
@@ -34,5 +34,11 @@ int ivpu_jsm_hws_set_context_sched_properties(struct ivpu_device *vdev, u32 ctx_
 int ivpu_jsm_hws_set_scheduling_log(struct ivpu_device *vdev, u32 engine_idx, u32 host_ssid,
 				    u64 vpu_log_buffer_va);
 int ivpu_jsm_hws_setup_priority_bands(struct ivpu_device *vdev);
-
+int ivpu_jsm_metric_streamer_start(struct ivpu_device *vdev, u64 metric_group_mask,
+				   u64 sampling_rate, u64 buffer_addr, u64 buffer_size);
+int ivpu_jsm_metric_streamer_stop(struct ivpu_device *vdev, u64 metric_group_mask);
+int ivpu_jsm_metric_streamer_update(struct ivpu_device *vdev, u64 metric_group_mask,
+				    u64 buffer_addr, u64 buffer_size, u64 *bytes_written);
+int ivpu_jsm_metric_streamer_info(struct ivpu_device *vdev, u64 metric_group_mask, u64 buffer_addr,
+				  u64 buffer_size, u32 *sample_size, u64 *info_size);
 #endif
drivers/accel/ivpu/ivpu_ms.c new file +309 -0

309 lines not on this page · raw message

drivers/accel/ivpu/ivpu_ms.h new file +36 -0
new file mode 100644
index 000000000000..fbd5ebebc3d9
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * Copyright (C) 2020-2024 Intel Corporation
+ */
+#ifndef __IVPU_MS_H__
+#define __IVPU_MS_H__
+
+#include <linux/list.h>
+
+struct drm_device;
+struct drm_file;
+struct ivpu_bo;
+struct ivpu_device;
+struct ivpu_file_priv;
+
+struct ivpu_ms_instance {
+	struct ivpu_bo *bo;
+	struct list_head ms_instance_node;
+	u64 mask;
+	u64 buff_size;
+	u64 active_buff_vpu_addr;
+	u64 inactive_buff_vpu_addr;
+	void *active_buff_ptr;
+	void *inactive_buff_ptr;
+	u64 leftover_bytes;
+	void *leftover_addr;
+};
+
+int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
+int ivpu_ms_stop_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
+int ivpu_ms_get_data_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
+int ivpu_ms_get_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
+void ivpu_ms_cleanup(struct ivpu_file_priv *file_priv);
+void ivpu_ms_cleanup_all(struct ivpu_device *vdev);
+
+#endif /* __IVPU_MS_H__ */
drivers/accel/ivpu/ivpu_pm.c +4 -0
index 4f5ea466731f..7b2aa205fdec 100644
@@ -18,6 +18,7 @@
 #include "ivpu_job.h"
 #include "ivpu_jsm_msg.h"
 #include "ivpu_mmu.h"
+#include "ivpu_ms.h"
 #include "ivpu_pm.h"
 
 static bool ivpu_disable_recovery;
@@ -131,6 +132,7 @@ static void ivpu_pm_recovery_work(struct work_struct *work)
 	ivpu_suspend(vdev);
 	ivpu_pm_prepare_cold_boot(vdev);
 	ivpu_jobs_abort_all(vdev);
+	ivpu_ms_cleanup_all(vdev);
 
 	ret = ivpu_resume(vdev);
 	if (ret)
@@ -333,6 +335,8 @@ void ivpu_pm_reset_prepare_cb(struct pci_dev *pdev)
 	ivpu_hw_reset(vdev);
 	ivpu_pm_prepare_cold_boot(vdev);
 	ivpu_jobs_abort_all(vdev);
+	ivpu_ms_cleanup_all(vdev);
+
 	ivpu_dbg(vdev, PM, "Pre-reset done.\n");
 }
 
include/uapi/drm/ivpu_accel.h +68 -1

92 lines not on this page · raw message

Signature · 1 line
2.43.2
#19 lore raw

Re: [PATCH 08/12] accel/ivpu: Add NPU profiling support

Quoted 32 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

Implement time based Metric Streamer profiling UAPI.

This is a generic mechanism allowing user mode tools to sample NPU metrics. These metrics are defined by the FW and transparent to the driver.

The user space can check for this feature by checking DRM_IVPU_CAP_METRIC_STREAMER driver capability.

---
  drivers/accel/ivpu/Makefile       |   3 +-
  drivers/accel/ivpu/ivpu_drv.c     |  14 +-
  drivers/accel/ivpu/ivpu_drv.h     |   3 +
  drivers/accel/ivpu/ivpu_jsm_msg.c |  98 ++++++++++
  drivers/accel/ivpu/ivpu_jsm_msg.h |   8 +-
  drivers/accel/ivpu/ivpu_ms.c      | 309 ++++++++++++++++++++++++++++++
  drivers/accel/ivpu/ivpu_ms.h      |  36 ++++
  drivers/accel/ivpu/ivpu_pm.c      |   4 +
  include/uapi/drm/ivpu_accel.h     |  69 ++++++-
  9 files changed, 540 insertions(+), 4 deletions(-)

create mode 100644 drivers/accel/ivpu/ivpu_ms.c
create mode 100644 drivers/accel/ivpu/ivpu_ms.h

drivers/accel/ivpu/Makefile +0 -0
index 95ff7ad16338..726cf8f28ea3 100644

drivers/accel/ivpu/Makefile line 2

Quoted 3 lines
drivers/accel/ivpu/Makefile +1 -1
@@ -1,5 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0-only
-# Copyright (C) 2023 Intel Corporation
+# Copyright (C) 2022-2024 Intel Corporation

Are you sure this is correct? Seems odd to be adding 2022 in addition to 2024 at this point.

-Jeff

#20 lore raw

Re: [PATCH 08/12] accel/ivpu: Add NPU profiling support

Hi,

Quoted 28 lines · Jeffrey Hugo
Quoted 27 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

Implement time based Metric Streamer profiling UAPI.

This is a generic mechanism allowing user mode tools to sample NPU metrics. These metrics are defined by the FW and transparent to the driver.

The user space can check for this feature by checking DRM_IVPU_CAP_METRIC_STREAMER driver capability.

---
  drivers/accel/ivpu/Makefile       |   3 +- drivers/accel/ivpu/ivpu_drv.c     |  14 +- drivers/accel/ivpu/ivpu_drv.h     |   3 + drivers/accel/ivpu/ivpu_jsm_msg.c |  98 ++++++++++ drivers/accel/ivpu/ivpu_jsm_msg.h |   8 +-

  drivers/accel/ivpu/ivpu_ms.c      | 309 ++++++++++++++++++++++++++++++
  drivers/accel/ivpu/ivpu_ms.h      |  36 ++++
  drivers/accel/ivpu/ivpu_pm.c      |   4 +
  include/uapi/drm/ivpu_accel.h     |  69 ++++++-
  9 files changed, 540 insertions(+), 4 deletions(-)

  create mode 100644 drivers/accel/ivpu/ivpu_ms.c
  create mode 100644 drivers/accel/ivpu/ivpu_ms.h

Quoted 10 lines

drivers/accel/ivpu/Makefile line 2

Quoted 8 lines
drivers/accel/ivpu/Makefile +1 -1
index 95ff7ad16338..726cf8f28ea3 100644
@@ -1,5 +1,5 @@
   # SPDX-License-Identifier: GPL-2.0-only
-# Copyright (C) 2023 Intel Corporation
+# Copyright (C) 2022-2024 Intel Corporation

Are you sure this is correct?  Seems odd to be adding 2022 in addition to 2024 at this point.

This is a typo. I will fix it.

#21 lore raw

PATCH 9/12 accel/ivpu: Add force snoop module parameter

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Add module parameter that enforces snooping for all NPU accesses, both through MMU PTEs mappings and through TCU page table walk override register bits for MMU page walks / configuration access.

---
 drivers/accel/ivpu/ivpu_drv.c     |  4 ++++
 drivers/accel/ivpu/ivpu_drv.h     |  6 ++++++
 drivers/accel/ivpu/ivpu_gem.h     | 11 +++++++----
 drivers/accel/ivpu/ivpu_hw_37xx.c |  6 +++++-
 drivers/accel/ivpu/ivpu_hw_40xx.c |  6 +++++-
 drivers/accel/ivpu/ivpu_mmu.c     | 12 ++++++++----
 6 files changed, 35 insertions(+), 10 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +4 -0
index ece6b212aaf8..87c48fa8d719 100644
@@ -60,6 +60,10 @@ bool ivpu_disable_mmu_cont_pages;
 module_param_named(disable_mmu_cont_pages, ivpu_disable_mmu_cont_pages, bool, 0644);
 MODULE_PARM_DESC(disable_mmu_cont_pages, "Disable MMU contiguous pages optimization");
 
+bool ivpu_force_snoop;
+module_param_named(force_snoop, ivpu_force_snoop, bool, 0644);
+MODULE_PARM_DESC(force_snoop, "Force snooping for NPU host memory access");
+
 struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv)
 {
 	struct ivpu_device *vdev = file_priv->vdev;
drivers/accel/ivpu/ivpu_drv.h +6 -0
index 0f42a3a9e59c..d55f0bdffd71 100644
@@ -167,6 +167,7 @@ extern u8 ivpu_pll_min_ratio;
 extern u8 ivpu_pll_max_ratio;
 extern bool ivpu_sched_mode;
 extern bool ivpu_disable_mmu_cont_pages;
+extern bool ivpu_force_snoop;
 
 #define IVPU_TEST_MODE_FW_TEST            BIT(0)
 #define IVPU_TEST_MODE_NULL_HW            BIT(1)
@@ -241,4 +242,9 @@ static inline bool ivpu_is_fpga(struct ivpu_device *vdev)
 	return ivpu_get_platform(vdev) == IVPU_PLATFORM_FPGA;
 }
 
+static inline bool ivpu_is_force_snoop_enabled(struct ivpu_device *vdev)
+{
+	return ivpu_force_snoop;
+}
+
 #endif /* __IVPU_DRV_H__ */
drivers/accel/ivpu/ivpu_gem.h +7 -4
index fb7117c13eec..d975000abd78 100644
@@ -60,14 +60,17 @@ static inline u32 ivpu_bo_cache_mode(struct ivpu_bo *bo)
 	return bo->flags & DRM_IVPU_BO_CACHE_MASK;
 }
 
-static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
+static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
 {
-	return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
+	return to_ivpu_device(bo->base.base.dev);
 }
 
-static inline struct ivpu_device *ivpu_bo_to_vdev(struct ivpu_bo *bo)
+static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
 {
-	return to_ivpu_device(bo->base.base.dev);
+	if (ivpu_is_force_snoop_enabled(ivpu_bo_to_vdev(bo)))
+		return true;
+
+	return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
 }
 
 static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
drivers/accel/ivpu/ivpu_hw_37xx.c +5 -1
index ce664b6515aa..250291cc1f3a 100644
@@ -514,7 +514,11 @@ static void ivpu_boot_no_snoop_enable(struct ivpu_device *vdev)
 
 	val = REG_SET_FLD(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, NOSNOOP_OVERRIDE_EN, val);
 	val = REG_CLR_FLD(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, AW_NOSNOOP_OVERRIDE, val);
-	val = REG_SET_FLD(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, AR_NOSNOOP_OVERRIDE, val);
+
+	if (ivpu_is_force_snoop_enabled(vdev))
+		val = REG_CLR_FLD(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, AR_NOSNOOP_OVERRIDE, val);
+	else
+		val = REG_SET_FLD(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, AR_NOSNOOP_OVERRIDE, val);
 
 	REGV_WR32(VPU_37XX_HOST_IF_TCU_PTW_OVERRIDES, val);
 }
drivers/accel/ivpu/ivpu_hw_40xx.c +5 -1
index 186cd87079c2..e64ee705d00c 100644
@@ -531,7 +531,11 @@ static void ivpu_boot_no_snoop_enable(struct ivpu_device *vdev)
 
 	val = REG_SET_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, SNOOP_OVERRIDE_EN, val);
 	val = REG_SET_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AW_SNOOP_OVERRIDE, val);
-	val = REG_CLR_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AR_SNOOP_OVERRIDE, val);
+
+	if (ivpu_is_force_snoop_enabled(vdev))
+		val = REG_SET_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AR_SNOOP_OVERRIDE, val);
+	else
+		val = REG_CLR_FLD(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, AR_SNOOP_OVERRIDE, val);
 
 	REGV_WR32(VPU_40XX_HOST_IF_TCU_PTW_OVERRIDES, val);
 }
drivers/accel/ivpu/ivpu_mmu.c +8 -4
index 2e46b322c450..8682e6145520 100644
@@ -519,7 +519,8 @@ static int ivpu_mmu_cmdq_sync(struct ivpu_device *vdev)
 	if (ret)
 		return ret;
 
-	clflush_cache_range(q->base, IVPU_MMU_CMDQ_SIZE);
+	if (!ivpu_is_force_snoop_enabled(vdev))
+		clflush_cache_range(q->base, IVPU_MMU_CMDQ_SIZE);
 	REGV_WR32(IVPU_MMU_REG_CMDQ_PROD, q->prod);
 
 	ret = ivpu_mmu_cmdq_wait_for_cons(vdev);
@@ -567,7 +568,8 @@ static int ivpu_mmu_reset(struct ivpu_device *vdev)
 	int ret;
 
 	memset(mmu->cmdq.base, 0, IVPU_MMU_CMDQ_SIZE);
-	clflush_cache_range(mmu->cmdq.base, IVPU_MMU_CMDQ_SIZE);
+	if (!ivpu_is_force_snoop_enabled(vdev))
+		clflush_cache_range(mmu->cmdq.base, IVPU_MMU_CMDQ_SIZE);
 	mmu->cmdq.prod = 0;
 	mmu->cmdq.cons = 0;
 
@@ -661,7 +663,8 @@ static void ivpu_mmu_strtab_link_cd(struct ivpu_device *vdev, u32 sid)
 	WRITE_ONCE(entry[1], str[1]);
 	WRITE_ONCE(entry[0], str[0]);
 
-	clflush_cache_range(entry, IVPU_MMU_STRTAB_ENT_SIZE);
+	if (!ivpu_is_force_snoop_enabled(vdev))
+		clflush_cache_range(entry, IVPU_MMU_STRTAB_ENT_SIZE);
 
 	ivpu_dbg(vdev, MMU, "STRTAB write entry (SSID=%u): 0x%llx, 0x%llx\n", sid, str[0], str[1]);
 }
@@ -735,7 +738,8 @@ static int ivpu_mmu_cd_add(struct ivpu_device *vdev, u32 ssid, u64 cd_dma)
 	WRITE_ONCE(entry[3], cd[3]);
 	WRITE_ONCE(entry[0], cd[0]);
 
-	clflush_cache_range(entry, IVPU_MMU_CDTAB_ENT_SIZE);
+	if (!ivpu_is_force_snoop_enabled(vdev))
+		clflush_cache_range(entry, IVPU_MMU_CDTAB_ENT_SIZE);
 
 	ivpu_dbg(vdev, MMU, "CDTAB %s entry (SSID=%u, dma=%pad): 0x%llx, 0x%llx, 0x%llx, 0x%llx\n",
 		 cd_dma ? "write" : "clear", ssid, &cd_dma, cd[0], cd[1], cd[2], cd[3]);
Signature · 1 line
2.43.2
Reviewed-by on v1 9/12
#22 lore raw

Re: [PATCH 09/12] accel/ivpu: Add force snoop module parameter

Quoted 8 lines · Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Add module parameter that enforces snooping for all NPU accesses, both through MMU PTEs mappings and through TCU page table walk override register bits for MMU page walks / configuration access.

#23 lore raw

PATCH 10/12 accel/ivpu: Configure fw logging using debugfs

In reply to Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

Add fw_dyndbg file that can be used to control FW logging.

---
 drivers/accel/ivpu/ivpu_debugfs.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/accel/ivpu/ivpu_debugfs.c +26 -0
index 6ff967e595cf..b6c7d6a53c79 100644
@@ -145,6 +145,30 @@ static const struct file_operations dvfs_mode_fops = {
 	.write = dvfs_mode_fops_write,
 };
 
+static ssize_t
+fw_dyndbg_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
+{
+	struct ivpu_device *vdev = file->private_data;
+	char buffer[VPU_DYNDBG_CMD_MAX_LEN] = {};
+	int ret;
+
+	if (size >= VPU_DYNDBG_CMD_MAX_LEN)
+		return -EINVAL;
+
+	ret = strncpy_from_user(buffer, user_buf, size);
+	if (ret < 0)
+		return ret;
+
+	ivpu_jsm_dyndbg_control(vdev, buffer, size);
+	return size;
+}
+
+static const struct file_operations fw_dyndbg_fops = {
+	.owner = THIS_MODULE,
+	.open = simple_open,
+	.write = fw_dyndbg_fops_write,
+};
+
 static int fw_log_show(struct seq_file *s, void *v)
 {
 	struct ivpu_device *vdev = s->private;
@@ -369,6 +393,8 @@ void ivpu_debugfs_init(struct ivpu_device *vdev)
 	debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
 			    &dvfs_mode_fops);
 
+	debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev,
+			    &fw_dyndbg_fops);
 	debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
 			    &fw_log_fops);
 	debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
Signature · 1 line
2.43.2
#24 lore raw

PATCH 11/12 accel/ivpu: Increase reset counter when warm boot fails

In reply to Jacek Lawrynowicz

Failed warm boot causes a cold boot that looses FW state and is equivalent to a recovery or reset, so reset_counter should be incremented in order for this failure to be detected by tests.

---
 drivers/accel/ivpu/ivpu_pm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/accel/ivpu/ivpu_pm.c +1 -0
index 7b2aa205fdec..02b4eac13f8b 100644
@@ -264,6 +264,7 @@ int ivpu_pm_runtime_suspend_cb(struct device *dev)
 
 	if (!hw_is_idle) {
 		ivpu_err(vdev, "NPU failed to enter idle, force suspended.\n");
+		atomic_inc(&vdev->pm->reset_counter);
 		ivpu_fw_log_dump(vdev);
 		ivpu_pm_prepare_cold_boot(vdev);
 	} else {
Signature · 1 line
2.43.2
Reviewed-by on v1 11/12
#25 lore raw

Re: [PATCH 11/12] accel/ivpu: Increase reset counter when warm boot fails

Quoted 5 lines · Jacek Lawrynowicz

Failed warm boot causes a cold boot that looses FW state and is equivalent to a recovery or reset, so reset_counter should be incremented in order for this failure to be detected by tests.

#26 lore raw

PATCH 12/12 accel/ivpu: Share NPU busy time in sysfs

In reply to Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

The driver tracks the time spent by NPU executing jobs and shares it through sysfs npu_busy_time_us file. It can be then used by user space applications to monitor device utilization.

NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing.

---
 drivers/accel/ivpu/Makefile     |  3 +-
 drivers/accel/ivpu/ivpu_drv.c   |  2 ++
 drivers/accel/ivpu/ivpu_drv.h   |  3 ++
 drivers/accel/ivpu/ivpu_job.c   | 23 ++++++++++++-
 drivers/accel/ivpu/ivpu_sysfs.c | 58 +++++++++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_sysfs.h | 13 ++++++++
 6 files changed, 100 insertions(+), 2 deletions(-)
 create mode 100644 drivers/accel/ivpu/ivpu_sysfs.c
 create mode 100644 drivers/accel/ivpu/ivpu_sysfs.h
drivers/accel/ivpu/Makefile +2 -1
index 726cf8f28ea3..f61d8d3320e2 100644
@@ -14,7 +14,8 @@ intel_vpu-y := \
 	ivpu_mmu.o \
 	ivpu_mmu_context.o \
 	ivpu_ms.o \
-	ivpu_pm.o
+	ivpu_pm.o \
+	ivpu_sysfs.o
 
 intel_vpu-$(CONFIG_DEBUG_FS) += ivpu_debugfs.o
 
drivers/accel/ivpu/ivpu_drv.c +2 -0
index 87c48fa8d719..b34d1766891c 100644
@@ -28,6 +28,7 @@
 #include "ivpu_mmu_context.h"
 #include "ivpu_ms.h"
 #include "ivpu_pm.h"
+#include "ivpu_sysfs.h"
 
 #ifndef DRIVER_VERSION_STR
 #define DRIVER_VERSION_STR __stringify(DRM_IVPU_DRIVER_MAJOR) "." \
@@ -696,6 +697,7 @@ static int ivpu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return ret;
 
 	ivpu_debugfs_init(vdev);
+	ivpu_sysfs_init(vdev);
 
 	ret = drm_dev_register(&vdev->drm, 0);
 	if (ret) {
drivers/accel/ivpu/ivpu_drv.h +3 -0
index d55f0bdffd71..04a054080eff 100644
@@ -135,6 +135,9 @@ struct ivpu_device {
 
 	atomic64_t unique_id_counter;
 
+	ktime_t busy_start_ts;
+	ktime_t busy_time;
+
 	struct {
 		int boot;
 		int jsm;
drivers/accel/ivpu/ivpu_job.c +22 -1
index 1d7b4388eb3b..845181b48b3a 100644
@@ -438,11 +438,28 @@ ivpu_job_create(struct ivpu_file_priv *file_priv, u32 engine_idx, u32 bo_count)
 	return NULL;
 }
 
+static struct ivpu_job *ivpu_job_remove_from_submitted_jobs(struct ivpu_device *vdev, u32 job_id)
+{
+	struct ivpu_job *job;
+
+	xa_lock(&vdev->submitted_jobs_xa);
+	job = __xa_erase(&vdev->submitted_jobs_xa, job_id);
+
+	if (xa_empty(&vdev->submitted_jobs_xa) && job) {
+		vdev->busy_time = ktime_add(ktime_sub(ktime_get(), vdev->busy_start_ts),
+					    vdev->busy_time);
+	}
+
+	xa_unlock(&vdev->submitted_jobs_xa);
+
+	return job;
+}
+
 static int ivpu_job_signal_and_destroy(struct ivpu_device *vdev, u32 job_id, u32 job_status)
 {
 	struct ivpu_job *job;
 
-	job = xa_erase(&vdev->submitted_jobs_xa, job_id);
+	job = ivpu_job_remove_from_submitted_jobs(vdev, job_id);
 	if (!job)
 		return -ENOENT;
 
@@ -477,6 +494,7 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
 	struct ivpu_device *vdev = job->vdev;
 	struct xa_limit job_id_range;
 	struct ivpu_cmdq *cmdq;
+	bool is_first_job;
 	int ret;
 
 	ret = ivpu_rpm_get(vdev);
@@ -497,6 +515,7 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
 	job_id_range.max = job_id_range.min | JOB_ID_JOB_MASK;
 
 	xa_lock(&vdev->submitted_jobs_xa);
+	is_first_job = xa_empty(&vdev->submitted_jobs_xa);
 	ret = __xa_alloc(&vdev->submitted_jobs_xa, &job->job_id, job, job_id_range, GFP_KERNEL);
 	if (ret) {
 		ivpu_dbg(vdev, JOB, "Too many active jobs in ctx %d\n",
@@ -516,6 +535,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
 		wmb(); /* Flush WC buffer for jobq header */
 	} else {
 		ivpu_cmdq_ring_db(vdev, cmdq);
+		if (is_first_job)
+			vdev->busy_start_ts = ktime_get();
 	}
 
 	ivpu_dbg(vdev, JOB, "Job submitted: id %3u ctx %2d engine %d prio %d addr 0x%llx next %d\n",
drivers/accel/ivpu/ivpu_sysfs.c new file +58 -0

58 lines not on this page · raw message

drivers/accel/ivpu/ivpu_sysfs.h new file +13 -0
new file mode 100644
index 000000000000..9836f09b35a3
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2024 Intel Corporation
+ */
+
+#ifndef __IVPU_SYSFS_H__
+#define __IVPU_SYSFS_H__
+
+#include "ivpu_drv.h"
+
+void ivpu_sysfs_init(struct ivpu_device *vdev);
+
+#endif /* __IVPU_SYSFS_H__ */
Signature · 1 line
2.43.2
#27 lore raw

Re: [PATCH 12/12] accel/ivpu: Share NPU busy time in sysfs

Quoted 7 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

The driver tracks the time spent by NPU executing jobs and shares it through sysfs npu_busy_time_us file. It can be then used by user space applications to monitor device utilization.

Quoted 5 lines

NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing.

This feels like something that would normally be handled by perf. Why not use that mechanism?

-Jeff

#28 lore raw

Re: [PATCH 12/12] accel/ivpu: Share NPU busy time in sysfs

Hi,

Quoted 8 lines · Jeffrey Hugo
Quoted 7 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

The driver tracks the time spent by NPU executing jobs and shares it through sysfs npu_busy_time_us file. It can be then used by user space applications to monitor device utilization.

Quoted 7 lines
Quoted 5 lines

NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing.

This feels like something that would normally be handled by perf. Why not use that mechanism?

Yeah, probably but we had several request to provide easy to use interface for this metric that could be integrated in various user space apps/tools that do not use ftrace.

#29 lore raw

Re: [PATCH 12/12] accel/ivpu: Share NPU busy time in sysfs

Quoted 14 lines · Jacek Lawrynowicz

Hi,

Quoted 11 lines · Jeffrey Hugo
Quoted 10 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

The driver tracks the time spent by NPU executing jobs and shares it through sysfs npu_busy_time_us file. It can be then used by user space applications to monitor device utilization.

NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This feels like something that would normally be handled by perf. Why not use that mechanism?

Yeah, probably but we had several request to provide easy to use interface for this metric that could be integrated in various user space apps/tools that do not use ftrace.

Probably more Perf/PMU aka performance counters? Which would be scriptable via $kernel/tools/perf or directly via perf_event_open(2) and read(2).

Note it is not easy to get right and in the i915 implementation (see i915_pmu.c) we have a known issue with PCI hot unplug and use after free which needs input from perf core folks.

Regards,

Tvrtko

#30 lore raw

Re: [PATCH 12/12] accel/ivpu: Share NPU busy time in sysfs

Hi,

Quoted 19 lines · Tvrtko Ursulin
Quoted 17 lines · Jacek Lawrynowicz

Hi,

Quoted 14 lines · Jeffrey Hugo
Quoted 12 lines · Jacek Lawrynowicz

From: Tomasz Rusinowicz <[email protected]>

The driver tracks the time spent by NPU executing jobs and shares it through sysfs npu_busy_time_us file. It can be then used by user space applications to monitor device utilization.

NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This feels like something that would normally be handled by perf. Why not use that mechanism?

Yeah, probably but we had several request to provide easy to use interface for this metric that could be integrated in various user space apps/tools that do not use ftrace.

Probably more Perf/PMU aka performance counters? Which would be scriptable via $kernel/tools/perf or directly via perf_event_open(2) and read(2).

Note it is not easy to get right and in the i915 implementation (see i915_pmu.c) we have a known issue with PCI hot unplug and use after free which needs input from perf core folks.

OK, we will consider using perf/pmu for NPU but for the moment I would like to keep this sysfs interface. It so simple it can be used from bash and it always can be removed if obsoleted by something fancier.