1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Intel Corporation
6 #ifndef LTHREAD_TIMER_H_
7 #define LTHREAD_TIMER_H_
13 #include "lthread_int.h"
14 #include "lthread_sched.h"
17 static inline uint64_t
18 _ns_to_clks(uint64_t ns)
21 * clkns needs to be divided by 1E9 to get ns clocks. However,
22 * dividing by this first would lose a lot of accuracy.
23 * Dividing after a multiply by ns, could cause overflow of
24 * uint64_t if ns is about 5 seconds [if we assume a max tsc
25 * rate of 4GHz]. Therefore we first divide by 1E4, then
26 * multiply and finally divide by 1E5. This allows ns to be
27 * values many hours long, without overflow, while still keeping
28 * reasonable accuracy.
30 uint64_t clkns = rte_get_tsc_hz() / 1e4;
40 _timer_start(struct lthread *lt, uint64_t clks)
43 DIAG_EVENT(lt, LT_DIAG_LTHREAD_TMR_START, <->tim, clks);
44 rte_timer_init(<->tim);
45 rte_timer_reset(<->tim,
56 _timer_stop(struct lthread *lt)
59 DIAG_EVENT(lt, LT_DIAG_LTHREAD_TMR_DELETE, <->tim, 0);
60 rte_timer_stop(<->tim);
68 #endif /* LTHREAD_TIMER_H_ */