Skip to contentSkip to conversation

nvme: use lighter smp barriers in nvme_irq

PATCH In review Heiner Kallweit 3 participants 7 messages Feb 14, 2021 – Feb 18, 2021 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: use lighter smp barriers in nvme_irq

Based on the description we should be fine using the less heavy-weight smp barriers here. On x86 this would be compiler barriers only.

---
 drivers/nvme/host/pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +2 -2
index 7b6632c00..59fee4a60 100644
@@ -1066,10 +1066,10 @@ static irqreturn_t nvme_irq(int irq, void *data)
 	 * The rmb/wmb pair ensures we see all updates from a previous run of
 	 * the irq handler, even if that was on another CPU.
 	 */
-	rmb();
+	smp_rmb();
 	if (nvme_process_cq(nvmeq))
 		ret = IRQ_HANDLED;
-	wmb();
+	smp_wmb();
 
 	return ret;
 }
Signature · 7 lines
2.30.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#2 lore raw
Quoted 7 lines · Chaitanya Kulkarni
Quoted 4 lines · Heiner Kallweit

Based on the description we should be fine using the less heavy-weight smp barriers here. On x86 this would be compiler barriers only.

Can you share performance numbers ?

I stumbled across this code piece by chance and don't have hw to test it. Having said that the change is based on code inspection only. Unfortunately the barrier comment is very generic and doesn't mention a problematic scenario. Also the commit message of 3a7afd8ee42a doesn't mention a potential race. Most likely the barrier can be removed completely. Helpful would be if someone could explain the potential race in detail, means which reordering / variable accesses could be racy. Then we would have a basis to talk about READ_ONCE/WRITE_ONCE vs. smp barrier vs. dma barrier vs. full barrier.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#3 lore raw
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Chaitanya Kulkarni
Quoted 4 lines · Heiner Kallweit

Based on the description we should be fine using the less heavy-weight smp barriers here. On x86 this would be compiler barriers only.

Can you share performance numbers ?

Quoted 10 lines

I stumbled across this code piece by chance and don't have hw to test it. Having said that the change is based on code inspection only. Unfortunately the barrier comment is very generic and doesn't mention a problematic scenario. Also the commit message of 3a7afd8ee42a doesn't mention a potential race. Most likely the barrier can be removed completely. Helpful would be if someone could explain the potential race in detail, means which reordering / variable accesses could be racy. Then we would have a basis to talk about READ_ONCE/WRITE_ONCE vs. smp barrier vs. dma barrier vs. full barrier.

For these question you need to add commit Author to original email, as far as
I know any performance improvement needs to be backed by data, unless there is an exception, in this case I'm not if it is.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#4 lore raw
In reply to Heiner Kallweit
Quoted 9 lines · Heiner Kallweit
Quoted 7 lines · Chaitanya Kulkarni
Quoted 4 lines · Heiner Kallweit

Based on the description we should be fine using the less heavy-weight smp barriers here. On x86 this would be compiler barriers only.

Can you share performance numbers ?

Quoted 9 lines

I stumbled across this code piece by chance and don't have hw to test it. Having said that the change is based on code inspection only. Unfortunately the barrier comment is very generic and doesn't mention a problematic scenario. Also the commit message of 3a7afd8ee42a doesn't mention a potential race. Most likely the barrier can be removed completely. Helpful would be if someone could explain the potential race in detail, means which reordering / variable accesses could be racy. Then we would have a basis to talk about READ_ONCE/WRITE_ONCE vs. smp barrier vs. dma barrier vs. full barrier.

The variables the driver was protecting no longer exist, so I also agree the barriers should not be necessary.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#5 lore raw

Keith,

Quoted 18 lines · Keith Busch
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Chaitanya Kulkarni
Quoted 4 lines · Heiner Kallweit

Based on the description we should be fine using the less heavy-weight smp barriers here. On x86 this would be compiler barriers only.

Can you share performance numbers ?

Quoted 9 lines

I stumbled across this code piece by chance and don't have hw to test it. Having said that the change is based on code inspection only. Unfortunately the barrier comment is very generic and doesn't mention a problematic scenario. Also the commit message of 3a7afd8ee42a doesn't mention a potential race. Most likely the barrier can be removed completely. Helpful would be if someone could explain the potential race in detail, means which reordering / variable accesses could be racy. Then we would have a basis to talk about READ_ONCE/WRITE_ONCE vs. smp barrier vs. dma barrier vs. full barrier.

Quoted 3 lines

The variables the driver was protecting no longer exist, so I also agree the barriers should not be necessary.

Are you saying something like following is needed ?

From a3a73bd3943b479f82ff00582baf2c37c1afd8e8 Mon Sep 17 00:00:00 2001
From: Chaitanya Kulkarni <[email protected]>
Date: Wed, 17 Feb 2021 20:01:37 -0800
Subject: [PATCH] nvme-pci: remove the barriers

The variable which was protected by the barriers is removed in The commit f6c4d97b0d82 (" nvme/pci: Remove last_cq_head").

Remove the barriers which was protecting the variable.

---
 drivers/nvme/host/pci.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/nvme/host/pci.c +0 -6
index 0045c5edf629..3729775f6a8a 100644
@@ -1062,14 +1062,8 @@ static irqreturn_t nvme_irq(int irq, void *data)
     struct nvme_queue *nvmeq = data;
     irqreturn_t ret = IRQ_NONE;
 
-    /*
-     * The rmb/wmb pair ensures we see all updates from a previous run of
-     * the irq handler, even if that was on another CPU.
-     */
-    rmb();
     if (nvme_process_cq(nvmeq))
         ret = IRQ_HANDLED;
-    wmb();
 
     return ret;
 }
Signature · 6 lines
2.22.1

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
maintainer
#6 lore raw
Quoted 6 lines · Chaitanya Kulkarni
Quoted 3 lines · Keith Busch

The variables the driver was protecting no longer exist, so I also agree the barriers should not be necessary.

Are you saying something like following is needed ?

Right, I'm just saying the barriers don't appear to be necessary, so they can go away as you've indicated below.

Quoted 36 lines

From a3a73bd3943b479f82ff00582baf2c37c1afd8e8 Mon Sep 17 00:00:00 2001
From: Chaitanya Kulkarni <[email protected]>
Date: Wed, 17 Feb 2021 20:01:37 -0800
Subject: [PATCH] nvme-pci: remove the barriers

The variable which was protected by the barriers is removed in The commit f6c4d97b0d82 (" nvme/pci: Remove last_cq_head").

Remove the barriers which was protecting the variable.

---
 drivers/nvme/host/pci.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/nvme/host/pci.c +0 -6
index 0045c5edf629..3729775f6a8a 100644
@@ -1062,14 +1062,8 @@ static irqreturn_t nvme_irq(int irq, void *data)
     struct nvme_queue *nvmeq = data;
     irqreturn_t ret = IRQ_NONE;
 
-    /*
-     * The rmb/wmb pair ensures we see all updates from a previous run of
-     * the irq handler, even if that was on another CPU.
-     */
-    rmb();
     if (nvme_process_cq(nvmeq))
         ret = IRQ_HANDLED;
-    wmb();
 
     return ret;
 }
Signature · 1 line
2.22.1

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme