]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2017 Cavium, Inc. | |
3 | * Copyright(c) 2017-2018 Intel Corporation. | |
4 | * All rights reserved. | |
5 | */ | |
6 | ||
7 | #ifndef __RTE_EVENT_TIMER_ADAPTER_H__ | |
8 | #define __RTE_EVENT_TIMER_ADAPTER_H__ | |
9 | ||
10 | /** | |
11 | * @file | |
12 | * | |
13 | * RTE Event Timer Adapter | |
14 | * | |
15 | * An event timer adapter has the following abstract working model: | |
16 | * | |
17 | * timer_tick_ns | |
18 | * + | |
19 | * +-------+ | | |
20 | * | | | | |
21 | * +-------+ bkt 0 +----v---+ | |
22 | * | | | | | |
23 | * | +-------+ | | |
24 | * +---+---+ +---+---+ +---+---+---+---+ | |
25 | * | | | | | | | | | | |
26 | * | bkt n | | bkt 1 |<-> t0| t1| t2| tn| | |
27 | * | | | | | | | | | | |
28 | * +---+---+ +---+---+ +---+---+---+---+ | |
29 | * | Timer adapter | | |
30 | * +---+---+ +---+---+ | |
31 | * | | | | | |
32 | * | bkt 4 | | bkt 2 |<--- Current bucket | |
33 | * | | | | | |
34 | * +---+---+ +---+---+ | |
35 | * | +-------+ | | |
36 | * | | | | | |
37 | * +------+ bkt 3 +-------+ | |
38 | * | | | |
39 | * +-------+ | |
40 | * | |
41 | * - It has a virtual monotonically increasing 64-bit timer adapter clock based | |
42 | * on *enum rte_event_timer_adapter_clk_src* clock source. The clock source | |
43 | * could be a CPU clock, or a platform dependent external clock. | |
44 | * | |
45 | * - The application creates a timer adapter instance with given the clock | |
46 | * source, the total number of event timers, and a resolution(expressed in ns) | |
47 | * to traverse between the buckets. | |
48 | * | |
49 | * - Each timer adapter may have 0 to n buckets based on the configured | |
50 | * max timeout(max_tmo_ns) and resolution(timer_tick_ns). Upon starting the | |
51 | * timer adapter, the adapter starts ticking at *timer_tick_ns* resolution. | |
52 | * | |
53 | * - The application arms an event timer that will expire *timer_tick_ns* | |
54 | * from now. | |
55 | * | |
56 | * - The application can cancel an armed timer and no timer expiry event will be | |
57 | * generated. | |
58 | * | |
59 | * - If a timer expires then the library injects the timer expiry event in | |
60 | * the designated event queue. | |
61 | * | |
62 | * - The timer expiry event will be received through *rte_event_dequeue_burst*. | |
63 | * | |
64 | * - The application frees the timer adapter instance. | |
65 | * | |
66 | * Multiple timer adapters can be created with a varying level of resolution | |
67 | * for various expiry use cases that run in parallel. | |
68 | * | |
69 | * Before using the timer adapter, the application has to create and configure | |
70 | * an event device along with the event port. Based on the event device | |
71 | * capability it might require creating an additional event port to be used | |
72 | * by the timer adapter. | |
73 | * | |
74 | * The application creates the event timer adapter using the | |
75 | * ``rte_event_timer_adapter_create()``. The event device id is passed to this | |
76 | * function, inside this function the event device capability is checked, | |
77 | * and if an in-built port is absent the application uses the default | |
78 | * function to create a new producer port. | |
79 | * | |
80 | * The application may also use the function | |
81 | * ``rte_event_timer_adapter_create_ext()`` to have granular control over | |
82 | * producer port creation in a case where the in-built port is absent. | |
83 | * | |
84 | * After creating the timer adapter, the application has to start it | |
85 | * using ``rte_event_timer_adapter_start()``. The buckets are traversed from | |
86 | * 0 to n; when the adapter ticks, the next bucket is visited. Each time, | |
87 | * the list per bucket is processed, and timer expiry events are sent to the | |
88 | * designated event queue. | |
89 | * | |
90 | * The application can arm one or more event timers using the | |
91 | * ``rte_event_timer_arm_burst()``. The *timeout_ticks* represents the number | |
92 | * of *timer_tick_ns* after which the timer has to expire. The timeout at | |
93 | * which the timers expire can be grouped or be independent of each | |
94 | * event timer instance. ``rte_event_timer_arm_tmo_tick_burst()`` addresses the | |
95 | * former case and ``rte_event_timer_arm_burst()`` addresses the latter case. | |
96 | * | |
97 | * The application can cancel the timers from expiring using the | |
98 | * ``rte_event_timer_cancel_burst()``. | |
99 | * | |
100 | * On the secondary process, ``rte_event_timer_adapter_lookup()`` can be used | |
101 | * to get the timer adapter pointer from its id and use it to invoke fastpath | |
102 | * operations such as arm and cancel. | |
103 | * | |
104 | * Some of the use cases of event timer adapter are Beacon Timers, | |
105 | * Generic SW Timeout, Wireless MAC Scheduling, 3G Frame Protocols, | |
106 | * Packet Scheduling, Protocol Retransmission Timers, Supervision Timers. | |
107 | * All these use cases require high resolution and low time drift. | |
108 | */ | |
109 | ||
110 | #ifdef __cplusplus | |
111 | extern "C" { | |
112 | #endif | |
113 | ||
114 | #include <rte_spinlock.h> | |
115 | #include <rte_memory.h> | |
116 | ||
117 | #include "rte_eventdev.h" | |
118 | ||
119 | /** | |
11fdf7f2 TL |
120 | * Timer adapter clock source |
121 | */ | |
122 | enum rte_event_timer_adapter_clk_src { | |
123 | RTE_EVENT_TIMER_ADAPTER_CPU_CLK, | |
124 | /**< Use CPU clock as the clock source. */ | |
125 | RTE_EVENT_TIMER_ADAPTER_EXT_CLK0, | |
126 | /**< Platform dependent external clock source 0. */ | |
127 | RTE_EVENT_TIMER_ADAPTER_EXT_CLK1, | |
128 | /**< Platform dependent external clock source 1. */ | |
129 | RTE_EVENT_TIMER_ADAPTER_EXT_CLK2, | |
130 | /**< Platform dependent external clock source 2. */ | |
131 | RTE_EVENT_TIMER_ADAPTER_EXT_CLK3, | |
132 | /**< Platform dependent external clock source 3. */ | |
133 | }; | |
134 | ||
135 | #define RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES (1ULL << 0) | |
136 | /**< The event timer adapter implementation may have constraints on the | |
137 | * resolution (timer_tick_ns) and maximum timer expiry timeout(max_tmo_ns) | |
138 | * based on the given timer adapter or system. If this flag is set, the | |
139 | * implementation adjusts the resolution and maximum timeout to the best | |
140 | * possible configuration. On successful timer adapter creation, the | |
141 | * application can get the configured resolution and max timeout with | |
142 | * ``rte_event_timer_adapter_get_info()``. | |
143 | * | |
144 | * @see struct rte_event_timer_adapter_info::min_resolution_ns | |
145 | * @see struct rte_event_timer_adapter_info::max_tmo_ns | |
146 | */ | |
147 | #define RTE_EVENT_TIMER_ADAPTER_F_SP_PUT (1ULL << 1) | |
148 | /**< ``rte_event_timer_arm_burst()`` API to be used in single producer mode. | |
149 | * | |
150 | * @see struct rte_event_timer_adapter_conf::flags | |
151 | */ | |
152 | ||
153 | /** | |
11fdf7f2 TL |
154 | * Timer adapter configuration structure |
155 | */ | |
156 | struct rte_event_timer_adapter_conf { | |
157 | uint8_t event_dev_id; | |
158 | /**< Event device identifier */ | |
159 | uint16_t timer_adapter_id; | |
160 | /**< Event timer adapter identifier */ | |
161 | uint32_t socket_id; | |
162 | /**< Identifier of socket from which to allocate memory for adapter */ | |
163 | enum rte_event_timer_adapter_clk_src clk_src; | |
164 | /**< Clock source for timer adapter */ | |
165 | uint64_t timer_tick_ns; | |
166 | /**< Timer adapter resolution in ns */ | |
167 | uint64_t max_tmo_ns; | |
168 | /**< Maximum timer timeout(expiry) in ns */ | |
169 | uint64_t nb_timers; | |
170 | /**< Total number of timers per adapter */ | |
171 | uint64_t flags; | |
172 | /**< Timer adapter config flags (RTE_EVENT_TIMER_ADAPTER_F_*) */ | |
173 | }; | |
174 | ||
175 | /** | |
11fdf7f2 TL |
176 | * Event timer adapter stats structure |
177 | */ | |
178 | struct rte_event_timer_adapter_stats { | |
179 | uint64_t evtim_exp_count; | |
180 | /**< Number of event timers that have expired. */ | |
181 | uint64_t ev_enq_count; | |
182 | /**< Eventdev enqueue count */ | |
183 | uint64_t ev_inv_count; | |
184 | /**< Invalid expiry event count */ | |
185 | uint64_t evtim_retry_count; | |
186 | /**< Event timer retry count */ | |
187 | uint64_t adapter_tick_count; | |
188 | /**< Tick count for the adapter, at its resolution */ | |
189 | }; | |
190 | ||
191 | struct rte_event_timer_adapter; | |
192 | ||
193 | /** | |
11fdf7f2 TL |
194 | * Callback function type for producer port creation. |
195 | */ | |
196 | typedef int (*rte_event_timer_adapter_port_conf_cb_t)(uint16_t id, | |
197 | uint8_t event_dev_id, | |
198 | uint8_t *event_port_id, | |
199 | void *conf_arg); | |
200 | ||
201 | /** | |
11fdf7f2 TL |
202 | * Create an event timer adapter. |
203 | * | |
204 | * This function must be invoked first before any other function in the API. | |
205 | * | |
206 | * @param conf | |
207 | * The event timer adapter configuration structure. | |
208 | * | |
209 | * @return | |
210 | * A pointer to the new allocated event timer adapter on success. | |
211 | * NULL on error with rte_errno set appropriately. | |
212 | * Possible rte_errno values include: | |
213 | * - ERANGE: timer_tick_ns is not in supported range. | |
214 | * - ENOMEM: unable to allocate sufficient memory for adapter instances | |
215 | * - EINVAL: invalid event device identifier specified in config | |
216 | * - ENOSPC: maximum number of adapters already created | |
217 | * - EIO: event device reconfiguration and restart error. The adapter | |
218 | * reconfigures the event device with an additional port by default if it is | |
219 | * required to use a service to manage timers. If the device had been started | |
220 | * before this call, this error code indicates an error in restart following | |
221 | * an error in reconfiguration, i.e., a combination of the two error codes. | |
222 | */ | |
9f95a23c | 223 | struct rte_event_timer_adapter * |
11fdf7f2 TL |
224 | rte_event_timer_adapter_create(const struct rte_event_timer_adapter_conf *conf); |
225 | ||
226 | /** | |
11fdf7f2 TL |
227 | * Create a timer adapter with the supplied callback. |
228 | * | |
229 | * This function can be used to have a more granular control over the timer | |
230 | * adapter creation. If a built-in port is absent, then the function uses the | |
231 | * callback provided to create and get the port id to be used as a producer | |
232 | * port. | |
233 | * | |
234 | * @param conf | |
235 | * The timer adapter configuration structure | |
236 | * @param conf_cb | |
237 | * The port config callback function. | |
238 | * @param conf_arg | |
239 | * Opaque pointer to the argument for the callback function | |
240 | * | |
241 | * @return | |
242 | * A pointer to the new allocated event timer adapter on success. | |
243 | * NULL on error with rte_errno set appropriately. | |
244 | * Possible rte_errno values include: | |
245 | * - ERANGE: timer_tick_ns is not in supported range. | |
246 | * - ENOMEM: unable to allocate sufficient memory for adapter instances | |
247 | * - EINVAL: invalid event device identifier specified in config | |
248 | * - ENOSPC: maximum number of adapters already created | |
249 | */ | |
9f95a23c | 250 | struct rte_event_timer_adapter * |
11fdf7f2 TL |
251 | rte_event_timer_adapter_create_ext( |
252 | const struct rte_event_timer_adapter_conf *conf, | |
253 | rte_event_timer_adapter_port_conf_cb_t conf_cb, | |
254 | void *conf_arg); | |
255 | ||
256 | /** | |
11fdf7f2 TL |
257 | * Timer adapter info structure. |
258 | */ | |
259 | struct rte_event_timer_adapter_info { | |
260 | uint64_t min_resolution_ns; | |
261 | /**< Minimum timer adapter resolution in ns */ | |
262 | uint64_t max_tmo_ns; | |
263 | /**< Maximum timer timeout(expire) in ns */ | |
264 | struct rte_event_timer_adapter_conf conf; | |
265 | /**< Configured timer adapter attributes */ | |
266 | uint32_t caps; | |
267 | /**< Event timer adapter capabilities */ | |
268 | int16_t event_dev_port_id; | |
269 | /**< Event device port ID, if applicable */ | |
270 | }; | |
271 | ||
272 | /** | |
11fdf7f2 TL |
273 | * Retrieve the contextual information of an event timer adapter. |
274 | * | |
275 | * @param adapter | |
276 | * A pointer to the event timer adapter structure. | |
277 | * | |
278 | * @param[out] adapter_info | |
279 | * A pointer to a structure of type *rte_event_timer_adapter_info* to be | |
280 | * filled with the contextual information of the adapter. | |
281 | * | |
282 | * @return | |
283 | * - 0: Success, driver updates the contextual information of the | |
284 | * timer adapter | |
285 | * - <0: Error code returned by the driver info get function. | |
286 | * - -EINVAL: adapter identifier invalid | |
287 | * | |
288 | * @see RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES, | |
289 | * struct rte_event_timer_adapter_info | |
290 | * | |
291 | */ | |
9f95a23c | 292 | int |
11fdf7f2 TL |
293 | rte_event_timer_adapter_get_info( |
294 | const struct rte_event_timer_adapter *adapter, | |
295 | struct rte_event_timer_adapter_info *adapter_info); | |
296 | ||
297 | /** | |
11fdf7f2 TL |
298 | * Start a timer adapter. |
299 | * | |
300 | * The adapter start step is the last one and consists of setting the timer | |
301 | * adapter to start accepting the timers and schedules to event queues. | |
302 | * | |
303 | * On success, all basic functions exported by the API (timer arm, | |
304 | * timer cancel and so on) can be invoked. | |
305 | * | |
306 | * @param adapter | |
307 | * A pointer to the event timer adapter structure. | |
308 | * | |
309 | * @return | |
310 | * - 0: Success, adapter started. | |
311 | * - <0: Error code returned by the driver start function. | |
312 | * - -EINVAL if adapter identifier invalid | |
313 | * - -ENOENT if software adapter but no service core mapped | |
314 | * - -ENOTSUP if software adapter and more than one service core mapped | |
9f95a23c TL |
315 | * - -EALREADY if adapter has already been started |
316 | * | |
317 | * @note | |
318 | * The eventdev to which the event_timer_adapter is connected needs to | |
319 | * be started before calling rte_event_timer_adapter_start(). | |
11fdf7f2 | 320 | */ |
9f95a23c | 321 | int |
11fdf7f2 TL |
322 | rte_event_timer_adapter_start( |
323 | const struct rte_event_timer_adapter *adapter); | |
324 | ||
325 | /** | |
11fdf7f2 TL |
326 | * Stop an event timer adapter. |
327 | * | |
328 | * The adapter can be restarted with a call to | |
329 | * ``rte_event_timer_adapter_start()``. | |
330 | * | |
331 | * @param adapter | |
332 | * A pointer to the event timer adapter structure. | |
333 | * | |
334 | * @return | |
335 | * - 0: Success, adapter stopped. | |
336 | * - <0: Error code returned by the driver stop function. | |
337 | * - -EINVAL if adapter identifier invalid | |
338 | */ | |
9f95a23c | 339 | int |
11fdf7f2 TL |
340 | rte_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter); |
341 | ||
342 | /** | |
11fdf7f2 TL |
343 | * Lookup an event timer adapter using its identifier. |
344 | * | |
345 | * If an event timer adapter was created in another process with the same | |
346 | * identifier, this function will locate its state and set up access to it | |
347 | * so that it can be used in this process. | |
348 | * | |
349 | * @param adapter_id | |
350 | * The event timer adapter identifier. | |
351 | * | |
352 | * @return | |
353 | * A pointer to the event timer adapter matching the identifier on success. | |
354 | * NULL on error with rte_errno set appropriately. | |
355 | * Possible rte_errno values include: | |
356 | * - ENOENT - requested entry not available to return. | |
357 | */ | |
9f95a23c | 358 | struct rte_event_timer_adapter * |
11fdf7f2 TL |
359 | rte_event_timer_adapter_lookup(uint16_t adapter_id); |
360 | ||
361 | /** | |
11fdf7f2 TL |
362 | * Free an event timer adapter. |
363 | * | |
364 | * Destroy an event timer adapter, freeing all resources. | |
365 | * | |
366 | * Before invoking this function, the application must wait for all the | |
367 | * armed timers to expire or cancel the outstanding armed timers. | |
368 | * | |
369 | * @param adapter | |
370 | * A pointer to an event timer adapter structure. | |
371 | * | |
372 | * @return | |
373 | * - 0: Successfully freed the event timer adapter resources. | |
374 | * - <0: Failed to free the event timer adapter resources. | |
375 | * - -EAGAIN: adapter is busy; timers outstanding | |
376 | * - -EBUSY: stop hasn't been called for this adapter yet | |
377 | * - -EINVAL: adapter id invalid, or adapter invalid | |
378 | */ | |
9f95a23c | 379 | int |
11fdf7f2 TL |
380 | rte_event_timer_adapter_free(struct rte_event_timer_adapter *adapter); |
381 | ||
382 | /** | |
383 | * Retrieve the service ID of the event timer adapter. If the adapter doesn't | |
384 | * use an rte_service function, this function returns -ESRCH. | |
385 | * | |
386 | * @param adapter | |
387 | * A pointer to an event timer adapter. | |
388 | * | |
389 | * @param [out] service_id | |
390 | * A pointer to a uint32_t, to be filled in with the service id. | |
391 | * | |
392 | * @return | |
393 | * - 0: Success | |
394 | * - <0: Error code on failure | |
395 | * - -ESRCH: the adapter does not require a service to operate | |
396 | */ | |
9f95a23c | 397 | int |
11fdf7f2 TL |
398 | rte_event_timer_adapter_service_id_get(struct rte_event_timer_adapter *adapter, |
399 | uint32_t *service_id); | |
400 | ||
401 | /** | |
11fdf7f2 TL |
402 | * Retrieve statistics for an event timer adapter instance. |
403 | * | |
404 | * @param adapter | |
405 | * A pointer to an event timer adapter structure. | |
406 | * @param[out] stats | |
407 | * A pointer to a structure to fill with statistics. | |
408 | * | |
409 | * @return | |
410 | * - 0: Successfully retrieved. | |
411 | * - <0: Failure; error code returned. | |
412 | */ | |
9f95a23c | 413 | int |
11fdf7f2 TL |
414 | rte_event_timer_adapter_stats_get(struct rte_event_timer_adapter *adapter, |
415 | struct rte_event_timer_adapter_stats *stats); | |
416 | ||
417 | /** | |
11fdf7f2 TL |
418 | * Reset statistics for an event timer adapter instance. |
419 | * | |
420 | * @param adapter | |
421 | * A pointer to an event timer adapter structure. | |
422 | * | |
423 | * @return | |
424 | * - 0: Successfully reset; | |
425 | * - <0: Failure; error code returned. | |
426 | */ | |
11fdf7f2 | 427 | int |
9f95a23c | 428 | rte_event_timer_adapter_stats_reset(struct rte_event_timer_adapter *adapter); |
11fdf7f2 TL |
429 | |
430 | /** | |
11fdf7f2 TL |
431 | * Event timer state. |
432 | */ | |
433 | enum rte_event_timer_state { | |
434 | RTE_EVENT_TIMER_NOT_ARMED = 0, | |
435 | /**< Event timer not armed. */ | |
436 | RTE_EVENT_TIMER_ARMED = 1, | |
437 | /**< Event timer successfully armed. */ | |
438 | RTE_EVENT_TIMER_CANCELED = 2, | |
439 | /**< Event timer successfully canceled. */ | |
440 | RTE_EVENT_TIMER_ERROR = -1, | |
441 | /**< Generic event timer error. */ | |
442 | RTE_EVENT_TIMER_ERROR_TOOEARLY = -2, | |
443 | /**< Event timer timeout tick value is too small for the adapter to | |
444 | * handle, given its configured resolution. | |
445 | */ | |
446 | RTE_EVENT_TIMER_ERROR_TOOLATE = -3, | |
447 | /**< Event timer timeout tick is greater than the maximum timeout.*/ | |
448 | }; | |
449 | ||
450 | /** | |
11fdf7f2 TL |
451 | * The generic *rte_event_timer* structure to hold the event timer attributes |
452 | * for arm and cancel operations. | |
453 | */ | |
454 | RTE_STD_C11 | |
455 | struct rte_event_timer { | |
456 | struct rte_event ev; | |
457 | /**< | |
458 | * Expiry event attributes. On successful event timer timeout, | |
459 | * the following attributes will be used to inject the expiry event to | |
460 | * the eventdev: | |
461 | * - event_queue_id: Targeted event queue id for expiry events. | |
462 | * - event_priority: Event priority of the event expiry event in the | |
463 | * event queue relative to other events. | |
464 | * - sched_type: Scheduling type of the expiry event. | |
465 | * - flow_id: Flow id of the expiry event. | |
466 | * - op: RTE_EVENT_OP_NEW | |
467 | * - event_type: RTE_EVENT_TYPE_TIMER | |
468 | */ | |
469 | volatile enum rte_event_timer_state state; | |
470 | /**< State of the event timer. */ | |
471 | uint64_t timeout_ticks; | |
472 | /**< Expiry timer ticks expressed in number of *timer_ticks_ns* from | |
473 | * now. | |
474 | * @see struct rte_event_timer_adapter_info::adapter_conf::timer_tick_ns | |
475 | */ | |
476 | uint64_t impl_opaque[2]; | |
477 | /**< Implementation-specific opaque data. | |
478 | * An event timer adapter implementation use this field to hold | |
479 | * implementation specific values to share between the arm and cancel | |
480 | * operations. The application should not modify this field. | |
481 | */ | |
482 | uint8_t user_meta[0]; | |
483 | /**< Memory to store user specific metadata. | |
484 | * The event timer adapter implementation should not modify this area. | |
485 | */ | |
486 | } __rte_cache_aligned; | |
487 | ||
488 | typedef uint16_t (*rte_event_timer_arm_burst_t)( | |
489 | const struct rte_event_timer_adapter *adapter, | |
490 | struct rte_event_timer **tims, | |
491 | uint16_t nb_tims); | |
492 | /**< @internal Enable event timers to enqueue timer events upon expiry */ | |
493 | typedef uint16_t (*rte_event_timer_arm_tmo_tick_burst_t)( | |
494 | const struct rte_event_timer_adapter *adapter, | |
495 | struct rte_event_timer **tims, | |
496 | uint64_t timeout_tick, | |
497 | uint16_t nb_tims); | |
498 | /**< @internal Enable event timers with common expiration time */ | |
499 | typedef uint16_t (*rte_event_timer_cancel_burst_t)( | |
500 | const struct rte_event_timer_adapter *adapter, | |
501 | struct rte_event_timer **tims, | |
502 | uint16_t nb_tims); | |
503 | /**< @internal Prevent event timers from enqueuing timer events */ | |
504 | ||
505 | /** | |
506 | * @internal Data structure associated with each event timer adapter. | |
507 | */ | |
508 | struct rte_event_timer_adapter { | |
509 | rte_event_timer_arm_burst_t arm_burst; | |
510 | /**< Pointer to driver arm_burst function. */ | |
511 | rte_event_timer_arm_tmo_tick_burst_t arm_tmo_tick_burst; | |
512 | /**< Pointer to driver arm_tmo_tick_burst function. */ | |
513 | rte_event_timer_cancel_burst_t cancel_burst; | |
514 | /**< Pointer to driver cancel function. */ | |
515 | struct rte_event_timer_adapter_data *data; | |
516 | /**< Pointer to shared adapter data */ | |
517 | const struct rte_event_timer_adapter_ops *ops; | |
518 | /**< Functions exported by adapter driver */ | |
519 | ||
520 | RTE_STD_C11 | |
521 | uint8_t allocated : 1; | |
522 | /**< Flag to indicate that this adapter has been allocated */ | |
523 | } __rte_cache_aligned; | |
524 | ||
525 | #define ADAPTER_VALID_OR_ERR_RET(adapter, retval) do { \ | |
526 | if (adapter == NULL || !adapter->allocated) \ | |
527 | return retval; \ | |
528 | } while (0) | |
529 | ||
530 | #define FUNC_PTR_OR_ERR_RET(func, errval) do { \ | |
531 | if ((func) == NULL) \ | |
532 | return errval; \ | |
533 | } while (0) | |
534 | ||
535 | #define FUNC_PTR_OR_NULL_RET_WITH_ERRNO(func, errval) do { \ | |
536 | if ((func) == NULL) { \ | |
537 | rte_errno = errval; \ | |
538 | return NULL; \ | |
539 | } \ | |
540 | } while (0) | |
541 | ||
542 | /** | |
11fdf7f2 TL |
543 | * Arm a burst of event timers with separate expiration timeout tick for each |
544 | * event timer. | |
545 | * | |
546 | * Before calling this function, the application allocates | |
547 | * ``struct rte_event_timer`` objects from mempool or huge page backed | |
548 | * application buffers of desired size. On successful allocation, | |
549 | * application updates the `struct rte_event_timer`` attributes such as | |
550 | * expiry event attributes, timeout ticks from now. | |
551 | * This function submits the event timer arm requests to the event timer adapter | |
552 | * and on expiry, the events will be injected to designated event queue. | |
553 | * | |
554 | * @param adapter | |
555 | * A pointer to an event timer adapter structure. | |
556 | * @param evtims | |
557 | * Pointer to an array of objects of type *rte_event_timer* structure. | |
558 | * @param nb_evtims | |
559 | * Number of event timers in the supplied array. | |
560 | * | |
561 | * @return | |
562 | * The number of successfully armed event timers. The return value can be less | |
563 | * than the value of the *nb_evtims* parameter. If the return value is less | |
564 | * than *nb_evtims*, the remaining event timers at the end of *evtims* | |
565 | * are not consumed, and the caller has to take care of them, and rte_errno | |
566 | * is set accordingly. Possible errno values include: | |
567 | * - EINVAL Invalid timer adapter, expiry event queue ID is invalid, or an | |
568 | * expiry event's sched type doesn't match the capabilities of the | |
569 | * destination event queue. | |
570 | * - EAGAIN Specified timer adapter is not running | |
571 | * - EALREADY A timer was encountered that was already armed | |
572 | */ | |
9f95a23c | 573 | static inline uint16_t |
11fdf7f2 TL |
574 | rte_event_timer_arm_burst(const struct rte_event_timer_adapter *adapter, |
575 | struct rte_event_timer **evtims, | |
576 | uint16_t nb_evtims) | |
577 | { | |
578 | #ifdef RTE_LIBRTE_EVENTDEV_DEBUG | |
579 | ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); | |
580 | FUNC_PTR_OR_ERR_RET(adapter->arm_burst, -EINVAL); | |
581 | #endif | |
582 | return adapter->arm_burst(adapter, evtims, nb_evtims); | |
583 | } | |
584 | ||
585 | /** | |
11fdf7f2 TL |
586 | * Arm a burst of event timers with same expiration timeout tick. |
587 | * | |
588 | * Provides the same functionality as ``rte_event_timer_arm_burst()``, except | |
589 | * that application can use this API when all the event timers have the | |
590 | * same timeout expiration tick. This specialized function can provide the | |
591 | * additional hint to the adapter implementation and optimize if possible. | |
592 | * | |
593 | * @param adapter | |
594 | * A pointer to an event timer adapter structure. | |
595 | * @param evtims | |
596 | * Points to an array of objects of type *rte_event_timer* structure. | |
597 | * @param timeout_ticks | |
598 | * The number of ticks in which the timers should expire. | |
599 | * @param nb_evtims | |
600 | * Number of event timers in the supplied array. | |
601 | * | |
602 | * @return | |
603 | * The number of successfully armed event timers. The return value can be less | |
604 | * than the value of the *nb_evtims* parameter. If the return value is less | |
605 | * than *nb_evtims*, the remaining event timers at the end of *evtims* | |
606 | * are not consumed, and the caller has to take care of them, and rte_errno | |
607 | * is set accordingly. Possible errno values include: | |
608 | * - EINVAL Invalid timer adapter, expiry event queue ID is invalid, or an | |
609 | * expiry event's sched type doesn't match the capabilities of the | |
610 | * destination event queue. | |
611 | * - EAGAIN Specified event timer adapter is not running | |
612 | * - EALREADY A timer was encountered that was already armed | |
613 | */ | |
9f95a23c | 614 | static inline uint16_t |
11fdf7f2 TL |
615 | rte_event_timer_arm_tmo_tick_burst( |
616 | const struct rte_event_timer_adapter *adapter, | |
617 | struct rte_event_timer **evtims, | |
618 | const uint64_t timeout_ticks, | |
619 | const uint16_t nb_evtims) | |
620 | { | |
621 | #ifdef RTE_LIBRTE_EVENTDEV_DEBUG | |
622 | ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); | |
623 | FUNC_PTR_OR_ERR_RET(adapter->arm_tmo_tick_burst, -EINVAL); | |
624 | #endif | |
625 | return adapter->arm_tmo_tick_burst(adapter, evtims, timeout_ticks, | |
626 | nb_evtims); | |
627 | } | |
628 | ||
629 | /** | |
11fdf7f2 TL |
630 | * Cancel a burst of event timers from being scheduled to the event device. |
631 | * | |
632 | * @param adapter | |
633 | * A pointer to an event timer adapter structure. | |
634 | * @param evtims | |
635 | * Points to an array of objects of type *rte_event_timer* structure | |
636 | * @param nb_evtims | |
637 | * Number of event timer instances in the supplied array. | |
638 | * | |
639 | * @return | |
640 | * The number of successfully canceled event timers. The return value can be | |
641 | * less than the value of the *nb_evtims* parameter. If the return value is | |
642 | * less than *nb_evtims*, the remaining event timers at the end of *evtims* | |
643 | * are not consumed, and the caller has to take care of them, and rte_errno | |
644 | * is set accordingly. Possible errno values include: | |
645 | * - EINVAL Invalid timer adapter identifier | |
646 | * - EAGAIN Specified timer adapter is not running | |
647 | * - EALREADY A timer was encountered that was already canceled | |
648 | */ | |
9f95a23c | 649 | static inline uint16_t |
11fdf7f2 TL |
650 | rte_event_timer_cancel_burst(const struct rte_event_timer_adapter *adapter, |
651 | struct rte_event_timer **evtims, | |
652 | uint16_t nb_evtims) | |
653 | { | |
654 | #ifdef RTE_LIBRTE_EVENTDEV_DEBUG | |
655 | ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); | |
656 | FUNC_PTR_OR_ERR_RET(adapter->cancel_burst, -EINVAL); | |
657 | #endif | |
658 | return adapter->cancel_burst(adapter, evtims, nb_evtims); | |
659 | } | |
660 | ||
661 | #endif /* __RTE_EVENT_TIMER_ADAPTER_H__ */ |