1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 #include <rte_common.h>
9 #include <rte_cycles.h>
19 * - Loop N times and check that the timer always increments and
20 * never decrements during this loop.
22 * - Wait one second using rte_usleep() and check that the increment
23 * of cycles is correct with regard to the frequency of the timer.
27 check_wait_one_second(void)
29 uint64_t cycles, prev_cycles;
30 uint64_t hz = rte_get_timer_hz();
31 uint64_t max_inc = (hz / 100); /* 10 ms max between 2 reads */
33 /* check that waiting 1 second is precise */
34 prev_cycles = rte_get_timer_cycles();
35 rte_delay_us(1000000);
36 cycles = rte_get_timer_cycles();
38 if ((uint64_t)(cycles - prev_cycles) > (hz + max_inc)) {
39 printf("delay_us is not accurate: too long\n");
42 if ((uint64_t)(cycles - prev_cycles) < (hz - max_inc)) {
43 printf("delay_us is not accurate: too short\n");
54 uint64_t start_cycles, cycles, prev_cycles;
55 uint64_t hz = rte_get_timer_hz();
56 uint64_t max_inc = (hz / 100); /* 10 ms max between 2 reads */
58 /* check that the timer is always incrementing */
59 start_cycles = rte_get_timer_cycles();
60 prev_cycles = start_cycles;
62 cycles = rte_get_timer_cycles();
63 if ((uint64_t)(cycles - prev_cycles) > max_inc) {
64 printf("increment too high or going backwards\n");
70 return check_wait_one_second();
73 REGISTER_TEST_COMMAND(cycles_autotest, test_cycles);
76 * One second precision test with rte_delay_us_sleep.
80 test_delay_us_sleep(void)
82 rte_delay_us_callback_register(rte_delay_us_sleep);
83 return check_wait_one_second();
86 REGISTER_TEST_COMMAND(delay_us_sleep_autotest, test_delay_us_sleep);
89 * rte_delay_us_callback test
91 * - check if callback is correctly registered/unregistered
95 static unsigned int pattern;
96 static void my_rte_delay_us(unsigned int us)
102 test_user_delay_us(void)
110 /* register custom delay function */
111 rte_delay_us_callback_register(my_rte_delay_us);
121 /* restore original delay function */
122 rte_delay_us_callback_register(rte_delay_us_block);
131 REGISTER_TEST_COMMAND(user_delay_us, test_user_delay_us);