net/gve: fix Rx no mbufs stats counter update

Message ID 20230219003059.85479-1-levendsayar@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/gve: fix Rx no mbufs stats counter update |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Levend Sayar Feb. 19, 2023, 12:30 a.m. UTC
  rx no_mbufs stats counter update is added for another error case.

Fixes: 4f6b1dd8240c ("net/gve: support basic statistics")
Cc: junfeng.guo@intel.com

Signed-off-by: Levend Sayar <levendsayar@gmail.com>
---
 drivers/net/gve/gve_rx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Stephen Hemminger Feb. 19, 2023, 5:35 p.m. UTC | #1
On Sun, 19 Feb 2023 03:30:59 +0300
Levend Sayar <levendsayar@gmail.com> wrote:

> rx no_mbufs stats counter update is added for another error case.
> 
> Fixes: 4f6b1dd8240c ("net/gve: support basic statistics")
> Cc: junfeng.guo@intel.com
> 
> Signed-off-by: Levend Sayar <levendsayar@gmail.com>
> ---
>  drivers/net/gve/gve_rx.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/gve/gve_rx.c b/drivers/net/gve/gve_rx.c
> index 66fbcf3930..b0427731f8 100644
> --- a/drivers/net/gve/gve_rx.c
> +++ b/drivers/net/gve/gve_rx.c
> @@ -24,6 +24,7 @@ gve_rx_refill(struct gve_rx_queue *rxq)
>  				nmb = rte_pktmbuf_alloc(rxq->mpool);
>  				if (!nmb)
>  					break;
> +
>  				rxq->sw_ring[idx + i] = nmb;
>  			}
>  			if (i != nb_alloc) {

Looks like accidental whitespace change included in this patch.

> @@ -59,9 +60,13 @@ gve_rx_refill(struct gve_rx_queue *rxq)
>  				nmb = rte_pktmbuf_alloc(rxq->mpool);
>  				if (!nmb)
>  					break;
> +
>  				rxq->sw_ring[idx + i] = nmb;
>  			}
> -			nb_alloc = i;
> +			if (i != nb_alloc) {
> +				rxq->no_mbufs += nb_alloc - i;
> +				nb_alloc = i;
> +			}

Would be better to add unlikely() here like:
			if (unlikely(i < nb_alloc)) {
				rxq->no_mbufs += nb_alloc - i;
				nb_alloc = i;
			}

Or eliminate conditional branch in hot path completely.
			rxq->no_mbufs += nb_alloc - i;
			nb_alloc = i;

Or better yet refactor code here to use rte_pktmbuf_alloc_bulk() which
does single ring operation.

>  		}
>  		rxq->nb_avail -= nb_alloc;
>  		next_avail += nb_alloc;
  
Levend Sayar Feb. 19, 2023, 8:43 p.m. UTC | #2
> On 19 Feb 2023, at 20:35, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Sun, 19 Feb 2023 03:30:59 +0300
> Levend Sayar <levendsayar@gmail.com <mailto:levendsayar@gmail.com>> wrote:
> 
>> rx no_mbufs stats counter update is added for another error case.
>> 
>> Fixes: 4f6b1dd8240c ("net/gve: support basic statistics")
>> Cc: junfeng.guo@intel.com
>> 
>> Signed-off-by: Levend Sayar <levendsayar@gmail.com>
>> ---
>> drivers/net/gve/gve_rx.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/gve/gve_rx.c b/drivers/net/gve/gve_rx.c
>> index 66fbcf3930..b0427731f8 100644
>> --- a/drivers/net/gve/gve_rx.c
>> +++ b/drivers/net/gve/gve_rx.c
>> @@ -24,6 +24,7 @@ gve_rx_refill(struct gve_rx_queue *rxq)
>> 				nmb = rte_pktmbuf_alloc(rxq->mpool);
>> 				if (!nmb)
>> 					break;
>> +
>> 				rxq->sw_ring[idx + i] = nmb;
>> 			}
>> 			if (i != nb_alloc) {
> 
> Looks like accidental whitespace change included in this patch.

LS: Right. Let me correct.

>> @@ -59,9 +60,13 @@ gve_rx_refill(struct gve_rx_queue *rxq)
>> 				nmb = rte_pktmbuf_alloc(rxq->mpool);
>> 				if (!nmb)
>> 					break;
>> +
>> 				rxq->sw_ring[idx + i] = nmb;
>> 			}
>> -			nb_alloc = i;
>> +			if (i != nb_alloc) {
>> +				rxq->no_mbufs += nb_alloc - i;
>> +				nb_alloc = i;
>> +			}
> 
> Would be better to add unlikely() here like:
> 			if (unlikely(i < nb_alloc)) {
> 				rxq->no_mbufs += nb_alloc - i;
> 				nb_alloc = i;
> 			}
> 
> Or eliminate conditional branch in hot path completely.
> 			rxq->no_mbufs += nb_alloc - i;
> 			nb_alloc = i;
> 
> Or better yet refactor code here to use rte_pktmbuf_alloc_bulk() which
> does single ring operation.
> 
>> 		}
>> 		rxq->nb_avail -= nb_alloc;
>> 		next_avail += nb_alloc;

LS: “unlikely” can be added. You’re right. Code already tries to make a bulk allocation first.
If that bulk allocation does not work, it tries to allocate one my one. 

I will supersede this one and create v2.
Thanks Stephen.

Best,
Levend
  
Stephen Hemminger Feb. 19, 2023, 10:59 p.m. UTC | #3
On Sun, 19 Feb 2023 23:43:08 +0300
Levend Sayar <levendsayar@gmail.com> wrote:

> LS: “unlikely” can be added. You’re right. Code already tries to make a bulk allocation first.
> If that bulk allocation does not work, it tries to allocate one my one.

That seems like a unnecessary step and unlikely to help.
Unless the user abuses driver by giving a very small mbuf pool.
  

Patch

diff --git a/drivers/net/gve/gve_rx.c b/drivers/net/gve/gve_rx.c
index 66fbcf3930..b0427731f8 100644
--- a/drivers/net/gve/gve_rx.c
+++ b/drivers/net/gve/gve_rx.c
@@ -24,6 +24,7 @@  gve_rx_refill(struct gve_rx_queue *rxq)
 				nmb = rte_pktmbuf_alloc(rxq->mpool);
 				if (!nmb)
 					break;
+
 				rxq->sw_ring[idx + i] = nmb;
 			}
 			if (i != nb_alloc) {
@@ -59,9 +60,13 @@  gve_rx_refill(struct gve_rx_queue *rxq)
 				nmb = rte_pktmbuf_alloc(rxq->mpool);
 				if (!nmb)
 					break;
+
 				rxq->sw_ring[idx + i] = nmb;
 			}
-			nb_alloc = i;
+			if (i != nb_alloc) {
+				rxq->no_mbufs += nb_alloc - i;
+				nb_alloc = i;
+			}
 		}
 		rxq->nb_avail -= nb_alloc;
 		next_avail += nb_alloc;