Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017 Cavium, Inc
3 : : */
4 : :
5 : : #include "timvf_worker.h"
6 : :
7 : : static inline int
8 : : timvf_timer_reg_checks(const struct timvf_ring * const timr,
9 : : struct rte_event_timer * const tim)
10 : : {
11 : 0 : if (unlikely(tim->state)) {
12 : 0 : tim->state = RTE_EVENT_TIMER_ERROR;
13 : 0 : rte_errno = EALREADY;
14 : 0 : goto fail;
15 : : }
16 : :
17 [ # # # # : 0 : if (unlikely(!tim->timeout_ticks ||
# # # # ]
18 : : tim->timeout_ticks >= timr->nb_bkts)) {
19 : 0 : tim->state = tim->timeout_ticks ? RTE_EVENT_TIMER_ERROR_TOOLATE
20 [ # # # # ]: 0 : : RTE_EVENT_TIMER_ERROR_TOOEARLY;
21 : 0 : rte_errno = EINVAL;
22 : 0 : goto fail;
23 : : }
24 : :
25 : : return 0;
26 : : fail:
27 : : return -EINVAL;
28 : : }
29 : :
30 : : static inline void
31 : : timvf_format_event(const struct rte_event_timer * const tim,
32 : : struct tim_mem_entry * const entry)
33 : : {
34 : 0 : entry->w0 = (tim->ev.event & 0xFFC000000000) >> 6 |
35 : 0 : (tim->ev.event & 0xFFFFFFFFF);
36 : 0 : entry->wqe = tim->ev.u64;
37 : : }
38 : :
39 : : uint16_t
40 : 0 : timvf_timer_cancel_burst(const struct rte_event_timer_adapter *adptr,
41 : : struct rte_event_timer **tim, const uint16_t nb_timers)
42 : : {
43 : : RTE_SET_USED(adptr);
44 : : int ret;
45 : : uint16_t index;
46 : :
47 [ # # ]: 0 : for (index = 0; index < nb_timers; index++) {
48 [ # # ]: 0 : if (tim[index]->state == RTE_EVENT_TIMER_CANCELED) {
49 : 0 : rte_errno = EALREADY;
50 : 0 : break;
51 : : }
52 : :
53 [ # # ]: 0 : if (tim[index]->state != RTE_EVENT_TIMER_ARMED) {
54 : 0 : rte_errno = EINVAL;
55 : 0 : break;
56 : : }
57 : 0 : ret = timvf_rem_entry(tim[index]);
58 [ # # ]: 0 : if (ret) {
59 : 0 : rte_errno = -ret;
60 : 0 : break;
61 : : }
62 : : }
63 : 0 : return index;
64 : : }
65 : :
66 : : uint16_t
67 : 0 : timvf_timer_arm_burst_sp(const struct rte_event_timer_adapter *adptr,
68 : : struct rte_event_timer **tim, const uint16_t nb_timers)
69 : : {
70 : : int ret;
71 : : uint16_t index;
72 : : struct tim_mem_entry entry;
73 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
74 [ # # ]: 0 : for (index = 0; index < nb_timers; index++) {
75 [ # # ]: 0 : if (timvf_timer_reg_checks(timr, tim[index]))
76 : : break;
77 : :
78 : : timvf_format_event(tim[index], &entry);
79 : 0 : ret = timvf_add_entry_sp(timr, tim[index]->timeout_ticks,
80 : : tim[index], &entry);
81 [ # # ]: 0 : if (unlikely(ret)) {
82 : 0 : rte_errno = -ret;
83 : 0 : break;
84 : : }
85 : : }
86 : :
87 : 0 : return index;
88 : : }
89 : :
90 : : uint16_t
91 : 0 : timvf_timer_arm_burst_sp_stats(const struct rte_event_timer_adapter *adptr,
92 : : struct rte_event_timer **tim, const uint16_t nb_timers)
93 : : {
94 : : uint16_t ret;
95 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
96 : :
97 : 0 : ret = timvf_timer_arm_burst_sp(adptr, tim, nb_timers);
98 : 0 : timr->tim_arm_cnt += ret;
99 : :
100 : 0 : return ret;
101 : : }
102 : :
103 : : uint16_t
104 : 0 : timvf_timer_arm_burst_mp(const struct rte_event_timer_adapter *adptr,
105 : : struct rte_event_timer **tim, const uint16_t nb_timers)
106 : : {
107 : : int ret;
108 : : uint16_t index;
109 : : struct tim_mem_entry entry;
110 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
111 [ # # ]: 0 : for (index = 0; index < nb_timers; index++) {
112 [ # # ]: 0 : if (timvf_timer_reg_checks(timr, tim[index]))
113 : : break;
114 : : timvf_format_event(tim[index], &entry);
115 : 0 : ret = timvf_add_entry_mp(timr, tim[index]->timeout_ticks,
116 : : tim[index], &entry);
117 [ # # ]: 0 : if (unlikely(ret)) {
118 : 0 : rte_errno = -ret;
119 : 0 : break;
120 : : }
121 : : }
122 : :
123 : 0 : return index;
124 : : }
125 : :
126 : : uint16_t
127 : 0 : timvf_timer_arm_burst_mp_stats(const struct rte_event_timer_adapter *adptr,
128 : : struct rte_event_timer **tim, const uint16_t nb_timers)
129 : : {
130 : : uint16_t ret;
131 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
132 : :
133 : 0 : ret = timvf_timer_arm_burst_mp(adptr, tim, nb_timers);
134 : 0 : timr->tim_arm_cnt += ret;
135 : :
136 : 0 : return ret;
137 : : }
138 : :
139 : : uint16_t
140 : 0 : timvf_timer_arm_tmo_brst(const struct rte_event_timer_adapter *adptr,
141 : : struct rte_event_timer **tim, const uint64_t timeout_tick,
142 : : const uint16_t nb_timers)
143 : : {
144 : : int ret;
145 : : uint16_t set_timers = 0;
146 : : uint16_t idx;
147 : : uint16_t arr_idx = 0;
148 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
149 : : alignas(RTE_CACHE_LINE_SIZE) struct tim_mem_entry entry[TIMVF_MAX_BURST];
150 : :
151 [ # # # # ]: 0 : if (unlikely(!timeout_tick || timeout_tick >= timr->nb_bkts)) {
152 : : const enum rte_event_timer_state state = timeout_tick ?
153 [ # # ]: 0 : RTE_EVENT_TIMER_ERROR_TOOLATE :
154 : : RTE_EVENT_TIMER_ERROR_TOOEARLY;
155 [ # # ]: 0 : for (idx = 0; idx < nb_timers; idx++)
156 : 0 : tim[idx]->state = state;
157 : 0 : rte_errno = EINVAL;
158 : 0 : return 0;
159 : : }
160 : :
161 [ # # ]: 0 : while (arr_idx < nb_timers) {
162 [ # # ]: 0 : for (idx = 0; idx < TIMVF_MAX_BURST && (arr_idx < nb_timers);
163 : 0 : idx++, arr_idx++) {
164 : 0 : timvf_format_event(tim[arr_idx], &entry[idx]);
165 : : }
166 : 0 : ret = timvf_add_entry_brst(timr, timeout_tick, &tim[set_timers],
167 : : entry, idx);
168 : 0 : set_timers += ret;
169 [ # # ]: 0 : if (ret != idx)
170 : : break;
171 : : }
172 : :
173 : : return set_timers;
174 : : }
175 : :
176 : :
177 : : uint16_t
178 : 0 : timvf_timer_arm_tmo_brst_stats(const struct rte_event_timer_adapter *adptr,
179 : : struct rte_event_timer **tim, const uint64_t timeout_tick,
180 : : const uint16_t nb_timers)
181 : : {
182 : : uint16_t set_timers;
183 : 0 : struct timvf_ring *timr = adptr->data->adapter_priv;
184 : :
185 : 0 : set_timers = timvf_timer_arm_tmo_brst(adptr, tim, timeout_tick,
186 : : nb_timers);
187 : 0 : timr->tim_arm_cnt += set_timers;
188 : :
189 : 0 : return set_timers;
190 : : }
191 : :
192 : : void
193 : 0 : timvf_set_chunk_refill(struct timvf_ring * const timr, uint8_t use_fpa)
194 : : {
195 [ # # ]: 0 : if (use_fpa)
196 : 0 : timr->refill_chunk = timvf_refill_chunk_fpa;
197 : : else
198 : 0 : timr->refill_chunk = timvf_refill_chunk_generic;
199 : 0 : }
|