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.
44 #include <cmdline_parse.h>
48 #ifdef RTE_LIBRTE_SCHED
52 #ifdef __INTEL_COMPILER
53 #pragma warning(disable:2259) /* conversion may lose significant bits */
54 #pragma warning(disable:181) /* Arg incompatible with format string */
57 #define DIM(x) (sizeof(x)/sizeof(x[0]))
58 #define TEST_HZ_PER_KHZ 1000
59 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
61 #define MAX_QEMPTY_TIME_MSEC 50000
62 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
63 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
64 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
66 /**< structures for testing rte_red performance and function */
67 struct test_rte_red_config { /**< Test structure for RTE_RED config */
68 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
69 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
70 uint8_t *wq_log2; /**< Test wq_log2 value to use */
71 uint32_t min_th; /**< Queue minimum threshold */
72 uint32_t max_th; /**< Queue maximum threshold */
73 uint8_t *maxp_inv; /**< Inverse mark probability */
76 struct test_queue { /**< Test structure for RTE_RED Queues */
77 struct rte_red *rdata; /**< RTE_RED runtime data */
78 uint32_t num_queues; /**< Number of RTE_RED queues to test */
79 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
80 uint32_t *q; /**< Queue size */
81 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
82 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
83 uint32_t avg_tolerance; /**< Tolerance in queue average */
84 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
87 struct test_var { /**< Test variables used for testing RTE_RED */
88 uint32_t wait_usec; /**< Micro second wait interval */
89 uint32_t num_iterations; /**< Number of test iterations */
90 uint32_t num_ops; /**< Number of test operations */
91 uint64_t clk_freq; /**< CPU clock frequency */
92 uint32_t sleep_sec; /**< Seconds to sleep */
93 uint32_t *dropped; /**< Test operations dropped */
94 uint32_t *enqueued; /**< Test operations enqueued */
97 struct test_config { /**< Master test structure for RTE_RED */
98 const char *ifname; /**< Interface name */
99 const char *msg; /**< Test message for display */
100 const char *htxt; /**< Header txt display for result output */
101 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
102 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
103 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
104 uint32_t *tlevel; /**< Queue levels */
112 /**< Test structure to define tests to run */
114 struct test_config *testcfg;
115 enum test_result (*testfn)(struct test_config *);
120 uint64_t clk_min; /**< min clocks */
121 uint64_t clk_max; /**< max clocks */
122 uint64_t clk_avgc; /**< count to calc average */
123 double clk_avg; /**< cumulative sum to calc average */
127 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
128 static double inv_cycles_per_byte = 0;
129 static double pkt_time_usec = 0;
131 static void init_port_ts(uint64_t cpu_clock)
133 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
134 inv_cycles_per_byte = 1.0 / cycles_per_byte;
135 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
138 static uint64_t get_port_ts(void)
140 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
143 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
145 p->clk_min = (uint64_t)(-1LL);
152 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
154 asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" );
155 p->clk_start = rte_rdtsc();
158 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
160 uint64_t clk_start = rte_rdtsc() - p->clk_start;
163 p->clk_avg += (double) clk_start;
165 if (clk_start > p->clk_max)
166 p->clk_max = clk_start;
167 if (clk_start < p->clk_min)
168 p->clk_min = clk_start;
171 static void rdtsc_prof_print(struct rdtsc_prof *p)
174 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
179 (p->clk_avg / ((double) p->clk_avgc)));
183 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
187 * scale by 1/n and convert from fixed-point to integer
189 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
192 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
196 * scale by 1/n and convert from fixed-point to floating-point
198 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
201 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
206 * scale by n and convert from integer to fixed-point
208 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
211 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
213 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
216 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
218 return (double)dropped / ((double)enqueued + (double)dropped);
222 * calculate the drop probability
224 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
225 uint32_t maxp_inv, uint32_t avg)
227 double drop_prob = 0.0;
231 } else if (avg < max_th) {
232 drop_prob = (1.0 / (double)maxp_inv)
233 * ((double)(avg - min_th)
234 / (double)(max_th - min_th));
242 * check if drop rate matches drop probability within tolerance
244 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
246 double abs_diff = 0.0;
249 abs_diff = fabs(drop_rate - drop_prob);
250 if ((int)abs_diff == 0) {
253 *diff = (abs_diff / drop_prob) * 100.0;
254 if (*diff > tolerance) {
262 * check if average queue size is within tolerance
264 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
266 double abs_diff = 0.0;
269 abs_diff = fabs(avg - exp_avg);
270 if ((int)abs_diff == 0) {
273 *diff = (abs_diff / exp_avg) * 100.0;
274 if (*diff > tolerance) {
282 * get the clk frequency in Hz
284 static uint64_t get_machclk_freq(void)
289 uint64_t clk_freq_hz = 0;
290 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
291 struct timespec req = {0, 0};
296 clock_gettime(CLOCK_REALTIME, &tv_start);
299 if (nanosleep(&req, NULL) != 0) {
300 perror("get_machclk_freq()");
304 clock_gettime(CLOCK_REALTIME, &tv_end);
307 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
308 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
309 USEC_PER_MSEC); /**< diff is in micro secs */
314 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
315 return (clk_freq_hz);
319 * initialize the test rte_red config
321 static enum test_result
322 test_rte_red_init(struct test_config *tcfg)
326 tcfg->tvar->clk_freq = get_machclk_freq();
327 init_port_ts( tcfg->tvar->clk_freq );
329 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
330 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
331 (uint16_t)tcfg->tconfig->wq_log2[i],
332 (uint16_t)tcfg->tconfig->min_th,
333 (uint16_t)tcfg->tconfig->max_th,
334 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
339 *tcfg->tqueue->q = 0;
340 *tcfg->tvar->dropped = 0;
341 *tcfg->tvar->enqueued = 0;
346 * enqueue until actual queue size reaches target level
349 increase_actual_qsize(struct rte_red_config *red_cfg,
357 for (i = 0; i < attempts; i++) {
363 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
370 * check if target actual queue size has been reached
381 * enqueue until average queue size reaches target level
384 increase_average_qsize(struct rte_red_config *red_cfg,
393 for (i = 0; i < num_ops; i++) {
397 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
400 * check if target average queue size has been reached
402 avg = rte_red_get_avg_int(red_cfg, red);
412 * setup default values for the functional test structures
414 static struct rte_red_config ft_wrconfig[1];
415 static struct rte_red ft_rtdata[1];
416 static uint8_t ft_wq_log2[] = {9};
417 static uint8_t ft_maxp_inv[] = {10};
418 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
419 static uint32_t ft_q[] ={0};
420 static uint32_t ft_dropped[] ={0};
421 static uint32_t ft_enqueued[] ={0};
423 static struct test_rte_red_config ft_tconfig = {
424 .rconfig = ft_wrconfig,
425 .num_cfg = DIM(ft_wrconfig),
426 .wq_log2 = ft_wq_log2,
429 .maxp_inv = ft_maxp_inv,
432 static struct test_queue ft_tqueue = {
434 .num_queues = DIM(ft_rtdata),
435 .qconfig = ft_qconfig,
437 .q_ramp_up = 1000000,
438 .avg_ramp_up = 1000000,
439 .avg_tolerance = 5, /* 5 percent */
440 .drop_tolerance = 50, /* 50 percent */
443 static struct test_var ft_tvar = {
445 .num_iterations = 20,
448 .dropped = ft_dropped,
449 .enqueued = ft_enqueued,
450 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
454 * functional test enqueue/dequeue packets
456 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
465 for (i = 0; i < num_ops; i++) {
471 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
480 * Test F1: functional test 1
482 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};
484 static struct test_config func_test1_config = {
485 .ifname = "functional test 1 interface",
486 .msg = "functional test 1 : use one rte_red configuration,\n"
487 " increase average queue size to various levels,\n"
488 " compare drop rate to drop probability\n\n",
498 .tconfig = &ft_tconfig,
499 .tqueue = &ft_tqueue,
501 .tlevel = ft1_tlevels,
504 static enum test_result func_test1(struct test_config *tcfg)
506 enum test_result result = PASS;
509 printf("%s", tcfg->msg);
511 if (test_rte_red_init(tcfg) != PASS) {
516 printf("%s", tcfg->htxt);
518 for (i = 0; i < DIM(ft1_tlevels); i++) {
519 const char *label = NULL;
521 double drop_rate = 0.0;
522 double drop_prob = 0.0;
526 * reset rte_red run-time data
528 rte_red_rt_data_init(tcfg->tqueue->rdata);
529 *tcfg->tvar->enqueued = 0;
530 *tcfg->tvar->dropped = 0;
532 if (increase_actual_qsize(tcfg->tconfig->rconfig,
536 tcfg->tqueue->q_ramp_up) != 0) {
541 if (increase_average_qsize(tcfg->tconfig->rconfig,
545 tcfg->tqueue->avg_ramp_up) != 0) {
550 enqueue_dequeue_func(tcfg->tconfig->rconfig,
554 tcfg->tvar->enqueued,
555 tcfg->tvar->dropped);
557 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
558 if (avg != tcfg->tlevel[i]) {
559 fprintf(stderr, "Fail: avg != level\n");
563 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
564 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
565 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
566 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
569 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
570 label = "min thresh: ";
571 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
572 label = "max thresh: ";
575 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
576 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
577 drop_prob * 100.0, drop_rate * 100.0, diff,
578 (double)tcfg->tqueue->drop_tolerance);
585 * Test F2: functional test 2
587 static uint32_t ft2_tlevel[] = {127};
588 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
589 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
590 static struct rte_red_config ft2_rconfig[10];
592 static struct test_rte_red_config ft2_tconfig = {
593 .rconfig = ft2_rconfig,
594 .num_cfg = DIM(ft2_rconfig),
595 .wq_log2 = ft2_wq_log2,
598 .maxp_inv = ft2_maxp_inv,
601 static struct test_config func_test2_config = {
602 .ifname = "functional test 2 interface",
603 .msg = "functional test 2 : use several RED configurations,\n"
604 " increase average queue size to just below maximum threshold,\n"
605 " compare drop rate to drop probability\n\n",
606 .htxt = "RED config "
615 .tconfig = &ft2_tconfig,
616 .tqueue = &ft_tqueue,
618 .tlevel = ft2_tlevel,
621 static enum test_result func_test2(struct test_config *tcfg)
623 enum test_result result = PASS;
624 double prev_drop_rate = 1.0;
627 printf("%s", tcfg->msg);
629 if (test_rte_red_init(tcfg) != PASS) {
633 rte_red_rt_data_init(tcfg->tqueue->rdata);
635 if (increase_actual_qsize(tcfg->tconfig->rconfig,
639 tcfg->tqueue->q_ramp_up) != 0) {
644 if (increase_average_qsize(tcfg->tconfig->rconfig,
648 tcfg->tqueue->avg_ramp_up) != 0) {
652 printf("%s", tcfg->htxt);
654 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
656 double drop_rate = 0.0;
657 double drop_prob = 0.0;
660 *tcfg->tvar->dropped = 0;
661 *tcfg->tvar->enqueued = 0;
663 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
667 tcfg->tvar->enqueued,
668 tcfg->tvar->dropped);
670 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
671 if (avg != *tcfg->tlevel)
674 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
675 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
676 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
677 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
680 * drop rate should decrease as maxp_inv increases
682 if (drop_rate > prev_drop_rate)
684 prev_drop_rate = drop_rate;
686 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
687 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
688 drop_prob * 100.0, drop_rate * 100.0, diff,
689 (double)tcfg->tqueue->drop_tolerance);
696 * Test F3: functional test 3
698 static uint32_t ft3_tlevel[] = {1022};
700 static struct test_rte_red_config ft3_tconfig = {
701 .rconfig = ft_wrconfig,
702 .num_cfg = DIM(ft_wrconfig),
703 .wq_log2 = ft_wq_log2,
706 .maxp_inv = ft_maxp_inv,
709 static struct test_config func_test3_config = {
710 .ifname = "functional test 3 interface",
711 .msg = "functional test 3 : use one RED configuration,\n"
712 " increase average queue size to target level,\n"
713 " dequeue all packets until queue is empty,\n"
714 " confirm that average queue size is computed correctly while queue is empty\n\n",
715 .htxt = "q avg before "
722 .tconfig = &ft3_tconfig,
723 .tqueue = &ft_tqueue,
725 .tlevel = ft3_tlevel,
728 static enum test_result func_test3(struct test_config *tcfg)
730 enum test_result result = PASS;
733 printf("%s", tcfg->msg);
735 if (test_rte_red_init(tcfg) != PASS) {
740 rte_red_rt_data_init(tcfg->tqueue->rdata);
742 if (increase_actual_qsize(tcfg->tconfig->rconfig,
746 tcfg->tqueue->q_ramp_up) != 0) {
751 if (increase_average_qsize(tcfg->tconfig->rconfig,
755 tcfg->tqueue->avg_ramp_up) != 0) {
760 printf("%s", tcfg->htxt);
762 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
763 double avg_before = 0;
764 double avg_after = 0;
768 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
773 *tcfg->tqueue->q = 0;
774 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
776 rte_delay_us(tcfg->tvar->wait_usec);
779 * enqueue one packet to recalculate average queue size
781 if (rte_red_enqueue(tcfg->tconfig->rconfig,
784 get_port_ts()) == 0) {
785 (*tcfg->tqueue->q)++;
787 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
791 exp_avg = calc_exp_avg_on_empty(avg_before,
792 (1 << *tcfg->tconfig->wq_log2),
793 tcfg->tvar->wait_usec);
794 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
795 tcfg->tqueue->rdata);
796 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
799 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
800 avg_before, avg_after, exp_avg, diff,
801 (double)tcfg->tqueue->avg_tolerance,
802 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
809 * Test F4: functional test 4
811 static uint32_t ft4_tlevel[] = {1022};
812 static uint8_t ft4_wq_log2[] = {11};
814 static struct test_rte_red_config ft4_tconfig = {
815 .rconfig = ft_wrconfig,
816 .num_cfg = DIM(ft_wrconfig),
819 .wq_log2 = ft4_wq_log2,
820 .maxp_inv = ft_maxp_inv,
823 static struct test_queue ft4_tqueue = {
825 .num_queues = DIM(ft_rtdata),
826 .qconfig = ft_qconfig,
828 .q_ramp_up = 1000000,
829 .avg_ramp_up = 1000000,
830 .avg_tolerance = 0, /* 0 percent */
831 .drop_tolerance = 50, /* 50 percent */
834 static struct test_config func_test4_config = {
835 .ifname = "functional test 4 interface",
836 .msg = "functional test 4 : use one RED configuration,\n"
837 " increase average queue size to target level,\n"
838 " dequeue all packets until queue is empty,\n"
839 " confirm that average queue size is computed correctly while\n"
840 " queue is empty for more than 50 sec,\n"
841 " (this test takes 52 sec to run)\n\n",
842 .htxt = "q avg before "
849 .tconfig = &ft4_tconfig,
850 .tqueue = &ft4_tqueue,
852 .tlevel = ft4_tlevel,
855 static enum test_result func_test4(struct test_config *tcfg)
857 enum test_result result = PASS;
858 uint64_t time_diff = 0;
860 double avg_before = 0.0;
861 double avg_after = 0.0;
862 double exp_avg = 0.0;
865 printf("%s", tcfg->msg);
867 if (test_rte_red_init(tcfg) != PASS) {
872 rte_red_rt_data_init(tcfg->tqueue->rdata);
874 if (increase_actual_qsize(tcfg->tconfig->rconfig,
878 tcfg->tqueue->q_ramp_up) != 0) {
883 if (increase_average_qsize(tcfg->tconfig->rconfig,
887 tcfg->tqueue->avg_ramp_up) != 0) {
892 printf("%s", tcfg->htxt);
894 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
899 *tcfg->tqueue->q = 0;
900 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
903 * record empty time locally
907 sleep(tcfg->tvar->sleep_sec);
910 * enqueue one packet to recalculate average queue size
912 if (rte_red_enqueue(tcfg->tconfig->rconfig,
915 get_port_ts()) != 0) {
919 (*tcfg->tqueue->q)++;
922 * calculate how long queue has been empty
924 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
926 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
928 * this could happen if sleep was interrupted for some reason
935 * confirm that average queue size is now at expected level
938 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
939 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
942 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
943 avg_before, avg_after, exp_avg,
944 diff, (double)tcfg->tqueue->avg_tolerance,
945 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
951 * Test F5: functional test 5
953 static uint32_t ft5_tlevel[] = {127};
954 static uint8_t ft5_wq_log2[] = {9, 8};
955 static uint8_t ft5_maxp_inv[] = {10, 20};
956 static struct rte_red_config ft5_config[2];
957 static struct rte_red ft5_data[4];
958 static uint32_t ft5_q[4];
959 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
960 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
962 static struct test_rte_red_config ft5_tconfig = {
963 .rconfig = ft5_config,
964 .num_cfg = DIM(ft5_config),
967 .wq_log2 = ft5_wq_log2,
968 .maxp_inv = ft5_maxp_inv,
971 static struct test_queue ft5_tqueue = {
973 .num_queues = DIM(ft5_data),
974 .qconfig = ft_qconfig,
976 .q_ramp_up = 1000000,
977 .avg_ramp_up = 1000000,
978 .avg_tolerance = 5, /* 10 percent */
979 .drop_tolerance = 50, /* 50 percent */
982 struct test_var ft5_tvar = {
984 .num_iterations = 15,
987 .dropped = ft5_dropped,
988 .enqueued = ft5_enqueued,
992 static struct test_config func_test5_config = {
993 .ifname = "functional test 5 interface",
994 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
995 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
996 " increase average queue size to just below maximum threshold,\n"
997 " compare drop rate to drop probability,\n"
998 " (this is a larger scale version of functional test 2)\n\n",
1009 .tconfig = &ft5_tconfig,
1010 .tqueue = &ft5_tqueue,
1012 .tlevel = ft5_tlevel,
1015 static enum test_result func_test5(struct test_config *tcfg)
1017 enum test_result result = PASS;
1020 printf("%s", tcfg->msg);
1022 if (test_rte_red_init(tcfg) != PASS) {
1027 printf("%s", tcfg->htxt);
1029 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1030 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1031 tcfg->tqueue->q[j] = 0;
1033 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1034 &tcfg->tqueue->rdata[j],
1035 &tcfg->tqueue->q[j],
1037 tcfg->tqueue->q_ramp_up) != 0) {
1042 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1043 &tcfg->tqueue->rdata[j],
1044 &tcfg->tqueue->q[j],
1046 tcfg->tqueue->avg_ramp_up) != 0) {
1052 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1054 double drop_rate = 0.0;
1055 double drop_prob = 0.0;
1058 tcfg->tvar->dropped[j] = 0;
1059 tcfg->tvar->enqueued[j] = 0;
1061 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1062 &tcfg->tqueue->rdata[j],
1063 &tcfg->tqueue->q[j],
1064 tcfg->tvar->num_ops,
1065 &tcfg->tvar->enqueued[j],
1066 &tcfg->tvar->dropped[j]);
1068 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1069 &tcfg->tqueue->rdata[j]);
1070 if (avg != *tcfg->tlevel)
1073 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1074 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1075 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1077 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1080 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1081 j, tcfg->tqueue->qconfig[j], avg,
1082 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1083 drop_prob * 100.0, drop_rate * 100.0,
1084 diff, (double)tcfg->tqueue->drop_tolerance);
1091 * Test F6: functional test 6
1093 static uint32_t ft6_tlevel[] = {1022};
1094 static uint8_t ft6_wq_log2[] = {9, 8};
1095 static uint8_t ft6_maxp_inv[] = {10, 20};
1096 static struct rte_red_config ft6_config[2];
1097 static struct rte_red ft6_data[4];
1098 static uint32_t ft6_q[4];
1100 static struct test_rte_red_config ft6_tconfig = {
1101 .rconfig = ft6_config,
1102 .num_cfg = DIM(ft6_config),
1105 .wq_log2 = ft6_wq_log2,
1106 .maxp_inv = ft6_maxp_inv,
1109 static struct test_queue ft6_tqueue = {
1111 .num_queues = DIM(ft6_data),
1112 .qconfig = ft_qconfig,
1114 .q_ramp_up = 1000000,
1115 .avg_ramp_up = 1000000,
1116 .avg_tolerance = 5, /* 10 percent */
1117 .drop_tolerance = 50, /* 50 percent */
1120 static struct test_config func_test6_config = {
1121 .ifname = "functional test 6 interface",
1122 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1123 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1124 " increase average queue size to target level,\n"
1125 " dequeue all packets until queue is empty,\n"
1126 " confirm that average queue size is computed correctly while queue is empty\n"
1127 " (this is a larger scale version of functional test 3)\n\n",
1136 .tconfig = &ft6_tconfig,
1137 .tqueue = &ft6_tqueue,
1139 .tlevel = ft6_tlevel,
1142 static enum test_result func_test6(struct test_config *tcfg)
1144 enum test_result result = PASS;
1147 printf("%s", tcfg->msg);
1148 if (test_rte_red_init(tcfg) != PASS) {
1152 printf("%s", tcfg->htxt);
1154 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1155 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1156 tcfg->tqueue->q[j] = 0;
1158 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1159 &tcfg->tqueue->rdata[j],
1160 &tcfg->tqueue->q[j],
1162 tcfg->tqueue->q_ramp_up) != 0) {
1166 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1167 &tcfg->tqueue->rdata[j],
1168 &tcfg->tqueue->q[j],
1170 tcfg->tqueue->avg_ramp_up) != 0) {
1175 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1176 double avg_before = 0;
1177 double avg_after = 0;
1181 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1182 &tcfg->tqueue->rdata[j]);
1187 tcfg->tqueue->q[j] = 0;
1188 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1189 rte_delay_us(tcfg->tvar->wait_usec);
1192 * enqueue one packet to recalculate average queue size
1194 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1195 &tcfg->tqueue->rdata[j],
1197 get_port_ts()) == 0) {
1198 tcfg->tqueue->q[j]++;
1200 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1204 exp_avg = calc_exp_avg_on_empty(avg_before,
1205 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1206 tcfg->tvar->wait_usec);
1207 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1208 &tcfg->tqueue->rdata[j]);
1209 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1212 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1213 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1214 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1215 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1222 * setup default values for the performance test structures
1224 static struct rte_red_config pt_wrconfig[1];
1225 static struct rte_red pt_rtdata[1];
1226 static uint8_t pt_wq_log2[] = {9};
1227 static uint8_t pt_maxp_inv[] = {10};
1228 static uint32_t pt_qconfig[] = {0};
1229 static uint32_t pt_q[] = {0};
1230 static uint32_t pt_dropped[] = {0};
1231 static uint32_t pt_enqueued[] = {0};
1233 static struct test_rte_red_config pt_tconfig = {
1234 .rconfig = pt_wrconfig,
1235 .num_cfg = DIM(pt_wrconfig),
1236 .wq_log2 = pt_wq_log2,
1239 .maxp_inv = pt_maxp_inv,
1242 static struct test_queue pt_tqueue = {
1244 .num_queues = DIM(pt_rtdata),
1245 .qconfig = pt_qconfig,
1247 .q_ramp_up = 1000000,
1248 .avg_ramp_up = 1000000,
1249 .avg_tolerance = 5, /* 10 percent */
1250 .drop_tolerance = 50, /* 50 percent */
1254 * enqueue/dequeue packets
1256 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1257 struct rte_red *red,
1262 struct rdtsc_prof *prof)
1266 for (i = 0; i < num_ops; i++) {
1273 rdtsc_prof_start(prof);
1274 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1275 rdtsc_prof_end(prof);
1284 * Setup test structures for tests P1, P2, P3
1285 * performance tests 1, 2 and 3
1287 static uint32_t pt1_tlevel[] = {16};
1288 static uint32_t pt2_tlevel[] = {80};
1289 static uint32_t pt3_tlevel[] = {144};
1291 static struct test_var perf1_tvar = {
1293 .num_iterations = 15,
1294 .num_ops = 50000000,
1296 .dropped = pt_dropped,
1297 .enqueued = pt_enqueued,
1301 static struct test_config perf1_test1_config = {
1302 .ifname = "performance test 1 interface",
1303 .msg = "performance test 1 : use one RED configuration,\n"
1304 " set actual and average queue sizes to level below min threshold,\n"
1305 " measure enqueue performance\n\n",
1306 .tconfig = &pt_tconfig,
1307 .tqueue = &pt_tqueue,
1308 .tvar = &perf1_tvar,
1309 .tlevel = pt1_tlevel,
1312 static struct test_config perf1_test2_config = {
1313 .ifname = "performance test 2 interface",
1314 .msg = "performance test 2 : use one RED configuration,\n"
1315 " set actual and average queue sizes to level in between min and max thresholds,\n"
1316 " measure enqueue performance\n\n",
1317 .tconfig = &pt_tconfig,
1318 .tqueue = &pt_tqueue,
1319 .tvar = &perf1_tvar,
1320 .tlevel = pt2_tlevel,
1323 static struct test_config perf1_test3_config = {
1324 .ifname = "performance test 3 interface",
1325 .msg = "performance test 3 : use one RED configuration,\n"
1326 " set actual and average queue sizes to level above max threshold,\n"
1327 " measure enqueue performance\n\n",
1328 .tconfig = &pt_tconfig,
1329 .tqueue = &pt_tqueue,
1330 .tvar = &perf1_tvar,
1331 .tlevel = pt3_tlevel,
1335 * Performance test function to measure enqueue performance.
1336 * This runs performance tests 1, 2 and 3
1338 static enum test_result perf1_test(struct test_config *tcfg)
1340 enum test_result result = PASS;
1341 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1344 printf("%s", tcfg->msg);
1346 rdtsc_prof_init(&prof, "enqueue");
1348 if (test_rte_red_init(tcfg) != PASS) {
1354 * set average queue size to target level
1356 *tcfg->tqueue->q = *tcfg->tlevel;
1359 * initialize the rte_red run time data structure
1361 rte_red_rt_data_init(tcfg->tqueue->rdata);
1364 * set the queue average
1366 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1367 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1373 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1374 tcfg->tqueue->rdata,
1376 tcfg->tvar->num_ops,
1377 tcfg->tvar->enqueued,
1378 tcfg->tvar->dropped,
1381 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1383 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1384 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1385 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1387 rdtsc_prof_print(&prof);
1393 * Setup test structures for tests P4, P5, P6
1394 * performance tests 4, 5 and 6
1396 static uint32_t pt4_tlevel[] = {16};
1397 static uint32_t pt5_tlevel[] = {80};
1398 static uint32_t pt6_tlevel[] = {144};
1400 static struct test_var perf2_tvar = {
1402 .num_iterations = 10000,
1404 .dropped = pt_dropped,
1405 .enqueued = pt_enqueued,
1409 static struct test_config perf2_test4_config = {
1410 .ifname = "performance test 4 interface",
1411 .msg = "performance test 4 : use one RED configuration,\n"
1412 " set actual and average queue sizes to level below min threshold,\n"
1413 " dequeue all packets until queue is empty,\n"
1414 " measure enqueue performance when queue is empty\n\n",
1415 .htxt = "iteration "
1422 .tconfig = &pt_tconfig,
1423 .tqueue = &pt_tqueue,
1424 .tvar = &perf2_tvar,
1425 .tlevel = pt4_tlevel,
1428 static struct test_config perf2_test5_config = {
1429 .ifname = "performance test 5 interface",
1430 .msg = "performance test 5 : use one RED configuration,\n"
1431 " set actual and average queue sizes to level in between min and max thresholds,\n"
1432 " dequeue all packets until queue is empty,\n"
1433 " measure enqueue performance when queue is empty\n\n",
1434 .htxt = "iteration "
1441 .tconfig = &pt_tconfig,
1442 .tqueue = &pt_tqueue,
1443 .tvar = &perf2_tvar,
1444 .tlevel = pt5_tlevel,
1447 static struct test_config perf2_test6_config = {
1448 .ifname = "performance test 6 interface",
1449 .msg = "performance test 6 : use one RED configuration,\n"
1450 " set actual and average queue sizes to level above max threshold,\n"
1451 " dequeue all packets until queue is empty,\n"
1452 " measure enqueue performance when queue is empty\n\n",
1453 .htxt = "iteration "
1460 .tconfig = &pt_tconfig,
1461 .tqueue = &pt_tqueue,
1462 .tvar = &perf2_tvar,
1463 .tlevel = pt6_tlevel,
1467 * Performance test function to measure enqueue performance when the
1468 * queue is empty. This runs performance tests 4, 5 and 6
1470 static enum test_result perf2_test(struct test_config *tcfg)
1472 enum test_result result = PASS;
1473 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1477 printf("%s", tcfg->msg);
1479 rdtsc_prof_init(&prof, "enqueue");
1481 if (test_rte_red_init(tcfg) != PASS) {
1486 printf("%s", tcfg->htxt);
1488 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1491 double avg_before = 0;
1495 * set average queue size to target level
1497 *tcfg->tqueue->q = *tcfg->tlevel;
1498 count = (*tcfg->tqueue->rdata).count;
1501 * initialize the rte_red run time data structure
1503 rte_red_rt_data_init(tcfg->tqueue->rdata);
1504 (*tcfg->tqueue->rdata).count = count;
1507 * set the queue average
1509 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1510 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1511 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1519 *tcfg->tqueue->q = 0;
1520 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1523 * wait for specified period of time
1525 rte_delay_us(tcfg->tvar->wait_usec);
1528 * measure performance of enqueue operation while queue is empty
1531 rdtsc_prof_start(&prof);
1532 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1533 *tcfg->tqueue->q, ts );
1534 rdtsc_prof_end(&prof);
1537 * gather enqueued/dropped statistics
1540 (*tcfg->tvar->enqueued)++;
1542 (*tcfg->tvar->dropped)++;
1545 * on first and last iteration, confirm that
1546 * average queue size was computed correctly
1548 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1549 double avg_after = 0;
1554 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1555 exp_avg = calc_exp_avg_on_empty(avg_before,
1556 (1 << *tcfg->tconfig->wq_log2),
1557 tcfg->tvar->wait_usec);
1558 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1560 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1561 i, avg_before, avg_after, exp_avg, diff,
1562 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1569 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1570 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1571 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1572 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1574 rdtsc_prof_print(&prof);
1580 * setup default values for overflow test structures
1582 static uint32_t avg_max = 0;
1583 static uint32_t avg_max_bits = 0;
1585 static struct rte_red_config ovfl_wrconfig[1];
1586 static struct rte_red ovfl_rtdata[1];
1587 static uint8_t ovfl_maxp_inv[] = {10};
1588 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1589 static uint32_t ovfl_q[] ={0};
1590 static uint32_t ovfl_dropped[] ={0};
1591 static uint32_t ovfl_enqueued[] ={0};
1592 static uint32_t ovfl_tlevel[] = {1023};
1593 static uint8_t ovfl_wq_log2[] = {12};
1595 static struct test_rte_red_config ovfl_tconfig = {
1596 .rconfig = ovfl_wrconfig,
1597 .num_cfg = DIM(ovfl_wrconfig),
1598 .wq_log2 = ovfl_wq_log2,
1601 .maxp_inv = ovfl_maxp_inv,
1604 static struct test_queue ovfl_tqueue = {
1605 .rdata = ovfl_rtdata,
1606 .num_queues = DIM(ovfl_rtdata),
1607 .qconfig = ovfl_qconfig,
1609 .q_ramp_up = 1000000,
1610 .avg_ramp_up = 1000000,
1611 .avg_tolerance = 5, /* 10 percent */
1612 .drop_tolerance = 50, /* 50 percent */
1615 static struct test_var ovfl_tvar = {
1617 .num_iterations = 1,
1620 .dropped = ovfl_dropped,
1621 .enqueued = ovfl_enqueued,
1625 static void ovfl_check_avg(uint32_t avg)
1627 if (avg > avg_max) {
1631 avg_log = log(((double)avg_max));
1632 avg_log = avg_log / log(2.0);
1633 bits = (uint32_t)ceil(avg_log);
1634 if (bits > avg_max_bits)
1635 avg_max_bits = bits;
1639 static struct test_config ovfl_test1_config = {
1640 .ifname = "queue avergage overflow test interface",
1641 .msg = "overflow test 1 : use one RED configuration,\n"
1642 " increase average queue size to target level,\n"
1643 " check maximum number of bits requirte_red to represent avg_s\n\n",
1644 .htxt = "avg queue size "
1654 .tconfig = &ovfl_tconfig,
1655 .tqueue = &ovfl_tqueue,
1657 .tlevel = ovfl_tlevel,
1660 static enum test_result ovfl_test1(struct test_config *tcfg)
1662 enum test_result result = PASS;
1665 double drop_rate = 0.0;
1666 double drop_prob = 0.0;
1670 printf("%s", tcfg->msg);
1672 if (test_rte_red_init(tcfg) != PASS) {
1679 * reset rte_red run-time data
1681 rte_red_rt_data_init(tcfg->tqueue->rdata);
1684 * increase actual queue size
1686 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1687 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1688 *tcfg->tqueue->q, get_port_ts());
1691 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1699 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1700 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1701 *tcfg->tqueue->q, get_port_ts());
1702 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1703 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1704 if (avg == *tcfg->tlevel) {
1706 (*tcfg->tvar->enqueued)++;
1708 (*tcfg->tvar->dropped)++;
1713 * check if target average queue size has been reached
1715 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1716 if (avg != *tcfg->tlevel) {
1722 * check drop rate against drop probability
1724 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1725 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1726 tcfg->tconfig->max_th,
1727 *tcfg->tconfig->maxp_inv,
1729 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1732 printf("%s", tcfg->htxt);
1734 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1735 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1736 avg_max, avg_max_bits,
1737 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1738 drop_prob * 100.0, drop_rate * 100.0);
1744 * define the functional and performance tests to be executed
1746 struct tests func_tests[] = {
1747 { &func_test1_config, func_test1 },
1748 { &func_test2_config, func_test2 },
1749 { &func_test3_config, func_test3 },
1750 { &func_test4_config, func_test4 },
1751 { &func_test5_config, func_test5 },
1752 { &func_test6_config, func_test6 },
1753 { &ovfl_test1_config, ovfl_test1 },
1756 struct tests perf_tests[] = {
1757 { &perf1_test1_config, perf1_test },
1758 { &perf1_test2_config, perf1_test },
1759 { &perf1_test3_config, perf1_test },
1760 { &perf2_test4_config, perf2_test },
1761 { &perf2_test5_config, perf2_test },
1762 { &perf2_test6_config, perf2_test },
1766 * function to execute the required_red tests
1768 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1770 enum test_result result = PASS;
1773 for (i = 0; i < test_count; i++) {
1774 printf("\n--------------------------------------------------------------------------------\n");
1775 result = test_type[i].testfn(test_type[i].testcfg);
1777 if (result == PASS) {
1779 printf("-------------------------------------<pass>-------------------------------------\n");
1781 printf("-------------------------------------<fail>-------------------------------------\n");
1788 * check if functions accept invalid parameters
1790 * First, all functions will be called without initialized RED
1791 * Then, all of them will be called with NULL/invalid parameters
1793 * Some functions are not tested as they are performance-critical and thus
1794 * don't do any parameter checking.
1797 test_invalid_parameters(void)
1799 struct rte_red_config config;
1801 if (rte_red_rt_data_init(NULL) == 0) {
1802 printf("rte_red_rt_data_init should have failed!\n");
1806 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1807 printf("rte_red_config_init should have failed!\n");
1811 if (rte_red_rt_data_init(NULL) == 0) {
1812 printf("rte_red_rt_data_init should have failed!\n");
1817 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1818 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1821 /* min_treshold == max_treshold */
1822 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1823 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1826 /* min_treshold > max_treshold */
1827 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1828 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1831 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1832 if (rte_red_config_init(&config,
1833 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1834 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1837 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1838 if (rte_red_config_init(&config,
1839 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1840 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1843 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1844 if (rte_red_config_init(&config,
1845 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1846 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1849 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1850 if (rte_red_config_init(&config,
1851 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1852 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1861 uint32_t num_tests = 0;
1862 uint32_t num_pass = 0;
1865 if (test_invalid_parameters() < 0)
1868 run_tests(func_tests, DIM(func_tests), &num_tests, &num_pass);
1869 run_tests(perf_tests, DIM(perf_tests), &num_tests, &num_pass);
1871 if (num_pass == num_tests) {
1872 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1875 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1886 printf("The SCHED library is not included in this build\n");