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 DIM(x) (sizeof(x)/sizeof(x[0]))
57 #define TEST_HZ_PER_KHZ 1000
58 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
60 #define MAX_QEMPTY_TIME_MSEC 50000
61 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
62 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
63 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
65 /**< structures for testing rte_red performance and function */
66 struct test_rte_red_config { /**< Test structure for RTE_RED config */
67 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
68 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
69 uint8_t *wq_log2; /**< Test wq_log2 value to use */
70 uint32_t min_th; /**< Queue minimum threshold */
71 uint32_t max_th; /**< Queue maximum threshold */
72 uint8_t *maxp_inv; /**< Inverse mark probability */
75 struct test_queue { /**< Test structure for RTE_RED Queues */
76 struct rte_red *rdata; /**< RTE_RED runtime data */
77 uint32_t num_queues; /**< Number of RTE_RED queues to test */
78 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
79 uint32_t *q; /**< Queue size */
80 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
81 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
82 uint32_t avg_tolerance; /**< Tolerance in queue average */
83 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
86 struct test_var { /**< Test variables used for testing RTE_RED */
87 uint32_t wait_usec; /**< Micro second wait interval */
88 uint32_t num_iterations; /**< Number of test iterations */
89 uint32_t num_ops; /**< Number of test operations */
90 uint64_t clk_freq; /**< CPU clock frequency */
91 uint32_t sleep_sec; /**< Seconds to sleep */
92 uint32_t *dropped; /**< Test operations dropped */
93 uint32_t *enqueued; /**< Test operations enqueued */
96 struct test_config { /**< Master test structure for RTE_RED */
97 const char *ifname; /**< Interface name */
98 const char *msg; /**< Test message for display */
99 const char *htxt; /**< Header txt display for result output */
100 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
101 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
102 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
103 uint32_t *tlevel; /**< Queue levels */
111 /**< Test structure to define tests to run */
113 struct test_config *testcfg;
114 enum test_result (*testfn)(struct test_config *);
119 uint64_t clk_min; /**< min clocks */
120 uint64_t clk_max; /**< max clocks */
121 uint64_t clk_avgc; /**< count to calc average */
122 double clk_avg; /**< cumulative sum to calc average */
126 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
127 static double inv_cycles_per_byte = 0;
128 static double pkt_time_usec = 0;
130 static void init_port_ts(uint64_t cpu_clock)
132 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
133 inv_cycles_per_byte = 1.0 / cycles_per_byte;
134 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
137 static uint64_t get_port_ts(void)
139 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
142 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
144 p->clk_min = (uint64_t)(-1LL);
151 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
157 "xchgl %%ebx, %%edi;\n"
158 : : : "%eax", "%edi", "%ecx", "%edx" );
160 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
162 p->clk_start = rte_rdtsc();
165 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
167 uint64_t clk_start = rte_rdtsc() - p->clk_start;
170 p->clk_avg += (double) clk_start;
172 if (clk_start > p->clk_max)
173 p->clk_max = clk_start;
174 if (clk_start < p->clk_min)
175 p->clk_min = clk_start;
178 static void rdtsc_prof_print(struct rdtsc_prof *p)
181 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
186 (p->clk_avg / ((double) p->clk_avgc)));
190 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
194 * scale by 1/n and convert from fixed-point to integer
196 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
199 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
203 * scale by 1/n and convert from fixed-point to floating-point
205 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
208 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
213 * scale by n and convert from integer to fixed-point
215 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
218 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
220 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
223 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
225 return (double)dropped / ((double)enqueued + (double)dropped);
229 * calculate the drop probability
231 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
232 uint32_t maxp_inv, uint32_t avg)
234 double drop_prob = 0.0;
238 } else if (avg < max_th) {
239 drop_prob = (1.0 / (double)maxp_inv)
240 * ((double)(avg - min_th)
241 / (double)(max_th - min_th));
249 * check if drop rate matches drop probability within tolerance
251 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
253 double abs_diff = 0.0;
256 abs_diff = fabs(drop_rate - drop_prob);
257 if ((int)abs_diff == 0) {
260 *diff = (abs_diff / drop_prob) * 100.0;
261 if (*diff > tolerance) {
269 * check if average queue size is within tolerance
271 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
273 double abs_diff = 0.0;
276 abs_diff = fabs(avg - exp_avg);
277 if ((int)abs_diff == 0) {
280 *diff = (abs_diff / exp_avg) * 100.0;
281 if (*diff > tolerance) {
289 * get the clk frequency in Hz
291 static uint64_t get_machclk_freq(void)
296 uint64_t clk_freq_hz = 0;
297 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
298 struct timespec req = {0, 0};
303 clock_gettime(CLOCK_REALTIME, &tv_start);
306 if (nanosleep(&req, NULL) != 0) {
307 perror("get_machclk_freq()");
311 clock_gettime(CLOCK_REALTIME, &tv_end);
314 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
315 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
316 USEC_PER_MSEC); /**< diff is in micro secs */
321 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
322 return (clk_freq_hz);
326 * initialize the test rte_red config
328 static enum test_result
329 test_rte_red_init(struct test_config *tcfg)
333 tcfg->tvar->clk_freq = get_machclk_freq();
334 init_port_ts( tcfg->tvar->clk_freq );
336 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
337 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
338 (uint16_t)tcfg->tconfig->wq_log2[i],
339 (uint16_t)tcfg->tconfig->min_th,
340 (uint16_t)tcfg->tconfig->max_th,
341 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
346 *tcfg->tqueue->q = 0;
347 *tcfg->tvar->dropped = 0;
348 *tcfg->tvar->enqueued = 0;
353 * enqueue until actual queue size reaches target level
356 increase_actual_qsize(struct rte_red_config *red_cfg,
364 for (i = 0; i < attempts; i++) {
370 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
377 * check if target actual queue size has been reached
388 * enqueue until average queue size reaches target level
391 increase_average_qsize(struct rte_red_config *red_cfg,
400 for (i = 0; i < num_ops; i++) {
404 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
407 * check if target average queue size has been reached
409 avg = rte_red_get_avg_int(red_cfg, red);
419 * setup default values for the functional test structures
421 static struct rte_red_config ft_wrconfig[1];
422 static struct rte_red ft_rtdata[1];
423 static uint8_t ft_wq_log2[] = {9};
424 static uint8_t ft_maxp_inv[] = {10};
425 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
426 static uint32_t ft_q[] ={0};
427 static uint32_t ft_dropped[] ={0};
428 static uint32_t ft_enqueued[] ={0};
430 static struct test_rte_red_config ft_tconfig = {
431 .rconfig = ft_wrconfig,
432 .num_cfg = DIM(ft_wrconfig),
433 .wq_log2 = ft_wq_log2,
436 .maxp_inv = ft_maxp_inv,
439 static struct test_queue ft_tqueue = {
441 .num_queues = DIM(ft_rtdata),
442 .qconfig = ft_qconfig,
444 .q_ramp_up = 1000000,
445 .avg_ramp_up = 1000000,
446 .avg_tolerance = 5, /* 5 percent */
447 .drop_tolerance = 50, /* 50 percent */
450 static struct test_var ft_tvar = {
452 .num_iterations = 20,
455 .dropped = ft_dropped,
456 .enqueued = ft_enqueued,
457 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
461 * functional test enqueue/dequeue packets
463 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
472 for (i = 0; i < num_ops; i++) {
478 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
487 * Test F1: functional test 1
489 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};
491 static struct test_config func_test1_config = {
492 .ifname = "functional test 1 interface",
493 .msg = "functional test 1 : use one rte_red configuration,\n"
494 " increase average queue size to various levels,\n"
495 " compare drop rate to drop probability\n\n",
505 .tconfig = &ft_tconfig,
506 .tqueue = &ft_tqueue,
508 .tlevel = ft1_tlevels,
511 static enum test_result func_test1(struct test_config *tcfg)
513 enum test_result result = PASS;
516 printf("%s", tcfg->msg);
518 if (test_rte_red_init(tcfg) != PASS) {
523 printf("%s", tcfg->htxt);
525 for (i = 0; i < DIM(ft1_tlevels); i++) {
526 const char *label = NULL;
528 double drop_rate = 0.0;
529 double drop_prob = 0.0;
533 * reset rte_red run-time data
535 rte_red_rt_data_init(tcfg->tqueue->rdata);
536 *tcfg->tvar->enqueued = 0;
537 *tcfg->tvar->dropped = 0;
539 if (increase_actual_qsize(tcfg->tconfig->rconfig,
543 tcfg->tqueue->q_ramp_up) != 0) {
548 if (increase_average_qsize(tcfg->tconfig->rconfig,
552 tcfg->tqueue->avg_ramp_up) != 0) {
557 enqueue_dequeue_func(tcfg->tconfig->rconfig,
561 tcfg->tvar->enqueued,
562 tcfg->tvar->dropped);
564 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
565 if (avg != tcfg->tlevel[i]) {
566 fprintf(stderr, "Fail: avg != level\n");
570 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
571 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
572 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
573 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
576 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
577 label = "min thresh: ";
578 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
579 label = "max thresh: ";
582 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
583 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
584 drop_prob * 100.0, drop_rate * 100.0, diff,
585 (double)tcfg->tqueue->drop_tolerance);
592 * Test F2: functional test 2
594 static uint32_t ft2_tlevel[] = {127};
595 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
596 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
597 static struct rte_red_config ft2_rconfig[10];
599 static struct test_rte_red_config ft2_tconfig = {
600 .rconfig = ft2_rconfig,
601 .num_cfg = DIM(ft2_rconfig),
602 .wq_log2 = ft2_wq_log2,
605 .maxp_inv = ft2_maxp_inv,
608 static struct test_config func_test2_config = {
609 .ifname = "functional test 2 interface",
610 .msg = "functional test 2 : use several RED configurations,\n"
611 " increase average queue size to just below maximum threshold,\n"
612 " compare drop rate to drop probability\n\n",
613 .htxt = "RED config "
622 .tconfig = &ft2_tconfig,
623 .tqueue = &ft_tqueue,
625 .tlevel = ft2_tlevel,
628 static enum test_result func_test2(struct test_config *tcfg)
630 enum test_result result = PASS;
631 double prev_drop_rate = 1.0;
634 printf("%s", tcfg->msg);
636 if (test_rte_red_init(tcfg) != PASS) {
640 rte_red_rt_data_init(tcfg->tqueue->rdata);
642 if (increase_actual_qsize(tcfg->tconfig->rconfig,
646 tcfg->tqueue->q_ramp_up) != 0) {
651 if (increase_average_qsize(tcfg->tconfig->rconfig,
655 tcfg->tqueue->avg_ramp_up) != 0) {
659 printf("%s", tcfg->htxt);
661 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
663 double drop_rate = 0.0;
664 double drop_prob = 0.0;
667 *tcfg->tvar->dropped = 0;
668 *tcfg->tvar->enqueued = 0;
670 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
674 tcfg->tvar->enqueued,
675 tcfg->tvar->dropped);
677 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
678 if (avg != *tcfg->tlevel)
681 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
682 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
683 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
684 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
687 * drop rate should decrease as maxp_inv increases
689 if (drop_rate > prev_drop_rate)
691 prev_drop_rate = drop_rate;
693 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
694 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
695 drop_prob * 100.0, drop_rate * 100.0, diff,
696 (double)tcfg->tqueue->drop_tolerance);
703 * Test F3: functional test 3
705 static uint32_t ft3_tlevel[] = {1022};
707 static struct test_rte_red_config ft3_tconfig = {
708 .rconfig = ft_wrconfig,
709 .num_cfg = DIM(ft_wrconfig),
710 .wq_log2 = ft_wq_log2,
713 .maxp_inv = ft_maxp_inv,
716 static struct test_config func_test3_config = {
717 .ifname = "functional test 3 interface",
718 .msg = "functional test 3 : use one RED configuration,\n"
719 " increase average queue size to target level,\n"
720 " dequeue all packets until queue is empty,\n"
721 " confirm that average queue size is computed correctly while queue is empty\n\n",
722 .htxt = "q avg before "
729 .tconfig = &ft3_tconfig,
730 .tqueue = &ft_tqueue,
732 .tlevel = ft3_tlevel,
735 static enum test_result func_test3(struct test_config *tcfg)
737 enum test_result result = PASS;
740 printf("%s", tcfg->msg);
742 if (test_rte_red_init(tcfg) != PASS) {
747 rte_red_rt_data_init(tcfg->tqueue->rdata);
749 if (increase_actual_qsize(tcfg->tconfig->rconfig,
753 tcfg->tqueue->q_ramp_up) != 0) {
758 if (increase_average_qsize(tcfg->tconfig->rconfig,
762 tcfg->tqueue->avg_ramp_up) != 0) {
767 printf("%s", tcfg->htxt);
769 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
770 double avg_before = 0;
771 double avg_after = 0;
775 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
780 *tcfg->tqueue->q = 0;
781 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
783 rte_delay_us(tcfg->tvar->wait_usec);
786 * enqueue one packet to recalculate average queue size
788 if (rte_red_enqueue(tcfg->tconfig->rconfig,
791 get_port_ts()) == 0) {
792 (*tcfg->tqueue->q)++;
794 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
798 exp_avg = calc_exp_avg_on_empty(avg_before,
799 (1 << *tcfg->tconfig->wq_log2),
800 tcfg->tvar->wait_usec);
801 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
802 tcfg->tqueue->rdata);
803 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
806 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
807 avg_before, avg_after, exp_avg, diff,
808 (double)tcfg->tqueue->avg_tolerance,
809 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
816 * Test F4: functional test 4
818 static uint32_t ft4_tlevel[] = {1022};
819 static uint8_t ft4_wq_log2[] = {11};
821 static struct test_rte_red_config ft4_tconfig = {
822 .rconfig = ft_wrconfig,
823 .num_cfg = DIM(ft_wrconfig),
826 .wq_log2 = ft4_wq_log2,
827 .maxp_inv = ft_maxp_inv,
830 static struct test_queue ft4_tqueue = {
832 .num_queues = DIM(ft_rtdata),
833 .qconfig = ft_qconfig,
835 .q_ramp_up = 1000000,
836 .avg_ramp_up = 1000000,
837 .avg_tolerance = 0, /* 0 percent */
838 .drop_tolerance = 50, /* 50 percent */
841 static struct test_config func_test4_config = {
842 .ifname = "functional test 4 interface",
843 .msg = "functional test 4 : use one RED configuration,\n"
844 " increase average queue size to target level,\n"
845 " dequeue all packets until queue is empty,\n"
846 " confirm that average queue size is computed correctly while\n"
847 " queue is empty for more than 50 sec,\n"
848 " (this test takes 52 sec to run)\n\n",
849 .htxt = "q avg before "
856 .tconfig = &ft4_tconfig,
857 .tqueue = &ft4_tqueue,
859 .tlevel = ft4_tlevel,
862 static enum test_result func_test4(struct test_config *tcfg)
864 enum test_result result = PASS;
865 uint64_t time_diff = 0;
867 double avg_before = 0.0;
868 double avg_after = 0.0;
869 double exp_avg = 0.0;
872 printf("%s", tcfg->msg);
874 if (test_rte_red_init(tcfg) != PASS) {
879 rte_red_rt_data_init(tcfg->tqueue->rdata);
881 if (increase_actual_qsize(tcfg->tconfig->rconfig,
885 tcfg->tqueue->q_ramp_up) != 0) {
890 if (increase_average_qsize(tcfg->tconfig->rconfig,
894 tcfg->tqueue->avg_ramp_up) != 0) {
899 printf("%s", tcfg->htxt);
901 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
906 *tcfg->tqueue->q = 0;
907 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
910 * record empty time locally
914 sleep(tcfg->tvar->sleep_sec);
917 * enqueue one packet to recalculate average queue size
919 if (rte_red_enqueue(tcfg->tconfig->rconfig,
922 get_port_ts()) != 0) {
926 (*tcfg->tqueue->q)++;
929 * calculate how long queue has been empty
931 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
933 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
935 * this could happen if sleep was interrupted for some reason
942 * confirm that average queue size is now at expected level
945 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
946 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
949 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
950 avg_before, avg_after, exp_avg,
951 diff, (double)tcfg->tqueue->avg_tolerance,
952 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
958 * Test F5: functional test 5
960 static uint32_t ft5_tlevel[] = {127};
961 static uint8_t ft5_wq_log2[] = {9, 8};
962 static uint8_t ft5_maxp_inv[] = {10, 20};
963 static struct rte_red_config ft5_config[2];
964 static struct rte_red ft5_data[4];
965 static uint32_t ft5_q[4];
966 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
967 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
969 static struct test_rte_red_config ft5_tconfig = {
970 .rconfig = ft5_config,
971 .num_cfg = DIM(ft5_config),
974 .wq_log2 = ft5_wq_log2,
975 .maxp_inv = ft5_maxp_inv,
978 static struct test_queue ft5_tqueue = {
980 .num_queues = DIM(ft5_data),
981 .qconfig = ft_qconfig,
983 .q_ramp_up = 1000000,
984 .avg_ramp_up = 1000000,
985 .avg_tolerance = 5, /* 10 percent */
986 .drop_tolerance = 50, /* 50 percent */
989 struct test_var ft5_tvar = {
991 .num_iterations = 15,
994 .dropped = ft5_dropped,
995 .enqueued = ft5_enqueued,
999 static struct test_config func_test5_config = {
1000 .ifname = "functional test 5 interface",
1001 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
1002 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
1003 " increase average queue size to just below maximum threshold,\n"
1004 " compare drop rate to drop probability,\n"
1005 " (this is a larger scale version of functional test 2)\n\n",
1016 .tconfig = &ft5_tconfig,
1017 .tqueue = &ft5_tqueue,
1019 .tlevel = ft5_tlevel,
1022 static enum test_result func_test5(struct test_config *tcfg)
1024 enum test_result result = PASS;
1027 printf("%s", tcfg->msg);
1029 if (test_rte_red_init(tcfg) != PASS) {
1034 printf("%s", tcfg->htxt);
1036 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1037 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1038 tcfg->tqueue->q[j] = 0;
1040 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1041 &tcfg->tqueue->rdata[j],
1042 &tcfg->tqueue->q[j],
1044 tcfg->tqueue->q_ramp_up) != 0) {
1049 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1050 &tcfg->tqueue->rdata[j],
1051 &tcfg->tqueue->q[j],
1053 tcfg->tqueue->avg_ramp_up) != 0) {
1059 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1061 double drop_rate = 0.0;
1062 double drop_prob = 0.0;
1065 tcfg->tvar->dropped[j] = 0;
1066 tcfg->tvar->enqueued[j] = 0;
1068 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1069 &tcfg->tqueue->rdata[j],
1070 &tcfg->tqueue->q[j],
1071 tcfg->tvar->num_ops,
1072 &tcfg->tvar->enqueued[j],
1073 &tcfg->tvar->dropped[j]);
1075 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1076 &tcfg->tqueue->rdata[j]);
1077 if (avg != *tcfg->tlevel)
1080 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1081 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1082 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1084 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1087 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1088 j, tcfg->tqueue->qconfig[j], avg,
1089 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1090 drop_prob * 100.0, drop_rate * 100.0,
1091 diff, (double)tcfg->tqueue->drop_tolerance);
1098 * Test F6: functional test 6
1100 static uint32_t ft6_tlevel[] = {1022};
1101 static uint8_t ft6_wq_log2[] = {9, 8};
1102 static uint8_t ft6_maxp_inv[] = {10, 20};
1103 static struct rte_red_config ft6_config[2];
1104 static struct rte_red ft6_data[4];
1105 static uint32_t ft6_q[4];
1107 static struct test_rte_red_config ft6_tconfig = {
1108 .rconfig = ft6_config,
1109 .num_cfg = DIM(ft6_config),
1112 .wq_log2 = ft6_wq_log2,
1113 .maxp_inv = ft6_maxp_inv,
1116 static struct test_queue ft6_tqueue = {
1118 .num_queues = DIM(ft6_data),
1119 .qconfig = ft_qconfig,
1121 .q_ramp_up = 1000000,
1122 .avg_ramp_up = 1000000,
1123 .avg_tolerance = 5, /* 10 percent */
1124 .drop_tolerance = 50, /* 50 percent */
1127 static struct test_config func_test6_config = {
1128 .ifname = "functional test 6 interface",
1129 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1130 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1131 " increase average queue size to target level,\n"
1132 " dequeue all packets until queue is empty,\n"
1133 " confirm that average queue size is computed correctly while queue is empty\n"
1134 " (this is a larger scale version of functional test 3)\n\n",
1143 .tconfig = &ft6_tconfig,
1144 .tqueue = &ft6_tqueue,
1146 .tlevel = ft6_tlevel,
1149 static enum test_result func_test6(struct test_config *tcfg)
1151 enum test_result result = PASS;
1154 printf("%s", tcfg->msg);
1155 if (test_rte_red_init(tcfg) != PASS) {
1159 printf("%s", tcfg->htxt);
1161 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1162 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1163 tcfg->tqueue->q[j] = 0;
1165 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1166 &tcfg->tqueue->rdata[j],
1167 &tcfg->tqueue->q[j],
1169 tcfg->tqueue->q_ramp_up) != 0) {
1173 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1174 &tcfg->tqueue->rdata[j],
1175 &tcfg->tqueue->q[j],
1177 tcfg->tqueue->avg_ramp_up) != 0) {
1182 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1183 double avg_before = 0;
1184 double avg_after = 0;
1188 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1189 &tcfg->tqueue->rdata[j]);
1194 tcfg->tqueue->q[j] = 0;
1195 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1196 rte_delay_us(tcfg->tvar->wait_usec);
1199 * enqueue one packet to recalculate average queue size
1201 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1202 &tcfg->tqueue->rdata[j],
1204 get_port_ts()) == 0) {
1205 tcfg->tqueue->q[j]++;
1207 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1211 exp_avg = calc_exp_avg_on_empty(avg_before,
1212 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1213 tcfg->tvar->wait_usec);
1214 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1215 &tcfg->tqueue->rdata[j]);
1216 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1219 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1220 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1221 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1222 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1229 * setup default values for the performance test structures
1231 static struct rte_red_config pt_wrconfig[1];
1232 static struct rte_red pt_rtdata[1];
1233 static uint8_t pt_wq_log2[] = {9};
1234 static uint8_t pt_maxp_inv[] = {10};
1235 static uint32_t pt_qconfig[] = {0};
1236 static uint32_t pt_q[] = {0};
1237 static uint32_t pt_dropped[] = {0};
1238 static uint32_t pt_enqueued[] = {0};
1240 static struct test_rte_red_config pt_tconfig = {
1241 .rconfig = pt_wrconfig,
1242 .num_cfg = DIM(pt_wrconfig),
1243 .wq_log2 = pt_wq_log2,
1246 .maxp_inv = pt_maxp_inv,
1249 static struct test_queue pt_tqueue = {
1251 .num_queues = DIM(pt_rtdata),
1252 .qconfig = pt_qconfig,
1254 .q_ramp_up = 1000000,
1255 .avg_ramp_up = 1000000,
1256 .avg_tolerance = 5, /* 10 percent */
1257 .drop_tolerance = 50, /* 50 percent */
1261 * enqueue/dequeue packets
1263 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1264 struct rte_red *red,
1269 struct rdtsc_prof *prof)
1273 for (i = 0; i < num_ops; i++) {
1280 rdtsc_prof_start(prof);
1281 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1282 rdtsc_prof_end(prof);
1291 * Setup test structures for tests P1, P2, P3
1292 * performance tests 1, 2 and 3
1294 static uint32_t pt1_tlevel[] = {16};
1295 static uint32_t pt2_tlevel[] = {80};
1296 static uint32_t pt3_tlevel[] = {144};
1298 static struct test_var perf1_tvar = {
1300 .num_iterations = 15,
1301 .num_ops = 50000000,
1303 .dropped = pt_dropped,
1304 .enqueued = pt_enqueued,
1308 static struct test_config perf1_test1_config = {
1309 .ifname = "performance test 1 interface",
1310 .msg = "performance test 1 : use one RED configuration,\n"
1311 " set actual and average queue sizes to level below min threshold,\n"
1312 " measure enqueue performance\n\n",
1313 .tconfig = &pt_tconfig,
1314 .tqueue = &pt_tqueue,
1315 .tvar = &perf1_tvar,
1316 .tlevel = pt1_tlevel,
1319 static struct test_config perf1_test2_config = {
1320 .ifname = "performance test 2 interface",
1321 .msg = "performance test 2 : use one RED configuration,\n"
1322 " set actual and average queue sizes to level in between min and max thresholds,\n"
1323 " measure enqueue performance\n\n",
1324 .tconfig = &pt_tconfig,
1325 .tqueue = &pt_tqueue,
1326 .tvar = &perf1_tvar,
1327 .tlevel = pt2_tlevel,
1330 static struct test_config perf1_test3_config = {
1331 .ifname = "performance test 3 interface",
1332 .msg = "performance test 3 : use one RED configuration,\n"
1333 " set actual and average queue sizes to level above max threshold,\n"
1334 " measure enqueue performance\n\n",
1335 .tconfig = &pt_tconfig,
1336 .tqueue = &pt_tqueue,
1337 .tvar = &perf1_tvar,
1338 .tlevel = pt3_tlevel,
1342 * Performance test function to measure enqueue performance.
1343 * This runs performance tests 1, 2 and 3
1345 static enum test_result perf1_test(struct test_config *tcfg)
1347 enum test_result result = PASS;
1348 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1351 printf("%s", tcfg->msg);
1353 rdtsc_prof_init(&prof, "enqueue");
1355 if (test_rte_red_init(tcfg) != PASS) {
1361 * set average queue size to target level
1363 *tcfg->tqueue->q = *tcfg->tlevel;
1366 * initialize the rte_red run time data structure
1368 rte_red_rt_data_init(tcfg->tqueue->rdata);
1371 * set the queue average
1373 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1374 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1380 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1381 tcfg->tqueue->rdata,
1383 tcfg->tvar->num_ops,
1384 tcfg->tvar->enqueued,
1385 tcfg->tvar->dropped,
1388 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1390 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1391 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1392 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1394 rdtsc_prof_print(&prof);
1400 * Setup test structures for tests P4, P5, P6
1401 * performance tests 4, 5 and 6
1403 static uint32_t pt4_tlevel[] = {16};
1404 static uint32_t pt5_tlevel[] = {80};
1405 static uint32_t pt6_tlevel[] = {144};
1407 static struct test_var perf2_tvar = {
1409 .num_iterations = 10000,
1411 .dropped = pt_dropped,
1412 .enqueued = pt_enqueued,
1416 static struct test_config perf2_test4_config = {
1417 .ifname = "performance test 4 interface",
1418 .msg = "performance test 4 : use one RED configuration,\n"
1419 " set actual and average queue sizes to level below min threshold,\n"
1420 " dequeue all packets until queue is empty,\n"
1421 " measure enqueue performance when queue is empty\n\n",
1422 .htxt = "iteration "
1429 .tconfig = &pt_tconfig,
1430 .tqueue = &pt_tqueue,
1431 .tvar = &perf2_tvar,
1432 .tlevel = pt4_tlevel,
1435 static struct test_config perf2_test5_config = {
1436 .ifname = "performance test 5 interface",
1437 .msg = "performance test 5 : use one RED configuration,\n"
1438 " set actual and average queue sizes to level in between min and max thresholds,\n"
1439 " dequeue all packets until queue is empty,\n"
1440 " measure enqueue performance when queue is empty\n\n",
1441 .htxt = "iteration "
1448 .tconfig = &pt_tconfig,
1449 .tqueue = &pt_tqueue,
1450 .tvar = &perf2_tvar,
1451 .tlevel = pt5_tlevel,
1454 static struct test_config perf2_test6_config = {
1455 .ifname = "performance test 6 interface",
1456 .msg = "performance test 6 : use one RED configuration,\n"
1457 " set actual and average queue sizes to level above max threshold,\n"
1458 " dequeue all packets until queue is empty,\n"
1459 " measure enqueue performance when queue is empty\n\n",
1460 .htxt = "iteration "
1467 .tconfig = &pt_tconfig,
1468 .tqueue = &pt_tqueue,
1469 .tvar = &perf2_tvar,
1470 .tlevel = pt6_tlevel,
1474 * Performance test function to measure enqueue performance when the
1475 * queue is empty. This runs performance tests 4, 5 and 6
1477 static enum test_result perf2_test(struct test_config *tcfg)
1479 enum test_result result = PASS;
1480 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1484 printf("%s", tcfg->msg);
1486 rdtsc_prof_init(&prof, "enqueue");
1488 if (test_rte_red_init(tcfg) != PASS) {
1493 printf("%s", tcfg->htxt);
1495 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1498 double avg_before = 0;
1502 * set average queue size to target level
1504 *tcfg->tqueue->q = *tcfg->tlevel;
1505 count = (*tcfg->tqueue->rdata).count;
1508 * initialize the rte_red run time data structure
1510 rte_red_rt_data_init(tcfg->tqueue->rdata);
1511 (*tcfg->tqueue->rdata).count = count;
1514 * set the queue average
1516 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1517 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1518 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1526 *tcfg->tqueue->q = 0;
1527 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1530 * wait for specified period of time
1532 rte_delay_us(tcfg->tvar->wait_usec);
1535 * measure performance of enqueue operation while queue is empty
1538 rdtsc_prof_start(&prof);
1539 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1540 *tcfg->tqueue->q, ts );
1541 rdtsc_prof_end(&prof);
1544 * gather enqueued/dropped statistics
1547 (*tcfg->tvar->enqueued)++;
1549 (*tcfg->tvar->dropped)++;
1552 * on first and last iteration, confirm that
1553 * average queue size was computed correctly
1555 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1556 double avg_after = 0;
1561 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1562 exp_avg = calc_exp_avg_on_empty(avg_before,
1563 (1 << *tcfg->tconfig->wq_log2),
1564 tcfg->tvar->wait_usec);
1565 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1567 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1568 i, avg_before, avg_after, exp_avg, diff,
1569 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1576 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1577 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1578 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1579 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1581 rdtsc_prof_print(&prof);
1587 * setup default values for overflow test structures
1589 static uint32_t avg_max = 0;
1590 static uint32_t avg_max_bits = 0;
1592 static struct rte_red_config ovfl_wrconfig[1];
1593 static struct rte_red ovfl_rtdata[1];
1594 static uint8_t ovfl_maxp_inv[] = {10};
1595 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1596 static uint32_t ovfl_q[] ={0};
1597 static uint32_t ovfl_dropped[] ={0};
1598 static uint32_t ovfl_enqueued[] ={0};
1599 static uint32_t ovfl_tlevel[] = {1023};
1600 static uint8_t ovfl_wq_log2[] = {12};
1602 static struct test_rte_red_config ovfl_tconfig = {
1603 .rconfig = ovfl_wrconfig,
1604 .num_cfg = DIM(ovfl_wrconfig),
1605 .wq_log2 = ovfl_wq_log2,
1608 .maxp_inv = ovfl_maxp_inv,
1611 static struct test_queue ovfl_tqueue = {
1612 .rdata = ovfl_rtdata,
1613 .num_queues = DIM(ovfl_rtdata),
1614 .qconfig = ovfl_qconfig,
1616 .q_ramp_up = 1000000,
1617 .avg_ramp_up = 1000000,
1618 .avg_tolerance = 5, /* 10 percent */
1619 .drop_tolerance = 50, /* 50 percent */
1622 static struct test_var ovfl_tvar = {
1624 .num_iterations = 1,
1627 .dropped = ovfl_dropped,
1628 .enqueued = ovfl_enqueued,
1632 static void ovfl_check_avg(uint32_t avg)
1634 if (avg > avg_max) {
1638 avg_log = log(((double)avg_max));
1639 avg_log = avg_log / log(2.0);
1640 bits = (uint32_t)ceil(avg_log);
1641 if (bits > avg_max_bits)
1642 avg_max_bits = bits;
1646 static struct test_config ovfl_test1_config = {
1647 .ifname = "queue avergage overflow test interface",
1648 .msg = "overflow test 1 : use one RED configuration,\n"
1649 " increase average queue size to target level,\n"
1650 " check maximum number of bits requirte_red to represent avg_s\n\n",
1651 .htxt = "avg queue size "
1661 .tconfig = &ovfl_tconfig,
1662 .tqueue = &ovfl_tqueue,
1664 .tlevel = ovfl_tlevel,
1667 static enum test_result ovfl_test1(struct test_config *tcfg)
1669 enum test_result result = PASS;
1672 double drop_rate = 0.0;
1673 double drop_prob = 0.0;
1677 printf("%s", tcfg->msg);
1679 if (test_rte_red_init(tcfg) != PASS) {
1686 * reset rte_red run-time data
1688 rte_red_rt_data_init(tcfg->tqueue->rdata);
1691 * increase actual queue size
1693 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1694 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1695 *tcfg->tqueue->q, get_port_ts());
1698 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1706 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1707 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1708 *tcfg->tqueue->q, get_port_ts());
1709 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1710 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1711 if (avg == *tcfg->tlevel) {
1713 (*tcfg->tvar->enqueued)++;
1715 (*tcfg->tvar->dropped)++;
1720 * check if target average queue size has been reached
1722 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1723 if (avg != *tcfg->tlevel) {
1729 * check drop rate against drop probability
1731 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1732 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1733 tcfg->tconfig->max_th,
1734 *tcfg->tconfig->maxp_inv,
1736 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1739 printf("%s", tcfg->htxt);
1741 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1742 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1743 avg_max, avg_max_bits,
1744 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1745 drop_prob * 100.0, drop_rate * 100.0);
1751 * define the functional and performance tests to be executed
1753 struct tests func_tests[] = {
1754 { &func_test1_config, func_test1 },
1755 { &func_test2_config, func_test2 },
1756 { &func_test3_config, func_test3 },
1757 { &func_test4_config, func_test4 },
1758 { &func_test5_config, func_test5 },
1759 { &func_test6_config, func_test6 },
1760 { &ovfl_test1_config, ovfl_test1 },
1763 struct tests perf_tests[] = {
1764 { &perf1_test1_config, perf1_test },
1765 { &perf1_test2_config, perf1_test },
1766 { &perf1_test3_config, perf1_test },
1767 { &perf2_test4_config, perf2_test },
1768 { &perf2_test5_config, perf2_test },
1769 { &perf2_test6_config, perf2_test },
1773 * function to execute the required_red tests
1775 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1777 enum test_result result = PASS;
1780 for (i = 0; i < test_count; i++) {
1781 printf("\n--------------------------------------------------------------------------------\n");
1782 result = test_type[i].testfn(test_type[i].testcfg);
1784 if (result == PASS) {
1786 printf("-------------------------------------<pass>-------------------------------------\n");
1788 printf("-------------------------------------<fail>-------------------------------------\n");
1795 * check if functions accept invalid parameters
1797 * First, all functions will be called without initialized RED
1798 * Then, all of them will be called with NULL/invalid parameters
1800 * Some functions are not tested as they are performance-critical and thus
1801 * don't do any parameter checking.
1804 test_invalid_parameters(void)
1806 struct rte_red_config config;
1808 if (rte_red_rt_data_init(NULL) == 0) {
1809 printf("rte_red_rt_data_init should have failed!\n");
1813 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1814 printf("rte_red_config_init should have failed!\n");
1818 if (rte_red_rt_data_init(NULL) == 0) {
1819 printf("rte_red_rt_data_init should have failed!\n");
1824 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1825 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1828 /* min_treshold == max_treshold */
1829 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1830 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1833 /* min_treshold > max_treshold */
1834 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1835 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1838 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1839 if (rte_red_config_init(&config,
1840 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1841 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1844 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1845 if (rte_red_config_init(&config,
1846 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1847 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1850 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1851 if (rte_red_config_init(&config,
1852 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1853 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1856 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1857 if (rte_red_config_init(&config,
1858 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1859 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1868 uint32_t num_tests = 0;
1869 uint32_t num_pass = 0;
1872 if (test_invalid_parameters() < 0)
1875 run_tests(func_tests, DIM(func_tests), &num_tests, &num_pass);
1876 run_tests(perf_tests, DIM(perf_tests), &num_tests, &num_pass);
1878 if (num_pass == num_tests) {
1879 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1882 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1893 printf("The SCHED library is not included in this build\n");