From d168b1dab5fb1163bde5d7fc6fc2984c8ed91633 Mon Sep 17 00:00:00 2001 From: Vikash Garodia Date: Fri, 23 Aug 2019 14:36:33 +0530 Subject: [PATCH] msm: vidc: Invalidate encoder output buffer cache For encode usecase, video driver operates cache always on the encoded data length rather than the buffer length. This is an optimization and saves cache operation on unused memory region. VB index is used to identify a buffer given to client and fed again to encoder. Based on that, the filled length of that buffer is then operated for cache operations. For certain usecases, it is difficult to identify the buffer based on VB index. Hence keep a counter to track the max filled length during the usecase and operate cache on that length Change-Id: I62cfe876077786ec9d14f541a0080cd2fc124b01 Signed-off-by: Vikash Garodia --- msm/vidc/msm_vidc.c | 1 + msm/vidc/msm_vidc_common.c | 70 +++--------------------------------- msm/vidc/msm_vidc_common.h | 4 --- msm/vidc/msm_vidc_internal.h | 2 +- 4 files changed, 7 insertions(+), 70 deletions(-) diff --git a/msm/vidc/msm_vidc.c b/msm/vidc/msm_vidc.c index a37b89f676ba..45f1b5f64253 100644 --- a/msm/vidc/msm_vidc.c +++ b/msm/vidc/msm_vidc.c @@ -1597,6 +1597,7 @@ void *msm_vidc_open(int core_id, int session_type) inst->rc_type = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR; inst->dpb_extra_binfo = NULL; inst->all_intra = false; + inst->max_filled_len = 0; for (i = SESSION_MSG_INDEX(SESSION_MSG_START); i <= SESSION_MSG_INDEX(SESSION_MSG_END); i++) { diff --git a/msm/vidc/msm_vidc_common.c b/msm/vidc/msm_vidc_common.c index c98dc6216853..cef7372396c6 100644 --- a/msm/vidc/msm_vidc_common.c +++ b/msm/vidc/msm_vidc_common.c @@ -2626,8 +2626,8 @@ static void handle_fbd(enum hal_command_response cmd, void *data) fill_buf_done->input_tag, fill_buf_done->input_tag2); if (inst->session_type == MSM_VIDC_ENCODER) { - msm_comm_store_filled_length(&inst->fbd_data, vb->index, - fill_buf_done->filled_len1); + if (inst->max_filled_len < fill_buf_done->filled_len1) + inst->max_filled_len = fill_buf_done->filled_len1; } f = &inst->fmts[OUTPUT_PORT].v4l2_fmt; @@ -6482,14 +6482,11 @@ int msm_comm_qbuf_cache_operations(struct msm_vidc_inst *inst, } } else if (vb->type == OUTPUT_MPLANE) { if (!i) { /* bitstream */ - u32 size_u32; skip = false; offset = 0; - size_u32 = vb->planes[i].length; - msm_comm_fetch_filled_length( - &inst->fbd_data, vb->index, - &size_u32); - size = size_u32; + size = vb->planes[i].length; + if (inst->max_filled_len) + size = inst->max_filled_len; cache_op = SMEM_CACHE_INVALIDATE; } } @@ -7055,63 +7052,6 @@ void msm_comm_release_client_data(struct msm_vidc_inst *inst, bool remove) mutex_unlock(&inst->client_data.lock); } -void msm_comm_store_filled_length(struct msm_vidc_list *data_list, - u32 index, u32 filled_length) -{ - struct msm_vidc_buf_data *pdata = NULL; - bool found = false; - - if (!data_list) { - dprintk(VIDC_ERR, "%s: invalid params %pK\n", - __func__, data_list); - return; - } - - mutex_lock(&data_list->lock); - list_for_each_entry(pdata, &data_list->list, list) { - if (pdata->index == index) { - pdata->filled_length = filled_length; - found = true; - break; - } - } - - if (!found) { - pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); - if (!pdata) { - dprintk(VIDC_ERR, "%s: malloc failure.\n", __func__); - goto exit; - } - pdata->index = index; - pdata->filled_length = filled_length; - list_add_tail(&pdata->list, &data_list->list); - } - -exit: - mutex_unlock(&data_list->lock); -} - -void msm_comm_fetch_filled_length(struct msm_vidc_list *data_list, - u32 index, u32 *filled_length) -{ - struct msm_vidc_buf_data *pdata = NULL; - - if (!data_list || !filled_length) { - dprintk(VIDC_ERR, "%s: invalid params %pK %pK\n", - __func__, data_list, filled_length); - return; - } - - mutex_lock(&data_list->lock); - list_for_each_entry(pdata, &data_list->list, list) { - if (pdata->index == index) { - *filled_length = pdata->filled_length; - break; - } - } - mutex_unlock(&data_list->lock); -} - void msm_comm_store_input_tag(struct msm_vidc_list *data_list, u32 index, u32 itag, u32 itag2) { diff --git a/msm/vidc/msm_vidc_common.h b/msm/vidc/msm_vidc_common.h index c6e5758b7267..45172d170cf4 100644 --- a/msm/vidc/msm_vidc_common.h +++ b/msm/vidc/msm_vidc_common.h @@ -302,10 +302,6 @@ void print_v4l2_buffer(u32 tag, const char *str, struct msm_vidc_inst *inst, struct v4l2_buffer *v4l2); void kref_put_mbuf(struct msm_vidc_buffer *mbuf); bool kref_get_mbuf(struct msm_vidc_inst *inst, struct msm_vidc_buffer *mbuf); -void msm_comm_store_filled_length(struct msm_vidc_list *data_list, - u32 index, u32 filled_length); -void msm_comm_fetch_filled_length(struct msm_vidc_list *data_list, - u32 index, u32 *filled_length); void msm_comm_store_input_tag(struct msm_vidc_list *data_list, u32 index, u32 itag, u32 itag2); int msm_comm_fetch_input_tag(struct msm_vidc_list *data_list, diff --git a/msm/vidc/msm_vidc_internal.h b/msm/vidc/msm_vidc_internal.h index f30ae5fb1c0f..73615c74a673 100644 --- a/msm/vidc/msm_vidc_internal.h +++ b/msm/vidc/msm_vidc_internal.h @@ -207,7 +207,6 @@ struct msm_vidc_buf_data { u32 index; u32 input_tag; u32 input_tag2; - u32 filled_length; }; struct msm_vidc_window_data { @@ -577,6 +576,7 @@ struct msm_vidc_inst { int (*buffer_size_calculators)(struct msm_vidc_inst *inst); bool all_intra; bool is_perf_eligible_session; + u32 max_filled_len; }; extern struct msm_vidc_drv *vidc_driver;