1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2022-2024 Nokia
*/
#ifndef ODP_PLAT_TIMER_INLINES_H_
#define ODP_PLAT_TIMER_INLINES_H_
#include <odp/api/event.h>
#include <odp/api/hints.h>
#include <odp/api/time_types.h>
#include <odp/api/timer_types.h>
#include <odp/api/plat/debug_inlines.h>
#include <odp/api/plat/timer_inline_types.h>
#include <rte_config.h>
#include <rte_cycles.h>
#include <stdint.h>
/** @cond _ODP_HIDE_FROM_DOXYGEN_ */
#ifndef _ODP_NO_INLINE
/* Inline functions by default */
#define _ODP_INLINE static inline
#define odp_timeout_timer __odp_timeout_timer
#define odp_timeout_tick __odp_timeout_tick
#define odp_timeout_user_ptr __odp_timeout_user_ptr
#define odp_timeout_user_area __odp_timeout_user_area
#define odp_timer_current_tick __odp_timer_current_tick
#define odp_timeout_from_event __odp_timeout_from_event
#define odp_timeout_from_event_multi __odp_timeout_from_event_multi
#define odp_timeout_to_event __odp_timeout_to_event
#define odp_timer_tick_to_ns __odp_timer_tick_to_ns
#define odp_timer_ns_to_tick __odp_timer_ns_to_tick
#else
#define _ODP_INLINE
#endif
_ODP_INLINE odp_timer_t odp_timeout_timer(odp_timeout_t tmo)
{
return _odp_timeout_hdr_field(tmo, odp_timer_t, timer);
}
_ODP_INLINE uint64_t odp_timeout_tick(odp_timeout_t tmo)
{
return _odp_timeout_hdr_field(tmo, uint64_t, expiration);
}
_ODP_INLINE void *odp_timeout_user_ptr(odp_timeout_t tmo)
{
return _odp_timeout_hdr_field(tmo, void *, user_ptr);
}
_ODP_INLINE void *odp_timeout_user_area(odp_timeout_t tmo)
{
return _odp_timeout_hdr_field(tmo, void *, uarea_addr);
}
_ODP_INLINE uint64_t odp_timer_current_tick(odp_timer_pool_t tp ODP_UNUSED)
{
return rte_get_timer_cycles();
}
_ODP_INLINE odp_timeout_t odp_timeout_from_event(odp_event_t ev)
{
_ODP_ASSERT(odp_event_type(ev) == ODP_EVENT_TIMEOUT);
return (odp_timeout_t)ev;
}
_ODP_INLINE void odp_timeout_from_event_multi(odp_timeout_t tmo[], const odp_event_t ev[], int num)
{
for (int i = 0; i < num; i++) {
_ODP_ASSERT(odp_event_type(ev[i]) == ODP_EVENT_TIMEOUT);
tmo[i] = (odp_timeout_t)ev[i];
}
}
_ODP_INLINE odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
{
return (odp_event_t)tmo;
}
_ODP_INLINE uint64_t odp_timer_tick_to_ns(odp_timer_pool_t tp ODP_UNUSED, uint64_t ticks)
{
uint64_t nsec;
uint64_t sec = 0;
const uint64_t freq_hz = _odp_timer_glob.freq_hz;
if (ticks >= freq_hz) {
sec = ticks / freq_hz;
ticks = ticks - sec * freq_hz;
}
nsec = (ODP_TIME_SEC_IN_NS * ticks) / freq_hz;
return (sec * ODP_TIME_SEC_IN_NS) + nsec;
}
_ODP_INLINE uint64_t odp_timer_ns_to_tick(odp_timer_pool_t tp ODP_UNUSED, uint64_t ns)
{
uint64_t ticks;
uint64_t sec = 0;
const uint64_t freq_hz = _odp_timer_glob.freq_hz;
if (ns >= ODP_TIME_SEC_IN_NS) {
sec = ns / ODP_TIME_SEC_IN_NS;
ns = ns - sec * ODP_TIME_SEC_IN_NS;
}
ticks = sec * freq_hz;
ticks += (ns * freq_hz) / ODP_TIME_SEC_IN_NS;
return ticks;
}
/** @endcond */
#endif
|