Re: [PATCH V1 2/2] ufs: ufs-qcom: Disable AHIT before SQ tail update to prevent race in MCQ mode
From: Bart Van Assche
Date: Tue Oct 14 2025 - 12:19:12 EST
On 10/13/25 11:04 PM, palash.kambar@xxxxxxxxxxxxxxxx wrote:
+static void ufs_qcom_send_command(struct ufs_hba *hba,
+ struct ufshcd_lrb *lrbp)
+{
+ struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+ unsigned long flags;
+
+ if ((host->hw_ver.major == 6 && host->hw_ver.minor == 0 &&
+ host->hw_ver.step == 0) && hba->mcq_enabled) {
+ spin_lock_irqsave(hba->host->host_lock, flags);
+ if ((++host->active_cmds) == 1)
+ /* Stop the auto-hiberate idle timer */
+ ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER);
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ }
+}
Do you realize that obtaining the host lock from the command submission
path introduces a contention point and hence cancels one of the benefits
of MCQ (different CPU cores can submit commands independently)? This
argument still applies if host->active_cmds would be changed into an
atomic counter because making that change would still trigger cache line
ping-pong if UFS commands are submitted from multiple CPU cores
simultaneously. I think this is a strong argument against this patch
series.
An example of how to implement this kind of counter without killing performance is available in the block layer (&q->q_usage_counter).
However, implementing a per-cpu counter and checking in an efficient
way whether it has reached zero is much more complicated than the
approach of this patch series.
Is AHIT really that valuable that you want to sacrifice MCQ performance
to enable AHIT? Why not to enable/disable AHIT from the RPM callbacks?
Bart.