Skip to contentSkip to conversation

unnecessary rx callbacks when zero packets

PATCH Stephen Hemminger 5 participants 5 messages Jan 7, 2024 – Jan 9, 2024

lore
Share & tools
lore
#0 lore raw

I noticed while looking at packet capture that currently the receive callbacks get called even if there are no packets. This seems unnecessary since if nb_rx is zero, then there are no packets to look at. My one concern is that an application could be using callbacks as some form of scheduling mechanism which would be broken.

The change would be:

lib/ethdev/rte_ethdev.h +1 -1
index 21e3a21903ec..f64bf977c46e 100644
@@ -6077,7 +6077,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
        nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-       {
+       if (nb_rx > 0) {
                void *cb;
 
                /* rte_memory_order_release memory order was used when the
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Sunday, January 7, 2024 11:37 AM
To: [email protected]
Subject: unnecessary rx callbacks when zero packets

Quoted 5 lines

I noticed while looking at packet capture that currently the receive callbacks get called even if there are no packets. This seems unnecessary since if nb_rx is zero, then there are no packets to look at. My one concern is that an application could be using callbacks as some form of scheduling mechanism which would be broken.

Is it possible that the call back functions are maintaining statistics on zero packet polls?

Quoted 18 lines

The change would be:

lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

21e3a21903ec..f64bf977c46e 100644

lib/ethdev/rte_ethdev.h +1 -1
@@ -6077,7 +6077,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t
 queue_id,
        nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-       {
+       if (nb_rx > 0) {
                void *cb;
 
                /* rte_memory_order_release memory order was used when the
#2 lore raw
Quoted 9 lines

From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Sunday, 7 January 2024 21.57

Quoted 4 lines

From: Stephen Hemminger <[email protected]>
Sent: Sunday, January 7, 2024 11:37 AM

I noticed while looking at packet capture that currently the receive

callbacks

Quoted 1 line

get called even if there are no packets. This seems unnecessary since

Quoted 8 lines

if nb_rx is

Quoted 1 line

zero, then there are no packets to look at. My one concern is that

an

Quoted 1 line

application could be using callbacks as some form of scheduling

mechanism

Quoted 1 line

which would be broken.

Is it possible that the call back functions are maintaining statistics on zero packet polls?

I agree with this concern. The primary argument for introducing the callbacks (instead of the application simply calling the same functions at RX and TX time) was to provide instrumentation outside of the application itself. And for instrumentation purposes, zero-packet calls may be relevant.

TX also calls its callback with zero packets. The callbacks treatment should be the same for both RX and TX: Either always call, or only call if non-zero packets.

So: NAK.

Perhaps the packet capture library can be optimized for zero packets instead.

Quoted 20 lines
Quoted 18 lines

The change would be:

lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

21e3a21903ec..f64bf977c46e 100644

lib/ethdev/rte_ethdev.h +1 -1
@@ -6077,7 +6077,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t
 queue_id,
        nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-       {
+       if (nb_rx > 0) {
                void *cb;
 
Quoted 1 line
                /* rte_memory_order_release memory order was used

when the

#3 lore raw
In reply to Stephen Hemminger

rx callbacks when zero packets

Quoted 6 lines

I noticed while looking at packet capture that currently the receive callbacks get called even if there are no packets. This seems unnecessary since if nb_rx is zero, then there are no packets to look at. My one concern is that an application could be using callbacks as some form of scheduling mechanism which would be broken.

As I remember, original idea was to allow callbacks to inject new packets if needed.

Quoted 17 lines

The change would be:

lib/ethdev/rte_ethdev.h +1 -1
index 21e3a21903ec..f64bf977c46e 100644
@@ -6077,7 +6077,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
        nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-       {
+       if (nb_rx > 0) {
                void *cb;
 
                /* rte_memory_order_release memory order was used when the
#4 lore raw
Quoted 11 lines · Konstantin Ananyev

rx callbacks when zero packets

Quoted 6 lines

I noticed while looking at packet capture that currently the receive callbacks get called even if there are no packets. This seems unnecessary since if nb_rx is zero, then there are no packets to look at. My one concern is that an application could be using callbacks as some form of scheduling mechanism which would be broken.

As I remember, original idea was to allow callbacks to inject new packets if needed.

Right, callback function updating 'nb_rx' enables this.

Also Honnappa has a good point that callback can be used to calculate zero packet polls.

These points are not documented and not obvious from the code, @Stephen does it make sense to document that callback function called with zero packet intentionally, in the 'rte_eth_rx_burst()' function comment?

Quoted 17 lines
Quoted 17 lines

The change would be:

lib/ethdev/rte_ethdev.h +1 -1
index 21e3a21903ec..f64bf977c46e 100644
@@ -6077,7 +6077,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
        nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-       {
+       if (nb_rx > 0) {
                void *cb;
 
                /* rte_memory_order_release memory order was used when the