Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1931ba31 authored by Qiwei Liu's avatar Qiwei Liu Committed by Chinmay Sawarkar
Browse files

msm: vidc: Update bitrate constraint check



Update window based average frame size constraint and
add max frame size constraint check.

CRs-Fixed: 2502809
Change-Id: Ia2d85d0394aec0cbda15314d227642a387ecaad4
Signed-off-by: default avatarQiwei Liu <qiweil@codeaurora.org>
Signed-off-by: default avatarChinmay Sawarkar <chinmays@codeaurora.org>
parent 383a14c1
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1039,7 +1039,7 @@ static int __vote_buses(struct venus_hfi_device *device,
				bus->range[0], bus->range[1]);
				bus->range[0], bus->range[1]);


			if (TRIVIAL_BW_CHANGE(bw_kbps, bw_prev) && bw_prev) {
			if (TRIVIAL_BW_CHANGE(bw_kbps, bw_prev) && bw_prev) {
				s_vpr_p(sid, "Skip voting bus %s to %llu bps",
				s_vpr_l(sid, "Skip voting bus %s to %llu bps",
					bus->name, bw_kbps * 1000);
					bus->name, bw_kbps * 1000);
				continue;
				continue;
			}
			}
+7 −5
Original line number Original line Diff line number Diff line
@@ -505,7 +505,7 @@ static unsigned long msm_vidc_max_freq(struct msm_vidc_core *core, u32 sid)


	allowed_clks_tbl = core->resources.allowed_clks_tbl;
	allowed_clks_tbl = core->resources.allowed_clks_tbl;
	freq = allowed_clks_tbl[0].clock_rate;
	freq = allowed_clks_tbl[0].clock_rate;
	s_vpr_p(sid, "Max rate = %lu\n", freq);
	s_vpr_l(sid, "Max rate = %lu\n", freq);
	return freq;
	return freq;
}
}


@@ -882,7 +882,7 @@ int msm_vidc_set_clocks(struct msm_vidc_core *core, u32 sid)
		freq_core_max = max_t(unsigned long, freq_core_1, freq_core_2);
		freq_core_max = max_t(unsigned long, freq_core_1, freq_core_2);


		if (msm_vidc_clock_voting) {
		if (msm_vidc_clock_voting) {
			s_vpr_p(sid, "msm_vidc_clock_voting %d\n",
			s_vpr_l(sid, "msm_vidc_clock_voting %d\n",
				 msm_vidc_clock_voting);
				 msm_vidc_clock_voting);
			freq_core_max = msm_vidc_clock_voting;
			freq_core_max = msm_vidc_clock_voting;
			decrement = false;
			decrement = false;
@@ -965,17 +965,19 @@ int msm_comm_scale_clocks(struct msm_vidc_inst *inst)
		return 0;
		return 0;
	}
	}


	if (inst->clk_data.buffer_counter < DCVS_FTB_WINDOW || is_turbo ||
	if (inst->clk_data.buffer_counter < DCVS_FTB_WINDOW || is_turbo) {
		msm_vidc_clock_voting) {
		inst->clk_data.min_freq =
		inst->clk_data.min_freq =
				msm_vidc_max_freq(inst->core, inst->sid);
				msm_vidc_max_freq(inst->core, inst->sid);
		inst->clk_data.dcvs_flags = 0;
		inst->clk_data.dcvs_flags = 0;
	} else if (msm_vidc_clock_voting) {
		inst->clk_data.min_freq = msm_vidc_clock_voting;
		inst->clk_data.dcvs_flags = 0;
	} else {
	} else {
		freq = call_core_op(inst->core, calc_freq, inst, filled_len);
		freq = call_core_op(inst->core, calc_freq, inst, filled_len);
		inst->clk_data.min_freq = freq;
		inst->clk_data.min_freq = freq;
		/* update dcvs flags */
		msm_dcvs_scale_clocks(inst, freq);
		msm_dcvs_scale_clocks(inst, freq);
	}
	}

	msm_vidc_set_clocks(inst->core, inst->sid);
	msm_vidc_set_clocks(inst->core, inst->sid);


	return 0;
	return 0;
+35 −14
Original line number Original line Diff line number Diff line
@@ -1670,6 +1670,8 @@ static void handle_event_change(enum hal_command_response cmd, void *data)
		if (event_fields_changed) {
		if (event_fields_changed) {
			event = V4L2_EVENT_SEQ_CHANGED_INSUFFICIENT;
			event = V4L2_EVENT_SEQ_CHANGED_INSUFFICIENT;
		} else {
		} else {
			inst->entropy_mode = event_notify->entropy_mode;

			s_vpr_h(inst->sid,
			s_vpr_h(inst->sid,
				"seq: No parameter change continue session\n");
				"seq: No parameter change continue session\n");
			rc = call_hfi_op(hdev, session_continue,
			rc = call_hfi_op(hdev, session_continue,
@@ -7251,7 +7253,8 @@ int msm_comm_check_window_bitrate(struct msm_vidc_inst *inst,
	struct vidc_frame_data *frame_data)
	struct vidc_frame_data *frame_data)
{
{
	struct msm_vidc_window_data *pdata, *temp = NULL;
	struct msm_vidc_window_data *pdata, *temp = NULL;
	u32 bitrate, max_br, window_size;
	u32 frame_size, window_size, window_buffer;
	u32 max_avg_frame_size, max_frame_size;
	int buf_cnt = 1, fps, window_start;
	int buf_cnt = 1, fps, window_start;


	if (!inst || !inst->core || !frame_data) {
	if (!inst || !inst->core || !frame_data) {
@@ -7260,25 +7263,37 @@ int msm_comm_check_window_bitrate(struct msm_vidc_inst *inst,
	}
	}


	if (!inst->core->resources.avsync_window_size ||
	if (!inst->core->resources.avsync_window_size ||
		inst->entropy_mode == HFI_H264_ENTROPY_CAVLC ||
		!frame_data->filled_len)
		!frame_data->filled_len)
		return 0;
		return 0;


	/*
	 * MaxAvgFrameSize <= (1 + B/S) * (MaxClock / fps - 25*NumOfMacroBlockperFrame) / 1.35
	 * S: Sliding window = #Frames in 40ms (av sync window) Closest point
	 * B: Buffer Count = B(vsp-vpp) = 2 for 2Stage, 0 for 1stage
	 */

	fps = inst->clk_data.frame_rate >> 16;
	fps = inst->clk_data.frame_rate >> 16;
	max_br = MAX_BITRATE_DECODER_CAVLC;
	if (inst->entropy_mode == HFI_H264_ENTROPY_CABAC)
		max_br = inst->clk_data.work_mode == HFI_WORKMODE_2 ?
			MAX_BITRATE_DECODER_2STAGE_CABAC :
			MAX_BITRATE_DECODER_1STAGE_CABAC;
	window_size = inst->core->resources.avsync_window_size * fps;
	window_size = inst->core->resources.avsync_window_size * fps;
	window_size = DIV_ROUND_UP(window_size, 1000);
	window_size = DIV_ROUND_CLOSEST(window_size, 1000);

	window_buffer = inst->clk_data.work_mode == HFI_WORKMODE_2 ? 2 : 0;
	bitrate = frame_data->filled_len;

	max_frame_size =
		inst->core->resources.allowed_clks_tbl[0].clock_rate / fps -
		inst->clk_data.entry->vsp_cycles *
		msm_vidc_get_mbs_per_frame(inst);
	max_avg_frame_size = (u64)max_frame_size * 100 *
		(window_size + window_buffer) / (window_size * 135);
	max_frame_size = (u64)max_frame_size * 100 *
		(1 + window_buffer) / 135;

	frame_size = frame_data->filled_len;
	window_start = inst->count.etb;
	window_start = inst->count.etb;


	mutex_lock(&inst->window_data.lock);
	mutex_lock(&inst->window_data.lock);
	list_for_each_entry(pdata, &inst->window_data.list, list) {
	list_for_each_entry(pdata, &inst->window_data.list, list) {
		if (buf_cnt < window_size && pdata->frame_size) {
		if (buf_cnt < window_size && pdata->frame_size) {
			bitrate += pdata->frame_size;
			frame_size += pdata->frame_size;
			window_start = pdata->etb_count;
			window_start = pdata->etb_count;
			buf_cnt++;
			buf_cnt++;
		} else {
		} else {
@@ -7304,13 +7319,19 @@ int msm_comm_check_window_bitrate(struct msm_vidc_inst *inst,
	list_add(&pdata->list, &inst->window_data.list);
	list_add(&pdata->list, &inst->window_data.list);
	mutex_unlock(&inst->window_data.lock);
	mutex_unlock(&inst->window_data.lock);


	bitrate = DIV_ROUND_UP(((u64)bitrate * 8 * fps), window_size);
	frame_size = DIV_ROUND_UP((frame_size * 8), window_size);
	if (bitrate > max_br) {
	if (frame_size > max_avg_frame_size) {
		s_vpr_p(inst->sid,
		s_vpr_p(inst->sid,
			"Unsupported bitrate %u max %u, window size %u [%u,%u]",
			"Unsupported avg frame size %u max %u, window size %u [%u,%u]",
			bitrate, max_br, window_size,
			frame_size, max_avg_frame_size, window_size,
			window_start, inst->count.etb);
			window_start, inst->count.etb);
	}
	}
	if (frame_data->filled_len * 8 > max_frame_size) {
		s_vpr_p(inst->sid,
			"Unsupported frame size(bit) %u max %u [%u]",
			frame_data->filled_len * 8, max_frame_size,
			inst->count.etb);
	}


	return 0;
	return 0;
}
}