iommu/iova: avoid false sharing on fq_timer_on
Subsystems (2)
PATCH 1/1 iommu/iova: avoid false sharing on fq_timer_on
In commit 14bd9a607f90 ("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 9a005a800ae8
("iommu/iova: Add flush timer").
--- drivers/iommu/iova.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iova.c +3 -1
@@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad,spin_unlock_irqrestore (&fq->lock, flags); -if (atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ) ==0 ) +/* Avoid false sharing as much as possible. */ +if (!atomic_read (&iovad->fq_timer_on) && + !atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ))mod_timer (&iovad->fq_timer, jiffies +msecs_to_jiffies (IOVA_FQ_TIMEOUT )); }
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Looks good to me, but adding Robin for his opinion.
Quoted 37 lines · Eric Dumazet
In commit
14bd9a607f90("iommu/iova: Separate atomic variables to improve performance") Jinyu Qi identified that theatomic_cmpxchg()inqueue_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 anatomic_read()will keep the cache line mostly shared.This false sharing came with commit
9a005a800ae8
("iommu/iova: Add flush timer").Signed-off-by Eric Dumazet <[email protected]>Cc Jinyu Qi <[email protected]>Cc Joerg Roedel <[email protected]>--- drivers/iommu/iova.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iommu/iova.c +3
-1@@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad,spin_unlock_irqrestore (&fq->lock, flags); -if (atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ) ==0 ) +/* Avoid false sharing as much as possible. */ +if (!atomic_read (&iovad->fq_timer_on) && + !atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ))mod_timer (&iovad->fq_timer, jiffies +msecs_to_jiffies (IOVA_FQ_TIMEOUT )); }Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Quoted 1 line · Joerg Roedel
Looks good to me, but adding Robin for his opinion.
Sounds reasonable to me too - that should also be true for the majority of Arm systems that we know of. Will suggested that atomic_try_cmpxchg() might be relevant, but AFAICS that's backwards compared to what we want to do here, which I guess is more of an "atomic_unlikely_cmpxchg".
Cheers,
Robin.
Quoted 38 lines · Eric Dumazet
Quoted 37 lines
In commit
14bd9a607f90("iommu/iova: Separate atomic variables to improve performance") Jinyu Qi identified that theatomic_cmpxchg()inqueue_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 anatomic_read()will keep the cache line mostly shared.This false sharing came with commit
9a005a800ae8
("iommu/iova: Add flush timer").Signed-off-by Eric Dumazet <[email protected]>Cc Jinyu Qi <[email protected]>Cc Joerg Roedel <[email protected]>--- drivers/iommu/iova.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iommu/iova.c +3
-1@@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad,spin_unlock_irqrestore (&fq->lock, flags); -if (atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ) ==0 ) +/* Avoid false sharing as much as possible. */ +if (!atomic_read (&iovad->fq_timer_on) && + !atomic_cmpxchg (&iovad->fq_timer_on,0 ,1 ))mod_timer (&iovad->fq_timer, jiffies +msecs_to_jiffies (IOVA_FQ_TIMEOUT )); }Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Quoted 9 lines · Robin Murphy
Quoted 1 line · Joerg Roedel
Looks good to me, but adding Robin for his opinion.
Sounds reasonable to me too - that should also be true for the majority of Arm systems that we know of. Will suggested that
atomic_try_cmpxchg()might be relevant, but AFAICS that's backwards compared to what we want to do here, which I guess is more of an "atomic_unlikely_cmpxchg".Acked-by Robin Murphy <[email protected]>
Great, thanks for looking into it, Robin.
Applied now, thanks Eric.