CNDP  22.08.0
cne_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 _CNE_GRAPH_H_
6 #define _CNE_GRAPH_H_
7 
21 #include <stdbool.h>
22 #include <stdio.h>
23 
24 #include <cne_common.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define CNE_GRAPH_BURST_SIZE 256
31 #define CNE_GRAPH_NAMESIZE 64
32 #define CNE_NODE_NAMESIZE 64
33 #define CNE_GRAPH_OFF_INVALID UINT32_MAX
34 #define CNE_NODE_ID_INVALID UINT32_MAX
35 #define CNE_EDGE_ID_INVALID UINT16_MAX
36 #define CNE_GRAPH_ID_INVALID UINT16_MAX
37 #define CNE_GRAPH_FENCE 0xdeadbeef12345678ULL
39 typedef uint32_t cne_graph_off_t;
40 typedef uint32_t cne_node_t;
41 typedef uint16_t cne_edge_t;
42 typedef uint16_t cne_graph_t;
45 #if CNE_GRAPH_BURST_SIZE == 1
46 #define CNE_GRAPH_BURST_SIZE_LOG2 0
47 #elif CNE_GRAPH_BURST_SIZE == 2
48 #define CNE_GRAPH_BURST_SIZE_LOG2 1
49 #elif CNE_GRAPH_BURST_SIZE == 4
50 #define CNE_GRAPH_BURST_SIZE_LOG2 2
51 #elif CNE_GRAPH_BURST_SIZE == 8
52 #define CNE_GRAPH_BURST_SIZE_LOG2 3
53 #elif CNE_GRAPH_BURST_SIZE == 16
54 #define CNE_GRAPH_BURST_SIZE_LOG2 4
55 #elif CNE_GRAPH_BURST_SIZE == 32
56 #define CNE_GRAPH_BURST_SIZE_LOG2 5
57 #elif CNE_GRAPH_BURST_SIZE == 64
58 #define CNE_GRAPH_BURST_SIZE_LOG2 6
59 #elif CNE_GRAPH_BURST_SIZE == 128
60 #define CNE_GRAPH_BURST_SIZE_LOG2 7
61 #elif CNE_GRAPH_BURST_SIZE == 256
62 #define CNE_GRAPH_BURST_SIZE_LOG2 8
63 #else
64 #error "Unsupported burst size"
65 #endif
66 
67 /* Forward declaration */
68 struct cne_node;
69 struct cne_graph;
70 struct cne_graph_cluster_stats;
94 typedef uint16_t (*cne_node_process_t)(struct cne_graph *graph, struct cne_node *node, void **objs,
95  uint16_t nb_objs);
96 
113 typedef int (*cne_node_init_t)(const struct cne_graph *graph, struct cne_node *node);
114 
128 typedef void (*cne_node_fini_t)(const struct cne_graph *graph, struct cne_node *node);
129 
144 typedef int (*cne_graph_cluster_stats_cb_t)(bool is_first, bool is_last,
145  const struct cne_graph_cluster_node_stats *stats);
146 
157 
158  uint16_t nb_graph_patterns;
159  const char **graph_patterns;
160 };
161 
168  uint64_t ts;
169  uint64_t calls;
170  uint64_t objs;
171  uint64_t cycles;
173  uint64_t prev_ts;
174  uint64_t prev_calls;
175  uint64_t prev_objs;
176  uint64_t prev_cycles;
178  uint64_t realloc_count;
181  uint64_t hz;
183 } __cne_cache_aligned;
184 
198 CNDP_API cne_graph_t cne_graph_create(const char *name, const char **patterns);
199 
212 
222 CNDP_API cne_graph_t cne_graph_from_name(const char *name);
223 
234 
246 CNDP_API int cne_graph_export(const char *name, FILE *f);
247 
249 typedef struct {
250  int (*header)(FILE *f, const char *name);
251  int (*body)(FILE *f, char *node_name, char **adj_names, cne_edge_t nb_edges,
252  int src);
253  int (*trailer)(FILE *f);
254 } cne_graph_export_t;
255 
272 CNDP_API int cne_graph_export_cb(const char *name, FILE *f, cne_graph_export_t *exp);
273 
281 
296 CNDP_API struct cne_graph *cne_graph_lookup(const char *name);
297 
306 CNDP_API void cne_graph_dump(FILE *f, cne_graph_t id);
307 
314 CNDP_API void cne_graph_list_dump(FILE *f);
315 
326 CNDP_API void cne_graph_obj_dump(FILE *f, struct cne_graph *graph, bool all);
327 
329 #define cne_graph_foreach_node(count, off, graph, node) \
330  for (count = 0, off = graph->nodes_start, node = CNE_PTR_ADD(graph, off); \
331  count < graph->nb_nodes; off = node->next, node = CNE_PTR_ADD(graph, off), count++)
332 
344 CNDP_API struct cne_node *cne_graph_node_get(cne_graph_t graph_id, cne_node_t node_id);
345 
357 CNDP_API struct cne_node *cne_graph_node_get_by_name(const char *graph, const char *name);
358 
370 CNDP_API struct cne_node *cne_graph_get_node_by_name(const struct cne_graph *graph,
371  const char *node_name);
372 
383 CNDP_API struct cne_graph_cluster_stats *
385 
392 CNDP_API void cne_graph_cluster_stats_destroy(struct cne_graph_cluster_stats *stat);
393 
402 CNDP_API void cne_graph_cluster_stats_get(struct cne_graph_cluster_stats *stat, bool skip_cb);
403 
410 CNDP_API void cne_graph_cluster_stats_reset(struct cne_graph_cluster_stats *stat);
411 
420 CNDP_API int cne_graph_stats_node_count(struct cne_graph_cluster_stats *stat);
421 
429  uint64_t flags;
436  const char *next_nodes[];
437 };
438 
440 #define CNE_NODE_SOURCE_F (1ULL << 0)
441 #define CNE_NODE_INPUT_F (1ULL << 1)
442 #define CNE_NODE_MASK_F (CNE_NODE_SOURCE_F | CNE_NODE_INPUT_F)
458 
468 #define CNE_NODE_REGISTER(node) \
469  CNE_INIT(cne_node_register_##node) \
470  { \
471  node.parent_id = CNE_NODE_ID_INVALID; \
472  node.id = __cne_node_register(&node); \
473  }
474 
488 CNDP_API cne_node_t cne_node_clone(cne_node_t id, const char *name);
489 
500 CNDP_API cne_node_t cne_node_from_name(const char *name);
501 
511 CNDP_API char *cne_node_id_to_name(cne_node_t id);
512 
523 
540 CNDP_API cne_edge_t cne_node_edge_update(cne_node_t id, cne_edge_t from, const char **next_nodes,
541  uint16_t nb_edges);
542 
555 
569 CNDP_API cne_node_t cne_node_edge_get(cne_node_t id, char *next_nodes[]);
570 
578 
587 CNDP_API void cne_node_dump(FILE *f, cne_node_t id);
588 
595 CNDP_API void cne_node_list_dump(FILE *f);
596 
606 static __cne_always_inline int
608 {
609  return (id == CNE_NODE_ID_INVALID);
610 }
611 
621 static __cne_always_inline int
623 {
624  return (id == CNE_EDGE_ID_INVALID);
625 }
626 
636 static __cne_always_inline int
638 {
639  return (id == CNE_GRAPH_ID_INVALID);
640 }
641 
648 static __cne_always_inline int
650 {
651  return 1;
652 }
653 
654 #ifdef __cplusplus
655 }
656 #endif
657 
658 #endif /* _CNE_GRAPH_H_ */
#define __cne_always_inline
Definition: cne_common.h:218
CNDP_API cne_edge_t cne_node_edge_update(cne_node_t id, cne_edge_t from, const char **next_nodes, uint16_t nb_edges)
CNDP_API void cne_graph_obj_dump(FILE *f, struct cne_graph *graph, bool all)
CNDP_API void cne_graph_cluster_stats_get(struct cne_graph_cluster_stats *stat, bool skip_cb)
CNDP_API void cne_graph_cluster_stats_reset(struct cne_graph_cluster_stats *stat)
CNDP_API cne_node_t cne_node_from_name(const char *name)
CNDP_API void cne_node_list_dump(FILE *f)
uint16_t(* cne_node_process_t)(struct cne_graph *graph, struct cne_node *node, void **objs, uint16_t nb_objs)
Definition: cne_graph.h:94
uint32_t cne_graph_off_t
Definition: cne_graph.h:39
uint32_t cne_node_t
Definition: cne_graph.h:40
static __cne_always_inline int cne_node_is_invalid(cne_node_t id)
Definition: cne_graph.h:607
CNDP_API void cne_graph_dump(FILE *f, cne_graph_t id)
int(* cne_graph_cluster_stats_cb_t)(bool is_first, bool is_last, const struct cne_graph_cluster_node_stats *stats)
Definition: cne_graph.h:144
CNDP_API cne_edge_t cne_node_edge_shrink(cne_node_t id, cne_edge_t size)
CNDP_API struct cne_node * cne_graph_node_get(cne_graph_t graph_id, cne_node_t node_id)
CNDP_API void cne_node_dump(FILE *f, cne_node_t id)
int(* cne_node_init_t)(const struct cne_graph *graph, struct cne_node *node)
Definition: cne_graph.h:113
CNDP_API int cne_graph_export(const char *name, FILE *f)
CNDP_API cne_graph_t cne_graph_max_count(void)
CNDP_API int cne_graph_destroy(cne_graph_t id)
CNDP_API cne_graph_t cne_graph_create(const char *name, const char **patterns)
CNDP_API struct cne_graph * cne_graph_lookup(const char *name)
CNDP_API int cne_graph_export_cb(const char *name, FILE *f, cne_graph_export_t *exp)
static __cne_always_inline int cne_graph_is_invalid(cne_graph_t id)
Definition: cne_graph.h:637
CNDP_API cne_node_t cne_node_max_count(void)
static __cne_always_inline int cne_graph_has_stats_feature(void)
Definition: cne_graph.h:649
CNDP_API void cne_graph_cluster_stats_destroy(struct cne_graph_cluster_stats *stat)
CNDP_API struct cne_node * cne_graph_node_get_by_name(const char *graph, const char *name)
CNDP_API cne_graph_t cne_graph_from_name(const char *name)
#define CNE_GRAPH_ID_INVALID
Definition: cne_graph.h:36
CNDP_API cne_edge_t cne_node_edge_count(cne_node_t id)
CNDP_API struct cne_graph_cluster_stats * cne_graph_cluster_stats_create(const struct cne_graph_cluster_stats_param *prm)
cne_node_t __cne_node_register(const struct cne_node_register *node)
CNDP_API char * cne_graph_id_to_name(cne_graph_t id)
static __cne_always_inline int cne_edge_is_invalid(cne_edge_t id)
Definition: cne_graph.h:622
uint16_t cne_edge_t
Definition: cne_graph.h:41
CNDP_API struct cne_node * cne_graph_get_node_by_name(const struct cne_graph *graph, const char *node_name)
#define CNE_NODE_ID_INVALID
Definition: cne_graph.h:34
CNDP_API char * cne_node_id_to_name(cne_node_t id)
uint16_t cne_graph_t
Definition: cne_graph.h:42
CNDP_API int cne_graph_stats_node_count(struct cne_graph_cluster_stats *stat)
#define CNE_NODE_NAMESIZE
Definition: cne_graph.h:32
CNDP_API void cne_graph_list_dump(FILE *f)
CNDP_API cne_node_t cne_node_clone(cne_node_t id, const char *name)
#define CNE_EDGE_ID_INVALID
Definition: cne_graph.h:35
void(* cne_node_fini_t)(const struct cne_graph *graph, struct cne_node *node)
Definition: cne_graph.h:128
CNDP_API cne_node_t cne_node_edge_get(cne_node_t id, char *next_nodes[])
char name[CNE_NODE_NAMESIZE]
Definition: cne_graph.h:182
const char ** graph_patterns
Definition: cne_graph.h:159
cne_graph_cluster_stats_cb_t fn
Definition: cne_graph.h:156
cne_node_fini_t fini
Definition: cne_graph.h:432
cne_node_init_t init
Definition: cne_graph.h:431
const char * next_nodes[]
Definition: cne_graph.h:436
cne_node_process_t process
Definition: cne_graph.h:430
cne_node_t parent_id
Definition: cne_graph.h:434
char name[CNE_NODE_NAMESIZE]
Definition: cne_graph.h:428
uint64_t flags
Definition: cne_graph.h:429
cne_node_t id
Definition: cne_graph.h:433
cne_edge_t nb_edges
Definition: cne_graph.h:435