From 5f665189a2eba34083b73ecaf8e005d259de1400 Mon Sep 17 00:00:00 2001 From: Govindaraj Rajagopal Date: Mon, 30 Dec 2019 13:19:11 +0530 Subject: [PATCH] msm: vidc: refine decode batching logic 1. is_batching_allowed api is not considering platform check(core->resources.decode_batching). 2. increase both input & output buffers count if current session supports batching. Change-Id: Iabe7479b4664a78b637ee981d67c604f7d0d5d56 Signed-off-by: Govindaraj Rajagopal --- msm/vidc/msm_vdec.c | 22 +++------------------- msm/vidc/msm_vidc.c | 10 +--------- msm/vidc/msm_vidc_buffer_calculations.c | 12 +++--------- msm/vidc/msm_vidc_common.c | 16 ++++++++++++---- 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/msm/vidc/msm_vdec.c b/msm/vidc/msm_vdec.c index 8f456dd31ad4..b0f5ee407747 100644 --- a/msm/vidc/msm_vdec.c +++ b/msm/vidc/msm_vdec.c @@ -673,15 +673,7 @@ int msm_vdec_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f) memcpy(f, &fmt->v4l2_fmt, sizeof(struct v4l2_format)); } - /* - * if batching enabled previously then you may chose - * to disable it based on recent configuration changes. - * if batching already disabled do not enable it again - * as sufficient extra buffers (required for batch mode - * on both ports) may not have been updated to client. - */ - if (inst->batch.enable) - inst->batch.enable = is_batching_allowed(inst); + inst->batch.enable = is_batching_allowed(inst); msm_dcvs_try_enable(inst); err_invalid_fmt: @@ -882,6 +874,7 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl) if (ctrl->val) inst->flags |= VIDC_THUMBNAIL; + inst->batch.enable = is_batching_allowed(inst); rc = msm_vidc_calculate_buffer_counts(inst); if (rc) { s_vpr_e(inst->sid, @@ -903,16 +896,6 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl) break; case V4L2_CID_MPEG_VIDC_VIDEO_FRAME_RATE: inst->clk_data.frame_rate = ctrl->val; - if (inst->state >= MSM_VIDC_LOAD_RESOURCES) - break; - /* Only recalculate buffer counts before buffers allocated */ - rc = msm_vidc_calculate_buffer_counts(inst); - if (rc) { - s_vpr_e(inst->sid, - "%s failed to calculate buffer count after set fps\n", - __func__); - return rc; - } break; case V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA: if (ctrl->val == EXTRADATA_NONE) @@ -938,6 +921,7 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl) break; case V4L2_CID_MPEG_VIDC_VIDEO_LOWLATENCY_MODE: inst->clk_data.low_latency_mode = !!ctrl->val; + inst->batch.enable = is_batching_allowed(inst); break; default: s_vpr_e(inst->sid, "Unknown control %#x\n", ctrl->id); diff --git a/msm/vidc/msm_vidc.c b/msm/vidc/msm_vidc.c index a44d0f99553b..22e63d9ed07b 100644 --- a/msm/vidc/msm_vidc.c +++ b/msm/vidc/msm_vidc.c @@ -913,15 +913,7 @@ static inline int start_streaming(struct msm_vidc_inst *inst) } } - /* - * if batching enabled previously then you may chose - * to disable it based on recent configuration changes. - * if batching already disabled do not enable it again - * as sufficient extra buffers (required for batch mode - * on both ports) may not have been updated to client. - */ - if (inst->batch.enable) - inst->batch.enable = is_batching_allowed(inst); + inst->batch.enable = is_batching_allowed(inst); s_vpr_hp(inst->sid, "%s: batching %s for inst %pK\n", __func__, inst->batch.enable ? "enabled" : "disabled", inst); diff --git a/msm/vidc/msm_vidc_buffer_calculations.c b/msm/vidc/msm_vidc_buffer_calculations.c index 29c2c6fc3cd1..b8e4bc2e74c8 100644 --- a/msm/vidc/msm_vidc_buffer_calculations.c +++ b/msm/vidc/msm_vidc_buffer_calculations.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. */ #include "msm_vidc_debug.h" @@ -775,13 +775,7 @@ static int msm_vidc_get_extra_input_buff_count(struct msm_vidc_inst *inst) f->fmt.pix_mp.height, 4096, 2160)) goto exit; - /* - * Allocating 2 extra buffers, assuming current session is - * always batch eligible. Cannot rely on inst->batch.enable - * as it can be enabled/disabled based on clip fps etc. But - * decoder input can not be reallocated at run time. - */ - if (core->resources.decode_batching) + if (inst->batch.enable) extra_input_count = (BATCH_DEC_TOTAL_INPUT_BUFFERS - MIN_INPUT_BUFFERS); @@ -872,7 +866,7 @@ static int msm_vidc_get_extra_output_buff_count(struct msm_vidc_inst *inst) * If platform supports decode batching ensure minimum 6 extra * output buffers. Else add 4 extra output buffers for DCVS. */ - if (core->resources.decode_batching) + if (inst->batch.enable) extra_output_count = BATCH_DEC_EXTRA_OUTPUT_BUFFERS; } else if (is_encode_session(inst)) { /* diff --git a/msm/vidc/msm_vidc_common.c b/msm/vidc/msm_vidc_common.c index c31c560284c8..a12a1037d2c7 100644 --- a/msm/vidc/msm_vidc_common.c +++ b/msm/vidc/msm_vidc_common.c @@ -1760,9 +1760,8 @@ static void handle_event_change(enum hal_command_response cmd, void *data) "seq: V4L2_EVENT_SEQ_CHANGED_INSUFFICIENT\n"); /* decide batching as configuration changed */ - if (inst->batch.enable) - inst->batch.enable = is_batching_allowed(inst); - s_vpr_hp(inst->sid, "seq : batching %s\n", __func__, + inst->batch.enable = is_batching_allowed(inst); + s_vpr_hp(inst->sid, "seq : batching %s\n", inst->batch.enable ? "enabled" : "disabled"); msm_dcvs_try_enable(inst); extra_buff_count = msm_vidc_get_extra_buff_count(inst, @@ -2790,7 +2789,16 @@ bool is_batching_allowed(struct msm_vidc_inst *inst) maxmbs = inst->capability.cap[CAP_BATCH_MAX_MB_PER_FRAME].max; maxfps = inst->capability.cap[CAP_BATCH_MAX_FPS].max; - return (is_single_session(inst, ignore_flags) && + /* + * if batching enabled previously then you may chose + * to disable it based on recent configuration changes. + * if batching already disabled do not enable it again + * as sufficient extra buffers (required for batch mode + * on both ports) may not have been updated to client. + */ + return (inst->batch.enable && + inst->core->resources.decode_batching && + is_single_session(inst, ignore_flags) && is_decode_session(inst) && !is_thumbnail_session(inst) && !inst->clk_data.low_latency_mode &&