1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
9 #include <rte_cycles.h>
10 #include <rte_errno.h>
11 #include <rte_mempool.h>
13 #include <rte_mbuf_dyn.h>
15 #ifdef RTE_EXEC_ENV_WINDOWS
17 test_distributor(void)
19 printf("distributor not supported on Windows, skipping test\n");
25 #include <rte_distributor.h>
26 #include <rte_string_fns.h>
28 #define ITER_POWER 20 /* log 2 of how many iterations we do when timing. */
30 #define BIG_BATCH 1024
32 typedef uint32_t seq_dynfield_t;
33 static int seq_dynfield_offset = -1;
35 static inline seq_dynfield_t *
36 seq_field(struct rte_mbuf *mbuf)
38 return RTE_MBUF_DYNFIELD(mbuf, seq_dynfield_offset, seq_dynfield_t *);
41 struct worker_params {
43 struct rte_distributor *dist;
46 struct worker_params worker_params;
48 /* statics - all zero-initialized by default */
49 static volatile int quit; /**< general quit variable for all threads */
50 static volatile int zero_quit; /**< var for when we just want thr0 to quit*/
51 static volatile int zero_sleep; /**< thr0 has quit basic loop and is sleeping*/
52 static volatile unsigned worker_idx;
53 static volatile unsigned zero_idx;
56 volatile unsigned handled_packets;
57 } __rte_cache_aligned;
58 struct worker_stats worker_stats[RTE_MAX_LCORE];
60 /* returns the total count of the number of packets handled by the worker
61 * functions given below.
63 static inline unsigned
64 total_packet_count(void)
66 unsigned i, count = 0;
67 for (i = 0; i < worker_idx; i++)
68 count += __atomic_load_n(&worker_stats[i].handled_packets,
73 /* resets the packet counts for a new test */
75 clear_packet_count(void)
78 for (i = 0; i < RTE_MAX_LCORE; i++)
79 __atomic_store_n(&worker_stats[i].handled_packets, 0,
83 /* this is the basic worker function for sanity test
84 * it does nothing but return packets and count them.
87 handle_work(void *arg)
89 struct rte_mbuf *buf[8] __rte_cache_aligned;
90 struct worker_params *wp = arg;
91 struct rte_distributor *db = wp->dist;
93 unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
95 num = rte_distributor_get_pkt(db, id, buf, NULL, 0);
97 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
99 num = rte_distributor_get_pkt(db, id,
102 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
104 rte_distributor_return_pkt(db, id, buf, num);
108 /* do basic sanity testing of the distributor. This test tests the following:
109 * - send 32 packets through distributor with the same tag and ensure they
110 * all go to the one worker
111 * - send 32 packets through the distributor with two different tags and
112 * verify that they go equally to two different workers.
113 * - send 32 packets with different tags through the distributors and
114 * just verify we get all packets back.
115 * - send 1024 packets through the distributor, gathering the returned packets
116 * as we go. Then verify that we correctly got all 1024 pointers back again,
117 * not necessarily in the same order (as different flows).
120 sanity_test(struct worker_params *wp, struct rte_mempool *p)
122 struct rte_distributor *db = wp->dist;
123 struct rte_mbuf *bufs[BURST];
124 struct rte_mbuf *returns[BURST*2];
125 unsigned int i, count;
126 unsigned int retries;
127 unsigned int processed;
129 printf("=== Basic distributor sanity tests ===\n");
130 clear_packet_count();
131 if (rte_mempool_get_bulk(p, (void *)bufs, BURST) != 0) {
132 printf("line %d: Error getting mbufs from pool\n", __LINE__);
136 /* now set all hash values in all buffers to zero, so all pkts go to the
137 * one worker thread */
138 for (i = 0; i < BURST; i++)
139 bufs[i]->hash.usr = 0;
142 while (processed < BURST)
143 processed += rte_distributor_process(db, &bufs[processed],
149 rte_distributor_flush(db);
150 count += rte_distributor_returned_pkts(db,
152 } while (count < BURST);
154 if (total_packet_count() != BURST) {
155 printf("Line %d: Error, not all packets flushed. "
156 "Expected %u, got %u\n",
157 __LINE__, BURST, total_packet_count());
158 rte_mempool_put_bulk(p, (void *)bufs, BURST);
162 for (i = 0; i < rte_lcore_count() - 1; i++)
163 printf("Worker %u handled %u packets\n", i,
164 __atomic_load_n(&worker_stats[i].handled_packets,
166 printf("Sanity test with all zero hashes done.\n");
168 /* pick two flows and check they go correctly */
169 if (rte_lcore_count() >= 3) {
170 clear_packet_count();
171 for (i = 0; i < BURST; i++)
172 bufs[i]->hash.usr = (i & 1) << 8;
174 rte_distributor_process(db, bufs, BURST);
177 rte_distributor_flush(db);
178 count += rte_distributor_returned_pkts(db,
180 } while (count < BURST);
181 if (total_packet_count() != BURST) {
182 printf("Line %d: Error, not all packets flushed. "
183 "Expected %u, got %u\n",
184 __LINE__, BURST, total_packet_count());
185 rte_mempool_put_bulk(p, (void *)bufs, BURST);
189 for (i = 0; i < rte_lcore_count() - 1; i++)
190 printf("Worker %u handled %u packets\n", i,
192 &worker_stats[i].handled_packets,
194 printf("Sanity test with two hash values done\n");
197 /* give a different hash value to each packet,
198 * so load gets distributed */
199 clear_packet_count();
200 for (i = 0; i < BURST; i++)
201 bufs[i]->hash.usr = i+1;
203 rte_distributor_process(db, bufs, BURST);
206 rte_distributor_flush(db);
207 count += rte_distributor_returned_pkts(db,
209 } while (count < BURST);
210 if (total_packet_count() != BURST) {
211 printf("Line %d: Error, not all packets flushed. "
212 "Expected %u, got %u\n",
213 __LINE__, BURST, total_packet_count());
214 rte_mempool_put_bulk(p, (void *)bufs, BURST);
218 for (i = 0; i < rte_lcore_count() - 1; i++)
219 printf("Worker %u handled %u packets\n", i,
220 __atomic_load_n(&worker_stats[i].handled_packets,
222 printf("Sanity test with non-zero hashes done\n");
224 rte_mempool_put_bulk(p, (void *)bufs, BURST);
226 /* sanity test with BIG_BATCH packets to ensure they all arrived back
227 * from the returned packets function */
228 clear_packet_count();
229 struct rte_mbuf *many_bufs[BIG_BATCH], *return_bufs[BIG_BATCH];
230 unsigned num_returned = 0;
231 unsigned int num_being_processed = 0;
232 unsigned int return_buffer_capacity = 127;/* RTE_DISTRIB_RETURNS_MASK */
234 /* flush out any remaining packets */
235 rte_distributor_flush(db);
236 rte_distributor_clear_returns(db);
238 if (rte_mempool_get_bulk(p, (void *)many_bufs, BIG_BATCH) != 0) {
239 printf("line %d: Error getting mbufs from pool\n", __LINE__);
242 for (i = 0; i < BIG_BATCH; i++)
243 many_bufs[i]->hash.usr = i << 2;
245 printf("=== testing big burst (%s) ===\n", wp->name);
246 for (i = 0; i < BIG_BATCH/BURST; i++) {
247 rte_distributor_process(db,
248 &many_bufs[i*BURST], BURST);
249 num_being_processed += BURST;
251 count = rte_distributor_returned_pkts(db,
252 &return_bufs[num_returned],
253 BIG_BATCH - num_returned);
254 num_being_processed -= count;
255 num_returned += count;
256 rte_distributor_flush(db);
257 } while (num_being_processed + BURST > return_buffer_capacity);
261 rte_distributor_flush(db);
262 count = rte_distributor_returned_pkts(db,
263 &return_bufs[num_returned],
264 BIG_BATCH - num_returned);
265 num_returned += count;
267 } while ((num_returned < BIG_BATCH) && (retries < 100));
269 if (num_returned != BIG_BATCH) {
270 printf("line %d: Missing packets, expected %d\n",
271 __LINE__, num_returned);
272 rte_mempool_put_bulk(p, (void *)many_bufs, BIG_BATCH);
276 /* big check - make sure all packets made it back!! */
277 for (i = 0; i < BIG_BATCH; i++) {
279 struct rte_mbuf *src = many_bufs[i];
280 for (j = 0; j < BIG_BATCH; j++) {
281 if (return_bufs[j] == src)
285 if (j == BIG_BATCH) {
286 printf("Error: could not find source packet #%u\n", i);
287 rte_mempool_put_bulk(p, (void *)many_bufs, BIG_BATCH);
291 printf("Sanity test of returned packets done\n");
293 rte_mempool_put_bulk(p, (void *)many_bufs, BIG_BATCH);
300 /* to test that the distributor does not lose packets, we use this worker
301 * function which frees mbufs when it gets them. The distributor thread does
302 * the mbuf allocation. If distributor drops packets we'll eventually run out
306 handle_work_with_free_mbufs(void *arg)
308 struct rte_mbuf *buf[8] __rte_cache_aligned;
309 struct worker_params *wp = arg;
310 struct rte_distributor *d = wp->dist;
313 unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
315 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
317 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
319 for (i = 0; i < num; i++)
320 rte_pktmbuf_free(buf[i]);
321 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
323 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
325 rte_distributor_return_pkt(d, id, buf, num);
329 /* Perform a sanity test of the distributor with a large number of packets,
330 * where we allocate a new set of mbufs for each burst. The workers then
331 * free the mbufs. This ensures that we don't have any packet leaks in the
335 sanity_test_with_mbuf_alloc(struct worker_params *wp, struct rte_mempool *p)
337 struct rte_distributor *d = wp->dist;
339 struct rte_mbuf *bufs[BURST];
340 unsigned int processed;
342 printf("=== Sanity test with mbuf alloc/free (%s) ===\n", wp->name);
344 clear_packet_count();
345 for (i = 0; i < ((1<<ITER_POWER)); i += BURST) {
347 while (rte_mempool_get_bulk(p, (void *)bufs, BURST) < 0)
348 rte_distributor_process(d, NULL, 0);
349 for (j = 0; j < BURST; j++) {
350 bufs[j]->hash.usr = (i+j) << 1;
354 while (processed < BURST)
355 processed += rte_distributor_process(d,
356 &bufs[processed], BURST - processed);
359 rte_distributor_flush(d);
363 if (total_packet_count() < (1<<ITER_POWER)) {
364 printf("Line %u: Packet count is incorrect, %u, expected %u\n",
365 __LINE__, total_packet_count(),
370 printf("Sanity test with mbuf alloc/free passed\n\n");
375 handle_work_for_shutdown_test(void *arg)
377 struct rte_mbuf *buf[8] __rte_cache_aligned;
378 struct worker_params *wp = arg;
379 struct rte_distributor *d = wp->dist;
381 unsigned int zero_id = 0;
382 unsigned int zero_unset;
383 const unsigned int id = __atomic_fetch_add(&worker_idx, 1,
386 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
389 zero_unset = RTE_MAX_LCORE;
390 __atomic_compare_exchange_n(&zero_idx, &zero_unset, id,
391 false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
393 zero_id = __atomic_load_n(&zero_idx, __ATOMIC_ACQUIRE);
395 /* wait for quit single globally, or for worker zero, wait
397 while (!quit && !(id == zero_id && zero_quit)) {
398 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
400 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
403 zero_unset = RTE_MAX_LCORE;
404 __atomic_compare_exchange_n(&zero_idx, &zero_unset, id,
405 false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
407 zero_id = __atomic_load_n(&zero_idx, __ATOMIC_ACQUIRE);
410 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
413 rte_distributor_return_pkt(d, id, NULL, 0);
415 /* for worker zero, allow it to restart to pick up last packet
416 * when all workers are shutting down.
418 __atomic_store_n(&zero_sleep, 1, __ATOMIC_RELEASE);
421 __atomic_store_n(&zero_sleep, 0, __ATOMIC_RELEASE);
423 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
426 __atomic_fetch_add(&worker_stats[id].handled_packets,
427 num, __ATOMIC_RELAXED);
428 num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
431 rte_distributor_return_pkt(d, id, buf, num);
436 /* Perform a sanity test of the distributor with a large number of packets,
437 * where we allocate a new set of mbufs for each burst. The workers then
438 * free the mbufs. This ensures that we don't have any packet leaks in the
442 sanity_test_with_worker_shutdown(struct worker_params *wp,
443 struct rte_mempool *p)
445 struct rte_distributor *d = wp->dist;
446 struct rte_mbuf *bufs[BURST];
447 struct rte_mbuf *bufs2[BURST];
449 unsigned int failed = 0;
450 unsigned int processed = 0;
452 printf("=== Sanity test of worker shutdown ===\n");
454 clear_packet_count();
456 if (rte_mempool_get_bulk(p, (void *)bufs, BURST) != 0) {
457 printf("line %d: Error getting mbufs from pool\n", __LINE__);
462 * Now set all hash values in all buffers to same value so all
463 * pkts go to the one worker thread
465 for (i = 0; i < BURST; i++)
466 bufs[i]->hash.usr = 1;
469 while (processed < BURST)
470 processed += rte_distributor_process(d, &bufs[processed],
472 rte_distributor_flush(d);
474 /* at this point, we will have processed some packets and have a full
475 * backlog for the other ones at worker 0.
478 /* get more buffers to queue up, again setting them to the same flow */
479 if (rte_mempool_get_bulk(p, (void *)bufs2, BURST) != 0) {
480 printf("line %d: Error getting mbufs from pool\n", __LINE__);
481 rte_mempool_put_bulk(p, (void *)bufs, BURST);
484 for (i = 0; i < BURST; i++)
485 bufs2[i]->hash.usr = 1;
487 /* get worker zero to quit */
489 rte_distributor_process(d, bufs2, BURST);
491 /* flush the distributor */
492 rte_distributor_flush(d);
493 while (!__atomic_load_n(&zero_sleep, __ATOMIC_ACQUIRE))
494 rte_distributor_flush(d);
497 while (__atomic_load_n(&zero_sleep, __ATOMIC_ACQUIRE))
500 for (i = 0; i < rte_lcore_count() - 1; i++)
501 printf("Worker %u handled %u packets\n", i,
502 __atomic_load_n(&worker_stats[i].handled_packets,
505 if (total_packet_count() != BURST * 2) {
506 printf("Line %d: Error, not all packets flushed. "
507 "Expected %u, got %u\n",
508 __LINE__, BURST * 2, total_packet_count());
512 rte_mempool_put_bulk(p, (void *)bufs, BURST);
513 rte_mempool_put_bulk(p, (void *)bufs2, BURST);
518 printf("Sanity test with worker shutdown passed\n\n");
522 /* Test that the flush function is able to move packets between workers when
523 * one worker shuts down..
526 test_flush_with_worker_shutdown(struct worker_params *wp,
527 struct rte_mempool *p)
529 struct rte_distributor *d = wp->dist;
530 struct rte_mbuf *bufs[BURST];
532 unsigned int failed = 0;
533 unsigned int processed;
535 printf("=== Test flush fn with worker shutdown (%s) ===\n", wp->name);
537 clear_packet_count();
538 if (rte_mempool_get_bulk(p, (void *)bufs, BURST) != 0) {
539 printf("line %d: Error getting mbufs from pool\n", __LINE__);
543 /* now set all hash values in all buffers to zero, so all pkts go to the
544 * one worker thread */
545 for (i = 0; i < BURST; i++)
546 bufs[i]->hash.usr = 0;
549 while (processed < BURST)
550 processed += rte_distributor_process(d, &bufs[processed],
552 /* at this point, we will have processed some packets and have a full
553 * backlog for the other ones at worker 0.
556 /* get worker zero to quit */
559 /* flush the distributor */
560 rte_distributor_flush(d);
562 while (!__atomic_load_n(&zero_sleep, __ATOMIC_ACQUIRE))
563 rte_distributor_flush(d);
567 while (__atomic_load_n(&zero_sleep, __ATOMIC_ACQUIRE))
570 for (i = 0; i < rte_lcore_count() - 1; i++)
571 printf("Worker %u handled %u packets\n", i,
572 __atomic_load_n(&worker_stats[i].handled_packets,
575 if (total_packet_count() != BURST) {
576 printf("Line %d: Error, not all packets flushed. "
577 "Expected %u, got %u\n",
578 __LINE__, BURST, total_packet_count());
582 rte_mempool_put_bulk(p, (void *)bufs, BURST);
587 printf("Flush test with worker shutdown passed\n\n");
592 handle_and_mark_work(void *arg)
594 struct rte_mbuf *buf[8] __rte_cache_aligned;
595 struct worker_params *wp = arg;
596 struct rte_distributor *db = wp->dist;
598 unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
599 num = rte_distributor_get_pkt(db, id, buf, NULL, 0);
601 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
603 for (i = 0; i < num; i++)
604 *seq_field(buf[i]) += id + 1;
605 num = rte_distributor_get_pkt(db, id,
608 __atomic_fetch_add(&worker_stats[id].handled_packets, num,
610 rte_distributor_return_pkt(db, id, buf, num);
614 /* sanity_mark_test sends packets to workers which mark them.
615 * Every packet has also encoded sequence number.
616 * The returned packets are sorted and verified if they were handled
620 sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
622 const unsigned int buf_count = 24;
623 const unsigned int burst = 8;
624 const unsigned int shift = 12;
625 const unsigned int seq_shift = 10;
627 struct rte_distributor *db = wp->dist;
628 struct rte_mbuf *bufs[buf_count];
629 struct rte_mbuf *returns[buf_count];
630 unsigned int i, count, id;
631 unsigned int sorted[buf_count], seq;
632 unsigned int failed = 0;
633 unsigned int processed;
635 printf("=== Marked packets test ===\n");
636 clear_packet_count();
637 if (rte_mempool_get_bulk(p, (void *)bufs, buf_count) != 0) {
638 printf("line %d: Error getting mbufs from pool\n", __LINE__);
642 /* bufs' hashes will be like these below, but shifted left.
643 * The shifting is for avoiding collisions with backlogs
644 * and in-flight tags left by previous tests.
645 * [1, 1, 1, 1, 1, 1, 1, 1
646 * 1, 1, 1, 1, 2, 2, 2, 2
647 * 2, 2, 2, 2, 1, 1, 1, 1]
649 for (i = 0; i < burst; i++) {
650 bufs[0 * burst + i]->hash.usr = 1 << shift;
651 bufs[1 * burst + i]->hash.usr = ((i < burst / 2) ? 1 : 2)
653 bufs[2 * burst + i]->hash.usr = ((i < burst / 2) ? 2 : 1)
656 /* Assign a sequence number to each packet. The sequence is shifted,
657 * so that lower bits will hold mark from worker.
659 for (i = 0; i < buf_count; i++)
660 *seq_field(bufs[i]) = i << seq_shift;
663 for (i = 0; i < buf_count/burst; i++) {
665 while (processed < burst)
666 processed += rte_distributor_process(db,
667 &bufs[i * burst + processed],
669 count += rte_distributor_returned_pkts(db, &returns[count],
674 rte_distributor_flush(db);
675 count += rte_distributor_returned_pkts(db, &returns[count],
677 } while (count < buf_count);
679 for (i = 0; i < rte_lcore_count() - 1; i++)
680 printf("Worker %u handled %u packets\n", i,
681 __atomic_load_n(&worker_stats[i].handled_packets,
684 /* Sort returned packets by sent order (sequence numbers). */
685 for (i = 0; i < buf_count; i++) {
686 seq = *seq_field(returns[i]) >> seq_shift;
687 id = *seq_field(returns[i]) - (seq << seq_shift);
691 /* Verify that packets [0-11] and [20-23] were processed
694 for (i = 1; i < 12; i++) {
695 if (sorted[i] != sorted[0]) {
696 printf("Packet number %u processed by worker %u,"
697 " but should be processes by worker %u\n",
698 i, sorted[i], sorted[0]);
702 for (i = 20; i < 24; i++) {
703 if (sorted[i] != sorted[0]) {
704 printf("Packet number %u processed by worker %u,"
705 " but should be processes by worker %u\n",
706 i, sorted[i], sorted[0]);
710 /* And verify that packets [12-19] were processed
711 * by the another worker
713 for (i = 13; i < 20; i++) {
714 if (sorted[i] != sorted[12]) {
715 printf("Packet number %u processed by worker %u,"
716 " but should be processes by worker %u\n",
717 i, sorted[i], sorted[12]);
722 rte_mempool_put_bulk(p, (void *)bufs, buf_count);
727 printf("Marked packets test passed\n");
732 int test_error_distributor_create_name(void)
734 struct rte_distributor *d = NULL;
735 struct rte_distributor *db = NULL;
738 d = rte_distributor_create(name, rte_socket_id(),
739 rte_lcore_count() - 1,
740 RTE_DIST_ALG_SINGLE);
741 if (d != NULL || rte_errno != EINVAL) {
742 printf("ERROR: No error on create() with NULL name param\n");
746 db = rte_distributor_create(name, rte_socket_id(),
747 rte_lcore_count() - 1,
749 if (db != NULL || rte_errno != EINVAL) {
750 printf("ERROR: No error on create() with NULL param\n");
759 int test_error_distributor_create_numworkers(void)
761 struct rte_distributor *ds = NULL;
762 struct rte_distributor *db = NULL;
764 ds = rte_distributor_create("test_numworkers", rte_socket_id(),
766 RTE_DIST_ALG_SINGLE);
767 if (ds != NULL || rte_errno != EINVAL) {
768 printf("ERROR: No error on create() with num_workers > MAX\n");
772 db = rte_distributor_create("test_numworkers", rte_socket_id(),
775 if (db != NULL || rte_errno != EINVAL) {
776 printf("ERROR: No error on create() num_workers > MAX\n");
784 /* Useful function which ensures that all worker functions terminate */
786 quit_workers(struct worker_params *wp, struct rte_mempool *p)
788 struct rte_distributor *d = wp->dist;
789 const unsigned num_workers = rte_lcore_count() - 1;
791 struct rte_mbuf *bufs[RTE_MAX_LCORE];
792 struct rte_mbuf *returns[RTE_MAX_LCORE];
793 if (rte_mempool_get_bulk(p, (void *)bufs, num_workers) != 0) {
794 printf("line %d: Error getting mbufs from pool\n", __LINE__);
800 for (i = 0; i < num_workers; i++) {
801 bufs[i]->hash.usr = i << 1;
802 rte_distributor_process(d, &bufs[i], 1);
805 rte_distributor_process(d, NULL, 0);
806 rte_distributor_flush(d);
807 rte_eal_mp_wait_lcore();
809 while (rte_distributor_returned_pkts(d, returns, RTE_MAX_LCORE))
812 rte_distributor_clear_returns(d);
813 rte_mempool_put_bulk(p, (void *)bufs, num_workers);
817 zero_idx = RTE_MAX_LCORE;
823 test_distributor(void)
825 static struct rte_distributor *ds;
826 static struct rte_distributor *db;
827 static struct rte_distributor *dist[2];
828 static struct rte_mempool *p;
831 static const struct rte_mbuf_dynfield seq_dynfield_desc = {
832 .name = "test_distributor_dynfield_seq",
833 .size = sizeof(seq_dynfield_t),
834 .align = __alignof__(seq_dynfield_t),
836 seq_dynfield_offset =
837 rte_mbuf_dynfield_register(&seq_dynfield_desc);
838 if (seq_dynfield_offset < 0) {
839 printf("Error registering mbuf field\n");
843 if (rte_lcore_count() < 2) {
844 printf("Not enough cores for distributor_autotest, expecting at least 2\n");
849 db = rte_distributor_create("Test_dist_burst", rte_socket_id(),
850 rte_lcore_count() - 1,
853 printf("Error creating burst distributor\n");
857 rte_distributor_flush(db);
858 rte_distributor_clear_returns(db);
862 ds = rte_distributor_create("Test_dist_single",
864 rte_lcore_count() - 1,
865 RTE_DIST_ALG_SINGLE);
867 printf("Error creating single distributor\n");
871 rte_distributor_flush(ds);
872 rte_distributor_clear_returns(ds);
875 const unsigned nb_bufs = (511 * rte_lcore_count()) < BIG_BATCH ?
876 (BIG_BATCH * 2) - 1 : (511 * rte_lcore_count());
878 p = rte_pktmbuf_pool_create("DT_MBUF_POOL", nb_bufs, BURST,
879 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
881 printf("Error creating mempool\n");
889 for (i = 0; i < 2; i++) {
891 worker_params.dist = dist[i];
893 strlcpy(worker_params.name, "burst",
894 sizeof(worker_params.name));
896 strlcpy(worker_params.name, "single",
897 sizeof(worker_params.name));
899 rte_eal_mp_remote_launch(handle_work,
900 &worker_params, SKIP_MAIN);
901 if (sanity_test(&worker_params, p) < 0)
903 quit_workers(&worker_params, p);
905 rte_eal_mp_remote_launch(handle_work_with_free_mbufs,
906 &worker_params, SKIP_MAIN);
907 if (sanity_test_with_mbuf_alloc(&worker_params, p) < 0)
909 quit_workers(&worker_params, p);
911 if (rte_lcore_count() > 2) {
912 rte_eal_mp_remote_launch(handle_work_for_shutdown_test,
915 if (sanity_test_with_worker_shutdown(&worker_params,
918 quit_workers(&worker_params, p);
920 rte_eal_mp_remote_launch(handle_work_for_shutdown_test,
923 if (test_flush_with_worker_shutdown(&worker_params,
926 quit_workers(&worker_params, p);
928 rte_eal_mp_remote_launch(handle_and_mark_work,
929 &worker_params, SKIP_MAIN);
930 if (sanity_mark_test(&worker_params, p) < 0)
932 quit_workers(&worker_params, p);
935 printf("Too few cores to run worker shutdown test\n");
940 if (test_error_distributor_create_numworkers() == -1 ||
941 test_error_distributor_create_name() == -1) {
942 printf("rte_distributor_create parameter check tests failed");
949 quit_workers(&worker_params, p);
953 #endif /* !RTE_EXEC_ENV_WINDOWS */
955 REGISTER_TEST_COMMAND(distributor_autotest, test_distributor);