Loading drivers/media/platform/msm/cvp/msm_cvp.c +96 −43 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ #include <synx_api.h> #include "cvp_core_hfi.h" struct cvp_power_level { unsigned long core_sum; unsigned long bw_sum; }; void print_internal_buffer(u32 tag, const char *str, struct msm_cvp_inst *inst, struct msm_cvp_internal_buffer *cbuf) { Loading Loading @@ -1200,14 +1205,79 @@ static inline int max_3(unsigned int a, unsigned int b, unsigned int c) return (a >= b) ? ((a >= c) ? a : c) : ((b >= c) ? b : c); } static void aggregate_power_request(struct msm_cvp_core *core, struct cvp_power_level *nrt_pwr, struct cvp_power_level *rt_pwr, unsigned int max_clk_rate) { struct msm_cvp_inst *inst; int i; unsigned long core_sum[2] = {0}, ctlr_sum[2] = {0}, fw_sum[2] = {0}; unsigned long op_core_max[2] = {0}, op_ctlr_max[2] = {0}; unsigned long op_fw_max[2] = {0}, bw_sum[2] = {0}, op_bw_max[2] = {0}; list_for_each_entry(inst, &core->instances, list) { if (inst->state == MSM_CVP_CORE_INVALID || inst->state == MSM_CVP_CORE_UNINIT) continue; if (inst->prop.priority <= CVP_RT_PRIO_THRESHOLD) { /* Non-realtime session use index 0 */ i = 0; } else { i = 1; } core_sum[i] += inst->power.clock_cycles_a; ctlr_sum[i] += inst->power.clock_cycles_b; fw_sum[i] += inst->power.reserved[0]; op_core_max[i] = (op_core_max[i] >= inst->power.reserved[1]) ? op_core_max[i] : inst->power.reserved[1]; op_ctlr_max[i] = (op_ctlr_max[i] >= inst->power.reserved[2]) ? op_ctlr_max[i] : inst->power.reserved[2]; op_fw_max[i] = (op_fw_max[i] >= inst->power.reserved[3]) ? op_fw_max[i] : inst->power.reserved[3]; bw_sum[i] += inst->power.ddr_bw; op_bw_max[i] = (op_bw_max[i] >= inst->power.reserved[4]) ? op_bw_max[i] : inst->power.reserved[4]; } for (i = 0; i < 2; i++) { core_sum[i] = max_3(core_sum[i], ctlr_sum[i], fw_sum[i]); op_core_max[i] = max_3(op_core_max[i], op_ctlr_max[i], op_fw_max[i]); op_core_max[i] = (op_core_max[i] > max_clk_rate) ? max_clk_rate : op_core_max[i]; core_sum[i] = (core_sum[i] >= op_core_max[i]) ? core_sum[i] : op_core_max[i]; bw_sum[i] = (bw_sum[i] >= op_bw_max[i]) ? bw_sum[i] : op_bw_max[i]; } nrt_pwr->core_sum = core_sum[0]; nrt_pwr->bw_sum = bw_sum[0]; rt_pwr->core_sum = core_sum[1]; rt_pwr->bw_sum = bw_sum[1]; } /** * adjust_bw_freqs(): calculate CVP clock freq and bw required to sustain * required use case. * Bandwidth vote will be best-effort, not returning error if the request * b/w exceeds max limit. * Clock vote from non-realtime sessions will be best effort, not returning * error if the aggreated session clock request exceeds max limit. * Clock vote from realtime session will be hard request. If aggregated * session clock request exceeds max limit, the function will return * error. */ static int adjust_bw_freqs(void) { struct msm_cvp_core *core; struct msm_cvp_inst *inst; struct iris_hfi_device *hdev; struct bus_info *bus; struct clock_set *clocks; Loading @@ -1215,9 +1285,8 @@ static int adjust_bw_freqs(void) struct allowed_clock_rates_table *tbl = NULL; unsigned int tbl_size; unsigned int cvp_min_rate, cvp_max_rate, max_bw; unsigned long core_sum = 0, ctlr_sum = 0, fw_sum = 0; unsigned long op_core_max = 0, op_ctlr_max = 0, op_fw_max = 0; unsigned long bw_sum = 0, op_bw_max = 0; struct cvp_power_level rt_pwr, nrt_pwr; unsigned long tmp, core_sum, bw_sum; int i, rc = 0; core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list); Loading @@ -1232,67 +1301,49 @@ static int adjust_bw_freqs(void) bus = &core->resources.bus_set.bus_tbl[1]; max_bw = bus->range[1]; list_for_each_entry(inst, &core->instances, list) { if (inst->state == MSM_CVP_CORE_INVALID || inst->state == MSM_CVP_CORE_UNINIT) continue; core_sum += inst->power.clock_cycles_a; ctlr_sum += inst->power.clock_cycles_b; fw_sum += inst->power.reserved[0]; op_core_max = (op_core_max >= inst->power.reserved[1]) ? op_core_max : inst->power.reserved[1]; op_ctlr_max = (op_ctlr_max >= inst->power.reserved[2]) ? op_ctlr_max : inst->power.reserved[2]; op_fw_max = (op_fw_max >= inst->power.reserved[3]) ? op_fw_max : inst->power.reserved[3]; bw_sum += inst->power.ddr_bw; op_bw_max = (op_bw_max >= inst->power.reserved[4]) ? op_bw_max : inst->power.reserved[4]; } core_sum = max_3(core_sum, ctlr_sum, fw_sum); op_core_max = max_3(op_core_max, op_ctlr_max, op_fw_max); op_core_max = (op_core_max > tbl[tbl_size - 1].clock_rate) ? tbl[tbl_size - 1].clock_rate : op_core_max; core_sum = (core_sum >= op_core_max) ? core_sum : op_core_max; bw_sum = (bw_sum >= op_bw_max) ? bw_sum : op_bw_max; if (core_sum < tbl[0].clock_rate) { core_sum = tbl[0].clock_rate; } else { for (i = 1; i < tbl_size; i++) if (core_sum <= tbl[i].clock_rate) break; aggregate_power_request(core, &nrt_pwr, &rt_pwr, cvp_max_rate); if (i == tbl_size) { if (rt_pwr.core_sum > cvp_max_rate) { dprintk(CVP_WARN, "%s clk vote out of range %lld\n", __func__, core_sum); __func__, rt_pwr.core_sum); return -ENOTSUPP; } core_sum = rt_pwr.core_sum + nrt_pwr.core_sum; if (core_sum > cvp_max_rate) { core_sum = cvp_max_rate; } else if (core_sum < cvp_min_rate) { core_sum = cvp_min_rate; } else { for (i = 1; i < tbl_size; i++) if (core_sum <= tbl[i].clock_rate) break; core_sum = tbl[i].clock_rate; } bw_sum = rt_pwr.bw_sum + nrt_pwr.bw_sum; if (bw_sum > max_bw) bw_sum = max_bw; dprintk(CVP_DBG, "%s %lld %lld %lld\n", __func__, core_sum, bw_sum, op_bw_max); dprintk(CVP_DBG, "%s %lld %lld\n", __func__, core_sum, bw_sum); if (!cl->has_scaling) { dprintk(CVP_ERR, "Cannot scale CVP clock\n"); return -EINVAL; } ctlr_sum = core->curr_freq; tmp = core->curr_freq; core->curr_freq = core_sum; rc = msm_cvp_set_clocks(core); if (rc) { dprintk(CVP_ERR, "Failed to set clock rate %u %s: %d %s\n", core_sum, cl->name, rc, __func__); core->curr_freq = ctlr_sum; core->curr_freq = tmp; return rc; } hdev->clk_freq = core_sum; hdev->clk_freq = core->curr_freq; rc = msm_bus_scale_update_bw(bus->client, bw_sum, 0); if (rc) Loading Loading @@ -1349,8 +1400,10 @@ static int msm_cvp_request_power(struct msm_cvp_inst *inst, inst->power.ddr_bw = inst->power.ddr_bw >> 10; rc = adjust_bw_freqs(); if (rc) if (rc) { memset(&inst->power, 0x0, sizeof(inst->power)); dprintk(CVP_ERR, "Instance %pK power request out of range\n"); } mutex_unlock(&core->lock); inst->cur_cmd_type = 0; Loading drivers/media/platform/msm/cvp/msm_cvp_internal.h +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ #define ARP_BUF_SIZE 0x100000 #define CVP_RT_PRIO_THRESHOLD 1 struct msm_cvp_inst; enum cvp_core_state { Loading Loading
drivers/media/platform/msm/cvp/msm_cvp.c +96 −43 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ #include <synx_api.h> #include "cvp_core_hfi.h" struct cvp_power_level { unsigned long core_sum; unsigned long bw_sum; }; void print_internal_buffer(u32 tag, const char *str, struct msm_cvp_inst *inst, struct msm_cvp_internal_buffer *cbuf) { Loading Loading @@ -1200,14 +1205,79 @@ static inline int max_3(unsigned int a, unsigned int b, unsigned int c) return (a >= b) ? ((a >= c) ? a : c) : ((b >= c) ? b : c); } static void aggregate_power_request(struct msm_cvp_core *core, struct cvp_power_level *nrt_pwr, struct cvp_power_level *rt_pwr, unsigned int max_clk_rate) { struct msm_cvp_inst *inst; int i; unsigned long core_sum[2] = {0}, ctlr_sum[2] = {0}, fw_sum[2] = {0}; unsigned long op_core_max[2] = {0}, op_ctlr_max[2] = {0}; unsigned long op_fw_max[2] = {0}, bw_sum[2] = {0}, op_bw_max[2] = {0}; list_for_each_entry(inst, &core->instances, list) { if (inst->state == MSM_CVP_CORE_INVALID || inst->state == MSM_CVP_CORE_UNINIT) continue; if (inst->prop.priority <= CVP_RT_PRIO_THRESHOLD) { /* Non-realtime session use index 0 */ i = 0; } else { i = 1; } core_sum[i] += inst->power.clock_cycles_a; ctlr_sum[i] += inst->power.clock_cycles_b; fw_sum[i] += inst->power.reserved[0]; op_core_max[i] = (op_core_max[i] >= inst->power.reserved[1]) ? op_core_max[i] : inst->power.reserved[1]; op_ctlr_max[i] = (op_ctlr_max[i] >= inst->power.reserved[2]) ? op_ctlr_max[i] : inst->power.reserved[2]; op_fw_max[i] = (op_fw_max[i] >= inst->power.reserved[3]) ? op_fw_max[i] : inst->power.reserved[3]; bw_sum[i] += inst->power.ddr_bw; op_bw_max[i] = (op_bw_max[i] >= inst->power.reserved[4]) ? op_bw_max[i] : inst->power.reserved[4]; } for (i = 0; i < 2; i++) { core_sum[i] = max_3(core_sum[i], ctlr_sum[i], fw_sum[i]); op_core_max[i] = max_3(op_core_max[i], op_ctlr_max[i], op_fw_max[i]); op_core_max[i] = (op_core_max[i] > max_clk_rate) ? max_clk_rate : op_core_max[i]; core_sum[i] = (core_sum[i] >= op_core_max[i]) ? core_sum[i] : op_core_max[i]; bw_sum[i] = (bw_sum[i] >= op_bw_max[i]) ? bw_sum[i] : op_bw_max[i]; } nrt_pwr->core_sum = core_sum[0]; nrt_pwr->bw_sum = bw_sum[0]; rt_pwr->core_sum = core_sum[1]; rt_pwr->bw_sum = bw_sum[1]; } /** * adjust_bw_freqs(): calculate CVP clock freq and bw required to sustain * required use case. * Bandwidth vote will be best-effort, not returning error if the request * b/w exceeds max limit. * Clock vote from non-realtime sessions will be best effort, not returning * error if the aggreated session clock request exceeds max limit. * Clock vote from realtime session will be hard request. If aggregated * session clock request exceeds max limit, the function will return * error. */ static int adjust_bw_freqs(void) { struct msm_cvp_core *core; struct msm_cvp_inst *inst; struct iris_hfi_device *hdev; struct bus_info *bus; struct clock_set *clocks; Loading @@ -1215,9 +1285,8 @@ static int adjust_bw_freqs(void) struct allowed_clock_rates_table *tbl = NULL; unsigned int tbl_size; unsigned int cvp_min_rate, cvp_max_rate, max_bw; unsigned long core_sum = 0, ctlr_sum = 0, fw_sum = 0; unsigned long op_core_max = 0, op_ctlr_max = 0, op_fw_max = 0; unsigned long bw_sum = 0, op_bw_max = 0; struct cvp_power_level rt_pwr, nrt_pwr; unsigned long tmp, core_sum, bw_sum; int i, rc = 0; core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list); Loading @@ -1232,67 +1301,49 @@ static int adjust_bw_freqs(void) bus = &core->resources.bus_set.bus_tbl[1]; max_bw = bus->range[1]; list_for_each_entry(inst, &core->instances, list) { if (inst->state == MSM_CVP_CORE_INVALID || inst->state == MSM_CVP_CORE_UNINIT) continue; core_sum += inst->power.clock_cycles_a; ctlr_sum += inst->power.clock_cycles_b; fw_sum += inst->power.reserved[0]; op_core_max = (op_core_max >= inst->power.reserved[1]) ? op_core_max : inst->power.reserved[1]; op_ctlr_max = (op_ctlr_max >= inst->power.reserved[2]) ? op_ctlr_max : inst->power.reserved[2]; op_fw_max = (op_fw_max >= inst->power.reserved[3]) ? op_fw_max : inst->power.reserved[3]; bw_sum += inst->power.ddr_bw; op_bw_max = (op_bw_max >= inst->power.reserved[4]) ? op_bw_max : inst->power.reserved[4]; } core_sum = max_3(core_sum, ctlr_sum, fw_sum); op_core_max = max_3(op_core_max, op_ctlr_max, op_fw_max); op_core_max = (op_core_max > tbl[tbl_size - 1].clock_rate) ? tbl[tbl_size - 1].clock_rate : op_core_max; core_sum = (core_sum >= op_core_max) ? core_sum : op_core_max; bw_sum = (bw_sum >= op_bw_max) ? bw_sum : op_bw_max; if (core_sum < tbl[0].clock_rate) { core_sum = tbl[0].clock_rate; } else { for (i = 1; i < tbl_size; i++) if (core_sum <= tbl[i].clock_rate) break; aggregate_power_request(core, &nrt_pwr, &rt_pwr, cvp_max_rate); if (i == tbl_size) { if (rt_pwr.core_sum > cvp_max_rate) { dprintk(CVP_WARN, "%s clk vote out of range %lld\n", __func__, core_sum); __func__, rt_pwr.core_sum); return -ENOTSUPP; } core_sum = rt_pwr.core_sum + nrt_pwr.core_sum; if (core_sum > cvp_max_rate) { core_sum = cvp_max_rate; } else if (core_sum < cvp_min_rate) { core_sum = cvp_min_rate; } else { for (i = 1; i < tbl_size; i++) if (core_sum <= tbl[i].clock_rate) break; core_sum = tbl[i].clock_rate; } bw_sum = rt_pwr.bw_sum + nrt_pwr.bw_sum; if (bw_sum > max_bw) bw_sum = max_bw; dprintk(CVP_DBG, "%s %lld %lld %lld\n", __func__, core_sum, bw_sum, op_bw_max); dprintk(CVP_DBG, "%s %lld %lld\n", __func__, core_sum, bw_sum); if (!cl->has_scaling) { dprintk(CVP_ERR, "Cannot scale CVP clock\n"); return -EINVAL; } ctlr_sum = core->curr_freq; tmp = core->curr_freq; core->curr_freq = core_sum; rc = msm_cvp_set_clocks(core); if (rc) { dprintk(CVP_ERR, "Failed to set clock rate %u %s: %d %s\n", core_sum, cl->name, rc, __func__); core->curr_freq = ctlr_sum; core->curr_freq = tmp; return rc; } hdev->clk_freq = core_sum; hdev->clk_freq = core->curr_freq; rc = msm_bus_scale_update_bw(bus->client, bw_sum, 0); if (rc) Loading Loading @@ -1349,8 +1400,10 @@ static int msm_cvp_request_power(struct msm_cvp_inst *inst, inst->power.ddr_bw = inst->power.ddr_bw >> 10; rc = adjust_bw_freqs(); if (rc) if (rc) { memset(&inst->power, 0x0, sizeof(inst->power)); dprintk(CVP_ERR, "Instance %pK power request out of range\n"); } mutex_unlock(&core->lock); inst->cur_cmd_type = 0; Loading
drivers/media/platform/msm/cvp/msm_cvp_internal.h +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ #define ARP_BUF_SIZE 0x100000 #define CVP_RT_PRIO_THRESHOLD 1 struct msm_cvp_inst; enum cvp_core_state { Loading