X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=app%2Ftest%2Ftest_red.c;h=81c9d6795c64e727916bacf318ed0dac7d7c59d3;hb=62a785a68ebf710eba22b70b46a970a4e4e1cec7;hp=bee490ed940997de1a37e8e5ed4068d494f18db8;hpb=21a7f4e2646e1cb6b0dbd6643e5d64f72355af58;p=dpdk.git diff --git a/app/test/test_red.c b/app/test/test_red.c index bee490ed94..81c9d6795c 100644 --- a/app/test/test_red.c +++ b/app/test/test_red.c @@ -1,13 +1,13 @@ /*- * BSD LICENSE - * + * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -43,8 +43,6 @@ #include "test.h" -#ifdef RTE_LIBRTE_SCHED - #include #ifdef __INTEL_COMPILER @@ -76,7 +74,7 @@ struct test_queue { /**< Test structure for RTE_RED Queues */ uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */ uint32_t *q; /**< Queue size */ uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */ - uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */ + uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */ uint32_t avg_tolerance; /**< Tolerance in queue average */ double drop_tolerance; /**< Drop tolerance of packets not enqueued */ }; @@ -148,16 +146,7 @@ static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name) static inline void rdtsc_prof_start(struct rdtsc_prof *p) { -#ifdef __PIC__ - asm volatile ( - "mov %%ebx, %%edi\n" - "cpuid\n" - "xchgl %%ebx, %%edi;\n" - : : : "%eax", "%edi", "%ecx", "%edx" ); -#else - asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" ); -#endif - p->clk_start = rte_rdtsc(); + p->clk_start = rte_rdtsc_precise(); } static inline void rdtsc_prof_end(struct rdtsc_prof *p) @@ -240,7 +229,7 @@ static double calc_drop_prob(uint32_t min_th, uint32_t max_th, } else { drop_prob = 1.0; } - return (drop_prob); + return drop_prob; } /** @@ -260,7 +249,7 @@ static int check_drop_rate(double *diff, double drop_rate, double drop_prob, dou ret = 0; } } - return (ret); + return ret; } /** @@ -280,7 +269,7 @@ static int check_avg(double *diff, double avg, double exp_avg, double tolerance) ret = 0; } } - return (ret); + return ret; } /** @@ -310,14 +299,14 @@ static uint64_t get_machclk_freq(void) end = rte_rdtsc(); diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC - + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) / + + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) / USEC_PER_MSEC); /**< diff is in micro secs */ if (diff == 0) - return(0); + return 0; clk_freq_hz = ((end - start) * USEC_PER_SEC / diff); - return (clk_freq_hz); + return clk_freq_hz; } /** @@ -337,14 +326,14 @@ test_rte_red_init(struct test_config *tcfg) (uint16_t)tcfg->tconfig->min_th, (uint16_t)tcfg->tconfig->max_th, (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) { - return(FAIL); + return FAIL; } } *tcfg->tqueue->q = 0; *tcfg->tvar->dropped = 0; *tcfg->tvar->enqueued = 0; - return(PASS); + return PASS; } /** @@ -375,11 +364,11 @@ increase_actual_qsize(struct rte_red_config *red_cfg, * check if target actual queue size has been reached */ if (*q != level) - return (-1); + return -1; /** * success */ - return (0); + return 0; } /** @@ -406,11 +395,11 @@ increase_average_qsize(struct rte_red_config *red_cfg, */ avg = rte_red_get_avg_int(red_cfg, red); if (avg != level) - return (-1); + return -1; /** * success */ - return (0); + return 0; } /** @@ -419,7 +408,7 @@ increase_average_qsize(struct rte_red_config *red_cfg, static struct rte_red_config ft_wrconfig[1]; static struct rte_red ft_rtdata[1]; static uint8_t ft_wq_log2[] = {9}; -static uint8_t ft_maxp_inv[] = {10}; +static uint8_t ft_maxp_inv[] = {10}; static uint32_t ft_qconfig[] = {0, 0, 1, 1}; static uint32_t ft_q[] ={0}; static uint32_t ft_dropped[] ={0}; @@ -518,7 +507,7 @@ static enum test_result func_test1(struct test_config *tcfg) goto out; } - printf("%s", tcfg->htxt); + printf("%s", tcfg->htxt); for (i = 0; i < RTE_DIM(ft1_tlevels); i++) { const char *label = NULL; @@ -583,7 +572,7 @@ static enum test_result func_test1(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -694,7 +683,7 @@ static enum test_result func_test2(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -793,10 +782,10 @@ static enum test_result func_test3(struct test_config *tcfg) result = FAIL; } - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << *tcfg->tconfig->wq_log2), tcfg->tvar->wait_usec); - avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, + avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata); if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance)) result = FAIL; @@ -807,7 +796,7 @@ static enum test_result func_test3(struct test_config *tcfg) diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -905,7 +894,7 @@ static enum test_result func_test4(struct test_config *tcfg) rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts()); /** - * record empty time locally + * record empty time locally */ start = rte_rdtsc(); @@ -914,8 +903,8 @@ static enum test_result func_test4(struct test_config *tcfg) /** * enqueue one packet to recalculate average queue size */ - if (rte_red_enqueue(tcfg->tconfig->rconfig, - tcfg->tqueue->rdata, + if (rte_red_enqueue(tcfg->tconfig->rconfig, + tcfg->tqueue->rdata, *tcfg->tqueue->q, get_port_ts()) != 0) { result = FAIL; @@ -949,7 +938,7 @@ static enum test_result func_test4(struct test_config *tcfg) diff, (double)tcfg->tqueue->avg_tolerance, diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail"); out: - return (result); + return result; } /** @@ -1077,7 +1066,7 @@ static enum test_result func_test5(struct test_config *tcfg) drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]); drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th, - tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]], + tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]], *tcfg->tlevel); if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance)) result = FAIL; @@ -1089,7 +1078,7 @@ static enum test_result func_test5(struct test_config *tcfg) diff, (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -1183,7 +1172,7 @@ static enum test_result func_test6(struct test_config *tcfg) double exp_avg = 0; double diff = 0.0; - avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], + avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], &tcfg->tqueue->rdata[j]); /** @@ -1196,7 +1185,7 @@ static enum test_result func_test6(struct test_config *tcfg) /** * enqueue one packet to recalculate average queue size */ - if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], + if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], &tcfg->tqueue->rdata[j], tcfg->tqueue->q[j], get_port_ts()) == 0) { @@ -1206,7 +1195,7 @@ static enum test_result func_test6(struct test_config *tcfg) result = FAIL; } - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]), tcfg->tvar->wait_usec); avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], @@ -1220,7 +1209,7 @@ static enum test_result func_test6(struct test_config *tcfg) diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -1229,7 +1218,7 @@ out: static struct rte_red_config pt_wrconfig[1]; static struct rte_red pt_rtdata[1]; static uint8_t pt_wq_log2[] = {9}; -static uint8_t pt_maxp_inv[] = {10}; +static uint8_t pt_maxp_inv[] = {10}; static uint32_t pt_qconfig[] = {0}; static uint32_t pt_q[] = {0}; static uint32_t pt_dropped[] = {0}; @@ -1286,7 +1275,7 @@ static void enqueue_dequeue_perf(struct rte_red_config *red_cfg, } /** - * Setup test structures for tests P1, P2, P3 + * Setup test structures for tests P1, P2, P3 * performance tests 1, 2 and 3 */ static uint32_t pt1_tlevel[] = {16}; @@ -1337,8 +1326,8 @@ static struct test_config perf1_test3_config = { }; /** - * Performance test function to measure enqueue performance. - * This runs performance tests 1, 2 and 3 + * Performance test function to measure enqueue performance. + * This runs performance tests 1, 2 and 3 */ static enum test_result perf1_test(struct test_config *tcfg) { @@ -1369,7 +1358,7 @@ static enum test_result perf1_test(struct test_config *tcfg) * set the queue average */ rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel); - if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata) + if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata) != *tcfg->tlevel) { result = FAIL; goto out; @@ -1391,11 +1380,11 @@ static enum test_result perf1_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** - * Setup test structures for tests P4, P5, P6 + * Setup test structures for tests P4, P5, P6 * performance tests 4, 5 and 6 */ static uint32_t pt4_tlevel[] = {16}; @@ -1469,8 +1458,8 @@ static struct test_config perf2_test6_config = { }; /** - * Performance test function to measure enqueue performance when the - * queue is empty. This runs performance tests 4, 5 and 6 + * Performance test function to measure enqueue performance when the + * queue is empty. This runs performance tests 4, 5 and 6 */ static enum test_result perf2_test(struct test_config *tcfg) { @@ -1488,7 +1477,7 @@ static enum test_result perf2_test(struct test_config *tcfg) goto out; } - printf("%s", tcfg->htxt); + printf("%s", tcfg->htxt); for (i = 0; i < tcfg->tvar->num_iterations; i++) { uint32_t count = 0; @@ -1534,7 +1523,7 @@ static enum test_result perf2_test(struct test_config *tcfg) */ ts = get_port_ts(); rdtsc_prof_start(&prof); - ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, + ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tqueue->q, ts ); rdtsc_prof_end(&prof); @@ -1557,7 +1546,7 @@ static enum test_result perf2_test(struct test_config *tcfg) int ok = 0; avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata); - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << *tcfg->tconfig->wq_log2), tcfg->tvar->wait_usec); if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance)) @@ -1578,7 +1567,7 @@ static enum test_result perf2_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** @@ -1589,7 +1578,7 @@ static uint32_t avg_max_bits = 0; static struct rte_red_config ovfl_wrconfig[1]; static struct rte_red ovfl_rtdata[1]; -static uint8_t ovfl_maxp_inv[] = {10}; +static uint8_t ovfl_maxp_inv[] = {10}; static uint32_t ovfl_qconfig[] = {0, 0, 1, 1}; static uint32_t ovfl_q[] ={0}; static uint32_t ovfl_dropped[] ={0}; @@ -1735,30 +1724,30 @@ static enum test_result ovfl_test1(struct test_config *tcfg) result = FAIL; printf("%s", tcfg->htxt); - + printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n", avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING, avg_max, avg_max_bits, *tcfg->tvar->enqueued, *tcfg->tvar->dropped, drop_prob * 100.0, drop_rate * 100.0); out: - return (result); + return result; } /** * define the functional and performance tests to be executed */ -struct tests func_tests[] = { +struct tests func_tests[] = { { &func_test1_config, func_test1 }, - { &func_test2_config, func_test2 }, + { &func_test2_config, func_test2 }, { &func_test3_config, func_test3 }, { &func_test4_config, func_test4 }, { &func_test5_config, func_test5 }, { &func_test6_config, func_test6 }, - { &ovfl_test1_config, ovfl_test1 }, + { &ovfl_test1_config, ovfl_test1 }, }; -struct tests perf_tests[] = { +struct tests perf_tests[] = { { &perf1_test1_config, perf1_test }, { &perf1_test2_config, perf1_test }, { &perf1_test3_config, perf1_test }, @@ -1861,7 +1850,8 @@ test_invalid_parameters(void) return 0; } -int test_red(void) +static int +test_red(void) { uint32_t num_tests = 0; uint32_t num_pass = 0; @@ -1880,16 +1870,11 @@ int test_red(void) printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass); ret = -1; } - return (ret); -} - -#else - -int -test_red(void) -{ - printf("The SCHED library is not included in this build\n"); - return 0; + return ret; } -#endif +static struct test_command red_cmd = { + .command = "red_autotest", + .callback = test_red, +}; +REGISTER_TEST_COMMAND(red_cmd);