4 * Copyright(c) 2010-2013 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)
153 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
154 p->clk_start = rte_rdtsc();
157 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
159 uint64_t clk_start = rte_rdtsc() - p->clk_start;
162 p->clk_avg += (double) clk_start;
164 if (clk_start > p->clk_max)
165 p->clk_max = clk_start;
166 if (clk_start < p->clk_min)
167 p->clk_min = clk_start;
170 static void rdtsc_prof_print(struct rdtsc_prof *p)
173 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
178 (p->clk_avg / ((double) p->clk_avgc)));
182 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
186 * scale by 1/n and convert from fixed-point to integer
188 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
191 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
195 * scale by 1/n and convert from fixed-point to floating-point
197 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
200 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
205 * scale by n and convert from integer to fixed-point
207 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
210 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
212 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
215 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
217 return (double)dropped / ((double)enqueued + (double)dropped);
221 * calculate the drop probability
223 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
224 uint32_t maxp_inv, uint32_t avg)
226 double drop_prob = 0.0;
230 } else if (avg < max_th) {
231 drop_prob = (1.0 / (double)maxp_inv)
232 * ((double)(avg - min_th)
233 / (double)(max_th - min_th));
241 * check if drop rate matches drop probability within tolerance
243 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
245 double abs_diff = 0.0;
248 abs_diff = fabs(drop_rate - drop_prob);
249 if ((int)abs_diff == 0) {
252 *diff = (abs_diff / drop_prob) * 100.0;
253 if (*diff > tolerance) {
261 * check if average queue size is within tolerance
263 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
265 double abs_diff = 0.0;
268 abs_diff = fabs(avg - exp_avg);
269 if ((int)abs_diff == 0) {
272 *diff = (abs_diff / exp_avg) * 100.0;
273 if (*diff > tolerance) {
281 * get the clk frequency in Hz
283 static uint64_t get_machclk_freq(void)
288 uint64_t clk_freq_hz = 0;
289 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
290 struct timespec req = {0, 0};
295 clock_gettime(CLOCK_REALTIME, &tv_start);
298 if (nanosleep(&req, NULL) != 0) {
299 perror("get_machclk_freq()");
303 clock_gettime(CLOCK_REALTIME, &tv_end);
306 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
307 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
308 USEC_PER_MSEC); /**< diff is in micro secs */
313 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
314 return (clk_freq_hz);
318 * initialize the test rte_red config
320 static enum test_result
321 test_rte_red_init(struct test_config *tcfg)
325 tcfg->tvar->clk_freq = get_machclk_freq();
326 init_port_ts( tcfg->tvar->clk_freq );
328 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
329 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
330 (uint16_t)tcfg->tconfig->wq_log2[i],
331 (uint16_t)tcfg->tconfig->min_th,
332 (uint16_t)tcfg->tconfig->max_th,
333 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
338 *tcfg->tqueue->q = 0;
339 *tcfg->tvar->dropped = 0;
340 *tcfg->tvar->enqueued = 0;
345 * enqueue until actual queue size reaches target level
348 increase_actual_qsize(struct rte_red_config *red_cfg,
356 for (i = 0; i < attempts; i++) {
362 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
369 * check if target actual queue size has been reached
380 * enqueue until average queue size reaches target level
383 increase_average_qsize(struct rte_red_config *red_cfg,
392 for (i = 0; i < num_ops; i++) {
396 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
399 * check if target average queue size has been reached
401 avg = rte_red_get_avg_int(red_cfg, red);
411 * setup default values for the functional test structures
413 static struct rte_red_config ft_wrconfig[1];
414 static struct rte_red ft_rtdata[1];
415 static uint8_t ft_wq_log2[] = {9};
416 static uint8_t ft_maxp_inv[] = {10};
417 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
418 static uint32_t ft_q[] ={0};
419 static uint32_t ft_dropped[] ={0};
420 static uint32_t ft_enqueued[] ={0};
422 static struct test_rte_red_config ft_tconfig = {
423 .rconfig = ft_wrconfig,
424 .num_cfg = DIM(ft_wrconfig),
425 .wq_log2 = ft_wq_log2,
428 .maxp_inv = ft_maxp_inv,
431 static struct test_queue ft_tqueue = {
433 .num_queues = DIM(ft_rtdata),
434 .qconfig = ft_qconfig,
436 .q_ramp_up = 1000000,
437 .avg_ramp_up = 1000000,
438 .avg_tolerance = 5, /* 5 percent */
439 .drop_tolerance = 50, /* 50 percent */
442 static struct test_var ft_tvar = {
444 .num_iterations = 20,
447 .dropped = ft_dropped,
448 .enqueued = ft_enqueued,
449 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
453 * functional test enqueue/dequeue packets
455 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
464 for (i = 0; i < num_ops; i++) {
470 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
479 * Test F1: functional test 1
481 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};
483 static struct test_config func_test1_config = {
484 .ifname = "functional test 1 interface",
485 .msg = "functional test 1 : use one rte_red configuration,\n"
486 " increase average queue size to various levels,\n"
487 " compare drop rate to drop probability\n\n",
497 .tconfig = &ft_tconfig,
498 .tqueue = &ft_tqueue,
500 .tlevel = ft1_tlevels,
503 static enum test_result func_test1(struct test_config *tcfg)
505 enum test_result result = PASS;
508 printf("%s", tcfg->msg);
510 if (test_rte_red_init(tcfg) != PASS) {
515 printf("%s", tcfg->htxt);
517 for (i = 0; i < DIM(ft1_tlevels); i++) {
518 const char *label = NULL;
520 double drop_rate = 0.0;
521 double drop_prob = 0.0;
525 * reset rte_red run-time data
527 rte_red_rt_data_init(tcfg->tqueue->rdata);
528 *tcfg->tvar->enqueued = 0;
529 *tcfg->tvar->dropped = 0;
531 if (increase_actual_qsize(tcfg->tconfig->rconfig,
535 tcfg->tqueue->q_ramp_up) != 0) {
540 if (increase_average_qsize(tcfg->tconfig->rconfig,
544 tcfg->tqueue->avg_ramp_up) != 0) {
549 enqueue_dequeue_func(tcfg->tconfig->rconfig,
553 tcfg->tvar->enqueued,
554 tcfg->tvar->dropped);
556 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
557 if (avg != tcfg->tlevel[i]) {
558 fprintf(stderr, "Fail: avg != level\n");
562 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
563 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
564 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
565 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
568 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
569 label = "min thresh: ";
570 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
571 label = "max thresh: ";
574 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
575 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
576 drop_prob * 100.0, drop_rate * 100.0, diff,
577 (double)tcfg->tqueue->drop_tolerance);
584 * Test F2: functional test 2
586 static uint32_t ft2_tlevel[] = {127};
587 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
588 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
589 static struct rte_red_config ft2_rconfig[10];
591 static struct test_rte_red_config ft2_tconfig = {
592 .rconfig = ft2_rconfig,
593 .num_cfg = DIM(ft2_rconfig),
594 .wq_log2 = ft2_wq_log2,
597 .maxp_inv = ft2_maxp_inv,
600 static struct test_config func_test2_config = {
601 .ifname = "functional test 2 interface",
602 .msg = "functional test 2 : use several RED configurations,\n"
603 " increase average queue size to just below maximum threshold,\n"
604 " compare drop rate to drop probability\n\n",
605 .htxt = "RED config "
614 .tconfig = &ft2_tconfig,
615 .tqueue = &ft_tqueue,
617 .tlevel = ft2_tlevel,
620 static enum test_result func_test2(struct test_config *tcfg)
622 enum test_result result = PASS;
623 double prev_drop_rate = 1.0;
626 printf("%s", tcfg->msg);
628 if (test_rte_red_init(tcfg) != PASS) {
632 rte_red_rt_data_init(tcfg->tqueue->rdata);
634 if (increase_actual_qsize(tcfg->tconfig->rconfig,
638 tcfg->tqueue->q_ramp_up) != 0) {
643 if (increase_average_qsize(tcfg->tconfig->rconfig,
647 tcfg->tqueue->avg_ramp_up) != 0) {
651 printf("%s", tcfg->htxt);
653 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
655 double drop_rate = 0.0;
656 double drop_prob = 0.0;
659 *tcfg->tvar->dropped = 0;
660 *tcfg->tvar->enqueued = 0;
662 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
666 tcfg->tvar->enqueued,
667 tcfg->tvar->dropped);
669 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
670 if (avg != *tcfg->tlevel)
673 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
674 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
675 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
676 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
679 * drop rate should decrease as maxp_inv increases
681 if (drop_rate > prev_drop_rate)
683 prev_drop_rate = drop_rate;
685 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
686 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
687 drop_prob * 100.0, drop_rate * 100.0, diff,
688 (double)tcfg->tqueue->drop_tolerance);
695 * Test F3: functional test 3
697 static uint32_t ft3_tlevel[] = {1022};
699 static struct test_rte_red_config ft3_tconfig = {
700 .rconfig = ft_wrconfig,
701 .num_cfg = DIM(ft_wrconfig),
702 .wq_log2 = ft_wq_log2,
705 .maxp_inv = ft_maxp_inv,
708 static struct test_config func_test3_config = {
709 .ifname = "functional test 3 interface",
710 .msg = "functional test 3 : use one RED configuration,\n"
711 " increase average queue size to target level,\n"
712 " dequeue all packets until queue is empty,\n"
713 " confirm that average queue size is computed correctly while queue is empty\n\n",
714 .htxt = "q avg before "
721 .tconfig = &ft3_tconfig,
722 .tqueue = &ft_tqueue,
724 .tlevel = ft3_tlevel,
727 static enum test_result func_test3(struct test_config *tcfg)
729 enum test_result result = PASS;
732 printf("%s", tcfg->msg);
734 if (test_rte_red_init(tcfg) != PASS) {
739 rte_red_rt_data_init(tcfg->tqueue->rdata);
741 if (increase_actual_qsize(tcfg->tconfig->rconfig,
745 tcfg->tqueue->q_ramp_up) != 0) {
750 if (increase_average_qsize(tcfg->tconfig->rconfig,
754 tcfg->tqueue->avg_ramp_up) != 0) {
759 printf("%s", tcfg->htxt);
761 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
762 double avg_before = 0;
763 double avg_after = 0;
767 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
772 *tcfg->tqueue->q = 0;
773 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
775 rte_delay_us(tcfg->tvar->wait_usec);
778 * enqueue one packet to recalculate average queue size
780 if (rte_red_enqueue(tcfg->tconfig->rconfig,
783 get_port_ts()) == 0) {
784 (*tcfg->tqueue->q)++;
786 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
790 exp_avg = calc_exp_avg_on_empty(avg_before,
791 (1 << *tcfg->tconfig->wq_log2),
792 tcfg->tvar->wait_usec);
793 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
794 tcfg->tqueue->rdata);
795 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
798 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
799 avg_before, avg_after, exp_avg, diff,
800 (double)tcfg->tqueue->avg_tolerance,
801 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
808 * Test F4: functional test 4
810 static uint32_t ft4_tlevel[] = {1022};
811 static uint8_t ft4_wq_log2[] = {11};
813 static struct test_rte_red_config ft4_tconfig = {
814 .rconfig = ft_wrconfig,
815 .num_cfg = DIM(ft_wrconfig),
818 .wq_log2 = ft4_wq_log2,
819 .maxp_inv = ft_maxp_inv,
822 static struct test_queue ft4_tqueue = {
824 .num_queues = DIM(ft_rtdata),
825 .qconfig = ft_qconfig,
827 .q_ramp_up = 1000000,
828 .avg_ramp_up = 1000000,
829 .avg_tolerance = 0, /* 0 percent */
830 .drop_tolerance = 50, /* 50 percent */
833 static struct test_config func_test4_config = {
834 .ifname = "functional test 4 interface",
835 .msg = "functional test 4 : use one RED configuration,\n"
836 " increase average queue size to target level,\n"
837 " dequeue all packets until queue is empty,\n"
838 " confirm that average queue size is computed correctly while\n"
839 " queue is empty for more than 50 sec,\n"
840 " (this test takes 52 sec to run)\n\n",
841 .htxt = "q avg before "
848 .tconfig = &ft4_tconfig,
849 .tqueue = &ft4_tqueue,
851 .tlevel = ft4_tlevel,
854 static enum test_result func_test4(struct test_config *tcfg)
856 enum test_result result = PASS;
857 uint64_t time_diff = 0;
859 double avg_before = 0.0;
860 double avg_after = 0.0;
861 double exp_avg = 0.0;
864 printf("%s", tcfg->msg);
866 if (test_rte_red_init(tcfg) != PASS) {
871 rte_red_rt_data_init(tcfg->tqueue->rdata);
873 if (increase_actual_qsize(tcfg->tconfig->rconfig,
877 tcfg->tqueue->q_ramp_up) != 0) {
882 if (increase_average_qsize(tcfg->tconfig->rconfig,
886 tcfg->tqueue->avg_ramp_up) != 0) {
891 printf("%s", tcfg->htxt);
893 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
898 *tcfg->tqueue->q = 0;
899 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
902 * record empty time locally
906 sleep(tcfg->tvar->sleep_sec);
909 * enqueue one packet to recalculate average queue size
911 if (rte_red_enqueue(tcfg->tconfig->rconfig,
914 get_port_ts()) != 0) {
918 (*tcfg->tqueue->q)++;
921 * calculate how long queue has been empty
923 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
925 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
927 * this could happen if sleep was interrupted for some reason
934 * confirm that average queue size is now at expected level
937 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
938 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
941 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
942 avg_before, avg_after, exp_avg,
943 diff, (double)tcfg->tqueue->avg_tolerance,
944 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
950 * Test F5: functional test 5
952 static uint32_t ft5_tlevel[] = {127};
953 static uint8_t ft5_wq_log2[] = {9, 8};
954 static uint8_t ft5_maxp_inv[] = {10, 20};
955 static struct rte_red_config ft5_config[2];
956 static struct rte_red ft5_data[4];
957 static uint32_t ft5_q[4];
958 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
959 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
961 static struct test_rte_red_config ft5_tconfig = {
962 .rconfig = ft5_config,
963 .num_cfg = DIM(ft5_config),
966 .wq_log2 = ft5_wq_log2,
967 .maxp_inv = ft5_maxp_inv,
970 static struct test_queue ft5_tqueue = {
972 .num_queues = DIM(ft5_data),
973 .qconfig = ft_qconfig,
975 .q_ramp_up = 1000000,
976 .avg_ramp_up = 1000000,
977 .avg_tolerance = 5, /* 10 percent */
978 .drop_tolerance = 50, /* 50 percent */
981 struct test_var ft5_tvar = {
983 .num_iterations = 15,
986 .dropped = ft5_dropped,
987 .enqueued = ft5_enqueued,
991 static struct test_config func_test5_config = {
992 .ifname = "functional test 5 interface",
993 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
994 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
995 " increase average queue size to just below maximum threshold,\n"
996 " compare drop rate to drop probability,\n"
997 " (this is a larger scale version of functional test 2)\n\n",
1008 .tconfig = &ft5_tconfig,
1009 .tqueue = &ft5_tqueue,
1011 .tlevel = ft5_tlevel,
1014 static enum test_result func_test5(struct test_config *tcfg)
1016 enum test_result result = PASS;
1019 printf("%s", tcfg->msg);
1021 if (test_rte_red_init(tcfg) != PASS) {
1026 printf("%s", tcfg->htxt);
1028 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1029 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1030 tcfg->tqueue->q[j] = 0;
1032 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1033 &tcfg->tqueue->rdata[j],
1034 &tcfg->tqueue->q[j],
1036 tcfg->tqueue->q_ramp_up) != 0) {
1041 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1042 &tcfg->tqueue->rdata[j],
1043 &tcfg->tqueue->q[j],
1045 tcfg->tqueue->avg_ramp_up) != 0) {
1051 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1053 double drop_rate = 0.0;
1054 double drop_prob = 0.0;
1057 tcfg->tvar->dropped[j] = 0;
1058 tcfg->tvar->enqueued[j] = 0;
1060 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1061 &tcfg->tqueue->rdata[j],
1062 &tcfg->tqueue->q[j],
1063 tcfg->tvar->num_ops,
1064 &tcfg->tvar->enqueued[j],
1065 &tcfg->tvar->dropped[j]);
1067 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1068 &tcfg->tqueue->rdata[j]);
1069 if (avg != *tcfg->tlevel)
1072 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1073 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1074 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1076 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1079 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1080 j, tcfg->tqueue->qconfig[j], avg,
1081 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1082 drop_prob * 100.0, drop_rate * 100.0,
1083 diff, (double)tcfg->tqueue->drop_tolerance);
1090 * Test F6: functional test 6
1092 static uint32_t ft6_tlevel[] = {1022};
1093 static uint8_t ft6_wq_log2[] = {9, 8};
1094 static uint8_t ft6_maxp_inv[] = {10, 20};
1095 static struct rte_red_config ft6_config[2];
1096 static struct rte_red ft6_data[4];
1097 static uint32_t ft6_q[4];
1099 static struct test_rte_red_config ft6_tconfig = {
1100 .rconfig = ft6_config,
1101 .num_cfg = DIM(ft6_config),
1104 .wq_log2 = ft6_wq_log2,
1105 .maxp_inv = ft6_maxp_inv,
1108 static struct test_queue ft6_tqueue = {
1110 .num_queues = DIM(ft6_data),
1111 .qconfig = ft_qconfig,
1113 .q_ramp_up = 1000000,
1114 .avg_ramp_up = 1000000,
1115 .avg_tolerance = 5, /* 10 percent */
1116 .drop_tolerance = 50, /* 50 percent */
1119 static struct test_config func_test6_config = {
1120 .ifname = "functional test 6 interface",
1121 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1122 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1123 " increase average queue size to target level,\n"
1124 " dequeue all packets until queue is empty,\n"
1125 " confirm that average queue size is computed correctly while queue is empty\n"
1126 " (this is a larger scale version of functional test 3)\n\n",
1135 .tconfig = &ft6_tconfig,
1136 .tqueue = &ft6_tqueue,
1138 .tlevel = ft6_tlevel,
1141 static enum test_result func_test6(struct test_config *tcfg)
1143 enum test_result result = PASS;
1146 printf("%s", tcfg->msg);
1147 if (test_rte_red_init(tcfg) != PASS) {
1151 printf("%s", tcfg->htxt);
1153 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1154 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1155 tcfg->tqueue->q[j] = 0;
1157 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1158 &tcfg->tqueue->rdata[j],
1159 &tcfg->tqueue->q[j],
1161 tcfg->tqueue->q_ramp_up) != 0) {
1165 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1166 &tcfg->tqueue->rdata[j],
1167 &tcfg->tqueue->q[j],
1169 tcfg->tqueue->avg_ramp_up) != 0) {
1174 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1175 double avg_before = 0;
1176 double avg_after = 0;
1180 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1181 &tcfg->tqueue->rdata[j]);
1186 tcfg->tqueue->q[j] = 0;
1187 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1188 rte_delay_us(tcfg->tvar->wait_usec);
1191 * enqueue one packet to recalculate average queue size
1193 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1194 &tcfg->tqueue->rdata[j],
1196 get_port_ts()) == 0) {
1197 tcfg->tqueue->q[j]++;
1199 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1203 exp_avg = calc_exp_avg_on_empty(avg_before,
1204 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1205 tcfg->tvar->wait_usec);
1206 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1207 &tcfg->tqueue->rdata[j]);
1208 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1211 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1212 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1213 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1214 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1221 * setup default values for the performance test structures
1223 static struct rte_red_config pt_wrconfig[1];
1224 static struct rte_red pt_rtdata[1];
1225 static uint8_t pt_wq_log2[] = {9};
1226 static uint8_t pt_maxp_inv[] = {10};
1227 static uint32_t pt_qconfig[] = {0};
1228 static uint32_t pt_q[] = {0};
1229 static uint32_t pt_dropped[] = {0};
1230 static uint32_t pt_enqueued[] = {0};
1232 static struct test_rte_red_config pt_tconfig = {
1233 .rconfig = pt_wrconfig,
1234 .num_cfg = DIM(pt_wrconfig),
1235 .wq_log2 = pt_wq_log2,
1238 .maxp_inv = pt_maxp_inv,
1241 static struct test_queue pt_tqueue = {
1243 .num_queues = DIM(pt_rtdata),
1244 .qconfig = pt_qconfig,
1246 .q_ramp_up = 1000000,
1247 .avg_ramp_up = 1000000,
1248 .avg_tolerance = 5, /* 10 percent */
1249 .drop_tolerance = 50, /* 50 percent */
1253 * enqueue/dequeue packets
1255 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1256 struct rte_red *red,
1261 struct rdtsc_prof *prof)
1265 for (i = 0; i < num_ops; i++) {
1272 rdtsc_prof_start(prof);
1273 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1274 rdtsc_prof_end(prof);
1283 * Setup test structures for tests P1, P2, P3
1284 * performance tests 1, 2 and 3
1286 static uint32_t pt1_tlevel[] = {16};
1287 static uint32_t pt2_tlevel[] = {80};
1288 static uint32_t pt3_tlevel[] = {144};
1290 static struct test_var perf1_tvar = {
1292 .num_iterations = 15,
1293 .num_ops = 50000000,
1295 .dropped = pt_dropped,
1296 .enqueued = pt_enqueued,
1300 static struct test_config perf1_test1_config = {
1301 .ifname = "performance test 1 interface",
1302 .msg = "performance test 1 : use one RED configuration,\n"
1303 " set actual and average queue sizes to level below min threshold,\n"
1304 " measure enqueue performance\n\n",
1305 .tconfig = &pt_tconfig,
1306 .tqueue = &pt_tqueue,
1307 .tvar = &perf1_tvar,
1308 .tlevel = pt1_tlevel,
1311 static struct test_config perf1_test2_config = {
1312 .ifname = "performance test 2 interface",
1313 .msg = "performance test 2 : use one RED configuration,\n"
1314 " set actual and average queue sizes to level in between min and max thresholds,\n"
1315 " measure enqueue performance\n\n",
1316 .tconfig = &pt_tconfig,
1317 .tqueue = &pt_tqueue,
1318 .tvar = &perf1_tvar,
1319 .tlevel = pt2_tlevel,
1322 static struct test_config perf1_test3_config = {
1323 .ifname = "performance test 3 interface",
1324 .msg = "performance test 3 : use one RED configuration,\n"
1325 " set actual and average queue sizes to level above max threshold,\n"
1326 " measure enqueue performance\n\n",
1327 .tconfig = &pt_tconfig,
1328 .tqueue = &pt_tqueue,
1329 .tvar = &perf1_tvar,
1330 .tlevel = pt3_tlevel,
1334 * Performance test function to measure enqueue performance.
1335 * This runs performance tests 1, 2 and 3
1337 static enum test_result perf1_test(struct test_config *tcfg)
1339 enum test_result result = PASS;
1340 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1343 printf("%s", tcfg->msg);
1345 rdtsc_prof_init(&prof, "enqueue");
1347 if (test_rte_red_init(tcfg) != PASS) {
1353 * set average queue size to target level
1355 *tcfg->tqueue->q = *tcfg->tlevel;
1358 * initialize the rte_red run time data structure
1360 rte_red_rt_data_init(tcfg->tqueue->rdata);
1363 * set the queue average
1365 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1366 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1372 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1373 tcfg->tqueue->rdata,
1375 tcfg->tvar->num_ops,
1376 tcfg->tvar->enqueued,
1377 tcfg->tvar->dropped,
1380 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1382 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1383 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1384 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1386 rdtsc_prof_print(&prof);
1392 * Setup test structures for tests P4, P5, P6
1393 * performance tests 4, 5 and 6
1395 static uint32_t pt4_tlevel[] = {16};
1396 static uint32_t pt5_tlevel[] = {80};
1397 static uint32_t pt6_tlevel[] = {144};
1399 static struct test_var perf2_tvar = {
1401 .num_iterations = 10000,
1403 .dropped = pt_dropped,
1404 .enqueued = pt_enqueued,
1408 static struct test_config perf2_test4_config = {
1409 .ifname = "performance test 4 interface",
1410 .msg = "performance test 4 : use one RED configuration,\n"
1411 " set actual and average queue sizes to level below min threshold,\n"
1412 " dequeue all packets until queue is empty,\n"
1413 " measure enqueue performance when queue is empty\n\n",
1414 .htxt = "iteration "
1421 .tconfig = &pt_tconfig,
1422 .tqueue = &pt_tqueue,
1423 .tvar = &perf2_tvar,
1424 .tlevel = pt4_tlevel,
1427 static struct test_config perf2_test5_config = {
1428 .ifname = "performance test 5 interface",
1429 .msg = "performance test 5 : use one RED configuration,\n"
1430 " set actual and average queue sizes to level in between min and max thresholds,\n"
1431 " dequeue all packets until queue is empty,\n"
1432 " measure enqueue performance when queue is empty\n\n",
1433 .htxt = "iteration "
1440 .tconfig = &pt_tconfig,
1441 .tqueue = &pt_tqueue,
1442 .tvar = &perf2_tvar,
1443 .tlevel = pt5_tlevel,
1446 static struct test_config perf2_test6_config = {
1447 .ifname = "performance test 6 interface",
1448 .msg = "performance test 6 : use one RED configuration,\n"
1449 " set actual and average queue sizes to level above max threshold,\n"
1450 " dequeue all packets until queue is empty,\n"
1451 " measure enqueue performance when queue is empty\n\n",
1452 .htxt = "iteration "
1459 .tconfig = &pt_tconfig,
1460 .tqueue = &pt_tqueue,
1461 .tvar = &perf2_tvar,
1462 .tlevel = pt6_tlevel,
1466 * Performance test function to measure enqueue performance when the
1467 * queue is empty. This runs performance tests 4, 5 and 6
1469 static enum test_result perf2_test(struct test_config *tcfg)
1471 enum test_result result = PASS;
1472 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1476 printf("%s", tcfg->msg);
1478 rdtsc_prof_init(&prof, "enqueue");
1480 if (test_rte_red_init(tcfg) != PASS) {
1485 printf("%s", tcfg->htxt);
1487 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1490 double avg_before = 0;
1494 * set average queue size to target level
1496 *tcfg->tqueue->q = *tcfg->tlevel;
1497 count = (*tcfg->tqueue->rdata).count;
1500 * initialize the rte_red run time data structure
1502 rte_red_rt_data_init(tcfg->tqueue->rdata);
1503 (*tcfg->tqueue->rdata).count = count;
1506 * set the queue average
1508 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1509 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1510 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1518 *tcfg->tqueue->q = 0;
1519 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1522 * wait for specified period of time
1524 rte_delay_us(tcfg->tvar->wait_usec);
1527 * measure performance of enqueue operation while queue is empty
1530 rdtsc_prof_start(&prof);
1531 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1532 *tcfg->tqueue->q, ts );
1533 rdtsc_prof_end(&prof);
1536 * gather enqueued/dropped statistics
1539 (*tcfg->tvar->enqueued)++;
1541 (*tcfg->tvar->dropped)++;
1544 * on first and last iteration, confirm that
1545 * average queue size was computed correctly
1547 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1548 double avg_after = 0;
1553 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1554 exp_avg = calc_exp_avg_on_empty(avg_before,
1555 (1 << *tcfg->tconfig->wq_log2),
1556 tcfg->tvar->wait_usec);
1557 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1559 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1560 i, avg_before, avg_after, exp_avg, diff,
1561 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1568 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1569 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1570 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1571 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1573 rdtsc_prof_print(&prof);
1579 * setup default values for overflow test structures
1581 static uint32_t avg_max = 0;
1582 static uint32_t avg_max_bits = 0;
1584 static struct rte_red_config ovfl_wrconfig[1];
1585 static struct rte_red ovfl_rtdata[1];
1586 static uint8_t ovfl_maxp_inv[] = {10};
1587 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1588 static uint32_t ovfl_q[] ={0};
1589 static uint32_t ovfl_dropped[] ={0};
1590 static uint32_t ovfl_enqueued[] ={0};
1591 static uint32_t ovfl_tlevel[] = {1023};
1592 static uint8_t ovfl_wq_log2[] = {12};
1594 static struct test_rte_red_config ovfl_tconfig = {
1595 .rconfig = ovfl_wrconfig,
1596 .num_cfg = DIM(ovfl_wrconfig),
1597 .wq_log2 = ovfl_wq_log2,
1600 .maxp_inv = ovfl_maxp_inv,
1603 static struct test_queue ovfl_tqueue = {
1604 .rdata = ovfl_rtdata,
1605 .num_queues = DIM(ovfl_rtdata),
1606 .qconfig = ovfl_qconfig,
1608 .q_ramp_up = 1000000,
1609 .avg_ramp_up = 1000000,
1610 .avg_tolerance = 5, /* 10 percent */
1611 .drop_tolerance = 50, /* 50 percent */
1614 static struct test_var ovfl_tvar = {
1616 .num_iterations = 1,
1619 .dropped = ovfl_dropped,
1620 .enqueued = ovfl_enqueued,
1624 static void ovfl_check_avg(uint32_t avg)
1626 if (avg > avg_max) {
1630 avg_log = log(((double)avg_max));
1631 avg_log = avg_log / log(2.0);
1632 bits = (uint32_t)ceil(avg_log);
1633 if (bits > avg_max_bits)
1634 avg_max_bits = bits;
1638 static struct test_config ovfl_test1_config = {
1639 .ifname = "queue avergage overflow test interface",
1640 .msg = "overflow test 1 : use one RED configuration,\n"
1641 " increase average queue size to target level,\n"
1642 " check maximum number of bits requirte_red to represent avg_s\n\n",
1643 .htxt = "avg queue size "
1653 .tconfig = &ovfl_tconfig,
1654 .tqueue = &ovfl_tqueue,
1656 .tlevel = ovfl_tlevel,
1659 static enum test_result ovfl_test1(struct test_config *tcfg)
1661 enum test_result result = PASS;
1664 double drop_rate = 0.0;
1665 double drop_prob = 0.0;
1669 printf("%s", tcfg->msg);
1671 if (test_rte_red_init(tcfg) != PASS) {
1678 * reset rte_red run-time data
1680 rte_red_rt_data_init(tcfg->tqueue->rdata);
1683 * increase actual queue size
1685 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1686 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1687 *tcfg->tqueue->q, get_port_ts());
1690 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1698 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1699 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1700 *tcfg->tqueue->q, get_port_ts());
1701 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1702 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1703 if (avg == *tcfg->tlevel) {
1705 (*tcfg->tvar->enqueued)++;
1707 (*tcfg->tvar->dropped)++;
1712 * check if target average queue size has been reached
1714 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1715 if (avg != *tcfg->tlevel) {
1721 * check drop rate against drop probability
1723 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1724 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1725 tcfg->tconfig->max_th,
1726 *tcfg->tconfig->maxp_inv,
1728 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1731 printf("%s", tcfg->htxt);
1733 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1734 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1735 avg_max, avg_max_bits,
1736 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1737 drop_prob * 100.0, drop_rate * 100.0);
1743 * define the functional and performance tests to be executed
1745 struct tests func_tests[] = {
1746 { &func_test1_config, func_test1 },
1747 { &func_test2_config, func_test2 },
1748 { &func_test3_config, func_test3 },
1749 { &func_test4_config, func_test4 },
1750 { &func_test5_config, func_test5 },
1751 { &func_test6_config, func_test6 },
1752 { &ovfl_test1_config, ovfl_test1 },
1755 struct tests perf_tests[] = {
1756 { &perf1_test1_config, perf1_test },
1757 { &perf1_test2_config, perf1_test },
1758 { &perf1_test3_config, perf1_test },
1759 { &perf2_test4_config, perf2_test },
1760 { &perf2_test5_config, perf2_test },
1761 { &perf2_test6_config, perf2_test },
1765 * function to execute the required_red tests
1767 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1769 enum test_result result = PASS;
1772 for (i = 0; i < test_count; i++) {
1773 printf("\n--------------------------------------------------------------------------------\n");
1774 result = test_type[i].testfn(test_type[i].testcfg);
1776 if (result == PASS) {
1778 printf("-------------------------------------<pass>-------------------------------------\n");
1780 printf("-------------------------------------<fail>-------------------------------------\n");
1787 * check if functions accept invalid parameters
1789 * First, all functions will be called without initialized RED
1790 * Then, all of them will be called with NULL/invalid parameters
1792 * Some functions are not tested as they are performance-critical and thus
1793 * don't do any parameter checking.
1796 test_invalid_parameters(void)
1798 struct rte_red_config config;
1800 if (rte_red_rt_data_init(NULL) == 0) {
1801 printf("rte_red_rt_data_init should have failed!\n");
1805 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1806 printf("rte_red_config_init should have failed!\n");
1810 if (rte_red_rt_data_init(NULL) == 0) {
1811 printf("rte_red_rt_data_init should have failed!\n");
1816 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1817 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1820 /* min_treshold == max_treshold */
1821 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1822 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1825 /* min_treshold > max_treshold */
1826 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1827 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1830 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1831 if (rte_red_config_init(&config,
1832 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1833 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1836 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1837 if (rte_red_config_init(&config,
1838 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1839 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1842 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1843 if (rte_red_config_init(&config,
1844 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1845 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1848 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1849 if (rte_red_config_init(&config,
1850 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1851 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1860 uint32_t num_tests = 0;
1861 uint32_t num_pass = 0;
1864 if (test_invalid_parameters() < 0)
1867 run_tests(func_tests, DIM(func_tests), &num_tests, &num_pass);
1868 run_tests(perf_tests, DIM(perf_tests), &num_tests, &num_pass);
1870 if (num_pass == num_tests) {
1871 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1874 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1885 printf("The SCHED library is not included in this build\n");