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"
16 extern int rte_graph_logtype;
18 #define GRAPH_LOG(level, ...) \
19 rte_log(RTE_LOG_##level, rte_graph_logtype, \
20 RTE_FMT("GRAPH: %s():%u " RTE_FMT_HEAD(__VA_ARGS__, ) "\n", \
21 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__, )))
23 #define graph_err(...) GRAPH_LOG(ERR, __VA_ARGS__)
24 #define graph_info(...) GRAPH_LOG(INFO, __VA_ARGS__)
25 #define graph_dbg(...) GRAPH_LOG(DEBUG, __VA_ARGS__)
27 #define ID_CHECK(id, id_max) \
29 if ((id) >= (id_max)) { \
35 #define SET_ERR_JMP(err, where, fmt, ...) \
37 graph_err(fmt, ##__VA_ARGS__); \
45 * Structure that holds node internal data.
48 STAILQ_ENTRY(node) next; /**< Next node in the list. */
49 char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */
50 uint64_t flags; /**< Node configuration flag. */
51 rte_node_process_t process; /**< Node process function. */
52 rte_node_init_t init; /**< Node init function. */
53 rte_node_fini_t fini; /**< Node fini function. */
54 rte_node_t id; /**< Allocated identifier for the node. */
55 rte_node_t parent_id; /**< Parent node identifier. */
56 rte_edge_t nb_edges; /**< Number of edges from this node. */
57 char next_nodes[][RTE_NODE_NAMESIZE]; /**< Names of next nodes. */
63 * Structure that holds the graph node data.
66 STAILQ_ENTRY(graph_node) next; /**< Next graph node in the list. */
67 struct node *node; /**< Pointer to internal node. */
68 bool visited; /**< Flag used in BFS to mark node visited. */
69 struct graph_node *adjacency_list[]; /**< Adjacency list of the node. */
75 * Structure that holds graph internal data.
78 STAILQ_ENTRY(graph) next;
79 /**< List of graphs. */
80 char name[RTE_GRAPH_NAMESIZE];
81 /**< Name of the graph. */
82 const struct rte_memzone *mz;
83 /**< Memzone to store graph data. */
84 rte_graph_off_t nodes_start;
85 /**< Node memory start offset in graph reel. */
86 rte_node_t src_node_count;
87 /**< Number of source nodes in a graph. */
88 struct rte_graph *graph;
89 /**< Pointer to graph data. */
90 rte_node_t node_count;
91 /**< Total number of nodes. */
93 /**< Circular buffer start offset in graph reel. */
95 /**< Circular buffer mask for wrap around. */
97 /**< Graph identifier. */
99 /**< Memory size of the graph. */
101 /**< Socket identifier where memory is allocated. */
102 STAILQ_HEAD(gnode_list, graph_node) node_list;
103 /**< Nodes in a graph. */
107 STAILQ_HEAD(node_head, node);
112 * Get the head of the node list.
115 * Pointer to the node head.
117 struct node_head *node_list_head_get(void);
122 * Get node pointer from node name.
125 * Pointer to character string containing the node name.
128 * Pointer to the node.
130 struct node *node_from_name(const char *name);
132 /* Graph list functions */
133 STAILQ_HEAD(graph_head, graph);
138 * Get the head of the graph list.
141 * Pointer to the graph head.
143 struct graph_head *graph_list_head_get(void);
149 * Take a lock on the graph internal spin lock.
151 void graph_spinlock_lock(void);
156 * Release a lock on the graph internal spin lock.
158 void graph_spinlock_unlock(void);
160 /* Graph operations */
164 * Run a BFS(Breadth First Search) on the graph marking all
165 * the graph nodes as visited.
168 * Pointer to the internal graph object.
170 * Pointer to the starting graph node.
174 * - -ENOMEM: Not enough memory for BFS.
176 int graph_bfs(struct graph *graph, struct graph_node *start);
181 * Check if there is an isolated node in the given graph.
184 * Pointer to the internal graph object.
187 * - 0: No isolated node found.
188 * - 1: Isolated node found.
190 int graph_has_isolated_node(struct graph *graph);
195 * Check whether a node in the graph has next_node to a source node.
198 * Pointer to the internal graph object.
201 * - 0: Node has an edge to source node.
202 * - 1: Node doesn't have an edge to source node.
204 int graph_node_has_edge_to_src_node(struct graph *graph);
209 * Checks whether node in the graph has a edge to itself i.e. forms a
213 * Pointer to the internal graph object.
216 * - 0: Node has an edge to itself.
217 * - 1: Node doesn't have an edge to itself.
219 int graph_node_has_loop_edge(struct graph *graph);
224 * Get the count of source nodes in the graph.
227 * Pointer to the internal graph object.
230 * Number of source nodes.
232 rte_node_t graph_src_nodes_count(struct graph *graph);
237 * Get the count of total number of nodes in the graph.
240 * Pointer to the internal graph object.
245 rte_node_t graph_nodes_count(struct graph *graph);
250 * Clear the visited flag of all the nodes in the graph.
253 * Pointer to the internal graph object.
255 void graph_mark_nodes_as_not_visited(struct graph *graph);
261 * Dump internal node object data.
264 * FILE pointer to dump the info.
266 * Pointer to the internal node object.
268 void node_dump(FILE *f, struct node *n);
270 #endif /* _RTE_GRAPH_PRIVATE_H_ */