4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #ifdef __INTEL_COMPILER
49 #pragma warning(disable:2259) /* conversion may lose significant bits */
50 #pragma warning(disable:181) /* Arg incompatible with format string */
53 #define TEST_HZ_PER_KHZ 1000
54 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
56 #define MAX_QEMPTY_TIME_MSEC 50000
57 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
58 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
59 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
61 /**< structures for testing rte_red performance and function */
62 struct test_rte_red_config { /**< Test structure for RTE_RED config */
63 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
64 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
65 uint8_t *wq_log2; /**< Test wq_log2 value to use */
66 uint32_t min_th; /**< Queue minimum threshold */
67 uint32_t max_th; /**< Queue maximum threshold */
68 uint8_t *maxp_inv; /**< Inverse mark probability */
71 struct test_queue { /**< Test structure for RTE_RED Queues */
72 struct rte_red *rdata; /**< RTE_RED runtime data */
73 uint32_t num_queues; /**< Number of RTE_RED queues to test */
74 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
75 uint32_t *q; /**< Queue size */
76 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
77 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
78 uint32_t avg_tolerance; /**< Tolerance in queue average */
79 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
82 struct test_var { /**< Test variables used for testing RTE_RED */
83 uint32_t wait_usec; /**< Micro second wait interval */
84 uint32_t num_iterations; /**< Number of test iterations */
85 uint32_t num_ops; /**< Number of test operations */
86 uint64_t clk_freq; /**< CPU clock frequency */
87 uint32_t sleep_sec; /**< Seconds to sleep */
88 uint32_t *dropped; /**< Test operations dropped */
89 uint32_t *enqueued; /**< Test operations enqueued */
92 struct test_config { /**< Master test structure for RTE_RED */
93 const char *ifname; /**< Interface name */
94 const char *msg; /**< Test message for display */
95 const char *htxt; /**< Header txt display for result output */
96 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
97 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
98 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
99 uint32_t *tlevel; /**< Queue levels */
107 /**< Test structure to define tests to run */
109 struct test_config *testcfg;
110 enum test_result (*testfn)(struct test_config *);
115 uint64_t clk_min; /**< min clocks */
116 uint64_t clk_max; /**< max clocks */
117 uint64_t clk_avgc; /**< count to calc average */
118 double clk_avg; /**< cumulative sum to calc average */
122 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
123 static double inv_cycles_per_byte = 0;
124 static double pkt_time_usec = 0;
126 static void init_port_ts(uint64_t cpu_clock)
128 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
129 inv_cycles_per_byte = 1.0 / cycles_per_byte;
130 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
133 static uint64_t get_port_ts(void)
135 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
138 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
140 p->clk_min = (uint64_t)(-1LL);
147 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
153 "xchgl %%ebx, %%edi;\n"
154 : : : "%eax", "%edi", "%ecx", "%edx" );
156 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
158 p->clk_start = rte_rdtsc();
161 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
163 uint64_t clk_start = rte_rdtsc() - p->clk_start;
166 p->clk_avg += (double) clk_start;
168 if (clk_start > p->clk_max)
169 p->clk_max = clk_start;
170 if (clk_start < p->clk_min)
171 p->clk_min = clk_start;
174 static void rdtsc_prof_print(struct rdtsc_prof *p)
177 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
182 (p->clk_avg / ((double) p->clk_avgc)));
186 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
190 * scale by 1/n and convert from fixed-point to integer
192 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
195 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
199 * scale by 1/n and convert from fixed-point to floating-point
201 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
204 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
209 * scale by n and convert from integer to fixed-point
211 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
214 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
216 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
219 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
221 return (double)dropped / ((double)enqueued + (double)dropped);
225 * calculate the drop probability
227 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
228 uint32_t maxp_inv, uint32_t avg)
230 double drop_prob = 0.0;
234 } else if (avg < max_th) {
235 drop_prob = (1.0 / (double)maxp_inv)
236 * ((double)(avg - min_th)
237 / (double)(max_th - min_th));
245 * check if drop rate matches drop probability within tolerance
247 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
249 double abs_diff = 0.0;
252 abs_diff = fabs(drop_rate - drop_prob);
253 if ((int)abs_diff == 0) {
256 *diff = (abs_diff / drop_prob) * 100.0;
257 if (*diff > tolerance) {
265 * check if average queue size is within tolerance
267 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
269 double abs_diff = 0.0;
272 abs_diff = fabs(avg - exp_avg);
273 if ((int)abs_diff == 0) {
276 *diff = (abs_diff / exp_avg) * 100.0;
277 if (*diff > tolerance) {
285 * get the clk frequency in Hz
287 static uint64_t get_machclk_freq(void)
292 uint64_t clk_freq_hz = 0;
293 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
294 struct timespec req = {0, 0};
299 clock_gettime(CLOCK_REALTIME, &tv_start);
302 if (nanosleep(&req, NULL) != 0) {
303 perror("get_machclk_freq()");
307 clock_gettime(CLOCK_REALTIME, &tv_end);
310 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
311 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
312 USEC_PER_MSEC); /**< diff is in micro secs */
317 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
318 return (clk_freq_hz);
322 * initialize the test rte_red config
324 static enum test_result
325 test_rte_red_init(struct test_config *tcfg)
329 tcfg->tvar->clk_freq = get_machclk_freq();
330 init_port_ts( tcfg->tvar->clk_freq );
332 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
333 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
334 (uint16_t)tcfg->tconfig->wq_log2[i],
335 (uint16_t)tcfg->tconfig->min_th,
336 (uint16_t)tcfg->tconfig->max_th,
337 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
342 *tcfg->tqueue->q = 0;
343 *tcfg->tvar->dropped = 0;
344 *tcfg->tvar->enqueued = 0;
349 * enqueue until actual queue size reaches target level
352 increase_actual_qsize(struct rte_red_config *red_cfg,
360 for (i = 0; i < attempts; i++) {
366 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
373 * check if target actual queue size has been reached
384 * enqueue until average queue size reaches target level
387 increase_average_qsize(struct rte_red_config *red_cfg,
396 for (i = 0; i < num_ops; i++) {
400 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
403 * check if target average queue size has been reached
405 avg = rte_red_get_avg_int(red_cfg, red);
415 * setup default values for the functional test structures
417 static struct rte_red_config ft_wrconfig[1];
418 static struct rte_red ft_rtdata[1];
419 static uint8_t ft_wq_log2[] = {9};
420 static uint8_t ft_maxp_inv[] = {10};
421 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
422 static uint32_t ft_q[] ={0};
423 static uint32_t ft_dropped[] ={0};
424 static uint32_t ft_enqueued[] ={0};
426 static struct test_rte_red_config ft_tconfig = {
427 .rconfig = ft_wrconfig,
428 .num_cfg = RTE_DIM(ft_wrconfig),
429 .wq_log2 = ft_wq_log2,
432 .maxp_inv = ft_maxp_inv,
435 static struct test_queue ft_tqueue = {
437 .num_queues = RTE_DIM(ft_rtdata),
438 .qconfig = ft_qconfig,
440 .q_ramp_up = 1000000,
441 .avg_ramp_up = 1000000,
442 .avg_tolerance = 5, /* 5 percent */
443 .drop_tolerance = 50, /* 50 percent */
446 static struct test_var ft_tvar = {
448 .num_iterations = 20,
451 .dropped = ft_dropped,
452 .enqueued = ft_enqueued,
453 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
457 * functional test enqueue/dequeue packets
459 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
468 for (i = 0; i < num_ops; i++) {
474 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
483 * Test F1: functional test 1
485 static uint32_t ft1_tlevels[] = {6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144};
487 static struct test_config func_test1_config = {
488 .ifname = "functional test 1 interface",
489 .msg = "functional test 1 : use one rte_red configuration,\n"
490 " increase average queue size to various levels,\n"
491 " compare drop rate to drop probability\n\n",
501 .tconfig = &ft_tconfig,
502 .tqueue = &ft_tqueue,
504 .tlevel = ft1_tlevels,
507 static enum test_result func_test1(struct test_config *tcfg)
509 enum test_result result = PASS;
512 printf("%s", tcfg->msg);
514 if (test_rte_red_init(tcfg) != PASS) {
519 printf("%s", tcfg->htxt);
521 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
522 const char *label = NULL;
524 double drop_rate = 0.0;
525 double drop_prob = 0.0;
529 * reset rte_red run-time data
531 rte_red_rt_data_init(tcfg->tqueue->rdata);
532 *tcfg->tvar->enqueued = 0;
533 *tcfg->tvar->dropped = 0;
535 if (increase_actual_qsize(tcfg->tconfig->rconfig,
539 tcfg->tqueue->q_ramp_up) != 0) {
544 if (increase_average_qsize(tcfg->tconfig->rconfig,
548 tcfg->tqueue->avg_ramp_up) != 0) {
553 enqueue_dequeue_func(tcfg->tconfig->rconfig,
557 tcfg->tvar->enqueued,
558 tcfg->tvar->dropped);
560 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
561 if (avg != tcfg->tlevel[i]) {
562 fprintf(stderr, "Fail: avg != level\n");
566 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
567 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
568 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
569 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
572 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
573 label = "min thresh: ";
574 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
575 label = "max thresh: ";
578 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
579 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
580 drop_prob * 100.0, drop_rate * 100.0, diff,
581 (double)tcfg->tqueue->drop_tolerance);
588 * Test F2: functional test 2
590 static uint32_t ft2_tlevel[] = {127};
591 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
592 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
593 static struct rte_red_config ft2_rconfig[10];
595 static struct test_rte_red_config ft2_tconfig = {
596 .rconfig = ft2_rconfig,
597 .num_cfg = RTE_DIM(ft2_rconfig),
598 .wq_log2 = ft2_wq_log2,
601 .maxp_inv = ft2_maxp_inv,
604 static struct test_config func_test2_config = {
605 .ifname = "functional test 2 interface",
606 .msg = "functional test 2 : use several RED configurations,\n"
607 " increase average queue size to just below maximum threshold,\n"
608 " compare drop rate to drop probability\n\n",
609 .htxt = "RED config "
618 .tconfig = &ft2_tconfig,
619 .tqueue = &ft_tqueue,
621 .tlevel = ft2_tlevel,
624 static enum test_result func_test2(struct test_config *tcfg)
626 enum test_result result = PASS;
627 double prev_drop_rate = 1.0;
630 printf("%s", tcfg->msg);
632 if (test_rte_red_init(tcfg) != PASS) {
636 rte_red_rt_data_init(tcfg->tqueue->rdata);
638 if (increase_actual_qsize(tcfg->tconfig->rconfig,
642 tcfg->tqueue->q_ramp_up) != 0) {
647 if (increase_average_qsize(tcfg->tconfig->rconfig,
651 tcfg->tqueue->avg_ramp_up) != 0) {
655 printf("%s", tcfg->htxt);
657 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
659 double drop_rate = 0.0;
660 double drop_prob = 0.0;
663 *tcfg->tvar->dropped = 0;
664 *tcfg->tvar->enqueued = 0;
666 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
670 tcfg->tvar->enqueued,
671 tcfg->tvar->dropped);
673 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
674 if (avg != *tcfg->tlevel)
677 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
678 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
679 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
680 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
683 * drop rate should decrease as maxp_inv increases
685 if (drop_rate > prev_drop_rate)
687 prev_drop_rate = drop_rate;
689 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
690 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
691 drop_prob * 100.0, drop_rate * 100.0, diff,
692 (double)tcfg->tqueue->drop_tolerance);
699 * Test F3: functional test 3
701 static uint32_t ft3_tlevel[] = {1022};
703 static struct test_rte_red_config ft3_tconfig = {
704 .rconfig = ft_wrconfig,
705 .num_cfg = RTE_DIM(ft_wrconfig),
706 .wq_log2 = ft_wq_log2,
709 .maxp_inv = ft_maxp_inv,
712 static struct test_config func_test3_config = {
713 .ifname = "functional test 3 interface",
714 .msg = "functional test 3 : use one RED configuration,\n"
715 " increase average queue size to target level,\n"
716 " dequeue all packets until queue is empty,\n"
717 " confirm that average queue size is computed correctly while queue is empty\n\n",
718 .htxt = "q avg before "
725 .tconfig = &ft3_tconfig,
726 .tqueue = &ft_tqueue,
728 .tlevel = ft3_tlevel,
731 static enum test_result func_test3(struct test_config *tcfg)
733 enum test_result result = PASS;
736 printf("%s", tcfg->msg);
738 if (test_rte_red_init(tcfg) != PASS) {
743 rte_red_rt_data_init(tcfg->tqueue->rdata);
745 if (increase_actual_qsize(tcfg->tconfig->rconfig,
749 tcfg->tqueue->q_ramp_up) != 0) {
754 if (increase_average_qsize(tcfg->tconfig->rconfig,
758 tcfg->tqueue->avg_ramp_up) != 0) {
763 printf("%s", tcfg->htxt);
765 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
766 double avg_before = 0;
767 double avg_after = 0;
771 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
776 *tcfg->tqueue->q = 0;
777 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
779 rte_delay_us(tcfg->tvar->wait_usec);
782 * enqueue one packet to recalculate average queue size
784 if (rte_red_enqueue(tcfg->tconfig->rconfig,
787 get_port_ts()) == 0) {
788 (*tcfg->tqueue->q)++;
790 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
794 exp_avg = calc_exp_avg_on_empty(avg_before,
795 (1 << *tcfg->tconfig->wq_log2),
796 tcfg->tvar->wait_usec);
797 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
798 tcfg->tqueue->rdata);
799 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
802 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
803 avg_before, avg_after, exp_avg, diff,
804 (double)tcfg->tqueue->avg_tolerance,
805 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
812 * Test F4: functional test 4
814 static uint32_t ft4_tlevel[] = {1022};
815 static uint8_t ft4_wq_log2[] = {11};
817 static struct test_rte_red_config ft4_tconfig = {
818 .rconfig = ft_wrconfig,
819 .num_cfg = RTE_DIM(ft_wrconfig),
822 .wq_log2 = ft4_wq_log2,
823 .maxp_inv = ft_maxp_inv,
826 static struct test_queue ft4_tqueue = {
828 .num_queues = RTE_DIM(ft_rtdata),
829 .qconfig = ft_qconfig,
831 .q_ramp_up = 1000000,
832 .avg_ramp_up = 1000000,
833 .avg_tolerance = 0, /* 0 percent */
834 .drop_tolerance = 50, /* 50 percent */
837 static struct test_config func_test4_config = {
838 .ifname = "functional test 4 interface",
839 .msg = "functional test 4 : use one RED configuration,\n"
840 " increase average queue size to target level,\n"
841 " dequeue all packets until queue is empty,\n"
842 " confirm that average queue size is computed correctly while\n"
843 " queue is empty for more than 50 sec,\n"
844 " (this test takes 52 sec to run)\n\n",
845 .htxt = "q avg before "
852 .tconfig = &ft4_tconfig,
853 .tqueue = &ft4_tqueue,
855 .tlevel = ft4_tlevel,
858 static enum test_result func_test4(struct test_config *tcfg)
860 enum test_result result = PASS;
861 uint64_t time_diff = 0;
863 double avg_before = 0.0;
864 double avg_after = 0.0;
865 double exp_avg = 0.0;
868 printf("%s", tcfg->msg);
870 if (test_rte_red_init(tcfg) != PASS) {
875 rte_red_rt_data_init(tcfg->tqueue->rdata);
877 if (increase_actual_qsize(tcfg->tconfig->rconfig,
881 tcfg->tqueue->q_ramp_up) != 0) {
886 if (increase_average_qsize(tcfg->tconfig->rconfig,
890 tcfg->tqueue->avg_ramp_up) != 0) {
895 printf("%s", tcfg->htxt);
897 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
902 *tcfg->tqueue->q = 0;
903 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
906 * record empty time locally
910 sleep(tcfg->tvar->sleep_sec);
913 * enqueue one packet to recalculate average queue size
915 if (rte_red_enqueue(tcfg->tconfig->rconfig,
918 get_port_ts()) != 0) {
922 (*tcfg->tqueue->q)++;
925 * calculate how long queue has been empty
927 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
929 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
931 * this could happen if sleep was interrupted for some reason
938 * confirm that average queue size is now at expected level
941 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
942 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
945 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
946 avg_before, avg_after, exp_avg,
947 diff, (double)tcfg->tqueue->avg_tolerance,
948 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
954 * Test F5: functional test 5
956 static uint32_t ft5_tlevel[] = {127};
957 static uint8_t ft5_wq_log2[] = {9, 8};
958 static uint8_t ft5_maxp_inv[] = {10, 20};
959 static struct rte_red_config ft5_config[2];
960 static struct rte_red ft5_data[4];
961 static uint32_t ft5_q[4];
962 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
963 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
965 static struct test_rte_red_config ft5_tconfig = {
966 .rconfig = ft5_config,
967 .num_cfg = RTE_DIM(ft5_config),
970 .wq_log2 = ft5_wq_log2,
971 .maxp_inv = ft5_maxp_inv,
974 static struct test_queue ft5_tqueue = {
976 .num_queues = RTE_DIM(ft5_data),
977 .qconfig = ft_qconfig,
979 .q_ramp_up = 1000000,
980 .avg_ramp_up = 1000000,
981 .avg_tolerance = 5, /* 10 percent */
982 .drop_tolerance = 50, /* 50 percent */
985 struct test_var ft5_tvar = {
987 .num_iterations = 15,
990 .dropped = ft5_dropped,
991 .enqueued = ft5_enqueued,
995 static struct test_config func_test5_config = {
996 .ifname = "functional test 5 interface",
997 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
998 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
999 " increase average queue size to just below maximum threshold,\n"
1000 " compare drop rate to drop probability,\n"
1001 " (this is a larger scale version of functional test 2)\n\n",
1012 .tconfig = &ft5_tconfig,
1013 .tqueue = &ft5_tqueue,
1015 .tlevel = ft5_tlevel,
1018 static enum test_result func_test5(struct test_config *tcfg)
1020 enum test_result result = PASS;
1023 printf("%s", tcfg->msg);
1025 if (test_rte_red_init(tcfg) != PASS) {
1030 printf("%s", tcfg->htxt);
1032 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1033 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1034 tcfg->tqueue->q[j] = 0;
1036 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1037 &tcfg->tqueue->rdata[j],
1038 &tcfg->tqueue->q[j],
1040 tcfg->tqueue->q_ramp_up) != 0) {
1045 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1046 &tcfg->tqueue->rdata[j],
1047 &tcfg->tqueue->q[j],
1049 tcfg->tqueue->avg_ramp_up) != 0) {
1055 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1057 double drop_rate = 0.0;
1058 double drop_prob = 0.0;
1061 tcfg->tvar->dropped[j] = 0;
1062 tcfg->tvar->enqueued[j] = 0;
1064 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1065 &tcfg->tqueue->rdata[j],
1066 &tcfg->tqueue->q[j],
1067 tcfg->tvar->num_ops,
1068 &tcfg->tvar->enqueued[j],
1069 &tcfg->tvar->dropped[j]);
1071 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1072 &tcfg->tqueue->rdata[j]);
1073 if (avg != *tcfg->tlevel)
1076 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1077 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1078 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1080 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1083 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1084 j, tcfg->tqueue->qconfig[j], avg,
1085 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1086 drop_prob * 100.0, drop_rate * 100.0,
1087 diff, (double)tcfg->tqueue->drop_tolerance);
1094 * Test F6: functional test 6
1096 static uint32_t ft6_tlevel[] = {1022};
1097 static uint8_t ft6_wq_log2[] = {9, 8};
1098 static uint8_t ft6_maxp_inv[] = {10, 20};
1099 static struct rte_red_config ft6_config[2];
1100 static struct rte_red ft6_data[4];
1101 static uint32_t ft6_q[4];
1103 static struct test_rte_red_config ft6_tconfig = {
1104 .rconfig = ft6_config,
1105 .num_cfg = RTE_DIM(ft6_config),
1108 .wq_log2 = ft6_wq_log2,
1109 .maxp_inv = ft6_maxp_inv,
1112 static struct test_queue ft6_tqueue = {
1114 .num_queues = RTE_DIM(ft6_data),
1115 .qconfig = ft_qconfig,
1117 .q_ramp_up = 1000000,
1118 .avg_ramp_up = 1000000,
1119 .avg_tolerance = 5, /* 10 percent */
1120 .drop_tolerance = 50, /* 50 percent */
1123 static struct test_config func_test6_config = {
1124 .ifname = "functional test 6 interface",
1125 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1126 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1127 " increase average queue size to target level,\n"
1128 " dequeue all packets until queue is empty,\n"
1129 " confirm that average queue size is computed correctly while queue is empty\n"
1130 " (this is a larger scale version of functional test 3)\n\n",
1139 .tconfig = &ft6_tconfig,
1140 .tqueue = &ft6_tqueue,
1142 .tlevel = ft6_tlevel,
1145 static enum test_result func_test6(struct test_config *tcfg)
1147 enum test_result result = PASS;
1150 printf("%s", tcfg->msg);
1151 if (test_rte_red_init(tcfg) != PASS) {
1155 printf("%s", tcfg->htxt);
1157 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1158 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1159 tcfg->tqueue->q[j] = 0;
1161 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1162 &tcfg->tqueue->rdata[j],
1163 &tcfg->tqueue->q[j],
1165 tcfg->tqueue->q_ramp_up) != 0) {
1169 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1170 &tcfg->tqueue->rdata[j],
1171 &tcfg->tqueue->q[j],
1173 tcfg->tqueue->avg_ramp_up) != 0) {
1178 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1179 double avg_before = 0;
1180 double avg_after = 0;
1184 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1185 &tcfg->tqueue->rdata[j]);
1190 tcfg->tqueue->q[j] = 0;
1191 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1192 rte_delay_us(tcfg->tvar->wait_usec);
1195 * enqueue one packet to recalculate average queue size
1197 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1198 &tcfg->tqueue->rdata[j],
1200 get_port_ts()) == 0) {
1201 tcfg->tqueue->q[j]++;
1203 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1207 exp_avg = calc_exp_avg_on_empty(avg_before,
1208 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1209 tcfg->tvar->wait_usec);
1210 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1211 &tcfg->tqueue->rdata[j]);
1212 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1215 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1216 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1217 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1218 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1225 * setup default values for the performance test structures
1227 static struct rte_red_config pt_wrconfig[1];
1228 static struct rte_red pt_rtdata[1];
1229 static uint8_t pt_wq_log2[] = {9};
1230 static uint8_t pt_maxp_inv[] = {10};
1231 static uint32_t pt_qconfig[] = {0};
1232 static uint32_t pt_q[] = {0};
1233 static uint32_t pt_dropped[] = {0};
1234 static uint32_t pt_enqueued[] = {0};
1236 static struct test_rte_red_config pt_tconfig = {
1237 .rconfig = pt_wrconfig,
1238 .num_cfg = RTE_DIM(pt_wrconfig),
1239 .wq_log2 = pt_wq_log2,
1242 .maxp_inv = pt_maxp_inv,
1245 static struct test_queue pt_tqueue = {
1247 .num_queues = RTE_DIM(pt_rtdata),
1248 .qconfig = pt_qconfig,
1250 .q_ramp_up = 1000000,
1251 .avg_ramp_up = 1000000,
1252 .avg_tolerance = 5, /* 10 percent */
1253 .drop_tolerance = 50, /* 50 percent */
1257 * enqueue/dequeue packets
1259 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1260 struct rte_red *red,
1265 struct rdtsc_prof *prof)
1269 for (i = 0; i < num_ops; i++) {
1276 rdtsc_prof_start(prof);
1277 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1278 rdtsc_prof_end(prof);
1287 * Setup test structures for tests P1, P2, P3
1288 * performance tests 1, 2 and 3
1290 static uint32_t pt1_tlevel[] = {16};
1291 static uint32_t pt2_tlevel[] = {80};
1292 static uint32_t pt3_tlevel[] = {144};
1294 static struct test_var perf1_tvar = {
1296 .num_iterations = 15,
1297 .num_ops = 50000000,
1299 .dropped = pt_dropped,
1300 .enqueued = pt_enqueued,
1304 static struct test_config perf1_test1_config = {
1305 .ifname = "performance test 1 interface",
1306 .msg = "performance test 1 : use one RED configuration,\n"
1307 " set actual and average queue sizes to level below min threshold,\n"
1308 " measure enqueue performance\n\n",
1309 .tconfig = &pt_tconfig,
1310 .tqueue = &pt_tqueue,
1311 .tvar = &perf1_tvar,
1312 .tlevel = pt1_tlevel,
1315 static struct test_config perf1_test2_config = {
1316 .ifname = "performance test 2 interface",
1317 .msg = "performance test 2 : use one RED configuration,\n"
1318 " set actual and average queue sizes to level in between min and max thresholds,\n"
1319 " measure enqueue performance\n\n",
1320 .tconfig = &pt_tconfig,
1321 .tqueue = &pt_tqueue,
1322 .tvar = &perf1_tvar,
1323 .tlevel = pt2_tlevel,
1326 static struct test_config perf1_test3_config = {
1327 .ifname = "performance test 3 interface",
1328 .msg = "performance test 3 : use one RED configuration,\n"
1329 " set actual and average queue sizes to level above max threshold,\n"
1330 " measure enqueue performance\n\n",
1331 .tconfig = &pt_tconfig,
1332 .tqueue = &pt_tqueue,
1333 .tvar = &perf1_tvar,
1334 .tlevel = pt3_tlevel,
1338 * Performance test function to measure enqueue performance.
1339 * This runs performance tests 1, 2 and 3
1341 static enum test_result perf1_test(struct test_config *tcfg)
1343 enum test_result result = PASS;
1344 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1347 printf("%s", tcfg->msg);
1349 rdtsc_prof_init(&prof, "enqueue");
1351 if (test_rte_red_init(tcfg) != PASS) {
1357 * set average queue size to target level
1359 *tcfg->tqueue->q = *tcfg->tlevel;
1362 * initialize the rte_red run time data structure
1364 rte_red_rt_data_init(tcfg->tqueue->rdata);
1367 * set the queue average
1369 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1370 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1376 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1377 tcfg->tqueue->rdata,
1379 tcfg->tvar->num_ops,
1380 tcfg->tvar->enqueued,
1381 tcfg->tvar->dropped,
1384 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1386 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1387 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1388 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1390 rdtsc_prof_print(&prof);
1396 * Setup test structures for tests P4, P5, P6
1397 * performance tests 4, 5 and 6
1399 static uint32_t pt4_tlevel[] = {16};
1400 static uint32_t pt5_tlevel[] = {80};
1401 static uint32_t pt6_tlevel[] = {144};
1403 static struct test_var perf2_tvar = {
1405 .num_iterations = 10000,
1407 .dropped = pt_dropped,
1408 .enqueued = pt_enqueued,
1412 static struct test_config perf2_test4_config = {
1413 .ifname = "performance test 4 interface",
1414 .msg = "performance test 4 : use one RED configuration,\n"
1415 " set actual and average queue sizes to level below min threshold,\n"
1416 " dequeue all packets until queue is empty,\n"
1417 " measure enqueue performance when queue is empty\n\n",
1418 .htxt = "iteration "
1425 .tconfig = &pt_tconfig,
1426 .tqueue = &pt_tqueue,
1427 .tvar = &perf2_tvar,
1428 .tlevel = pt4_tlevel,
1431 static struct test_config perf2_test5_config = {
1432 .ifname = "performance test 5 interface",
1433 .msg = "performance test 5 : use one RED configuration,\n"
1434 " set actual and average queue sizes to level in between min and max thresholds,\n"
1435 " dequeue all packets until queue is empty,\n"
1436 " measure enqueue performance when queue is empty\n\n",
1437 .htxt = "iteration "
1444 .tconfig = &pt_tconfig,
1445 .tqueue = &pt_tqueue,
1446 .tvar = &perf2_tvar,
1447 .tlevel = pt5_tlevel,
1450 static struct test_config perf2_test6_config = {
1451 .ifname = "performance test 6 interface",
1452 .msg = "performance test 6 : use one RED configuration,\n"
1453 " set actual and average queue sizes to level above max threshold,\n"
1454 " dequeue all packets until queue is empty,\n"
1455 " measure enqueue performance when queue is empty\n\n",
1456 .htxt = "iteration "
1463 .tconfig = &pt_tconfig,
1464 .tqueue = &pt_tqueue,
1465 .tvar = &perf2_tvar,
1466 .tlevel = pt6_tlevel,
1470 * Performance test function to measure enqueue performance when the
1471 * queue is empty. This runs performance tests 4, 5 and 6
1473 static enum test_result perf2_test(struct test_config *tcfg)
1475 enum test_result result = PASS;
1476 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1480 printf("%s", tcfg->msg);
1482 rdtsc_prof_init(&prof, "enqueue");
1484 if (test_rte_red_init(tcfg) != PASS) {
1489 printf("%s", tcfg->htxt);
1491 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1494 double avg_before = 0;
1498 * set average queue size to target level
1500 *tcfg->tqueue->q = *tcfg->tlevel;
1501 count = (*tcfg->tqueue->rdata).count;
1504 * initialize the rte_red run time data structure
1506 rte_red_rt_data_init(tcfg->tqueue->rdata);
1507 (*tcfg->tqueue->rdata).count = count;
1510 * set the queue average
1512 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1513 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1514 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1522 *tcfg->tqueue->q = 0;
1523 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1526 * wait for specified period of time
1528 rte_delay_us(tcfg->tvar->wait_usec);
1531 * measure performance of enqueue operation while queue is empty
1534 rdtsc_prof_start(&prof);
1535 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1536 *tcfg->tqueue->q, ts );
1537 rdtsc_prof_end(&prof);
1540 * gather enqueued/dropped statistics
1543 (*tcfg->tvar->enqueued)++;
1545 (*tcfg->tvar->dropped)++;
1548 * on first and last iteration, confirm that
1549 * average queue size was computed correctly
1551 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1552 double avg_after = 0;
1557 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1558 exp_avg = calc_exp_avg_on_empty(avg_before,
1559 (1 << *tcfg->tconfig->wq_log2),
1560 tcfg->tvar->wait_usec);
1561 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1563 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1564 i, avg_before, avg_after, exp_avg, diff,
1565 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1572 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1573 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1574 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1575 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1577 rdtsc_prof_print(&prof);
1583 * setup default values for overflow test structures
1585 static uint32_t avg_max = 0;
1586 static uint32_t avg_max_bits = 0;
1588 static struct rte_red_config ovfl_wrconfig[1];
1589 static struct rte_red ovfl_rtdata[1];
1590 static uint8_t ovfl_maxp_inv[] = {10};
1591 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1592 static uint32_t ovfl_q[] ={0};
1593 static uint32_t ovfl_dropped[] ={0};
1594 static uint32_t ovfl_enqueued[] ={0};
1595 static uint32_t ovfl_tlevel[] = {1023};
1596 static uint8_t ovfl_wq_log2[] = {12};
1598 static struct test_rte_red_config ovfl_tconfig = {
1599 .rconfig = ovfl_wrconfig,
1600 .num_cfg = RTE_DIM(ovfl_wrconfig),
1601 .wq_log2 = ovfl_wq_log2,
1604 .maxp_inv = ovfl_maxp_inv,
1607 static struct test_queue ovfl_tqueue = {
1608 .rdata = ovfl_rtdata,
1609 .num_queues = RTE_DIM(ovfl_rtdata),
1610 .qconfig = ovfl_qconfig,
1612 .q_ramp_up = 1000000,
1613 .avg_ramp_up = 1000000,
1614 .avg_tolerance = 5, /* 10 percent */
1615 .drop_tolerance = 50, /* 50 percent */
1618 static struct test_var ovfl_tvar = {
1620 .num_iterations = 1,
1623 .dropped = ovfl_dropped,
1624 .enqueued = ovfl_enqueued,
1628 static void ovfl_check_avg(uint32_t avg)
1630 if (avg > avg_max) {
1634 avg_log = log(((double)avg_max));
1635 avg_log = avg_log / log(2.0);
1636 bits = (uint32_t)ceil(avg_log);
1637 if (bits > avg_max_bits)
1638 avg_max_bits = bits;
1642 static struct test_config ovfl_test1_config = {
1643 .ifname = "queue avergage overflow test interface",
1644 .msg = "overflow test 1 : use one RED configuration,\n"
1645 " increase average queue size to target level,\n"
1646 " check maximum number of bits requirte_red to represent avg_s\n\n",
1647 .htxt = "avg queue size "
1657 .tconfig = &ovfl_tconfig,
1658 .tqueue = &ovfl_tqueue,
1660 .tlevel = ovfl_tlevel,
1663 static enum test_result ovfl_test1(struct test_config *tcfg)
1665 enum test_result result = PASS;
1668 double drop_rate = 0.0;
1669 double drop_prob = 0.0;
1673 printf("%s", tcfg->msg);
1675 if (test_rte_red_init(tcfg) != PASS) {
1682 * reset rte_red run-time data
1684 rte_red_rt_data_init(tcfg->tqueue->rdata);
1687 * increase actual queue size
1689 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1690 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1691 *tcfg->tqueue->q, get_port_ts());
1694 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1702 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1703 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1704 *tcfg->tqueue->q, get_port_ts());
1705 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1706 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1707 if (avg == *tcfg->tlevel) {
1709 (*tcfg->tvar->enqueued)++;
1711 (*tcfg->tvar->dropped)++;
1716 * check if target average queue size has been reached
1718 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1719 if (avg != *tcfg->tlevel) {
1725 * check drop rate against drop probability
1727 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1728 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1729 tcfg->tconfig->max_th,
1730 *tcfg->tconfig->maxp_inv,
1732 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1735 printf("%s", tcfg->htxt);
1737 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1738 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1739 avg_max, avg_max_bits,
1740 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1741 drop_prob * 100.0, drop_rate * 100.0);
1747 * define the functional and performance tests to be executed
1749 struct tests func_tests[] = {
1750 { &func_test1_config, func_test1 },
1751 { &func_test2_config, func_test2 },
1752 { &func_test3_config, func_test3 },
1753 { &func_test4_config, func_test4 },
1754 { &func_test5_config, func_test5 },
1755 { &func_test6_config, func_test6 },
1756 { &ovfl_test1_config, ovfl_test1 },
1759 struct tests perf_tests[] = {
1760 { &perf1_test1_config, perf1_test },
1761 { &perf1_test2_config, perf1_test },
1762 { &perf1_test3_config, perf1_test },
1763 { &perf2_test4_config, perf2_test },
1764 { &perf2_test5_config, perf2_test },
1765 { &perf2_test6_config, perf2_test },
1769 * function to execute the required_red tests
1771 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1773 enum test_result result = PASS;
1776 for (i = 0; i < test_count; i++) {
1777 printf("\n--------------------------------------------------------------------------------\n");
1778 result = test_type[i].testfn(test_type[i].testcfg);
1780 if (result == PASS) {
1782 printf("-------------------------------------<pass>-------------------------------------\n");
1784 printf("-------------------------------------<fail>-------------------------------------\n");
1791 * check if functions accept invalid parameters
1793 * First, all functions will be called without initialized RED
1794 * Then, all of them will be called with NULL/invalid parameters
1796 * Some functions are not tested as they are performance-critical and thus
1797 * don't do any parameter checking.
1800 test_invalid_parameters(void)
1802 struct rte_red_config config;
1804 if (rte_red_rt_data_init(NULL) == 0) {
1805 printf("rte_red_rt_data_init should have failed!\n");
1809 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1810 printf("rte_red_config_init should have failed!\n");
1814 if (rte_red_rt_data_init(NULL) == 0) {
1815 printf("rte_red_rt_data_init should have failed!\n");
1820 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1821 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1824 /* min_treshold == max_treshold */
1825 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1826 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1829 /* min_treshold > max_treshold */
1830 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1831 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1834 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1835 if (rte_red_config_init(&config,
1836 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1837 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1840 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1841 if (rte_red_config_init(&config,
1842 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1843 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1846 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1847 if (rte_red_config_init(&config,
1848 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1849 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1852 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1853 if (rte_red_config_init(&config,
1854 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1855 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1865 uint32_t num_tests = 0;
1866 uint32_t num_pass = 0;
1869 if (test_invalid_parameters() < 0)
1872 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1873 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1875 if (num_pass == num_tests) {
1876 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1879 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1885 static struct test_command red_cmd = {
1886 .command = "red_autotest",
1887 .callback = test_red,
1889 REGISTER_TEST_COMMAND(red_cmd);