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.
43 #include <cmdline_parse.h>
47 #ifdef RTE_LIBRTE_SCHED
51 #ifdef __INTEL_COMPILER
52 #pragma warning(disable:2259) /* conversion may lose significant bits */
53 #pragma warning(disable:181) /* Arg incompatible with format string */
56 #define TEST_HZ_PER_KHZ 1000
57 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
59 #define MAX_QEMPTY_TIME_MSEC 50000
60 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
61 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
62 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
64 /**< structures for testing rte_red performance and function */
65 struct test_rte_red_config { /**< Test structure for RTE_RED config */
66 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
67 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
68 uint8_t *wq_log2; /**< Test wq_log2 value to use */
69 uint32_t min_th; /**< Queue minimum threshold */
70 uint32_t max_th; /**< Queue maximum threshold */
71 uint8_t *maxp_inv; /**< Inverse mark probability */
74 struct test_queue { /**< Test structure for RTE_RED Queues */
75 struct rte_red *rdata; /**< RTE_RED runtime data */
76 uint32_t num_queues; /**< Number of RTE_RED queues to test */
77 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
78 uint32_t *q; /**< Queue size */
79 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
80 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
81 uint32_t avg_tolerance; /**< Tolerance in queue average */
82 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
85 struct test_var { /**< Test variables used for testing RTE_RED */
86 uint32_t wait_usec; /**< Micro second wait interval */
87 uint32_t num_iterations; /**< Number of test iterations */
88 uint32_t num_ops; /**< Number of test operations */
89 uint64_t clk_freq; /**< CPU clock frequency */
90 uint32_t sleep_sec; /**< Seconds to sleep */
91 uint32_t *dropped; /**< Test operations dropped */
92 uint32_t *enqueued; /**< Test operations enqueued */
95 struct test_config { /**< Master test structure for RTE_RED */
96 const char *ifname; /**< Interface name */
97 const char *msg; /**< Test message for display */
98 const char *htxt; /**< Header txt display for result output */
99 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
100 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
101 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
102 uint32_t *tlevel; /**< Queue levels */
110 /**< Test structure to define tests to run */
112 struct test_config *testcfg;
113 enum test_result (*testfn)(struct test_config *);
118 uint64_t clk_min; /**< min clocks */
119 uint64_t clk_max; /**< max clocks */
120 uint64_t clk_avgc; /**< count to calc average */
121 double clk_avg; /**< cumulative sum to calc average */
125 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
126 static double inv_cycles_per_byte = 0;
127 static double pkt_time_usec = 0;
129 static void init_port_ts(uint64_t cpu_clock)
131 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
132 inv_cycles_per_byte = 1.0 / cycles_per_byte;
133 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
136 static uint64_t get_port_ts(void)
138 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
141 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
143 p->clk_min = (uint64_t)(-1LL);
150 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
156 "xchgl %%ebx, %%edi;\n"
157 : : : "%eax", "%edi", "%ecx", "%edx" );
159 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
161 p->clk_start = rte_rdtsc();
164 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
166 uint64_t clk_start = rte_rdtsc() - p->clk_start;
169 p->clk_avg += (double) clk_start;
171 if (clk_start > p->clk_max)
172 p->clk_max = clk_start;
173 if (clk_start < p->clk_min)
174 p->clk_min = clk_start;
177 static void rdtsc_prof_print(struct rdtsc_prof *p)
180 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
185 (p->clk_avg / ((double) p->clk_avgc)));
189 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
193 * scale by 1/n and convert from fixed-point to integer
195 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
198 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
202 * scale by 1/n and convert from fixed-point to floating-point
204 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
207 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
212 * scale by n and convert from integer to fixed-point
214 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
217 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
219 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
222 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
224 return (double)dropped / ((double)enqueued + (double)dropped);
228 * calculate the drop probability
230 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
231 uint32_t maxp_inv, uint32_t avg)
233 double drop_prob = 0.0;
237 } else if (avg < max_th) {
238 drop_prob = (1.0 / (double)maxp_inv)
239 * ((double)(avg - min_th)
240 / (double)(max_th - min_th));
248 * check if drop rate matches drop probability within tolerance
250 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
252 double abs_diff = 0.0;
255 abs_diff = fabs(drop_rate - drop_prob);
256 if ((int)abs_diff == 0) {
259 *diff = (abs_diff / drop_prob) * 100.0;
260 if (*diff > tolerance) {
268 * check if average queue size is within tolerance
270 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
272 double abs_diff = 0.0;
275 abs_diff = fabs(avg - exp_avg);
276 if ((int)abs_diff == 0) {
279 *diff = (abs_diff / exp_avg) * 100.0;
280 if (*diff > tolerance) {
288 * get the clk frequency in Hz
290 static uint64_t get_machclk_freq(void)
295 uint64_t clk_freq_hz = 0;
296 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
297 struct timespec req = {0, 0};
302 clock_gettime(CLOCK_REALTIME, &tv_start);
305 if (nanosleep(&req, NULL) != 0) {
306 perror("get_machclk_freq()");
310 clock_gettime(CLOCK_REALTIME, &tv_end);
313 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
314 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
315 USEC_PER_MSEC); /**< diff is in micro secs */
320 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
321 return (clk_freq_hz);
325 * initialize the test rte_red config
327 static enum test_result
328 test_rte_red_init(struct test_config *tcfg)
332 tcfg->tvar->clk_freq = get_machclk_freq();
333 init_port_ts( tcfg->tvar->clk_freq );
335 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
336 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
337 (uint16_t)tcfg->tconfig->wq_log2[i],
338 (uint16_t)tcfg->tconfig->min_th,
339 (uint16_t)tcfg->tconfig->max_th,
340 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
345 *tcfg->tqueue->q = 0;
346 *tcfg->tvar->dropped = 0;
347 *tcfg->tvar->enqueued = 0;
352 * enqueue until actual queue size reaches target level
355 increase_actual_qsize(struct rte_red_config *red_cfg,
363 for (i = 0; i < attempts; i++) {
369 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
376 * check if target actual queue size has been reached
387 * enqueue until average queue size reaches target level
390 increase_average_qsize(struct rte_red_config *red_cfg,
399 for (i = 0; i < num_ops; i++) {
403 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
406 * check if target average queue size has been reached
408 avg = rte_red_get_avg_int(red_cfg, red);
418 * setup default values for the functional test structures
420 static struct rte_red_config ft_wrconfig[1];
421 static struct rte_red ft_rtdata[1];
422 static uint8_t ft_wq_log2[] = {9};
423 static uint8_t ft_maxp_inv[] = {10};
424 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
425 static uint32_t ft_q[] ={0};
426 static uint32_t ft_dropped[] ={0};
427 static uint32_t ft_enqueued[] ={0};
429 static struct test_rte_red_config ft_tconfig = {
430 .rconfig = ft_wrconfig,
431 .num_cfg = RTE_DIM(ft_wrconfig),
432 .wq_log2 = ft_wq_log2,
435 .maxp_inv = ft_maxp_inv,
438 static struct test_queue ft_tqueue = {
440 .num_queues = RTE_DIM(ft_rtdata),
441 .qconfig = ft_qconfig,
443 .q_ramp_up = 1000000,
444 .avg_ramp_up = 1000000,
445 .avg_tolerance = 5, /* 5 percent */
446 .drop_tolerance = 50, /* 50 percent */
449 static struct test_var ft_tvar = {
451 .num_iterations = 20,
454 .dropped = ft_dropped,
455 .enqueued = ft_enqueued,
456 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
460 * functional test enqueue/dequeue packets
462 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
471 for (i = 0; i < num_ops; i++) {
477 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
486 * Test F1: functional test 1
488 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};
490 static struct test_config func_test1_config = {
491 .ifname = "functional test 1 interface",
492 .msg = "functional test 1 : use one rte_red configuration,\n"
493 " increase average queue size to various levels,\n"
494 " compare drop rate to drop probability\n\n",
504 .tconfig = &ft_tconfig,
505 .tqueue = &ft_tqueue,
507 .tlevel = ft1_tlevels,
510 static enum test_result func_test1(struct test_config *tcfg)
512 enum test_result result = PASS;
515 printf("%s", tcfg->msg);
517 if (test_rte_red_init(tcfg) != PASS) {
522 printf("%s", tcfg->htxt);
524 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
525 const char *label = NULL;
527 double drop_rate = 0.0;
528 double drop_prob = 0.0;
532 * reset rte_red run-time data
534 rte_red_rt_data_init(tcfg->tqueue->rdata);
535 *tcfg->tvar->enqueued = 0;
536 *tcfg->tvar->dropped = 0;
538 if (increase_actual_qsize(tcfg->tconfig->rconfig,
542 tcfg->tqueue->q_ramp_up) != 0) {
547 if (increase_average_qsize(tcfg->tconfig->rconfig,
551 tcfg->tqueue->avg_ramp_up) != 0) {
556 enqueue_dequeue_func(tcfg->tconfig->rconfig,
560 tcfg->tvar->enqueued,
561 tcfg->tvar->dropped);
563 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
564 if (avg != tcfg->tlevel[i]) {
565 fprintf(stderr, "Fail: avg != level\n");
569 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
570 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
571 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
572 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
575 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
576 label = "min thresh: ";
577 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
578 label = "max thresh: ";
581 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
582 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
583 drop_prob * 100.0, drop_rate * 100.0, diff,
584 (double)tcfg->tqueue->drop_tolerance);
591 * Test F2: functional test 2
593 static uint32_t ft2_tlevel[] = {127};
594 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
595 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
596 static struct rte_red_config ft2_rconfig[10];
598 static struct test_rte_red_config ft2_tconfig = {
599 .rconfig = ft2_rconfig,
600 .num_cfg = RTE_DIM(ft2_rconfig),
601 .wq_log2 = ft2_wq_log2,
604 .maxp_inv = ft2_maxp_inv,
607 static struct test_config func_test2_config = {
608 .ifname = "functional test 2 interface",
609 .msg = "functional test 2 : use several RED configurations,\n"
610 " increase average queue size to just below maximum threshold,\n"
611 " compare drop rate to drop probability\n\n",
612 .htxt = "RED config "
621 .tconfig = &ft2_tconfig,
622 .tqueue = &ft_tqueue,
624 .tlevel = ft2_tlevel,
627 static enum test_result func_test2(struct test_config *tcfg)
629 enum test_result result = PASS;
630 double prev_drop_rate = 1.0;
633 printf("%s", tcfg->msg);
635 if (test_rte_red_init(tcfg) != PASS) {
639 rte_red_rt_data_init(tcfg->tqueue->rdata);
641 if (increase_actual_qsize(tcfg->tconfig->rconfig,
645 tcfg->tqueue->q_ramp_up) != 0) {
650 if (increase_average_qsize(tcfg->tconfig->rconfig,
654 tcfg->tqueue->avg_ramp_up) != 0) {
658 printf("%s", tcfg->htxt);
660 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
662 double drop_rate = 0.0;
663 double drop_prob = 0.0;
666 *tcfg->tvar->dropped = 0;
667 *tcfg->tvar->enqueued = 0;
669 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
673 tcfg->tvar->enqueued,
674 tcfg->tvar->dropped);
676 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
677 if (avg != *tcfg->tlevel)
680 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
681 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
682 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
683 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
686 * drop rate should decrease as maxp_inv increases
688 if (drop_rate > prev_drop_rate)
690 prev_drop_rate = drop_rate;
692 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
693 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
694 drop_prob * 100.0, drop_rate * 100.0, diff,
695 (double)tcfg->tqueue->drop_tolerance);
702 * Test F3: functional test 3
704 static uint32_t ft3_tlevel[] = {1022};
706 static struct test_rte_red_config ft3_tconfig = {
707 .rconfig = ft_wrconfig,
708 .num_cfg = RTE_DIM(ft_wrconfig),
709 .wq_log2 = ft_wq_log2,
712 .maxp_inv = ft_maxp_inv,
715 static struct test_config func_test3_config = {
716 .ifname = "functional test 3 interface",
717 .msg = "functional test 3 : use one RED configuration,\n"
718 " increase average queue size to target level,\n"
719 " dequeue all packets until queue is empty,\n"
720 " confirm that average queue size is computed correctly while queue is empty\n\n",
721 .htxt = "q avg before "
728 .tconfig = &ft3_tconfig,
729 .tqueue = &ft_tqueue,
731 .tlevel = ft3_tlevel,
734 static enum test_result func_test3(struct test_config *tcfg)
736 enum test_result result = PASS;
739 printf("%s", tcfg->msg);
741 if (test_rte_red_init(tcfg) != PASS) {
746 rte_red_rt_data_init(tcfg->tqueue->rdata);
748 if (increase_actual_qsize(tcfg->tconfig->rconfig,
752 tcfg->tqueue->q_ramp_up) != 0) {
757 if (increase_average_qsize(tcfg->tconfig->rconfig,
761 tcfg->tqueue->avg_ramp_up) != 0) {
766 printf("%s", tcfg->htxt);
768 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
769 double avg_before = 0;
770 double avg_after = 0;
774 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
779 *tcfg->tqueue->q = 0;
780 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
782 rte_delay_us(tcfg->tvar->wait_usec);
785 * enqueue one packet to recalculate average queue size
787 if (rte_red_enqueue(tcfg->tconfig->rconfig,
790 get_port_ts()) == 0) {
791 (*tcfg->tqueue->q)++;
793 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
797 exp_avg = calc_exp_avg_on_empty(avg_before,
798 (1 << *tcfg->tconfig->wq_log2),
799 tcfg->tvar->wait_usec);
800 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
801 tcfg->tqueue->rdata);
802 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
805 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
806 avg_before, avg_after, exp_avg, diff,
807 (double)tcfg->tqueue->avg_tolerance,
808 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
815 * Test F4: functional test 4
817 static uint32_t ft4_tlevel[] = {1022};
818 static uint8_t ft4_wq_log2[] = {11};
820 static struct test_rte_red_config ft4_tconfig = {
821 .rconfig = ft_wrconfig,
822 .num_cfg = RTE_DIM(ft_wrconfig),
825 .wq_log2 = ft4_wq_log2,
826 .maxp_inv = ft_maxp_inv,
829 static struct test_queue ft4_tqueue = {
831 .num_queues = RTE_DIM(ft_rtdata),
832 .qconfig = ft_qconfig,
834 .q_ramp_up = 1000000,
835 .avg_ramp_up = 1000000,
836 .avg_tolerance = 0, /* 0 percent */
837 .drop_tolerance = 50, /* 50 percent */
840 static struct test_config func_test4_config = {
841 .ifname = "functional test 4 interface",
842 .msg = "functional test 4 : use one RED configuration,\n"
843 " increase average queue size to target level,\n"
844 " dequeue all packets until queue is empty,\n"
845 " confirm that average queue size is computed correctly while\n"
846 " queue is empty for more than 50 sec,\n"
847 " (this test takes 52 sec to run)\n\n",
848 .htxt = "q avg before "
855 .tconfig = &ft4_tconfig,
856 .tqueue = &ft4_tqueue,
858 .tlevel = ft4_tlevel,
861 static enum test_result func_test4(struct test_config *tcfg)
863 enum test_result result = PASS;
864 uint64_t time_diff = 0;
866 double avg_before = 0.0;
867 double avg_after = 0.0;
868 double exp_avg = 0.0;
871 printf("%s", tcfg->msg);
873 if (test_rte_red_init(tcfg) != PASS) {
878 rte_red_rt_data_init(tcfg->tqueue->rdata);
880 if (increase_actual_qsize(tcfg->tconfig->rconfig,
884 tcfg->tqueue->q_ramp_up) != 0) {
889 if (increase_average_qsize(tcfg->tconfig->rconfig,
893 tcfg->tqueue->avg_ramp_up) != 0) {
898 printf("%s", tcfg->htxt);
900 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
905 *tcfg->tqueue->q = 0;
906 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
909 * record empty time locally
913 sleep(tcfg->tvar->sleep_sec);
916 * enqueue one packet to recalculate average queue size
918 if (rte_red_enqueue(tcfg->tconfig->rconfig,
921 get_port_ts()) != 0) {
925 (*tcfg->tqueue->q)++;
928 * calculate how long queue has been empty
930 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
932 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
934 * this could happen if sleep was interrupted for some reason
941 * confirm that average queue size is now at expected level
944 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
945 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
948 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
949 avg_before, avg_after, exp_avg,
950 diff, (double)tcfg->tqueue->avg_tolerance,
951 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
957 * Test F5: functional test 5
959 static uint32_t ft5_tlevel[] = {127};
960 static uint8_t ft5_wq_log2[] = {9, 8};
961 static uint8_t ft5_maxp_inv[] = {10, 20};
962 static struct rte_red_config ft5_config[2];
963 static struct rte_red ft5_data[4];
964 static uint32_t ft5_q[4];
965 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
966 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
968 static struct test_rte_red_config ft5_tconfig = {
969 .rconfig = ft5_config,
970 .num_cfg = RTE_DIM(ft5_config),
973 .wq_log2 = ft5_wq_log2,
974 .maxp_inv = ft5_maxp_inv,
977 static struct test_queue ft5_tqueue = {
979 .num_queues = RTE_DIM(ft5_data),
980 .qconfig = ft_qconfig,
982 .q_ramp_up = 1000000,
983 .avg_ramp_up = 1000000,
984 .avg_tolerance = 5, /* 10 percent */
985 .drop_tolerance = 50, /* 50 percent */
988 struct test_var ft5_tvar = {
990 .num_iterations = 15,
993 .dropped = ft5_dropped,
994 .enqueued = ft5_enqueued,
998 static struct test_config func_test5_config = {
999 .ifname = "functional test 5 interface",
1000 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
1001 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
1002 " increase average queue size to just below maximum threshold,\n"
1003 " compare drop rate to drop probability,\n"
1004 " (this is a larger scale version of functional test 2)\n\n",
1015 .tconfig = &ft5_tconfig,
1016 .tqueue = &ft5_tqueue,
1018 .tlevel = ft5_tlevel,
1021 static enum test_result func_test5(struct test_config *tcfg)
1023 enum test_result result = PASS;
1026 printf("%s", tcfg->msg);
1028 if (test_rte_red_init(tcfg) != PASS) {
1033 printf("%s", tcfg->htxt);
1035 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1036 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1037 tcfg->tqueue->q[j] = 0;
1039 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1040 &tcfg->tqueue->rdata[j],
1041 &tcfg->tqueue->q[j],
1043 tcfg->tqueue->q_ramp_up) != 0) {
1048 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1049 &tcfg->tqueue->rdata[j],
1050 &tcfg->tqueue->q[j],
1052 tcfg->tqueue->avg_ramp_up) != 0) {
1058 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1060 double drop_rate = 0.0;
1061 double drop_prob = 0.0;
1064 tcfg->tvar->dropped[j] = 0;
1065 tcfg->tvar->enqueued[j] = 0;
1067 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1068 &tcfg->tqueue->rdata[j],
1069 &tcfg->tqueue->q[j],
1070 tcfg->tvar->num_ops,
1071 &tcfg->tvar->enqueued[j],
1072 &tcfg->tvar->dropped[j]);
1074 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1075 &tcfg->tqueue->rdata[j]);
1076 if (avg != *tcfg->tlevel)
1079 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1080 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1081 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1083 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1086 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1087 j, tcfg->tqueue->qconfig[j], avg,
1088 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1089 drop_prob * 100.0, drop_rate * 100.0,
1090 diff, (double)tcfg->tqueue->drop_tolerance);
1097 * Test F6: functional test 6
1099 static uint32_t ft6_tlevel[] = {1022};
1100 static uint8_t ft6_wq_log2[] = {9, 8};
1101 static uint8_t ft6_maxp_inv[] = {10, 20};
1102 static struct rte_red_config ft6_config[2];
1103 static struct rte_red ft6_data[4];
1104 static uint32_t ft6_q[4];
1106 static struct test_rte_red_config ft6_tconfig = {
1107 .rconfig = ft6_config,
1108 .num_cfg = RTE_DIM(ft6_config),
1111 .wq_log2 = ft6_wq_log2,
1112 .maxp_inv = ft6_maxp_inv,
1115 static struct test_queue ft6_tqueue = {
1117 .num_queues = RTE_DIM(ft6_data),
1118 .qconfig = ft_qconfig,
1120 .q_ramp_up = 1000000,
1121 .avg_ramp_up = 1000000,
1122 .avg_tolerance = 5, /* 10 percent */
1123 .drop_tolerance = 50, /* 50 percent */
1126 static struct test_config func_test6_config = {
1127 .ifname = "functional test 6 interface",
1128 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1129 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1130 " increase average queue size to target level,\n"
1131 " dequeue all packets until queue is empty,\n"
1132 " confirm that average queue size is computed correctly while queue is empty\n"
1133 " (this is a larger scale version of functional test 3)\n\n",
1142 .tconfig = &ft6_tconfig,
1143 .tqueue = &ft6_tqueue,
1145 .tlevel = ft6_tlevel,
1148 static enum test_result func_test6(struct test_config *tcfg)
1150 enum test_result result = PASS;
1153 printf("%s", tcfg->msg);
1154 if (test_rte_red_init(tcfg) != PASS) {
1158 printf("%s", tcfg->htxt);
1160 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1161 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1162 tcfg->tqueue->q[j] = 0;
1164 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1165 &tcfg->tqueue->rdata[j],
1166 &tcfg->tqueue->q[j],
1168 tcfg->tqueue->q_ramp_up) != 0) {
1172 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1173 &tcfg->tqueue->rdata[j],
1174 &tcfg->tqueue->q[j],
1176 tcfg->tqueue->avg_ramp_up) != 0) {
1181 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1182 double avg_before = 0;
1183 double avg_after = 0;
1187 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1188 &tcfg->tqueue->rdata[j]);
1193 tcfg->tqueue->q[j] = 0;
1194 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1195 rte_delay_us(tcfg->tvar->wait_usec);
1198 * enqueue one packet to recalculate average queue size
1200 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1201 &tcfg->tqueue->rdata[j],
1203 get_port_ts()) == 0) {
1204 tcfg->tqueue->q[j]++;
1206 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1210 exp_avg = calc_exp_avg_on_empty(avg_before,
1211 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1212 tcfg->tvar->wait_usec);
1213 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1214 &tcfg->tqueue->rdata[j]);
1215 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1218 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1219 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1220 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1221 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1228 * setup default values for the performance test structures
1230 static struct rte_red_config pt_wrconfig[1];
1231 static struct rte_red pt_rtdata[1];
1232 static uint8_t pt_wq_log2[] = {9};
1233 static uint8_t pt_maxp_inv[] = {10};
1234 static uint32_t pt_qconfig[] = {0};
1235 static uint32_t pt_q[] = {0};
1236 static uint32_t pt_dropped[] = {0};
1237 static uint32_t pt_enqueued[] = {0};
1239 static struct test_rte_red_config pt_tconfig = {
1240 .rconfig = pt_wrconfig,
1241 .num_cfg = RTE_DIM(pt_wrconfig),
1242 .wq_log2 = pt_wq_log2,
1245 .maxp_inv = pt_maxp_inv,
1248 static struct test_queue pt_tqueue = {
1250 .num_queues = RTE_DIM(pt_rtdata),
1251 .qconfig = pt_qconfig,
1253 .q_ramp_up = 1000000,
1254 .avg_ramp_up = 1000000,
1255 .avg_tolerance = 5, /* 10 percent */
1256 .drop_tolerance = 50, /* 50 percent */
1260 * enqueue/dequeue packets
1262 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1263 struct rte_red *red,
1268 struct rdtsc_prof *prof)
1272 for (i = 0; i < num_ops; i++) {
1279 rdtsc_prof_start(prof);
1280 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1281 rdtsc_prof_end(prof);
1290 * Setup test structures for tests P1, P2, P3
1291 * performance tests 1, 2 and 3
1293 static uint32_t pt1_tlevel[] = {16};
1294 static uint32_t pt2_tlevel[] = {80};
1295 static uint32_t pt3_tlevel[] = {144};
1297 static struct test_var perf1_tvar = {
1299 .num_iterations = 15,
1300 .num_ops = 50000000,
1302 .dropped = pt_dropped,
1303 .enqueued = pt_enqueued,
1307 static struct test_config perf1_test1_config = {
1308 .ifname = "performance test 1 interface",
1309 .msg = "performance test 1 : use one RED configuration,\n"
1310 " set actual and average queue sizes to level below min threshold,\n"
1311 " measure enqueue performance\n\n",
1312 .tconfig = &pt_tconfig,
1313 .tqueue = &pt_tqueue,
1314 .tvar = &perf1_tvar,
1315 .tlevel = pt1_tlevel,
1318 static struct test_config perf1_test2_config = {
1319 .ifname = "performance test 2 interface",
1320 .msg = "performance test 2 : use one RED configuration,\n"
1321 " set actual and average queue sizes to level in between min and max thresholds,\n"
1322 " measure enqueue performance\n\n",
1323 .tconfig = &pt_tconfig,
1324 .tqueue = &pt_tqueue,
1325 .tvar = &perf1_tvar,
1326 .tlevel = pt2_tlevel,
1329 static struct test_config perf1_test3_config = {
1330 .ifname = "performance test 3 interface",
1331 .msg = "performance test 3 : use one RED configuration,\n"
1332 " set actual and average queue sizes to level above max threshold,\n"
1333 " measure enqueue performance\n\n",
1334 .tconfig = &pt_tconfig,
1335 .tqueue = &pt_tqueue,
1336 .tvar = &perf1_tvar,
1337 .tlevel = pt3_tlevel,
1341 * Performance test function to measure enqueue performance.
1342 * This runs performance tests 1, 2 and 3
1344 static enum test_result perf1_test(struct test_config *tcfg)
1346 enum test_result result = PASS;
1347 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1350 printf("%s", tcfg->msg);
1352 rdtsc_prof_init(&prof, "enqueue");
1354 if (test_rte_red_init(tcfg) != PASS) {
1360 * set average queue size to target level
1362 *tcfg->tqueue->q = *tcfg->tlevel;
1365 * initialize the rte_red run time data structure
1367 rte_red_rt_data_init(tcfg->tqueue->rdata);
1370 * set the queue average
1372 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1373 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1379 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1380 tcfg->tqueue->rdata,
1382 tcfg->tvar->num_ops,
1383 tcfg->tvar->enqueued,
1384 tcfg->tvar->dropped,
1387 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1389 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1390 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1391 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1393 rdtsc_prof_print(&prof);
1399 * Setup test structures for tests P4, P5, P6
1400 * performance tests 4, 5 and 6
1402 static uint32_t pt4_tlevel[] = {16};
1403 static uint32_t pt5_tlevel[] = {80};
1404 static uint32_t pt6_tlevel[] = {144};
1406 static struct test_var perf2_tvar = {
1408 .num_iterations = 10000,
1410 .dropped = pt_dropped,
1411 .enqueued = pt_enqueued,
1415 static struct test_config perf2_test4_config = {
1416 .ifname = "performance test 4 interface",
1417 .msg = "performance test 4 : use one RED configuration,\n"
1418 " set actual and average queue sizes to level below min threshold,\n"
1419 " dequeue all packets until queue is empty,\n"
1420 " measure enqueue performance when queue is empty\n\n",
1421 .htxt = "iteration "
1428 .tconfig = &pt_tconfig,
1429 .tqueue = &pt_tqueue,
1430 .tvar = &perf2_tvar,
1431 .tlevel = pt4_tlevel,
1434 static struct test_config perf2_test5_config = {
1435 .ifname = "performance test 5 interface",
1436 .msg = "performance test 5 : use one RED configuration,\n"
1437 " set actual and average queue sizes to level in between min and max thresholds,\n"
1438 " dequeue all packets until queue is empty,\n"
1439 " measure enqueue performance when queue is empty\n\n",
1440 .htxt = "iteration "
1447 .tconfig = &pt_tconfig,
1448 .tqueue = &pt_tqueue,
1449 .tvar = &perf2_tvar,
1450 .tlevel = pt5_tlevel,
1453 static struct test_config perf2_test6_config = {
1454 .ifname = "performance test 6 interface",
1455 .msg = "performance test 6 : use one RED configuration,\n"
1456 " set actual and average queue sizes to level above max threshold,\n"
1457 " dequeue all packets until queue is empty,\n"
1458 " measure enqueue performance when queue is empty\n\n",
1459 .htxt = "iteration "
1466 .tconfig = &pt_tconfig,
1467 .tqueue = &pt_tqueue,
1468 .tvar = &perf2_tvar,
1469 .tlevel = pt6_tlevel,
1473 * Performance test function to measure enqueue performance when the
1474 * queue is empty. This runs performance tests 4, 5 and 6
1476 static enum test_result perf2_test(struct test_config *tcfg)
1478 enum test_result result = PASS;
1479 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1483 printf("%s", tcfg->msg);
1485 rdtsc_prof_init(&prof, "enqueue");
1487 if (test_rte_red_init(tcfg) != PASS) {
1492 printf("%s", tcfg->htxt);
1494 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1497 double avg_before = 0;
1501 * set average queue size to target level
1503 *tcfg->tqueue->q = *tcfg->tlevel;
1504 count = (*tcfg->tqueue->rdata).count;
1507 * initialize the rte_red run time data structure
1509 rte_red_rt_data_init(tcfg->tqueue->rdata);
1510 (*tcfg->tqueue->rdata).count = count;
1513 * set the queue average
1515 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1516 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1517 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1525 *tcfg->tqueue->q = 0;
1526 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1529 * wait for specified period of time
1531 rte_delay_us(tcfg->tvar->wait_usec);
1534 * measure performance of enqueue operation while queue is empty
1537 rdtsc_prof_start(&prof);
1538 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1539 *tcfg->tqueue->q, ts );
1540 rdtsc_prof_end(&prof);
1543 * gather enqueued/dropped statistics
1546 (*tcfg->tvar->enqueued)++;
1548 (*tcfg->tvar->dropped)++;
1551 * on first and last iteration, confirm that
1552 * average queue size was computed correctly
1554 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1555 double avg_after = 0;
1560 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1561 exp_avg = calc_exp_avg_on_empty(avg_before,
1562 (1 << *tcfg->tconfig->wq_log2),
1563 tcfg->tvar->wait_usec);
1564 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1566 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1567 i, avg_before, avg_after, exp_avg, diff,
1568 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1575 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1576 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1577 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1578 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1580 rdtsc_prof_print(&prof);
1586 * setup default values for overflow test structures
1588 static uint32_t avg_max = 0;
1589 static uint32_t avg_max_bits = 0;
1591 static struct rte_red_config ovfl_wrconfig[1];
1592 static struct rte_red ovfl_rtdata[1];
1593 static uint8_t ovfl_maxp_inv[] = {10};
1594 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1595 static uint32_t ovfl_q[] ={0};
1596 static uint32_t ovfl_dropped[] ={0};
1597 static uint32_t ovfl_enqueued[] ={0};
1598 static uint32_t ovfl_tlevel[] = {1023};
1599 static uint8_t ovfl_wq_log2[] = {12};
1601 static struct test_rte_red_config ovfl_tconfig = {
1602 .rconfig = ovfl_wrconfig,
1603 .num_cfg = RTE_DIM(ovfl_wrconfig),
1604 .wq_log2 = ovfl_wq_log2,
1607 .maxp_inv = ovfl_maxp_inv,
1610 static struct test_queue ovfl_tqueue = {
1611 .rdata = ovfl_rtdata,
1612 .num_queues = RTE_DIM(ovfl_rtdata),
1613 .qconfig = ovfl_qconfig,
1615 .q_ramp_up = 1000000,
1616 .avg_ramp_up = 1000000,
1617 .avg_tolerance = 5, /* 10 percent */
1618 .drop_tolerance = 50, /* 50 percent */
1621 static struct test_var ovfl_tvar = {
1623 .num_iterations = 1,
1626 .dropped = ovfl_dropped,
1627 .enqueued = ovfl_enqueued,
1631 static void ovfl_check_avg(uint32_t avg)
1633 if (avg > avg_max) {
1637 avg_log = log(((double)avg_max));
1638 avg_log = avg_log / log(2.0);
1639 bits = (uint32_t)ceil(avg_log);
1640 if (bits > avg_max_bits)
1641 avg_max_bits = bits;
1645 static struct test_config ovfl_test1_config = {
1646 .ifname = "queue avergage overflow test interface",
1647 .msg = "overflow test 1 : use one RED configuration,\n"
1648 " increase average queue size to target level,\n"
1649 " check maximum number of bits requirte_red to represent avg_s\n\n",
1650 .htxt = "avg queue size "
1660 .tconfig = &ovfl_tconfig,
1661 .tqueue = &ovfl_tqueue,
1663 .tlevel = ovfl_tlevel,
1666 static enum test_result ovfl_test1(struct test_config *tcfg)
1668 enum test_result result = PASS;
1671 double drop_rate = 0.0;
1672 double drop_prob = 0.0;
1676 printf("%s", tcfg->msg);
1678 if (test_rte_red_init(tcfg) != PASS) {
1685 * reset rte_red run-time data
1687 rte_red_rt_data_init(tcfg->tqueue->rdata);
1690 * increase actual queue size
1692 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1693 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1694 *tcfg->tqueue->q, get_port_ts());
1697 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1705 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1706 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1707 *tcfg->tqueue->q, get_port_ts());
1708 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1709 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1710 if (avg == *tcfg->tlevel) {
1712 (*tcfg->tvar->enqueued)++;
1714 (*tcfg->tvar->dropped)++;
1719 * check if target average queue size has been reached
1721 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1722 if (avg != *tcfg->tlevel) {
1728 * check drop rate against drop probability
1730 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1731 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1732 tcfg->tconfig->max_th,
1733 *tcfg->tconfig->maxp_inv,
1735 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1738 printf("%s", tcfg->htxt);
1740 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1741 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1742 avg_max, avg_max_bits,
1743 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1744 drop_prob * 100.0, drop_rate * 100.0);
1750 * define the functional and performance tests to be executed
1752 struct tests func_tests[] = {
1753 { &func_test1_config, func_test1 },
1754 { &func_test2_config, func_test2 },
1755 { &func_test3_config, func_test3 },
1756 { &func_test4_config, func_test4 },
1757 { &func_test5_config, func_test5 },
1758 { &func_test6_config, func_test6 },
1759 { &ovfl_test1_config, ovfl_test1 },
1762 struct tests perf_tests[] = {
1763 { &perf1_test1_config, perf1_test },
1764 { &perf1_test2_config, perf1_test },
1765 { &perf1_test3_config, perf1_test },
1766 { &perf2_test4_config, perf2_test },
1767 { &perf2_test5_config, perf2_test },
1768 { &perf2_test6_config, perf2_test },
1772 * function to execute the required_red tests
1774 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1776 enum test_result result = PASS;
1779 for (i = 0; i < test_count; i++) {
1780 printf("\n--------------------------------------------------------------------------------\n");
1781 result = test_type[i].testfn(test_type[i].testcfg);
1783 if (result == PASS) {
1785 printf("-------------------------------------<pass>-------------------------------------\n");
1787 printf("-------------------------------------<fail>-------------------------------------\n");
1794 * check if functions accept invalid parameters
1796 * First, all functions will be called without initialized RED
1797 * Then, all of them will be called with NULL/invalid parameters
1799 * Some functions are not tested as they are performance-critical and thus
1800 * don't do any parameter checking.
1803 test_invalid_parameters(void)
1805 struct rte_red_config config;
1807 if (rte_red_rt_data_init(NULL) == 0) {
1808 printf("rte_red_rt_data_init should have failed!\n");
1812 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1813 printf("rte_red_config_init should have failed!\n");
1817 if (rte_red_rt_data_init(NULL) == 0) {
1818 printf("rte_red_rt_data_init should have failed!\n");
1823 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1824 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1827 /* min_treshold == max_treshold */
1828 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1829 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1832 /* min_treshold > max_treshold */
1833 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1834 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1837 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1838 if (rte_red_config_init(&config,
1839 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1840 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1843 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1844 if (rte_red_config_init(&config,
1845 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1846 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1849 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1850 if (rte_red_config_init(&config,
1851 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1852 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1855 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1856 if (rte_red_config_init(&config,
1857 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1858 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1867 uint32_t num_tests = 0;
1868 uint32_t num_pass = 0;
1871 if (test_invalid_parameters() < 0)
1874 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1875 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1877 if (num_pass == num_tests) {
1878 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1881 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1892 printf("The SCHED library is not included in this build\n");