DPDK  20.05.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 
25 #include <stdbool.h>
26 #include <stdio.h>
27 
28 #include <rte_common.h>
29 #include <rte_compat.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define RTE_GRAPH_NAMESIZE 64
36 #define RTE_NODE_NAMESIZE 64
37 #define RTE_GRAPH_OFF_INVALID UINT32_MAX
38 #define RTE_NODE_ID_INVALID UINT32_MAX
39 #define RTE_EDGE_ID_INVALID UINT16_MAX
40 #define RTE_GRAPH_ID_INVALID UINT16_MAX
41 #define RTE_GRAPH_FENCE 0xdeadbeef12345678ULL
43 typedef uint32_t rte_graph_off_t;
44 typedef uint32_t rte_node_t;
45 typedef uint16_t rte_edge_t;
46 typedef uint16_t rte_graph_t;
49 #if RTE_GRAPH_BURST_SIZE == 1
50 #define RTE_GRAPH_BURST_SIZE_LOG2 0
51 #elif RTE_GRAPH_BURST_SIZE == 2
52 #define RTE_GRAPH_BURST_SIZE_LOG2 1
53 #elif RTE_GRAPH_BURST_SIZE == 4
54 #define RTE_GRAPH_BURST_SIZE_LOG2 2
55 #elif RTE_GRAPH_BURST_SIZE == 8
56 #define RTE_GRAPH_BURST_SIZE_LOG2 3
57 #elif RTE_GRAPH_BURST_SIZE == 16
58 #define RTE_GRAPH_BURST_SIZE_LOG2 4
59 #elif RTE_GRAPH_BURST_SIZE == 32
60 #define RTE_GRAPH_BURST_SIZE_LOG2 5
61 #elif RTE_GRAPH_BURST_SIZE == 64
62 #define RTE_GRAPH_BURST_SIZE_LOG2 6
63 #elif RTE_GRAPH_BURST_SIZE == 128
64 #define RTE_GRAPH_BURST_SIZE_LOG2 7
65 #elif RTE_GRAPH_BURST_SIZE == 256
66 #define RTE_GRAPH_BURST_SIZE_LOG2 8
67 #else
68 #error "Unsupported burst size"
69 #endif
70 
71 /* Forward declaration */
72 struct rte_node;
73 struct rte_graph;
74 struct rte_graph_cluster_stats;
98 typedef uint16_t (*rte_node_process_t)(struct rte_graph *graph,
99  struct rte_node *node, void **objs,
100  uint16_t nb_objs);
101 
118 typedef int (*rte_node_init_t)(const struct rte_graph *graph,
119  struct rte_node *node);
120 
134 typedef void (*rte_node_fini_t)(const struct rte_graph *graph,
135  struct rte_node *node);
136 
153 typedef int (*rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
154  void *cookie, const struct rte_graph_cluster_node_stats *stats);
155 
162  int socket_id;
163  uint16_t nb_node_patterns;
164  const char **node_patterns;
166 };
167 
181  union {
182  void *cookie;
183  FILE *f;
184  };
185  uint16_t nb_graph_patterns;
186  const char **graph_patterns;
188 };
189 
196  uint64_t ts;
197  uint64_t calls;
198  uint64_t objs;
199  uint64_t cycles;
201  uint64_t prev_ts;
202  uint64_t prev_calls;
203  uint64_t prev_objs;
204  uint64_t prev_cycles;
206  uint64_t realloc_count;
209  uint64_t hz;
212 
227 __rte_experimental
228 rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
229 
241 __rte_experimental
243 
253 __rte_experimental
254 rte_graph_t rte_graph_from_name(const char *name);
255 
265 __rte_experimental
267 
279 __rte_experimental
280 int rte_graph_export(const char *name, FILE *f);
281 
296 __rte_experimental
297 struct rte_graph *rte_graph_lookup(const char *name);
298 
305 __rte_experimental
307 
316 __rte_experimental
317 void rte_graph_dump(FILE *f, rte_graph_t id);
318 
325 __rte_experimental
326 void rte_graph_list_dump(FILE *f);
327 
338 __rte_experimental
339 void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
340 
342 #define rte_graph_foreach_node(count, off, graph, node) \
343  for (count = 0, off = graph->nodes_start, \
344  node = RTE_PTR_ADD(graph, off); \
345  count < graph->nb_nodes; \
346  off = node->next, node = RTE_PTR_ADD(graph, off), count++)
347 
359 __rte_experimental
360 struct rte_node *rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id);
361 
373 __rte_experimental
374 struct rte_node *rte_graph_node_get_by_name(const char *graph,
375  const char *name);
376 
387 __rte_experimental
388 struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
389  const struct rte_graph_cluster_stats_param *prm);
390 
397 __rte_experimental
398 void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
399 
408 __rte_experimental
409 void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
410  bool skip_cb);
411 
418 __rte_experimental
419 void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
420 
428  uint64_t flags;
429 #define RTE_NODE_SOURCE_F (1ULL << 0)
430  rte_node_process_t process;
431  rte_node_init_t init;
432  rte_node_fini_t fini;
433  rte_node_t id;
434  rte_node_t parent_id;
435  rte_edge_t nb_edges;
436  const char *next_nodes[];
437 };
438 
452 __rte_experimental
454 
464 #define RTE_NODE_REGISTER(node) \
465  RTE_INIT(rte_node_register_##node) \
466  { \
467  node.parent_id = RTE_NODE_ID_INVALID; \
468  node.id = __rte_node_register(&node); \
469  }
470 
484 __rte_experimental
485 rte_node_t rte_node_clone(rte_node_t id, const char *name);
486 
497 __rte_experimental
498 rte_node_t rte_node_from_name(const char *name);
499 
509 __rte_experimental
511 
521 __rte_experimental
523 
540 __rte_experimental
542  const char **next_nodes, uint16_t nb_edges);
543 
555 __rte_experimental
557 
571 __rte_experimental
573 
580 __rte_experimental
582 
591 __rte_experimental
592 void rte_node_dump(FILE *f, rte_node_t id);
593 
600 __rte_experimental
601 void rte_node_list_dump(FILE *f);
602 
612 static __rte_always_inline int
614 {
615  return (id == RTE_NODE_ID_INVALID);
616 }
617 
627 static __rte_always_inline int
629 {
630  return (id == RTE_EDGE_ID_INVALID);
631 }
632 
642 static __rte_always_inline int
644 {
645  return (id == RTE_GRAPH_ID_INVALID);
646 }
647 
654 static __rte_always_inline int
656 {
657 #ifdef RTE_LIBRTE_GRAPH_STATS
658  return RTE_LIBRTE_GRAPH_STATS;
659 #else
660  return 0;
661 #endif
662 }
663 
664 #ifdef __cplusplus
665 }
666 #endif
667 
668 #endif /* _RTE_GRAPH_H_ */
uint32_t rte_node_t
Definition: rte_graph.h:44
rte_edge_t nb_edges
Definition: rte_graph.h:435
#define __rte_always_inline
Definition: rte_common.h:193
uint16_t rte_edge_t
Definition: rte_graph.h:45
__rte_experimental rte_node_t rte_node_clone(rte_node_t id, const char *name)
const char * next_nodes[]
Definition: rte_graph.h:436
__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:36
__rte_experimental void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat)
char name[RTE_NODE_NAMESIZE]
Definition: rte_graph.h:210
static __rte_always_inline int rte_graph_has_stats_feature(void)
Definition: rte_graph.h:655
__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:46
__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:98
__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:613
#define RTE_GRAPH_ID_INVALID
Definition: rte_graph.h:40
__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:428
void(* rte_node_fini_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:134
uint16_t nb_node_patterns
Definition: rte_graph.h:163
__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:153
__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:118
__rte_experimental void rte_node_dump(FILE *f, rte_node_t id)
const char ** graph_patterns
Definition: rte_graph.h:186
__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)
char name[RTE_NODE_NAMESIZE]
Definition: rte_graph.h:427
#define RTE_STD_C11
Definition: rte_common.h:40
rte_graph_cluster_stats_cb_t fn
Definition: rte_graph.h:176
static __rte_always_inline int rte_edge_is_invalid(rte_edge_t id)
Definition: rte_graph.h:628
__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)
#define __rte_cache_aligned
Definition: rte_common.h:367
__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:643
__rte_experimental rte_edge_t rte_node_edge_count(rte_node_t id)
#define RTE_NODE_ID_INVALID
Definition: rte_graph.h:38
const char ** node_patterns
Definition: rte_graph.h:164
__rte_experimental int rte_graph_export(const char *name, FILE *f)
#define RTE_EDGE_ID_INVALID
Definition: rte_graph.h:39