xref: /dpdk/lib/graph/rte_graph.h (revision 070db97e017b7ed9a5320b2f624f05562a632bd3)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(C) 2020 Marvell International Ltd.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_GRAPH_H_
699a2dd95SBruce Richardson #define _RTE_GRAPH_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file rte_graph.h
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * Graph architecture abstracts the data processing functions as
1299a2dd95SBruce Richardson  * "node" and "link" them together to create a complex "graph" to enable
1399a2dd95SBruce Richardson  * reusable/modular data processing functions.
1499a2dd95SBruce Richardson  *
1599a2dd95SBruce Richardson  * This API enables graph framework operations such as create, lookup,
1699a2dd95SBruce Richardson  * dump and destroy on graph and node operations such as clone,
1799a2dd95SBruce Richardson  * edge update, and edge shrink, etc. The API also allows to create the stats
1899a2dd95SBruce Richardson  * cluster to monitor per graph and per node stats.
1999a2dd95SBruce Richardson  */
2099a2dd95SBruce Richardson 
2199a2dd95SBruce Richardson #include <stdbool.h>
2299a2dd95SBruce Richardson #include <stdio.h>
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson #include <rte_common.h>
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson #ifdef __cplusplus
2799a2dd95SBruce Richardson extern "C" {
2899a2dd95SBruce Richardson #endif
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson #define RTE_GRAPH_NAMESIZE 64 /**< Max length of graph name. */
3199a2dd95SBruce Richardson #define RTE_NODE_NAMESIZE 64  /**< Max length of node name. */
32*070db97eSPavan Nikhilesh #define RTE_NODE_XSTAT_DESC_SIZE 64  /**< Max length of node xstat description. */
339b72ea1fSAmit Prakash Shukla #define RTE_GRAPH_PCAP_FILE_SZ 64 /**< Max length of pcap file name. */
3499a2dd95SBruce Richardson #define RTE_GRAPH_OFF_INVALID UINT32_MAX /**< Invalid graph offset. */
3599a2dd95SBruce Richardson #define RTE_NODE_ID_INVALID UINT32_MAX   /**< Invalid node id. */
3699a2dd95SBruce Richardson #define RTE_EDGE_ID_INVALID UINT16_MAX   /**< Invalid edge id. */
3799a2dd95SBruce Richardson #define RTE_GRAPH_ID_INVALID UINT16_MAX  /**< Invalid graph id. */
3899a2dd95SBruce Richardson #define RTE_GRAPH_FENCE 0xdeadbeef12345678ULL /**< Graph fence data. */
3999a2dd95SBruce Richardson 
4099a2dd95SBruce Richardson typedef uint32_t rte_graph_off_t;  /**< Graph offset type. */
4199a2dd95SBruce Richardson typedef uint32_t rte_node_t;       /**< Node id type. */
4299a2dd95SBruce Richardson typedef uint16_t rte_edge_t;       /**< Edge id type. */
4399a2dd95SBruce Richardson typedef uint16_t rte_graph_t;      /**< Graph id type. */
4499a2dd95SBruce Richardson 
4599a2dd95SBruce Richardson /** Burst size in terms of log2 */
4699a2dd95SBruce Richardson #if RTE_GRAPH_BURST_SIZE == 1
4799a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 0  /**< Object burst size of 1. */
4899a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 2
4999a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 1  /**< Object burst size of 2. */
5099a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 4
5199a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 2  /**< Object burst size of 4. */
5299a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 8
5399a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 3  /**< Object burst size of 8. */
5499a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 16
5599a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 4  /**< Object burst size of 16. */
5699a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 32
5799a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 5  /**< Object burst size of 32. */
5899a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 64
5999a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 6  /**< Object burst size of 64. */
6099a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 128
6199a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 7  /**< Object burst size of 128. */
6299a2dd95SBruce Richardson #elif RTE_GRAPH_BURST_SIZE == 256
6399a2dd95SBruce Richardson #define RTE_GRAPH_BURST_SIZE_LOG2 8  /**< Object burst size of 256. */
6499a2dd95SBruce Richardson #else
6599a2dd95SBruce Richardson #error "Unsupported burst size"
6699a2dd95SBruce Richardson #endif
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson /* Forward declaration */
6999a2dd95SBruce Richardson struct rte_node;  /**< Node object */
7099a2dd95SBruce Richardson struct rte_graph; /**< Graph object */
7199a2dd95SBruce Richardson struct rte_graph_cluster_stats;      /**< Stats for Cluster of graphs */
7299a2dd95SBruce Richardson struct rte_graph_cluster_node_stats; /**< Node stats within cluster of graphs */
7399a2dd95SBruce Richardson 
7499a2dd95SBruce Richardson /**
7599a2dd95SBruce Richardson  * Node process function.
7699a2dd95SBruce Richardson  *
7799a2dd95SBruce Richardson  * The function invoked when the worker thread walks on nodes using
7899a2dd95SBruce Richardson  * rte_graph_walk().
7999a2dd95SBruce Richardson  *
8099a2dd95SBruce Richardson  * @param graph
8199a2dd95SBruce Richardson  *   Pointer to the graph object.
8299a2dd95SBruce Richardson  * @param node
8399a2dd95SBruce Richardson  *   Pointer to the node object.
8499a2dd95SBruce Richardson  * @param objs
8599a2dd95SBruce Richardson  *   Pointer to an array of objects to be processed.
8699a2dd95SBruce Richardson  * @param nb_objs
8799a2dd95SBruce Richardson  *   Number of objects in the array.
8899a2dd95SBruce Richardson  *
8999a2dd95SBruce Richardson  * @return
9099a2dd95SBruce Richardson  *   Number of objects processed.
9199a2dd95SBruce Richardson  *
9299a2dd95SBruce Richardson  * @see rte_graph_walk()
9399a2dd95SBruce Richardson  */
9499a2dd95SBruce Richardson typedef uint16_t (*rte_node_process_t)(struct rte_graph *graph,
9599a2dd95SBruce Richardson 				       struct rte_node *node, void **objs,
9699a2dd95SBruce Richardson 				       uint16_t nb_objs);
9799a2dd95SBruce Richardson 
9899a2dd95SBruce Richardson /**
9999a2dd95SBruce Richardson  * Node initialization function.
10099a2dd95SBruce Richardson  *
10199a2dd95SBruce Richardson  * The function invoked when the user creates the graph using rte_graph_create()
10299a2dd95SBruce Richardson  *
10399a2dd95SBruce Richardson  * @param graph
10499a2dd95SBruce Richardson  *   Pointer to the graph object.
10599a2dd95SBruce Richardson  * @param node
10699a2dd95SBruce Richardson  *   Pointer to the node object.
10799a2dd95SBruce Richardson  *
10899a2dd95SBruce Richardson  * @return
10999a2dd95SBruce Richardson  *   - 0: Success.
11099a2dd95SBruce Richardson  *   -<0: Failure.
11199a2dd95SBruce Richardson  *
11299a2dd95SBruce Richardson  * @see rte_graph_create()
11399a2dd95SBruce Richardson  */
11499a2dd95SBruce Richardson typedef int (*rte_node_init_t)(const struct rte_graph *graph,
11599a2dd95SBruce Richardson 			       struct rte_node *node);
11699a2dd95SBruce Richardson 
11799a2dd95SBruce Richardson /**
11899a2dd95SBruce Richardson  * Node finalization function.
11999a2dd95SBruce Richardson  *
12099a2dd95SBruce Richardson  * The function invoked when the user destroys the graph using
12199a2dd95SBruce Richardson  * rte_graph_destroy().
12299a2dd95SBruce Richardson  *
12399a2dd95SBruce Richardson  * @param graph
12499a2dd95SBruce Richardson  *   Pointer to the graph object.
12599a2dd95SBruce Richardson  * @param node
12699a2dd95SBruce Richardson  *   Pointer to the node object.
12799a2dd95SBruce Richardson  *
12899a2dd95SBruce Richardson  * @see rte_graph_destroy()
12999a2dd95SBruce Richardson  */
13099a2dd95SBruce Richardson typedef void (*rte_node_fini_t)(const struct rte_graph *graph,
13199a2dd95SBruce Richardson 				struct rte_node *node);
13299a2dd95SBruce Richardson 
13399a2dd95SBruce Richardson /**
13499a2dd95SBruce Richardson  * Graph cluster stats callback.
13599a2dd95SBruce Richardson  *
13699a2dd95SBruce Richardson  * @param is_first
13799a2dd95SBruce Richardson  *   Flag to denote that stats are of the first node.
13899a2dd95SBruce Richardson  * @param is_last
13999a2dd95SBruce Richardson  *   Flag to denote that stats are of the last node.
14099a2dd95SBruce Richardson  * @param cookie
14199a2dd95SBruce Richardson  *   Cookie supplied during stats creation.
14299a2dd95SBruce Richardson  * @param stats
14399a2dd95SBruce Richardson  *   Node cluster stats data.
14499a2dd95SBruce Richardson  *
14599a2dd95SBruce Richardson  * @return
14699a2dd95SBruce Richardson  *   - 0: Success.
14799a2dd95SBruce Richardson  *   -<0: Failure.
14899a2dd95SBruce Richardson  */
14999a2dd95SBruce Richardson typedef int (*rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
15099a2dd95SBruce Richardson 	     void *cookie, const struct rte_graph_cluster_node_stats *stats);
15199a2dd95SBruce Richardson 
15299a2dd95SBruce Richardson /**
15399a2dd95SBruce Richardson  * Structure to hold configuration parameters for creating the graph.
15499a2dd95SBruce Richardson  *
15599a2dd95SBruce Richardson  * @see rte_graph_create()
15699a2dd95SBruce Richardson  */
15799a2dd95SBruce Richardson struct rte_graph_param {
15899a2dd95SBruce Richardson 	int socket_id; /**< Socket id where memory is allocated. */
15999a2dd95SBruce Richardson 	uint16_t nb_node_patterns;  /**< Number of node patterns. */
16099a2dd95SBruce Richardson 	const char **node_patterns;
16199a2dd95SBruce Richardson 	/**< Array of node patterns based on shell pattern. */
1629b72ea1fSAmit Prakash Shukla 
1639b72ea1fSAmit Prakash Shukla 	bool pcap_enable; /**< Pcap enable. */
1649b72ea1fSAmit Prakash Shukla 	uint64_t num_pkt_to_capture; /**< Number of packets to capture. */
1659b72ea1fSAmit Prakash Shukla 	char *pcap_filename; /**< Filename in which packets to be captured.*/
1661e2aed1aSZhirun Yan 
1671e2aed1aSZhirun Yan 	union {
1681e2aed1aSZhirun Yan 		struct {
1691e2aed1aSZhirun Yan 			uint64_t rsvd; /**< Reserved for rtc model. */
1701e2aed1aSZhirun Yan 		} rtc;
1711e2aed1aSZhirun Yan 		struct {
1721e2aed1aSZhirun Yan 			uint32_t wq_size_max; /**< Maximum size of workqueue for dispatch model. */
1731e2aed1aSZhirun Yan 			uint32_t mp_capacity; /**< Capacity of memory pool for dispatch model. */
1741e2aed1aSZhirun Yan 		} dispatch;
1751e2aed1aSZhirun Yan 	};
17699a2dd95SBruce Richardson };
17799a2dd95SBruce Richardson 
17899a2dd95SBruce Richardson /**
17999a2dd95SBruce Richardson  * Structure to hold configuration parameters for graph cluster stats create.
18099a2dd95SBruce Richardson  *
18199a2dd95SBruce Richardson  * @see rte_graph_cluster_stats_create()
18299a2dd95SBruce Richardson  */
18399a2dd95SBruce Richardson struct rte_graph_cluster_stats_param {
18499a2dd95SBruce Richardson 	int socket_id;
18599a2dd95SBruce Richardson 	/**< Socket id where memory is allocated */
18699a2dd95SBruce Richardson 	rte_graph_cluster_stats_cb_t fn;
18799a2dd95SBruce Richardson 	/**< Stats print callback function. NULL value allowed, in that case,
18899a2dd95SBruce Richardson 	 *   default print stat function used.
18999a2dd95SBruce Richardson 	 */
19099a2dd95SBruce Richardson 	union {
19199a2dd95SBruce Richardson 		void *cookie;
19299a2dd95SBruce Richardson 		FILE *f; /**< File pointer to dump the stats when fn == NULL. */
19399a2dd95SBruce Richardson 	};
19499a2dd95SBruce Richardson 	uint16_t nb_graph_patterns;  /**< Number of graph patterns. */
19599a2dd95SBruce Richardson 	const char **graph_patterns;
19699a2dd95SBruce Richardson 	/**< Array of graph patterns based on shell pattern. */
19799a2dd95SBruce Richardson };
19899a2dd95SBruce Richardson 
19999a2dd95SBruce Richardson /**
20099a2dd95SBruce Richardson  * Node cluster stats data structure.
20199a2dd95SBruce Richardson  *
20299a2dd95SBruce Richardson  * @see struct rte_graph_cluster_stats_param::fn
20399a2dd95SBruce Richardson  */
204c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_graph_cluster_node_stats {
20599a2dd95SBruce Richardson 	uint64_t ts;	    /**< Current timestamp. */
20699a2dd95SBruce Richardson 	uint64_t calls;	    /**< Current number of calls made. */
20799a2dd95SBruce Richardson 	uint64_t objs;      /**< Current number of objs processed. */
20899a2dd95SBruce Richardson 	uint64_t cycles;    /**< Current number of cycles. */
20999a2dd95SBruce Richardson 
21099a2dd95SBruce Richardson 	uint64_t prev_ts;	/**< Previous call timestamp. */
21199a2dd95SBruce Richardson 	uint64_t prev_calls;	/**< Previous number of calls. */
21299a2dd95SBruce Richardson 	uint64_t prev_objs;	/**< Previous number of processed objs. */
21399a2dd95SBruce Richardson 	uint64_t prev_cycles;	/**< Previous number of cycles. */
21499a2dd95SBruce Richardson 
215358ff83fSZhirun Yan 	union {
216358ff83fSZhirun Yan 		struct {
217358ff83fSZhirun Yan 			uint64_t sched_objs;
218358ff83fSZhirun Yan 			/**< Previous number of scheduled objs for dispatch model. */
219358ff83fSZhirun Yan 			uint64_t sched_fail;
220358ff83fSZhirun Yan 			/**< Previous number of failed schedule objs for dispatch model. */
221358ff83fSZhirun Yan 		} dispatch;
222358ff83fSZhirun Yan 	};
223358ff83fSZhirun Yan 
22499a2dd95SBruce Richardson 	uint64_t realloc_count; /**< Realloc count. */
22599a2dd95SBruce Richardson 
226*070db97eSPavan Nikhilesh 	uint8_t xstat_cntrs;			      /**< Number of Node xstat counters. */
227*070db97eSPavan Nikhilesh 	char (*xstat_desc)[RTE_NODE_XSTAT_DESC_SIZE]; /**< Names of the Node xstat counters. */
228*070db97eSPavan Nikhilesh 	uint64_t *xstat_count;			      /**< Total stat count per each xstat. */
229*070db97eSPavan Nikhilesh 
23099a2dd95SBruce Richardson 	rte_node_t id;	/**< Node identifier of stats. */
23199a2dd95SBruce Richardson 	uint64_t hz;	/**< Cycles per seconds. */
23299a2dd95SBruce Richardson 	char name[RTE_NODE_NAMESIZE];	/**< Name of the node. */
233c6552d9aSTyler Retzlaff };
23499a2dd95SBruce Richardson 
23599a2dd95SBruce Richardson /**
23699a2dd95SBruce Richardson  * Create Graph.
23799a2dd95SBruce Richardson  *
23899a2dd95SBruce Richardson  * Create memory reel, detect loops and find isolated nodes.
23999a2dd95SBruce Richardson  *
24099a2dd95SBruce Richardson  * @param name
24199a2dd95SBruce Richardson  *   Unique name for this graph.
24299a2dd95SBruce Richardson  * @param prm
24399a2dd95SBruce Richardson  *   Graph parameter, includes node names and count to be included
24499a2dd95SBruce Richardson  *   in this graph.
24599a2dd95SBruce Richardson  *
24699a2dd95SBruce Richardson  * @return
24799a2dd95SBruce Richardson  *   Unique graph id on success, RTE_GRAPH_ID_INVALID otherwise.
24899a2dd95SBruce Richardson  */
24999a2dd95SBruce Richardson rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
25099a2dd95SBruce Richardson 
25199a2dd95SBruce Richardson /**
25299a2dd95SBruce Richardson  * Destroy Graph.
25399a2dd95SBruce Richardson  *
25499a2dd95SBruce Richardson  * Free Graph memory reel.
25599a2dd95SBruce Richardson  *
25699a2dd95SBruce Richardson  * @param id
25799a2dd95SBruce Richardson  *   id of the graph to destroy.
25899a2dd95SBruce Richardson  *
25999a2dd95SBruce Richardson  * @return
26099a2dd95SBruce Richardson  *   0 on success, error otherwise.
26199a2dd95SBruce Richardson  */
26299a2dd95SBruce Richardson int rte_graph_destroy(rte_graph_t id);
26399a2dd95SBruce Richardson 
26499a2dd95SBruce Richardson /**
265d6e2e9d8SZhirun Yan  * Clone Graph.
266d6e2e9d8SZhirun Yan  *
267d6e2e9d8SZhirun Yan  * Clone a graph from static graph (graph created from rte_graph_create()). And
268d6e2e9d8SZhirun Yan  * all cloned graphs attached to the parent graph MUST be destroyed together
269d6e2e9d8SZhirun Yan  * for fast schedule design limitation (stop ALL graph walk firstly).
270d6e2e9d8SZhirun Yan  *
271d6e2e9d8SZhirun Yan  * @param id
272d6e2e9d8SZhirun Yan  *   Static graph id to clone from.
273d6e2e9d8SZhirun Yan  * @param name
274d6e2e9d8SZhirun Yan  *   Name of the new graph. The library prepends the parent graph name to the
275d6e2e9d8SZhirun Yan  * user-specified name. The final graph name will be,
276d6e2e9d8SZhirun Yan  * "parent graph name" + "-" + name.
2771e2aed1aSZhirun Yan  * @param prm
2781e2aed1aSZhirun Yan  *   Graph parameter, includes model-specific parameters in this graph.
279d6e2e9d8SZhirun Yan  *
280d6e2e9d8SZhirun Yan  * @return
281d6e2e9d8SZhirun Yan  *   Valid graph id on success, RTE_GRAPH_ID_INVALID otherwise.
282d6e2e9d8SZhirun Yan  */
2831e2aed1aSZhirun Yan rte_graph_t rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_param *prm);
284d6e2e9d8SZhirun Yan 
285d6e2e9d8SZhirun Yan /**
28699a2dd95SBruce Richardson  * Get graph id from graph name.
28799a2dd95SBruce Richardson  *
28899a2dd95SBruce Richardson  * @param name
28999a2dd95SBruce Richardson  *   Name of the graph to get id.
29099a2dd95SBruce Richardson  *
29199a2dd95SBruce Richardson  * @return
29299a2dd95SBruce Richardson  *   Graph id on success, RTE_GRAPH_ID_INVALID otherwise.
29399a2dd95SBruce Richardson  */
29499a2dd95SBruce Richardson rte_graph_t rte_graph_from_name(const char *name);
29599a2dd95SBruce Richardson 
29699a2dd95SBruce Richardson /**
29799a2dd95SBruce Richardson  * Get graph name from graph id.
29899a2dd95SBruce Richardson  *
29999a2dd95SBruce Richardson  * @param id
30099a2dd95SBruce Richardson  *   id of the graph to get name.
30199a2dd95SBruce Richardson  *
30299a2dd95SBruce Richardson  * @return
30399a2dd95SBruce Richardson  *   Graph name on success, NULL otherwise.
30499a2dd95SBruce Richardson  */
30599a2dd95SBruce Richardson char *rte_graph_id_to_name(rte_graph_t id);
30699a2dd95SBruce Richardson 
30799a2dd95SBruce Richardson /**
30899a2dd95SBruce Richardson  * Export the graph as graph viz dot file
30999a2dd95SBruce Richardson  *
31099a2dd95SBruce Richardson  * @param name
31199a2dd95SBruce Richardson  *   Name of the graph to export.
31299a2dd95SBruce Richardson  * @param f
31399a2dd95SBruce Richardson  *   File pointer to export the graph.
31499a2dd95SBruce Richardson  *
31599a2dd95SBruce Richardson  * @return
31699a2dd95SBruce Richardson  *   0 on success, error otherwise.
31799a2dd95SBruce Richardson  */
31899a2dd95SBruce Richardson int rte_graph_export(const char *name, FILE *f);
31999a2dd95SBruce Richardson 
32099a2dd95SBruce Richardson /**
321ecb22a29SZhirun Yan  * Bind graph with specific lcore for mcore dispatch model.
322ecb22a29SZhirun Yan  *
323ecb22a29SZhirun Yan  * @param id
324ecb22a29SZhirun Yan  *   Graph id to get the pointer of graph object
325ecb22a29SZhirun Yan  * @param lcore
326ecb22a29SZhirun Yan  * The lcore where the graph will run on
327ecb22a29SZhirun Yan  * @return
328ecb22a29SZhirun Yan  *   0 on success, error otherwise.
329ecb22a29SZhirun Yan  */
330ecb22a29SZhirun Yan int rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore);
331ecb22a29SZhirun Yan 
332ecb22a29SZhirun Yan /**
333ecb22a29SZhirun Yan  * Unbind graph with lcore for mcore dispatch model
334ecb22a29SZhirun Yan  *
335ecb22a29SZhirun Yan  * @param id
336ecb22a29SZhirun Yan  * Graph id to get the pointer of graph object
337ecb22a29SZhirun Yan  */
338ecb22a29SZhirun Yan void rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id);
339ecb22a29SZhirun Yan 
340ecb22a29SZhirun Yan /**
34199a2dd95SBruce Richardson  * Get graph object from its name.
34299a2dd95SBruce Richardson  *
34399a2dd95SBruce Richardson  * Typical usage of this API to get graph objects in the worker thread and
34499a2dd95SBruce Richardson  * followed calling rte_graph_walk() in a loop.
34599a2dd95SBruce Richardson  *
34699a2dd95SBruce Richardson  * @param name
34799a2dd95SBruce Richardson  *   Name of the graph.
34899a2dd95SBruce Richardson  *
34999a2dd95SBruce Richardson  * @return
35099a2dd95SBruce Richardson  *   Graph pointer on success, NULL otherwise.
35199a2dd95SBruce Richardson  *
35299a2dd95SBruce Richardson  * @see rte_graph_walk()
35399a2dd95SBruce Richardson  */
35499a2dd95SBruce Richardson struct rte_graph *rte_graph_lookup(const char *name);
35599a2dd95SBruce Richardson 
35699a2dd95SBruce Richardson /**
35799a2dd95SBruce Richardson  * Get maximum number of graph available.
35899a2dd95SBruce Richardson  *
35999a2dd95SBruce Richardson  * @return
36099a2dd95SBruce Richardson  *   Maximum graph count.
36199a2dd95SBruce Richardson  */
36299a2dd95SBruce Richardson rte_graph_t rte_graph_max_count(void);
36399a2dd95SBruce Richardson 
36499a2dd95SBruce Richardson /**
36599a2dd95SBruce Richardson  * Dump the graph information to file.
36699a2dd95SBruce Richardson  *
36799a2dd95SBruce Richardson  * @param f
36899a2dd95SBruce Richardson  *   File pointer to dump graph info.
36999a2dd95SBruce Richardson  * @param id
37099a2dd95SBruce Richardson  *   Graph id to get graph info.
37199a2dd95SBruce Richardson  */
37299a2dd95SBruce Richardson void rte_graph_dump(FILE *f, rte_graph_t id);
37399a2dd95SBruce Richardson 
37499a2dd95SBruce Richardson /**
37599a2dd95SBruce Richardson  * Dump all graphs information to file
37699a2dd95SBruce Richardson  *
37799a2dd95SBruce Richardson  * @param f
37899a2dd95SBruce Richardson  *   File pointer to dump graph info.
37999a2dd95SBruce Richardson  */
38099a2dd95SBruce Richardson void rte_graph_list_dump(FILE *f);
38199a2dd95SBruce Richardson 
38299a2dd95SBruce Richardson /**
38399a2dd95SBruce Richardson  * Dump graph information along with node info to file
38499a2dd95SBruce Richardson  *
38599a2dd95SBruce Richardson  * @param f
38699a2dd95SBruce Richardson  *   File pointer to dump graph info.
38799a2dd95SBruce Richardson  * @param graph
38899a2dd95SBruce Richardson  *   Graph pointer to get graph info.
38999a2dd95SBruce Richardson  * @param all
39099a2dd95SBruce Richardson  *   true to dump nodes in the graph.
39199a2dd95SBruce Richardson  */
39299a2dd95SBruce Richardson void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
39399a2dd95SBruce Richardson 
39499a2dd95SBruce Richardson /** Macro to browse rte_node object after the graph creation */
39599a2dd95SBruce Richardson #define rte_graph_foreach_node(count, off, graph, node)                        \
39699a2dd95SBruce Richardson 	for (count = 0, off = graph->nodes_start,                              \
39799a2dd95SBruce Richardson 	     node = RTE_PTR_ADD(graph, off);                                   \
39899a2dd95SBruce Richardson 	     count < graph->nb_nodes;                                          \
39999a2dd95SBruce Richardson 	     off = node->next, node = RTE_PTR_ADD(graph, off), count++)
40099a2dd95SBruce Richardson 
40199a2dd95SBruce Richardson /**
40299a2dd95SBruce Richardson  * Get node object with in graph from id.
40399a2dd95SBruce Richardson  *
40499a2dd95SBruce Richardson  * @param graph_id
40599a2dd95SBruce Richardson  *   Graph id to get node pointer from.
40699a2dd95SBruce Richardson  * @param node_id
40799a2dd95SBruce Richardson  *   Node id to get node pointer.
40899a2dd95SBruce Richardson  *
40999a2dd95SBruce Richardson  * @return
41099a2dd95SBruce Richardson  *   Node pointer on success, NULL otherwise.
41199a2dd95SBruce Richardson  */
41299a2dd95SBruce Richardson struct rte_node *rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id);
41399a2dd95SBruce Richardson 
41499a2dd95SBruce Richardson /**
41599a2dd95SBruce Richardson  * Get node pointer with in graph from name.
41699a2dd95SBruce Richardson  *
41799a2dd95SBruce Richardson  * @param graph
41899a2dd95SBruce Richardson  *   Graph name to get node pointer from.
41999a2dd95SBruce Richardson  * @param name
42099a2dd95SBruce Richardson  *   Node name to get the node pointer.
42199a2dd95SBruce Richardson  *
42299a2dd95SBruce Richardson  * @return
42399a2dd95SBruce Richardson  *   Node pointer on success, NULL otherwise.
42499a2dd95SBruce Richardson  */
42599a2dd95SBruce Richardson struct rte_node *rte_graph_node_get_by_name(const char *graph,
42699a2dd95SBruce Richardson 					    const char *name);
42799a2dd95SBruce Richardson 
42899a2dd95SBruce Richardson /**
42999a2dd95SBruce Richardson  * Create graph stats cluster to aggregate runtime node stats.
43099a2dd95SBruce Richardson  *
43199a2dd95SBruce Richardson  * @param prm
43299a2dd95SBruce Richardson  *   Parameters including file pointer to dump stats,
43399a2dd95SBruce Richardson  *   Graph pattern to create cluster and callback function.
43499a2dd95SBruce Richardson  *
43599a2dd95SBruce Richardson  * @return
43699a2dd95SBruce Richardson  *   Valid pointer on success, NULL otherwise.
43799a2dd95SBruce Richardson  */
43899a2dd95SBruce Richardson struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
43999a2dd95SBruce Richardson 			const struct rte_graph_cluster_stats_param *prm);
44099a2dd95SBruce Richardson 
44199a2dd95SBruce Richardson /**
44299a2dd95SBruce Richardson  * Destroy cluster stats.
44399a2dd95SBruce Richardson  *
44499a2dd95SBruce Richardson  * @param stat
44599a2dd95SBruce Richardson  *    Valid cluster pointer to destroy.
44699a2dd95SBruce Richardson  */
44799a2dd95SBruce Richardson void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
44899a2dd95SBruce Richardson 
44999a2dd95SBruce Richardson /**
45099a2dd95SBruce Richardson  * Get stats to application.
45199a2dd95SBruce Richardson  *
45299a2dd95SBruce Richardson  * @param[out] stat
45399a2dd95SBruce Richardson  *   Cluster status.
45499a2dd95SBruce Richardson  * @param skip_cb
45599a2dd95SBruce Richardson  *   true to skip callback function invocation.
45699a2dd95SBruce Richardson  */
45799a2dd95SBruce Richardson void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
45899a2dd95SBruce Richardson 				 bool skip_cb);
45999a2dd95SBruce Richardson 
46099a2dd95SBruce Richardson /**
46199a2dd95SBruce Richardson  * Reset cluster stats to zero.
46299a2dd95SBruce Richardson  *
46399a2dd95SBruce Richardson  * @param stat
46499a2dd95SBruce Richardson  *   Valid cluster stats pointer.
46599a2dd95SBruce Richardson  */
46699a2dd95SBruce Richardson void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
46799a2dd95SBruce Richardson 
46899a2dd95SBruce Richardson /**
469*070db97eSPavan Nikhilesh  * Structure defines the number of xstats a given node has and each xstat
470*070db97eSPavan Nikhilesh  * description.
471*070db97eSPavan Nikhilesh  */
472*070db97eSPavan Nikhilesh struct rte_node_xstats {
473*070db97eSPavan Nikhilesh 	uint16_t nb_xstats;			     /**< Number of xstats. */
474*070db97eSPavan Nikhilesh 	char xstat_desc[][RTE_NODE_XSTAT_DESC_SIZE]; /**< Names of xstats. */
475*070db97eSPavan Nikhilesh };
476*070db97eSPavan Nikhilesh 
477*070db97eSPavan Nikhilesh /**
47899a2dd95SBruce Richardson  * Structure defines the node registration parameters.
47999a2dd95SBruce Richardson  *
48099a2dd95SBruce Richardson  * @see __rte_node_register(), RTE_NODE_REGISTER()
48199a2dd95SBruce Richardson  */
48299a2dd95SBruce Richardson struct rte_node_register {
48399a2dd95SBruce Richardson 	char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */
48499a2dd95SBruce Richardson 	uint64_t flags;		      /**< Node configuration flag. */
48599a2dd95SBruce Richardson #define RTE_NODE_SOURCE_F (1ULL << 0) /**< Node type is source. */
48699a2dd95SBruce Richardson 	rte_node_process_t process; /**< Node process function. */
48799a2dd95SBruce Richardson 	rte_node_init_t init;       /**< Node init function. */
48899a2dd95SBruce Richardson 	rte_node_fini_t fini;       /**< Node fini function. */
489*070db97eSPavan Nikhilesh 	struct rte_node_xstats *xstats; /**< Node specific xstats. */
49099a2dd95SBruce Richardson 	rte_node_t id;		    /**< Node Identifier. */
49199a2dd95SBruce Richardson 	rte_node_t parent_id;       /**< Identifier of parent node. */
49299a2dd95SBruce Richardson 	rte_edge_t nb_edges;        /**< Number of edges from this node. */
49399a2dd95SBruce Richardson 	const char *next_nodes[];   /**< Names of next nodes. */
49499a2dd95SBruce Richardson };
49599a2dd95SBruce Richardson 
49699a2dd95SBruce Richardson /**
49799a2dd95SBruce Richardson  * Register new packet processing node. Nodes can be registered
49899a2dd95SBruce Richardson  * dynamically via this call or statically via the RTE_NODE_REGISTER
49999a2dd95SBruce Richardson  * macro.
50099a2dd95SBruce Richardson  *
50199a2dd95SBruce Richardson  * @param node
50299a2dd95SBruce Richardson  *   Valid node pointer with name, process function and next_nodes.
50399a2dd95SBruce Richardson  *
50499a2dd95SBruce Richardson  * @return
50599a2dd95SBruce Richardson  *   Valid node id on success, RTE_NODE_ID_INVALID otherwise.
50699a2dd95SBruce Richardson  *
50799a2dd95SBruce Richardson  * @see RTE_NODE_REGISTER()
50899a2dd95SBruce Richardson  */
50999a2dd95SBruce Richardson rte_node_t __rte_node_register(const struct rte_node_register *node);
51099a2dd95SBruce Richardson 
51199a2dd95SBruce Richardson /**
51299a2dd95SBruce Richardson  * Register a static node.
51399a2dd95SBruce Richardson  *
51499a2dd95SBruce Richardson  * The static node is registered through the constructor scheme, thereby, it can
51599a2dd95SBruce Richardson  * be used in a multi-process scenario.
51699a2dd95SBruce Richardson  *
51799a2dd95SBruce Richardson  * @param node
51899a2dd95SBruce Richardson  *   Valid node pointer with name, process function, and next_nodes.
51999a2dd95SBruce Richardson  */
52099a2dd95SBruce Richardson #define RTE_NODE_REGISTER(node)                                                \
52199a2dd95SBruce Richardson 	RTE_INIT(rte_node_register_##node)                                     \
52299a2dd95SBruce Richardson 	{                                                                      \
52399a2dd95SBruce Richardson 		node.parent_id = RTE_NODE_ID_INVALID;                          \
52499a2dd95SBruce Richardson 		node.id = __rte_node_register(&node);                          \
52599a2dd95SBruce Richardson 	}
52699a2dd95SBruce Richardson 
52799a2dd95SBruce Richardson /**
52899a2dd95SBruce Richardson  * Clone a node from static node(node created from RTE_NODE_REGISTER).
52999a2dd95SBruce Richardson  *
53099a2dd95SBruce Richardson  * @param id
53199a2dd95SBruce Richardson  *   Static node id to clone from.
53299a2dd95SBruce Richardson  * @param name
53399a2dd95SBruce Richardson  *   Name of the new node. The library prepends the parent node name to the
53499a2dd95SBruce Richardson  * user-specified name. The final node name will be,
53599a2dd95SBruce Richardson  * "parent node name" + "-" + name.
53699a2dd95SBruce Richardson  *
53799a2dd95SBruce Richardson  * @return
53899a2dd95SBruce Richardson  *   Valid node id on success, RTE_NODE_ID_INVALID otherwise.
53999a2dd95SBruce Richardson  */
54099a2dd95SBruce Richardson rte_node_t rte_node_clone(rte_node_t id, const char *name);
54199a2dd95SBruce Richardson 
54299a2dd95SBruce Richardson /**
54399a2dd95SBruce Richardson  * Get node id from node name.
54499a2dd95SBruce Richardson  *
54599a2dd95SBruce Richardson  * @param name
54699a2dd95SBruce Richardson  *   Valid node name. In the case of the cloned node, the name will be
54799a2dd95SBruce Richardson  * "parent node name" + "-" + name.
54899a2dd95SBruce Richardson  *
54999a2dd95SBruce Richardson  * @return
55099a2dd95SBruce Richardson  *   Valid node id on success, RTE_NODE_ID_INVALID otherwise.
55199a2dd95SBruce Richardson  */
55299a2dd95SBruce Richardson rte_node_t rte_node_from_name(const char *name);
55399a2dd95SBruce Richardson 
55499a2dd95SBruce Richardson /**
55599a2dd95SBruce Richardson  * Get node name from node id.
55699a2dd95SBruce Richardson  *
55799a2dd95SBruce Richardson  * @param id
55899a2dd95SBruce Richardson  *   Valid node id.
55999a2dd95SBruce Richardson  *
56099a2dd95SBruce Richardson  * @return
56199a2dd95SBruce Richardson  *   Valid node name on success, NULL otherwise.
56299a2dd95SBruce Richardson  */
56399a2dd95SBruce Richardson char *rte_node_id_to_name(rte_node_t id);
56499a2dd95SBruce Richardson 
56599a2dd95SBruce Richardson /**
56699a2dd95SBruce Richardson  * Get the number of edges(next-nodes) for a node from node id.
56799a2dd95SBruce Richardson  *
56899a2dd95SBruce Richardson  * @param id
56999a2dd95SBruce Richardson  *   Valid node id.
57099a2dd95SBruce Richardson  *
57199a2dd95SBruce Richardson  * @return
57299a2dd95SBruce Richardson  *   Valid edge count on success, RTE_EDGE_ID_INVALID otherwise.
57399a2dd95SBruce Richardson  */
57499a2dd95SBruce Richardson rte_edge_t rte_node_edge_count(rte_node_t id);
57599a2dd95SBruce Richardson 
57699a2dd95SBruce Richardson /**
57799a2dd95SBruce Richardson  * Update the edges for a node from node id.
57899a2dd95SBruce Richardson  *
57999a2dd95SBruce Richardson  * @param id
58099a2dd95SBruce Richardson  *   Valid node id.
58199a2dd95SBruce Richardson  * @param from
58299a2dd95SBruce Richardson  *   Index to update the edges from. RTE_EDGE_ID_INVALID is valid,
58399a2dd95SBruce Richardson  * in that case, it will be added to the end of the list.
58499a2dd95SBruce Richardson  * @param next_nodes
58599a2dd95SBruce Richardson  *   Name of the edges to update.
58699a2dd95SBruce Richardson  * @param nb_edges
58799a2dd95SBruce Richardson  *   Number of edges to update.
58899a2dd95SBruce Richardson  *
58999a2dd95SBruce Richardson  * @return
59099a2dd95SBruce Richardson  *   Valid edge count on success, 0 otherwise.
59199a2dd95SBruce Richardson  */
59299a2dd95SBruce Richardson rte_edge_t rte_node_edge_update(rte_node_t id, rte_edge_t from,
59399a2dd95SBruce Richardson 				const char **next_nodes, uint16_t nb_edges);
59499a2dd95SBruce Richardson 
59599a2dd95SBruce Richardson /**
59699a2dd95SBruce Richardson  * Shrink the edges to a given size.
59799a2dd95SBruce Richardson  *
59899a2dd95SBruce Richardson  * @param id
59999a2dd95SBruce Richardson  *   Valid node id.
60099a2dd95SBruce Richardson  * @param size
60199a2dd95SBruce Richardson  *   New size to shrink the edges.
60299a2dd95SBruce Richardson  *
60399a2dd95SBruce Richardson  * @return
60499a2dd95SBruce Richardson  *   New size on success, RTE_EDGE_ID_INVALID otherwise.
60599a2dd95SBruce Richardson  */
60699a2dd95SBruce Richardson rte_edge_t rte_node_edge_shrink(rte_node_t id, rte_edge_t size);
60799a2dd95SBruce Richardson 
60899a2dd95SBruce Richardson /**
60999a2dd95SBruce Richardson  * Get the edge names from a given node.
61099a2dd95SBruce Richardson  *
61199a2dd95SBruce Richardson  * @param id
61299a2dd95SBruce Richardson  *   Valid node id.
61399a2dd95SBruce Richardson  * @param[out] next_nodes
61499a2dd95SBruce Richardson  *   Buffer to copy the edge names. The NULL value is allowed in that case,
61599a2dd95SBruce Richardson  * the function returns the size of the array that needs to be allocated.
61699a2dd95SBruce Richardson  *
61799a2dd95SBruce Richardson  * @return
61899a2dd95SBruce Richardson  *   When next_nodes == NULL, it returns the size of the array else
61999a2dd95SBruce Richardson  *  number of item copied.
62099a2dd95SBruce Richardson  */
62199a2dd95SBruce Richardson rte_node_t rte_node_edge_get(rte_node_t id, char *next_nodes[]);
62299a2dd95SBruce Richardson 
62399a2dd95SBruce Richardson /**
62499a2dd95SBruce Richardson  * Get maximum nodes available.
62599a2dd95SBruce Richardson  *
62699a2dd95SBruce Richardson  * @return
62799a2dd95SBruce Richardson  *   Maximum nodes count.
62899a2dd95SBruce Richardson  */
62999a2dd95SBruce Richardson rte_node_t rte_node_max_count(void);
63099a2dd95SBruce Richardson 
63199a2dd95SBruce Richardson /**
63299a2dd95SBruce Richardson  * Dump node info to file.
63399a2dd95SBruce Richardson  *
63499a2dd95SBruce Richardson  * @param f
63599a2dd95SBruce Richardson  *   File pointer to dump the node info.
63699a2dd95SBruce Richardson  * @param id
63799a2dd95SBruce Richardson  *   Node id to get the info.
63899a2dd95SBruce Richardson  */
63999a2dd95SBruce Richardson void rte_node_dump(FILE *f, rte_node_t id);
64099a2dd95SBruce Richardson 
64199a2dd95SBruce Richardson /**
64299a2dd95SBruce Richardson  * Dump all node info to file.
64399a2dd95SBruce Richardson  *
64499a2dd95SBruce Richardson  * @param f
64599a2dd95SBruce Richardson  *   File pointer to dump the node info.
64699a2dd95SBruce Richardson  */
64799a2dd95SBruce Richardson void rte_node_list_dump(FILE *f);
64899a2dd95SBruce Richardson 
64999a2dd95SBruce Richardson /**
65099a2dd95SBruce Richardson  * Test the validity of node id.
65199a2dd95SBruce Richardson  *
65299a2dd95SBruce Richardson  * @param id
65399a2dd95SBruce Richardson  *   Node id to check.
65499a2dd95SBruce Richardson  *
65599a2dd95SBruce Richardson  * @return
65699a2dd95SBruce Richardson  *   1 if valid id, 0 otherwise.
65799a2dd95SBruce Richardson  */
65899a2dd95SBruce Richardson static __rte_always_inline int
65999a2dd95SBruce Richardson rte_node_is_invalid(rte_node_t id)
66099a2dd95SBruce Richardson {
66199a2dd95SBruce Richardson 	return (id == RTE_NODE_ID_INVALID);
66299a2dd95SBruce Richardson }
66399a2dd95SBruce Richardson 
66499a2dd95SBruce Richardson /**
66599a2dd95SBruce Richardson  * Test the validity of edge id.
66699a2dd95SBruce Richardson  *
66799a2dd95SBruce Richardson  * @param id
66899a2dd95SBruce Richardson  *   Edge node id to check.
66999a2dd95SBruce Richardson  *
67099a2dd95SBruce Richardson  * @return
67199a2dd95SBruce Richardson  *   1 if valid id, 0 otherwise.
67299a2dd95SBruce Richardson  */
67399a2dd95SBruce Richardson static __rte_always_inline int
67499a2dd95SBruce Richardson rte_edge_is_invalid(rte_edge_t id)
67599a2dd95SBruce Richardson {
67699a2dd95SBruce Richardson 	return (id == RTE_EDGE_ID_INVALID);
67799a2dd95SBruce Richardson }
67899a2dd95SBruce Richardson 
67999a2dd95SBruce Richardson /**
68099a2dd95SBruce Richardson  * Test the validity of graph id.
68199a2dd95SBruce Richardson  *
68299a2dd95SBruce Richardson  * @param id
68399a2dd95SBruce Richardson  *   Graph id to check.
68499a2dd95SBruce Richardson  *
68599a2dd95SBruce Richardson  * @return
68699a2dd95SBruce Richardson  *   1 if valid id, 0 otherwise.
68799a2dd95SBruce Richardson  */
68899a2dd95SBruce Richardson static __rte_always_inline int
68999a2dd95SBruce Richardson rte_graph_is_invalid(rte_graph_t id)
69099a2dd95SBruce Richardson {
69199a2dd95SBruce Richardson 	return (id == RTE_GRAPH_ID_INVALID);
69299a2dd95SBruce Richardson }
69399a2dd95SBruce Richardson 
69499a2dd95SBruce Richardson /**
69599a2dd95SBruce Richardson  * Test stats feature support.
69699a2dd95SBruce Richardson  *
69799a2dd95SBruce Richardson  * @return
69899a2dd95SBruce Richardson  *   1 if stats enabled, 0 otherwise.
69999a2dd95SBruce Richardson  */
70099a2dd95SBruce Richardson static __rte_always_inline int
70199a2dd95SBruce Richardson rte_graph_has_stats_feature(void)
70299a2dd95SBruce Richardson {
70399a2dd95SBruce Richardson #ifdef RTE_LIBRTE_GRAPH_STATS
70499a2dd95SBruce Richardson 	return RTE_LIBRTE_GRAPH_STATS;
70599a2dd95SBruce Richardson #else
70699a2dd95SBruce Richardson 	return 0;
70799a2dd95SBruce Richardson #endif
70899a2dd95SBruce Richardson }
70999a2dd95SBruce Richardson 
71099a2dd95SBruce Richardson #ifdef __cplusplus
71199a2dd95SBruce Richardson }
71299a2dd95SBruce Richardson #endif
71399a2dd95SBruce Richardson 
71499a2dd95SBruce Richardson #endif /* _RTE_GRAPH_H_ */
715