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.
30 uint64_t start_cycles, cycles, prev_cycles;
31 uint64_t hz = rte_get_timer_hz();
32 uint64_t max_inc = (hz / 100); /* 10 ms max between 2 reads */
34 /* check that the timer is always incrementing */
35 start_cycles = rte_get_timer_cycles();
36 prev_cycles = start_cycles;
38 cycles = rte_get_timer_cycles();
39 if ((uint64_t)(cycles - prev_cycles) > max_inc) {
40 printf("increment too high or going backwards\n");
46 /* check that waiting 1 second is precise */
47 prev_cycles = rte_get_timer_cycles();
48 rte_delay_us(1000000);
49 cycles = rte_get_timer_cycles();
51 if ((uint64_t)(cycles - prev_cycles) > (hz + max_inc)) {
52 printf("delay_us is not accurate: too long\n");
55 if ((uint64_t)(cycles - prev_cycles) < (hz - max_inc)) {
56 printf("delay_us is not accurate: too short\n");
63 REGISTER_TEST_COMMAND(cycles_autotest, test_cycles);
66 * rte_delay_us_callback test
68 * - check if callback is correctly registered/unregistered
72 static unsigned int pattern;
73 static void my_rte_delay_us(unsigned int us)
79 test_user_delay_us(void)
87 /* register custom delay function */
88 rte_delay_us_callback_register(my_rte_delay_us);
98 /* restore original delay function */
99 rte_delay_us_callback_register(rte_delay_us_block);
108 REGISTER_TEST_COMMAND(user_delay_us, test_user_delay_us);