Skip to content

Commit 0d87308

Browse files
edumazetjoergroedel
authored andcommitted
iommu/iova: Avoid false sharing on fq_timer_on
In commit 14bd9a6 ("iommu/iova: Separate atomic variables to improve performance") Jinyu Qi identified that the atomic_cmpxchg() in queue_iova() was causing a performance loss and moved critical fields so that the false sharing would not impact them. However, avoiding the false sharing in the first place seems easy. We should attempt the atomic_cmpxchg() no more than 100 times per second. Adding an atomic_read() will keep the cache line mostly shared. This false sharing came with commit 9a005a8 ("iommu/iova: Add flush timer"). Signed-off-by: Eric Dumazet <[email protected]> Fixes: 9a005a8 ('iommu/iova: Add flush timer') Cc: Jinyu Qi <[email protected]> Cc: Joerg Roedel <[email protected]> Acked-by: Robin Murphy <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent c8fb436 commit 0d87308

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/iommu/iova.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad,
577577

578578
spin_unlock_irqrestore(&fq->lock, flags);
579579

580-
if (atomic_cmpxchg(&iovad->fq_timer_on, 0, 1) == 0)
580+
/* Avoid false sharing as much as possible. */
581+
if (!atomic_read(&iovad->fq_timer_on) &&
582+
!atomic_cmpxchg(&iovad->fq_timer_on, 0, 1))
581583
mod_timer(&iovad->fq_timer,
582584
jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT));
583585
}

0 commit comments

Comments
 (0)