DPDK  23.03.0
rte_graph.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4 
5 #ifndef _RTE_GRAPH_H_
6 #define _RTE_GRAPH_H_
7 
26 #include <stdbool.h>
27 #include <stdio.h>
28 
29 #include <rte_common.h>
30 #include <rte_compat.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define RTE_GRAPH_NAMESIZE 64
37 #define RTE_NODE_NAMESIZE 64
38 #define RTE_GRAPH_PCAP_FILE_SZ 64
39 #define RTE_GRAPH_OFF_INVALID UINT32_MAX
40 #define RTE_NODE_ID_INVALID UINT32_MAX
41 #define RTE_EDGE_ID_INVALID UINT16_MAX
42 #define RTE_GRAPH_ID_INVALID UINT16_MAX
43 #define RTE_GRAPH_FENCE 0xdeadbeef12345678ULL
45 typedef uint32_t rte_graph_off_t;
46 typedef uint32_t rte_node_t;
47 typedef uint16_t rte_edge_t;
48 typedef uint16_t rte_graph_t;
51 #if RTE_GRAPH_BURST_SIZE == 1
52 #define RTE_GRAPH_BURST_SIZE_LOG2 0
53 #elif RTE_GRAPH_BURST_SIZE == 2
54 #define RTE_GRAPH_BURST_SIZE_LOG2 1
55 #elif RTE_GRAPH_BURST_SIZE == 4
56 #define RTE_GRAPH_BURST_SIZE_LOG2 2
57 #elif RTE_GRAPH_BURST_SIZE == 8
58 #define RTE_GRAPH_BURST_SIZE_LOG2 3
59 #elif RTE_GRAPH_BURST_SIZE == 16
60 #define RTE_GRAPH_BURST_SIZE_LOG2 4
61 #elif RTE_GRAPH_BURST_SIZE == 32
62 #define RTE_GRAPH_BURST_SIZE_LOG2 5
63 #elif RTE_GRAPH_BURST_SIZE == 64
64 #define RTE_GRAPH_BURST_SIZE_LOG2 6
65 #elif RTE_GRAPH_BURST_SIZE == 128
66 #define RTE_GRAPH_BURST_SIZE_LOG2 7
67 #elif RTE_GRAPH_BURST_SIZE == 256
68 #define RTE_GRAPH_BURST_SIZE_LOG2 8
69 #else
70 #error "Unsupported burst size"
71 #endif
72 
73 /* Forward declaration */
74 struct rte_node;
75 struct rte_graph;
76 struct rte_graph_cluster_stats;
100 typedef uint16_t (*rte_node_process_t)(struct rte_graph *graph,
101  struct rte_node *node, void **objs,
102  uint16_t nb_objs);
103 
120 typedef int (*rte_node_init_t)(const struct rte_graph *graph,
121  struct rte_node *node);
122 
136 typedef void (*rte_node_fini_t)(const struct rte_graph *graph,
137  struct rte_node *node);
138 
155 typedef int (*rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
156  void *cookie, const struct rte_graph_cluster_node_stats *stats);
157 
164  int socket_id;
165  uint16_t nb_node_patterns;
166  const char **node_patterns;
169  bool pcap_enable;
172 };
173 
187  union {
188  void *cookie;
189  FILE *f;
190  };
191  uint16_t nb_graph_patterns;
192  const char **graph_patterns;
194 };
195 
202  uint64_t ts;
203  uint64_t calls;
204  uint64_t objs;
205  uint64_t cycles;
207  uint64_t prev_ts;
208  uint64_t prev_calls;
209  uint64_t prev_objs;
210  uint64_t prev_cycles;
212  uint64_t realloc_count;
215  uint64_t hz;
216  char name[RTE_NODE_NAMESIZE];
218 
233 __rte_experimental
234 rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
235 
247 __rte_experimental
249 
259 __rte_experimental
260 rte_graph_t rte_graph_from_name(const char *name);
261 
271 __rte_experimental
273 
285 __rte_experimental
286 int rte_graph_export(const char *name, FILE *f);
287 
302 __rte_experimental
303 struct rte_graph *rte_graph_lookup(const char *name);
304 
311 __rte_experimental
313 
322 __rte_experimental
323 void rte_graph_dump(FILE *f, rte_graph_t id);
324 
331 __rte_experimental
332 void rte_graph_list_dump(FILE *f);
333 
344 __rte_experimental
345 void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
346 
348 #define rte_graph_foreach_node(count, off, graph, node) \
349  for (count = 0, off = graph->nodes_start, \
350  node = RTE_PTR_ADD(graph, off); \
351  count < graph->nb_nodes; \
352  off = node->next, node = RTE_PTR_ADD(graph, off), count++)
353 
365 __rte_experimental
366 struct rte_node *rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id);
367 
379 __rte_experimental
380 struct rte_node *rte_graph_node_get_by_name(const char *graph,
381  const char *name);
382 
393 __rte_experimental
394 struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
395  const struct rte_graph_cluster_stats_param *prm);
396 
403 __rte_experimental
404 void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
405 
414 __rte_experimental
415 void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
416  bool skip_cb);
417 
424 __rte_experimental
425 void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
426 
433  char name[RTE_NODE_NAMESIZE];
434  uint64_t flags;
435 #define RTE_NODE_SOURCE_F (1ULL << 0)
436  rte_node_process_t process;
437  rte_node_init_t init;
438  rte_node_fini_t fini;
439  rte_node_t id;
440  rte_node_t parent_id;
441  rte_edge_t nb_edges;
442  const char *next_nodes[];
443 };
444 
458 __rte_experimental
460 
470 #define RTE_NODE_REGISTER(node) \
471  RTE_INIT(rte_node_register_##node) \
472  { \
473  node.parent_id = RTE_NODE_ID_INVALID; \
474  node.id = __rte_node_register(&node); \
475  }
476 
490 __rte_experimental
491 rte_node_t rte_node_clone(rte_node_t id, const char *name);
492 
503 __rte_experimental
504 rte_node_t rte_node_from_name(const char *name);
505 
515 __rte_experimental
517 
527 __rte_experimental
529 
546 __rte_experimental
548  const char **next_nodes, uint16_t nb_edges);
549 
561 __rte_experimental
563 
577 __rte_experimental
578 rte_node_t rte_node_edge_get(rte_node_t id, char *next_nodes[]);
579 
586 __rte_experimental
588 
597 __rte_experimental
598 void rte_node_dump(FILE *f, rte_node_t id);
599 
606 __rte_experimental
607 void rte_node_list_dump(FILE *f);
608 
618 static __rte_always_inline int
620 {
621  return (id == RTE_NODE_ID_INVALID);
622 }
623 
633 static __rte_always_inline int
635 {
636  return (id == RTE_EDGE_ID_INVALID);
637 }
638 
648 static __rte_always_inline int
650 {
651  return (id == RTE_GRAPH_ID_INVALID);
652 }
653 
660 static __rte_always_inline int
662 {
663 #ifdef RTE_LIBRTE_GRAPH_STATS
664  return RTE_LIBRTE_GRAPH_STATS;
665 #else
666  return 0;
667 #endif
668 }
669 
670 #ifdef __cplusplus
671 }
672 #endif
673 
674 #endif /* _RTE_GRAPH_H_ */
uint32_t rte_node_t
Definition: rte_graph.h:46
#define __rte_always_inline
Definition: rte_common.h:255
uint16_t rte_edge_t
Definition: rte_graph.h:47
uint64_t num_pkt_to_capture
Definition: rte_graph.h:170
__rte_experimental rte_node_t rte_node_clone(rte_node_t id, const char *name)
__rte_experimental struct rte_graph_cluster_stats * rte_graph_cluster_stats_create(const struct rte_graph_cluster_stats_param *prm)
__rte_experimental rte_node_t rte_node_from_name(const char *name)
#define RTE_NODE_NAMESIZE
Definition: rte_graph.h:37
__rte_experimental void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat)
static __rte_always_inline int rte_graph_has_stats_feature(void)
Definition: rte_graph.h:661
__rte_experimental rte_node_t rte_node_edge_get(rte_node_t id, char *next_nodes[])
uint16_t rte_graph_t
Definition: rte_graph.h:48
__rte_experimental rte_node_t __rte_node_register(const struct rte_node_register *node)
__rte_experimental int rte_graph_destroy(rte_graph_t id)
__rte_experimental char * rte_node_id_to_name(rte_node_t id)
uint16_t(* rte_node_process_t)(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t nb_objs)
Definition: rte_graph.h:100
__rte_experimental char * rte_graph_id_to_name(rte_graph_t id)
__rte_experimental rte_node_t rte_node_max_count(void)
__rte_experimental struct rte_node * rte_graph_node_get_by_name(const char *graph, const char *name)
static __rte_always_inline int rte_node_is_invalid(rte_node_t id)
Definition: rte_graph.h:619
#define RTE_GRAPH_ID_INVALID
Definition: rte_graph.h:42
__rte_experimental rte_edge_t rte_node_edge_update(rte_node_t id, rte_edge_t from, const char **next_nodes, uint16_t nb_edges)
uint64_t flags
Definition: rte_graph.h:434
void(* rte_node_fini_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:136
uint16_t nb_node_patterns
Definition: rte_graph.h:165
__rte_experimental void rte_graph_list_dump(FILE *f)
__rte_experimental void rte_node_list_dump(FILE *f)
int(* rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last, void *cookie, const struct rte_graph_cluster_node_stats *stats)
Definition: rte_graph.h:155
__rte_experimental struct rte_node * rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id)
int(* rte_node_init_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:120
__rte_experimental void rte_node_dump(FILE *f, rte_node_t id)
const char ** graph_patterns
Definition: rte_graph.h:192
__rte_experimental void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat)
__rte_experimental rte_graph_t rte_graph_max_count(void)
__rte_experimental rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm)
#define __rte_cache_aligned
Definition: rte_common.h:440
char * pcap_filename
Definition: rte_graph.h:171
#define RTE_STD_C11
Definition: rte_common.h:39
rte_graph_cluster_stats_cb_t fn
Definition: rte_graph.h:182
static __rte_always_inline int rte_edge_is_invalid(rte_edge_t id)
Definition: rte_graph.h:634
__rte_experimental rte_edge_t rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
__rte_experimental rte_graph_t rte_graph_from_name(const char *name)
__rte_experimental struct rte_graph * rte_graph_lookup(const char *name)
__rte_experimental void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all)
__rte_experimental void rte_graph_dump(FILE *f, rte_graph_t id)
__rte_experimental void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat, bool skip_cb)
static __rte_always_inline int rte_graph_is_invalid(rte_graph_t id)
Definition: rte_graph.h:649
__rte_experimental rte_edge_t rte_node_edge_count(rte_node_t id)
#define RTE_NODE_ID_INVALID
Definition: rte_graph.h:40
const char ** node_patterns
Definition: rte_graph.h:166
__rte_experimental int rte_graph_export(const char *name, FILE *f)
#define RTE_EDGE_ID_INVALID
Definition: rte_graph.h:41