graph: deferred enqueue API for simplified node processing
cover graph: deferred enqueue API for simplified node processing
This series introduces a deferred enqueue API for the graph library that simplifies node development while maintaining performance.
The current node implementations use a manual speculation pattern where each node pre-allocates destination buffer slots, tracks which packets diverge from the speculated edge, and handles fixups at the end. This results in complex boilerplate code with multiple local variables (to_next, from, held, last_spec), memcpy calls, and stream get/put operations repeated across every node.
The new rte_node_enqueue_deferred() API handles this automatically:
- Tracks runs of consecutive packets going to the same edge
- Flushes runs in bulk when the edge changes
- Uses rte_node_next_stream_move() (pointer swap) when all packets go to the same destination
- Preserves last_edge across invocations for cross-batch speculation
The deferred state is stored in the node's fast-path cache line 1, alongside xstat_off, keeping frequently accessed data together.
Performance was measured with l3fwd forwarding between two ports of an Intel E810-XXV 2x25G NIC (1 RX queue per port). Two graph worker threads ran on hyper threads of the same physical core on an Intel Xeon Silver 4316 CPU @ 2.30GHz.
Results:
- Baseline (manual speculation): 37.0 Mpps
- Deferred API: 36.2 Mpps (-2.2%)
The slight overhead comes from per-packet edge comparisons. However, this is offset by:
- 826 fewer lines of code across 13 node implementations
- Reduced instruction cache pressure from simpler code paths
- Elimination of per-node speculation boilerplate
- Easier development of new nodes
Robin Jarry (3):
graph: optimize rte_node_enqueue_next to batch by edge
graph: add deferred enqueue API for batch processing
node: use deferred enqueue API in process functions
app/graph/ip4_output_hook.c | 35 +------- lib/graph/graph_populate.c | 1 + lib/graph/rte_graph_worker_common.h | 90 ++++++++++++++++++- lib/node/interface_tx_feature.c | 105 +++------------------- lib/node/ip4_local.c | 36 +------- lib/node/ip4_lookup.c | 37 +------- lib/node/ip4_lookup_fib.c | 36 +------- lib/node/ip4_lookup_neon.h | 100 ++------------------- lib/node/ip4_lookup_sse.h | 100 ++------------------- lib/node/ip4_rewrite.c | 120 +++---------------------- lib/node/ip6_lookup.c | 95 ++------------------ lib/node/ip6_lookup_fib.c | 34 +------- lib/node/ip6_rewrite.c | 118 +++---------------------- lib/node/pkt_cls.c | 130 +++------------------------- lib/node/udp4_input.c | 42 +-------- 15 files changed, 170 insertions(+), 909 deletions(-)
Signature · 1 line
2.52.0
RFC PATCH 1/3 graph: optimize rte_node_enqueue_next to batch by edge
Replace the per-object rte_node_enqueue_x1() calls with batched rte_node_enqueue() calls. The function now tracks runs of consecutive objects going to the same edge and flushes them in bulk.
When all objects go to the same edge and come from the node's own buffer (objs == node->objs), use rte_node_next_stream_move() which swaps pointers instead of copying.
--- lib/graph/rte_graph_worker_common.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
lib/graph/rte_graph_worker_common.h +13 -2
@@ -432,10 +432,21 @@ static inline void rte_node_enqueue_next(struct rte_graph *graph, struct rte_node *node, rte_edge_t *nexts, void **objs, uint16_t nb_objs) { + rte_edge_t last = nexts[0]; +uint16_t run_start =0 ;uint16_t i; -for (i =0 ; i < nb_objs; i++) -rte_node_enqueue_x1 (graph, node, nexts[i], objs[i]); +for (i =1 ; i < nb_objs; i++) { +if (nexts[i] != last) { +rte_node_enqueue (graph, node, last, &objs[run_start], i - run_start); + run_start = i; + last = nexts[i]; + } + } +if (run_start ==0 && objs == node->objs) +rte_node_next_stream_move (graph, node, last); +else +rte_node_enqueue (graph, node, last, &objs[run_start], nb_objs - run_start); }/**
Signature · 1 line
2.52.0
Re: [EXTERNAL] [RFC PATCH dpdk 1/3] graph: optimize rte_node_enqueue_next to batch by edge
Quoted 19 lines
Replace the per-object
rte_node_enqueue_x1()calls with batchedrte_node_enqueue()calls. The function now tracks runs of consecutive objects going to the same edge and flushes them in bulk.When all objects go to the same edge and come from the node's own buffer (objs ==
node->objs), userte_node_next_stream_move()which swaps pointers instead of copying.Signed-off-by Robin Jarry <[email protected]>---
lib/graph/rte_graph_worker_common.h| 15 +++++++++++++--1 file changed, 13 insertions(+), 2 deletions(-)lib/graph/rte_graph_worker_common.h +0
-0@@ -432,10 +432,21 @@ static inline void rte_node_enqueue_next(struct rte_graph *graph, struct rte_node *node,
lib/graph/rte_graph_worker_common.h static inline void · line 440
Quoted 10 lines
lib/graph/rte_graph_worker_common.h +4
-2rte_edge_t *nexts, void **objs, uint16_t nb_objs) { +rte_edge_t last = nexts[0 ]; +uint16_t run_start =0 ;uint16_t i; -for (i =0 ; i < nb_objs; i++) -rte_node_enqueue_x1 (graph, node, nexts[i], objs[i]); +for (i =1 ; i < nb_objs; i++) { +if (nexts[i] != last) {
We can probably use SIMD here for comparision, 128b would process 8 nexts at a time. But might not be worth it if nexts are too unique.
lib/graph/rte_graph_worker_common.h static inline void · line 452
Quoted 12 lines
lib/graph/rte_graph_worker_common.h +9
-0+rte_node_enqueue (graph, node, last, &objs[run_start], i - run_start); + run_start = i; + last = nexts[i]; + } + } +if (run_start ==0 && objs == node->objs) +rte_node_next_stream_move (graph, node, last); +else +rte_node_enqueue (graph, node, last, &objs[run_start], nb_objs - run_start); }/**
--
2.52.0
RFC PATCH 2/3 graph: add deferred enqueue API for batch processing
In reply to Robin JarryAdd rte_node_enqueue_deferred() which tracks runs of consecutive objects going to the same edge and flushes them efficiently in bulk. When all objects go to the same edge (the common case), the function uses rte_node_next_stream_move() which swaps pointers instead of copying data.
The deferred state (run_start and last_edge) is stored in the node fast-path cache line 1, keeping it close to other frequently accessed node data. The last_edge is preserved across node invocations, allowing speculation: if traffic continues to the same destination, no action is needed until the edge changes.
The flush is performed automatically at the end of node processing by __rte_node_process().
--- lib/graph/graph_populate.c | 1 + lib/graph/rte_graph_worker_common.h | 75 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
lib/graph/graph_populate.c +1 -0
@@ -84,6 +84,7 @@ graph_nodes_populate(struct graph *_graph)struct rte_node *node =RTE_PTR_ADD (graph, off);memset (node,0 ,sizeof (*node)); node->fence =RTE_GRAPH_FENCE ; + node->deferred_last_edge =RTE_EDGE_ID_INVALID ; node->off = off;if (graph_pcap_is_enable ()) { node->process = graph_pcap_dispatch;
lib/graph/rte_graph_worker_common.h +75 -0
111 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [EXTERNAL] [RFC PATCH dpdk 2/3] graph: add deferred enqueue API for batch processing
Quoted 21 lines
Add
rte_node_enqueue_deferred()which tracks runs of consecutive objects going to the same edge and flushes them efficiently in bulk. When all objects go to the same edge (the common case), the function usesrte_node_next_stream_move()which swaps pointers instead of copying data.The deferred state (
run_startandlast_edge) is stored in the node fast-path cache line 1, keeping it close to other frequently accessed node data. Thelast_edgeis preserved across node invocations, allowing speculation: if traffic continues to the same destination, no action is needed until the edge changes.The flush is performed automatically at the end of node processing by
__rte_node_process().Signed-off-by Robin Jarry <[email protected]>---
lib/graph/graph_populate.c| 1 +lib/graph/rte_graph_worker_common.h| 75 +++++++++++++++++++++++++++++2 files changed, 76 insertions(+)
<snip>
Quoted 33 lines
lib/graph/rte_graph_worker_common.h +33
-0+/** +* Enqueue objects to a next node in a cache-efficient deferred manner. +* +* This function tracks runs of objects going to the same edge. When the edge +* changes, the previous run is flushed using bulk enqueue. At the end of node +* processing, any remaining objects are flushed automatically. When all +* objects go to the same edge (the common case), rte_node_next_stream_move() +* is used which swaps pointers instead of copying. +* +* The function does not require consecutive idx values. It can be called with +* any stride (e.g., 0, 4, 8, ... to process batches of 4). All objects from +* the previous idx up to the current one are considered part of the current +* run until the edge changes. +* +* For homogeneous traffic, the destination node structure is touched once +* per batch instead of once per object, reducing cache line bouncing. +* +* @param graph +* Graph pointer returned from rte_graph_lookup(). +* @param node +* Current node pointer. +* @param next +* Next node edge index. +* @param idx +* Index of the current object being processed in node->objs[]. +* +* @see rte_node_next_stream_move(). +*/ +static inline void +rte_node_enqueue_deferred (struct rte_graph *graph,struct rte_node *node, +rte_edge_t next,uint16_t idx) +{ +if (next != node->deferred_last_edge) {
lib/graph/rte_graph_worker_common.h rte_node_next_stream_move(struct rte_graph *graph, struct rte_node *src, · line 604
Quoted 10 lines
lib/graph/rte_graph_worker_common.h +10
-0+/* edge changed, flush previous run if not empty */ +if (idx > node->deferred_run_start) +rte_node_enqueue (graph, node, node->deferred_last_edge, + &node->objs[node->deferred_run_start], + idx - node->deferred_run_start); + node->deferred_run_start = idx; + node->deferred_last_edge = next; + } +} +
Can we add a deferredx4 variant too? It need not have SIMD but would reduce LoC further.
Thanks,
Pavan.
RFC PATCH 3/3 node: use deferred enqueue API in process functions
In reply to Robin JarryConvert all node process functions to use rte_node_enqueue_deferred() instead of the manual speculation pattern with rte_node_enqueue_x1().
The deferred enqueue API automatically batches consecutive packets going to the same edge and flushes them efficiently. When all packets go to the same destination (the common case), it uses rte_node_next_stream_move() which swaps pointers rather than copying.
This significantly simplifies the node process functions by removing the speculation tracking logic (to_next, from, held, last_spec variables, memcpy calls, and stream get/put operations).
The deferred state is stored in the node fast-path cache line, keeping it close to other frequently accessed node data. The last_edge value is preserved across invocations, providing cross-batch speculation for free.
Performance testing with l3fwd on two E810 NICs shows throughput within 2-3% of the baseline while significantly reducing code complexity. The slight overhead comes from per-packet edge comparisons, but this is offset by reduced instruction cache pressure and simpler code paths.
Also remove unused speculation-related macros and fields from node context structures:
- IP4_REWRITE_NODE_LAST_NEXT and next_index field
- IP6_REWRITE_NODE_LAST_NEXT and next_index field
- IF_TX_FEATURE_LAST_NEXT_INDEX and last_index field
- UDP4_INPUT_NODE_NEXT_INDEX and next_index field
--- app/graph/ip4_output_hook.c | 35 +-------- lib/node/interface_tx_feature.c | 105 +++----------------------- lib/node/ip4_local.c | 36 +-------- lib/node/ip4_lookup.c | 37 +-------- lib/node/ip4_lookup_fib.c | 36 +-------- lib/node/ip4_lookup_neon.h | 100 +++--------------------- lib/node/ip4_lookup_sse.h | 100 +++--------------------- lib/node/ip4_rewrite.c | 120 +++-------------------------- lib/node/ip6_lookup.c | 95 +++-------------------- lib/node/ip6_lookup_fib.c | 34 +-------- lib/node/ip6_rewrite.c | 118 +++-------------------------- lib/node/pkt_cls.c | 130 +++----------------------------- lib/node/udp4_input.c | 42 +---------- 13 files changed, 81 insertions(+), 907 deletions(-)
app/graph/ip4_output_hook.c +2 -33
@@ -51,50 +51,19 @@ __app_graph_ip4_output_hook_node_process(struct rte_graph *graph, struct rte_nodstruct rte_graph_feature_arc *arc =rte_graph_feature_arc_get (OUTPUT_HOOK_FEATURE_ARC (node->ctx));struct rte_graph_feature_arc_mbuf_dynfields *mbfields =NULL ; -uint16_t next =OUTPUT_HOOK_PKT_DROP ; -void **to_next, **from; -uint16_t last_spec =0 ; -rte_edge_t next_index;struct rte_mbuf *mbuf; -uint16_t held =0 ; +rte_edge_t next;int i; -/* Speculative next */ - next_index =OUTPUT_HOOK_LAST_NEXT_INDEX (node->ctx); - - from = objs; - to_next =rte_node_next_stream_get (graph, node, next_index, nb_objs);for (i =0 ; i < nb_objs; i++) { - mbuf = (struct rte_mbuf *)objs[i];/* Send mbuf to next enabled feature */ mbfields =rte_graph_feature_arc_mbuf_dynfields_get (mbuf, arc->mbuf_dyn_offset);rte_graph_feature_data_next_feature_get (arc, &mbfields->feature_data, &next); -if (unlikely (next_index != next)) { -/* Copy things successfully speculated till now */ -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); - from += last_spec; - to_next += last_spec; - held += last_spec; - last_spec =0 ; - -rte_node_enqueue_x1 (graph, node, next, from[0 ]); - from +=1 ; - }else { - last_spec +=1 ; - } +rte_node_enqueue_deferred (graph, node, next, i); } -/* !!! Home run !!! */ -if (likely (last_spec == nb_objs)) { -rte_node_next_stream_move (graph, node, next_index); -return nb_objs; - } - held += last_spec; -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); -rte_node_next_stream_put (graph, node, next_index, held); -OUTPUT_HOOK_LAST_NEXT_INDEX (node->ctx) = next;return nb_objs; }
lib/node/interface_tx_feature.c +11 -94
150 lines not on this page · raw message
lib/node/ip4_local.c +3 -33
@@ -24,51 +24,21 @@ static uint16_t ip4_local_node_process_scalar(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t nb_objs) { - void **to_next, **from; -uint16_t last_spec =0 ; -rte_edge_t next_index; struct rte_mbuf *mbuf; -uint16_t held =0 ; +rte_edge_t next;uint32_t l4;int i; -/* Speculative next */ - next_index =RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT ; - - from = objs; - to_next =rte_node_next_stream_get (graph, node, next_index, nb_objs);for (i =0 ; i < nb_objs; i++) { -uint16_t next; - mbuf = (struct rte_mbuf *)objs[i]; l4 = mbuf->packet_type &RTE_PTYPE_L4_MASK ; next = (l4 ==RTE_PTYPE_L4_UDP ) - ? next_index + ?RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT :RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP ; -if (unlikely (next_index != next)) { -/* Copy things successfully speculated till now */ -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); - from += last_spec; - to_next += last_spec; - held += last_spec; - last_spec =0 ; - -rte_node_enqueue_x1 (graph, node, next, from[0 ]); - from +=1 ; - }else { - last_spec +=1 ; - } +rte_node_enqueue_deferred (graph, node, next, i); } -/* !!! Home run !!! */ -if (likely (last_spec == nb_objs)) { -rte_node_next_stream_move (graph, node, next_index); -return nb_objs; - } - held += last_spec; -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); -rte_node_next_stream_put (graph, node, next_index, held);return nb_objs; }
lib/node/ip4_lookup.c +3 -34
@@ -53,25 +53,16 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,struct rte_lpm *lpm =IP4_LOOKUP_NODE_LPM (node->ctx);const int dyn =IP4_LOOKUP_NODE_PRIV1_OFF (node->ctx);struct rte_ipv4_hdr *ipv4_hdr; -void **to_next, **from; -uint16_t last_spec =0 ;struct rte_mbuf *mbuf; -rte_edge_t next_index; -uint16_t held =0 ;uint32_t drop_nh;int i, rc; -/* Speculative next */ - next_index =RTE_NODE_IP4_LOOKUP_NEXT_REWRITE ;/* Drop node */ drop_nh = ((uint32_t )RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP ) <<16 ; - from = objs; -/* Get stream for the speculated next node */ - to_next =rte_node_next_stream_get (graph, node, next_index, nb_objs);for (i =0 ; i < nb_objs; i++) {uint32_t next_hop; -uint16_t next; +rte_edge_t next; mbuf = (struct rte_mbuf *)objs[i];
@@ -88,33 +79,11 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,NODE_INCREMENT_XSTAT_ID (node,0 , rc !=0 ,1 );node_mbuf_priv1 (mbuf, dyn)->nh = (uint16_t )next_hop; - next_hop = next_hop >>16 ; - next = (uint16_t )next_hop; + next = (uint16_t )(next_hop >>16 ); -if (unlikely (next_index != next)) { -/* Copy things successfully speculated till now */ -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); - from += last_spec; - to_next += last_spec; - held += last_spec; - last_spec =0 ; - -rte_node_enqueue_x1 (graph, node, next, from[0 ]); - from +=1 ; - }else { - last_spec +=1 ; - } +rte_node_enqueue_deferred (graph, node, next, i); } -/* !!! Home run !!! */ -if (likely (last_spec == nb_objs)) { -rte_node_next_stream_move (graph, node, next_index); -return nb_objs; - } - held += last_spec; -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); -rte_node_next_stream_put (graph, node, next_index, held); -return nb_objs; }
lib/node/ip4_lookup_fib.c +2 -34
@@ -51,24 +51,13 @@ ip4_lookup_fib_node_process(struct rte_graph *graph, struct rte_node *node, voiduint32_t ip[RTE_GRAPH_BURST_SIZE ];struct rte_ipv4_hdr *ipv4_hdr;uint16_t lookup_err =0 ; -void **to_next, **from; -uint16_t last_spec =0 ; -rte_edge_t next_index;uint16_t n_left_from; -uint16_t held =0 ; -uint16_t next; +rte_edge_t next;int i; -/* Speculative next */ - next_index =RTE_NODE_IP4_LOOKUP_NEXT_REWRITE ; - pkts = (struct rte_mbuf **)objs; - from = objs; n_left_from = nb_objs; -/* Get stream for the speculated next node */ - to_next =rte_node_next_stream_get (graph, node, next_index, nb_objs); -for (i =0 ; i <4 && i < n_left_from; i++) rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[i], void *,sizeof (struct rte_ether_hdr )));
@@ -161,34 +150,13 @@ ip4_lookup_fib_node_process(struct rte_graph *graph, struct rte_node *node, voidnode_mbuf_priv1 (mbuf0, dyn)->nh = (uint16_t )next_hop[i]; next = (uint16_t )(next_hop[i] >>16 ); -if (unlikely (next_index ^ next)) { -/* Copy things successfully speculated till now */ -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); - from += last_spec; - to_next += last_spec; - held += last_spec; - last_spec =0 ; - -rte_node_enqueue_x1 (graph, node, next, from[0 ]); - from +=1 ; - }else { - last_spec +=1 ; - } -if (unlikely (next_hop[i] ==FIB_DEFAULT_NH )) lookup_err +=1 ; - } -/* !!! Home run !!! */ -if (likely (last_spec == nb_objs)) { -rte_node_next_stream_move (graph, node, next_index); -return nb_objs; +rte_node_enqueue_deferred (graph, node, next, i); }NODE_INCREMENT_XSTAT_ID (node,0 , lookup_err !=0 , lookup_err); - held += last_spec; -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); -rte_node_next_stream_put (graph, node, next_index, held);return nb_objs; }
lib/node/ip4_lookup_neon.h +9 -91
138 lines not on this page · raw message
lib/node/ip4_lookup_sse.h +9 -91
138 lines not on this page · raw message
lib/node/ip4_rewrite.c +10 -110
174 lines not on this page · raw message
lib/node/ip6_lookup.c +9 -86
130 lines not on this page · raw message
lib/node/ip6_lookup_fib.c +1 -33
@@ -51,24 +51,13 @@ ip6_lookup_fib_node_process(struct rte_graph *graph, struct rte_node *node, voiduint64_t next_hop[RTE_GRAPH_BURST_SIZE ];struct rte_ipv6_hdr *ipv6_hdr;uint16_t lookup_err =0 ; -void **to_next, **from; -uint16_t last_spec =0 ; -rte_edge_t next_index;uint16_t n_left_from; -uint16_t held =0 ;uint16_t next;int i; -/* Speculative next */ - next_index =RTE_NODE_IP6_LOOKUP_NEXT_REWRITE ; - pkts = (struct rte_mbuf **)objs; - from = objs; n_left_from = nb_objs; -/* Get stream for the speculated next node */ - to_next =rte_node_next_stream_get (graph, node, next_index, nb_objs); -for (i =0 ; i <4 && i < n_left_from; i++) rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[i], void *,sizeof (struct rte_ether_hdr )));
@@ -155,34 +144,13 @@ ip6_lookup_fib_node_process(struct rte_graph *graph, struct rte_node *node, voidnode_mbuf_priv1 (mbuf0, dyn)->nh = (uint16_t )next_hop[i]; next = (uint16_t )(next_hop[i] >>16 ); -if (unlikely (next_index ^ next)) { -/* Copy things successfully speculated till now */ -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); - from += last_spec; - to_next += last_spec; - held += last_spec; - last_spec =0 ; - -rte_node_enqueue_x1 (graph, node, next, from[0 ]); - from +=1 ; - }else { - last_spec +=1 ; - } -if (unlikely (next_hop[i] ==FIB6_DEFAULT_NH )) lookup_err +=1 ; - } -/* !!! Home run !!! */ -if (likely (last_spec == nb_objs)) { -rte_node_next_stream_move (graph, node, next_index); -return nb_objs; +rte_node_enqueue_deferred (graph, node, next, i); }NODE_INCREMENT_XSTAT_ID (node,0 , lookup_err !=0 , lookup_err); - held += last_spec; -rte_memcpy (to_next, from, last_spec *sizeof (from[0 ])); -rte_node_next_stream_put (graph, node, next_index, held);return nb_objs; }
lib/node/ip6_rewrite.c +10 -108
162 lines not on this page · raw message
lib/node/pkt_cls.c +10 -120
160 lines not on this page · raw message
lib/node/udp4_input.c +2 -40
71 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 10 lines
Performance was measured with l3fwd forwarding between two ports of an Intel E810-XXV 2x25G NIC (1 RX queue per port). Two graph worker threads ran on hyper threads of the same physical core on an Intel Xeon Silver 4316 CPU @ 2.30GHz.
Results:
- Baseline (manual speculation): 37.0 Mpps
- Deferred API: 36.2 Mpps (-2.2%)
On Octeon(Neoverse-n2) platform we see a slight performance increase ~1.5%.
Quoted 6 lines
The slight overhead comes from per-packet edge comparisons. However, this is offset by:
- 826 fewer lines of code across 13 node implementations
- Reduced instruction cache pressure from simpler code paths
- Elimination of per-node speculation boilerplate
- Easier development of new nodes
Quoted 41 lines · On Thu, 5 Feb 2026 10:26:32 +0100 Robin Jarry <[email protected]> wrote:
This series introduces a deferred enqueue API for the graph library that simplifies node development while maintaining performance.
The current node implementations use a manual speculation pattern where each node pre-allocates destination buffer slots, tracks which packets diverge from the speculated edge, and handles fixups at the end. This results in complex boilerplate code with multiple local variables (
to_next, from, held,last_spec), memcpy calls, and stream get/put operations repeated across every node.The new
rte_node_enqueue_deferred()API handles this automatically:
- Tracks runs of consecutive packets going to the same edge
- Flushes runs in bulk when the edge changes
- Usesrte_node_next_stream_move()(pointer swap) when all packets go to the same destination
- Preserveslast_edgeacross invocations for cross-batch speculationThe deferred state is stored in the node's fast-path cache line 1, alongside
xstat_off, keeping frequently accessed data together.Performance was measured with l3fwd forwarding between two ports of an Intel E810-XXV 2x25G NIC (1 RX queue per port). Two graph worker threads ran on hyper threads of the same physical core on an Intel Xeon Silver 4316 CPU @ 2.30GHz.
Results:
- Baseline (manual speculation): 37.0 Mpps
- Deferred API: 36.2 Mpps (-2.2%)The slight overhead comes from per-packet edge comparisons. However, this is offset by:
- 826 fewer lines of code across 13 node implementations
- Reduced instruction cache pressure from simpler code paths
- Elimination of per-node speculation boilerplate
- Easier development of new nodesRobin Jarry (3):
graph: optimizerte_node_enqueue_nextto batch by edge
graph: add deferred enqueue API for batch processing
node: use deferred enqueue API in process functions
Quoted 17 lines
app/graph/ip4_output_hook.c | 35 +------- lib/graph/graph_populate.c | 1 + lib/graph/rte_graph_worker_common.h | 90 ++++++++++++++++++- lib/node/interface_tx_feature.c | 105 +++------------------- lib/node/ip4_local.c | 36 +------- lib/node/ip4_lookup.c | 37 +------- lib/node/ip4_lookup_fib.c | 36 +------- lib/node/ip4_lookup_neon.h | 100 ++------------------- lib/node/ip4_lookup_sse.h | 100 ++------------------- lib/node/ip4_rewrite.c | 120 +++---------------------- lib/node/ip6_lookup.c | 95 ++------------------ lib/node/ip6_lookup_fib.c | 34 +------- lib/node/ip6_rewrite.c | 118 +++---------------------- lib/node/pkt_cls.c | 130 +++------------------------- lib/node/udp4_input.c | 42 +-------- 15 files changed, 170 insertions(+), 909 deletions(-)
AI review comments:
Review: [RFC PATCH dpdk 1/3] graph: optimize rte_node_enqueue_next to batch by edge
[RFC PATCH dpdk 2/3] graph: add deferred enqueue API for batch processing [RFC PATCH dpdk 3/3] node: use deferred enqueue API in process functions
This is a well-motivated series. The deferred enqueue API is a clean abstraction that replaces the repetitive speculation boilerplate in every node process function. The code reduction in patch 3 speaks for itself -- roughly 900 lines of hand-rolled speculation logic replaced with single-line rte_node_enqueue_deferred() calls.
Patch 1/3 - rte_node_enqueue_next batching
Error: Out-of-bounds read when nb_objs is 0.
rte_edge_t last = nexts[0];
reads nexts[0] unconditionally. If nb_objs == 0, this is an out-of-bounds access. The old code handled this correctly because the loop for (i = 0; i < nb_objs; i++) would simply not execute. Add a guard:
if (nb_objs == 0)
return;
Patch 2/3 - deferred enqueue API
Error: Flush in __rte_node_process fires for nodes that do not use the deferred API, corrupting their data.
__rte_node_process now unconditionally checks:
if (node->deferred_last_edge != RTE_EDGE_ID_INVALID)
__rte_node_enqueue_deferred_flush(graph, node);deferred_last_edge is initialized to RTE_EDGE_ID_INVALID at graph populate time, but it is preserved across invocations ("Keep deferred_last_edge from previous invocation for speculation"). Once a deferred-API node sets it to a valid value, it will never be reset to RTE_EDGE_ID_INVALID.
This means any node that uses the old manual speculation pattern (rte_node_next_stream_move / stream_get / stream_put directly) will have the flush fire after its process function returns, because deferred_last_edge may be stale from a prior incarnation or from the node's first call. The flush would then attempt rte_node_next_stream_move based on the stale deferred_last_edge and the current node->idx (which may still be non-zero because stream_move does not zero src->idx).
Even though patch 3 converts all in-tree nodes, this is a public API change in __rte_node_process that affects all node implementations including third-party and out-of-tree nodes that are compiled against the DPDK headers. Any node process function that does not use rte_node_enqueue_deferred() will be silently broken.
The fix is to ensure the flush only fires when the deferred API was actually used during this invocation. For example, reset deferred_last_edge to RTE_EDGE_ID_INVALID at the start of __rte_node_process (instead of preserving it), or add a flag that is set when rte_node_enqueue_deferred() is first called:
/* Option A: reset each invocation (loses cross-batch
* speculation but is safe) */
node->deferred_last_edge = RTE_EDGE_ID_INVALID;
/* Option B: add a "deferred_active" flag set by
* rte_node_enqueue_deferred, cleared by flush */
Note that option A sacrifices the cross-batch speculation benefit described in the commit message. Option B preserves speculation but adds a branch and a byte to the cache line. The right choice depends on how much the cross-batch speculation matters in practice -- given the 2-3% overhead already mentioned, the safety of option A may be preferable.
Warning: deferred_run_start and deferred_last_edge add 4 bytes to cache line 1 of struct rte_node.
The commit says "stored in the node fast-path cache line 1, keeping it close to other frequently accessed node data." Since this is an ABI change to a public struct, it should be noted in the release notes. Verify that the addition does not push other hot fields out of the cache line or cross a cache line boundary. The current cache line 1 only had xstat_off before this change, so there is room, but this should be explicitly confirmed.
Warning: __rte_node_enqueue_deferred_flush uses node->idx after the process function has potentially manipulated it.
The flush reads node->idx as "count" to determine how many objects to flush. This relies on the invariant that the process function did NOT modify node->idx. With the deferred API this is true (the process function just calls rte_node_enqueue_deferred which doesn't touch node->idx), but this implicit contract is fragile and undocumented. If any process function uses a mix of deferred and non-deferred enqueue APIs, node->idx may not reflect the original object count. Add a comment or assertion documenting this invariant.
Warning: the new API should be marked __rte_experimental.
rte_node_enqueue_deferred() is a new public inline function in an installed header. Per DPDK policy, new APIs must be marked __rte_experimental.
Patch 3/3 - node conversions
Warning: pkt_cls_node_process loses its cross-invocation l2l3_type speculation state.
The old code saved the last packet type in ctx->l2l3_type and used it as the speculative next index on the following invocation. The new code removes the pkt_cls_node_ctx struct entirely and relies on deferred_last_edge for speculation. This works because deferred_last_edge maps to the next node edge, which is what the old code was ultimately speculating on. However, the old code speculated on the *packet type* (l2l3_type) which was then mapped to the edge -- this two-level speculation could be more precise if different packet types map to the same edge. In practice, this is likely fine since the deferred API speculates on the edge directly, which is what matters for performance. This is noted for completeness.
Info: The conversions are mechanical and consistent across all 13 files. Each follows the same pattern: remove from/to_next/ held/last_spec/next_index variables, remove stream_get/put/ memcpy/enqueue_x1 logic, replace with rte_node_enqueue_deferred(graph, node, next, i). The manual i index tracking is correct in all cases -- the x4 loops increment i by 4, the x1 tail loops by 1, matching the pkts pointer increment in n_left_from.