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.
46 #ifdef RTE_LIBRTE_SCHED
50 #ifdef __INTEL_COMPILER
51 #pragma warning(disable:2259) /* conversion may lose significant bits */
52 #pragma warning(disable:181) /* Arg incompatible with format string */
55 #define TEST_HZ_PER_KHZ 1000
56 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
58 #define MAX_QEMPTY_TIME_MSEC 50000
59 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
60 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
61 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
63 /**< structures for testing rte_red performance and function */
64 struct test_rte_red_config { /**< Test structure for RTE_RED config */
65 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
66 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
67 uint8_t *wq_log2; /**< Test wq_log2 value to use */
68 uint32_t min_th; /**< Queue minimum threshold */
69 uint32_t max_th; /**< Queue maximum threshold */
70 uint8_t *maxp_inv; /**< Inverse mark probability */
73 struct test_queue { /**< Test structure for RTE_RED Queues */
74 struct rte_red *rdata; /**< RTE_RED runtime data */
75 uint32_t num_queues; /**< Number of RTE_RED queues to test */
76 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
77 uint32_t *q; /**< Queue size */
78 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
79 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
80 uint32_t avg_tolerance; /**< Tolerance in queue average */
81 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
84 struct test_var { /**< Test variables used for testing RTE_RED */
85 uint32_t wait_usec; /**< Micro second wait interval */
86 uint32_t num_iterations; /**< Number of test iterations */
87 uint32_t num_ops; /**< Number of test operations */
88 uint64_t clk_freq; /**< CPU clock frequency */
89 uint32_t sleep_sec; /**< Seconds to sleep */
90 uint32_t *dropped; /**< Test operations dropped */
91 uint32_t *enqueued; /**< Test operations enqueued */
94 struct test_config { /**< Master test structure for RTE_RED */
95 const char *ifname; /**< Interface name */
96 const char *msg; /**< Test message for display */
97 const char *htxt; /**< Header txt display for result output */
98 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
99 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
100 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
101 uint32_t *tlevel; /**< Queue levels */
109 /**< Test structure to define tests to run */
111 struct test_config *testcfg;
112 enum test_result (*testfn)(struct test_config *);
117 uint64_t clk_min; /**< min clocks */
118 uint64_t clk_max; /**< max clocks */
119 uint64_t clk_avgc; /**< count to calc average */
120 double clk_avg; /**< cumulative sum to calc average */
124 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
125 static double inv_cycles_per_byte = 0;
126 static double pkt_time_usec = 0;
128 static void init_port_ts(uint64_t cpu_clock)
130 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
131 inv_cycles_per_byte = 1.0 / cycles_per_byte;
132 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
135 static uint64_t get_port_ts(void)
137 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
140 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
142 p->clk_min = (uint64_t)(-1LL);
149 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
155 "xchgl %%ebx, %%edi;\n"
156 : : : "%eax", "%edi", "%ecx", "%edx" );
158 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
160 p->clk_start = rte_rdtsc();
163 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
165 uint64_t clk_start = rte_rdtsc() - p->clk_start;
168 p->clk_avg += (double) clk_start;
170 if (clk_start > p->clk_max)
171 p->clk_max = clk_start;
172 if (clk_start < p->clk_min)
173 p->clk_min = clk_start;
176 static void rdtsc_prof_print(struct rdtsc_prof *p)
179 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
184 (p->clk_avg / ((double) p->clk_avgc)));
188 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
192 * scale by 1/n and convert from fixed-point to integer
194 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
197 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
201 * scale by 1/n and convert from fixed-point to floating-point
203 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
206 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
211 * scale by n and convert from integer to fixed-point
213 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
216 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
218 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
221 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
223 return (double)dropped / ((double)enqueued + (double)dropped);
227 * calculate the drop probability
229 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
230 uint32_t maxp_inv, uint32_t avg)
232 double drop_prob = 0.0;
236 } else if (avg < max_th) {
237 drop_prob = (1.0 / (double)maxp_inv)
238 * ((double)(avg - min_th)
239 / (double)(max_th - min_th));
247 * check if drop rate matches drop probability within tolerance
249 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
251 double abs_diff = 0.0;
254 abs_diff = fabs(drop_rate - drop_prob);
255 if ((int)abs_diff == 0) {
258 *diff = (abs_diff / drop_prob) * 100.0;
259 if (*diff > tolerance) {
267 * check if average queue size is within tolerance
269 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
271 double abs_diff = 0.0;
274 abs_diff = fabs(avg - exp_avg);
275 if ((int)abs_diff == 0) {
278 *diff = (abs_diff / exp_avg) * 100.0;
279 if (*diff > tolerance) {
287 * get the clk frequency in Hz
289 static uint64_t get_machclk_freq(void)
294 uint64_t clk_freq_hz = 0;
295 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
296 struct timespec req = {0, 0};
301 clock_gettime(CLOCK_REALTIME, &tv_start);
304 if (nanosleep(&req, NULL) != 0) {
305 perror("get_machclk_freq()");
309 clock_gettime(CLOCK_REALTIME, &tv_end);
312 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
313 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
314 USEC_PER_MSEC); /**< diff is in micro secs */
319 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
320 return (clk_freq_hz);
324 * initialize the test rte_red config
326 static enum test_result
327 test_rte_red_init(struct test_config *tcfg)
331 tcfg->tvar->clk_freq = get_machclk_freq();
332 init_port_ts( tcfg->tvar->clk_freq );
334 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
335 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
336 (uint16_t)tcfg->tconfig->wq_log2[i],
337 (uint16_t)tcfg->tconfig->min_th,
338 (uint16_t)tcfg->tconfig->max_th,
339 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
344 *tcfg->tqueue->q = 0;
345 *tcfg->tvar->dropped = 0;
346 *tcfg->tvar->enqueued = 0;
351 * enqueue until actual queue size reaches target level
354 increase_actual_qsize(struct rte_red_config *red_cfg,
362 for (i = 0; i < attempts; i++) {
368 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
375 * check if target actual queue size has been reached
386 * enqueue until average queue size reaches target level
389 increase_average_qsize(struct rte_red_config *red_cfg,
398 for (i = 0; i < num_ops; i++) {
402 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
405 * check if target average queue size has been reached
407 avg = rte_red_get_avg_int(red_cfg, red);
417 * setup default values for the functional test structures
419 static struct rte_red_config ft_wrconfig[1];
420 static struct rte_red ft_rtdata[1];
421 static uint8_t ft_wq_log2[] = {9};
422 static uint8_t ft_maxp_inv[] = {10};
423 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
424 static uint32_t ft_q[] ={0};
425 static uint32_t ft_dropped[] ={0};
426 static uint32_t ft_enqueued[] ={0};
428 static struct test_rte_red_config ft_tconfig = {
429 .rconfig = ft_wrconfig,
430 .num_cfg = RTE_DIM(ft_wrconfig),
431 .wq_log2 = ft_wq_log2,
434 .maxp_inv = ft_maxp_inv,
437 static struct test_queue ft_tqueue = {
439 .num_queues = RTE_DIM(ft_rtdata),
440 .qconfig = ft_qconfig,
442 .q_ramp_up = 1000000,
443 .avg_ramp_up = 1000000,
444 .avg_tolerance = 5, /* 5 percent */
445 .drop_tolerance = 50, /* 50 percent */
448 static struct test_var ft_tvar = {
450 .num_iterations = 20,
453 .dropped = ft_dropped,
454 .enqueued = ft_enqueued,
455 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
459 * functional test enqueue/dequeue packets
461 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
470 for (i = 0; i < num_ops; i++) {
476 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
485 * Test F1: functional test 1
487 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};
489 static struct test_config func_test1_config = {
490 .ifname = "functional test 1 interface",
491 .msg = "functional test 1 : use one rte_red configuration,\n"
492 " increase average queue size to various levels,\n"
493 " compare drop rate to drop probability\n\n",
503 .tconfig = &ft_tconfig,
504 .tqueue = &ft_tqueue,
506 .tlevel = ft1_tlevels,
509 static enum test_result func_test1(struct test_config *tcfg)
511 enum test_result result = PASS;
514 printf("%s", tcfg->msg);
516 if (test_rte_red_init(tcfg) != PASS) {
521 printf("%s", tcfg->htxt);
523 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
524 const char *label = NULL;
526 double drop_rate = 0.0;
527 double drop_prob = 0.0;
531 * reset rte_red run-time data
533 rte_red_rt_data_init(tcfg->tqueue->rdata);
534 *tcfg->tvar->enqueued = 0;
535 *tcfg->tvar->dropped = 0;
537 if (increase_actual_qsize(tcfg->tconfig->rconfig,
541 tcfg->tqueue->q_ramp_up) != 0) {
546 if (increase_average_qsize(tcfg->tconfig->rconfig,
550 tcfg->tqueue->avg_ramp_up) != 0) {
555 enqueue_dequeue_func(tcfg->tconfig->rconfig,
559 tcfg->tvar->enqueued,
560 tcfg->tvar->dropped);
562 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
563 if (avg != tcfg->tlevel[i]) {
564 fprintf(stderr, "Fail: avg != level\n");
568 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
569 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
570 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
571 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
574 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
575 label = "min thresh: ";
576 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
577 label = "max thresh: ";
580 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
581 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
582 drop_prob * 100.0, drop_rate * 100.0, diff,
583 (double)tcfg->tqueue->drop_tolerance);
590 * Test F2: functional test 2
592 static uint32_t ft2_tlevel[] = {127};
593 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
594 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
595 static struct rte_red_config ft2_rconfig[10];
597 static struct test_rte_red_config ft2_tconfig = {
598 .rconfig = ft2_rconfig,
599 .num_cfg = RTE_DIM(ft2_rconfig),
600 .wq_log2 = ft2_wq_log2,
603 .maxp_inv = ft2_maxp_inv,
606 static struct test_config func_test2_config = {
607 .ifname = "functional test 2 interface",
608 .msg = "functional test 2 : use several RED configurations,\n"
609 " increase average queue size to just below maximum threshold,\n"
610 " compare drop rate to drop probability\n\n",
611 .htxt = "RED config "
620 .tconfig = &ft2_tconfig,
621 .tqueue = &ft_tqueue,
623 .tlevel = ft2_tlevel,
626 static enum test_result func_test2(struct test_config *tcfg)
628 enum test_result result = PASS;
629 double prev_drop_rate = 1.0;
632 printf("%s", tcfg->msg);
634 if (test_rte_red_init(tcfg) != PASS) {
638 rte_red_rt_data_init(tcfg->tqueue->rdata);
640 if (increase_actual_qsize(tcfg->tconfig->rconfig,
644 tcfg->tqueue->q_ramp_up) != 0) {
649 if (increase_average_qsize(tcfg->tconfig->rconfig,
653 tcfg->tqueue->avg_ramp_up) != 0) {
657 printf("%s", tcfg->htxt);
659 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
661 double drop_rate = 0.0;
662 double drop_prob = 0.0;
665 *tcfg->tvar->dropped = 0;
666 *tcfg->tvar->enqueued = 0;
668 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
672 tcfg->tvar->enqueued,
673 tcfg->tvar->dropped);
675 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
676 if (avg != *tcfg->tlevel)
679 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
680 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
681 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
682 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
685 * drop rate should decrease as maxp_inv increases
687 if (drop_rate > prev_drop_rate)
689 prev_drop_rate = drop_rate;
691 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
692 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
693 drop_prob * 100.0, drop_rate * 100.0, diff,
694 (double)tcfg->tqueue->drop_tolerance);
701 * Test F3: functional test 3
703 static uint32_t ft3_tlevel[] = {1022};
705 static struct test_rte_red_config ft3_tconfig = {
706 .rconfig = ft_wrconfig,
707 .num_cfg = RTE_DIM(ft_wrconfig),
708 .wq_log2 = ft_wq_log2,
711 .maxp_inv = ft_maxp_inv,
714 static struct test_config func_test3_config = {
715 .ifname = "functional test 3 interface",
716 .msg = "functional test 3 : use one RED configuration,\n"
717 " increase average queue size to target level,\n"
718 " dequeue all packets until queue is empty,\n"
719 " confirm that average queue size is computed correctly while queue is empty\n\n",
720 .htxt = "q avg before "
727 .tconfig = &ft3_tconfig,
728 .tqueue = &ft_tqueue,
730 .tlevel = ft3_tlevel,
733 static enum test_result func_test3(struct test_config *tcfg)
735 enum test_result result = PASS;
738 printf("%s", tcfg->msg);
740 if (test_rte_red_init(tcfg) != PASS) {
745 rte_red_rt_data_init(tcfg->tqueue->rdata);
747 if (increase_actual_qsize(tcfg->tconfig->rconfig,
751 tcfg->tqueue->q_ramp_up) != 0) {
756 if (increase_average_qsize(tcfg->tconfig->rconfig,
760 tcfg->tqueue->avg_ramp_up) != 0) {
765 printf("%s", tcfg->htxt);
767 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
768 double avg_before = 0;
769 double avg_after = 0;
773 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
778 *tcfg->tqueue->q = 0;
779 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
781 rte_delay_us(tcfg->tvar->wait_usec);
784 * enqueue one packet to recalculate average queue size
786 if (rte_red_enqueue(tcfg->tconfig->rconfig,
789 get_port_ts()) == 0) {
790 (*tcfg->tqueue->q)++;
792 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
796 exp_avg = calc_exp_avg_on_empty(avg_before,
797 (1 << *tcfg->tconfig->wq_log2),
798 tcfg->tvar->wait_usec);
799 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
800 tcfg->tqueue->rdata);
801 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
804 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
805 avg_before, avg_after, exp_avg, diff,
806 (double)tcfg->tqueue->avg_tolerance,
807 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
814 * Test F4: functional test 4
816 static uint32_t ft4_tlevel[] = {1022};
817 static uint8_t ft4_wq_log2[] = {11};
819 static struct test_rte_red_config ft4_tconfig = {
820 .rconfig = ft_wrconfig,
821 .num_cfg = RTE_DIM(ft_wrconfig),
824 .wq_log2 = ft4_wq_log2,
825 .maxp_inv = ft_maxp_inv,
828 static struct test_queue ft4_tqueue = {
830 .num_queues = RTE_DIM(ft_rtdata),
831 .qconfig = ft_qconfig,
833 .q_ramp_up = 1000000,
834 .avg_ramp_up = 1000000,
835 .avg_tolerance = 0, /* 0 percent */
836 .drop_tolerance = 50, /* 50 percent */
839 static struct test_config func_test4_config = {
840 .ifname = "functional test 4 interface",
841 .msg = "functional test 4 : use one RED configuration,\n"
842 " increase average queue size to target level,\n"
843 " dequeue all packets until queue is empty,\n"
844 " confirm that average queue size is computed correctly while\n"
845 " queue is empty for more than 50 sec,\n"
846 " (this test takes 52 sec to run)\n\n",
847 .htxt = "q avg before "
854 .tconfig = &ft4_tconfig,
855 .tqueue = &ft4_tqueue,
857 .tlevel = ft4_tlevel,
860 static enum test_result func_test4(struct test_config *tcfg)
862 enum test_result result = PASS;
863 uint64_t time_diff = 0;
865 double avg_before = 0.0;
866 double avg_after = 0.0;
867 double exp_avg = 0.0;
870 printf("%s", tcfg->msg);
872 if (test_rte_red_init(tcfg) != PASS) {
877 rte_red_rt_data_init(tcfg->tqueue->rdata);
879 if (increase_actual_qsize(tcfg->tconfig->rconfig,
883 tcfg->tqueue->q_ramp_up) != 0) {
888 if (increase_average_qsize(tcfg->tconfig->rconfig,
892 tcfg->tqueue->avg_ramp_up) != 0) {
897 printf("%s", tcfg->htxt);
899 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
904 *tcfg->tqueue->q = 0;
905 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
908 * record empty time locally
912 sleep(tcfg->tvar->sleep_sec);
915 * enqueue one packet to recalculate average queue size
917 if (rte_red_enqueue(tcfg->tconfig->rconfig,
920 get_port_ts()) != 0) {
924 (*tcfg->tqueue->q)++;
927 * calculate how long queue has been empty
929 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
931 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
933 * this could happen if sleep was interrupted for some reason
940 * confirm that average queue size is now at expected level
943 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
944 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
947 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
948 avg_before, avg_after, exp_avg,
949 diff, (double)tcfg->tqueue->avg_tolerance,
950 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
956 * Test F5: functional test 5
958 static uint32_t ft5_tlevel[] = {127};
959 static uint8_t ft5_wq_log2[] = {9, 8};
960 static uint8_t ft5_maxp_inv[] = {10, 20};
961 static struct rte_red_config ft5_config[2];
962 static struct rte_red ft5_data[4];
963 static uint32_t ft5_q[4];
964 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
965 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
967 static struct test_rte_red_config ft5_tconfig = {
968 .rconfig = ft5_config,
969 .num_cfg = RTE_DIM(ft5_config),
972 .wq_log2 = ft5_wq_log2,
973 .maxp_inv = ft5_maxp_inv,
976 static struct test_queue ft5_tqueue = {
978 .num_queues = RTE_DIM(ft5_data),
979 .qconfig = ft_qconfig,
981 .q_ramp_up = 1000000,
982 .avg_ramp_up = 1000000,
983 .avg_tolerance = 5, /* 10 percent */
984 .drop_tolerance = 50, /* 50 percent */
987 struct test_var ft5_tvar = {
989 .num_iterations = 15,
992 .dropped = ft5_dropped,
993 .enqueued = ft5_enqueued,
997 static struct test_config func_test5_config = {
998 .ifname = "functional test 5 interface",
999 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
1000 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
1001 " increase average queue size to just below maximum threshold,\n"
1002 " compare drop rate to drop probability,\n"
1003 " (this is a larger scale version of functional test 2)\n\n",
1014 .tconfig = &ft5_tconfig,
1015 .tqueue = &ft5_tqueue,
1017 .tlevel = ft5_tlevel,
1020 static enum test_result func_test5(struct test_config *tcfg)
1022 enum test_result result = PASS;
1025 printf("%s", tcfg->msg);
1027 if (test_rte_red_init(tcfg) != PASS) {
1032 printf("%s", tcfg->htxt);
1034 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1035 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1036 tcfg->tqueue->q[j] = 0;
1038 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1039 &tcfg->tqueue->rdata[j],
1040 &tcfg->tqueue->q[j],
1042 tcfg->tqueue->q_ramp_up) != 0) {
1047 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1048 &tcfg->tqueue->rdata[j],
1049 &tcfg->tqueue->q[j],
1051 tcfg->tqueue->avg_ramp_up) != 0) {
1057 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1059 double drop_rate = 0.0;
1060 double drop_prob = 0.0;
1063 tcfg->tvar->dropped[j] = 0;
1064 tcfg->tvar->enqueued[j] = 0;
1066 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1067 &tcfg->tqueue->rdata[j],
1068 &tcfg->tqueue->q[j],
1069 tcfg->tvar->num_ops,
1070 &tcfg->tvar->enqueued[j],
1071 &tcfg->tvar->dropped[j]);
1073 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1074 &tcfg->tqueue->rdata[j]);
1075 if (avg != *tcfg->tlevel)
1078 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1079 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1080 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1082 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1085 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1086 j, tcfg->tqueue->qconfig[j], avg,
1087 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1088 drop_prob * 100.0, drop_rate * 100.0,
1089 diff, (double)tcfg->tqueue->drop_tolerance);
1096 * Test F6: functional test 6
1098 static uint32_t ft6_tlevel[] = {1022};
1099 static uint8_t ft6_wq_log2[] = {9, 8};
1100 static uint8_t ft6_maxp_inv[] = {10, 20};
1101 static struct rte_red_config ft6_config[2];
1102 static struct rte_red ft6_data[4];
1103 static uint32_t ft6_q[4];
1105 static struct test_rte_red_config ft6_tconfig = {
1106 .rconfig = ft6_config,
1107 .num_cfg = RTE_DIM(ft6_config),
1110 .wq_log2 = ft6_wq_log2,
1111 .maxp_inv = ft6_maxp_inv,
1114 static struct test_queue ft6_tqueue = {
1116 .num_queues = RTE_DIM(ft6_data),
1117 .qconfig = ft_qconfig,
1119 .q_ramp_up = 1000000,
1120 .avg_ramp_up = 1000000,
1121 .avg_tolerance = 5, /* 10 percent */
1122 .drop_tolerance = 50, /* 50 percent */
1125 static struct test_config func_test6_config = {
1126 .ifname = "functional test 6 interface",
1127 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1128 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1129 " increase average queue size to target level,\n"
1130 " dequeue all packets until queue is empty,\n"
1131 " confirm that average queue size is computed correctly while queue is empty\n"
1132 " (this is a larger scale version of functional test 3)\n\n",
1141 .tconfig = &ft6_tconfig,
1142 .tqueue = &ft6_tqueue,
1144 .tlevel = ft6_tlevel,
1147 static enum test_result func_test6(struct test_config *tcfg)
1149 enum test_result result = PASS;
1152 printf("%s", tcfg->msg);
1153 if (test_rte_red_init(tcfg) != PASS) {
1157 printf("%s", tcfg->htxt);
1159 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1160 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1161 tcfg->tqueue->q[j] = 0;
1163 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1164 &tcfg->tqueue->rdata[j],
1165 &tcfg->tqueue->q[j],
1167 tcfg->tqueue->q_ramp_up) != 0) {
1171 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1172 &tcfg->tqueue->rdata[j],
1173 &tcfg->tqueue->q[j],
1175 tcfg->tqueue->avg_ramp_up) != 0) {
1180 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1181 double avg_before = 0;
1182 double avg_after = 0;
1186 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1187 &tcfg->tqueue->rdata[j]);
1192 tcfg->tqueue->q[j] = 0;
1193 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1194 rte_delay_us(tcfg->tvar->wait_usec);
1197 * enqueue one packet to recalculate average queue size
1199 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1200 &tcfg->tqueue->rdata[j],
1202 get_port_ts()) == 0) {
1203 tcfg->tqueue->q[j]++;
1205 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1209 exp_avg = calc_exp_avg_on_empty(avg_before,
1210 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1211 tcfg->tvar->wait_usec);
1212 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1213 &tcfg->tqueue->rdata[j]);
1214 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1217 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1218 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1219 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1220 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1227 * setup default values for the performance test structures
1229 static struct rte_red_config pt_wrconfig[1];
1230 static struct rte_red pt_rtdata[1];
1231 static uint8_t pt_wq_log2[] = {9};
1232 static uint8_t pt_maxp_inv[] = {10};
1233 static uint32_t pt_qconfig[] = {0};
1234 static uint32_t pt_q[] = {0};
1235 static uint32_t pt_dropped[] = {0};
1236 static uint32_t pt_enqueued[] = {0};
1238 static struct test_rte_red_config pt_tconfig = {
1239 .rconfig = pt_wrconfig,
1240 .num_cfg = RTE_DIM(pt_wrconfig),
1241 .wq_log2 = pt_wq_log2,
1244 .maxp_inv = pt_maxp_inv,
1247 static struct test_queue pt_tqueue = {
1249 .num_queues = RTE_DIM(pt_rtdata),
1250 .qconfig = pt_qconfig,
1252 .q_ramp_up = 1000000,
1253 .avg_ramp_up = 1000000,
1254 .avg_tolerance = 5, /* 10 percent */
1255 .drop_tolerance = 50, /* 50 percent */
1259 * enqueue/dequeue packets
1261 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1262 struct rte_red *red,
1267 struct rdtsc_prof *prof)
1271 for (i = 0; i < num_ops; i++) {
1278 rdtsc_prof_start(prof);
1279 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1280 rdtsc_prof_end(prof);
1289 * Setup test structures for tests P1, P2, P3
1290 * performance tests 1, 2 and 3
1292 static uint32_t pt1_tlevel[] = {16};
1293 static uint32_t pt2_tlevel[] = {80};
1294 static uint32_t pt3_tlevel[] = {144};
1296 static struct test_var perf1_tvar = {
1298 .num_iterations = 15,
1299 .num_ops = 50000000,
1301 .dropped = pt_dropped,
1302 .enqueued = pt_enqueued,
1306 static struct test_config perf1_test1_config = {
1307 .ifname = "performance test 1 interface",
1308 .msg = "performance test 1 : use one RED configuration,\n"
1309 " set actual and average queue sizes to level below min threshold,\n"
1310 " measure enqueue performance\n\n",
1311 .tconfig = &pt_tconfig,
1312 .tqueue = &pt_tqueue,
1313 .tvar = &perf1_tvar,
1314 .tlevel = pt1_tlevel,
1317 static struct test_config perf1_test2_config = {
1318 .ifname = "performance test 2 interface",
1319 .msg = "performance test 2 : use one RED configuration,\n"
1320 " set actual and average queue sizes to level in between min and max thresholds,\n"
1321 " measure enqueue performance\n\n",
1322 .tconfig = &pt_tconfig,
1323 .tqueue = &pt_tqueue,
1324 .tvar = &perf1_tvar,
1325 .tlevel = pt2_tlevel,
1328 static struct test_config perf1_test3_config = {
1329 .ifname = "performance test 3 interface",
1330 .msg = "performance test 3 : use one RED configuration,\n"
1331 " set actual and average queue sizes to level above max threshold,\n"
1332 " measure enqueue performance\n\n",
1333 .tconfig = &pt_tconfig,
1334 .tqueue = &pt_tqueue,
1335 .tvar = &perf1_tvar,
1336 .tlevel = pt3_tlevel,
1340 * Performance test function to measure enqueue performance.
1341 * This runs performance tests 1, 2 and 3
1343 static enum test_result perf1_test(struct test_config *tcfg)
1345 enum test_result result = PASS;
1346 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1349 printf("%s", tcfg->msg);
1351 rdtsc_prof_init(&prof, "enqueue");
1353 if (test_rte_red_init(tcfg) != PASS) {
1359 * set average queue size to target level
1361 *tcfg->tqueue->q = *tcfg->tlevel;
1364 * initialize the rte_red run time data structure
1366 rte_red_rt_data_init(tcfg->tqueue->rdata);
1369 * set the queue average
1371 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1372 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1378 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1379 tcfg->tqueue->rdata,
1381 tcfg->tvar->num_ops,
1382 tcfg->tvar->enqueued,
1383 tcfg->tvar->dropped,
1386 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1388 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1389 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1390 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1392 rdtsc_prof_print(&prof);
1398 * Setup test structures for tests P4, P5, P6
1399 * performance tests 4, 5 and 6
1401 static uint32_t pt4_tlevel[] = {16};
1402 static uint32_t pt5_tlevel[] = {80};
1403 static uint32_t pt6_tlevel[] = {144};
1405 static struct test_var perf2_tvar = {
1407 .num_iterations = 10000,
1409 .dropped = pt_dropped,
1410 .enqueued = pt_enqueued,
1414 static struct test_config perf2_test4_config = {
1415 .ifname = "performance test 4 interface",
1416 .msg = "performance test 4 : use one RED configuration,\n"
1417 " set actual and average queue sizes to level below min threshold,\n"
1418 " dequeue all packets until queue is empty,\n"
1419 " measure enqueue performance when queue is empty\n\n",
1420 .htxt = "iteration "
1427 .tconfig = &pt_tconfig,
1428 .tqueue = &pt_tqueue,
1429 .tvar = &perf2_tvar,
1430 .tlevel = pt4_tlevel,
1433 static struct test_config perf2_test5_config = {
1434 .ifname = "performance test 5 interface",
1435 .msg = "performance test 5 : use one RED configuration,\n"
1436 " set actual and average queue sizes to level in between min and max thresholds,\n"
1437 " dequeue all packets until queue is empty,\n"
1438 " measure enqueue performance when queue is empty\n\n",
1439 .htxt = "iteration "
1446 .tconfig = &pt_tconfig,
1447 .tqueue = &pt_tqueue,
1448 .tvar = &perf2_tvar,
1449 .tlevel = pt5_tlevel,
1452 static struct test_config perf2_test6_config = {
1453 .ifname = "performance test 6 interface",
1454 .msg = "performance test 6 : use one RED configuration,\n"
1455 " set actual and average queue sizes to level above max threshold,\n"
1456 " dequeue all packets until queue is empty,\n"
1457 " measure enqueue performance when queue is empty\n\n",
1458 .htxt = "iteration "
1465 .tconfig = &pt_tconfig,
1466 .tqueue = &pt_tqueue,
1467 .tvar = &perf2_tvar,
1468 .tlevel = pt6_tlevel,
1472 * Performance test function to measure enqueue performance when the
1473 * queue is empty. This runs performance tests 4, 5 and 6
1475 static enum test_result perf2_test(struct test_config *tcfg)
1477 enum test_result result = PASS;
1478 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1482 printf("%s", tcfg->msg);
1484 rdtsc_prof_init(&prof, "enqueue");
1486 if (test_rte_red_init(tcfg) != PASS) {
1491 printf("%s", tcfg->htxt);
1493 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1496 double avg_before = 0;
1500 * set average queue size to target level
1502 *tcfg->tqueue->q = *tcfg->tlevel;
1503 count = (*tcfg->tqueue->rdata).count;
1506 * initialize the rte_red run time data structure
1508 rte_red_rt_data_init(tcfg->tqueue->rdata);
1509 (*tcfg->tqueue->rdata).count = count;
1512 * set the queue average
1514 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1515 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1516 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1524 *tcfg->tqueue->q = 0;
1525 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1528 * wait for specified period of time
1530 rte_delay_us(tcfg->tvar->wait_usec);
1533 * measure performance of enqueue operation while queue is empty
1536 rdtsc_prof_start(&prof);
1537 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1538 *tcfg->tqueue->q, ts );
1539 rdtsc_prof_end(&prof);
1542 * gather enqueued/dropped statistics
1545 (*tcfg->tvar->enqueued)++;
1547 (*tcfg->tvar->dropped)++;
1550 * on first and last iteration, confirm that
1551 * average queue size was computed correctly
1553 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1554 double avg_after = 0;
1559 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1560 exp_avg = calc_exp_avg_on_empty(avg_before,
1561 (1 << *tcfg->tconfig->wq_log2),
1562 tcfg->tvar->wait_usec);
1563 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1565 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1566 i, avg_before, avg_after, exp_avg, diff,
1567 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1574 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1575 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1576 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1577 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1579 rdtsc_prof_print(&prof);
1585 * setup default values for overflow test structures
1587 static uint32_t avg_max = 0;
1588 static uint32_t avg_max_bits = 0;
1590 static struct rte_red_config ovfl_wrconfig[1];
1591 static struct rte_red ovfl_rtdata[1];
1592 static uint8_t ovfl_maxp_inv[] = {10};
1593 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1594 static uint32_t ovfl_q[] ={0};
1595 static uint32_t ovfl_dropped[] ={0};
1596 static uint32_t ovfl_enqueued[] ={0};
1597 static uint32_t ovfl_tlevel[] = {1023};
1598 static uint8_t ovfl_wq_log2[] = {12};
1600 static struct test_rte_red_config ovfl_tconfig = {
1601 .rconfig = ovfl_wrconfig,
1602 .num_cfg = RTE_DIM(ovfl_wrconfig),
1603 .wq_log2 = ovfl_wq_log2,
1606 .maxp_inv = ovfl_maxp_inv,
1609 static struct test_queue ovfl_tqueue = {
1610 .rdata = ovfl_rtdata,
1611 .num_queues = RTE_DIM(ovfl_rtdata),
1612 .qconfig = ovfl_qconfig,
1614 .q_ramp_up = 1000000,
1615 .avg_ramp_up = 1000000,
1616 .avg_tolerance = 5, /* 10 percent */
1617 .drop_tolerance = 50, /* 50 percent */
1620 static struct test_var ovfl_tvar = {
1622 .num_iterations = 1,
1625 .dropped = ovfl_dropped,
1626 .enqueued = ovfl_enqueued,
1630 static void ovfl_check_avg(uint32_t avg)
1632 if (avg > avg_max) {
1636 avg_log = log(((double)avg_max));
1637 avg_log = avg_log / log(2.0);
1638 bits = (uint32_t)ceil(avg_log);
1639 if (bits > avg_max_bits)
1640 avg_max_bits = bits;
1644 static struct test_config ovfl_test1_config = {
1645 .ifname = "queue avergage overflow test interface",
1646 .msg = "overflow test 1 : use one RED configuration,\n"
1647 " increase average queue size to target level,\n"
1648 " check maximum number of bits requirte_red to represent avg_s\n\n",
1649 .htxt = "avg queue size "
1659 .tconfig = &ovfl_tconfig,
1660 .tqueue = &ovfl_tqueue,
1662 .tlevel = ovfl_tlevel,
1665 static enum test_result ovfl_test1(struct test_config *tcfg)
1667 enum test_result result = PASS;
1670 double drop_rate = 0.0;
1671 double drop_prob = 0.0;
1675 printf("%s", tcfg->msg);
1677 if (test_rte_red_init(tcfg) != PASS) {
1684 * reset rte_red run-time data
1686 rte_red_rt_data_init(tcfg->tqueue->rdata);
1689 * increase actual queue size
1691 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1692 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1693 *tcfg->tqueue->q, get_port_ts());
1696 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1704 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1705 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1706 *tcfg->tqueue->q, get_port_ts());
1707 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1708 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1709 if (avg == *tcfg->tlevel) {
1711 (*tcfg->tvar->enqueued)++;
1713 (*tcfg->tvar->dropped)++;
1718 * check if target average queue size has been reached
1720 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1721 if (avg != *tcfg->tlevel) {
1727 * check drop rate against drop probability
1729 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1730 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1731 tcfg->tconfig->max_th,
1732 *tcfg->tconfig->maxp_inv,
1734 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1737 printf("%s", tcfg->htxt);
1739 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1740 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1741 avg_max, avg_max_bits,
1742 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1743 drop_prob * 100.0, drop_rate * 100.0);
1749 * define the functional and performance tests to be executed
1751 struct tests func_tests[] = {
1752 { &func_test1_config, func_test1 },
1753 { &func_test2_config, func_test2 },
1754 { &func_test3_config, func_test3 },
1755 { &func_test4_config, func_test4 },
1756 { &func_test5_config, func_test5 },
1757 { &func_test6_config, func_test6 },
1758 { &ovfl_test1_config, ovfl_test1 },
1761 struct tests perf_tests[] = {
1762 { &perf1_test1_config, perf1_test },
1763 { &perf1_test2_config, perf1_test },
1764 { &perf1_test3_config, perf1_test },
1765 { &perf2_test4_config, perf2_test },
1766 { &perf2_test5_config, perf2_test },
1767 { &perf2_test6_config, perf2_test },
1771 * function to execute the required_red tests
1773 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1775 enum test_result result = PASS;
1778 for (i = 0; i < test_count; i++) {
1779 printf("\n--------------------------------------------------------------------------------\n");
1780 result = test_type[i].testfn(test_type[i].testcfg);
1782 if (result == PASS) {
1784 printf("-------------------------------------<pass>-------------------------------------\n");
1786 printf("-------------------------------------<fail>-------------------------------------\n");
1793 * check if functions accept invalid parameters
1795 * First, all functions will be called without initialized RED
1796 * Then, all of them will be called with NULL/invalid parameters
1798 * Some functions are not tested as they are performance-critical and thus
1799 * don't do any parameter checking.
1802 test_invalid_parameters(void)
1804 struct rte_red_config config;
1806 if (rte_red_rt_data_init(NULL) == 0) {
1807 printf("rte_red_rt_data_init should have failed!\n");
1811 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1812 printf("rte_red_config_init should have failed!\n");
1816 if (rte_red_rt_data_init(NULL) == 0) {
1817 printf("rte_red_rt_data_init should have failed!\n");
1822 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1823 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1826 /* min_treshold == max_treshold */
1827 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1828 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1831 /* min_treshold > max_treshold */
1832 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1833 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1836 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1837 if (rte_red_config_init(&config,
1838 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1839 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1842 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1843 if (rte_red_config_init(&config,
1844 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1845 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1848 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1849 if (rte_red_config_init(&config,
1850 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1851 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1854 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1855 if (rte_red_config_init(&config,
1856 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1857 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1866 uint32_t num_tests = 0;
1867 uint32_t num_pass = 0;
1870 if (test_invalid_parameters() < 0)
1873 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1874 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1876 if (num_pass == num_tests) {
1877 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1880 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1891 printf("The SCHED library is not included in this build\n");