1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2020 Marvell International Ltd.
5 #ifndef _RTE_GRAPH_PRIVATE_H_
6 #define _RTE_GRAPH_PRIVATE_H_
11 #include <rte_common.h>
14 #include "rte_graph.h"
15 #include "rte_graph_worker.h"
17 extern int rte_graph_logtype;
19 #define GRAPH_LOG(level, ...) \
20 rte_log(RTE_LOG_##level, rte_graph_logtype, \
21 RTE_FMT("GRAPH: %s():%u " RTE_FMT_HEAD(__VA_ARGS__, ) "\n", \
22 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__, )))
24 #define graph_err(...) GRAPH_LOG(ERR, __VA_ARGS__)
25 #define graph_info(...) GRAPH_LOG(INFO, __VA_ARGS__)
26 #define graph_dbg(...) GRAPH_LOG(DEBUG, __VA_ARGS__)
28 #define ID_CHECK(id, id_max) \
30 if ((id) >= (id_max)) { \
36 #define SET_ERR_JMP(err, where, fmt, ...) \
38 graph_err(fmt, ##__VA_ARGS__); \
46 * Structure that holds node internal data.
49 STAILQ_ENTRY(node) next; /**< Next node in the list. */
50 char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */
51 uint64_t flags; /**< Node configuration flag. */
52 rte_node_process_t process; /**< Node process function. */
53 rte_node_init_t init; /**< Node init function. */
54 rte_node_fini_t fini; /**< Node fini function. */
55 rte_node_t id; /**< Allocated identifier for the node. */
56 rte_node_t parent_id; /**< Parent node identifier. */
57 rte_edge_t nb_edges; /**< Number of edges from this node. */
58 char next_nodes[][RTE_NODE_NAMESIZE]; /**< Names of next nodes. */
64 * Structure that holds the graph node data.
67 STAILQ_ENTRY(graph_node) next; /**< Next graph node in the list. */
68 struct node *node; /**< Pointer to internal node. */
69 bool visited; /**< Flag used in BFS to mark node visited. */
70 struct graph_node *adjacency_list[]; /**< Adjacency list of the node. */
76 * Structure that holds graph internal data.
79 STAILQ_ENTRY(graph) next;
80 /**< List of graphs. */
81 char name[RTE_GRAPH_NAMESIZE];
82 /**< Name of the graph. */
83 const struct rte_memzone *mz;
84 /**< Memzone to store graph data. */
85 rte_graph_off_t nodes_start;
86 /**< Node memory start offset in graph reel. */
87 rte_node_t src_node_count;
88 /**< Number of source nodes in a graph. */
89 struct rte_graph *graph;
90 /**< Pointer to graph data. */
91 rte_node_t node_count;
92 /**< Total number of nodes. */
94 /**< Circular buffer start offset in graph reel. */
96 /**< Circular buffer mask for wrap around. */
98 /**< Graph identifier. */
100 /**< Memory size of the graph. */
102 /**< Socket identifier where memory is allocated. */
103 STAILQ_HEAD(gnode_list, graph_node) node_list;
104 /**< Nodes in a graph. */
108 STAILQ_HEAD(node_head, node);
113 * Get the head of the node list.
116 * Pointer to the node head.
118 struct node_head *node_list_head_get(void);
123 * Get node pointer from node name.
126 * Pointer to character string containing the node name.
129 * Pointer to the node.
131 struct node *node_from_name(const char *name);
133 /* Graph list functions */
134 STAILQ_HEAD(graph_head, graph);
139 * Get the head of the graph list.
142 * Pointer to the graph head.
144 struct graph_head *graph_list_head_get(void);
150 * Take a lock on the graph internal spin lock.
152 void graph_spinlock_lock(void);
157 * Release a lock on the graph internal spin lock.
159 void graph_spinlock_unlock(void);
161 /* Graph operations */
165 * Run a BFS(Breadth First Search) on the graph marking all
166 * the graph nodes as visited.
169 * Pointer to the internal graph object.
171 * Pointer to the starting graph node.
175 * - -ENOMEM: Not enough memory for BFS.
177 int graph_bfs(struct graph *graph, struct graph_node *start);
182 * Check if there is an isolated node in the given graph.
185 * Pointer to the internal graph object.
188 * - 0: No isolated node found.
189 * - 1: Isolated node found.
191 int graph_has_isolated_node(struct graph *graph);
196 * Check whether a node in the graph has next_node to a source node.
199 * Pointer to the internal graph object.
202 * - 0: Node has an edge to source node.
203 * - 1: Node doesn't have an edge to source node.
205 int graph_node_has_edge_to_src_node(struct graph *graph);
210 * Checks whether node in the graph has a edge to itself i.e. forms a
214 * Pointer to the internal graph object.
217 * - 0: Node has an edge to itself.
218 * - 1: Node doesn't have an edge to itself.
220 int graph_node_has_loop_edge(struct graph *graph);
225 * Get the count of source nodes in the graph.
228 * Pointer to the internal graph object.
231 * Number of source nodes.
233 rte_node_t graph_src_nodes_count(struct graph *graph);
238 * Get the count of total number of nodes in the graph.
241 * Pointer to the internal graph object.
246 rte_node_t graph_nodes_count(struct graph *graph);
251 * Clear the visited flag of all the nodes in the graph.
254 * Pointer to the internal graph object.
256 void graph_mark_nodes_as_not_visited(struct graph *graph);
258 /* Fast path graph memory populate unctions */
263 * Create fast-path memory for the graph and nodes.
266 * Pointer to the internal graph object.
270 * - -ENOMEM: Not enough for graph and nodes.
271 * - -EINVAL: Graph nodes not found.
273 int graph_fp_mem_create(struct graph *graph);
278 * Free fast-path memory used by graph and nodes.
281 * Pointer to the internal graph object.
285 * - <0: Graph memzone related error.
287 int graph_fp_mem_destroy(struct graph *graph);
289 /* Lookup functions */
293 * Get graph node object from node id.
296 * Pointer to rte_graph object.
301 * Pointer to rte_node if identifier is valid else NULL.
303 struct rte_node *graph_node_id_to_ptr(const struct rte_graph *graph,
309 * Get graph node object from node name.
312 * Pointer to rte_graph object.
314 * Pointer to character string holding the node name.
317 * Pointer to rte_node if identifier is valid else NULL.
319 struct rte_node *graph_node_name_to_ptr(const struct rte_graph *graph,
320 const char *node_name);
322 /* Debug functions */
326 * Dump internal graph object data.
329 * FILE pointer to dump the data.
331 * Pointer to the internal graph object.
333 void graph_dump(FILE *f, struct graph *g);
338 * Dump internal node object data.
341 * FILE pointer to dump the info.
343 * Pointer to the internal node object.
345 void node_dump(FILE *f, struct node *n);
347 #endif /* _RTE_GRAPH_PRIVATE_H_ */