Skip to content

Commit 4cec909

Browse files
committed
drm/xe/xe_guc_pc: Lock once to update stashed frequencies
pc_set_mert_freq_cap() currently lock()/unlock() the mutex multiple times to stash the current frequencies. It's not a problem since xe_guc_pc_restore_stashed_freq() is guaranteed to be called only later in the init sequence. However, now that we have _locked() variants for this functions, use them and avoid potential issues when called from other places or using the same pattern. While at it, prefer and early return for the WA check to reduce indentation. Reviewed-by: Rodrigo Vivi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> (cherry picked from commit d878c97) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent d839076 commit 4cec909

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

drivers/gpu/drm/xe/xe_guc_pc.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -885,27 +885,28 @@ static int pc_adjust_requested_freq(struct xe_guc_pc *pc)
885885

886886
static int pc_set_mert_freq_cap(struct xe_guc_pc *pc)
887887
{
888-
int ret = 0;
888+
int ret;
889889

890-
if (XE_WA(pc_to_gt(pc), 22019338487)) {
891-
/*
892-
* Get updated min/max and stash them.
893-
*/
894-
ret = xe_guc_pc_get_min_freq(pc, &pc->stashed_min_freq);
895-
if (!ret)
896-
ret = xe_guc_pc_get_max_freq(pc, &pc->stashed_max_freq);
897-
if (ret)
898-
return ret;
890+
if (!XE_WA(pc_to_gt(pc), 22019338487))
891+
return 0;
899892

900-
/*
901-
* Ensure min and max are bound by MERT_FREQ_CAP until driver loads.
902-
*/
903-
mutex_lock(&pc->freq_lock);
904-
ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc)));
905-
if (!ret)
906-
ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc)));
907-
mutex_unlock(&pc->freq_lock);
908-
}
893+
guard(mutex)(&pc->freq_lock);
894+
895+
/*
896+
* Get updated min/max and stash them.
897+
*/
898+
ret = xe_guc_pc_get_min_freq_locked(pc, &pc->stashed_min_freq);
899+
if (!ret)
900+
ret = xe_guc_pc_get_max_freq_locked(pc, &pc->stashed_max_freq);
901+
if (ret)
902+
return ret;
903+
904+
/*
905+
* Ensure min and max are bound by MERT_FREQ_CAP until driver loads.
906+
*/
907+
ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc)));
908+
if (!ret)
909+
ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc)));
909910

910911
return ret;
911912
}

0 commit comments

Comments
 (0)