1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <rte_common.h>
14 #include <rte_cycles.h>
15 #include <rte_pause.h>
17 #include "eal_private.h"
19 /* The frequency of the RDTSC timer resolution */
20 static uint64_t eal_tsc_resolution_hz;
22 /* Pointer to user delay function */
23 void (*rte_delay_us)(unsigned int) = NULL;
26 rte_delay_us_block(unsigned int us)
28 const uint64_t start = rte_get_timer_cycles();
29 const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
30 while ((rte_get_timer_cycles() - start) < ticks)
37 return eal_tsc_resolution_hz;
41 estimate_tsc_freq(void)
43 RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
44 " - clock timings may be less accurate.\n");
45 /* assume that the sleep(1) will sleep for 1 second */
46 uint64_t start = rte_rdtsc();
48 return rte_rdtsc() - start;
56 freq = get_tsc_freq_arch();
58 freq = get_tsc_freq();
60 freq = estimate_tsc_freq();
62 RTE_LOG(DEBUG, EAL, "TSC frequency is ~%" PRIu64 " KHz\n", freq / 1000);
63 eal_tsc_resolution_hz = freq;
66 void rte_delay_us_callback_register(void (*userfunc)(unsigned int))
68 rte_delay_us = userfunc;
71 RTE_INIT(rte_timer_init)
73 /* set rte_delay_us_block as a delay function */
74 rte_delay_us_callback_register(rte_delay_us_block);