1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2023 Intel Corporation
*/
#include "graph_private.h"
#include <eal_export.h>
#include "rte_graph_model_mcore_dispatch.h"
int
graph_sched_wq_create(struct graph *_graph, struct graph *_parent_graph,
struct rte_graph_param *prm)
{
struct rte_graph *parent_graph = _parent_graph->graph;
struct rte_graph *graph = _graph->graph;
unsigned int wq_size;
unsigned int flags = RING_F_SC_DEQ;
wq_size = RTE_GRAPH_SCHED_WQ_SIZE(graph->nb_nodes);
wq_size = rte_align32pow2(wq_size + 1);
if (prm->dispatch.wq_size_max > 0)
wq_size = wq_size <= (prm->dispatch.wq_size_max) ? wq_size :
prm->dispatch.wq_size_max;
if (!rte_is_power_of_2(wq_size))
flags |= RING_F_EXACT_SZ;
graph->dispatch.wq = rte_ring_create(graph->name, wq_size, graph->socket,
flags);
if (graph->dispatch.wq == NULL)
SET_ERR_JMP(EIO, fail, "Failed to allocate graph WQ");
if (prm->dispatch.mp_capacity > 0)
wq_size = (wq_size <= prm->dispatch.mp_capacity) ? wq_size :
prm->dispatch.mp_capacity;
graph->dispatch.mp = rte_mempool_create(graph->name, wq_size,
sizeof(struct graph_mcore_dispatch_wq_node),
0, 0, NULL, NULL, NULL, NULL,
graph->socket, MEMPOOL_F_SP_PUT);
if (graph->dispatch.mp == NULL)
SET_ERR_JMP(EIO, fail_mp,
"Failed to allocate graph WQ schedule entry");
graph->dispatch.lcore_id = _graph->lcore_id;
if (parent_graph->dispatch.rq == NULL) {
parent_graph->dispatch.rq = &parent_graph->dispatch.rq_head;
SLIST_INIT(parent_graph->dispatch.rq);
}
graph->dispatch.rq = parent_graph->dispatch.rq;
SLIST_INSERT_HEAD(graph->dispatch.rq, graph, next);
return 0;
fail_mp:
rte_ring_free(graph->dispatch.wq);
graph->dispatch.wq = NULL;
fail:
return -rte_errno;
}
void
graph_sched_wq_destroy(struct graph *_graph)
{
struct rte_graph *graph = _graph->graph;
if (graph == NULL)
return;
rte_ring_free(graph->dispatch.wq);
graph->dispatch.wq = NULL;
rte_mempool_free(graph->dispatch.mp);
graph->dispatch.mp = NULL;
}
static __rte_always_inline bool
__graph_sched_node_enqueue(struct rte_node *node, struct rte_graph *graph)
{
struct graph_mcore_dispatch_wq_node *wq_node;
uint16_t off = 0;
uint16_t size;
submit_again:
if (rte_mempool_get(graph->dispatch.mp, (void **)&wq_node) < 0)
goto fallback;
size = RTE_MIN(node->idx, RTE_DIM(wq_node->objs));
wq_node->node_off = node->off;
wq_node->nb_objs = size;
rte_memcpy(wq_node->objs, &node->objs[off], size * sizeof(void *));
while (rte_ring_mp_enqueue_bulk_elem(graph->dispatch.wq, (void *)&wq_node,
sizeof(wq_node), 1, NULL) == 0)
rte_pause();
off += size;
node->dispatch.total_sched_objs += size;
node->idx -= size;
if (node->idx > 0)
goto submit_again;
if (graph->dispatch.notify_cb)
graph->dispatch.notify_cb(graph, graph->dispatch.cb_priv);
return true;
fallback:
if (off != 0)
memmove(&node->objs[0], &node->objs[off],
node->idx * sizeof(void *));
node->dispatch.total_sched_fail += node->idx;
return false;
}
RTE_EXPORT_SYMBOL(__rte_graph_mcore_dispatch_sched_node_enqueue)
bool __rte_noinline
__rte_graph_mcore_dispatch_sched_node_enqueue(struct rte_node *node,
struct rte_graph_rq_head *rq)
{
const unsigned int lcore_id = node->dispatch.lcore_id;
struct rte_graph *graph = node->dispatch.graph;
if (unlikely((!graph) || (graph->dispatch.lcore_id != lcore_id))) {
SLIST_FOREACH(graph, rq, next)
if (graph->dispatch.lcore_id == lcore_id)
break;
node->dispatch.graph = graph;
}
return graph != NULL ? __graph_sched_node_enqueue(node, graph) : false;
}
RTE_EXPORT_SYMBOL(__rte_graph_mcore_dispatch_sched_wq_process)
void
__rte_graph_mcore_dispatch_sched_wq_process(struct rte_graph *graph)
{
#define WQ_SZ 32
struct graph_mcore_dispatch_wq_node *wq_node;
struct rte_mempool *mp = graph->dispatch.mp;
struct rte_ring *wq = graph->dispatch.wq;
uint16_t idx, free_space;
struct rte_node *node;
unsigned int i, n;
struct graph_mcore_dispatch_wq_node *wq_nodes[WQ_SZ];
n = rte_ring_sc_dequeue_burst_elem(wq, wq_nodes, sizeof(wq_nodes[0]),
RTE_DIM(wq_nodes), NULL);
if (n == 0)
return;
for (i = 0; i < n; i++) {
wq_node = wq_nodes[i];
node = RTE_PTR_ADD(graph, wq_node->node_off);
RTE_ASSERT(node->fence == RTE_GRAPH_FENCE);
idx = node->idx;
free_space = node->size - idx;
if (unlikely(free_space < wq_node->nb_objs))
__rte_node_stream_alloc_size(graph, node, node->size + wq_node->nb_objs);
memmove(&node->objs[idx], wq_node->objs, wq_node->nb_objs * sizeof(void *));
node->idx = idx + wq_node->nb_objs;
__rte_node_process(graph, node);
wq_node->nb_objs = 0;
node->idx = 0;
}
rte_mempool_put_bulk(mp, (void **)wq_nodes, n);
}
RTE_EXPORT_SYMBOL(rte_graph_model_mcore_dispatch_node_lcore_affinity_set)
int
rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id)
{
struct node *node;
int ret = -EINVAL;
if (lcore_id >= RTE_MAX_LCORE)
return ret;
graph_spinlock_lock();
STAILQ_FOREACH(node, node_list_head_get(), next) {
if (strncmp(node->name, name, RTE_NODE_NAMESIZE) == 0) {
node->lcore_id = lcore_id;
ret = 0;
break;
}
}
graph_spinlock_unlock();
return ret;
}
|