From decaa6f5d2cf5cf2b2b123c5f3bb407432cb0007 Mon Sep 17 00:00:00 2001 From: Dikshita Agarwal Date: Thu, 1 Oct 2020 16:32:22 +0530 Subject: [PATCH 1/6] msm-vidc: fix final BW voting to ICC Currently, Required BW is calculated in bytes per second but when setting it to ICC, kbps_to_icc macro is applied to calculated BW which again divides the value by 8 and resulting into less final vote to icc. Change-Id: I7a645478d05909308edea2170d7c5cb911cbf6f0 Signed-off-by: Dikshita Agarwal --- msm/vidc/hfi_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msm/vidc/hfi_common.c b/msm/vidc/hfi_common.c index bbb48a5120de..ba8106a16d1b 100644 --- a/msm/vidc/hfi_common.c +++ b/msm/vidc/hfi_common.c @@ -888,7 +888,7 @@ static int __vote_bandwidth(struct bus_info *bus, int rc = 0; s_vpr_p(sid, "Voting bus %s to ab %llu kbps\n", bus->name, bw_kbps); - rc = icc_set_bw(bus->path, kbps_to_icc(bw_kbps), 0); + rc = icc_set_bw(bus->path, bw_kbps, 0); if (rc) s_vpr_e(sid, "Failed voting bus %s to ab %llu, rc=%d\n", bus->name, bw_kbps, rc); From 165ee8e71ba370654d4a48c4099450cf7acf2bbe Mon Sep 17 00:00:00 2001 From: Brijesh Patel Date: Sat, 10 Oct 2020 02:38:19 +0530 Subject: [PATCH 2/6] msm: vidc: Avoid dma_buf memory leak under memory pressure dma_buf_put does not happen in case of failure while mapping dma_buf. This leads to ion_dma_buf leak as refcount is 1 even after session close. In memory pressure scenario while running concurrency usecase such scenario can occur. Change-Id: I2084538162b54d87acd6fa57bb5cc5bd2096c08d Signed-off-by: Brijesh Patel --- msm/vidc/msm_smem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/msm/vidc/msm_smem.c b/msm/vidc/msm_smem.c index 4688aa9717a3..4d3454ebc46b 100644 --- a/msm/vidc/msm_smem.c +++ b/msm/vidc/msm_smem.c @@ -216,7 +216,7 @@ int msm_smem_map_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem) rc = dma_buf_get_flags(dbuf, &ion_flags); if (rc) { s_vpr_e(inst->sid, "Failed to get dma buf flags: %d\n", rc); - goto exit; + goto fail_map_dma_buf; } if (ion_flags & ION_FLAG_CACHED) smem->flags |= SMEM_CACHED; @@ -230,7 +230,7 @@ int msm_smem_map_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem) smem->flags & SMEM_SECURE ? "secure" : "non-secure", inst->flags & VIDC_SECURE ? "secure" : "non-secure"); rc = -EINVAL; - goto exit; + goto fail_map_dma_buf; } buffer_size = smem->size; @@ -240,18 +240,25 @@ int msm_smem_map_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem) inst->sid); if (rc) { s_vpr_e(inst->sid, "Failed to get device address: %d\n", rc); - goto exit; + goto fail_map_dma_buf; } temp = (u32)iova; if ((dma_addr_t)temp != iova) { s_vpr_e(inst->sid, "iova(%pa) truncated to %#x", &iova, temp); rc = -EINVAL; - goto exit; + goto fail_iova_truncation; } smem->device_addr = (u32)iova + smem->offset; smem->refcount++; + return 0; + +fail_iova_truncation: + msm_dma_put_device_address(smem->flags, &smem->mapping_info, + smem->buffer_type, inst->sid); +fail_map_dma_buf: + msm_smem_put_dma_buf(dbuf, inst->sid); exit: return rc; } From f3b640dc89760a34c81e09e7a10550e80225ec46 Mon Sep 17 00:00:00 2001 From: Govindaraj Rajagopal Date: Mon, 19 Oct 2020 20:27:05 +0530 Subject: [PATCH 3/6] msm: vidc: tune input buffer size based on buffer_size_limit Codec2 HAL sets V4L2_CID_MPEG_VIDC_VIDEO_BUFFER_SIZE_LIMIT for all session and it is very low value. So decoder input buffer size is always limited by buffer_size_limit. Memory budget estimation is going for toss in msm_comm_check_memory_supported. So video driver started allowing all sessions during concurrency run without any restriction. Added change to use correct buffer size during memory estimation. Change-Id: Ic7c5e51a91615fdba8965b3a359c2d3a37c9a14b Signed-off-by: Govindaraj Rajagopal --- msm/vidc/msm_vdec.c | 6 +++--- msm/vidc/msm_vidc_buffer_calculations.c | 7 +++---- msm/vidc/msm_vidc_buffer_calculations.h | 3 ++- msm/vidc/msm_vidc_common.c | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/msm/vidc/msm_vdec.c b/msm/vidc/msm_vdec.c index bb69dede610c..7d4b1de3b252 100644 --- a/msm/vidc/msm_vdec.c +++ b/msm/vidc/msm_vdec.c @@ -685,7 +685,7 @@ int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f) } mplane->plane_fmt[0].sizeimage = - msm_vidc_calculate_dec_input_frame_size(inst); + msm_vidc_calculate_dec_input_frame_size(inst, inst->buffer_size_limit); /* Driver can recalculate buffer count only for * only for bitstream port. Decoder YUV port reconfig @@ -733,7 +733,7 @@ int msm_vdec_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f) } else if (f->type == INPUT_MPLANE) { fmt = &inst->fmts[INPUT_PORT].v4l2_fmt; fmt->fmt.pix_mp.plane_fmt[0].sizeimage = - msm_vidc_calculate_dec_input_frame_size(inst); + msm_vidc_calculate_dec_input_frame_size(inst, inst->buffer_size_limit); memcpy(f, fmt, sizeof(struct v4l2_format)); } else { s_vpr_e(inst->sid, "%s: Unsupported buf type: %d\n", @@ -817,7 +817,7 @@ int msm_vdec_inst_init(struct msm_vidc_inst *inst) f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264; f->fmt.pix_mp.num_planes = 1; f->fmt.pix_mp.plane_fmt[0].sizeimage = - msm_vidc_calculate_dec_input_frame_size(inst); + msm_vidc_calculate_dec_input_frame_size(inst, inst->buffer_size_limit); fmt_desc = msm_comm_get_pixel_fmt_fourcc(vdec_input_formats, ARRAY_SIZE(vdec_input_formats), f->fmt.pix_mp.pixelformat, inst->sid); diff --git a/msm/vidc/msm_vidc_buffer_calculations.c b/msm/vidc/msm_vidc_buffer_calculations.c index 45e75a527235..ae233546846f 100644 --- a/msm/vidc/msm_vidc_buffer_calculations.c +++ b/msm/vidc/msm_vidc_buffer_calculations.c @@ -862,7 +862,7 @@ static int msm_vidc_get_extra_output_buff_count(struct msm_vidc_inst *inst) return extra_output_count; } -u32 msm_vidc_calculate_dec_input_frame_size(struct msm_vidc_inst *inst) +u32 msm_vidc_calculate_dec_input_frame_size(struct msm_vidc_inst *inst, u32 buffer_size_limit) { u32 frame_size, num_mbs; u32 div_factor = 1; @@ -914,9 +914,8 @@ u32 msm_vidc_calculate_dec_input_frame_size(struct msm_vidc_inst *inst) inst->core->platform_data->vpu_ver != VPU_VERSION_AR50_LITE) frame_size = frame_size + (frame_size >> 2); - if (inst->buffer_size_limit && - (inst->buffer_size_limit < frame_size)) { - frame_size = inst->buffer_size_limit; + if (buffer_size_limit && (buffer_size_limit < frame_size)) { + frame_size = buffer_size_limit; s_vpr_h(inst->sid, "input buffer size limited to %d\n", frame_size); } else { diff --git a/msm/vidc/msm_vidc_buffer_calculations.h b/msm/vidc/msm_vidc_buffer_calculations.h index e890db526660..a4d27a696dad 100644 --- a/msm/vidc/msm_vidc_buffer_calculations.h +++ b/msm/vidc/msm_vidc_buffer_calculations.h @@ -36,7 +36,8 @@ int msm_vidc_calculate_output_buffer_count(struct msm_vidc_inst *inst); int msm_vidc_calculate_buffer_counts(struct msm_vidc_inst *inst); int msm_vidc_get_extra_buff_count(struct msm_vidc_inst *inst, enum hal_buffer buffer_type); -u32 msm_vidc_calculate_dec_input_frame_size(struct msm_vidc_inst *inst); +u32 msm_vidc_calculate_dec_input_frame_size(struct msm_vidc_inst *inst, + u32 buffer_size_limit); u32 msm_vidc_calculate_dec_output_frame_size(struct msm_vidc_inst *inst); u32 msm_vidc_calculate_dec_output_extra_size(struct msm_vidc_inst *inst); u32 msm_vidc_calculate_enc_input_frame_size(struct msm_vidc_inst *inst); diff --git a/msm/vidc/msm_vidc_common.c b/msm/vidc/msm_vidc_common.c index 4c71d3512441..b01fe32fcbdc 100644 --- a/msm/vidc/msm_vidc_common.c +++ b/msm/vidc/msm_vidc_common.c @@ -3332,7 +3332,10 @@ static void msm_comm_print_mem_usage(struct msm_vidc_core *core) break; } } - sz_i = iplane->plane_fmt[0].sizeimage; + if (is_decode_session(inst)) + sz_i = msm_vidc_calculate_dec_input_frame_size(inst, 0); + else + sz_i = iplane->plane_fmt[0].sizeimage; sz_i_e = iplane->plane_fmt[1].sizeimage; cnt_i = inp_f->count_min_host; @@ -5783,7 +5786,7 @@ int msm_comm_check_memory_supported(struct msm_vidc_inst *vidc_inst) struct v4l2_format *f; struct hal_buffer_requirements *req; struct context_bank_info *cb = NULL; - u32 i, dpb_cnt = 0, dpb_size = 0, rc = 0; + u32 i, dpb_cnt = 0, dpb_size = 0, input_size = 1, rc = 0; u32 inst_mem_size, non_sec_cb_size = 0; u64 total_mem_size = 0, non_sec_mem_size = 0; u32 memory_limit_mbytes; @@ -5793,10 +5796,17 @@ int msm_comm_check_memory_supported(struct msm_vidc_inst *vidc_inst) mutex_lock(&core->lock); list_for_each_entry(inst, &core->instances, list) { inst_mem_size = 0; + input_size = 1; /* input port buffers memory size */ fmt = &inst->fmts[INPUT_PORT]; f = &fmt->v4l2_fmt; - for (i = 0; i < f->fmt.pix_mp.num_planes; i++) + if (is_decode_session(inst)) + input_size = msm_vidc_calculate_dec_input_frame_size(inst, 0); + else + input_size = f->fmt.pix_mp.plane_fmt[0].sizeimage; + inst_mem_size += input_size * fmt->count_min_host; + + for (i = 1; i < f->fmt.pix_mp.num_planes; i++) inst_mem_size += f->fmt.pix_mp.plane_fmt[i].sizeimage * fmt->count_min_host; From 8623b83cff0781f4d044a7c390bef0bb62e3d7fb Mon Sep 17 00:00:00 2001 From: Priyanka Gujjula Date: Mon, 2 Nov 2020 16:02:39 +0530 Subject: [PATCH 4/6] msm: vidc: optimize HEIC output buffer calc for encoder For HEIC encode, output buffer dimension is 512 x 512. Updating total output buffer size as twice the frame size of 512 x 512 for image sessions. Change-Id: I69311b485072ef7f43afd23da690e77eecee180d Signed-off-by: Vikash Garodia --- msm/vidc/msm_vidc_buffer_calculations.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/msm/vidc/msm_vidc_buffer_calculations.c b/msm/vidc/msm_vidc_buffer_calculations.c index 0d63bca7395d..8cd29bb19eeb 100644 --- a/msm/vidc/msm_vidc_buffer_calculations.c +++ b/msm/vidc/msm_vidc_buffer_calculations.c @@ -982,6 +982,7 @@ u32 msm_vidc_calculate_enc_output_frame_size(struct msm_vidc_inst *inst) f = &inst->fmts[OUTPUT_PORT].v4l2_fmt; /* * Encoder output size calculation: 32 Align width/height + * For CQ or heic session : YUVsize * 2 * For resolution < 720p : YUVsize * 4 * For resolution > 720p & <= 4K : YUVsize / 2 * For resolution > 4k : YUVsize / 4 @@ -996,6 +997,10 @@ u32 msm_vidc_calculate_enc_output_frame_size(struct msm_vidc_inst *inst) mbs_per_frame = NUM_MBS_PER_FRAME(width, height); frame_size = (width * height * 3); + if (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ || + is_grid_session(inst) || is_image_session(inst)) + goto calc_done; + if (mbs_per_frame < NUM_MBS_720P) frame_size = frame_size << 1; else if (mbs_per_frame <= NUM_MBS_4k) @@ -1003,17 +1008,19 @@ u32 msm_vidc_calculate_enc_output_frame_size(struct msm_vidc_inst *inst) else frame_size = frame_size >> 3; - if ((inst->rc_type == RATE_CONTROL_OFF) || - (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ)) + if (inst->rc_type == RATE_CONTROL_OFF) frame_size = frame_size << 1; if (inst->rc_type == RATE_CONTROL_LOSSLESS) frame_size = (width * height * 9) >> 2; /* multiply by 10/8 (1.25) to get size for 10 bit case */ - if (f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_HEVC) + if (inst->core->platform_data->vpu_ver != VPU_VERSION_AR50_LITE && + f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_HEVC) { frame_size = frame_size + (frame_size >> 2); + } +calc_done: return ALIGN(frame_size, SZ_4K); } From c43b5d4507ffb7f79ac404afee2cc0a08eb881bd Mon Sep 17 00:00:00 2001 From: chenmf5 Date: Wed, 1 Dec 2021 17:50:14 +0800 Subject: [PATCH 5/6] extend codec limitation to 1080@90fps. SM4350 video spec of Qcom only support 1080@60fps, that easy to throw overload exception when recording if 3rd app hold codec resource at background. Try to extend it due to exist codec capability margin comparing with spec. Change-Id: I8395352a00e657da41ccef67d262d32c228b6100 Signed-off-by: chenmf5 Reviewed-on: https://gerrit.mot.com/2132620 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Jiefeng Ou Submit-Approved: Jira Key --- msm/vidc/msm_vidc_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msm/vidc/msm_vidc_platform.c b/msm/vidc/msm_vidc_platform.c index 4dc258ae6214..2bceabf9db28 100644 --- a/msm/vidc/msm_vidc_platform.c +++ b/msm/vidc/msm_vidc_platform.c @@ -2070,7 +2070,7 @@ static struct msm_vidc_common_data holi_common_data[] = { }, { .key = "qcom,max-hw-load", - .value = 489600, /* ((1088x1920)/256)@60fps */ + .value = 734400, /* ((1088x1920)/256)@90fps */ // Motorola chenmf5, IKSWS-28942 extend from 489600 to 734400 }, { .key = "qcom,max-image-load", From 07570bbeb5fa9f7874a2868681657fba9ed77bd9 Mon Sep 17 00:00:00 2001 From: panzh2 Date: Sat, 6 May 2023 17:28:35 +0800 Subject: [PATCH 6/6] Adjust qbuf cache/dqbuf cache ops failed log to VIDC_HIGH Since the log qbuf cache ops failed /dqbuf cache ops failed doesn't affect video function. Its level doesn't reach error. According to the suggestion from qcom change the log level from VIDC_ERR to VIDC_HIGH Change-Id: I3ba806a47158770ca6dc6bd64ecb1ab264dfbe1c Signed-off-by: panzh2 Reviewed-on: https://gerrit.mot.com/2599077 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Wang Wang Submit-Approved: Jira Key --- msm/vidc/msm_vidc_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msm/vidc/msm_vidc_common.c b/msm/vidc/msm_vidc_common.c index a793677718c7..f38687d5e943 100644 --- a/msm/vidc/msm_vidc_common.c +++ b/msm/vidc/msm_vidc_common.c @@ -6856,7 +6856,7 @@ int msm_comm_qbuf_cache_operations(struct msm_vidc_inst *inst, rc = msm_smem_cache_operations(mbuf->smem[i].dma_buf, cache_op, offset, size, inst->sid); if (rc) - print_vidc_buffer(VIDC_ERR, + print_vidc_buffer(VIDC_HIGH, "qbuf cache ops failed", inst, mbuf); } } @@ -6918,7 +6918,7 @@ int msm_comm_dqbuf_cache_operations(struct msm_vidc_inst *inst, rc = msm_smem_cache_operations(mbuf->smem[i].dma_buf, cache_op, offset, size, inst->sid); if (rc) - print_vidc_buffer(VIDC_ERR, + print_vidc_buffer(VIDC_HIGH, "dqbuf cache ops failed", inst, mbuf); } }