[PATCH v4 9/9] media: hantro: Add v4l2_hw run/done traces
From: Detlev Casanova
Date: Fri Nov 27 2026 - 11:46:33 EST
Add the trace calls as well as retrieving the number of clock cycles for
the rockchip_vpu core.
Signed-off-by: Detlev Casanova <detlev.casanova@xxxxxxxxxxxxx>
---
drivers/media/platform/verisilicon/hantro.h | 3 +++
drivers/media/platform/verisilicon/hantro_drv.c | 9 +++++++++
drivers/media/platform/verisilicon/rockchip_vpu981_regs.h | 1 +
drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 2 ++
4 files changed, 15 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 0353de154a1e..3f7c54f81f3b 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -193,6 +193,8 @@ hantro_vdev_to_func(struct video_device *vdev)
* shared with interrupt handlers.
* @variant: Hardware variant-specific parameters.
* @watchdog_work: Delayed work for hardware timeout handling.
+ * @hw_cycles: Hardware cycles used by the current job, if reported
+ * by the variant. Reset to 0 when a job is started.
*/
struct hantro_dev {
struct v4l2_device v4l2_dev;
@@ -213,6 +215,7 @@ struct hantro_dev {
spinlock_t irqlock;
const struct hantro_variant *variant;
struct delayed_work watchdog_work;
+ u32 hw_cycles;
};
/**
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 3734ea701145..45bf926c0480 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -25,6 +25,8 @@
#include <media/videobuf2-core.h>
#include <media/videobuf2-vmalloc.h>
+#include <trace/events/v4l2.h>
+
#include "hantro_v4l2.h"
#include "hantro.h"
#include "hantro_hw.h"
@@ -106,6 +108,7 @@ void hantro_irq_done(struct hantro_dev *vpu,
* and will take care of finishing the job.
*/
if (cancel_delayed_work(&vpu->watchdog_work)) {
+ trace_v4l2_hw_done(ctx->fh.tgid, ctx->fh.fd, vpu->hw_cycles);
if (result == VB2_BUF_STATE_DONE && ctx->codec_ops->done)
ctx->codec_ops->done(ctx);
hantro_job_finish(ctx, result);
@@ -122,6 +125,9 @@ void hantro_watchdog(struct work_struct *work)
ctx = v4l2_m2m_get_curr_priv(vpu->m2m_dev);
if (ctx) {
vpu_err("frame processing timed out!\n");
+
+ trace_v4l2_hw_done(ctx->fh.tgid, ctx->fh.fd, vpu->hw_cycles);
+
if (ctx->codec_ops->reset)
ctx->codec_ops->reset(ctx);
hantro_job_finish(ctx, VB2_BUF_STATE_ERROR);
@@ -159,6 +165,8 @@ void hantro_end_prepare_run(struct hantro_ctx *ctx)
v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req,
&ctx->ctrl_handler);
+ trace_v4l2_hw_run(ctx->fh.tgid, ctx->fh.fd);
+
/* Kick the watchdog. */
schedule_delayed_work(&ctx->dev->watchdog_work,
msecs_to_jiffies(2000));
@@ -182,6 +190,7 @@ static void device_run(void *priv)
v4l2_m2m_buf_copy_metadata(src, dst);
+ vpu->hw_cycles = 0;
ret = ctx->codec_ops->run(ctx);
if (ret)
hantro_job_finish(ctx, VB2_BUF_STATE_ERROR);
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h b/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
index e4008da64f19..96b85470208b 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h
@@ -451,6 +451,7 @@
#define av1_pp0_dup_ver AV1_DEC_REG(394, 16, 0xff)
#define av1_pp0_dup_hor AV1_DEC_REG(394, 24, 0xff)
+#define AV1_CYCLE_COUNT (AV1_SWREG(63))
#define AV1_TILE_OUT_LU (AV1_SWREG(65))
#define AV1_REFERENCE_Y(i) (AV1_SWREG(67) + ((i) * 0x8))
#define AV1_SEGMENTATION (AV1_SWREG(81))
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
index 02673be9878e..04f26d6fded2 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
@@ -433,6 +433,8 @@ static irqreturn_t rk3588_vpu981_irq(int irq, void *dev_id)
vdpu_write(vpu, 0, AV1_REG_INTERRUPT);
vdpu_write(vpu, AV1_REG_CONFIG_DEC_CLK_GATE_E, AV1_REG_CONFIG);
+ vpu->hw_cycles = vdpu_read(vpu, AV1_CYCLE_COUNT);
+
hantro_irq_done(vpu, state);
return IRQ_HANDLED;
--
2.56.1