DPDK  20.05.0-rc0
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;
101 typedef uint16_t (*rte_node_process_t)(struct rte_graph *graph,
102  struct rte_node *node, void **objs,
103  uint16_t nb_objs);
104 
124 typedef int (*rte_node_init_t)(const struct rte_graph *graph,
125  struct rte_node *node);
126 
143 typedef void (*rte_node_fini_t)(const struct rte_graph *graph,
144  struct rte_node *node);
145 
165 typedef int (*rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
166  void *cookie, const struct rte_graph_cluster_node_stats *stats);
167 
177  int socket_id;
178  uint16_t nb_node_patterns;
179  const char **node_patterns;
181 };
182 
199  union {
200  void *cookie;
201  FILE *f;
202  };
203  uint16_t nb_graph_patterns;
204  const char **graph_patterns;
206 };
207 
217  uint64_t ts;
218  uint64_t calls;
219  uint64_t objs;
220  uint64_t cycles;
222  uint64_t prev_ts;
223  uint64_t prev_calls;
224  uint64_t prev_objs;
225  uint64_t prev_cycles;
227  uint64_t realloc_count;
230  uint64_t hz;
231  char name[RTE_NODE_NAMESIZE];
233 
243  char name[RTE_NODE_NAMESIZE];
244  uint64_t flags;
245 #define RTE_NODE_SOURCE_F (1ULL << 0)
246  rte_node_process_t process;
247  rte_node_init_t init;
248  rte_node_fini_t fini;
249  rte_node_t id;
250  rte_node_t parent_id;
251  rte_edge_t nb_edges;
252  const char *next_nodes[];
253 };
254 
272 __rte_experimental
273 rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
274 
289 __rte_experimental
290 rte_graph_t rte_graph_destroy(const char *name);
291 
304 __rte_experimental
305 rte_graph_t rte_graph_from_name(const char *name);
306 
319 __rte_experimental
321 
336 __rte_experimental
337 rte_graph_t rte_graph_export(const char *name, FILE *f);
338 
356 __rte_experimental
357 struct rte_graph *rte_graph_lookup(const char *name);
358 
368 __rte_experimental
370 
382 __rte_experimental
383 void rte_graph_dump(FILE *f, rte_graph_t id);
384 
394 __rte_experimental
395 void rte_graph_list_dump(FILE *f);
396 
410 __rte_experimental
411 void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
412 
414 #define rte_graph_foreach_node(count, off, graph, node) \
415  for (count = 0, off = graph->nodes_start, \
416  node = RTE_PTR_ADD(graph, off); \
417  count < graph->nb_nodes; \
418  off = node->next, node = RTE_PTR_ADD(graph, off), count++)
419 
434 __rte_experimental
435 struct rte_node *rte_graph_node_get(rte_graph_t graph_id, uint32_t node_id);
436 
451 __rte_experimental
452 struct rte_node *rte_graph_node_get_by_name(const char *graph,
453  const char *name);
454 
468 __rte_experimental
469 struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
470  const struct rte_graph_cluster_stats_param *prm);
471 
482 __rte_experimental
483 void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
484 
496 __rte_experimental
497 void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
498  bool skip_cb);
499 
509 __rte_experimental
510 void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
511 
528 __rte_experimental
530 
540 #define RTE_NODE_REGISTER(node) \
541  RTE_INIT(rte_node_register_##node) \
542  { \
543  node.parent_id = RTE_NODE_ID_INVALID; \
544  node.id = __rte_node_register(&node); \
545  }
546 
563 __rte_experimental
564 rte_node_t rte_node_clone(rte_node_t id, const char *name);
565 
579 __rte_experimental
580 rte_node_t rte_node_from_name(const char *name);
581 
594 __rte_experimental
596 
609 __rte_experimental
611 
631 __rte_experimental
633  const char **next_nodes, uint16_t nb_edges);
634 
649 __rte_experimental
651 
668 __rte_experimental
669 rte_node_t rte_node_edge_get(rte_node_t id, char *next_nodes[]);
670 
680 __rte_experimental
682 
694 __rte_experimental
695 void rte_node_dump(FILE *f, rte_node_t id);
696 
706 __rte_experimental
707 void rte_node_list_dump(FILE *f);
708 
721 static __rte_always_inline int
723 {
724  return (id == RTE_NODE_ID_INVALID);
725 }
726 
739 static __rte_always_inline int
741 {
742  return (id == RTE_EDGE_ID_INVALID);
743 }
744 
757 static __rte_always_inline int
759 {
760  return (id == RTE_GRAPH_ID_INVALID);
761 }
762 
772 static __rte_always_inline int
774 {
775 #ifdef RTE_LIBRTE_GRAPH_STATS
776  return RTE_LIBRTE_GRAPH_STATS;
777 #else
778  return 0;
779 #endif
780 }
781 
782 #ifdef __cplusplus
783 }
784 #endif
785 
786 #endif /* _RTE_GRAPH_H_ */
uint32_t rte_node_t
Definition: rte_graph.h:44
#define __rte_always_inline
Definition: rte_common.h:183
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)
__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)
__rte_experimental rte_graph_t rte_graph_destroy(const char *name)
static __rte_always_inline int rte_graph_has_stats_feature(void)
Definition: rte_graph.h:773
__rte_experimental rte_graph_t rte_graph_export(const char *name, FILE *f)
__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 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:101
__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:722
#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:244
void(* rte_node_fini_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:143
uint16_t nb_node_patterns
Definition: rte_graph.h:178
__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:165
int(* rte_node_init_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:124
__rte_experimental void rte_node_dump(FILE *f, rte_node_t id)
const char ** graph_patterns
Definition: rte_graph.h:204
__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_STD_C11
Definition: rte_common.h:40
rte_graph_cluster_stats_cb_t fn
Definition: rte_graph.h:194
static __rte_always_inline int rte_edge_is_invalid(rte_edge_t id)
Definition: rte_graph.h:740
__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:347
__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 struct rte_node * rte_graph_node_get(rte_graph_t graph_id, uint32_t node_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:758
__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:179
#define RTE_EDGE_ID_INVALID
Definition: rte_graph.h:39