xref: /dpdk/lib/graph/rte_graph_model_mcore_dispatch.h (revision 43f062ac3a926e53993b52a3d4333f2de2c6a706)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2023 Intel Corporation
3  */
4 
5 #ifndef _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_
6 #define _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_
7 
8 /**
9  * @file rte_graph_model_mcore_dispatch.h
10  *
11  * @warning
12  * @b EXPERIMENTAL:
13  * All functions in this file may be changed or removed without prior notice.
14  *
15  * These APIs allow to set core affinity with the node and only used for mcore
16  * dispatch model.
17  */
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <rte_errno.h>
24 #include <rte_mempool.h>
25 #include <rte_memzone.h>
26 #include <rte_ring.h>
27 
28 #include "rte_graph_worker_common.h"
29 
30 #define RTE_GRAPH_SCHED_WQ_SIZE_MULTIPLIER  8
31 #define RTE_GRAPH_SCHED_WQ_SIZE(nb_nodes)   \
32 	((typeof(nb_nodes))((nb_nodes) * RTE_GRAPH_SCHED_WQ_SIZE_MULTIPLIER))
33 
34 /**
35  * @internal
36  *
37  * Schedule the node to the right graph's work queue for mcore dispatch model.
38  *
39  * @param node
40  *   Pointer to the scheduled node object.
41  * @param rq
42  *   Pointer to the scheduled run-queue for all graphs.
43  *
44  * @return
45  *   True on success, false otherwise.
46  *
47  * @note
48  * This implementation is used by mcore dispatch model only and user application
49  * should not call it directly.
50  */
51 __rte_experimental
52 bool __rte_noinline __rte_graph_mcore_dispatch_sched_node_enqueue(struct rte_node *node,
53 								  struct rte_graph_rq_head *rq);
54 
55 /**
56  * @internal
57  *
58  * Process all nodes (streams) in the graph's work queue for mcore dispatch model.
59  *
60  * @param graph
61  *   Pointer to the graph object.
62  *
63  * @note
64  * This implementation is used by mcore dispatch model only and user application
65  * should not call it directly.
66  */
67 __rte_experimental
68 void __rte_graph_mcore_dispatch_sched_wq_process(struct rte_graph *graph);
69 
70 /**
71  * Set lcore affinity with the node used for mcore dispatch model.
72  *
73  * @param name
74  *   Valid node name. In the case of the cloned node, the name will be
75  * "parent node name" + "-" + name.
76  * @param lcore_id
77  *   The lcore ID value.
78  *
79  * @return
80  *   0 on success, error otherwise.
81  */
82 __rte_experimental
83 int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,
84 							   unsigned int lcore_id);
85 
86 /**
87  * Perform graph walk on the circular buffer and invoke the process function
88  * of the nodes and collect the stats.
89  *
90  * @param graph
91  *   Graph pointer returned from rte_graph_lookup function.
92  *
93  * @see rte_graph_lookup()
94  */
95 __rte_experimental
96 static inline void
97 rte_graph_walk_mcore_dispatch(struct rte_graph *graph)
98 {
99 	const rte_graph_off_t *cir_start = graph->cir_start;
100 	const rte_node_t mask = graph->cir_mask;
101 	uint32_t head = graph->head;
102 	struct rte_node *node;
103 
104 	if (graph->dispatch.wq != NULL)
105 		__rte_graph_mcore_dispatch_sched_wq_process(graph);
106 
107 	while (likely(head != graph->tail)) {
108 		node = (struct rte_node *)RTE_PTR_ADD(graph, cir_start[(int32_t)head++]);
109 
110 		/* skip the src nodes which not bind with current worker */
111 		if ((int32_t)head < 0 && node->dispatch.lcore_id != graph->dispatch.lcore_id)
112 			continue;
113 
114 		/* Schedule the node until all task/objs are done */
115 		if (node->dispatch.lcore_id != RTE_MAX_LCORE &&
116 		    graph->dispatch.lcore_id != node->dispatch.lcore_id &&
117 		    graph->dispatch.rq != NULL &&
118 		    __rte_graph_mcore_dispatch_sched_node_enqueue(node, graph->dispatch.rq))
119 			continue;
120 
121 		__rte_node_process(graph, node);
122 
123 		head = likely((int32_t)head > 0) ? head & mask : head;
124 	}
125 
126 	graph->tail = 0;
127 }
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif /* _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_ */
134