DPDK  23.07.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_PCAP_FILE_SZ 64
38 #define RTE_GRAPH_OFF_INVALID UINT32_MAX
39 #define RTE_NODE_ID_INVALID UINT32_MAX
40 #define RTE_EDGE_ID_INVALID UINT16_MAX
41 #define RTE_GRAPH_ID_INVALID UINT16_MAX
42 #define RTE_GRAPH_FENCE 0xdeadbeef12345678ULL
44 typedef uint32_t rte_graph_off_t;
45 typedef uint32_t rte_node_t;
46 typedef uint16_t rte_edge_t;
47 typedef uint16_t rte_graph_t;
50 #if RTE_GRAPH_BURST_SIZE == 1
51 #define RTE_GRAPH_BURST_SIZE_LOG2 0
52 #elif RTE_GRAPH_BURST_SIZE == 2
53 #define RTE_GRAPH_BURST_SIZE_LOG2 1
54 #elif RTE_GRAPH_BURST_SIZE == 4
55 #define RTE_GRAPH_BURST_SIZE_LOG2 2
56 #elif RTE_GRAPH_BURST_SIZE == 8
57 #define RTE_GRAPH_BURST_SIZE_LOG2 3
58 #elif RTE_GRAPH_BURST_SIZE == 16
59 #define RTE_GRAPH_BURST_SIZE_LOG2 4
60 #elif RTE_GRAPH_BURST_SIZE == 32
61 #define RTE_GRAPH_BURST_SIZE_LOG2 5
62 #elif RTE_GRAPH_BURST_SIZE == 64
63 #define RTE_GRAPH_BURST_SIZE_LOG2 6
64 #elif RTE_GRAPH_BURST_SIZE == 128
65 #define RTE_GRAPH_BURST_SIZE_LOG2 7
66 #elif RTE_GRAPH_BURST_SIZE == 256
67 #define RTE_GRAPH_BURST_SIZE_LOG2 8
68 #else
69 #error "Unsupported burst size"
70 #endif
71 
72 /* Forward declaration */
73 struct rte_node;
74 struct rte_graph;
75 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;
167  bool pcap_enable;
172  union {
173  struct {
174  uint64_t rsvd;
175  } rtc;
176  struct {
177  uint32_t wq_size_max;
178  uint32_t mp_capacity;
179  } dispatch;
180  };
181 };
182 
196  union {
197  void *cookie;
198  FILE *f;
199  };
200  uint16_t nb_graph_patterns;
201  const char **graph_patterns;
203 };
204 
211  uint64_t ts;
212  uint64_t calls;
213  uint64_t objs;
214  uint64_t cycles;
216  uint64_t prev_ts;
217  uint64_t prev_calls;
218  uint64_t prev_objs;
219  uint64_t prev_cycles;
222  union {
223  struct {
224  uint64_t sched_objs;
226  uint64_t sched_fail;
228  } dispatch;
229  };
230 
231  uint64_t realloc_count;
234  uint64_t hz;
235  char name[RTE_NODE_NAMESIZE];
237 
252 __rte_experimental
253 rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
254 
266 __rte_experimental
268 
288 __rte_experimental
289 rte_graph_t rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_param *prm);
290 
300 __rte_experimental
301 rte_graph_t rte_graph_from_name(const char *name);
302 
312 __rte_experimental
314 
326 __rte_experimental
327 int rte_graph_export(const char *name, FILE *f);
328 
339 __rte_experimental
341 
348 __rte_experimental
350 
365 __rte_experimental
366 struct rte_graph *rte_graph_lookup(const char *name);
367 
374 __rte_experimental
376 
385 __rte_experimental
386 void rte_graph_dump(FILE *f, rte_graph_t id);
387 
394 __rte_experimental
395 void rte_graph_list_dump(FILE *f);
396 
407 __rte_experimental
408 void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
409 
411 #define rte_graph_foreach_node(count, off, graph, node) \
412  for (count = 0, off = graph->nodes_start, \
413  node = RTE_PTR_ADD(graph, off); \
414  count < graph->nb_nodes; \
415  off = node->next, node = RTE_PTR_ADD(graph, off), count++)
416 
428 __rte_experimental
429 struct rte_node *rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id);
430 
442 __rte_experimental
443 struct rte_node *rte_graph_node_get_by_name(const char *graph,
444  const char *name);
445 
456 __rte_experimental
457 struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
458  const struct rte_graph_cluster_stats_param *prm);
459 
466 __rte_experimental
467 void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
468 
477 __rte_experimental
478 void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
479  bool skip_cb);
480 
487 __rte_experimental
488 void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
489 
496  char name[RTE_NODE_NAMESIZE];
497  uint64_t flags;
498 #define RTE_NODE_SOURCE_F (1ULL << 0)
499  rte_node_process_t process;
500  rte_node_init_t init;
501  rte_node_fini_t fini;
502  rte_node_t id;
503  rte_node_t parent_id;
504  rte_edge_t nb_edges;
505  const char *next_nodes[];
506 };
507 
521 __rte_experimental
523 
533 #define RTE_NODE_REGISTER(node) \
534  RTE_INIT(rte_node_register_##node) \
535  { \
536  node.parent_id = RTE_NODE_ID_INVALID; \
537  node.id = __rte_node_register(&node); \
538  }
539 
553 __rte_experimental
554 rte_node_t rte_node_clone(rte_node_t id, const char *name);
555 
566 __rte_experimental
567 rte_node_t rte_node_from_name(const char *name);
568 
578 __rte_experimental
580 
590 __rte_experimental
592 
609 __rte_experimental
611  const char **next_nodes, uint16_t nb_edges);
612 
624 __rte_experimental
626 
640 __rte_experimental
641 rte_node_t rte_node_edge_get(rte_node_t id, char *next_nodes[]);
642 
649 __rte_experimental
651 
660 __rte_experimental
661 void rte_node_dump(FILE *f, rte_node_t id);
662 
669 __rte_experimental
670 void rte_node_list_dump(FILE *f);
671 
681 static __rte_always_inline int
683 {
684  return (id == RTE_NODE_ID_INVALID);
685 }
686 
696 static __rte_always_inline int
698 {
699  return (id == RTE_EDGE_ID_INVALID);
700 }
701 
711 static __rte_always_inline int
713 {
714  return (id == RTE_GRAPH_ID_INVALID);
715 }
716 
723 static __rte_always_inline int
725 {
726 #ifdef RTE_LIBRTE_GRAPH_STATS
727  return RTE_LIBRTE_GRAPH_STATS;
728 #else
729  return 0;
730 #endif
731 }
732 
733 #ifdef __cplusplus
734 }
735 #endif
736 
737 #endif /* _RTE_GRAPH_H_ */
uint32_t rte_node_t
Definition: rte_graph.h:45
#define __rte_always_inline
Definition: rte_common.h:255
uint16_t rte_edge_t
Definition: rte_graph.h:46
uint64_t num_pkt_to_capture
Definition: rte_graph.h:168
__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_graph_t rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_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)
static __rte_always_inline int rte_graph_has_stats_feature(void)
Definition: rte_graph.h:724
__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:47
__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:682
#define RTE_GRAPH_ID_INVALID
Definition: rte_graph.h:41
__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:497
__rte_experimental int rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore)
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)
uint32_t mp_capacity
Definition: rte_graph.h:178
__rte_experimental void rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id)
__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:201
__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:169
#define RTE_STD_C11
Definition: rte_common.h:39
rte_graph_cluster_stats_cb_t fn
Definition: rte_graph.h:191
uint32_t wq_size_max
Definition: rte_graph.h:177
static __rte_always_inline int rte_edge_is_invalid(rte_edge_t id)
Definition: rte_graph.h:697
__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)
uint64_t rsvd
Definition: rte_graph.h:174
__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:712
__rte_experimental rte_edge_t rte_node_edge_count(rte_node_t id)
#define RTE_NODE_ID_INVALID
Definition: rte_graph.h:39
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:40