graph: populate fastpath memory for graph reel
[dpdk.git] / lib / librte_graph / rte_graph_worker.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4
5 #ifndef _RTE_GRAPH_WORKER_H_
6 #define _RTE_GRAPH_WORKER_H_
7
8 /**
9  * @file rte_graph_worker.h
10  *
11  * @warning
12  * @b EXPERIMENTAL: this API may change without prior notice
13  *
14  * This API allows a worker thread to walk over a graph and nodes to create,
15  * process, enqueue and move streams of objects to the next nodes.
16  */
17
18 #include <rte_common.h>
19 #include <rte_cycles.h>
20 #include <rte_prefetch.h>
21 #include <rte_memcpy.h>
22 #include <rte_memory.h>
23
24 #include "rte_graph.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31  * @internal
32  *
33  * Data structure to hold graph data.
34  */
35 struct rte_graph {
36         uint32_t tail;               /**< Tail of circular buffer. */
37         uint32_t head;               /**< Head of circular buffer. */
38         uint32_t cir_mask;           /**< Circular buffer wrap around mask. */
39         rte_node_t nb_nodes;         /**< Number of nodes in the graph. */
40         rte_graph_off_t *cir_start;  /**< Pointer to circular buffer. */
41         rte_graph_off_t nodes_start; /**< Offset at which node memory starts. */
42         rte_graph_t id; /**< Graph identifier. */
43         int socket;     /**< Socket ID where memory is allocated. */
44         char name[RTE_GRAPH_NAMESIZE];  /**< Name of the graph. */
45         uint64_t fence;                 /**< Fence. */
46 } __rte_cache_aligned;
47
48 /**
49  * @internal
50  *
51  * Data structure to hold node data.
52  */
53 struct rte_node {
54         /* Slow path area  */
55         uint64_t fence;         /**< Fence. */
56         rte_graph_off_t next;   /**< Index to next node. */
57         rte_node_t id;          /**< Node identifier. */
58         rte_node_t parent_id;   /**< Parent Node identifier. */
59         rte_edge_t nb_edges;    /**< Number of edges from this node. */
60         uint32_t realloc_count; /**< Number of times realloced. */
61
62         char parent[RTE_NODE_NAMESIZE]; /**< Parent node name. */
63         char name[RTE_NODE_NAMESIZE];   /**< Name of the node. */
64
65         /* Fast path area  */
66 #define RTE_NODE_CTX_SZ 16
67         uint8_t ctx[RTE_NODE_CTX_SZ] __rte_cache_aligned; /**< Node Context. */
68         uint16_t size;          /**< Total number of objects available. */
69         uint16_t idx;           /**< Number of objects used. */
70         rte_graph_off_t off;    /**< Offset of node in the graph reel. */
71         uint64_t total_cycles;  /**< Cycles spent in this node. */
72         uint64_t total_calls;   /**< Calls done to this node. */
73         uint64_t total_objs;    /**< Objects processed by this node. */
74         RTE_STD_C11
75                 union {
76                         void **objs;       /**< Array of object pointers. */
77                         uint64_t objs_u64;
78                 };
79         RTE_STD_C11
80                 union {
81                         rte_node_process_t process; /**< Process function. */
82                         uint64_t process_u64;
83                 };
84         struct rte_node *nodes[] __rte_cache_min_aligned; /**< Next nodes. */
85 } __rte_cache_aligned;
86
87 /**
88  * @internal
89  *
90  * Allocate a stream of objects.
91  *
92  * If stream already exists then re-allocate it to a larger size.
93  *
94  * @param graph
95  *   Pointer to the graph object.
96  * @param node
97  *   Pointer to the node object.
98  */
99 __rte_experimental
100 void __rte_node_stream_alloc(struct rte_graph *graph, struct rte_node *node);
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif /* _RTE_GRAPH_WORKER_H_ */