]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/xe_guc_pc: Lock once to update stashed frequencies
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 18 Jun 2025 18:49:59 +0000 (11:49 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 24 Jun 2025 16:58:03 +0000 (09:58 -0700)
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 <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/20250618-wa-22019338487-v5-2-b888388477f2@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_guc_pc.c

index 624e3a1a78121c9616b971066e831891b687c8a1..6224cc4fefb94b832ffe989ee795a3c7d92d2496 100644 (file)
@@ -890,27 +890,28 @@ static int pc_adjust_requested_freq(struct xe_guc_pc *pc)
 
 static int pc_set_mert_freq_cap(struct xe_guc_pc *pc)
 {
-       int ret = 0;
+       int ret;
 
-       if (XE_WA(pc_to_gt(pc), 22019338487)) {
-               /*
-                * Get updated min/max and stash them.
-                */
-               ret = xe_guc_pc_get_min_freq(pc, &pc->stashed_min_freq);
-               if (!ret)
-                       ret = xe_guc_pc_get_max_freq(pc, &pc->stashed_max_freq);
-               if (ret)
-                       return ret;
+       if (!XE_WA(pc_to_gt(pc), 22019338487))
+               return 0;
 
-               /*
-                * Ensure min and max are bound by MERT_FREQ_CAP until driver loads.
-                */
-               mutex_lock(&pc->freq_lock);
-               ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc)));
-               if (!ret)
-                       ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc)));
-               mutex_unlock(&pc->freq_lock);
-       }
+       guard(mutex)(&pc->freq_lock);
+
+       /*
+        * Get updated min/max and stash them.
+        */
+       ret = xe_guc_pc_get_min_freq_locked(pc, &pc->stashed_min_freq);
+       if (!ret)
+               ret = xe_guc_pc_get_max_freq_locked(pc, &pc->stashed_max_freq);
+       if (ret)
+               return ret;
+
+       /*
+        * Ensure min and max are bound by MERT_FREQ_CAP until driver loads.
+        */
+       ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc)));
+       if (!ret)
+               ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc)));
 
        return ret;
 }