Skip to content

Commit 795aef6

Browse files
committed
drm/msm/dpu: remove duplicate code calculating sum of bandwidths
The code in dpu_core_perf_crtc_check() mostly duplicates code in dpu_core_perf_aggregate(). Remove the duplication by reusing the latter function. Reviewed-by: Abhinav Kumar <[email protected]> Signed-off-by: Dmitry Baryshkov <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/636059/ Link: https://lore.kernel.org/r/[email protected]
1 parent b9aedd3 commit 795aef6

File tree

1 file changed

+38
-56
lines changed

1 file changed

+38
-56
lines changed

drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@ static void _dpu_core_perf_calc_crtc(const struct dpu_core_perf *core_perf,
140140
perf->max_per_pipe_ib, perf->bw_ctl);
141141
}
142142

143+
static void dpu_core_perf_aggregate(struct drm_device *ddev,
144+
enum dpu_crtc_client_type curr_client_type,
145+
struct dpu_core_perf_params *perf)
146+
{
147+
struct dpu_crtc_state *dpu_cstate;
148+
struct drm_crtc *tmp_crtc;
149+
150+
drm_for_each_crtc(tmp_crtc, ddev) {
151+
if (tmp_crtc->enabled &&
152+
curr_client_type == dpu_crtc_get_client_type(tmp_crtc)) {
153+
dpu_cstate = to_dpu_crtc_state(tmp_crtc->state);
154+
155+
perf->max_per_pipe_ib = max(perf->max_per_pipe_ib,
156+
dpu_cstate->new_perf.max_per_pipe_ib);
157+
158+
perf->bw_ctl += dpu_cstate->new_perf.bw_ctl;
159+
160+
DRM_DEBUG_ATOMIC("crtc=%d bw=%llu\n",
161+
tmp_crtc->base.id,
162+
dpu_cstate->new_perf.bw_ctl);
163+
}
164+
}
165+
}
166+
143167
/**
144168
* dpu_core_perf_crtc_check - validate performance of the given crtc state
145169
* @crtc: Pointer to crtc
@@ -150,11 +174,9 @@ int dpu_core_perf_crtc_check(struct drm_crtc *crtc,
150174
struct drm_crtc_state *state)
151175
{
152176
u32 bw, threshold;
153-
u64 bw_sum_of_intfs = 0;
154-
enum dpu_crtc_client_type curr_client_type;
155177
struct dpu_crtc_state *dpu_cstate;
156-
struct drm_crtc *tmp_crtc;
157178
struct dpu_kms *kms;
179+
struct dpu_core_perf_params perf;
158180

159181
if (!crtc || !state) {
160182
DPU_ERROR("invalid crtc\n");
@@ -172,68 +194,28 @@ int dpu_core_perf_crtc_check(struct drm_crtc *crtc,
172194
/* obtain new values */
173195
_dpu_core_perf_calc_crtc(&kms->perf, crtc, state, &dpu_cstate->new_perf);
174196

175-
bw_sum_of_intfs = dpu_cstate->new_perf.bw_ctl;
176-
curr_client_type = dpu_crtc_get_client_type(crtc);
177-
178-
drm_for_each_crtc(tmp_crtc, crtc->dev) {
179-
if (tmp_crtc->enabled &&
180-
dpu_crtc_get_client_type(tmp_crtc) == curr_client_type &&
181-
tmp_crtc != crtc) {
182-
struct dpu_crtc_state *tmp_cstate =
183-
to_dpu_crtc_state(tmp_crtc->state);
184-
185-
DRM_DEBUG_ATOMIC("crtc:%d bw:%llu ctrl:%d\n",
186-
tmp_crtc->base.id, tmp_cstate->new_perf.bw_ctl,
187-
tmp_cstate->bw_control);
188-
189-
bw_sum_of_intfs += tmp_cstate->new_perf.bw_ctl;
190-
}
197+
dpu_core_perf_aggregate(crtc->dev, dpu_crtc_get_client_type(crtc), &perf);
191198

192-
/* convert bandwidth to kb */
193-
bw = DIV_ROUND_UP_ULL(bw_sum_of_intfs, 1000);
194-
DRM_DEBUG_ATOMIC("calculated bandwidth=%uk\n", bw);
199+
/* convert bandwidth to kb */
200+
bw = DIV_ROUND_UP_ULL(perf.bw_ctl, 1000);
201+
DRM_DEBUG_ATOMIC("calculated bandwidth=%uk\n", bw);
195202

196-
threshold = kms->perf.perf_cfg->max_bw_high;
203+
threshold = kms->perf.perf_cfg->max_bw_high;
197204

198-
DRM_DEBUG_ATOMIC("final threshold bw limit = %d\n", threshold);
205+
DRM_DEBUG_ATOMIC("final threshold bw limit = %d\n", threshold);
199206

200-
if (!threshold) {
201-
DPU_ERROR("no bandwidth limits specified\n");
202-
return -E2BIG;
203-
} else if (bw > threshold) {
204-
DPU_ERROR("exceeds bandwidth: %ukb > %ukb\n", bw,
205-
threshold);
206-
return -E2BIG;
207-
}
207+
if (!threshold) {
208+
DPU_ERROR("no bandwidth limits specified\n");
209+
return -E2BIG;
210+
} else if (bw > threshold) {
211+
DPU_ERROR("exceeds bandwidth: %ukb > %ukb\n", bw,
212+
threshold);
213+
return -E2BIG;
208214
}
209215

210216
return 0;
211217
}
212218

213-
static void dpu_core_perf_aggregate(struct drm_device *ddev,
214-
enum dpu_crtc_client_type curr_client_type,
215-
struct dpu_core_perf_params *perf)
216-
{
217-
struct dpu_crtc_state *dpu_cstate;
218-
struct drm_crtc *tmp_crtc;
219-
220-
drm_for_each_crtc(tmp_crtc, ddev) {
221-
if (tmp_crtc->enabled &&
222-
curr_client_type == dpu_crtc_get_client_type(tmp_crtc)) {
223-
dpu_cstate = to_dpu_crtc_state(tmp_crtc->state);
224-
225-
perf->max_per_pipe_ib = max(perf->max_per_pipe_ib,
226-
dpu_cstate->new_perf.max_per_pipe_ib);
227-
228-
perf->bw_ctl += dpu_cstate->new_perf.bw_ctl;
229-
230-
DRM_DEBUG_ATOMIC("crtc=%d bw=%llu\n",
231-
tmp_crtc->base.id,
232-
dpu_cstate->new_perf.bw_ctl);
233-
}
234-
}
235-
}
236-
237219
static int _dpu_core_perf_crtc_update_bus(struct dpu_kms *kms,
238220
struct drm_crtc *crtc)
239221
{

0 commit comments

Comments
 (0)