Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2017 Cavium, Inc.
3 : : */
4 : :
5 : : #include "test_pipeline_common.h"
6 : :
7 : : int
8 : 0 : pipeline_test_result(struct evt_test *test, struct evt_options *opt)
9 : : {
10 : : RTE_SET_USED(opt);
11 : : int i;
12 : : uint64_t total = 0;
13 : : struct test_pipeline *t = evt_test_priv(test);
14 : :
15 : 0 : evt_info("Packet distribution across worker cores :");
16 : 0 : for (i = 0; i < t->nb_workers; i++)
17 : 0 : total += t->worker[i].processed_pkts;
18 : 0 : for (i = 0; i < t->nb_workers; i++)
19 : 0 : evt_info("Worker %d packets: "CLGRN"%"PRIx64""CLNRM" percentage:"
20 : : CLGRN" %3.2f"CLNRM, i,
21 : : t->worker[i].processed_pkts,
22 : : (((double)t->worker[i].processed_pkts)/total)
23 : : * 100);
24 : 0 : return t->result;
25 : : }
26 : :
27 : : void
28 : 0 : pipeline_opt_dump(struct evt_options *opt, uint8_t nb_queues)
29 : : {
30 : 0 : evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
31 : 0 : evt_dump_worker_lcores(opt);
32 : : evt_dump_nb_stages(opt);
33 : : evt_dump("nb_evdev_ports", "%d", pipeline_nb_event_ports(opt));
34 : 0 : evt_dump("nb_evdev_queues", "%d", nb_queues);
35 : 0 : evt_dump_queue_priority(opt);
36 : 0 : evt_dump_sched_type_list(opt);
37 : 0 : evt_dump_producer_type(opt);
38 : 0 : evt_dump("nb_eth_rx_queues", "%d", opt->eth_queues);
39 : 0 : evt_dump("event_vector", "%d", opt->ena_vector);
40 : 0 : if (opt->ena_vector) {
41 : 0 : evt_dump("vector_size", "%d", opt->vector_size);
42 : 0 : evt_dump("vector_tmo_ns", "%" PRIu64 "", opt->vector_tmo_nsec);
43 : : }
44 : 0 : }
45 : :
46 : : static inline uint64_t
47 : : processed_pkts(struct test_pipeline *t)
48 : : {
49 : : uint8_t i;
50 : : uint64_t total = 0;
51 : :
52 : 0 : for (i = 0; i < t->nb_workers; i++)
53 : 0 : total += t->worker[i].processed_pkts;
54 : :
55 : : return total;
56 : : }
57 : :
58 : : /* RFC863 discard port */
59 : : #define UDP_SRC_PORT 9
60 : : #define UDP_DST_PORT 9
61 : :
62 : : /* RFC2544 reserved test subnet 192.18.0.0 */
63 : : #define IP_SRC_ADDR(x, y) ((192U << 24) | (18 << 16) | ((x) << 8) | (y))
64 : : #define IP_DST_ADDR(x, y) ((192U << 24) | (18 << 16) | ((x) << 8) | (y))
65 : :
66 : : #define IP_DEFTTL 64 /* from RFC 1340. */
67 : : #define IP_VERSION 0x40
68 : : #define IP_HDRLEN 0x05 /* default IP header length == five 32-bits words. */
69 : : #define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
70 : :
71 : : static void
72 : 0 : setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
73 : : struct rte_udp_hdr *udp_hdr, uint16_t pkt_data_len,
74 : : uint8_t port, uint8_t flow)
75 : : {
76 : : uint16_t pkt_len;
77 : :
78 : : /*
79 : : * Initialize UDP header.
80 : : */
81 : 0 : pkt_len = (uint16_t)(pkt_data_len + sizeof(struct rte_udp_hdr));
82 : 0 : udp_hdr->src_port = rte_cpu_to_be_16(UDP_SRC_PORT);
83 : 0 : udp_hdr->dst_port = rte_cpu_to_be_16(UDP_DST_PORT);
84 : 0 : udp_hdr->dgram_len = rte_cpu_to_be_16(pkt_len);
85 : 0 : udp_hdr->dgram_cksum = 0; /* No UDP checksum. */
86 : :
87 : : /*
88 : : * Initialize IP header.
89 : : */
90 : 0 : pkt_len = (uint16_t)(pkt_len + sizeof(struct rte_ipv4_hdr));
91 : 0 : ip_hdr->version_ihl = IP_VHL_DEF;
92 : 0 : ip_hdr->type_of_service = 0;
93 : 0 : ip_hdr->fragment_offset = 0;
94 : 0 : ip_hdr->time_to_live = IP_DEFTTL;
95 : 0 : ip_hdr->next_proto_id = IPPROTO_UDP;
96 : 0 : ip_hdr->packet_id = 0;
97 : 0 : ip_hdr->total_length = rte_cpu_to_be_16(pkt_len);
98 : 0 : ip_hdr->src_addr = rte_cpu_to_be_32(IP_SRC_ADDR(port, 1));
99 : 0 : ip_hdr->dst_addr = rte_cpu_to_be_32(IP_DST_ADDR(port + 1, flow));
100 : :
101 : : /*
102 : : * Compute IP header checksum.
103 : : */
104 : 0 : ip_hdr->hdr_checksum = rte_ipv4_cksum_simple(ip_hdr);
105 : 0 : }
106 : :
107 : : static void
108 : 0 : pipeline_tx_first(struct test_pipeline *t, struct evt_options *opt)
109 : : {
110 : : #define TX_DEF_PACKET_LEN 64
111 : : uint16_t eth_port_id = 0;
112 : : uint16_t pkt_sz, rc;
113 : : uint32_t i;
114 : :
115 : 0 : pkt_sz = opt->tx_pkt_sz;
116 : 0 : if (pkt_sz > opt->max_pkt_sz)
117 : 0 : pkt_sz = opt->max_pkt_sz;
118 : 0 : if (!pkt_sz)
119 : : pkt_sz = TX_DEF_PACKET_LEN;
120 : :
121 : 0 : RTE_ETH_FOREACH_DEV(eth_port_id) {
122 : : struct rte_ether_addr src_mac;
123 : : struct rte_ether_addr dst_mac;
124 : : struct rte_ether_hdr eth_hdr;
125 : :
126 : : /* Send to the same dest.mac as port mac */
127 : 0 : rte_eth_macaddr_get(eth_port_id, &dst_mac);
128 : 0 : rte_eth_random_addr((uint8_t *)&src_mac);
129 : :
130 : : rte_ether_addr_copy(&dst_mac, ð_hdr.dst_addr);
131 : : rte_ether_addr_copy(&src_mac, ð_hdr.src_addr);
132 : : eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
133 : :
134 : 0 : for (i = 0; i < opt->tx_first; i++) {
135 : : struct rte_udp_hdr *pkt_udp_hdr;
136 : : struct rte_ipv4_hdr ip_hdr;
137 : : struct rte_udp_hdr udp_hdr;
138 : : struct rte_mbuf *mbuf;
139 : :
140 : 0 : mbuf = rte_pktmbuf_alloc(
141 : 0 : opt->per_port_pool ? t->pool[i] : t->pool[0]);
142 : 0 : if (mbuf == NULL)
143 : 0 : continue;
144 : :
145 : 0 : setup_pkt_udp_ip_headers(
146 : : &ip_hdr, &udp_hdr,
147 : : pkt_sz - sizeof(struct rte_ether_hdr) -
148 : 0 : sizeof(struct rte_ipv4_hdr) -
149 : : sizeof(struct rte_udp_hdr),
150 : : eth_port_id, i);
151 : 0 : mbuf->port = eth_port_id;
152 : 0 : mbuf->data_len = pkt_sz;
153 : 0 : mbuf->pkt_len = pkt_sz;
154 : :
155 : : /* Copy Ethernet header */
156 : 0 : rte_memcpy(rte_pktmbuf_mtod_offset(mbuf, char *, 0),
157 : : ð_hdr, sizeof(struct rte_ether_hdr));
158 : :
159 : : /* Copy Ipv4 header */
160 : 0 : rte_memcpy(rte_pktmbuf_mtod_offset(
161 : : mbuf, char *,
162 : : sizeof(struct rte_ether_hdr)),
163 : : &ip_hdr, sizeof(struct rte_ipv4_hdr));
164 : :
165 : : /* Copy UDP header */
166 : : rte_memcpy(
167 : 0 : rte_pktmbuf_mtod_offset(
168 : : mbuf, char *,
169 : : sizeof(struct rte_ipv4_hdr) +
170 : : sizeof(struct rte_ether_hdr)),
171 : : &udp_hdr, sizeof(struct rte_udp_hdr));
172 : 0 : pkt_udp_hdr = rte_pktmbuf_mtod_offset(
173 : : mbuf, struct rte_udp_hdr *,
174 : : sizeof(struct rte_ipv4_hdr) +
175 : : sizeof(struct rte_ether_hdr));
176 : 0 : pkt_udp_hdr->src_port =
177 : 0 : rte_cpu_to_be_16(UDP_SRC_PORT + i);
178 : 0 : pkt_udp_hdr->dst_port =
179 : 0 : rte_cpu_to_be_16(UDP_SRC_PORT + i);
180 : :
181 : 0 : rc = rte_eth_tx_burst(eth_port_id, 0, &mbuf, 1);
182 : 0 : if (rc == 0)
183 : 0 : rte_pktmbuf_free(mbuf);
184 : : }
185 : : }
186 : 0 : }
187 : :
188 : : int
189 : 0 : pipeline_launch_lcores(struct evt_test *test, struct evt_options *opt,
190 : : int (*worker)(void *))
191 : : {
192 : : struct test_pipeline *t = evt_test_priv(test);
193 : : int ret, lcore_id;
194 : : int port_idx = 0;
195 : :
196 : 0 : if (opt->tx_first)
197 : 0 : pipeline_tx_first(t, opt);
198 : :
199 : : /* launch workers */
200 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
201 : 0 : if (!(opt->wlcores[lcore_id]))
202 : 0 : continue;
203 : :
204 : 0 : ret = rte_eal_remote_launch(worker,
205 : 0 : &t->worker[port_idx], lcore_id);
206 : 0 : if (ret) {
207 : 0 : evt_err("failed to launch worker %d", lcore_id);
208 : 0 : return ret;
209 : : }
210 : 0 : port_idx++;
211 : : }
212 : :
213 : : uint64_t perf_cycles = rte_get_timer_cycles();
214 : : const uint64_t perf_sample = rte_get_timer_hz();
215 : :
216 : : static float total_mpps;
217 : : static uint64_t samples;
218 : :
219 : : uint64_t prev_pkts = 0;
220 : :
221 : 0 : while (t->done == false) {
222 : : const uint64_t new_cycles = rte_get_timer_cycles();
223 : :
224 : 0 : if ((new_cycles - perf_cycles) > perf_sample) {
225 : : const uint64_t curr_pkts = processed_pkts(t);
226 : :
227 : 0 : float mpps = (float)(curr_pkts - prev_pkts)/1000000;
228 : :
229 : : prev_pkts = curr_pkts;
230 : : perf_cycles = new_cycles;
231 : 0 : total_mpps += mpps;
232 : 0 : ++samples;
233 : 0 : printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
234 : 0 : mpps, total_mpps/samples);
235 : 0 : fflush(stdout);
236 : : }
237 : : }
238 : : printf("\n");
239 : 0 : return 0;
240 : : }
241 : :
242 : : int
243 : 0 : pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
244 : : {
245 : : unsigned int lcores;
246 : :
247 : : /* N worker + main */
248 : : lcores = 2;
249 : :
250 : 0 : if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
251 : 0 : evt_err("Invalid producer type '%s' valid producer '%s'",
252 : : evt_prod_id_to_name(opt->prod_type),
253 : : evt_prod_id_to_name(EVT_PROD_TYPE_ETH_RX_ADPTR));
254 : 0 : return -1;
255 : : }
256 : :
257 : 0 : if (!rte_eth_dev_count_avail()) {
258 : 0 : evt_err("test needs minimum 1 ethernet dev");
259 : 0 : return -1;
260 : : }
261 : :
262 : 0 : if (rte_lcore_count() < lcores) {
263 : 0 : evt_err("test need minimum %d lcores", lcores);
264 : 0 : return -1;
265 : : }
266 : :
267 : : /* Validate worker lcores */
268 : 0 : if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
269 : 0 : evt_err("worker lcores overlaps with main lcore");
270 : 0 : return -1;
271 : : }
272 : 0 : if (evt_has_disabled_lcore(opt->wlcores)) {
273 : 0 : evt_err("one or more workers lcores are not enabled");
274 : 0 : return -1;
275 : : }
276 : 0 : if (!evt_has_active_lcore(opt->wlcores)) {
277 : 0 : evt_err("minimum one worker is required");
278 : 0 : return -1;
279 : : }
280 : :
281 : 0 : if (nb_queues > EVT_MAX_QUEUES) {
282 : 0 : evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
283 : 0 : return -1;
284 : : }
285 : 0 : if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
286 : 0 : evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
287 : 0 : return -1;
288 : : }
289 : :
290 : 0 : if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) {
291 : 0 : evt_err("Invalid producer type, only --prod_type_ethdev is supported");
292 : 0 : return -1;
293 : : }
294 : :
295 : 0 : if (evt_has_invalid_stage(opt))
296 : : return -1;
297 : :
298 : 0 : if (evt_has_invalid_sched_type(opt))
299 : 0 : return -1;
300 : :
301 : : return 0;
302 : : }
303 : :
304 : : #define NB_RX_DESC 128
305 : : #define NB_TX_DESC 512
306 : : int
307 : 0 : pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
308 : : {
309 : : uint16_t i, j;
310 : : int ret;
311 : : uint8_t nb_queues = 1;
312 : : struct test_pipeline *t = evt_test_priv(test);
313 : : struct rte_eth_rxconf rx_conf;
314 : 0 : struct rte_eth_conf port_conf = {
315 : : .rxmode = {
316 : : .mq_mode = RTE_ETH_MQ_RX_RSS,
317 : : },
318 : : .rx_adv_conf = {
319 : : .rss_conf = {
320 : : .rss_key = NULL,
321 : : .rss_hf = RTE_ETH_RSS_IP,
322 : : },
323 : : },
324 : : };
325 : :
326 : 0 : if (!rte_eth_dev_count_avail()) {
327 : 0 : evt_err("No ethernet ports found.");
328 : 0 : return -ENODEV;
329 : : }
330 : :
331 : 0 : if (opt->max_pkt_sz < RTE_ETHER_MIN_LEN) {
332 : 0 : evt_err("max_pkt_sz can not be less than %d",
333 : : RTE_ETHER_MIN_LEN);
334 : 0 : return -EINVAL;
335 : : }
336 : :
337 : 0 : port_conf.rxmode.mtu = opt->max_pkt_sz - RTE_ETHER_HDR_LEN -
338 : : RTE_ETHER_CRC_LEN;
339 : :
340 : 0 : t->internal_port = 1;
341 : 0 : RTE_ETH_FOREACH_DEV(i) {
342 : : struct rte_eth_dev_info dev_info;
343 : 0 : struct rte_eth_conf local_port_conf = port_conf;
344 : 0 : uint32_t caps = 0;
345 : :
346 : 0 : ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id, i, &caps);
347 : 0 : if (ret != 0) {
348 : 0 : evt_err("failed to get event tx adapter[%d] caps", i);
349 : 0 : return ret;
350 : : }
351 : :
352 : 0 : if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
353 : 0 : t->internal_port = 0;
354 : :
355 : 0 : ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id, i, &caps);
356 : 0 : if (ret != 0) {
357 : 0 : evt_err("failed to get event tx adapter[%d] caps", i);
358 : 0 : return ret;
359 : : }
360 : :
361 : 0 : if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
362 : 0 : local_port_conf.rxmode.offloads |=
363 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
364 : :
365 : 0 : ret = rte_eth_dev_info_get(i, &dev_info);
366 : 0 : if (ret != 0) {
367 : 0 : evt_err("Error during getting device (port %u) info: %s\n",
368 : : i, strerror(-ret));
369 : 0 : return ret;
370 : : }
371 : :
372 : : /* Enable mbuf fast free if PMD has the capability. */
373 : 0 : if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
374 : 0 : local_port_conf.txmode.offloads |=
375 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
376 : :
377 : 0 : rx_conf = dev_info.default_rxconf;
378 : 0 : rx_conf.offloads = port_conf.rxmode.offloads;
379 : :
380 : 0 : local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
381 : 0 : dev_info.flow_type_rss_offloads;
382 : 0 : if (local_port_conf.rx_adv_conf.rss_conf.rss_hf == 0)
383 : 0 : local_port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
384 : 0 : if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
385 : : port_conf.rx_adv_conf.rss_conf.rss_hf) {
386 : 0 : evt_info("Port %u modified RSS hash function based on hardware support,"
387 : : "requested:%#"PRIx64" configured:%#"PRIx64"",
388 : : i,
389 : : port_conf.rx_adv_conf.rss_conf.rss_hf,
390 : : local_port_conf.rx_adv_conf.rss_conf.rss_hf);
391 : : }
392 : :
393 : 0 : if (rte_eth_dev_configure(i, opt->eth_queues, nb_queues,
394 : : &local_port_conf) < 0) {
395 : 0 : evt_err("Failed to configure eth port [%d]", i);
396 : 0 : return -EINVAL;
397 : : }
398 : :
399 : 0 : for (j = 0; j < opt->eth_queues; j++) {
400 : 0 : if (rte_eth_rx_queue_setup(
401 : : i, j, NB_RX_DESC, rte_socket_id(), &rx_conf,
402 : 0 : opt->per_port_pool ? t->pool[i] :
403 : : t->pool[0]) < 0) {
404 : 0 : evt_err("Failed to setup eth port [%d] rx_queue: %d.",
405 : : i, 0);
406 : 0 : return -EINVAL;
407 : : }
408 : : }
409 : :
410 : 0 : if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
411 : : rte_socket_id(), NULL) < 0) {
412 : 0 : evt_err("Failed to setup eth port [%d] tx_queue: %d.",
413 : : i, 0);
414 : 0 : return -EINVAL;
415 : : }
416 : :
417 : 0 : ret = rte_eth_promiscuous_enable(i);
418 : 0 : if (ret != 0) {
419 : 0 : evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
420 : : i, rte_strerror(-ret));
421 : 0 : return ret;
422 : : }
423 : : }
424 : :
425 : : return 0;
426 : : }
427 : :
428 : : int
429 : 0 : pipeline_event_port_setup(struct evt_test *test, struct evt_options *opt,
430 : : uint8_t *queue_arr, uint8_t nb_queues,
431 : : const struct rte_event_port_conf p_conf)
432 : : {
433 : : int ret;
434 : : uint8_t port;
435 : : struct test_pipeline *t = evt_test_priv(test);
436 : :
437 : :
438 : : /* setup one port per worker, linking to all queues */
439 : 0 : for (port = 0; port < evt_nr_active_lcores(opt->wlcores); port++) {
440 : : struct worker_data *w = &t->worker[port];
441 : :
442 : 0 : w->dev_id = opt->dev_id;
443 : 0 : w->port_id = port;
444 : 0 : w->t = t;
445 : 0 : w->processed_pkts = 0;
446 : :
447 : 0 : ret = rte_event_port_setup(opt->dev_id, port, &p_conf);
448 : 0 : if (ret) {
449 : 0 : evt_err("failed to setup port %d", port);
450 : 0 : return ret;
451 : : }
452 : :
453 : 0 : if (rte_event_port_link(opt->dev_id, port, queue_arr, NULL,
454 : : nb_queues) != nb_queues)
455 : 0 : goto link_fail;
456 : : }
457 : :
458 : : return 0;
459 : :
460 : : link_fail:
461 : 0 : evt_err("failed to link queues to port %d", port);
462 : 0 : return -EINVAL;
463 : : }
464 : :
465 : : int
466 : 0 : pipeline_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
467 : : struct rte_event_port_conf prod_conf)
468 : : {
469 : : int ret = 0;
470 : : uint16_t prod;
471 : : struct rte_mempool *vector_pool = NULL;
472 : : struct rte_event_eth_rx_adapter_queue_conf queue_conf;
473 : :
474 : : memset(&queue_conf, 0,
475 : : sizeof(struct rte_event_eth_rx_adapter_queue_conf));
476 : 0 : queue_conf.ev.sched_type = opt->sched_type_list[0];
477 : 0 : if (opt->ena_vector) {
478 : 0 : unsigned int nb_elem = (opt->pool_sz / opt->vector_size) << 1;
479 : :
480 : 0 : nb_elem = RTE_MAX(512U, nb_elem);
481 : 0 : nb_elem += evt_nr_active_lcores(opt->wlcores) * 32;
482 : 0 : vector_pool = rte_event_vector_pool_create(
483 : : "vector_pool", nb_elem, 32, opt->vector_size,
484 : : opt->socket_id);
485 : 0 : if (vector_pool == NULL) {
486 : 0 : evt_err("failed to create event vector pool");
487 : 0 : return -ENOMEM;
488 : : }
489 : : }
490 : 0 : RTE_ETH_FOREACH_DEV(prod) {
491 : : struct rte_event_eth_rx_adapter_vector_limits limits;
492 : : uint32_t cap;
493 : :
494 : 0 : ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
495 : : prod, &cap);
496 : 0 : if (ret) {
497 : 0 : evt_err("failed to get event rx adapter[%d]"
498 : : " capabilities",
499 : : opt->dev_id);
500 : 0 : return ret;
501 : : }
502 : :
503 : 0 : if (opt->ena_vector) {
504 : : memset(&limits, 0, sizeof(limits));
505 : 0 : ret = rte_event_eth_rx_adapter_vector_limits_get(
506 : 0 : opt->dev_id, prod, &limits);
507 : 0 : if (ret) {
508 : 0 : evt_err("failed to get vector limits");
509 : 0 : return ret;
510 : : }
511 : :
512 : 0 : if (opt->vector_size < limits.min_sz ||
513 : 0 : opt->vector_size > limits.max_sz) {
514 : 0 : evt_err("Vector size [%d] not within limits max[%d] min[%d]",
515 : : opt->vector_size, limits.max_sz,
516 : : limits.min_sz);
517 : 0 : return -EINVAL;
518 : : }
519 : :
520 : 0 : if (limits.log2_sz &&
521 : 0 : !rte_is_power_of_2(opt->vector_size)) {
522 : 0 : evt_err("Vector size [%d] not power of 2",
523 : : opt->vector_size);
524 : 0 : return -EINVAL;
525 : : }
526 : :
527 : 0 : if (opt->vector_tmo_nsec > limits.max_timeout_ns ||
528 : 0 : opt->vector_tmo_nsec < limits.min_timeout_ns) {
529 : 0 : evt_err("Vector timeout [%" PRIu64
530 : : "] not within limits max[%" PRIu64
531 : : "] min[%" PRIu64 "]",
532 : : opt->vector_tmo_nsec,
533 : : limits.max_timeout_ns,
534 : : limits.min_timeout_ns);
535 : 0 : return -EINVAL;
536 : : }
537 : :
538 : 0 : if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR) {
539 : 0 : queue_conf.vector_sz = opt->vector_size;
540 : 0 : queue_conf.vector_timeout_ns =
541 : : opt->vector_tmo_nsec;
542 : 0 : queue_conf.rx_queue_flags |=
543 : : RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR;
544 : 0 : queue_conf.vector_mp = vector_pool;
545 : : } else {
546 : 0 : evt_err("Rx adapter doesn't support event vector");
547 : 0 : return -EINVAL;
548 : : }
549 : : }
550 : 0 : queue_conf.ev.queue_id = prod * stride;
551 : 0 : ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
552 : : &prod_conf);
553 : 0 : if (ret) {
554 : 0 : evt_err("failed to create rx adapter[%d]", prod);
555 : 0 : return ret;
556 : : }
557 : 0 : ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
558 : : &queue_conf);
559 : 0 : if (ret) {
560 : 0 : evt_err("failed to add rx queues to adapter[%d]", prod);
561 : 0 : return ret;
562 : : }
563 : :
564 : 0 : if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
565 : 0 : uint32_t service_id = -1U;
566 : :
567 : 0 : rte_event_eth_rx_adapter_service_id_get(prod,
568 : : &service_id);
569 : 0 : ret = evt_service_setup(service_id);
570 : 0 : if (ret) {
571 : 0 : evt_err("Failed to setup service core"
572 : : " for Rx adapter");
573 : 0 : return ret;
574 : : }
575 : : }
576 : :
577 : 0 : evt_info("Port[%d] using Rx adapter[%d] configured", prod,
578 : : prod);
579 : : }
580 : :
581 : : return ret;
582 : : }
583 : :
584 : : int
585 : 0 : pipeline_event_tx_adapter_setup(struct evt_options *opt,
586 : : struct rte_event_port_conf port_conf)
587 : : {
588 : : int ret = 0;
589 : : uint16_t consm;
590 : :
591 : 0 : RTE_ETH_FOREACH_DEV(consm) {
592 : : uint32_t cap;
593 : :
594 : 0 : ret = rte_event_eth_tx_adapter_caps_get(opt->dev_id,
595 : : consm, &cap);
596 : 0 : if (ret) {
597 : 0 : evt_err("failed to get event tx adapter[%d] caps",
598 : : consm);
599 : 0 : return ret;
600 : : }
601 : :
602 : 0 : if (opt->ena_vector) {
603 : 0 : if (!(cap &
604 : : RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR)) {
605 : 0 : evt_err("Tx adapter doesn't support event vector");
606 : 0 : return -EINVAL;
607 : : }
608 : : }
609 : :
610 : 0 : ret = rte_event_eth_tx_adapter_create(consm, opt->dev_id,
611 : : &port_conf);
612 : 0 : if (ret) {
613 : 0 : evt_err("failed to create tx adapter[%d]", consm);
614 : 0 : return ret;
615 : : }
616 : :
617 : 0 : ret = rte_event_eth_tx_adapter_queue_add(consm, consm, -1);
618 : 0 : if (ret) {
619 : 0 : evt_err("failed to add tx queues to adapter[%d]",
620 : : consm);
621 : 0 : return ret;
622 : : }
623 : :
624 : 0 : if (!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT)) {
625 : 0 : uint32_t service_id = -1U;
626 : :
627 : 0 : ret = rte_event_eth_tx_adapter_service_id_get(consm,
628 : : &service_id);
629 : 0 : if (ret != -ESRCH && ret != 0) {
630 : 0 : evt_err("Failed to get Tx adptr service ID");
631 : 0 : return ret;
632 : : }
633 : 0 : ret = evt_service_setup(service_id);
634 : 0 : if (ret) {
635 : 0 : evt_err("Failed to setup service core"
636 : : " for Tx adapter");
637 : 0 : return ret;
638 : : }
639 : : }
640 : :
641 : 0 : evt_info("Port[%d] using Tx adapter[%d] Configured", consm,
642 : : consm);
643 : : }
644 : :
645 : : return ret;
646 : : }
647 : :
648 : : static void
649 : 0 : pipeline_vector_array_free(struct rte_event events[], uint16_t num)
650 : : {
651 : : uint16_t i;
652 : :
653 : 0 : for (i = 0; i < num; i++) {
654 : 0 : rte_pktmbuf_free_bulk(
655 : 0 : &events[i].vec->mbufs[events[i].vec->elem_offset],
656 : 0 : events[i].vec->nb_elem);
657 : 0 : rte_mempool_put(rte_mempool_from_obj(events[i].vec),
658 : 0 : events[i].vec);
659 : : }
660 : 0 : }
661 : :
662 : : static void
663 : 0 : pipeline_event_port_flush(uint8_t dev_id __rte_unused, struct rte_event ev,
664 : : void *args __rte_unused)
665 : : {
666 : 0 : if (ev.event_type & RTE_EVENT_TYPE_VECTOR)
667 : 0 : pipeline_vector_array_free(&ev, 1);
668 : : else
669 : 0 : rte_pktmbuf_free(ev.mbuf);
670 : 0 : }
671 : :
672 : : void
673 : 0 : pipeline_worker_cleanup(uint8_t dev, uint8_t port, struct rte_event ev[],
674 : : uint16_t enq, uint16_t deq)
675 : : {
676 : : int i;
677 : :
678 : 0 : if (deq) {
679 : 0 : for (i = enq; i < deq; i++) {
680 : 0 : if (ev[i].op == RTE_EVENT_OP_RELEASE)
681 : 0 : continue;
682 : 0 : if (ev[i].event_type & RTE_EVENT_TYPE_VECTOR)
683 : 0 : pipeline_vector_array_free(&ev[i], 1);
684 : : else
685 : 0 : rte_pktmbuf_free(ev[i].mbuf);
686 : : }
687 : :
688 : 0 : for (i = enq; i < deq; i++)
689 : 0 : ev[i].op = RTE_EVENT_OP_RELEASE;
690 : :
691 : 0 : rte_event_enqueue_burst(dev, port, ev + enq, deq - enq);
692 : : }
693 : :
694 : 0 : rte_event_port_quiesce(dev, port, pipeline_event_port_flush, NULL);
695 : 0 : }
696 : :
697 : : void
698 : 0 : pipeline_ethdev_rx_stop(struct evt_test *test, struct evt_options *opt)
699 : : {
700 : : uint16_t i, j;
701 : : RTE_SET_USED(test);
702 : :
703 : 0 : if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
704 : 0 : RTE_ETH_FOREACH_DEV(i) {
705 : 0 : rte_event_eth_rx_adapter_stop(i);
706 : 0 : rte_event_eth_rx_adapter_queue_del(i, i, -1);
707 : 0 : for (j = 0; j < opt->eth_queues; j++)
708 : 0 : rte_eth_dev_rx_queue_stop(i, j);
709 : : }
710 : : }
711 : 0 : }
712 : :
713 : : void
714 : 0 : pipeline_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
715 : : {
716 : : uint16_t i;
717 : : RTE_SET_USED(test);
718 : : RTE_SET_USED(opt);
719 : :
720 : 0 : RTE_ETH_FOREACH_DEV(i) {
721 : 0 : rte_event_eth_tx_adapter_stop(i);
722 : 0 : rte_event_eth_tx_adapter_queue_del(i, i, -1);
723 : 0 : rte_eth_dev_tx_queue_stop(i, 0);
724 : 0 : rte_eth_dev_stop(i);
725 : : }
726 : 0 : }
727 : :
728 : : void
729 : 0 : pipeline_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
730 : : {
731 : : RTE_SET_USED(test);
732 : :
733 : 0 : rte_event_dev_stop(opt->dev_id);
734 : 0 : rte_event_dev_close(opt->dev_id);
735 : 0 : }
736 : :
737 : : int
738 : 0 : pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
739 : : {
740 : : struct test_pipeline *t = evt_test_priv(test);
741 : : int i, ret;
742 : :
743 : 0 : if (!opt->mbuf_sz)
744 : 0 : opt->mbuf_sz = RTE_MBUF_DEFAULT_BUF_SIZE;
745 : :
746 : 0 : if (!opt->max_pkt_sz)
747 : 0 : opt->max_pkt_sz = RTE_ETHER_MAX_LEN;
748 : :
749 : 0 : RTE_ETH_FOREACH_DEV(i) {
750 : : struct rte_eth_dev_info dev_info;
751 : : uint16_t data_size = 0;
752 : :
753 : : memset(&dev_info, 0, sizeof(dev_info));
754 : 0 : ret = rte_eth_dev_info_get(i, &dev_info);
755 : 0 : if (ret != 0) {
756 : 0 : evt_err("Error during getting device (port %u) info: %s\n",
757 : : i, strerror(-ret));
758 : 0 : return ret;
759 : : }
760 : :
761 : 0 : if (dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
762 : : dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
763 : 0 : data_size = opt->max_pkt_sz /
764 : 0 : dev_info.rx_desc_lim.nb_mtu_seg_max;
765 : 0 : data_size += RTE_PKTMBUF_HEADROOM;
766 : :
767 : 0 : if (data_size > opt->mbuf_sz)
768 : 0 : opt->mbuf_sz = data_size;
769 : : }
770 : 0 : if (opt->per_port_pool) {
771 : : char name[RTE_MEMPOOL_NAMESIZE];
772 : :
773 : 0 : snprintf(name, RTE_MEMPOOL_NAMESIZE, "%s-%d",
774 : : test->name, i);
775 : 0 : t->pool[i] = rte_pktmbuf_pool_create(
776 : : name, /* mempool name */
777 : 0 : opt->pool_sz, /* number of elements*/
778 : : 0, /* cache size*/
779 : 0 : 0, opt->mbuf_sz, opt->socket_id); /* flags */
780 : :
781 : 0 : if (t->pool[i] == NULL) {
782 : 0 : evt_err("failed to create mempool %s", name);
783 : 0 : return -ENOMEM;
784 : : }
785 : : }
786 : : }
787 : :
788 : 0 : if (!opt->per_port_pool) {
789 : 0 : t->pool[0] = rte_pktmbuf_pool_create(
790 : : test->name, /* mempool name */
791 : 0 : opt->pool_sz, /* number of elements*/
792 : : 0, /* cache size*/
793 : 0 : 0, opt->mbuf_sz, opt->socket_id); /* flags */
794 : :
795 : 0 : if (t->pool[0] == NULL) {
796 : 0 : evt_err("failed to create mempool");
797 : 0 : return -ENOMEM;
798 : : }
799 : : }
800 : :
801 : : return 0;
802 : : }
803 : :
804 : : void
805 : 0 : pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
806 : : {
807 : : struct test_pipeline *t = evt_test_priv(test);
808 : : int i;
809 : :
810 : : RTE_SET_USED(opt);
811 : 0 : if (opt->per_port_pool) {
812 : 0 : RTE_ETH_FOREACH_DEV(i)
813 : 0 : rte_mempool_free(t->pool[i]);
814 : : } else {
815 : 0 : rte_mempool_free(t->pool[0]);
816 : : }
817 : 0 : }
818 : :
819 : : int
820 : 0 : pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
821 : : {
822 : : void *test_pipeline;
823 : :
824 : 0 : test_pipeline = rte_zmalloc_socket(test->name,
825 : : sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
826 : : opt->socket_id);
827 : 0 : if (test_pipeline == NULL) {
828 : 0 : evt_err("failed to allocate test_pipeline memory");
829 : 0 : goto nomem;
830 : : }
831 : 0 : test->test_priv = test_pipeline;
832 : :
833 : : struct test_pipeline *t = evt_test_priv(test);
834 : :
835 : 0 : t->nb_workers = evt_nr_active_lcores(opt->wlcores);
836 : 0 : t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
837 : 0 : t->done = false;
838 : 0 : t->nb_flows = opt->nb_flows;
839 : 0 : t->result = EVT_TEST_FAILED;
840 : 0 : t->opt = opt;
841 : 0 : opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
842 : 0 : memcpy(t->sched_type_list, opt->sched_type_list,
843 : : sizeof(opt->sched_type_list));
844 : 0 : return 0;
845 : : nomem:
846 : 0 : return -ENOMEM;
847 : : }
848 : :
849 : : void
850 : 0 : pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
851 : : {
852 : : RTE_SET_USED(opt);
853 : :
854 : 0 : rte_free(test->test_priv);
855 : 0 : }
|