Skip to content

Commit e6f1856

Browse files
Vishnu Reddygouravk-qualcomm
authored andcommitted
FROMLIST: media: iris: add FPS calculation and VPP FW overhead in frequency formula
The driver was using a fixed default FPS value when calculating the VPU frequency. This caused wrong frequency requests for high-frame-rate streams, for example 4K at 240 FPS. Because of this, the hardware was running at a lower frequency than needed. Add the FPS measurement based on the decoder input buffer arrival rate. The measured FPS is stored per instance and used in frequency calculation instead of the fixed default FPS. The value is clamped so that it does not exceed platform limits. Add a VPP firmware overhead when running in STAGE_2. Link: https://lore.kernel.org/all/20260401-update_fps_calculation-v6-1-f44f8154ca39@oss.qualcomm.com/ Reviewed-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com> (cherry picked from commit f323616c9d818e6149da5a46a8dfe80383fba2f0)
1 parent b92b7c0 commit e6f1856

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

drivers/media/platform/qcom/iris/iris_instance.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct iris_fmt {
6767
* @metadata_idx: index for metadata buffer
6868
* @codec: codec type
6969
* @last_buffer_dequeued: a flag to indicate that last buffer is sent by driver
70+
* @last_buf_ns: start time of received input buffer for current one second FPS window
71+
* @frame_counter: input buffer counter for current one second FPS window
7072
* @frame_rate: frame rate of current instance
7173
* @operating_rate: operating rate of current instance
7274
* @hfi_rc_type: rate control type
@@ -109,6 +111,8 @@ struct iris_inst {
109111
u32 metadata_idx;
110112
u32 codec;
111113
bool last_buffer_dequeued;
114+
u64 last_buf_ns;
115+
u32 frame_counter;
112116
u32 frame_rate;
113117
u32 operating_rate;
114118
u32 hfi_rc_type;

drivers/media/platform/qcom/iris/iris_vdec.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int iris_vdec_inst_init(struct iris_inst *inst)
5454
f->fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
5555
inst->buffers[BUF_OUTPUT].min_count = iris_vpu_buf_count(inst, BUF_OUTPUT);
5656
inst->buffers[BUF_OUTPUT].size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
57+
inst->frame_rate = MAXIMUM_FPS;
5758

5859
memcpy(&inst->fw_caps[0], &core->inst_fw_caps_dec[0],
5960
INST_FW_CAP_MAX * sizeof(struct platform_inst_fw_cap));
@@ -371,6 +372,8 @@ int iris_vdec_streamon_input(struct iris_inst *inst)
371372
if (ret)
372373
return ret;
373374

375+
inst->frame_counter = 0;
376+
374377
return iris_process_streamon_input(inst);
375378
}
376379

@@ -413,6 +416,7 @@ int iris_vdec_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf)
413416
{
414417
struct iris_buffer *buf = to_iris_buffer(vbuf);
415418
struct vb2_buffer *vb2 = &vbuf->vb2_buf;
419+
u64 cur_buf_ns, delta_ns;
416420
struct vb2_queue *q;
417421
int ret;
418422

@@ -429,6 +433,22 @@ int iris_vdec_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf)
429433
return 0;
430434
}
431435

436+
if (buf->type == BUF_INPUT) {
437+
cur_buf_ns = ktime_get_ns();
438+
439+
if (!inst->frame_counter)
440+
inst->last_buf_ns = cur_buf_ns;
441+
442+
inst->frame_counter++;
443+
delta_ns = cur_buf_ns - inst->last_buf_ns;
444+
445+
if (delta_ns >= NSEC_PER_SEC) {
446+
inst->frame_rate = clamp_t(u32, inst->frame_counter, DEFAULT_FPS,
447+
MAXIMUM_FPS);
448+
inst->frame_counter = 0;
449+
}
450+
}
451+
432452
iris_scale_power(inst);
433453

434454
return iris_queue_buffer(inst, buf);

drivers/media/platform/qcom/iris/iris_vpu2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static u64 iris_vpu2_calc_freq(struct iris_inst *inst, size_t data_size)
1818
struct v4l2_format *inp_f = inst->fmt_src;
1919
u32 mbs_per_second, mbpf, height, width;
2020
unsigned long vpp_freq, vsp_freq;
21-
u32 fps = DEFAULT_FPS;
21+
u32 fps = inst->frame_rate;
2222

2323
width = max(inp_f->fmt.pix_mp.width, inst->crop.width);
2424
height = max(inp_f->fmt.pix_mp.height, inst->crop.height);

drivers/media/platform/qcom/iris/iris_vpu_common.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ u64 iris_vpu3x_vpu4x_calculate_frequency(struct iris_inst *inst, size_t data_siz
416416
u32 height, width, mbs_per_second, mbpf;
417417
u64 fw_cycles, fw_vpp_cycles;
418418
u64 vsp_cycles, vpp_cycles;
419-
u32 fps = DEFAULT_FPS;
419+
u32 fps = inst->frame_rate;
420420

421421
width = max(inp_f->fmt.pix_mp.width, inst->crop.width);
422422
height = max(inp_f->fmt.pix_mp.height, inst->crop.height);
@@ -435,6 +435,10 @@ u64 iris_vpu3x_vpu4x_calculate_frequency(struct iris_inst *inst, size_t data_siz
435435
if (inst->fw_caps[PIPE].value > 1)
436436
vpp_cycles += div_u64(vpp_cycles * 59, 1000);
437437

438+
/* 1.05 is VPP FW overhead */
439+
if (inst->fw_caps[STAGE].value == STAGE_2)
440+
vpp_cycles += mult_frac(vpp_cycles, 5, 100);
441+
438442
vsp_cycles = fps * data_size * 8;
439443
vsp_cycles = div_u64(vsp_cycles, 2);
440444
/* VSP FW overhead 1.05 */

0 commit comments

Comments
 (0)