[PATCH v2 5/5] media: rkvdec: Add per-context fdinfo usage stats
Detlev Casanova
detlev.casanova at collabora.com
Wed Jun 17 11:11:00 PDT 2026
Add per-file-descriptor hardware utilization tracking to the rkvdec
stateless codec driver, exposed via v4l2_stats.
Update the v4l2_stats instance each time a job completes with the
time it took in ns.
This enables userspace monitoring tools to compute per-process decoder
and encoder utilization. The current and max frequency keys report the
same value today since the driver lacks devfreq support, but will
diverge once DVFS is added, allowing userspace to approximate true
capacity utilization without any fdinfo code changes. A future series
can add hardware cycle counter support (via media-cycles) to v4l2_stats
for exact utilization under DVFS, with no changes to the existing uAPI.
Signed-off-by: Detlev Casanova <detlev.casanova at collabora.com>
---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 19 +++++++++++++++++++
drivers/media/platform/rockchip/rkvdec/rkvdec.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
index 1d1e9bfef8e9..929171232ccf 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
@@ -25,6 +25,7 @@
#include <linux/workqueue.h>
#include <media/v4l2-event.h>
#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-stats.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-vmalloc.h>
@@ -1094,6 +1095,9 @@ static void rkvdec_job_finish(struct rkvdec_ctx *ctx,
{
struct rkvdec_dev *rkvdec = ctx->dev;
+ v4l2_stats_update_hw_usage(&ctx->fh.stats,
+ ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time)));
+
pm_runtime_put_autosuspend(rkvdec->dev);
rkvdec_job_finish_no_pm(ctx, result);
}
@@ -1174,6 +1178,8 @@ static void rkvdec_device_run(void *priv)
return;
}
+ ctx->start_time = ktime_get();
+
ret = desc->ops->run(ctx);
if (ret)
rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
@@ -1304,6 +1310,8 @@ static int rkvdec_open(struct file *filp)
v4l2_fh_add(&ctx->fh, filp);
+ v4l2_stats_set_media_dev_type(&ctx->fh.stats, MEDIA_DEV_TYPE_V4L2_STATELESS_DECODER);
+
return 0;
err_cleanup_m2m_ctx:
@@ -1327,10 +1335,21 @@ static int rkvdec_release(struct file *filp)
return 0;
}
+static void rkvdec_show_fdinfo(struct seq_file *m, struct file *file)
+{
+ struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
+ struct rkvdec_dev *rkvdec = ctx->dev;
+
+ v4l2_stats_show(&ctx->fh.stats, m);
+
+ v4l2_stats_show_clock(m, rkvdec->axi_clk);
+}
+
static const struct v4l2_file_operations rkvdec_fops = {
.owner = THIS_MODULE,
.open = rkvdec_open,
.release = rkvdec_release,
+ .show_fdinfo = rkvdec_show_fdinfo,
.poll = v4l2_m2m_fop_poll,
.unlocked_ioctl = video_ioctl2,
.mmap = v4l2_m2m_fop_mmap,
diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.h b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
index a24be6638b6b..590e213bd800 100644
--- a/drivers/media/platform/rockchip/rkvdec/rkvdec.h
+++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
@@ -157,6 +157,7 @@ struct rkvdec_ctx {
void *priv;
u8 has_sps_st_rps: 1;
u8 has_sps_lt_rps: 1;
+ ktime_t start_time;
};
static inline struct rkvdec_ctx *file_to_rkvdec_ctx(struct file *filp)
--
2.54.0
More information about the Linux-rockchip
mailing list