Skip to contentSkip to conversation

Support host1x actmon

PATCH In review Johnny Liu 2 participants 8 messages Dec 9, 2024 – Dec 10, 2024

Subsystems (6)
lore
Share & tools
lore

Johnny Liu

author
#0 lore raw

cover Support host1x actmon

Activity monitoring (actmon for short) is a means to dynamically measure the utilization of units in the system to help drive software power management policies.

In Tegra, Dynamic Voltage and Frequency Scaling (DVFS) is the primary dynamic power management mechanism. It uses utilization information from various units to select the most efficient frequency and thereby, voltage that the unit should operate while providing the requisite performance.

---
Johnny Liu (5):
dt-bindings: display: tegra: Add actmon information
arm64: tegra: Add actmon information
gpu: host1x: Support device monitoring with actmon drm/tegra: nvdec: Register the device with actmon drm/tegra: vic: Register the device with actmon

 .../display/tegra/nvidia,tegra20-host1x.yaml  |  45 +-
 arch/arm64/boot/dts/nvidia/tegra234.dtsi      |  10 +-
 drivers/gpu/drm/tegra/nvdec.c                 |  82 ++-
 drivers/gpu/drm/tegra/vic.c                   |  39 +-
 drivers/gpu/drm/tegra/vic.h                   |   9 +
 drivers/gpu/host1x/Makefile                   |   1 +
 drivers/gpu/host1x/actmon.c                   | 558 ++++++++++++++++++
 drivers/gpu/host1x/actmon.h                   |  46 ++
 drivers/gpu/host1x/dev.c                      |  71 ++-
 drivers/gpu/host1x/dev.h                      |  57 +-
 drivers/gpu/host1x/hw/actmon.h                |  49 ++
 drivers/gpu/host1x/hw/host1x08.c              |   6 +-
 drivers/gpu/host1x/hw/hw_host1x08_common.h    |  16 +-
 drivers/gpu/host1x/hw/intr_general_hw.c       |  83 +++
 include/linux/host1x.h                        |  30 +-
 15 files changed, 1074 insertions(+), 28 deletions(-)
 create mode 100644 drivers/gpu/host1x/actmon.c
 create mode 100644 drivers/gpu/host1x/actmon.h
 create mode 100644 drivers/gpu/host1x/hw/actmon.h
 create mode 100644 drivers/gpu/host1x/hw/intr_general_hw.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/5 dt-bindings: display: tegra: Add actmon information

An activity monitor (actmon) is used to measure the device runtime utilization to help drive software power management policies.

Extend the reg space to include actmon aperture for actmon configuration through host1x.

Extend the number of clocks to include actmon clock, which is shared between unit actmons for different host1x clients.

---
 .../display/tegra/nvidia,tegra20-host1x.yaml  | 45 ++++++++++++++++---
 1 file changed, 39 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.yaml +39 -6
index 3563378a01af4..46e1d27ddef8b 100644
@@ -32,11 +32,11 @@ properties:
 
   reg:
     minItems: 1
-    maxItems: 3
+    maxItems: 4
 
   reg-names:
     minItems: 1
-    maxItems: 3
+    maxItems: 4
 
   interrupts:
     minItems: 1
@@ -60,12 +60,12 @@ properties:
     maxItems: 1
 
   clocks:
-    description: Must contain one entry, for the module clock. See
-      ../clocks/clock-bindings.txt for details.
+    minItems: 1
+    maxItems: 2
 
   clock-names:
-    items:
-      - const: host1x
+    minItems: 1
+    maxItems: 2
 
   resets:
     minItems: 1 # MC reset is optional on Tegra186 and later
@@ -132,6 +132,15 @@ allOf:
           items:
             - const: syncpt
             - const: host1x
+
+        clocks:
+          items:
+            - description: host1x clock
+
+        clock-names:
+          items:
+            - const: host1x
+
       required:
         - resets
         - reset-names
@@ -170,6 +179,14 @@ allOf:
             - const: syncpt
             - const: host1x
 
+        clocks:
+          items:
+            - description: host1x clock
+
+        clock-names:
+          items:
+            - const: host1x
+
         iommu-map:
           description: Specification of stream IDs available for memory context device
             use. Should be a mapping of IDs 0..n to IOMMU entries corresponding to
@@ -195,16 +212,20 @@ allOf:
     then:
       properties:
         reg-names:
+          minItems: 3
           items:
             - const: common
             - const: hypervisor
             - const: vm
+            - const: actmon
 
         reg:
+          minItems: 3
           items:
             - description: region used by host1x server
             - description: region used by the hypervisor
             - description: region assigned to the virtual machine
+            - description: region used for configuring actmon for host1x clients
 
         interrupts:
           items:
@@ -230,6 +251,18 @@ allOf:
             - const: syncpt7
             - const: host1x
 
+        clocks:
+          minItems: 1
+          items:
+            - description: host1x clock
+            - description: actmon clock
+
+        clock-names:
+          minItems: 1
+          items:
+            - const: host1x
+            - const: actmon
+
         iommu-map:
           description: Specification of stream IDs available for memory context device
             use. Should be a mapping of IDs 0..n to IOMMU entries corresponding to
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/5] dt-bindings: display: tegra: Add actmon information

Quoted 10 lines · Johnny Liu

An activity monitor (actmon) is used to measure the device runtime utilization to help drive software power management policies.

Extend the reg space to include actmon aperture for actmon configuration through host1x.

Extend the number of clocks to include actmon clock, which is shared between unit actmons for different host1x clients.

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Please kindly resend and include all necessary To/Cc entries. </form letter>

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH 1/5] dt-bindings: display: tegra: Add actmon information

Quoted 9 lines
Quoted 9 lines

An activity monitor (actmon) is used to measure the device runtime utilization to help drive software power management policies.

Extend the reg space to include actmon aperture for actmon configuration through host1x.

Extend the number of clocks to include actmon clock, which is shared between unit actmons for different host1x clients.

Quoted 7 lines
Quoted 1 line

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Thanks for your correction. I will resend the patch and add necessary people in the to-list, and add mailing-list to cc-list.

Quoted 6 lines

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

Thanks for your guidance.

Quoted 3 lines

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Thanks for your information. I will cover devicetree list in the next patch series.

Quoted 2 lines

Please kindly resend and include all necessary To/Cc entries. </form letter>

Ack.

Best regards,
Johnny

author
#4 lore raw

PATCH 2/5 arm64: tegra: Add actmon information

In reply to Johnny Liu

An activity monitor (actmon) is used to measure the device runtime utilization to help drive software power management policies.

Configuration of actmon is under the host1x address space. Therefore, add the actmon aperture under the host1x.

All unit actmons for host1x clients share the same actmon clock source from host1x. Therefore, add the clock phandle in host1x.

---
 arch/arm64/boot/dts/nvidia/tegra234.dtsi | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +6 -4
index f2e2d8d6845bf..dee12754b97de 100644
@@ -4311,8 +4311,9 @@ host1x@13e00000 {
 			compatible = "nvidia,tegra234-host1x";
 			reg = <0x0 0x13e00000 0x0 0x10000>,
 			      <0x0 0x13e10000 0x0 0x10000>,
-			      <0x0 0x13e40000 0x0 0x10000>;
-			reg-names = "common", "hypervisor", "vm";
+			      <0x0 0x13e40000 0x0 0x10000>,
+			      <0x0 0x13ef0000 0x0 0x60000>;
+			reg-names = "common", "hypervisor", "vm", "actmon";
 			interrupts = <GIC_SPI 448 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 449 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 450 IRQ_TYPE_LEVEL_HIGH>,
@@ -4324,8 +4325,9 @@ host1x@13e00000 {
 				     <GIC_SPI 263 IRQ_TYPE_LEVEL_HIGH>;
 			interrupt-names = "syncpt0", "syncpt1", "syncpt2", "syncpt3", "syncpt4",
 					  "syncpt5", "syncpt6", "syncpt7", "host1x";
-			clocks = <&bpmp TEGRA234_CLK_HOST1X>;
-			clock-names = "host1x";
+			clocks = <&bpmp TEGRA234_CLK_HOST1X>,
+				 <&bpmp TEGRA234_CLK_ACTMON>;
+			clock-names = "host1x", "actmon";
 
 			#address-cells = <2>;
 			#size-cells = <2>;
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 3/5 gpu: host1x: Support device monitoring with actmon

In reply to Johnny Liu

An activity monitor (actmon) is used to measure the device runtime utilization to help drive software power management policies, such as device dynamic frequency scaling.

For every host1x client, an actmon is employed to monitor its runtime utilization. Upon detecting an actmon watermark breach against the sampled runtime utilization value, it will trigger an interrupt to the host1x subsystem to trigger device dynamic frequency scaling if supported by the client.

Upon registration with actmon within the host1x subsystem, a host1x client gains the ability to activate/deactivate its own actmon during the device resume/suspend cycle. This ensures that a host1x client runs at the power-optimal frequency when active, while also preventing unnecessary actmon interrupts during periods of inactivity.

---
 drivers/gpu/host1x/Makefile                |   1 +
 drivers/gpu/host1x/actmon.c                | 558 +++++++++++++++++++++
 drivers/gpu/host1x/actmon.h                |  46 ++
 drivers/gpu/host1x/dev.c                   |  71 ++-
 drivers/gpu/host1x/dev.h                   |  57 ++-
 drivers/gpu/host1x/hw/actmon.h             |  49 ++
 drivers/gpu/host1x/hw/host1x08.c           |   6 +-
 drivers/gpu/host1x/hw/hw_host1x08_common.h |  16 +-
 drivers/gpu/host1x/hw/intr_general_hw.c    |  83 +++
 include/linux/host1x.h                     |  30 +-
 10 files changed, 902 insertions(+), 15 deletions(-)
 create mode 100644 drivers/gpu/host1x/actmon.c
 create mode 100644 drivers/gpu/host1x/actmon.h
 create mode 100644 drivers/gpu/host1x/hw/actmon.h
 create mode 100644 drivers/gpu/host1x/hw/intr_general_hw.c
drivers/gpu/host1x/Makefile +1 -0
index ee5286ffe08d5..230afea0f2aa5 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 host1x-y = \
+	actmon.o \
 	bus.o \
 	syncpt.o \
 	dev.o \
drivers/gpu/host1x/actmon.c new file +558 -0

558 lines not on this page · raw message

drivers/gpu/host1x/actmon.h new file +46 -0

46 lines not on this page · raw message

drivers/gpu/host1x/dev.c +67 -4

161 lines not on this page · raw message

drivers/gpu/host1x/dev.h +54 -3

126 lines not on this page · raw message

drivers/gpu/host1x/hw/actmon.h new file +49 -0

49 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x08.c +4 -2
index 754890c34c740..a32b263bcbc75 100644
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Host1x init for Tegra234 SoCs
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  *
- * Copyright (c) 2022 NVIDIA Corporation.
+ * Host1x init for Tegra234 SoCs
  */
 
 /* include hw specification */
@@ -15,6 +15,7 @@
 #include "cdma_hw.c"
 #include "channel_hw.c"
 #include "debug_hw.c"
+#include "intr_general_hw.c"
 #include "intr_hw.c"
 #include "syncpt_hw.c"
 
@@ -26,6 +27,7 @@ int host1x08_init(struct host1x *host)
 	host->cdma_op = &host1x_cdma_ops;
 	host->cdma_pb_op = &host1x_pushbuffer_ops;
 	host->syncpt_op = &host1x_syncpt_ops;
+	host->intr_general_op = &host1x_intr_general_ops;
 	host->intr_op = &host1x_intr_ops;
 	host->debug_op = &host1x_debug_ops;
 
drivers/gpu/host1x/hw/hw_host1x08_common.h +13 -3
index 8e0c99150ec2c..b6c210f357428 100644
@@ -1,6 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (c) 2022 NVIDIA Corporation.
+/* SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  */
 
 #define HOST1X_COMMON_OFA_MLOCK			0x4050
@@ -9,3 +8,14 @@
 #define HOST1X_COMMON_NVENC_MLOCK		0x407c
 #define HOST1X_COMMON_NVDEC_MLOCK		0x4080
 #define HOST1X_COMMON_NVJPG_MLOCK		0x4084
+
+#define HOST1X_COMMON_INTR_CPU0_MASK		0x4
+#define HOST1X_COMMON_THOST_INTRSTATUS		0x1c
+#define HOST1X_COMMON_THOST_INTRMASK		0x30
+#define HOST1X_COMMON_THOST_GLOBAL_INTRMASK	0x44
+
+#define HOST1X_COMMON_THOST_INTRMASK_VIC_ACTMON(v)		((v) << 3)
+#define HOST1X_COMMON_THOST_INTRMASK_NVDEC_ACTMON(v)		((v) << 4)
+
+#define HOST1X_COMMON_THOST_INTRSTATUS_VIC_ACTMON_INTR		BIT(3)
+#define HOST1X_COMMON_THOST_INTRSTATUS_NVDEC_ACTMON_INTR	BIT(4)
drivers/gpu/host1x/hw/intr_general_hw.c new file +83 -0

83 lines not on this page · raw message

include/linux/host1x.h +27 -3
index 9c8119ed13a4b..903f1a41b218f 100644
@@ -1,6 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
+/* SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-FileCopyrightText: Copyright (c) 2009-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  */
 
 #ifndef __LINUX_HOST1X_H
@@ -22,6 +21,13 @@ enum host1x_class {
 	HOST1X_CLASS_NVDEC1 = 0xF5,
 };
 
+enum host1x_actmon_wmark_event {
+	HOST1X_ACTMON_AVG_WMARK_BELOW,
+	HOST1X_ACTMON_AVG_WMARK_ABOVE,
+	HOST1X_ACTMON_CONSEC_WMARK_BELOW,
+	HOST1X_ACTMON_CONSEC_WMARK_ABOVE,
+};
+
 struct host1x;
 struct host1x_client;
 struct iommu_group;
@@ -63,6 +69,8 @@ static inline void host1x_bo_cache_destroy(struct host1x_bo_cache *cache)
  * @late_exit: host1x client late tear down code
  * @suspend: host1x client suspend code
  * @resume: host1x client resume code
+ * @get_rate: host1x client get clock rate code
+ * @actmon_event: host1x client actmon event handling code in threaded interrupt context
  */
 struct host1x_client_ops {
 	int (*early_init)(struct host1x_client *client);
@@ -71,8 +79,13 @@ struct host1x_client_ops {
 	int (*late_exit)(struct host1x_client *client);
 	int (*suspend)(struct host1x_client *client);
 	int (*resume)(struct host1x_client *client);
+	unsigned long (*get_rate)(struct host1x_client *client);
+	void (*actmon_event)(struct host1x_client *client,
+			     enum host1x_actmon_wmark_event event);
 };
 
+struct host1x_actmon;
+
 /**
  * struct host1x_client - host1x client structure
  * @list: list node for the host1x client
@@ -88,6 +101,7 @@ struct host1x_client_ops {
  * @usecount: reference count for this structure
  * @lock: mutex for mutually exclusive concurrency
  * @cache: host1x buffer object cache
+ * @actmon: unit actmon for this host1x client
  */
 struct host1x_client {
 	struct list_head list;
@@ -108,6 +122,8 @@ struct host1x_client {
 	struct mutex lock;
 
 	struct host1x_bo_cache cache;
+
+	struct host1x_actmon *actmon;
 };
 
 /*
@@ -494,4 +510,12 @@ static inline void host1x_memory_context_put(struct host1x_memory_context *cd)
 }
 #endif
 
+int host1x_actmon_register(struct host1x_client *client);
+void host1x_actmon_unregister(struct host1x_client *client);
+void host1x_actmon_enable(struct host1x_client *client);
+void host1x_actmon_disable(struct host1x_client *client);
+void host1x_actmon_update_client_rate(struct host1x_client *client,
+				      unsigned long rate,
+				      u32 *weight);
+
 #endif
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 4/5 drm/tegra: nvdec: Register the device with actmon

In reply to Johnny Liu

By registering the nvdec with actmon, engine load information can be exported to the user through debugfs for engine profiling purpose.

---
 drivers/gpu/drm/tegra/nvdec.c | 82 ++++++++++++++++++++++++++++++++++-
 1 file changed, 80 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/nvdec.c +80 -2
index 4860790666af5..f546e89b2bbd0 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2015-2022, NVIDIA Corporation.
+ * SPDX-FileCopyrightText: Copyright (c) 2015-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  */
 
 #include <linux/clk.h>
@@ -22,8 +22,21 @@
 #include "riscv.h"
 #include "vic.h"
 
-#define NVDEC_FALCON_DEBUGINFO			0x1094
+#define NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_MASK	0xCAU
+#define NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_BORPS	0xCBU
+#define NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_WEIGHT	0xC9U
+#define NVDEC_FALCON_UCLASS_METHOD_OFFSET       0x40
+#define NVDEC_FALCON_UCLASS_METHOD_DATA         0x44
+#define NVDEC_FALCON_DEBUGINFO                  0x1094
 #define NVDEC_TFBIF_TRANSCFG			0x2c44
+#define NVDEC_TFBIF_ACTMON_ACTIVE_MASK		0x2c4c
+#define NVDEC_TFBIF_ACTMON_ACTIVE_BORPS		0x2c50
+#define NVDEC_TFBIF_ACTMON_ACTIVE_WEIGHT	0x2c54
+
+#define NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STARVED	BIT(0)
+#define NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STALLED	BIT(1)
+#define NVDEC_TFBIF_ACTMON_ACTIVE_MASK_DELAYED	BIT(2)
+#define NVDEC_TFBIF_ACTMON_ACTIVE_BORPS_ACTIVE	BIT(7)
 
 struct nvdec_config {
 	const char *firmware;
@@ -306,6 +319,56 @@ static int nvdec_load_falcon_firmware(struct nvdec *nvdec)
 	return err;
 }
 
+static void nvdec_actmon_reg_init(struct nvdec *nvdec)
+{
+	if (nvdec->config->has_riscv) {
+		nvdec_writel(nvdec,
+			     NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_MASK,
+			     NVDEC_FALCON_UCLASS_METHOD_OFFSET);
+		nvdec_writel(nvdec,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_DELAYED |
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STALLED |
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STARVED,
+			     NVDEC_FALCON_UCLASS_METHOD_DATA);
+		nvdec_writel(nvdec,
+			     NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_BORPS,
+			     NVDEC_FALCON_UCLASS_METHOD_OFFSET);
+		nvdec_writel(nvdec,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_BORPS_ACTIVE,
+			     NVDEC_FALCON_UCLASS_METHOD_DATA);
+	} else {
+		nvdec_writel(nvdec,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_DELAYED |
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STALLED |
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK_STARVED,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_MASK);
+		nvdec_writel(nvdec,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_BORPS_ACTIVE,
+			     NVDEC_TFBIF_ACTMON_ACTIVE_BORPS);
+	}
+}
+
+static void nvdec_count_weight_init(struct nvdec *nvdec, unsigned long rate)
+{
+	const struct nvdec_config *config = nvdec->config;
+	struct host1x_client *client = &nvdec->client.base;
+	u32 weight;
+
+	host1x_actmon_update_client_rate(client, rate, &weight);
+
+	if (!weight)
+		return;
+
+	if (!config->has_riscv) {
+		nvdec_writel(nvdec, weight, NVDEC_TFBIF_ACTMON_ACTIVE_WEIGHT);
+	} else {
+		nvdec_writel(nvdec,
+			     NVDEC_FW_MTHD_ADDR_ACTMON_ACTIVE_WEIGHT,
+			     NVDEC_FALCON_UCLASS_METHOD_OFFSET);
+		nvdec_writel(nvdec, weight, NVDEC_FALCON_UCLASS_METHOD_DATA);
+	}
+}
+
 static __maybe_unused int nvdec_runtime_resume(struct device *dev)
 {
 	struct nvdec *nvdec = dev_get_drvdata(dev);
@@ -331,6 +394,10 @@ static __maybe_unused int nvdec_runtime_resume(struct device *dev)
 			goto disable;
 	}
 
+	nvdec_actmon_reg_init(nvdec);
+	nvdec_count_weight_init(nvdec, clk_get_rate(nvdec->clks[0].clk));
+	host1x_actmon_enable(&nvdec->client.base);
+
 	return 0;
 
 disable:
@@ -346,6 +413,8 @@ static __maybe_unused int nvdec_runtime_suspend(struct device *dev)
 
 	clk_bulk_disable_unprepare(nvdec->num_clks, nvdec->clks);
 
+	host1x_actmon_disable(&nvdec->client.base);
+
 	return 0;
 }
 
@@ -532,12 +601,20 @@ static int nvdec_probe(struct platform_device *pdev)
 		goto exit_falcon;
 	}
 
+	err = host1x_actmon_register(&nvdec->client.base);
+	if (err < 0) {
+		dev_info(&pdev->dev, "failed to register host1x actmon: %d\n", err);
+		goto exit_client;
+	}
+
 	pm_runtime_enable(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 500);
 
 	return 0;
 
+exit_client:
+	host1x_client_unregister(&nvdec->client.base);
 exit_falcon:
 	falcon_exit(&nvdec->falcon);
 
@@ -549,6 +626,7 @@ static void nvdec_remove(struct platform_device *pdev)
 	struct nvdec *nvdec = platform_get_drvdata(pdev);
 
 	pm_runtime_disable(&pdev->dev);
+	host1x_actmon_unregister(&nvdec->client.base);
 	host1x_client_unregister(&nvdec->client.base);
 	falcon_exit(&nvdec->falcon);
 }
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH 5/5 drm/tegra: vic: Register the device with actmon

In reply to Johnny Liu

By registering the vic with actmon, engine load information can be exported to the user through debugfs for engine profiling purpose.

---
 drivers/gpu/drm/tegra/vic.c | 39 ++++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/tegra/vic.h |  9 +++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/tegra/vic.c +38 -1
index 73c356f1c9012..629cc8244c285 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2015, NVIDIA Corporation.
+ * SPDX-FileCopyrightText: Copyright (c) 2015-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  */
 
 #include <linux/clk.h>
@@ -302,6 +302,28 @@ static int vic_load_firmware(struct vic *vic)
 	return err;
 }
 
+static void vic_actmon_reg_init(struct vic *vic)
+{
+	vic_writel(vic,
+		   VIC_TFBIF_ACTMON_ACTIVE_MASK_STARVED |
+		   VIC_TFBIF_ACTMON_ACTIVE_MASK_STALLED |
+		   VIC_TFBIF_ACTMON_ACTIVE_MASK_DELAYED,
+		   NV_PVIC_TFBIF_ACTMON_ACTIVE_MASK);
+	vic_writel(vic,
+		   VIC_TFBIF_ACTMON_ACTIVE_BORPS_ACTIVE,
+		   NV_PVIC_TFBIF_ACTMON_ACTIVE_BORPS);
+}
+
+static void vic_count_weight_init(struct vic *vic, unsigned long rate)
+{
+	struct host1x_client *client = &vic->client.base;
+	u32 weight = 0;
+
+	host1x_actmon_update_client_rate(client, rate, &weight);
+
+	if (weight)
+		vic_writel(vic, weight, NV_PVIC_TFBIF_ACTMON_ACTIVE_WEIGHT);
+}
 
 static int __maybe_unused vic_runtime_resume(struct device *dev)
 {
@@ -328,6 +350,10 @@ static int __maybe_unused vic_runtime_resume(struct device *dev)
 	if (err < 0)
 		goto assert;
 
+	vic_actmon_reg_init(vic);
+	vic_count_weight_init(vic, clk_get_rate(vic->clk));
+	host1x_actmon_enable(&vic->client.base);
+
 	return 0;
 
 assert:
@@ -352,6 +378,8 @@ static int __maybe_unused vic_runtime_suspend(struct device *dev)
 
 	clk_disable_unprepare(vic->clk);
 
+	host1x_actmon_disable(&vic->client.base);
+
 	return 0;
 }
 
@@ -520,12 +548,20 @@ static int vic_probe(struct platform_device *pdev)
 		goto exit_falcon;
 	}
 
+	err = host1x_actmon_register(&vic->client.base);
+	if (err < 0) {
+		dev_info(&pdev->dev, "failed to register host1x actmon: %d\n", err);
+		goto exit_client;
+	}
+
 	pm_runtime_enable(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 500);
 
 	return 0;
 
+exit_client:
+	host1x_client_unregister(&vic->client.base);
 exit_falcon:
 	falcon_exit(&vic->falcon);
 
@@ -537,6 +573,7 @@ static void vic_remove(struct platform_device *pdev)
 	struct vic *vic = platform_get_drvdata(pdev);
 
 	pm_runtime_disable(&pdev->dev);
+	host1x_actmon_unregister(&vic->client.base);
 	host1x_client_unregister(&vic->client.base);
 	falcon_exit(&vic->falcon);
 }
drivers/gpu/drm/tegra/vic.h +9 -0
index acf35aac948b2..905cd7bfde2f6 100644
@@ -21,6 +21,15 @@
 #define CG_IDLE_CG_EN				(1 << 6)
 #define CG_WAKEUP_DLY_CNT(val)			((val & 0xf) << 16)
 
+#define NV_PVIC_TFBIF_ACTMON_ACTIVE_MASK	0x0000204c
+#define NV_PVIC_TFBIF_ACTMON_ACTIVE_BORPS	0x00002050
+#define NV_PVIC_TFBIF_ACTMON_ACTIVE_WEIGHT	0x00002054
+
+#define VIC_TFBIF_ACTMON_ACTIVE_MASK_STARVED	BIT(0)
+#define VIC_TFBIF_ACTMON_ACTIVE_MASK_STALLED	BIT(1)
+#define VIC_TFBIF_ACTMON_ACTIVE_MASK_DELAYED	BIT(2)
+#define VIC_TFBIF_ACTMON_ACTIVE_BORPS_ACTIVE	BIT(7)
+
 #define VIC_TFBIF_TRANSCFG	0x00002044
 #define  TRANSCFG_ATT(i, v)	(((v) & 0x3) << (i * 4))
 #define  TRANSCFG_SID_HW	0
Signature · 1 line
2.34.1