Skip to contentSkip to conversation

net/i40e: remove the SMP barrier in HW scanning func

PATCH In review Joyce Kong 5 participants 22 messages Jun 4, 2021 – Jul 13, 2021 Network drivers

lore
Share & tools
lore

Joyce Kong

author
#0 lore raw

PATCH 1/1 net/i40e: remove the SMP barrier in HW scanning func

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/i40e/i40e_rxtx.c +8 -5
index 6c58decec..410a81f30 100644
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
@@ -482,11 +482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
Signature · 1 line
2.17.1
#1 lore raw

<snip>

Quoted 3 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

Are there any performance numbers with this change?

Quoted 42 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +2 -5
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

drivers/net/i40e/i40e_rxtx.c +7 -1
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#2 lore raw
In reply to Joyce Kong
Quoted 10 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Friday, June 4, 2021 3:34 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH v1] net/i40e: remove the SMP barrier in HW scanning func

Quoted 2 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the ring. So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 21 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +1 -1
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11 +482,14

@@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 485

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -1
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

Quoted 16 lines
drivers/net/i40e/i40e_rxtx.c +7 -4
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#3 lore raw

<snip>

Quoted 7 lines
Quoted 3 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the ring.

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

On x86, the reads are not re-ordered (though the compiler can re-order). On ARM, the reads can get re-ordered and hence the barriers are required. In order to avoid the barriers, we are trying to process only those descriptors whose DD bits are set such that they are contiguous. i.e. if the DD bits are 1011, we process only the first descriptor.

Quoted 50 lines

So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 16 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index
6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 10 lines
drivers/net/i40e/i40e_rxtx.c +2 -2
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -3
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

Quoted 12 lines
drivers/net/i40e/i40e_rxtx.c +7 -1
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#4 lore raw
Quoted 18 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Monday, June 7, 2021 2:33 AM
To: Zhang, Qi Z <[email protected]>; Joyce Kong <[email protected]>; Xing, Beilei <[email protected]>; Ruifeng Wang <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v1] net/i40e: remove the SMP barrier in HW scanning func

<snip>

Quoted 4 lines
Quoted 3 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

Quoted 7 lines
Quoted 3 lines

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the ring.

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0" as the read address are declared as volatile, compiler will not re-ordered them.

Quoted 6 lines

On x86, the reads are not re-ordered (though the compiler can re-order). On ARM, the reads can get re-ordered and hence the barriers are required. In order to avoid the barriers, we are trying to process only those descriptors whose DD bits are set such that they are contiguous. i.e. if the DD bits are 1011, we process only the first descriptor.

Ok, I see. thanks for the explanation.
At this moment, I may prefer not change the behavior of x86, so compile option for arm can be added, in future when we observe no performance impact for x86 as well, we can consider to remove it, what do you think?

Quoted 51 lines
Quoted 51 lines

So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 16 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index
6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 10 lines
drivers/net/i40e/i40e_rxtx.c +2 -2
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -3
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

Quoted 12 lines
drivers/net/i40e/i40e_rxtx.c +7 -1
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#5 lore raw

<snip>

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the

ring.

Quoted 4 lines

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

Quoted 5 lines

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0"
as the read address are declared as volatile, compiler will not re-ordered them.

My understanding is that

1) the NIC will write an entire cache line of descriptors to memory "atomically" (i.e. the entire cache line is visible to the CPU at once) if there are enough descriptors ready to fill one cache line.
2) But, if there are not enough descriptors ready (because for ex: there is not enough traffic), then it might write partial cache lines.

Please correct me if I am wrong.

For #1, I do not think it matters if we read the descriptors in reverse order or not as the cache line is written atomically.
For #1, if we read in reverse order, does it make sense to not check the DD bits of descriptors that are earlier in the order once we encounter a descriptor that has its DD bit set? This is because NIC updates the descriptors in order.

Quoted 8 lines
Quoted 7 lines

On x86, the reads are not re-ordered (though the compiler can re-order). On ARM, the reads can get re-ordered and hence the barriers are required. In order to avoid the barriers, we are trying to process only those descriptors whose DD bits are set such that they are contiguous. i.e. if the DD bits are 1011, we process only the first descriptor.

Quoted 4 lines

Ok, I see. thanks for the explanation.
At this moment, I may prefer not change the behavior of x86, so compile option for arm can be added, in future when we observe no performance impact for x86 as well, we can consider to remove it, what do you think?

I am ok with this approach.

Quoted 53 lines
Quoted 12 lines
Quoted 12 lines

So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 7 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Quoted 6 lines
Quoted 6 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index
6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue

*rxq)

Quoted 34 lines
Quoted 34 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 13 lines
drivers/net/i40e/i40e_rxtx.c +2 -2
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -3
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

Quoted 12 lines
drivers/net/i40e/i40e_rxtx.c +7 -1
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

author
#6 lore raw

<snip>

Quoted 41 lines
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the ring.

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

Quoted 5 lines

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0" as the read address are declared as volatile, compiler will not re-ordered them.

My understanding is that

1) the NIC will write an entire cache line of descriptors to memory "atomically" (i.e. the entire cache line is visible to the CPU at once) if there are enough descriptors ready to fill one cache line.
2) But, if there are not enough descriptors ready (because for ex: there is not enough traffic), then it might write partial cache lines.

Please correct me if I am wrong.

For #1, I do not think it matters if we read the descriptors in reverse order or not as the cache line is written atomically.
For #1, if we read in reverse order, does it make sense to not check the DD bits of descriptors that are earlier in the order once we encounter a descriptor that has its DD bit set? This is because NIC updates the descriptors in order.

Quoted 7 lines
Quoted 7 lines

On x86, the reads are not re-ordered (though the compiler can re-order). On ARM, the reads can get re-ordered and hence the barriers are required. In order to avoid the barriers, we are trying to process only those descriptors whose DD bits are set such that they are contiguous. i.e. if the DD bits are 1011, we process only the first

Quoted 9 lines

descriptor.

Quoted 5 lines

Ok, I see. thanks for the explanation.
At this moment, I may prefer not change the behavior of x86, so compile option for arm can be added, in future when we observe no performance impact for x86 as well, we can consider to remove it, what do

you think?
I am ok with this approach.

Thanks for your comments, I will modify the patch according to your suggestions.

Quoted 31 lines
Quoted 31 lines
Quoted 12 lines
Quoted 12 lines

So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 7 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Quoted 6 lines
Quoted 6 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index
6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue

*rxq)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/i40e/i40e_rxtx.c +2 -1
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 485

Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +0 -1
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

I have tested the patch on both x86 and Arm platforms, it seems no performance change. As Honnappa explained, we combined these to avoid the barriers. In this way, we only process those descriptors whose DD bits are set such that they are contiguous.

Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -3
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

drivers/net/i40e/i40e_rxtx.c

Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c +2 -0
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_rxtx.c +5 -1
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#7 lore raw
In reply to Honnappa Nagarahalli

Hi

Quoted 32 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Tuesday, June 8, 2021 5:36 AM
To: Zhang, Qi Z <[email protected]>; Joyce Kong <[email protected]>; Xing, Beilei <[email protected]>; Ruifeng Wang <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v1] net/i40e: remove the SMP barrier in HW scanning func

<snip>

Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the

ring.

Quoted 4 lines

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

Quoted 5 lines

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0" as the read address are declared as volatile, compiler will not re-ordered them.

Quoted 7 lines

My understanding is that

1) the NIC will write an entire cache line of descriptors to memory "atomically" (i.e. the entire cache line is visible to the CPU at once) if there are enough descriptors ready to fill one cache line.
2) But, if there are not enough descriptors ready (because for ex: there is not enough traffic), then it might write partial cache lines.

Yes, for example a cache line contains 4 x16 bytes descriptors and it is possible we get 1 1 1 0 for DD bit at some moment.

Quoted 5 lines

Please correct me if I am wrong.

For #1, I do not think it matters if we read the descriptors in reverse order or not as the cache line is written atomically.

I think below cases may happens if we don't read in reserve order.

1. CPU get first cache line as 1 1 1 0 in a loop
2. new packets coming and NIC append last 1 to the first cache and a new cache line with 1 1 1 1.
3. CPU continue new cache line with 1 1 1 1 in the same loop, but the last 1 of first cache line is missed, so finally it get 1 1 1 0 1 1 1 1.

Quoted 3 lines

For #1, if we read in reverse order, does it make sense to not check the DD bits of descriptors that are earlier in the order once we encounter a descriptor that has its DD bit set? This is because NIC updates the descriptors in order.

I think the answer is yes, when we met the first DD bit, we should able to calculated the exact number base on the index, but not sure how much performance gain.

Quoted 70 lines
Quoted 8 lines
Quoted 8 lines

On x86, the reads are not re-ordered (though the compiler can re-order). On ARM, the reads can get re-ordered and hence the barriers are required. In order to avoid the barriers, we are trying to process only those descriptors whose DD bits are set such that they are contiguous. i.e. if the DD bits are 1011, we process only the first

descriptor.

Quoted 5 lines

Ok, I see. thanks for the explanation.
At this moment, I may prefer not change the behavior of x86, so compile option for arm can be added, in future when we observe no performance impact for x86 as well, we can consider to remove it, what do

you think?
I am ok with this approach.

Quoted 53 lines
Quoted 12 lines
Quoted 12 lines

So I didn't see the a new logic be added, would you describe more clear about the purpose of this patch?

Quoted 7 lines
---
 drivers/net/i40e/i40e_rxtx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Quoted 6 lines
Quoted 6 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index
6c58decec..410a81f30 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue

*rxq)

Quoted 34 lines
Quoted 34 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 13 lines
drivers/net/i40e/i40e_rxtx.c +2 -2
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,14 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();

Any performance gain by removing this? and it is not necessary to be combined with below change, right?

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0 -3
-
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

Quoted 12 lines
drivers/net/i40e/i40e_rxtx.c +7 -1
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

#8 lore raw
Quoted 47 lines · Qi Z

Hi

Quoted 32 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Tuesday, June 8, 2021 5:36 AM
To: Zhang, Qi Z <[email protected]>; Joyce Kong <[email protected]>; Xing, Beilei <[email protected]>; Ruifeng Wang <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v1] net/i40e: remove the SMP barrier in HW scanning func

<snip>

Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading descs.

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the

ring.

Quoted 4 lines

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can occur. Appreciate if you could explain that.

Quoted 5 lines

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0" as the read address are declared as volatile, compiler will not re-ordered them.

Quoted 7 lines

My understanding is that

1) the NIC will write an entire cache line of descriptors to memory "atomically" (i.e. the entire cache line is visible to the CPU at once) if there are enough descriptors ready to fill one cache line.
2) But, if there are not enough descriptors ready (because for ex: there is not enough traffic), then it might write partial cache lines.

Yes, for example a cache line contains 4 x16 bytes descriptors and it is possible we get 1 1 1 0 for DD bit at some moment.

Quoted 3 lines

Please correct me if I am wrong.

Quoted 9 lines
Quoted 2 lines

For #1, I do not think it matters if we read the descriptors in reverse order or not as the cache line is written atomically.

I think below cases may happens if we don't read in reserve order.

1. CPU get first cache line as 1 1 1 0 in a loop
2. new packets coming and NIC append last 1 to the first cache and a new cache line with 1 1 1 1.
3. CPU continue new cache line with 1 1 1 1 in the same loop, but the last 1 of first cache line is missed, so finally it get 1 1 1 0 1 1 1 1.

The one-sentence answer here is: when two entities are moving along a line in the same direction - like two runners in a race - then they can pass each other multiple times as each goes slower or faster at any point in time, whereas if they are moving in opposite directions there will only ever be one cross-over point no matter how the speed of each changes.

In the case of NIC and software this fact means that there will always be a clear cross-over point from DD set to not-set.

Quoted 7 lines
Quoted 4 lines

For #1, if we read in reverse order, does it make sense to not check the DD bits of descriptors that are earlier in the order once we encounter a descriptor that has its DD bit set? This is because NIC updates the descriptors in order.

I think the answer is yes, when we met the first DD bit, we should able to calculated the exact number base on the index, but not sure how much performance gain.

The other factors here are:
1. The driver does not do a straight read of all 32 DD bits in one go, rather it does 8 at a time and aborts at the end of a set of 8 if not all are valid.
2. For any that are set, we have to read the descriptor anyway to get the packet data out of it, so in the shortcut case of the last descriptor being set, we still have to read the other 7 anyway, and DD comes for free as part of it.
3. Blindly reading 8 at a time reduces the branching to just a single decision point at the end of each set of 8, reducing possible branch mispredicts.

#9 lore raw

<snip>

Quoted 48 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Add the logic to determine how many DD bits have been set for contiguous packets, for removing the SMP barrier while reading

descs.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines

I didn't understand this.
The current logic already guarantee the read out DD bits are from continue packets, as it read Rx descriptor in a reversed order from the

ring.

Quoted 3 lines

Qi, the comments in the code mention that there is a race condition if the descriptors are not read in the reverse order. But, they do not mention what the race condition is and how it can

occur.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 1 line

Appreciate if you could explain that.

The Race condition happens between the NIC and CPU, if write and read DD bit in the same order, there might be a hole (e.g. 1011) with the reverse read order, we make sure no more "1" after the first "0" as the read address are declared as volatile, compiler will not re-ordered them.

My understanding is that

1) the NIC will write an entire cache line of descriptors to memory

"atomically"

Quoted 6 lines
Quoted 4 lines

(i.e. the entire cache line is visible to the CPU at once) if there are enough descriptors ready to fill one cache line.
2) But, if there are not enough descriptors ready (because for ex:
there is not enough traffic), then it might write partial cache lines.

Yes, for example a cache line contains 4 x16 bytes descriptors and it is

possible we get 1 1 1 0 for DD bit at some moment.

Quoted 4 lines
Quoted 4 lines

Please correct me if I am wrong.

Quoted 8 lines
Quoted 2 lines

For #1, I do not think it matters if we read the descriptors in reverse order or not as the cache line is written atomically.

I think below cases may happens if we don't read in reserve order.

1. CPU get first cache line as 1 1 1 0 in a loop 2. new packets coming and NIC append last 1 to the first cache and a new cache line with 1 1 1 1.
3. CPU continue new cache line with 1 1 1 1 in the same loop, but the last 1

of first cache line is missed, so finally it get 1 1 1 0 1 1 1 1.

Quoted 1 line
Quoted 8 lines

The one-sentence answer here is: when two entities are moving along a line in the same direction - like two runners in a race - then they can pass each other multiple times as each goes slower or faster at any point in time, whereas if they are moving in opposite directions there will only ever be one cross-over point no matter how the speed of each changes.

In the case of NIC and software this fact means that there will always be a clear cross-over point from DD set to not-set.

Thanks Bruce, that is a great analogy to describe the problem assuming that the reads are actually happening in the program order.

On Arm platform, even though the program is reading in reverse order, the reads might get executed in any random order. We have 2 solutions here:
1) Enforced the order with barriers or
2) Only process descriptors with contiguous DD bits set

Quoted 11 lines
Quoted 5 lines
Quoted 5 lines

For #1, if we read in reverse order, does it make sense to not check the DD bits of descriptors that are earlier in the order once we encounter a descriptor that has its DD bit set? This is because NIC updates

the descriptors in order.

Quoted 2 lines

I think the answer is yes, when we met the first DD bit, we should able to

calculated the exact number base on the index, but not sure how much performance gain.

Quoted 1 line
Quoted 8 lines

The other factors here are:
1. The driver does not do a straight read of all 32 DD bits in one go, rather it does 8 at a time and aborts at the end of a set of 8 if not all are valid.
2. For any that are set, we have to read the descriptor anyway to get the packet data out of it, so in the shortcut case of the last descriptor being set, we still have to read the other 7 anyway, and DD comes for free as part of it.
3. Blindly reading 8 at a time reduces the branching to just a single decision point at the end of each set of 8, reducing possible branch mispredicts.

Agree.
I think there is another requirement. The other words in the descriptor should be read only after reading the word containing the DD bit.

On x86, the program order takes care of this (although compiler barrier is required). On Arm, this needs to be taken care explicitly using barriers.

author
#10 lore raw

PATCH v2 1/1 net/i40e: add logic of processing continuous DD bits for Arm

In reply to Joyce Kong

For Arm platforms, reading descs can get re-ordered, then the status of DD bits will be discontinuous, so add the logic to only process continuous descs by checking DD bits.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_rxtx.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c +15 -4
index 6c58decec..86e2f083e 100644
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
@@ -482,11 +482,22 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
+		/* This barrier is to order loads of different words in the descriptor */
+		rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
 
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+#ifdef RTE_ARCH_ARM
+			/* For Arm platforms, only compute continuous status bits */
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+#else
+			nb_dd += var;
+#endif
+		}
 
 		nb_rx += nb_dd;
 
Signature · 1 line
2.17.1
#11 lore raw

Re: [dpdk-dev] [PATCH v2] net/i40e: add logic of processing continuous DD bits for Arm

<snip>

Quoted 34 lines

For Arm platforms, reading descs can get re-ordered, then the status of DD bits will be discontinuous, so add the logic to only process continuous descs by checking DD bits.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_rxtx.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

6c58decec..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c +3 -2
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,22 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
+		/* This barrier is to order loads of different words in the

descriptor */

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +1 -0
+		rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

I think this should go into a separate commit as the following change is unrelated.

Quoted 24 lines
drivers/net/i40e/i40e_rxtx.c +0 -2
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

drivers/net/i40e/i40e_rxtx.c +2 -0
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);

#ifdef

drivers/net/i40e/i40e_rxtx.c +2 -0
+RTE_ARCH_ARM
+			/* For Arm platforms, only compute continuous

status bits */

drivers/net/i40e/i40e_rxtx.c +8 -1
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+#else
+			nb_dd += var;
+#endif
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

author
#12 lore raw

Re: [dpdk-dev] [PATCH v2] net/i40e: add logic of processing continuous DD bits for Arm

Quoted 45 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Wednesday, June 30, 2021 9:15 AM
To: Joyce Kong <[email protected]>; [email protected]; [email protected]; Ruifeng Wang <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v2] net/i40e: add logic of processing continuous DD bits for Arm

<snip>

Quoted 31 lines

For Arm platforms, reading descs can get re-ordered, then the status of DD bits will be discontinuous, so add the logic to only process continuous descs by checking DD bits.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_rxtx.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index 6c58decec..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c +2 -1
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl; @@ -482,11
+482,22 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
Quoted 6 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +1 -1
-		rte_smp_rmb();
+		/* This barrier is to order loads of different words in the

descriptor */

drivers/net/i40e/i40e_rxtx.c +1 -0
+		rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

I think this should go into a separate commit as the following change is unrelated.

Will separate the two changes in v3.

Quoted 25 lines
Quoted 25 lines
drivers/net/i40e/i40e_rxtx.c +0 -2
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 <<

I40E_RX_DESC_STATUS_DD_SHIFT);

drivers/net/i40e/i40e_rxtx.c +2 -0
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);

#ifdef

drivers/net/i40e/i40e_rxtx.c +2 -0
+RTE_ARCH_ARM
+			/* For Arm platforms, only compute continuous

status bits */

drivers/net/i40e/i40e_rxtx.c +8 -1
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+#else
+			nb_dd += var;
+#endif
+		}
 
 		nb_rx += nb_dd;
 
--

2.17.1

author
#13 lore raw

v3 cover fixes for i40e hw scan ring

In reply to Joyce Kong

This patchset contains two parts for i40e PMD, one is to add the logic of processing continuous DD bits for Arm platform, the other is to replace SMP barrier with thread fence.

v3:
Seperate the commit changes into two parts. <Honnappa Nagarahalli>

v2:
Only add the compile option for Arm and keep X86 intact. <Qi Zhang>

v1:
The initial version.

Joyce Kong (2):
net/i40e: add logic of processing continuous DD bits for Arm net/i40e: replace SMP barrier with thread fence

 drivers/net/i40e/i40e_rxtx.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
author
#14 lore raw

PATCH v3 1/2 net/i40e: add logic of processing continuous DD bits for Arm

For Arm platforms, reading descs can get re-ordered, then the status of DD bits will be discontinuous, so add the logic to only process continuous descs by checking DD bits.

Fixes 4861cde46116 ("i40e: new poll mode driver")
---
 drivers/net/i40e/i40e_rxtx.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_rxtx.c +13 -3
index 6c58decec..9aaabfd92 100644
@@ -452,7 +452,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	uint16_t pkt_len;
 	uint64_t qword1;
 	uint32_t rx_status;
-	int32_t s[I40E_LOOK_AHEAD], nb_dd;
+	int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
 	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
@@ -485,8 +485,18 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 		rte_smp_rmb();
 
 		/* Compute how many status bits were set */
-		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
-			nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
+			var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
+#ifdef RTE_ARCH_ARM
+			/* For Arm platforms, only compute continuous status bits */
+			if (var)
+				nb_dd += 1;
+			else
+				break;
+#else
+			nb_dd += var;
+#endif
+		}
 
 		nb_rx += nb_dd;
 
Signature · 1 line
2.17.1
Applied
#15 lore raw

Re: [dpdk-dev] [PATCH v3 1/2] net/i40e: add logic of processing continuous DD bits for Arm

Quoted 16 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Tuesday, July 6, 2021 2:54 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 1/2] net/i40e: add logic of processing continuous DD bits for Arm

For Arm platforms, reading descs can get re-ordered, then the status of DD bits will be discontinuous, so add the logic to only process continuous descs by checking DD bits.

Quoted 5 lines
Fixes 4861cde46116 ("i40e: new poll mode driver")

Applied to dpdk-next-net-intel.

Thanks
Qi

author
#16 lore raw

PATCH v3 2/2 net/i40e: replace SMP barrier with thread fence

In reply to Joyce Kong

Simply replace the SMP barrier with atomic thread fence for i40e hw ring sacn, if there is no synchronization point.

---
 drivers/net/i40e/i40e_rxtx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_rxtx.c +2 -1
index 9aaabfd92..86e2f083e 100644
@@ -482,7 +482,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
+		/* This barrier is to order loads of different words in the descriptor */
+		rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
 
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
Signature · 1 line
2.17.1
#17 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Quoted 25 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Tuesday, July 6, 2021 2:54 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Simply replace the SMP barrier with atomic thread fence for i40e hw ring sacn, if there is no synchronization point.

---
 drivers/net/i40e/i40e_rxtx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

9aaabfd92..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +2 -1
@@ -482,7 +482,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 					I40E_RXD_QW1_STATUS_SHIFT;
 		}
 
-		rte_smp_rmb();
+		/* This barrier is to order loads of different words in the descriptor */
+		rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

Now for x86, you actually replace a compiler barrier with a memory fence, this may have potential performance impact which need additional resource to investigate So there are 2 options:
1. if you want this patch be merged into DPDK 21.08, please change this for ARM only.
2. you can wait for our update for x86 but I guess it will miss 21.08.

What do you think?

Btw for patch 1/2, I think I can merge it independently right?

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +0 -1
 		/* Compute how many status bits were set */
 		for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
--

2.17.1

#18 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Quoted 29 lines · Qi Z
Quoted 29 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Tuesday, July 6, 2021 2:54 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Simply replace the SMP barrier with atomic thread fence for i40e hw ring sacn, if there is no synchronization point.

---
 drivers/net/i40e/i40e_rxtx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

9aaabfd92..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -482,7 +482,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
                                      I40E_RXD_QW1_STATUS_SHIFT;
              }
 
Quoted 5 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +2 -1
-             rte_smp_rmb();
+             /* This barrier is to order loads of different words in the descriptor */
+             rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

Now for x86, you actually replace a compiler barrier with a memory fence, this may have potential performance impact which need additional resource to investigate

No memory fence instruction is generated for __ATOMIC_ACQUIRE on x86 for any version of gcc or clang that I've tried, based on experiments here:

https://godbolt.org/z/Yxr1vGhKP

#19 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Quoted 53 lines

-----Original Message-----
From: Lance Richardson <[email protected]>
Sent: Thursday, July 8, 2021 9:51 PM
To: Zhang, Qi Z <[email protected]>
Cc: Joyce Kong <[email protected]>; Xing, Beilei <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Zhang, Helin <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Quoted 7 lines · Qi Z
Quoted 7 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Tuesday, July 6, 2021 2:54 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z

<[email protected]>;

Quoted 1 line
Quoted 1 line

[email protected]; [email protected]; Richardson,

Bruce

Quoted 5 lines
Quoted 5 lines

<[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Simply replace the SMP barrier with atomic thread fence for i40e hw ring

sacn,

Quoted 8 lines
Quoted 8 lines

if there is no synchronization point.

---
 drivers/net/i40e/i40e_rxtx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 482

Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0 -0

9aaabfd92..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -482,7 +482,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 

I40E_RXD_QW1_STATUS_SHIFT;

Quoted 4 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +1 -1
              }
 
-             rte_smp_rmb();
+             /* This barrier is to order loads of different words in the

descriptor */

Quoted 3 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +1 -0
+             rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

Now for x86, you actually replace a compiler barrier with a memory fence,

Quoted 8 lines

this may have potential performance impact which need additional resource to investigate

No memory fence instruction is generated for __ATOMIC_ACQUIRE on x86 for any version of gcc or clang that I've tried, based on experiments here:

https://godbolt.org/z/Yxr1vGhKP

Nice tool!
I try to write some dummy code combined with or without __atomic_thread_fence(__ATOMIC_ACQUIRE)
but I didn't see any difference of the generated assembly code, does that means __atomic_thread_fence(__ATOMIC_ACQUIRE) just does nothing on x86?

#20 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

<snip>

Quoted 37 lines
Quoted 37 lines
Quoted 3 lines
Quoted 3 lines

Simply replace the SMP barrier with atomic thread fence for i40e hw ring

sacn,

Quoted 8 lines
Quoted 8 lines

if there is no synchronization point.

---
 drivers/net/i40e/i40e_rxtx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 7 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue · line 483

Quoted 7 lines
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_rxtx.c index 9aaabfd92..86e2f083e 100644

drivers/net/i40e/i40e_rxtx.c +0 -0
@@ -482,7 +482,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue
 *rxq)
 

I40E_RXD_QW1_STATUS_SHIFT;

Quoted 5 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)

Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +2 -1
              }
 
-             rte_smp_rmb();
+             /* This barrier is to order loads of different words
+ in the

descriptor */

Quoted 4 lines

drivers/net/i40e/i40e_rxtx.c i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) · line 486

Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +1 -0
+             rte_atomic_thread_fence(__ATOMIC_ACQUIRE);

Now for x86, you actually replace a compiler barrier with a memory fence,

this may have potential performance impact which need additional resource to investigate

No memory fence instruction is generated for __ATOMIC_ACQUIRE on x86 for any version of gcc or clang that I've tried, based on experiments here:

Quoted 7 lines
Quoted 1 line

https://godbolt.org/z/Yxr1vGhKP

Nice tool!
I try to write some dummy code combined with or without __atomic_thread_fence(__ATOMIC_ACQUIRE)
but I didn't see any difference of the generated assembly code, does that means __atomic_thread_fence(__ATOMIC_ACQUIRE) just does nothing on x86?

Yes, it should not have any barriers generated for x86. At the same time it also acts as a compiler barrier.

Acked-by on v3 2/2 Applied
#21 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

In reply to Joyce Kong
Quoted 11 lines

-----Original Message-----
From: Joyce Kong <[email protected]>
Sent: Tuesday, July 6, 2021 2:54 PM
To: Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Zhang, Helin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 2/2] net/i40e: replace SMP barrier with thread fence

Quoted 5 lines

Simply replace the SMP barrier with atomic thread fence for i40e hw ring sacn, if there is no synchronization point.

Applied to dpdk-next-net-intel.

Thanks
Qi