DPDK  21.02.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_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;
99 typedef uint16_t (*rte_node_process_t)(struct rte_graph *graph,
100  struct rte_node *node, void **objs,
101  uint16_t nb_objs);
102 
119 typedef int (*rte_node_init_t)(const struct rte_graph *graph,
120  struct rte_node *node);
121 
135 typedef void (*rte_node_fini_t)(const struct rte_graph *graph,
136  struct rte_node *node);
137 
154 typedef int (*rte_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
155  void *cookie, const struct rte_graph_cluster_node_stats *stats);
156 
163  int socket_id;
164  uint16_t nb_node_patterns;
165  const char **node_patterns;
167 };
168 
182  union {
183  void *cookie;
184  FILE *f;
185  };
186  uint16_t nb_graph_patterns;
187  const char **graph_patterns;
189 };
190 
197  uint64_t ts;
198  uint64_t calls;
199  uint64_t objs;
200  uint64_t cycles;
202  uint64_t prev_ts;
203  uint64_t prev_calls;
204  uint64_t prev_objs;
205  uint64_t prev_cycles;
207  uint64_t realloc_count;
210  uint64_t hz;
213 
228 __rte_experimental
229 rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
230 
242 __rte_experimental
244 
254 __rte_experimental
255 rte_graph_t rte_graph_from_name(const char *name);
256 
266 __rte_experimental
268 
280 __rte_experimental
281 int rte_graph_export(const char *name, FILE *f);
282 
297 __rte_experimental
298 struct rte_graph *rte_graph_lookup(const char *name);
299 
306 __rte_experimental
308 
317 __rte_experimental
318 void rte_graph_dump(FILE *f, rte_graph_t id);
319 
326 __rte_experimental
327 void rte_graph_list_dump(FILE *f);
328 
339 __rte_experimental
340 void rte_graph_obj_dump(FILE *f, struct rte_graph *graph, bool all);
341 
343 #define rte_graph_foreach_node(count, off, graph, node) \
344  for (count = 0, off = graph->nodes_start, \
345  node = RTE_PTR_ADD(graph, off); \
346  count < graph->nb_nodes; \
347  off = node->next, node = RTE_PTR_ADD(graph, off), count++)
348 
360 __rte_experimental
361 struct rte_node *rte_graph_node_get(rte_graph_t graph_id, rte_node_t node_id);
362 
374 __rte_experimental
375 struct rte_node *rte_graph_node_get_by_name(const char *graph,
376  const char *name);
377 
388 __rte_experimental
389 struct rte_graph_cluster_stats *rte_graph_cluster_stats_create(
390  const struct rte_graph_cluster_stats_param *prm);
391 
398 __rte_experimental
399 void rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat);
400 
409 __rte_experimental
410 void rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat,
411  bool skip_cb);
412 
419 __rte_experimental
420 void rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat);
421 
429  uint64_t flags;
430 #define RTE_NODE_SOURCE_F (1ULL << 0)
431  rte_node_process_t process;
432  rte_node_init_t init;
433  rte_node_fini_t fini;
434  rte_node_t id;
435  rte_node_t parent_id;
436  rte_edge_t nb_edges;
437  const char *next_nodes[];
438 };
439 
453 __rte_experimental
455 
465 #define RTE_NODE_REGISTER(node) \
466  RTE_INIT(rte_node_register_##node) \
467  { \
468  node.parent_id = RTE_NODE_ID_INVALID; \
469  node.id = __rte_node_register(&node); \
470  }
471 
485 __rte_experimental
486 rte_node_t rte_node_clone(rte_node_t id, const char *name);
487 
498 __rte_experimental
499 rte_node_t rte_node_from_name(const char *name);
500 
510 __rte_experimental
512 
522 __rte_experimental
524 
541 __rte_experimental
543  const char **next_nodes, uint16_t nb_edges);
544 
556 __rte_experimental
558 
572 __rte_experimental
574 
581 __rte_experimental
583 
592 __rte_experimental
593 void rte_node_dump(FILE *f, rte_node_t id);
594 
601 __rte_experimental
602 void rte_node_list_dump(FILE *f);
603 
613 static __rte_always_inline int
615 {
616  return (id == RTE_NODE_ID_INVALID);
617 }
618 
628 static __rte_always_inline int
630 {
631  return (id == RTE_EDGE_ID_INVALID);
632 }
633 
643 static __rte_always_inline int
645 {
646  return (id == RTE_GRAPH_ID_INVALID);
647 }
648 
655 static __rte_always_inline int
657 {
658 #ifdef RTE_LIBRTE_GRAPH_STATS
659  return RTE_LIBRTE_GRAPH_STATS;
660 #else
661  return 0;
662 #endif
663 }
664 
665 #ifdef __cplusplus
666 }
667 #endif
668 
669 #endif /* _RTE_GRAPH_H_ */
uint32_t rte_node_t
Definition: rte_graph.h:45
rte_edge_t nb_edges
Definition: rte_graph.h:436
#define __rte_always_inline
Definition: rte_common.h:226
uint16_t rte_edge_t
Definition: rte_graph.h:46
__rte_experimental rte_node_t rte_node_clone(rte_node_t id, const char *name)
const char * next_nodes[]
Definition: rte_graph.h:437
__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)
char name[RTE_NODE_NAMESIZE]
Definition: rte_graph.h:211
static __rte_always_inline int rte_graph_has_stats_feature(void)
Definition: rte_graph.h:656
__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:99
__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:614
#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:429
void(* rte_node_fini_t)(const struct rte_graph *graph, struct rte_node *node)
Definition: rte_graph.h:135
uint16_t nb_node_patterns
Definition: rte_graph.h:164
__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:154
__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:119
__rte_experimental void rte_node_dump(FILE *f, rte_node_t id)
const char ** graph_patterns
Definition: rte_graph.h:187
__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:428
#define __rte_cache_aligned
Definition: rte_common.h:400
#define RTE_STD_C11
Definition: rte_common.h:40
rte_graph_cluster_stats_cb_t fn
Definition: rte_graph.h:177
static __rte_always_inline int rte_edge_is_invalid(rte_edge_t id)
Definition: rte_graph.h:629
__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:644
__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:165
__rte_experimental int rte_graph_export(const char *name, FILE *f)
#define RTE_EDGE_ID_INVALID
Definition: rte_graph.h:40