graph: replace circular buffer with priority-based bitmap scheduling
PATCH 1/1 graph: replace circular buffer with priority-based bitmap scheduling
Replace the FIFO circular buffer used to track pending nodes with a bitmap and a priority-sorted schedule table. Each node can now have a scheduling priority (int16_t, default 0, lower value means visited first). Source nodes are forced to INT16_MIN so they always run first.
At graph creation time, nodes are sorted by (priority, id) and assigned a bit position (sched_idx). During the walk, a bitmap tracks which nodes have pending objects. Scanning from the lowest bit naturally visits nodes in priority order.
This improves batching in fan-out-then-converge topologies. When eth_input classifies packets to both mpls_input and ipv4_input, the old FIFO order could process ipv4_input before mpls_input, causing ipv4_input to be visited twice (once before and once after the MPLS label is popped). With mpls_input at a higher priority (lower value), it runs first and its output accumulates in ipv4_input which is then visited only once with all packets.
The bitmap set operation is idempotent (OR on an already-set bit is a no-op) which removes the need for the idx == 0 guards that the circular buffer required to avoid duplicate enqueue.
--- doc/guides/prog_guide/graph_lib.rst | 37 +- .../prog_guide/img/graph_mem_layout.svg | 1823 +++++++---------- lib/graph/graph.c | 19 +- lib/graph/graph_debug.c | 12 +- lib/graph/graph_populate.c | 117 +- lib/graph/graph_private.h | 27 +- lib/graph/node.c | 2 + lib/graph/rte_graph.h | 1 + lib/graph/rte_graph_model_mcore_dispatch.h | 34 +- lib/graph/rte_graph_model_rtc.h | 65 +- lib/graph/rte_graph_worker.h | 2 +- lib/graph/rte_graph_worker_common.h | 81 +- 12 files changed, 984 insertions(+), 1236 deletions(-)
doc/guides/prog_guide/graph_lib.rst +30 -7
@@ -117,13 +117,22 @@ next_node[]: The dynamic array to store the downstream nodes connected to this node. Downstream node should not be current node itself or a source node. +priority: +^^^^^^^^^ + +The scheduling priority of the node (``int16_t``, default 0). Nodes with lower +priority values are visited first during the graph walk. This allows control +over the order in which pending nodes are processed, which can improve packet +batching in topologies where multiple paths converge on the same node. + Source node: ^^^^^^^^^^^^ Source nodes are static nodes created using ``RTE_NODE_REGISTER`` by passing ``flags`` as ``RTE_NODE_SOURCE_F``. -While performing the graph walk, the ``process()`` function of all the source -nodes will be called first. So that these nodes can be used as input nodes for a graph. +Source nodes are automatically assigned the lowest possible priority +(``INT16_MIN``) so that their ``process()`` function is always called first +during the graph walk. This ensures they act as input nodes for a graph. nb_xstats: ^^^^^^^^^^
@@ -396,12 +405,26 @@ Graph object memory layout Understanding the memory layout helps to debug the graph library and improve the performance if needed. -Graph object consists of a header, circular buffer to store the pending stream -when walking over the graph, variable-length memory to store the ``rte_node`` objects, -and variable-length memory to store the xstat reported by each ``rte_node``. +A graph object consists of a header, a scheduling table mapping bit positions to +node offsets, pending and source bitmaps for tracking which nodes need +processing, variable-length memory to store the ``rte_node`` objects, and +variable-length memory to store the xstat reported by each ``rte_node``. -The graph_nodes_mem_create() creates and populate this memory. The functions -such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory +Nodes are sorted by ``(priority, node_id)`` at graph creation time and each +node is assigned a bit position in the pending bitmap. During the graph walk, +the bitmap is scanned from the lowest bit, so nodes with lower priority values +are visited first. Source nodes are always assigned the lowest priority +(``INT16_MIN``) to ensure they run before any processing node. + +This priority-based ordering improves batching in fan-out-then-converge +topologies. For example, if ``eth_input`` classifies packets to both +``mpls_input`` and ``ipv4_input``, giving ``mpls_input`` a lower priority value +ensures it runs first. Its output accumulates in ``ipv4_input`` which is then +visited only once with all packets, instead of being visited twice (before and +after MPLS label popping). + +The ``graph_fp_mem_create()`` function creates and populates this memory. The +functions such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory to enable fastpath services. Graph feature arc
doc/guides/prog_guide/img/graph_mem_layout.svg +710 -1113
1,848 lines not on this page · raw message
lib/graph/graph.c +2 -17
@@ -334,20 +334,6 @@ graph_mem_fixup_secondary(struct rte_graph *graph)return graph_mem_fixup_node_ctx (graph); } -static bool -graph_src_node_avail (struct graph *graph) -{ -struct graph_node *graph_node; - - STAILQ_FOREACH(graph_node, &graph->node_list, next) -if ((graph_node->node->flags &RTE_NODE_SOURCE_F ) && - (graph_node->node->lcore_id ==RTE_MAX_LCORE || - graph->lcore_id == graph_node->node->lcore_id)) -return true; - -return false; -} -RTE_EXPORT_SYMBOL (rte_graph_model_mcore_dispatch_core_bind) intrte_graph_model_mcore_dispatch_core_bind (rte_graph_t id,int lcore)
@@ -375,9 +361,8 @@ rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore) graph->graph->dispatch.lcore_id = graph->lcore_id; graph->socket =rte_lcore_to_socket_id (lcore); -/* check the availability of source node */ -if (!graph_src_node_avail (graph)) - graph->graph->head =0 ; +/* Rebuild source bitmap with only source nodes bound to this lcore */ +graph_src_bitmap_rebuild (graph);return 0 ;
lib/graph/graph_debug.c +6 -6
@@ -15,8 +15,8 @@ graph_dump(FILE *f, struct graph *g)fprintf (f,"graph <%s>\n" , g->name);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," cir_start=%" PRIu32"\n" , g->cir_start); -fprintf (f," cir_mask=%" PRIu32"\n" , g->cir_mask); +fprintf (f," sched_table_off=%" PRIu32"\n" , g->sched_table_off); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," addr=%p\n" , g);fprintf (f," graph=%p\n" , g->graph);fprintf (f," mem_sz=%zu\n" , g->mem_sz);
@@ -63,14 +63,14 @@ rte_graph_obj_dump(FILE *f, struct rte_graph *g, bool all)fprintf (f,"graph <%s> @ %p\n" , g->name, g);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," head=%" PRId32"\n" , (int32_t )g->head); -fprintf (f," tail=%" PRId32"\n" , (int32_t )g->tail); -fprintf (f," cir_mask=0x%" PRIx32"\n" , g->cir_mask);fprintf (f," nb_nodes=%" PRId32"\n" , g->nb_nodes); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," socket=%d\n" , g->socket);fprintf (f," fence=0x%" PRIx64"\n" , g->fence);fprintf (f," nodes_start=0x%" PRIx32"\n" , g->nodes_start); -fprintf (f," cir_start=%p\n" , g->cir_start); +fprintf (f," sched_table=%p\n" , g->sched_table); +fprintf (f," pending=%p\n" , g->pending); +fprintf (f," src_pending=%p\n" , g->src_pending); rte_graph_foreach_node(count, off, g, n) {if (!all && n->idx ==0 )
lib/graph/graph_populate.c +96 -21
200 lines not on this page · raw message
lib/graph/graph_private.h +21 -6
@@ -49,6 +49,7 @@ struct node {STAILQ_ENTRY (node) next;/**< Next node in the list. */ char name[RTE_NODE_NAMESIZE ];/**< Name of the node. */ uint64_t flags;/**< Node configuration flag. */ +int16_t priority;/**< Scheduling priority. */ unsigned int lcore_id;/**< Node runs on the Lcore ID used for mcore dispatch model. */ rte_node_process_t process;/**< Node process function. */
@@ -98,19 +99,23 @@ struct graph {const struct rte_memzone *mz;/**< Memzone to store graph data. */ rte_graph_off_t nodes_start; -/**< Node memory start offset in graph reel. */ +/**< Node memory start offset in graph memory. */ rte_graph_off_t xstats_start; -/**< Node xstats memory start offset in graph reel. */ +/**< Node xstats memory start offset in graph memory. */ rte_node_t src_node_count;/**< Number of source nodes in a graph. */ struct rte_graph *graph;/**< Pointer to graph data. */ rte_node_t node_count;/**< Total number of nodes. */ -uint32_t cir_start; -/**< Circular buffer start offset in graph reel. */ -uint32_t cir_mask; -/**< Circular buffer mask for wrap around. */ +uint32_t sched_table_off; +/**< Schedule table start offset in graph memory. */ +uint32_t pending_off; +/**< Pending bitmap start offset in graph memory. */ +uint32_t src_pending_off; +/**< Source pending bitmap start offset in graph memory. */ +uint16_t nb_sched_words; +/**< Number of uint64_t words in pending bitmaps. */ rte_graph_t id;/**< Graph identifier. */ rte_graph_t parent_id;
@@ -378,6 +383,16 @@ int graph_fp_mem_create(struct graph *graph);*/ int graph_fp_mem_destroy (struct graph *graph); +/** +* @internal +* +* Rebuild the source pending bitmap based on lcore affinity. +* +* @param graph +* Pointer to the internal graph object. +*/ +void graph_src_bitmap_rebuild (struct graph *graph); +/* Lookup functions */ /** * @internal
lib/graph/node.c +2 -0
@@ -153,6 +153,7 @@ __rte_node_register(const struct rte_node_register *reg)if (rte_strscpy (node->name, reg->name,RTE_NODE_NAMESIZE ) <0 ) goto free_xstat; node->flags = reg->flags; + node->priority = reg->priority; node->process = reg->process; node->init = reg->init; node->fini = reg->fini;
@@ -216,6 +217,7 @@ node_clone(struct node *node, const char *name)/* Clone the source node */ reg->flags = node->flags; + reg->priority = node->priority; reg->process = node->process; reg->init = node->init; reg->fini = node->fini;
lib/graph/rte_graph.h +1 -0
@@ -496,6 +496,7 @@ struct rte_node_register {char name[RTE_NODE_NAMESIZE ];/**< Name of the node. */ uint64_t flags;/**< Node configuration flag. */ #define RTE_NODE_SOURCE_F (1ULL << 0)/**< Node type is source. */ +int16_t priority;/**< Scheduling priority (lower = visited first, default 0). */ rte_node_process_t process;/**< Node process function. */ rte_node_init_t init;/**< Node init function. */ rte_node_fini_t fini;/**< Node fini function. */
lib/graph/rte_graph_model_mcore_dispatch.h +21 -13
@@ -77,9 +77,13 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id);/** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * +* Nodes are visited in scheduling order (lowest priority value first). +* Source nodes are seeded into the pending bitmap at the start of each walk. +* Nodes with different lcore affinity are dispatched to their target lcore. +* * @param graph * Graph pointer returned from rte_graph_lookup function. *
@@ -88,20 +92,28 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,static inline void rte_graph_walk_mcore_dispatch (struct rte_graph *graph) { -const rte_graph_off_t *cir_start = graph->cir_start; -const rte_node_t mask = graph->cir_mask; -uint32_t head = graph->head; +const uint16_t nwords = graph->nb_sched_words;struct rte_node *node; +uint16_t word, bit;if (graph->dispatch.wq !=NULL )__rte_graph_mcore_dispatch_sched_wq_process (graph); -while (likely (head != graph->tail)) { - node = (struct rte_node *)RTE_PTR_ADD (graph, cir_start[(int32_t )head++]); +/* Seed pending bitmap with source nodes bound to this lcore */ +for (word =0 ; word < nwords; word++) + graph->pending[word] |= graph->src_pending[word]; -/* skip the src nodes which not bind with current worker */ -if ((int32_t )head <1 && node->dispatch.lcore_id != graph->dispatch.lcore_id) -continue ; +for (;;) { +/* find first word with any pending bit */ +for (word =0 ; word < nwords; word++) +if (graph->pending[word]) +break ; +if (word == nwords) +break ;/* no more pending nodes */ + + bit =rte_ctz64 (graph->pending[word]); + graph->pending[word] &= ~(1ULL << bit); + node =__rte_graph_pending_node (graph, word, bit);/* Schedule the node until all task/objs are done */ if (node->dispatch.lcore_id != RTE_MAX_LCORE &&
@@ -111,11 +123,7 @@ rte_graph_walk_mcore_dispatch(struct rte_graph *graph)continue ;__rte_node_process (graph, node); - - head =likely ((int32_t )head >0 ) ? head & mask : head; } - - graph->tail =0 ; }#ifdef __cplusplus
lib/graph/rte_graph_model_rtc.h +45 -20
84 lines not on this page · raw message
lib/graph/rte_graph_worker.h +1 -1
@@ -14,7 +14,7 @@ extern "C" {#endif /** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * * @param graph
lib/graph/rte_graph_worker_common.h +49 -32
185 lines not on this page · raw message
Signature · 1 line
2.54.0
Quoted 37 lines
-----Original Message-----
From: Robin Jarry <[email protected]>
Sent: Tuesday, May 19, 2026 3:43 PM
To: [email protected]; Jerin Jacob <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Nithin Kumar Dabilpuram <[email protected]>; Zhirun Yan <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>; Christophe Fontaine <[email protected]>; David Marchand <[email protected]>; Konstantin Ananyev <[email protected]>; Maxime Leroy <[email protected]>
Subject: [EXTERNAL] [PATCH dpdk] graph: replace circular buffer with priority- based bitmap schedulingReplace the FIFO circular buffer used to track pending nodes with a bitmap and a priority-sorted schedule table. Each node can now have a scheduling priority (
int16_t, default 0, lower value means visited first). Source nodes are forced toINT16_MINQuoted 1 line
Replace the FIFO circular buffer used to track pending nodes with
a bitmap and a priority-sorted schedule table. Each node can now have a scheduling priority (
int16_t, default 0, lower value means visited first). Source nodes are forced toINT16_MINso they always run first.At graph creation time, nodes are sorted by (priority, id) and assigned a bit position (
sched_idx). During the walk, a bitmap tracks which nodes have pending objects. Scanning from the lowest bit naturally visits nodes in priority order.This improves batching in fan-out-then-converge topologies. When
eth_inputclassifies packets to bothmpls_inputandipv4_input, the old FIFO order could processipv4_inputbeforempls_input, causingipv4_inputto be visited twice (once before and once after the MPLS label is popped). Withmpls_inputat a higher priority (lower value), it runs first and its output accumulates inipv4_inputwhich is then visited only once with all packets.
Quoted 3 lines
The bitmap set operation is idempotent (OR on an already-set bit is a no-op) which removes the need for the idx == 0 guards that the circular buffer required to avoid duplicate enqueue.
Some high-level comments:
1)What will be the performance overhead for graph walk. Try app/test/test_graph_perf.c and l3fwd_graph 2)If priorities are same, Does it have similar performance with existing code?
3)Does it have any effect on packet ordering on egress.i.e for a given flow ingress order != egress order
If there is performance regression we may need to consider new RTE_GRAPH_MODEL_XXXXX to enable this feature
Hi Jerin,
Jerin Jacob, May 19, 2026 at 12:25:
Quoted 4 lines
Some high-level comments:
1)What will be the performance overhead for graph walk. Try
app/test/test_graph_perf.candl3fwd_graph
I have made some measurements. There was a regression caused by systematic access to a cache line. This will be fixed in v2.
Quoted 2 lines
2)If priorities are same, Does it have similar performance with
existing code?
Yes with v2. I have added a topo order as a fallback when all priorities are equal so that it behaves as previously.
Quoted 2 lines
3)Does it have any effect on packet ordering on egress.i.e for a given
flow ingress order != egress order
Some independent flows "may" be reordered but that depends on the topology, not the graph walk algorithm.
For example, the following graph:
+--------+
| eth_in |
+--------+
/ \
v v
+-------+ +---------+
| ip_in | <-- | mpls_in |
+-------+ +---------+
|
| ,------------.
v v |
+--------+ +----------+
| ip_out | --> | ipip_out |
+--------+ +----------+
|
v
+---------+
| eth_out |
+---------+If you receive the following stream of packets in "eth_in":
1. Eth/IP
2. Eth/IP
3. Eth/MPLS/IP
4. Eth/MPLS/IP
5. Eth/MPLS/IP
6. Eth/IP (needs IPIP encap)
7. Eth/IP (needs IPIP encap)
8. Eth/IP
The "eth_out" node will see:
1. Eth/IP
2. Eth/IP
3. Eth/IP
4. Eth/IP
5. Eth/IP
* 8. Eth/IP <----------- reordered before 6 and 7
6. Eth/IP/IP
7. Eth/IP/IP
With the FIFO circular buffer and with the new bitmap priority scheduler.
The only difference with the bitmap system is that If you set "mpls_in" and "ip_out" higher priorities, the "ip_in" and "eth_out" nodes will be visited only once.
Quoted 2 lines
If there is performance regression we may need to consider new
RTE_GRAPH_MODEL_XXXXXto enable this feature
Signature · 1 line
Robin
Quoted 1 line
Times approximate.
Quoted 11 lines · Robin Jarry
Hi Jerin,
Jerin Jacob, May 19, 2026 at 12:25:
Quoted 4 lines
Some high-level comments:
1)What will be the performance overhead for graph walk. Try
app/test/test_graph_perf.candl3fwd_graphI have made some measurements. There was a regression caused by systematic access to a cache line. This will be fixed in v2.
Thanks. We will review the v2.
Quoted 71 lines
Quoted 2 lines
2)If priorities are same, Does it have similar performance with
existing code?Yes with v2. I have added a topo order as a fallback when all priorities are equal so that it behaves as previously.
Quoted 2 lines
3)Does it have any effect on packet ordering on egress.i.e for a given
flow ingress order != egress orderSome independent flows "may" be reordered but that depends on the topology, not the graph walk algorithm.
For example, the following graph:
+--------+ | eth_in | +--------+ / \ v v +-------+ +---------+ | ip_in | <-- | mpls_in | +-------+ +---------+ | | ,------------. v v | +--------+ +----------+ | ip_out | --> | ipip_out | +--------+ +----------+ | v +---------+ | eth_out | +---------+If you receive the following stream of packets in "
eth_in":1. Eth/IP
2. Eth/IP
3. Eth/MPLS/IP
4. Eth/MPLS/IP
5. Eth/MPLS/IP
6. Eth/IP (needs IPIP encap)
7. Eth/IP (needs IPIP encap)
8. Eth/IPThe "
eth_out" node will see:1. Eth/IP
2. Eth/IP
3. Eth/IP
4. Eth/IP
5. Eth/IP
* 8. Eth/IP <----------- reordered before 6 and 7
6. Eth/IP/IP
7. Eth/IP/IPWith the FIFO circular buffer and with the new bitmap priority scheduler.
The only difference with the bitmap system is that If you set "
mpls_in" and "ip_out" higher priorities, the "ip_in" and "eth_out" nodes will be visited only once.Quoted 2 lines
If there is performance regression we may need to consider new
RTE_GRAPH_MODEL_XXXXXto enable this feature--
RobinQuoted 1 line
Times approximate.
v2 cover graph: priority-based bitmap scheduling
In reply to Robin JarryReplace the FIFO circular buffer in rte_graph with a bitmap and a priority-sorted schedule table. Nodes with lower priority values are visited first during the graph walk. Source nodes are forced to INT16_MIN. Topological depth from BFS ensures upstream-before-downstream ordering when all priorities are equal.
In fan-out-then-converge topologies, setting a higher priority (lower value) on branch nodes avoids redundant visits to the converge node. The diamond perf test shows a ~10% throughput improvement (converge visited once at 256 objs/call instead of twice at 128).
Changes v1 -> v2:
- added diamond perf test into separate preparatory patch
- added topological depth (topo_order) as secondary sort key to preserve FIFO-like upstream-before-downstream ordering for default priorities, preventing a regression in the reverse tree test
- restored idx == 0 guard on bitmap set in the enqueue path to avoid a ~15% throughput regression caused by touching the pending bitmap cache line on every enqueue call
- use hiprio worker nodes in diamond test to demonstrate the actual priority-based scheduling benefit
- added performance numbers measured before and after
Robin Jarry (2):
graph: add diamond topology performance test
graph: replace circular buffer with priority-based bitmap
app/test/test_graph_perf.c | 140 +- doc/guides/prog_guide/graph_lib.rst | 37 +- .../prog_guide/img/graph_mem_layout.svg | 1823 +++++++---------- lib/graph/graph.c | 27 +- lib/graph/graph_debug.c | 12 +- lib/graph/graph_ops.c | 46 + lib/graph/graph_populate.c | 119 +- lib/graph/graph_private.h | 42 +- lib/graph/node.c | 2 + lib/graph/rte_graph.h | 1 + lib/graph/rte_graph_model_mcore_dispatch.h | 34 +- lib/graph/rte_graph_model_rtc.h | 65 +- lib/graph/rte_graph_worker.h | 2 +- lib/graph/rte_graph_worker_common.h | 79 +- 14 files changed, 1194 insertions(+), 1235 deletions(-)
Signature · 1 line
2.54.0
PATCH v2 1/2 graph: add diamond topology performance test
Add a fan-out-then-converge test case to graph_perf_autotest. The fan_out node sends 50% of objects to a converge node (edge 0) and 50% to a branch node (edge 1). The branch node forwards everything to the same converge node.
Because converge is edge 0, a FIFO scheduler visits it before the branch has run, causing two visits at 128 objs/call each. This topology is used in a follow-up patch to demonstrate the benefit of priority-based scheduling.
--- app/test/test_graph_perf.c | 130 ++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-)
app/test/test_graph_perf.c +129 -1
@@ -263,7 +263,7 @@ graph_perf_teardown(void) }static inline rte_node_t -graph_node_get (const char *pname,char *nname) +graph_node_get (const char *pname,const char *nname) {rte_node_t pnode_id =rte_node_from_name (pname);char lookup_name[RTE_NODE_NAMESIZE ];
@@ -1042,6 +1042,132 @@ graph_init_parallel_tree(void)* snk_map[][2] = { {50, 50}, {50, 50}, {0, 0}, {0, 0} } */ +/* Graph Topology: fan-out-then-converge (diamond) +* +* src --> fan_out --(50%)-------------------+-> converge --(100%)--> sink +* `-(50%)--> branch -(100%)-' +* +* The fan_out node enqueues to converge (edge 0) before branch (edge 1). +* With a FIFO scheduler, converge is visited first with only 50% of the +* objects, then branch runs and re-enqueues to converge for a second visit. +* With priority-based bitmap scheduling, branch (priority -1) runs before +* converge (priority 0), so converge accumulates all objects and is visited +* only once. +*/ +static inline int +graph_init_diamond (void ) +{ +rte_node_t fan_out, branch, converge, src, snk; +struct test_graph_perf *graph_data; +struct rte_graph_param gconf = {0 }; +struct test_node_data *node_data; +const struct rte_memzone *mz; +const char *edge_names[2 ]; +char *node_patterns[5 ]; +rte_graph_t graph_id; + + mz =rte_memzone_reserve (TEST_GRAPH_PERF_MZ , +sizeof (struct test_graph_perf ),0 ,0 ); +if (mz ==NULL ) { +printf ("Failed to allocate graph common memory\n" ); +return -ENOMEM ; + } + graph_data = mz->addr; + graph_data->nb_nodes =5 ; + graph_data->node_data =calloc (5 ,sizeof (struct test_node_data )); +if (graph_data->node_data ==NULL ) + goto memzone_free; + +/* Clone all nodes */ + src =graph_node_get (TEST_GRAPH_SRC_NAME ,"0" ); + fan_out =graph_node_get (TEST_GRAPH_WRK_NAME ,"fan" ); +/* converge must be edge 0 from fan_out so FIFO visits it first */ + converge =graph_node_get (TEST_GRAPH_WRK_NAME ,"conv" ); + branch =graph_node_get (TEST_GRAPH_WRK_NAME ,"br" ); + snk =graph_node_get (TEST_GRAPH_SNK_NAME ,"0" ); + +if (src ==RTE_NODE_ID_INVALID || fan_out ==RTE_NODE_ID_INVALID || + converge ==RTE_NODE_ID_INVALID || branch ==RTE_NODE_ID_INVALID || + snk ==RTE_NODE_ID_INVALID ) { +printf ("Failed to create nodes\n" ); + goto data_free; + } + +/* src -> fan_out (100%) */ + edge_names[0 ] =rte_node_id_to_name (fan_out); +rte_node_edge_update (src,0 , edge_names,1 ); + node_data = &graph_data->node_data[0 ]; + node_data->node_id = src; + node_data->is_sink = false; + node_data->next_nodes[0 ] = fan_out; + node_data->next_percentage[0 ] =100 ; + +/* fan_out: edge 0 -> converge (50%), edge 1 -> branch (50%) */ + edge_names[0 ] =rte_node_id_to_name (converge); + edge_names[1 ] =rte_node_id_to_name (branch); +rte_node_edge_update (fan_out,0 , edge_names,2 ); + node_data = &graph_data->node_data[1 ]; + node_data->node_id = fan_out; + node_data->is_sink = false; + node_data->next_nodes[0 ] = converge; + node_data->next_percentage[0 ] =50 ; + node_data->next_nodes[1 ] = branch; + node_data->next_percentage[1 ] =50 ; + +/* branch -> converge (100%) */ + edge_names[0 ] =rte_node_id_to_name (converge); +rte_node_edge_update (branch,0 , edge_names,1 ); + node_data = &graph_data->node_data[2 ]; + node_data->node_id = branch; + node_data->is_sink = false; + node_data->next_nodes[0 ] = converge; + node_data->next_percentage[0 ] =100 ; + +/* converge -> sink (100%) */ + edge_names[0 ] =rte_node_id_to_name (snk); +rte_node_edge_update (converge,0 , edge_names,1 ); + node_data = &graph_data->node_data[3 ]; + node_data->node_id = converge; + node_data->is_sink = false; + node_data->next_nodes[0 ] = snk; + node_data->next_percentage[0 ] =100 ; + +/* sink */ + node_data = &graph_data->node_data[4 ]; + node_data->node_id = snk; + node_data->is_sink = true; + + node_patterns[0 ] =rte_node_id_to_name (src); + node_patterns[1 ] =rte_node_id_to_name (fan_out); + node_patterns[2 ] =rte_node_id_to_name (converge); + node_patterns[3 ] =rte_node_id_to_name (branch); + node_patterns[4 ] =rte_node_id_to_name (snk); + + gconf.socket_id =SOCKET_ID_ANY ; + gconf.nb_node_patterns =5 ; + gconf.node_patterns = (const char **)(uintptr_t )node_patterns; + + graph_id =rte_graph_create ("graph_diamond" , &gconf); +if (graph_id ==RTE_GRAPH_ID_INVALID ) { +printf ("Graph creation failed with error = %d\n" , rte_errno); + goto data_free; + } + graph_data->graph_id = graph_id; +return 0 ; + +data_free: +free (graph_data->node_data); +memzone_free: +rte_memzone_free (mz); +return -ENOMEM ; +} + +static inline int +graph_diamond_1src_1snk (void ) +{ +return measure_perf (); +} +static struct unit_test_suite graph_perf_testsuite = { .suite_name ="Graph library performance test suite" , .setup = graph_perf_setup,
@@ -1061,6 +1187,8 @@ static struct unit_test_suite graph_perf_testsuite = { graph_reverse_tree_3s_4n_1src_1snk),TEST_CASE_ST (graph_init_parallel_tree ,graph_fini ,graph_parallel_tree_5s_4n_4src_4snk ), +TEST_CASE_ST (graph_init_diamond ,graph_fini , +graph_diamond_1src_1snk ), TEST_CASES_END(), /**< NULL terminate unit test array */ }, };
Signature · 1 line
2.54.0
PATCH v2 2/2 graph: replace circular buffer with priority-based bitmap
In reply to Robin JarryReplace the FIFO circular buffer used to track pending nodes with a bitmap and a priority-sorted schedule table. Each node can have a scheduling priority (int16_t, default 0, lower value means visited first). Source nodes are forced to INT16_MIN so they always run first.
At graph creation time, nodes are sorted by (priority, topo_order, node_id) and assigned a bit position (sched_idx). The topological depth is computed via BFS from source nodes so that upstream nodes naturally come before downstream ones, matching the old FIFO behavior when all priorities are equal.
This enables reduced node visits in fan-out-then-converge topologies. In the diamond perf test, the branch node has priority -1 so it runs before the converge node. With the old circular buffer, the converge node is visited twice at 128 objs/call (~970M objs/sec). With bitmap scheduling, it is visited once at 256 objs/call (~1064M objs/sec), a ~10% throughput improvement.
perf stat on a server CPU shows ~7% more instructions executed but ~7% higher IPC (1.32 vs 1.23), 16% fewer L1 cache misses, and 8% fewer branch mispredictions. The bitmap (16 bytes for <64 nodes) is more cache-friendly than the circular buffer (256+ bytes). Net cycle count and elapsed time are neutral.
Existing linear and tree topologies show no measurable regression.
Update documentation and memory layout diagrams to reflect the new bitmap and scheduling table system.
--- app/test/test_graph_perf.c | 12 +- doc/guides/prog_guide/graph_lib.rst | 37 +- .../prog_guide/img/graph_mem_layout.svg | 1823 +++++++---------- lib/graph/graph.c | 27 +- lib/graph/graph_debug.c | 12 +- lib/graph/graph_ops.c | 46 + lib/graph/graph_populate.c | 119 +- lib/graph/graph_private.h | 42 +- lib/graph/node.c | 2 + lib/graph/rte_graph.h | 1 + lib/graph/rte_graph_model_mcore_dispatch.h | 34 +- lib/graph/rte_graph_model_rtc.h | 65 +- lib/graph/rte_graph_worker.h | 2 +- lib/graph/rte_graph_worker_common.h | 79 +- 14 files changed, 1066 insertions(+), 1235 deletions(-)
app/test/test_graph_perf.c +11 -1
@@ -32,6 +32,7 @@ test_graph_perf_func(void)#define TEST_GRAPH_SRC_NAME "test_graph_perf_source"#define TEST_GRAPH_SRC_BRST_ONE_NAME "test_graph_perf_source_one"#define TEST_GRAPH_WRK_NAME "test_graph_perf_worker" +#define TEST_GRAPH_WRK_HIPRIO_NAME "test_graph_perf_worker_hiprio"#define TEST_GRAPH_SNK_NAME "test_graph_perf_sink"#define SOURCES (map) RTE_DIM(map)
@@ -225,6 +226,15 @@ static struct rte_node_register test_graph_perf_worker = {RTE_NODE_REGISTER (test_graph_perf_worker); +static struct rte_node_register test_graph_perf_worker_hiprio = { + .name =TEST_GRAPH_WRK_HIPRIO_NAME , + .process = test_perf_node_worker, + .init = test_node_ctx_init, + .priority =-1 , +}; + +RTE_NODE_REGISTER (test_graph_perf_worker_hiprio); +/* Last node in graph a.k.a sink node */ static uint16_t test_perf_node_sink(struct rte_graph *graph, struct rte_node *node, void **objs,
@@ -1083,7 +1093,7 @@ graph_init_diamond(void) fan_out =graph_node_get (TEST_GRAPH_WRK_NAME ,"fan" );/* converge must be edge 0 from fan_out so FIFO visits it first */ converge =graph_node_get (TEST_GRAPH_WRK_NAME ,"conv" ); - branch =graph_node_get (TEST_GRAPH_WRK_NAME ,"br" ); + branch =graph_node_get (TEST_GRAPH_WRK_HIPRIO_NAME ,"br" ); snk =graph_node_get (TEST_GRAPH_SNK_NAME ,"0" ); if (src == RTE_NODE_ID_INVALID || fan_out == RTE_NODE_ID_INVALID ||
doc/guides/prog_guide/graph_lib.rst +30 -7
@@ -117,13 +117,22 @@ next_node[]: The dynamic array to store the downstream nodes connected to this node. Downstream node should not be current node itself or a source node. +priority: +^^^^^^^^^ + +The scheduling priority of the node (``int16_t``, default 0). Nodes with lower +priority values are visited first during the graph walk. This allows control +over the order in which pending nodes are processed, which can improve packet +batching in topologies where multiple paths converge on the same node. + Source node: ^^^^^^^^^^^^ Source nodes are static nodes created using ``RTE_NODE_REGISTER`` by passing ``flags`` as ``RTE_NODE_SOURCE_F``. -While performing the graph walk, the ``process()`` function of all the source -nodes will be called first. So that these nodes can be used as input nodes for a graph. +Source nodes are automatically assigned the lowest possible priority +(``INT16_MIN``) so that their ``process()`` function is always called first +during the graph walk. This ensures they act as input nodes for a graph. nb_xstats: ^^^^^^^^^^
@@ -396,12 +405,26 @@ Graph object memory layout Understanding the memory layout helps to debug the graph library and improve the performance if needed. -Graph object consists of a header, circular buffer to store the pending stream -when walking over the graph, variable-length memory to store the ``rte_node`` objects, -and variable-length memory to store the xstat reported by each ``rte_node``. +A graph object consists of a header, a scheduling table mapping bit positions to +node offsets, pending and source bitmaps for tracking which nodes need +processing, variable-length memory to store the ``rte_node`` objects, and +variable-length memory to store the xstat reported by each ``rte_node``. -The graph_nodes_mem_create() creates and populate this memory. The functions -such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory +Nodes are sorted by ``(priority, node_id)`` at graph creation time and each +node is assigned a bit position in the pending bitmap. During the graph walk, +the bitmap is scanned from the lowest bit, so nodes with lower priority values +are visited first. Source nodes are always assigned the lowest priority +(``INT16_MIN``) to ensure they run before any processing node. + +This priority-based ordering improves batching in fan-out-then-converge +topologies. For example, if ``eth_input`` classifies packets to both +``mpls_input`` and ``ipv4_input``, giving ``mpls_input`` a lower priority value +ensures it runs first. Its output accumulates in ``ipv4_input`` which is then +visited only once with all packets, instead of being visited twice (before and +after MPLS label popping). + +The ``graph_fp_mem_create()`` function creates and populates this memory. The +functions such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory to enable fastpath services. Graph feature arc
doc/guides/prog_guide/img/graph_mem_layout.svg +710 -1113
1,848 lines not on this page · raw message
lib/graph/graph.c +10 -17
@@ -334,20 +334,6 @@ graph_mem_fixup_secondary(struct rte_graph *graph)return graph_mem_fixup_node_ctx (graph); } -static bool -graph_src_node_avail (struct graph *graph) -{ -struct graph_node *graph_node; - - STAILQ_FOREACH(graph_node, &graph->node_list, next) -if ((graph_node->node->flags &RTE_NODE_SOURCE_F ) && - (graph_node->node->lcore_id ==RTE_MAX_LCORE || - graph->lcore_id == graph_node->node->lcore_id)) -return true; - -return false; -} -RTE_EXPORT_SYMBOL (rte_graph_model_mcore_dispatch_core_bind) intrte_graph_model_mcore_dispatch_core_bind (rte_graph_t id,int lcore)
@@ -375,9 +361,8 @@ rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore) graph->graph->dispatch.lcore_id = graph->lcore_id; graph->socket =rte_lcore_to_socket_id (lcore); -/* check the availability of source node */ -if (!graph_src_node_avail (graph)) - graph->graph->head =0 ; +/* Rebuild source bitmap with only source nodes bound to this lcore */ +graph_src_bitmap_rebuild (graph);return 0 ;
@@ -484,6 +469,10 @@ rte_graph_create(const char *name, struct rte_graph_param *prm)if (graph_has_isolated_node (graph)) goto graph_cleanup; +/* Compute topological depth for priority-based scheduling */ +if (graph_topo_order_compute (graph)) + goto graph_cleanup; +/* Initialize pcap config. */ graph_pcap_enable (prm->pcap_enable);
@@ -598,6 +587,10 @@ graph_clone(struct graph *parent_graph, const char *name, struct rte_graph_paramif (graph_adjacency_list_update (graph)) goto graph_cleanup; +/* Compute topological depth for priority-based scheduling */ +if (graph_topo_order_compute (graph)) + goto graph_cleanup; +/* Initialize the graph object */ graph->src_node_count = parent_graph->src_node_count; graph->node_count = parent_graph->node_count;
lib/graph/graph_debug.c +6 -6
@@ -15,8 +15,8 @@ graph_dump(FILE *f, struct graph *g)fprintf (f,"graph <%s>\n" , g->name);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," cir_start=%" PRIu32"\n" , g->cir_start); -fprintf (f," cir_mask=%" PRIu32"\n" , g->cir_mask); +fprintf (f," sched_table_off=%" PRIu32"\n" , g->sched_table_off); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," addr=%p\n" , g);fprintf (f," graph=%p\n" , g->graph);fprintf (f," mem_sz=%zu\n" , g->mem_sz);
@@ -63,14 +63,14 @@ rte_graph_obj_dump(FILE *f, struct rte_graph *g, bool all)fprintf (f,"graph <%s> @ %p\n" , g->name, g);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," head=%" PRId32"\n" , (int32_t )g->head); -fprintf (f," tail=%" PRId32"\n" , (int32_t )g->tail); -fprintf (f," cir_mask=0x%" PRIx32"\n" , g->cir_mask);fprintf (f," nb_nodes=%" PRId32"\n" , g->nb_nodes); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," socket=%d\n" , g->socket);fprintf (f," fence=0x%" PRIx64"\n" , g->fence);fprintf (f," nodes_start=0x%" PRIx32"\n" , g->nodes_start); -fprintf (f," cir_start=%p\n" , g->cir_start); +fprintf (f," sched_table=%p\n" , g->sched_table); +fprintf (f," pending=%p\n" , g->pending); +fprintf (f," src_pending=%p\n" , g->src_pending); rte_graph_foreach_node(count, off, g, n) {if (!all && n->idx ==0 )
lib/graph/graph_ops.c +46 -0
49 lines not on this page · raw message
lib/graph/graph_populate.c +98 -21
202 lines not on this page · raw message
lib/graph/graph_private.h +36 -6
79 lines not on this page · raw message
lib/graph/node.c +2 -0
@@ -153,6 +153,7 @@ __rte_node_register(const struct rte_node_register *reg)if (rte_strscpy (node->name, reg->name,RTE_NODE_NAMESIZE ) <0 ) goto free_xstat; node->flags = reg->flags; + node->priority = reg->priority; node->process = reg->process; node->init = reg->init; node->fini = reg->fini;
@@ -216,6 +217,7 @@ node_clone(struct node *node, const char *name)/* Clone the source node */ reg->flags = node->flags; + reg->priority = node->priority; reg->process = node->process; reg->init = node->init; reg->fini = node->fini;
lib/graph/rte_graph.h +1 -0
@@ -496,6 +496,7 @@ struct rte_node_register {char name[RTE_NODE_NAMESIZE ];/**< Name of the node. */ uint64_t flags;/**< Node configuration flag. */ #define RTE_NODE_SOURCE_F (1ULL << 0)/**< Node type is source. */ +int16_t priority;/**< Scheduling priority (lower = visited first, default 0). */ rte_node_process_t process;/**< Node process function. */ rte_node_init_t init;/**< Node init function. */ rte_node_fini_t fini;/**< Node fini function. */
lib/graph/rte_graph_model_mcore_dispatch.h +21 -13
@@ -77,9 +77,13 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id);/** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * +* Nodes are visited in scheduling order (lowest priority value first). +* Source nodes are seeded into the pending bitmap at the start of each walk. +* Nodes with different lcore affinity are dispatched to their target lcore. +* * @param graph * Graph pointer returned from rte_graph_lookup function. *
@@ -88,20 +92,28 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,static inline void rte_graph_walk_mcore_dispatch (struct rte_graph *graph) { -const rte_graph_off_t *cir_start = graph->cir_start; -const rte_node_t mask = graph->cir_mask; -uint32_t head = graph->head; +const uint16_t nwords = graph->nb_sched_words;struct rte_node *node; +uint16_t word, bit;if (graph->dispatch.wq !=NULL )__rte_graph_mcore_dispatch_sched_wq_process (graph); -while (likely (head != graph->tail)) { - node = (struct rte_node *)RTE_PTR_ADD (graph, cir_start[(int32_t )head++]); +/* Seed pending bitmap with source nodes bound to this lcore */ +for (word =0 ; word < nwords; word++) + graph->pending[word] |= graph->src_pending[word]; -/* skip the src nodes which not bind with current worker */ -if ((int32_t )head <1 && node->dispatch.lcore_id != graph->dispatch.lcore_id) -continue ; +for (;;) { +/* find first word with any pending bit */ +for (word =0 ; word < nwords; word++) +if (graph->pending[word]) +break ; +if (word == nwords) +break ;/* no more pending nodes */ + + bit =rte_ctz64 (graph->pending[word]); + graph->pending[word] &= ~(1ULL << bit); + node =__rte_graph_pending_node (graph, word, bit);/* Schedule the node until all task/objs are done */ if (node->dispatch.lcore_id != RTE_MAX_LCORE &&
@@ -111,11 +123,7 @@ rte_graph_walk_mcore_dispatch(struct rte_graph *graph)continue ;__rte_node_process (graph, node); - - head =likely ((int32_t )head >0 ) ? head & mask : head; } - - graph->tail =0 ; }#ifdef __cplusplus
lib/graph/rte_graph_model_rtc.h +45 -20
84 lines not on this page · raw message
lib/graph/rte_graph_worker.h +1 -1
@@ -14,7 +14,7 @@ extern "C" {#endif /** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * * @param graph
lib/graph/rte_graph_worker_common.h +49 -30
184 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v2 2/2 graph: replace circular buffer with priority-based bitmap
This will break the ABI. Please check and fix.
Quoted 380 lines
lib/graph/rte_graph.h +0
-0rte_node_process_t process;/**< Node process function. */ rte_node_init_t init;/**< Node init function. */ rte_node_fini_t fini;/**< Node fini function. */ lib/graph/rte_graph_model_mcore_dispatch.h +21
-13@@ -77,9 +77,13 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id);/** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * +* Nodes are visited in scheduling order (lowest priority value first). +* Source nodes are seeded into the pending bitmap at the start of each walk. +* Nodes with different lcore affinity are dispatched to their target lcore. +* * @param graph * Graph pointer returned from rte_graph_lookup function. * @@ -88,20 +92,28 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,static inline void rte_graph_walk_mcore_dispatch (struct rte_graph *graph) { -const rte_graph_off_t *cir_start = graph->cir_start; -const rte_node_t mask = graph->cir_mask; -uint32_t head = graph->head; +const uint16_t nwords = graph->nb_sched_words;struct rte_node *node; +uint16_t word, bit;if (graph->dispatch.wq !=NULL )__rte_graph_mcore_dispatch_sched_wq_process (graph); -while (likely (head != graph->tail)) { - node = (struct rte_node *)RTE_PTR_ADD (graph, cir_start[(int32_t )head++]); +/* Seed pending bitmap with source nodes bound to this lcore */ +for (word =0 ; word < nwords; word++) + graph->pending[word] |= graph->src_pending[word]; -/* skip the src nodes which not bind with current worker */ -if ((int32_t )head <1 && node->dispatch.lcore_id != graph->dispatch.lcore_id) -continue ; +for (;;) { +/* find first word with any pending bit */ +for (word =0 ; word < nwords; word++) +if (graph->pending[word]) +break ; +if (word == nwords) +break ;/* no more pending nodes */ + + bit =rte_ctz64 (graph->pending[word]); + graph->pending[word] &= ~(1ULL << bit); + node =__rte_graph_pending_node (graph, word, bit);/* Schedule the node until all task/objs are done */ if (node->dispatch.lcore_id != RTE_MAX_LCORE &&@@ -111,11 +123,7 @@ rte_graph_walk_mcore_dispatch(struct rte_graph *graph)continue ;__rte_node_process (graph, node); - - head =likely ((int32_t )head >0 ) ? head & mask : head; } - - graph->tail =0 ; }#ifdef __cpluspluslib/graph/rte_graph_model_rtc.h +45
-20@@ -6,9 +6,12 @@#include "rte_graph_worker_common.h" /** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * +* Nodes are visited in scheduling order (lowest priority value first). +* Source nodes are seeded into the pending bitmap at the start of each walk. +* * @param graph * Graph pointer returned from rte_graph_lookup function. * @@ -17,30 +20,52 @@static inline void rte_graph_walk_rtc (struct rte_graph *graph) { -const rte_graph_off_t *cir_start = graph->cir_start; -const rte_node_t mask = graph->cir_mask; -uint32_t head = graph->head; +const uint16_t nwords = graph->nb_sched_words;struct rte_node *node; +uint16_t word, bit;/* -* Walk on the source node(s) ((cir_start - head) -> cir_start) and then -* on the pending streams (cir_start -> (cir_start + mask) -> cir_start) -* in a circular buffer fashion. +* Nodes are assigned a bit position (sched_idx) sorted by (priority, +* node_id) at graph creation time. Source nodes are forced to INT16_MIN +* priority so they always come first. * -* +-----+ <= cir_start - head [number of source nodes] -* | | -* | ... | <= source nodes -* | | -* +-----+ <= cir_start [head = 0] [tail = 0] -* | | -* | ... | <= pending streams -* | | -* +-----+ <= cir_start + mask +* sched_table[] maps bit positions to node offsets: +* +* pending[] sched_table[] +* +----------+ +------------------+ +* | word 0 | ---> | src_node_0 | bit 0 (prio=INT16_MIN) +* | 1100...1 | | src_node_1 | bit 1 (prio=INT16_MIN) +* | | | mpls_input | bit 2 (prio=-10) +* | | | ipv4_input | bit 3 (prio=0) +* | | | ... | +* +----------+ +------------------+ +* | word 1 | ---> | ip4_rewrite | bit 64 (prio=10) +* | ... | | ... | +* +----------+ +------------------+ +* +* Walk: for each word, find lowest set bit (rte_ctz64), process that +* node, clear the bit, re-read the word (processing may have set new +* bits), repeat. +* +* After each node is processed, restart scanning from word 0 since +* processing may set bits in any word, including earlier ones. */ -while (likely (head != graph->tail)) { - node = (struct rte_node *)RTE_PTR_ADD (graph, cir_start[(int32_t )head++]); + +/* Seed pending bitmap with source nodes */ +for (word =0 ; word < nwords; word++) + graph->pending[word] |= graph->src_pending[word]; + +for (;;) { +/* find first word with any pending bit */ +for (word =0 ; word < nwords; word++) +if (graph->pending[word]) +break ; +if (word == nwords) +break ;/* no more pending nodes */ + + bit =rte_ctz64 (graph->pending[word]); + graph->pending[word] &= ~(1ULL << bit); + node =__rte_graph_pending_node (graph, word, bit);__rte_node_process (graph, node); - head =likely ((int32_t )head >0 ) ? head & mask : head; } - graph->tail =0 ; }lib/graph/rte_graph_worker.h +1
-1@@ -14,7 +14,7 @@ extern "C" {#endif /** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * * @param graph lib/graph/rte_graph_worker_common.h +49
-31@@ -49,15 +49,14 @@ SLIST_HEAD(rte_graph_rq_head, rte_graph);*/ struct __rte_cache_aligned rte_graph { /* Fast path area. */ - uint32_t tail; /**< Tail of circular buffer. */ - uint32_t head; /**< Head of circular buffer. */ - uint32_t cir_mask; /**< Circular buffer wrap around mask. */ rte_node_t nb_nodes; /**< Number of nodes in the graph. */ - rte_graph_off_t *cir_start; /**< Pointer to circular buffer. */ rte_graph_off_t nodes_start; /**< Offset at which node memory starts. */ + rte_graph_off_t *sched_table; /**< Node offset indexed by sched_idx. */ + uint64_t *pending; /**< Bitmap of pending nodes. */ + uint64_t *src_pending; /**< Bitmap of source nodes (constant). */ + uint16_t nb_sched_words; /**< Number of uint64_t words in pending bitmaps. */ uint8_t model; /**< graph model */ - uint8_t reserved1; /**< Reserved for future use. */ - uint16_t reserved2; /**< Reserved for future use. */ + /* 26 bytes padding */ union { /* Fast schedule area for mcore dispatch model */ struct {@@ -98,6 +97,7 @@ struct __rte_cache_aligned rte_node {rte_node_t id;/**< Node identifier. */ rte_node_t parent_id;/**< Parent Node identifier. */ rte_edge_t nb_edges;/**< Number of edges from this node. */ +uint16_t sched_idx;/**< Bit position in pending bitmap. */ uint32_t realloc_count;/**< Number of times realloced. */ char parent[RTE_NODE_NAMESIZE ];/**< Parent node name. */ @@ -132,7 +132,7 @@ struct __rte_cache_aligned rte_node { };/**< Node Context. */ uint16_t size;/**< Total number of objects available. */ uint16_t idx;/**< Number of objects used. */ -rte_graph_off_t off;/**< Offset of node in the graph reel. */ +rte_graph_off_t off;/**< Offset of node in the graph memory. */ uint64_t total_cycles;/**< Cycles spent in this node. */ uint64_t total_calls;/**< Calls done to this node. */ uint64_t total_objs;/**< Objects processed by this node. */ @@ -187,12 +187,12 @@ void __rte_node_stream_alloc_size(struct rte_graph *graph,/** * @internal * -* Enqueue a given node to the tail of the graph reel. +* Process a node's pending objects and collect stats. * * @param graph * Pointer Graph object. * @param node -* Pointer to node object to be enqueued. +* Pointer to node object to be processed. */ static __rte_always_inline void__rte_node_process (struct rte_graph *graph,struct rte_node *node)@@ -220,21 +220,42 @@ __rte_node_process(struct rte_graph *graph, struct rte_node *node)/** * @internal * -* Enqueue a given node to the tail of the graph reel. +* Get a pointer to a node from the scheduling table. * * @param graph * Pointer Graph object. +* @param word +* Offset in the pending bitmap. +* @param bit +* Bit number. +* +* @return +* Pointer to the node. +*/ +static __rte_always_inline struct rte_node * +__rte_graph_pending_node (struct rte_graph *graph,uint16_t word,uint16_t bit) +{ +const uint16_t index = (word *sizeof (*graph->pending) *CHAR_BIT ) + bit; +const rte_graph_off_t node_offset = graph->sched_table[index]; +return RTE_PTR_ADD (graph, node_offset); +} + +/** +* @internal +* +* Mark a node as pending in the graph scheduling bitmap. +* +* @param bitmap +* Either graph->pending or graph->src_pending. * @param node -* Pointer to node object to be enqueued. +* Pointer to node object to be marked pending. */ static __rte_always_inline void -__rte_node_enqueue_tail_update (struct rte_graph *graph,struct rte_node *node) +__rte_node_pending_set (uint64_t *bitmap,struct rte_node *node) { -uint32_t tail; - - tail = graph->tail; - graph->cir_start[tail++] = node->off; - graph->tail = tail & graph->cir_mask; +const uint16_t word = node->sched_idx / (sizeof (*bitmap) *CHAR_BIT ); +const uint16_t bit = node->sched_idx % (sizeof (*bitmap) *CHAR_BIT ); + bitmap[word] |=1ULL << bit; }/** @@ -242,8 +263,8 @@ __rte_node_enqueue_tail_update(struct rte_graph *graph, struct rte_node *node)* * Enqueue sequence prologue function. * -* Updates the node to tail of graph reel and resizes the number of objects -* available in the stream as needed. +* Marks the node as pending in the scheduling bitmap and resizes the number +* of objects available in the stream as needed. * * @param graph * Pointer to the graph object. @@ -259,9 +280,8 @@ __rte_node_enqueue_prologue(struct rte_graph *graph, struct rte_node *node, const uint16_t idx, const uint16_t space) { -/* Add to the pending stream list if the node is new */ if (idx == 0) -__rte_node_enqueue_tail_update (graph, node); + __rte_node_pending_set(graph->pending, node);if (unlikely (node->size < (idx + space)))__rte_node_stream_alloc_size (graph, node, node->size + space);@@ -293,7 +313,7 @@ __rte_node_next_node_get(struct rte_node *node, rte_edge_t next)/** * Enqueue the objs to next node for further processing and set -* the next node to pending state in the circular buffer. +* the next node to pending state in the scheduling bitmap. * * @param graph * Graph pointer returned from rte_graph_lookup(). @@ -321,7 +341,7 @@ rte_node_enqueue(struct rte_graph *graph, struct rte_node *node,/** * Enqueue only one obj to next node for further processing and -* set the next node to pending state in the circular buffer. +* set the next node to pending state in the scheduling bitmap. * * @param graph * Graph pointer returned from rte_graph_lookup(). @@ -347,7 +367,7 @@ rte_node_enqueue_x1(struct rte_graph *graph, struct rte_node *node,/** * Enqueue only two objs to next node for further processing and -* set the next node to pending state in the circular buffer. +* set the next node to pending state in the scheduling bitmap. * Same as rte_node_enqueue_x1 but enqueue two objs. * * @param graph @@ -377,7 +397,7 @@ rte_node_enqueue_x2(struct rte_graph *graph, struct rte_node *node,/** * Enqueue only four objs to next node for further processing and -* set the next node to pending state in the circular buffer. +* set the next node to pending state in the scheduling bitmap. * Same as rte_node_enqueue_x1 but enqueue four objs. * * @param graph @@ -414,7 +434,7 @@ rte_node_enqueue_x4(struct rte_graph *graph, struct rte_node *node,/** * Enqueue objs to multiple next nodes for further processing and -* set the next nodes to pending state in the circular buffer. +* set the next nodes to pending state in the scheduling bitmap. * objs[i] will be enqueued to nexts[i]. * * @param graph @@ -472,7 +492,7 @@ rte_node_next_stream_get(struct rte_graph *graph, struct rte_node *node, }/** -* Put the next stream to pending state in the circular buffer +* Put the next stream to pending state in the scheduling bitmap * for further processing. Should be invoked after rte_node_next_stream_get(). * * @param graph @@ -496,8 +516,7 @@ rte_node_next_stream_put(struct rte_graph *graph, struct rte_node *node, node =__rte_node_next_node_get (node, next);if (node->idx ==0 ) -__rte_node_enqueue_tail_update (graph, node); - +__rte_node_pending_set (graph->pending, node); node->idx += idx; }@@ -530,7 +549,7 @@ rte_node_next_stream_move(struct rte_graph *graph, struct rte_node *src, src->objs = dobjs; src->size = dsz; dst->idx = src->idx; -__rte_node_enqueue_tail_update (graph, dst); +__rte_node_pending_set (graph->pending, dst); }else {/* Move the objects from src node to dst node */ rte_node_enqueue (graph, src, next, src->objs, src->idx); } --2.54.0
Re: [PATCH dpdk v2 2/2] graph: replace circular buffer with priority-based bitmap
Hi,
, Jun 16, 2026 at 08:30:
Quoted 1 line
This will break the ABI. Please check and fix.
Yes it will break the ABI. There is no way around it. What did you mean by "check and fix"?
Re: [PATCH dpdk v2 2/2] graph: replace circular buffer with priority-based bitmap
Re: [PATCH dpdk v2 2/2] graph: replace circular buffer with priority-based bitmap
In reply to Robin JarryQuoted 8 lines
Hi,
, Jun 16, 2026 at 08:30:
Quoted 1 line
This will break the ABI. Please check and fix.
Yes it will break the ABI. There is no way around it. What did you mean by "check and fix"?
Looks like we canot avoid ABI break, Since Graph is not experimental library,
please send deprication notice and we need to wait for next ABI breaking release i.e 27.11
From: Robin Jarry <[email protected]>
Date: Tuesday, 19 May 2026 at 3:43 PM
To: [email protected] <[email protected]>; Jerin Jacob <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Nithin Kumar Dabilpuram <[email protected]>; Zhirun Yan <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>; Christophe Fontaine <[email protected]>; David Marchand <[email protected]>; Konstantin Ananyev <[email protected]>; Maxime Leroy <[email protected]>
Subject: [EXTERNAL] [PATCH dpdk] graph: replace circular buffer with priority-based bitmap scheduling
Replace the FIFO circular buffer used to track pending nodes with a bitmap and a priority-sorted schedule table. Each node can now have a scheduling priority (int16_t, default 0, lower value means visited first). Source nodes are forced to INT16_MIN so they always run first.
At graph creation time, nodes are sorted by (priority, id) and assigned a bit position (sched_idx). During the walk, a bitmap tracks which nodes have pending objects. Scanning from the lowest bit naturally visits nodes in priority order.
This improves batching in fan-out-then-converge topologies. When eth_input classifies packets to both mpls_input and ipv4_input, the old FIFO order could process ipv4_input before mpls_input, causing ipv4_input to be visited twice (once before and once after the MPLS label is popped). With mpls_input at a higher priority (lower value), it runs first and its output accumulates in ipv4_input which is then visited only once with all packets.
The bitmap set operation is idempotent (OR on an already-set bit is a no-op) which removes the need for the idx == 0 guards that the circular buffer required to avoid duplicate enqueue.
--- doc/guides/prog_guide/graph_lib.rst | 37 +- .../prog_guide/img/graph_mem_layout.svg | 1823 +++++++---------- lib/graph/graph.c | 19 +- lib/graph/graph_debug.c | 12 +- lib/graph/graph_populate.c | 117 +- lib/graph/graph_private.h | 27 +- lib/graph/node.c | 2 + lib/graph/rte_graph.h | 1 + lib/graph/rte_graph_model_mcore_dispatch.h | 34 +- lib/graph/rte_graph_model_rtc.h | 65 +- lib/graph/rte_graph_worker.h | 2 +- lib/graph/rte_graph_worker_common.h | 81 +- 12 files changed, 984 insertions(+), 1236 deletions(-)
doc/guides/prog_guide/graph_lib.rst +30 -7
@@ -117,13 +117,22 @@ next_node[]: The dynamic array to store the downstream nodes connected to this node. Downstream node should not be current node itself or a source node. +priority: +^^^^^^^^^ + +The scheduling priority of the node (``int16_t``, default 0). Nodes with lower +priority values are visited first during the graph walk. This allows control +over the order in which pending nodes are processed, which can improve packet +batching in topologies where multiple paths converge on the same node. + Source node: ^^^^^^^^^^^^ Source nodes are static nodes created using ``RTE_NODE_REGISTER`` by passing ``flags`` as ``RTE_NODE_SOURCE_F``. -While performing the graph walk, the ``process()`` function of all the source -nodes will be called first. So that these nodes can be used as input nodes for a graph. +Source nodes are automatically assigned the lowest possible priority +(``INT16_MIN``) so that their ``process()`` function is always called first +during the graph walk. This ensures they act as input nodes for a graph. nb_xstats: ^^^^^^^^^^
@@ -396,12 +405,26 @@ Graph object memory layout Understanding the memory layout helps to debug the graph library and improve the performance if needed. -Graph object consists of a header, circular buffer to store the pending stream -when walking over the graph, variable-length memory to store the ``rte_node`` objects, -and variable-length memory to store the xstat reported by each ``rte_node``. +A graph object consists of a header, a scheduling table mapping bit positions to +node offsets, pending and source bitmaps for tracking which nodes need +processing, variable-length memory to store the ``rte_node`` objects, and +variable-length memory to store the xstat reported by each ``rte_node``. -The graph_nodes_mem_create() creates and populate this memory. The functions -such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory +Nodes are sorted by ``(priority, node_id)`` at graph creation time and each +node is assigned a bit position in the pending bitmap. During the graph walk, +the bitmap is scanned from the lowest bit, so nodes with lower priority values +are visited first. Source nodes are always assigned the lowest priority +(``INT16_MIN``) to ensure they run before any processing node. + +This priority-based ordering improves batching in fan-out-then-converge +topologies. For example, if ``eth_input`` classifies packets to both +``mpls_input`` and ``ipv4_input``, giving ``mpls_input`` a lower priority value +ensures it runs first. Its output accumulates in ``ipv4_input`` which is then +visited only once with all packets, instead of being visited twice (before and +after MPLS label popping). + +The ``graph_fp_mem_create()`` function creates and populates this memory. The +functions such as ``rte_graph_walk()`` and ``rte_node_enqueue_*`` use this memory to enable fastpath services.
lib/graph/graph.c +2 -17
@@ -334,20 +334,6 @@ graph_mem_fixup_secondary(struct rte_graph *graph)return graph_mem_fixup_node_ctx (graph); } -static bool -graph_src_node_avail (struct graph *graph) -{ -struct graph_node *graph_node; - - STAILQ_FOREACH(graph_node, &graph->node_list, next) -if ((graph_node->node->flags &RTE_NODE_SOURCE_F ) && - (graph_node->node->lcore_id ==RTE_MAX_LCORE || - graph->lcore_id == graph_node->node->lcore_id)) -return true; - -return false; -} -RTE_EXPORT_SYMBOL (rte_graph_model_mcore_dispatch_core_bind) intrte_graph_model_mcore_dispatch_core_bind (rte_graph_t id,int lcore)
@@ -375,9 +361,8 @@ rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore) graph->graph->dispatch.lcore_id = graph->lcore_id; graph->socket =rte_lcore_to_socket_id (lcore); -/* check the availability of source node */ -if (!graph_src_node_avail (graph)) - graph->graph->head =0 ; +/* Rebuild source bitmap with only source nodes bound to this lcore */ +graph_src_bitmap_rebuild (graph);return 0 ;
lib/graph/graph_debug.c +6 -6
@@ -15,8 +15,8 @@ graph_dump(FILE *f, struct graph *g)fprintf (f,"graph <%s>\n" , g->name);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," cir_start=%" PRIu32"\n" , g->cir_start); -fprintf (f," cir_mask=%" PRIu32"\n" , g->cir_mask); +fprintf (f," sched_table_off=%" PRIu32"\n" , g->sched_table_off); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," addr=%p\n" , g);fprintf (f," graph=%p\n" , g->graph);fprintf (f," mem_sz=%zu\n" , g->mem_sz);
@@ -63,14 +63,14 @@ rte_graph_obj_dump(FILE *f, struct rte_graph *g, bool all)fprintf (f,"graph <%s> @ %p\n" , g->name, g);fprintf (f," id=%" PRIu32"\n" , g->id); -fprintf (f," head=%" PRId32"\n" , (int32_t )g->head); -fprintf (f," tail=%" PRId32"\n" , (int32_t )g->tail); -fprintf (f," cir_mask=0x%" PRIx32"\n" , g->cir_mask);fprintf (f," nb_nodes=%" PRId32"\n" , g->nb_nodes); +fprintf (f," nb_sched_words=%" PRIu16"\n" , g->nb_sched_words);fprintf (f," socket=%d\n" , g->socket);fprintf (f," fence=0x%" PRIx64"\n" , g->fence);fprintf (f," nodes_start=0x%" PRIx32"\n" , g->nodes_start); -fprintf (f," cir_start=%p\n" , g->cir_start); +fprintf (f," sched_table=%p\n" , g->sched_table); +fprintf (f," pending=%p\n" , g->pending); +fprintf (f," src_pending=%p\n" , g->src_pending); rte_graph_foreach_node(count, off, g, n) {if (!all && n->idx ==0 )
lib/graph/graph_populate.c +96 -21
200 lines not on this page · raw message
lib/graph/graph_private.h +21 -6
@@ -49,6 +49,7 @@ struct node {STAILQ_ENTRY (node) next;/**< Next node in the list. */ char name[RTE_NODE_NAMESIZE ];/**< Name of the node. */ uint64_t flags;/**< Node configuration flag. */ +int16_t priority;/**< Scheduling priority. */ unsigned int lcore_id;/**< Node runs on the Lcore ID used for mcore dispatch model. */ rte_node_process_t process;/**< Node process function. */
@@ -98,19 +99,23 @@ struct graph {const struct rte_memzone *mz;/**< Memzone to store graph data. */ rte_graph_off_t nodes_start; -/**< Node memory start offset in graph reel. */ +/**< Node memory start offset in graph memory. */ rte_graph_off_t xstats_start; -/**< Node xstats memory start offset in graph reel. */ +/**< Node xstats memory start offset in graph memory. */ rte_node_t src_node_count;/**< Number of source nodes in a graph. */ struct rte_graph *graph;/**< Pointer to graph data. */ rte_node_t node_count;/**< Total number of nodes. */ -uint32_t cir_start; -/**< Circular buffer start offset in graph reel. */ -uint32_t cir_mask; -/**< Circular buffer mask for wrap around. */ +uint32_t sched_table_off; +/**< Schedule table start offset in graph memory. */ +uint32_t pending_off; +/**< Pending bitmap start offset in graph memory. */ +uint32_t src_pending_off; +/**< Source pending bitmap start offset in graph memory. */ +uint16_t nb_sched_words; +/**< Number of uint64_t words in pending bitmaps. */ rte_graph_t id;/**< Graph identifier. */ rte_graph_t parent_id;
@@ -378,6 +383,16 @@ int graph_fp_mem_create(struct graph *graph);*/ int graph_fp_mem_destroy (struct graph *graph); +/** +* @internal +* +* Rebuild the source pending bitmap based on lcore affinity. +* +* @param graph +* Pointer to the internal graph object. +*/ +void graph_src_bitmap_rebuild (struct graph *graph); +/* Lookup functions */ /** * @internal
lib/graph/node.c +2 -0
@@ -153,6 +153,7 @@ __rte_node_register(const struct rte_node_register *reg)if (rte_strscpy (node->name, reg->name,RTE_NODE_NAMESIZE ) <0 ) goto free_xstat; node->flags = reg->flags; + node->priority = reg->priority; node->process = reg->process; node->init = reg->init; node->fini = reg->fini;
@@ -216,6 +217,7 @@ node_clone(struct node *node, const char *name)/* Clone the source node */ reg->flags = node->flags; + reg->priority = node->priority; reg->process = node->process; reg->init = node->init; reg->fini = node->fini;
lib/graph/rte_graph.h +1 -0
@@ -496,6 +496,7 @@ struct rte_node_register {char name[RTE_NODE_NAMESIZE ];/**< Name of the node. */ uint64_t flags;/**< Node configuration flag. */ #define RTE_NODE_SOURCE_F (1ULL << 0)/**< Node type is source. */ +int16_t priority;/**< Scheduling priority (lower = visited first, default 0). */
This will break the ABI. Please run ABI check and see/fix.
rte_node_process_t process; /**< Node process function. */
rte_node_init_t init; /**< Node init function. */
rte_node_fini_t fini; /**< Node fini function. */
lib/graph/rte_graph_model_mcore_dispatch.h +21 -13
@@ -77,9 +77,13 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id);/** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * +* Nodes are visited in scheduling order (lowest priority value first). +* Source nodes are seeded into the pending bitmap at the start of each walk. +* Nodes with different lcore affinity are dispatched to their target lcore. +* * @param graph * Graph pointer returned from rte_graph_lookup function. *
@@ -88,20 +92,28 @@ int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,static inline void rte_graph_walk_mcore_dispatch (struct rte_graph *graph) { -const rte_graph_off_t *cir_start = graph->cir_start; -const rte_node_t mask = graph->cir_mask; -uint32_t head = graph->head; +const uint16_t nwords = graph->nb_sched_words;struct rte_node *node; +uint16_t word, bit;if (graph->dispatch.wq !=NULL )__rte_graph_mcore_dispatch_sched_wq_process (graph); -while (likely (head != graph->tail)) { - node = (struct rte_node *)RTE_PTR_ADD (graph, cir_start[(int32_t )head++]); +/* Seed pending bitmap with source nodes bound to this lcore */ +for (word =0 ; word < nwords; word++) + graph->pending[word] |= graph->src_pending[word]; -/* skip the src nodes which not bind with current worker */ -if ((int32_t )head <1 && node->dispatch.lcore_id != graph->dispatch.lcore_id) -continue ; +for (;;) { +/* find first word with any pending bit */ +for (word =0 ; word < nwords; word++) +if (graph->pending[word]) +break ; +if (word == nwords) +break ;/* no more pending nodes */ + + bit =rte_ctz64 (graph->pending[word]); + graph->pending[word] &= ~(1ULL << bit); + node =__rte_graph_pending_node (graph, word, bit);/* Schedule the node until all task/objs are done */ if (node->dispatch.lcore_id != RTE_MAX_LCORE &&
@@ -111,11 +123,7 @@ rte_graph_walk_mcore_dispatch(struct rte_graph *graph)continue ;__rte_node_process (graph, node); - - head =likely ((int32_t )head >0 ) ? head & mask : head; } - - graph->tail =0 ; }#ifdef __cplusplus
lib/graph/rte_graph_model_rtc.h +45 -20
84 lines not on this page · raw message
lib/graph/rte_graph_worker.h +1 -1
@@ -14,7 +14,7 @@ extern "C" {#endif /** -* Perform graph walk on the circular buffer and invoke the process function +* Perform graph walk on the pending bitmap and invoke the process function * of the nodes and collect the stats. * * @param graph
lib/graph/rte_graph_worker_common.h +49 -32
185 lines not on this page · raw message
--
2.54.0