Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <quic_abhinavk@quicinc.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/636059/
Link: https://lore.kernel.org/r/20250209-dpu-perf-rework-v5-2-87e936cf3004@linaro.org

+52 -70
+52 -70
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
··· 140 140 perf->max_per_pipe_ib, perf->bw_ctl); 141 141 } 142 142 143 - /** 144 - * dpu_core_perf_crtc_check - validate performance of the given crtc state 145 - * @crtc: Pointer to crtc 146 - * @state: Pointer to new crtc state 147 - * return: zero if success, or error code otherwise 148 - */ 149 - int dpu_core_perf_crtc_check(struct drm_crtc *crtc, 150 - struct drm_crtc_state *state) 151 - { 152 - u32 bw, threshold; 153 - u64 bw_sum_of_intfs = 0; 154 - enum dpu_crtc_client_type curr_client_type; 155 - struct dpu_crtc_state *dpu_cstate; 156 - struct drm_crtc *tmp_crtc; 157 - struct dpu_kms *kms; 158 - 159 - if (!crtc || !state) { 160 - DPU_ERROR("invalid crtc\n"); 161 - return -EINVAL; 162 - } 163 - 164 - kms = _dpu_crtc_get_kms(crtc); 165 - 166 - /* we only need bandwidth check on real-time clients (interfaces) */ 167 - if (dpu_crtc_get_client_type(crtc) == NRT_CLIENT) 168 - return 0; 169 - 170 - dpu_cstate = to_dpu_crtc_state(state); 171 - 172 - /* obtain new values */ 173 - _dpu_core_perf_calc_crtc(&kms->perf, crtc, state, &dpu_cstate->new_perf); 174 - 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 - } 191 - 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); 195 - 196 - threshold = kms->perf.perf_cfg->max_bw_high; 197 - 198 - DRM_DEBUG_ATOMIC("final threshold bw limit = %d\n", threshold); 199 - 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 - } 208 - } 209 - 210 - return 0; 211 - } 212 - 213 143 static void dpu_core_perf_aggregate(struct drm_device *ddev, 214 144 enum dpu_crtc_client_type curr_client_type, 215 145 struct dpu_core_perf_params *perf) ··· 162 232 dpu_cstate->new_perf.bw_ctl); 163 233 } 164 234 } 235 + } 236 + 237 + /** 238 + * dpu_core_perf_crtc_check - validate performance of the given crtc state 239 + * @crtc: Pointer to crtc 240 + * @state: Pointer to new crtc state 241 + * return: zero if success, or error code otherwise 242 + */ 243 + int dpu_core_perf_crtc_check(struct drm_crtc *crtc, 244 + struct drm_crtc_state *state) 245 + { 246 + u32 bw, threshold; 247 + struct dpu_crtc_state *dpu_cstate; 248 + struct dpu_kms *kms; 249 + struct dpu_core_perf_params perf; 250 + 251 + if (!crtc || !state) { 252 + DPU_ERROR("invalid crtc\n"); 253 + return -EINVAL; 254 + } 255 + 256 + kms = _dpu_crtc_get_kms(crtc); 257 + 258 + /* we only need bandwidth check on real-time clients (interfaces) */ 259 + if (dpu_crtc_get_client_type(crtc) == NRT_CLIENT) 260 + return 0; 261 + 262 + dpu_cstate = to_dpu_crtc_state(state); 263 + 264 + /* obtain new values */ 265 + _dpu_core_perf_calc_crtc(&kms->perf, crtc, state, &dpu_cstate->new_perf); 266 + 267 + dpu_core_perf_aggregate(crtc->dev, dpu_crtc_get_client_type(crtc), &perf); 268 + 269 + /* convert bandwidth to kb */ 270 + bw = DIV_ROUND_UP_ULL(perf.bw_ctl, 1000); 271 + DRM_DEBUG_ATOMIC("calculated bandwidth=%uk\n", bw); 272 + 273 + threshold = kms->perf.perf_cfg->max_bw_high; 274 + 275 + DRM_DEBUG_ATOMIC("final threshold bw limit = %d\n", threshold); 276 + 277 + if (!threshold) { 278 + DPU_ERROR("no bandwidth limits specified\n"); 279 + return -E2BIG; 280 + } else if (bw > threshold) { 281 + DPU_ERROR("exceeds bandwidth: %ukb > %ukb\n", bw, 282 + threshold); 283 + return -E2BIG; 284 + } 285 + 286 + return 0; 165 287 } 166 288 167 289 static int _dpu_core_perf_crtc_update_bus(struct dpu_kms *kms,