EM-ODP  3.7.0
Event Machine on ODP
api/event_machine_timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2024, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef EVENT_MACHINE_TIMER_H_
31 #define EVENT_MACHINE_TIMER_H_
32 
33 #pragma GCC visibility push(default)
34 
35 /**
36  * @file
37  * Event Machine timer
38  * @defgroup em_timer Event timer
39  * Event Machine timer
40  * @{
41  *
42  * The timer API can be used to request an event to be sent to a specified
43  * queue at a specified time once (one-shot) or at regular intervals (periodic).
44  * A timer needs to be created first - it represents a collection of timeouts
45  * with certain attributes (e.g. timeout resolution and maximum period).
46  * A timer can be mapped to a HW resource on an SoC, thus the number of timers,
47  * capabilities and time bases are system specific. Typically only a few
48  * timers are supported.
49  * The application can specify required capabilities when a timer is created.
50  * The creation will fail if the implementation cannot fulfill the required
51  * values. Timers are typically created once at system startup.
52  *
53  * A timer is a shared resource with proper synchronization for concurrent
54  * multi-thread use. It is possible to exclude all multi-thread protections if a
55  * timer is used exclusively by a single thread (for potential performance
56  * gains). This is done by setting EM_TIMER_FLAG_PRIVATE when creating a timer.
57  * Setting this flag means that the application must ensure that only a single
58  * thread is using the timer (this also includes the receiver of periodic
59  * timeouts due to the ack-functionality). This private-mode is not necessarily
60  * implemented on all systems, in which case the flag is ignored as it will not
61  * cause any functional difference.
62  *
63  * Timeouts (tmo) can be created once a timer exists. Creating a timeout
64  * allocates the resources needed to serve the timeout, but does not arm it.
65  * This makes it possible to pre-create timeout(s) and set the expiry
66  * later at runtime. This can improve performance but also minimizes the
67  * possibility that the runtime call setting the expiry would fail, as resources
68  * have already been reserved beforehand.
69  *
70  * A pending timeout can be cancelled. Note that there is no way to cancel an
71  * expired timeout for which the event has already been sent but not yet
72  * received by the application. Canceling in this case will return an error
73  * to enable the application to detect the situation. For a periodic timer,
74  * a cancel will stop further timeouts, but may not be able to prevent the
75  * latest event from being received. An active timeout cannot be altered without
76  * canceling it first.
77  *
78  * A timeout can be re-used after it has been received or successfully
79  * cancelled. Timeouts need to be deleted after use. Deletion frees the
80  * resources reserved during creation.
81  *
82  * The timeout value is an abstract system and timer dependent tick count.
83  * It is assumed that the tick count increases with a static frequency.
84  * The frequency can be inquired at runtime for time calculations, e.g. tick
85  * frequency divided by 1000 gives ticks for 1ms. Tick frequency is at least
86  * equal to the resolution, but can also be higher (implementation can quantize
87  * ticks to any underlying implementation). Supported resolution can also be
88  * inquired.
89  * A clock source can be specified when creating a timer. It defines the time
90  * base of the timer for systems with multiple sources implemented (optional).
91  * EM_TIMER_CLKSRC_DEFAULT is a portable value that implements a basic
92  * monotonic time, that will not wrap back to zero in any reasonable uptime.
93  *
94  * The major event types EM_EVENT_TYPE_SW, EM_EVENT_TYPE_PACKET and
95  * EM_EVENT_TYPE_TIMER can be used as a timeout indication. The type
96  * EM_EVENT_TYPE_TIMER is alternative to EM_EVENT_TYPE_SW and works the same
97  * way. Additionally for ring timer only, the type EM_EVENT_TYPE_TIMER_IND
98  * is used. This is a special indication event without visible payload.
99  *
100  * A periodic timer requires the application to acknowledge each received
101  * timeout event after it has been processed. The acknowledgment activates the
102  * next timeout and compensates for the processing delay to keep the original
103  * interval. This creates a flow control mechanism and also protects the event
104  * handling from races if the same event is reused every time, the next
105  * timeout will not be sent before the previous has been acknowledged.
106  * The event to be received for each periodic timeout can also be different as
107  * the next event is given by the application with the acknowledge.
108  * The target queue cannot be modified after the timeout has been created.
109  *
110  * If the acknowledgment of a periodic timeout is done too late (after the next
111  * period has already passed), the default action is to skip the missed timeout
112  * slot(s) and arm for the next valid slot. If the application never wants to
113  * skip a missed timeout it can set the flag EM_TMO_FLAG_NOSKIP when creating a
114  * timeout. This causes each acknowledgment to schedule an immediate timeout
115  * event until all the missed time slots have been served. This keeps the number
116  * of timeouts as expected but may cause an event storm if a long processing
117  * delay has occurred.
118  *
119  * The timeout handle is needed when acknowledging a periodic timeout event.
120  * Because any event can be used for the timeout, the application must itself
121  * provide a way to derive the timeout handle from the received timeout event.
122  * A typical way is to include the tmo handle within the timeout event.
123  * Application also needs to have a mechanism to detect which event is a
124  * periodic timeout to be able to call acknowledge.
125  *
126  * If the timeout tick value given to timeout start points to the past or is too
127  * close to current time then error code EM_ERR_TOONEAR is returned. In this
128  * case EM will not call error handler to let application decide whether
129  * it is an error or if it will try again with updated target time.
130  *
131  * There is an alternative periodic ring timer. As it uses different abstraction
132  * it is created and started via separate ring specific APIs. It has three main
133  * differencies to the regular periodic timeouts:
134  * 1. Only a pre-defined read-only event type can be used and is provided
135  * by the timer (EM_EVENT_TYPE_TIMER_IND).
136  * 2. Flow control is not supported. Some implementations may have it,
137  * but the specification does not quarantee any so the user needs to be
138  * prepared to see the same event enqueued multiple times if handling of
139  * the received timeouts is not fast enough
140  * 2. A limited set of period times are supported per timer (base rate or
141  * an integer multiple of it only)
142  *
143  * Ring timers can be abstracted as a clock face ticking the pointer forward.
144  * One cycle around is the base rate (minimum rate). The same timeout can be
145  * inserted into multiple locations evenly spread within the clock face thus
146  * multiplying the base rate. The starting offset can be adjusted only up to
147  * one timeout period.
148  * Depending on platform, this mode may provide better integration with HW and
149  * thus have less runtime overhead. However, as it exposes a potential queue
150  * overflow and a race hazard (race avoidable by using atomic queue as target),
151  * the regular periodic timer is recommended as a default.
152  *
153  * Example usage
154  * @code
155  *
156  * // This would typically be done at application init.
157  * // Accept all defaults but change the name
158  * em_timer_attr_t attr;
159  * em_timer_attr_init(&attr);
160  * strncpy(attr.name, "myTimer", EM_TIMER_NAME_LEN);
161  * em_timer_t tmr = em_timer_create(&attr);
162  * if(tmr == EM_TIMER_UNDEF) {
163  * // handle error here or via error handler
164  * }
165  *
166  * // At runtime - create a timeout resource.
167  * // Can be done in advance to save time if the target queue is known.
168  * em_tmo_t tmo = em_tmo_create(tmr, EM_TIMER_FLAG_ONESHOT, target_queue);
169  * if(tmo == EM_TMO_UNDEF) {
170  * // no such timer or out of resources
171  * // handle error here or via error handler
172  * }
173  *
174  * // Get the timer tick frequency
175  * uint64_t hz = em_timer_get_freq(tmr);
176  *
177  * // Activate a 10ms timeout from now.
178  * // Very unlikely to fail with valid arguments.
179  * if (em_tmo_set_rel(tmo, hz / 100, my_tmo_event) != EM_OK) {
180  * // handle error here or via error handler
181  * }
182  *
183  * @endcode
184  *
185  */
186 #include <inttypes.h>
187 
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 
192 /** Deprecated
193  * Major EM Timer API version. Marks possibly backwards incompatible changes.
194  * EM timer is now part of EM API. Use EM_API_VERSION_MAJOR instead.
195  */
196 #define EM_TIMER_API_VERSION_MAJOR EM_API_VERSION_MAJOR
197 /** Deprecated
198  * Minor EM Timer API version. Marks possibly backwards incompatible changes.
199  * EM Timer is now part of EM API. Use EM_API_VERSION_MINOR instead.
200  */
201 #define EM_TIMER_API_VERSION_MINOR EM_API_VERSION_MINOR
202 
203 /**
204  * @typedef em_timer_t
205  * System specific type for a timer handle.
206  */
207 
208 /**
209  * @typedef em_tmo_t
210  * System specific type for a timeout handle.
211  */
212 
213 /**
214  * @typedef em_timer_flag_t
215  * System specific type for timer flags.
216  * This is system specific, but all implementations must define
217  * EM_TIMER_FLAG_DEFAULT and EM_TIMER_FLAG_PRIVATE, of which the latter is used
218  * to skip API synchronization for single threaded apps.
219  * Flags can be combined by bitwise OR.
220  */
221 
222 /**
223  * @typedef em_tmo_flag_t
224  * System specific enum type for timeout flags.
225  * This is system specific, but all implementations must define
226  * EM_TMO_FLAG_ONESHOT, EM_TMO_FLAG_PERIODIC and EM_TMO_FLAG_NOSKIP.
227  * Flags can be combined by bitwise OR.
228  */
229 
230 /**
231  * @typedef em_timer_clksrc_t
232  * System specific enum type for timer clock source.
233  * This is system specific, but all implementations must define
234  * EM_TIMER_CLKSRC_DEFAULT.
235  */
236 
237 /**
238  * Visible state of a timeout
239  */
240 typedef enum em_tmo_state_t {
241  EM_TMO_STATE_UNKNOWN = 0,
242  EM_TMO_STATE_IDLE = 1, /**< just created or canceled */
243  EM_TMO_STATE_ACTIVE = 2, /**< armed */
244  EM_TMO_STATE_INACTIVE = 3 /**< oneshot expired */
246 
247 /**
248  * Type returned by em_tmo_get_type()
249  */
250 typedef enum em_tmo_type_t {
251  EM_TMO_TYPE_NONE = 0, /**< unknown or not timer-related event */
252  EM_TMO_TYPE_ONESHOT = 1, /**< event is oneshot timeout indication */
253  EM_TMO_TYPE_PERIODIC = 2, /**< event is periodic timeout indication */
254 } em_tmo_type_t;
255 
256 /**
257  * The timer tick has HW and timer specific meaning, but the type is always a
258  * 64-bit integer and is normally assumed to be monotonic and not to wrap
259  * around. Exceptions with exotic extra timers should be clearly documented.
260  */
261 typedef uint64_t em_timer_tick_t;
262 
263 /**
264  * Fractional 64-bit unsigned value for timer frequency.
265  *
266  */
267 typedef struct em_fract_u64_t {
268  /** Int */
269  uint64_t integer;
270 
271  /** Numerator. Set 0 for integers */
272  uint64_t numer;
273 
274  /** Denominator */
275  uint64_t denom;
277 
278 /**
279  * Type for timer resolution parameters
280  *
281  * This structure is used to group timer resolution parameters that may
282  * affect each other.
283  * All time values are ns.
284  *
285  * @note This is used both as capability and configuration. When used as configuration
286  * either res_ns or res_hz must be 0 (for em_timer_create).
287  * @see em_timer_capability, em_timer_create
288  */
289 typedef struct em_timer_res_param_t {
290  /** Clock source (system specific) */
292  /** resolution, ns */
293  uint64_t res_ns;
294  /** resolution, hz */
295  uint64_t res_hz;
296  /** minimum timeout, ns */
297  uint64_t min_tmo;
298  /** maximum timeout, ns */
299  uint64_t max_tmo;
301 
302 /**
303  * Timer ring timing parameters.
304  *
305  */
306 typedef struct em_timer_ring_param_t {
307  /** Clock source (system specific) */
309  /** Base rate, i.e. minimum period rate */
311  /** Maximum base rate multiplier needed. 1 for single rate = base_hz */
312  uint64_t max_mul;
313  /** Resolution */
314  uint64_t res_ns;
316 
317 /**
318  * Structure used to create a timer or inquire its configuration later.
319  *
320  * This needs to be initialized with em_timer_attr_init(), which fills default
321  * values to each field. After that the values can be modified as needed.
322  * Values are considered a requirement, e.g. setting 'resparam.res_ns' to 1000(ns)
323  * requires at least 1us resolution. The timer creation will fail if the implementation
324  * cannot support such resolution (like only goes down to 1500ns).
325  * The implementation is free to provide better than requested, but not worse.
326  *
327  * To know the implementation specific limits use em_timer_capability and em_timer_res_capability.
328  *
329  * When creating the alternative periodic ring timer, this needs to be initialized
330  * with em_timer_ring_attr_init instead. EM_TIMER_FLAG_RING will be set by
331  * em_timer_ring_attr_init so it does not need to be manually set.
332  *
333  * @see em_timer_attr_init, em_timer_ring_attr_init, em_timer_capability
334  */
335 typedef struct em_timer_attr_t {
336  /** Resolution parameters. Set when not creating periodic ring.
337  * This gets cleared by em_timer_ring_attr_init
338  */
340  /** Maximum simultaneous timeouts */
341  uint32_t num_tmo;
342  /** Extra flags. A set flag is a requirement */
344  /** Optional name for this timer */
345  char name[EM_TIMER_NAME_LEN];
346 
347  /**
348  * used when creating alternative periodic ring timer.
349  * Cleared by em_timer_attr_init
350  */
352 
353  /**
354  * Internal check - don't touch!
355  *
356  * EM will verify that em_timer_attr_init() has been called before
357  * creating a timer
358  */
361 
362 /**
363  * Timeout statistics counters
364  *
365  * Some fields relate to periodic timeout only (0 on one-shots) and vice versa.
366  * New fields may be added later at the end.
367  */
368 typedef struct em_tmo_stats_t {
369  /** number of periodic ack() calls */
370  uint64_t num_acks;
371  /** number of delayed periodic ack() calls. 0 with ring timer */
372  uint64_t num_late_ack;
373  /** number of skipped periodic timeslots due to late ack. 0 with ring timer */
376 
377 /**
378  * Timer capability info
379  */
380 typedef struct em_timer_capability_t {
381  /** Number of supported timers of all types */
382  uint32_t max_timers;
383  /** Maximum number of simultaneous timeouts. 0 means only limited by memory */
384  uint32_t max_num_tmo;
385  /** Highest supported resolution and related limits for a timeout */
387  /** Longest supported timeout and related resolution */
389 
390  /** alternate periodic ring */
391  struct {
392  /** Maximum ring timers */
393  uint32_t max_rings;
394  /** Maximum simultaneous ring timeouts */
395  uint32_t max_num_tmo;
396  /** Minimum base_hz */
398  /** Minimum base_hz */
400  } ring;
401 
403 
404 /**
405  * tmo optional extra arguments
406  *
407  */
408 typedef struct em_tmo_args_t {
409  /** can be used with ring timer, see em_tmo_get_userptr */
410  void *userptr;
411 } em_tmo_args_t;
412 
413 /**
414  * Initialize em_timer_attr_t
415  *
416  * Initializes em_timer_attr_t to system specific default values.
417  * After initialization user can adjust the values as needed before
418  * calling em_timer_create. em_timer_capability() and/or em_timer_res_capability()
419  * can optionally be used to find valid values.
420  *
421  * Always initialize em_timer_attr_t with em_timer_attr_init before any use.
422  *
423  * This function will not trigger errorhandler calls internally.
424  *
425  * Example for all defaults
426  * @code
427  * em_timer_attr_t tmr_attr;
428  * em_timer_attr_init(&tmr_attr);
429  * em_timer_t tmr = em_timer_create(&tmr_attr);
430  * @endcode
431  *
432  * @param tmr_attr Pointer to em_timer_attr_t to be initialized
433  *
434  * @see em_timer_capability, em_timer_create
435  */
436 void em_timer_attr_init(em_timer_attr_t *tmr_attr);
437 
438 /**
439  * Initialize em_timer_ring_attr_t
440  *
441  * Initializes em_timer_ring_attr_t according to given values.
442  * After successful return the attributes can be given to em_timer_ring_create.
443  * Note, that if the implementation cannot use exact given combination it may
444  * update the ring_attr values, but always to meet or exceed given value.
445  * User can read the new values to determine if they were modified.
446  * Error is returned if given values cannot be met.
447  *
448  * Before creating the ring timer other values like num_tmo and name can be
449  * adjusted as needed. Also if non-integer frequency is needed the base_hz
450  * fractional part can be adjusted before timer_ring_create.
451  *
452  * This function will not trigger errorhandler calls.
453  *
454  * @param [out] ring_attr Pointer to em_timer_attr_t to be initialized
455  * @param clk_src Clock source to use (system specific or portable
456  * EM_TIMER_CLKSRC_DEFAULT)
457  * @param base_hz Base rate of the ring (minimum rate i.e. longest period)
458  * @param max_mul Maximum multiplier (maximum rate = base_hz * max_mul)
459  * @param res_ns Required resolution of the timing or 0 to accept default
460  *
461  * @return EM_OK if the given clk_src and other values are supported
462  *
463  * @see em_timer_ring_capability, em_timer_ring_create
464  */
466  em_timer_clksrc_t clk_src,
467  uint64_t base_hz,
468  uint64_t max_mul,
469  uint64_t res_ns);
470 
471 /**
472  * Inquire timer capabilities
473  *
474  * Returns timer capabilities for the given clock source, which is also written
475  * to both 'capa->max_res.clk_src' and 'capa->max_tmo.clk_src'.
476  * For resolution both 'res_ns' and 'res_hz' are filled.
477  *
478  * This function will not trigger errorhandler calls internally.
479  *
480  * @param capa pointer to em_timer_capability_t to be updated
481  * (does not need to be initialized)
482  * @param clk_src Clock source to use for timer
483  * (EM_TIMER_CLKSRC_DEFAULT for system specific default)
484  * @return EM_OK if the given clk_src is supported (capa updated)
485  *
486  * @see em_timer_capability_t, em_timer_res_capability
487  */
489 
490 /**
491  * Inquire timer capabilities for a specific resolution or maximum timeout
492  *
493  * Returns timer capabilities by given resolution or maximum timeout.
494  * Set one of resolution (res.res_ns) or maximum timeout (res.max_tmo) to required value
495  * and the other to zero and this will fill the other fields with valid limits.
496  * Error is returned if the given value is not supported.
497  * The given clk_src is used to set the values and also written to 'res->clk_src'.
498  * Both 'res_ns' and 'res_hz' are filled, so if this is passed to em_timer_create,
499  * one of those must be set to 0.
500  *
501  * Example for external clock maximum resolution
502  * @code
503  * em_timer_attr_t *tmr_attr;
504  * em_timer_capability_t capa;
505  *
506  * em_timer_attr_init(&tmr_attr);
507  * if (em_timer_capability(&capa, EM_TIMER_CLKSRC_EXT) != EM_OK) {
508  * // external clock not supported
509  * }
510  * tmr_attr.resparam = capa.max_res;
511  * tmr_attr.resparam.res_hz = 0;
512  * tmr = em_timer_create(&tmr_attr);
513  * @endcode
514  *
515  * This function will not trigger errorhandler calls internally.
516  *
517  * @param res Pointer to em_timer_res_param_t with one field set
518  * @param clk_src Clock source to use for timer
519  * (EM_TIMER_CLKSRC_DEFAULT for system specific default)
520  * @return EM_OK if the input value is supported (res updated)
521  *
522  * @see em_timer_capability
523  */
525 
526 /**
527  * @brief Check periodic ring timer capability.
528  *
529  * Returns ring timer capability from given input values. On input parameter
530  * ring must be initialized with the required values. res_ns can be 0,
531  * which gets replaced by the system default.
532  * During the call values are updated. If this returns EM_OK then the combination
533  * of given values are all supported (or exceeded e.g. better resolution),
534  * otherwise values are updated with the closest supported.
535  *
536  * As em_timer_ring_attr_init only takes integer base_hz, this can also be used
537  * to verify valid values for modified fractional frequencies to avoid
538  * errorhandler call from timer_ring_create().
539  *
540  * This function will not trigger errorhandler calls.
541  *
542  * @param ring [in,out] timer ring parameters to check
543  *
544  * @retval EM_OK Parameter combination is supported
545  * @retval EM_ERR_NOT_SUPPORTED Parameters not supported, values updated to closest
546  * @retval (other error) Unsupported arguments
547  */
549 
550 /**
551  * Create and start a timer resource
552  *
553  * Required attributes are given via tmr_attr. The given structure must be
554  * initialized with em_timer_attr_init before setting any field.
555  *
556  * Timer resolution can be given as time 'res_ns' or frequency 'res_hz'. User
557  * must choose which one to use by setting the other one to 0.
558  *
559  * To use all defaults initialize tmr_attr with em_timer_attr_init() and pass it
560  * as is to em_timer_create().
561  *
562  * @note NULL is no longer supported, must give pointer to initialized em_timer_attr_t
563  *
564  * @param tmr_attr Timer parameters to use, pointer to initialized em_timer_attr_t
565  *
566  * @return Timer handle on success or EM_TIMER_UNDEF on error
567  *
568  * @see em_timer_attr_init, em_timer_capability
569  */
570 em_timer_t em_timer_create(const em_timer_attr_t *tmr_attr);
571 
572 /**
573  * Create and start a timer ring (alternative periodic timer)
574  *
575  * Required attributes are given via ring_attr, which must have been initialized
576  * with em_timer_ring_attr_init and optionally adjusted for the required timing
577  * constraints.
578  *
579  * A periodic ring timer is different and will only send EM_EVENT_TYPE_TIMER_IND
580  * events, which are automatically provided and cannot be modified. These events
581  * can be allocated only via timer APIs.
582  *
583  * Example for 1ms ... 125us periodic ring timer (base 1000 hz, multiplier up to 8):
584  * @code
585  * em_timer_ring_attr_t attr;
586  * if (em_timer_ring_attr_init(&attr, EM_TIMER_CLKSRC_DEFAULT, 1000, 8, 0) != EM_OK) {
587  * // given values not supported
588  * }
589  *
590  * em_timer_t tmr = em_timer_ring_create(&attr);
591  * if (tmr == EM_TIMER_UNDEF) {
592  * // handle error here or via error handler
593  * }
594  * @endcode
595  *
596  * @param ring_attr Timer ring parameters to use
597  *
598  * @return Timer handle on success or EM_TIMER_UNDEF on error
599  *
600  * @see em_timer_ring_attr_init
601  */
602 em_timer_t em_timer_ring_create(const em_timer_attr_t *ring_attr);
603 
604 /**
605  * Stop and delete a timer
606  *
607  * Delete a timer, frees all resources.
608  * All timeouts for this timer must have been deleted first.
609  *
610  * @param tmr Timer handle
611  *
612  * @return EM_OK on success
613  */
614 em_status_t em_timer_delete(em_timer_t tmr);
615 
616 /**
617  * Returns current tick value of the given timer
618  *
619  * This can be used for calculating absolute timeouts.
620  *
621  * @param tmr Timer handle
622  *
623  * @return Current time in timer specific ticks or 0 on non-existing timer
624  */
625 em_timer_tick_t em_timer_current_tick(em_timer_t tmr);
626 
627 /**
628  * Allocate a new timeout
629  *
630  * Create a new timeout. Allocates the necessary internal resources from the
631  * given timer and prepares for em_tmo_set_abs/rel/periodic().
632  *
633  * Scheduled queues are always supported. LOCAL or OUTPUT queues can not be
634  * used as timeout targets. Support for unscheduled queues is implementation
635  * specific.
636  *
637  * Flags are used to select functionality:
638  * - EM_TMO_FLAG_ONESHOT creates a one-shot timeout and
639  * - EM_TMO_FLAG_PERIODIC creates a periodic timeout.
640  * The flag EM_TMO_FLAG_NOSKIP can, in the periodic case, be 'OR':d into the
641  * flags to make the timeout acknowledgment never skip a missed timeout (the
642  * default is to skip missed time slots).
643  *
644  * If used timer is timer ring the NOSKIP flag is ignored.
645  *
646  * @param tmr Timer handle
647  * @param flags Functionality flags
648  * @param queue Target queue where the timeout event should be delivered
649  *
650  * @return Timeout handle on success or EM_TMO_UNDEF on failure
651  */
652 em_tmo_t em_tmo_create(em_timer_t tmr, em_tmo_flag_t flags, em_queue_t queue);
653 
654 /**
655  * Allocate a new timeout with extra arguments
656  *
657  * Like em_tmo_create but with additional argument. This can be used with any
658  * timer type, but e.g. the userptr argument is only used with ring timers
659  * using events of type EM_EVENT_TYPE_TIMER_IND that can carry userptr.
660  *
661  * @param tmr Timer handle
662  * @param flags Functionality flags
663  * @param queue Target queue where the timeout event should be delivered
664  * @param args Optional pointer holding extra arguments e.g. userptr for
665  * ring timers. NULL ok.
666  *
667  * @return Timeout handle on success or EM_TMO_UNDEF on failure
668  * @see em_tmo_create
669  */
670 em_tmo_t em_tmo_create_arg(em_timer_t tmr, em_tmo_flag_t flags, em_queue_t queue,
671  em_tmo_args_t *args);
672 
673 /**
674  * Free a timeout
675  *
676  * Free (destroy) a timeout.
677  * The user provided timeout event for an active timeout will be returned via
678  * cur_event and the timeout is cancelled. The timeout event for an expired, but
679  * not yet received timeout will not be returned. It is the responsibility of
680  * the application to handle that case (event will still be received).
681  *
682  * After and during this call the tmo handle is not valid anymore and must not
683  * be used. With periodic timeout means em_tmo_ack must also not be called when
684  * tmo is deleted.
685  *
686  * @param tmo Timeout handle
687  * @param[out] cur_event Current event for an active timeout
688  *
689  * @return EM_OK on success
690  */
691 em_status_t em_tmo_delete(em_tmo_t tmo, em_event_t *cur_event);
692 
693 /**
694  * Activate a oneshot timeout with absolute time.
695  *
696  * Activates oneshot timeout to expire at specific absolute time. The given
697  * timeout event will be sent to the queue given to em_tmo_create() when the
698  * timeout expires.
699  *
700  * It is not possible to send timeouts with an event group, but the application
701  * can assign the event group when receiving the timeout event, see
702  * em_event_group_assign().
703  *
704  * The timeout event should not be accessed after it has been given to the
705  * timer, similar to sending an event.
706  *
707  * Even if not guaranteed, the implementation should make sure that this call
708  * can fail only in exceptional situations (em_tmo_create() should pre-
709  * allocate needed resources).
710  *
711  * Allowed minimum and maximum timeout can be inquired with
712  * em_timer_res_capability.
713  *
714  * An active timeout can not be modified. The timeout needs to be canceled and
715  * then set again with new arguments.
716  *
717  * An inactive timeout can be re-used by calling em_tmo_set_abs/rel() again
718  * after the previous timeout was received or was cancelled successfully.
719  *
720  * This function is for activating oneshot timeouts only. To activate
721  * a periodic timer use em_tmo_set_periodic() instead.
722  *
723  * @param tmo Timeout handle
724  * @param ticks_abs Expiration time in absolute timer specific ticks
725  * @param tmo_ev Timeout event
726  *
727  * @retval EM_OK success (event taken)
728  * @retval EM_ERR_TOONEAR failure, tick value is in past or too close to
729  * current time. Errorhandler not called, event
730  * not taken
731  * @retval (other_codes) failure, event not taken
732  *
733  * @see em_timer_res_capability
734  */
736  em_event_t tmo_ev);
737 
738 /**
739  * Activate a timeout with relative time.
740  *
741  * Similar to em_tmo_set_abs(), but instead of an absolute time uses timeout
742  * value relative to the moment of the call.
743  *
744  * This function is for activating oneshot timeouts only. To activate
745  * a periodic timer use em_tmo_set_periodic() instead.
746  *
747  * @param tmo Timeout handle
748  * @param ticks_rel Expiration time in relative timer specific ticks
749  * @param tmo_ev Timeout event handle
750  *
751  * @retval EM_OK success (event taken)
752  * @retval EM_ERR_TOONEAR failure, tick value is too low. Errorhandler not
753  * called, event not taken
754  * @retval (other_codes) failure, event not taken
755  *
756  * @deprecated Do not use for periodic timeouts
757  *
758  * @see em_tmo_set_abs, em_tmo_set_periodic
759  */
761  em_event_t tmo_ev);
762 
763 /**
764  * Activate a periodic timeout
765  *
766  * Used to activate periodic timeouts. The first period can be different from
767  * the repetitive period by providing an absolute start time e.g. the first period
768  * starts from that moment. Use 0 as start time if the period can start from the
769  * moment of the call (relative).
770  *
771  * The timeout event will be sent to the queue given to em_tmo_create() when the
772  * first timeout expires. Receiver then need to call em_tmo_ack() to allow
773  * sending next event.
774  *
775  * This function can only be used with periodic timeouts (created with flag
776  * EM_TMO_FLAG_PERIODIC).
777  *
778  * @param tmo Timeout handle
779  * @param start_abs Absolute start time (or 0 for period starting at call time)
780  * @param period Period in timer specific ticks
781  * @param tmo_ev Timeout event handle
782  *
783  * @retval EM_OK success (event taken)
784  * @retval EM_ERR_TOONEAR failure, tick value is in past or too close to
785  * current time. Errorhandler not called, event
786  * not taken
787  * @retval (other_codes) failure, event not taken
788  *
789  * @see em_tmo_ack
790  */
792  em_timer_tick_t start_abs,
793  em_timer_tick_t period,
794  em_event_t tmo_ev);
795 
796 /**
797  * Activate a periodic timeout on a periodic ring timer
798  *
799  * Use start_abs value 0 to start the timer relative to current time. To adjust
800  * the offset of timeouts an absolute tick can also be given, but the maximum
801  * distance from current time can only be up to one period.
802  * Periodic rate of the timeout event is base_hz (given when creating the timer)
803  * multiplied by the given multiplier. For example 1000Hz base_hz with multiplier
804  * of 8 will give 125us period.
805  *
806  * Timeout event of type EM_EVENT_TYPE_TIMER_IND is automatically allocated if
807  * not provided and will be sent to the queue given to em_tmo_create() when the
808  * timeout expires. User then needs to call em_timer_ack like with normal
809  * periodic timeout. With ring timer however there is no guaranteed flow control,
810  * new events may be sent even before user has called ack. This means the same
811  * event may be in the input queue multiple times if the application can not
812  * keep up the period rate.
813  * If the destination queue is not atomic the same event can then also be
814  * concurrently received by multiple cores. This is a race hazard to prepare for.
815  * Additionally the used event can not change via em_tmo_ack, the received event
816  * must always be returned.
817  *
818  * The last argument tmo_ev is normally EM_EVENT_UNDEF for a new timeout start.
819  * Then the implementation will use pre-allocated event. Exception is re-use of
820  * canceled ring timeout event (when ack returns EM_ERR_CANCELED the event stays
821  * with user and can be re-used). Such event can be recycled here to avoid extra
822  * free and alloc.
823  *
824  * This function can only be used with periodic timeouts with a ring timer.
825  * The timeout indication event is read-only and can be accessed only via
826  * accessor APIs.
827  *
828  * @param tmo Timeout handle
829  * @param start_abs Absolute start time (or 0 for period starting at call time)
830  * @param multiplier Rate multiplier (period rate = multiplier * timer base_hz)
831  * @param tmo_ev Event of type EM_EVENT_TYPE_TIMER_IND to re-use.
832  * Normally EM_EVENT_UNDEF.
833  *
834  * @retval EM_OK success
835  * @retval EM_ERR_TOONEAR failure, start tick value is past or too close
836  * to current time or multiplier is too high
837  * @retval EM_ERR_TOOFAR failure, start tick value exceeds one period
838  * @retval (other_codes) failure
839  *
840  * @see em_tmo_get_user_ptr, em_tmo_get_type, em_timer_create_ring
841  */
843  em_timer_tick_t start_abs,
844  uint64_t multiplier,
845  em_event_t tmo_ev);
846 
847 /**
848  * Cancel a timeout
849  *
850  * Cancels a timeout preventing future expiration. Returns the timeout event
851  * in case the timeout was not expired. A timeout that has already expired or
852  * just about to cannot be cancelled and the timeout event will be delivered to
853  * the destination queue. In this case cancel will return an error as it was
854  * too late to cancel. Errorhandler is not called if failure is due to expired
855  * timeout only.
856  *
857  * Periodic timeout: cancel may fail if attempted too close to the next period.
858  * This can be considered normal and indicates that one more timeout will be
859  * received. In this case errorhandler is not called, error status
860  * EM_ERR_TOONEAR returned and no event returned. When em_tmo_ack is then
861  * called on the canceled timeout event receive it will return EM_ERR_CANCELED
862  * to indicate this is the last event coming for this timeout.
863  *
864  * @param tmo Timeout handle
865  * @param[out] cur_event Event handle pointer to return the pending
866  * timeout event or EM_EVENT_UNDEF if cancel fails
867  * (e.g. called too late)
868  *
869  * @retval EM_OK success, event returned
870  * @retval EM_ERR_TOONEAR already expired (too late to cancel).
871  * Errorhandler not called
872  * @retval (other_codes) failure
873  *
874  * @see em_tmo_set_abs, em_tmo_set_rel, em_tmo_set_periodic, em_tmo_set_periodic_ring
875  */
876 em_status_t em_tmo_cancel(em_tmo_t tmo, em_event_t *cur_event);
877 
878 /**
879  * Acknowledge a periodic timeout
880  *
881  * All received periodic timeout events must be acknowledged with em_tmo_ack().
882  * No further timeout event(s) will be sent before the user has acknowledged
883  * the previous one unless a ring timer is used.
884  *
885  * Timeout acknowledgment is usually done at the end of the EO-receive function
886  * to prevent race conditions (e.g. if the same event is re-used for the next
887  * timeout period also). The implementation will adjust for the processing delay
888  * so that the time slot will not drift over time.
889  *
890  * If em_tmo_ack() is called too late, e.g. the next period(s) is already
891  * passed, the implementation by default will skip all the missed time slots and
892  * arm for the next future one keeping the original start offset. Application
893  * can alter this behaviour with the flag EM_TMO_FLAG_NOSKIP when creating a
894  * timeout. Then no past timeout is skipped and each late acknowledgment will
895  * immediately trigger sending the next timeout event until current time has
896  * been reached.
897  * Note that using EM_TMO_FLAG_NOSKIP may result in an event storm if a large
898  * number of timeouts have been unacknowledged for a longer time (limited by
899  * application response latency). Timing problems will not call errorhandler.
900  *
901  * If the timer has been canceled, but the cancel happened too late for the
902  * current period the timeout will be delivered. If application then calls
903  * em_tmo_ack it returns EM_ERR_CANCELED and does not call errorhandler. This is
904  * to signal it was the last timeout coming for that tmo.
905  *
906  * Application may re-use the same received timeout event or provide a new one
907  * for the next timeout. With ring timer the received event must be returned.
908  *
909  * The given event should not be touched after calling this function until it
910  * has been received again or after the timeout is successfully cancelled and
911  * event returned.
912  *
913  * Periodic timeout will stop if em_tmo_ack() returns an error other than
914  * timing related. The implementation will call errorhandler in this case
915  * unless timer was canceled, so the exception can be handled also there.
916  *
917  * em_tmo_ack() can only be used with periodic timeouts.
918  *
919  * @param tmo Timeout handle
920  * @param next_tmo_ev Next timeout event handle (can be the received one)
921  *
922  * @retval EM_OK success (event taken)
923  * @retval EM_ERR_CANCELED timer has been cancelled, no more coming, not taken
924  * @retval (other_codes) failure, event not taken
925  */
926 em_status_t em_tmo_ack(em_tmo_t tmo, em_event_t next_tmo_ev);
927 
928 /**
929  * Get a list of currently active timers.
930  *
931  * The timer handles returned via 'tmr_list' can be used for further timer
932  * queries or to destroy existing timers.
933  *
934  * The return value always reflects the actual number of timers in the
935  * EM instance but the output parameter 'tmr_list' is only written up to the
936  * given 'max' length.
937  *
938  * Note that the return value (number of timers) can be greater than the given
939  * 'max'. It is the user's responsibility to check the return value against the
940  * given 'max'.
941  *
942  * To only get the current number of active timers, without any timer handles
943  * output, use the following: num_timers = em_timer_get_all(NULL, 0);
944  *
945  * @param[out] tmr_list Pointer to an array of timer handles.
946  * Use NULL if only interested in the return value.
947  * @param max Max number of handles that can be written into tmr_list
948  * 'max' is ignored if 'tmr_list' is NULL.
949  *
950  * @return The number of active timers
951  */
952 int em_timer_get_all(em_timer_t *tmr_list, int max);
953 
954 /**
955  * Get timer attributes
956  *
957  * Returns the actual capabilities of the given timer.
958  *
959  * @param tmr Timer handle
960  * @param [out] tmr_attr Pointer to em_timer_attr_t to fill
961  *
962  * @return EM_OK on success
963  */
964 em_status_t em_timer_get_attr(em_timer_t tmr, em_timer_attr_t *tmr_attr);
965 
966 /**
967  * Returns the timer frequency, i.e. ticks per second for the given timer.
968  *
969  * Can be used to convert real time to timer specific tick.
970  *
971  * @param tmr Timer handle
972  *
973  * @return ticks per second (Hz), or 0 for non-existing timer
974  */
975 uint64_t em_timer_get_freq(em_timer_t tmr);
976 
977 /**
978  * Convert timer tick to ns
979  *
980  * @param tmr Valid timer handle
981  * @param ticks Timer specific ticks to convert
982  *
983  * @return converted amount in ns
984  */
985 uint64_t em_timer_tick_to_ns(em_timer_t tmr, em_timer_tick_t ticks);
986 
987 /**
988  * Convert ns to timer tick
989  *
990  * @param tmr Valid timer handle
991  * @param ns ns value to convert
992  *
993  * @return converted amount in timer ticks
994  */
995 em_timer_tick_t em_timer_ns_to_tick(em_timer_t tmr, uint64_t ns);
996 
997 /**
998  * Returns the current state of the given timeout.
999  *
1000  * Note that the returned state may change at any time if the timeout expires
1001  * or is manipulated by other threads.
1002  *
1003  * @param tmo Timeout handle
1004  *
1005  * @return current timeout state (EM_TMO_STATE_UNKNOWN on error)
1006  *
1007  * @see em_tmo_state_t
1008  */
1010 
1011 /**
1012  * Returns the statistic counters for a timeout.
1013  *
1014  * Returns a snapshot of the current counters of the given timeout.
1015  * Statistics can be accessed while the timeout is valid, i.e. tmo created but
1016  * not deleted.
1017  *
1018  * Counter support is optional. If counters are not supported the function
1019  * returns EM_ERR_NOT_IMPLEMENTED.
1020  * A quick way to detect whether counters are supported is to call the function
1021  * with stat=NULL and check the return value.
1022  *
1023  * @param tmo Timeout handle
1024  * @param [out] stat Pointer to em_tmo_stats_t to receive the values (NULL ok)
1025  *
1026  * @return EM_OK on success
1027  */
1029 
1030 /**
1031  * Ask if given event is currently used as timeout indication.
1032  *
1033  * This can be used with any valid event handle to ask if it is used as a
1034  * timeout indication event.
1035  * Events are updated for tmo type when going through timer API.
1036  * @note As a received event is owned by the application and not necessarily
1037  * passing through timer API anymore this type will not reset until event is
1038  * freed, re-used as another timeout or explicitly reset by setting the reset
1039  * argument to true. This reset should be done if re-using the received tmo event
1040  * for something else than timeout to avoid expired value being returned in case
1041  * someone later calls tmo_get_type.
1042  *
1043  * Successful timeout cancel (event returned) will reset the event type to
1044  * EM_TMO_TYPE_NONE.
1045  *
1046  * @note The reset argument is ignored if the given event is of type
1047  * EM_EVENT_TYPE_TIMER_IND.
1048  *
1049  * The related tmo handle can also be retrieved via parameter tmo. This
1050  * can be useful to call em_tmo_ack() for periodic timeouts:
1051  * @code
1052  * em_tmo_t tmo;
1053  *
1054  * if (em_tmo_get_type(event, &tmo, false) == EM_TMO_TYPE_PERIODIC)
1055  * retval = em_tmo_ack(tmo, event);
1056  * @endcode
1057  *
1058  * @param event event handle to check
1059  * @param [out] tmo pointer to em_tmo_t to receive related tmo handle (NULL ok)
1060  * @param reset set true to reset tmo type to EM_TMO_TYPE_NONE for non-timer re-use
1061  *
1062  * @return type of timeout use or EM_TMO_TYPE_NONE if event is not related to a timeout
1063  * @see em_tmo_type_t
1064  */
1065 em_tmo_type_t em_tmo_get_type(em_event_t event, em_tmo_t *tmo, bool reset);
1066 
1067 /**
1068  * Returns the optional user pointer for a periodic ring timeout
1069  *
1070  * Can only be used with an event received as a timeout for a periodic ring,
1071  * i.e. EM_EVENT_TYPE_TIMER_IND only. Other event types will return NULL.
1072  *
1073  * @param event Event received as timeout
1074  * @param [out] tmo Optionally returns associated tmo handle. NULL ok.
1075  *
1076  * @return A pointer given when creating the associated tmo or
1077  * NULL if the event is not ring timeout
1078  */
1079 void *em_tmo_get_userptr(em_event_t event, em_tmo_t *tmo);
1080 
1081 /**
1082  * Returns the associated timer handle from a timeout handle
1083  *
1084  * Associated timer handle is returned from a valid timeout. Can be used to for
1085  * instance read the current timer tick without having the timer handle:
1086  * @code
1087  * em_timer_tick_t tick = em_timer_current_tick(em_tmo_get_timer(tmo));
1088  * @endcode
1089  *
1090  * @param tmo valid timeout handle
1091  *
1092  * @return associated timer handle or EM_TIMER_UNDEF if tmo is not valid
1093  *
1094  */
1095 em_timer_t em_tmo_get_timer(em_tmo_t tmo);
1096 
1097 /**
1098  * Convert a timer handle to an unsigned integer
1099  *
1100  * @param timer timer handle to be converted
1101  * @return uint64_t value that can be used to print/display the handle
1102  *
1103  * @note This routine is intended to be used for diagnostic purposes
1104  * to enable applications to e.g. generate a printable value that represents
1105  * an em_timer_t handle.
1106  */
1107 uint64_t em_timer_to_u64(em_timer_t timer);
1108 
1109 /**
1110  * Convert a timeout handle to an unsigned integer
1111  *
1112  * @param tmo timeout handle to be converted
1113  * @return uint64_t value that can be used to print/display the handle
1114  *
1115  * @note This routine is intended to be used for diagnostic purposes
1116  * to enable applications to e.g. generate a printable value that represents
1117  * an em_tmo_t handle.
1118  */
1119 uint64_t em_tmo_to_u64(em_tmo_t tmo);
1120 
1121 /**
1122  * @}
1123  */
1124 #ifdef __cplusplus
1125 }
1126 #endif
1127 
1128 #pragma GCC visibility pop
1129 #endif /* EVENT_MACHINE_TIMER_H_ */
EM_TMO_TYPE_NONE
@ EM_TMO_TYPE_NONE
Definition: api/event_machine_timer.h:251
em_timer_ring_capability
em_status_t em_timer_ring_capability(em_timer_ring_param_t *ring)
Check periodic ring timer capability.
Definition: event_machine_timer.c:577
em_fract_u64_t
Definition: api/event_machine_timer.h:267
em_tmo_set_abs
em_status_t em_tmo_set_abs(em_tmo_t tmo, em_timer_tick_t ticks_abs, em_event_t tmo_ev)
Definition: event_machine_timer.c:1255
em_timer_current_tick
em_timer_tick_t em_timer_current_tick(em_timer_t tmr)
Definition: event_machine_timer.c:1045
em_timer_capability_t::max_timers
uint32_t max_timers
Definition: api/event_machine_timer.h:382
em_tmo_stats_t
Definition: api/event_machine_timer.h:368
em_tmo_args_t
struct em_tmo_args_t em_tmo_args_t
em_timer_capability_t
struct em_timer_capability_t em_timer_capability_t
em_timer_attr_t::resparam
em_timer_res_param_t resparam
Definition: api/event_machine_timer.h:339
em_tmo_create_arg
em_tmo_t em_tmo_create_arg(em_timer_t tmr, em_tmo_flag_t flags, em_queue_t queue, em_tmo_args_t *args)
Definition: event_machine_timer.c:1061
em_tmo_set_rel
em_status_t em_tmo_set_rel(em_tmo_t tmo, em_timer_tick_t ticks_rel, em_event_t tmo_ev)
Definition: event_machine_timer.c:1330
em_timer_capability_t::max_num_tmo
uint32_t max_num_tmo
Definition: api/event_machine_timer.h:384
em_tmo_delete
em_status_t em_tmo_delete(em_tmo_t tmo, em_event_t *cur_event)
Definition: event_machine_timer.c:1161
em_tmo_flag_t
em_tmo_flag_t
Definition: event_machine_timer_hw_specific.h:80
em_timer_tick_to_ns
uint64_t em_timer_tick_to_ns(em_timer_t tmr, em_timer_tick_t ticks)
Definition: event_machine_timer.c:1837
em_tmo_get_state
em_tmo_state_t em_tmo_get_state(em_tmo_t tmo)
Definition: event_machine_timer.c:1863
em_timer_capability_t::max_res
em_timer_res_param_t max_res
Definition: api/event_machine_timer.h:386
em_timer_attr_t::ringparam
em_timer_ring_param_t ringparam
Definition: api/event_machine_timer.h:351
em_timer_ring_param_t
Definition: api/event_machine_timer.h:306
em_tmo_stats_t::num_period_skips
uint64_t num_period_skips
Definition: api/event_machine_timer.h:374
em_tmo_ack
em_status_t em_tmo_ack(em_tmo_t tmo, em_event_t next_tmo_ev)
Definition: event_machine_timer.c:1638
EM_TMO_TYPE_ONESHOT
@ EM_TMO_TYPE_ONESHOT
Definition: api/event_machine_timer.h:252
em_timer_capability_t
Definition: api/event_machine_timer.h:380
em_timer_tick_t
uint64_t em_timer_tick_t
Definition: api/event_machine_timer.h:261
em_timer_capability
em_status_t em_timer_capability(em_timer_capability_t *capa, em_timer_clksrc_t clk_src)
Definition: event_machine_timer.c:502
em_timer_get_attr
em_status_t em_timer_get_attr(em_timer_t tmr, em_timer_attr_t *tmr_attr)
Definition: event_machine_timer.c:1778
em_timer_delete
em_status_t em_timer_delete(em_timer_t tmr)
Definition: event_machine_timer.c:980
em_timer_attr_t
struct em_timer_attr_t em_timer_attr_t
em_timer_attr_t::name
char name[EM_TIMER_NAME_LEN]
Definition: api/event_machine_timer.h:345
EM_TMO_STATE_INACTIVE
@ EM_TMO_STATE_INACTIVE
Definition: api/event_machine_timer.h:244
em_timer_ring_create
em_timer_t em_timer_ring_create(const em_timer_attr_t *ring_attr)
Definition: event_machine_timer.c:770
em_timer_attr_t::num_tmo
uint32_t num_tmo
Definition: api/event_machine_timer.h:341
em_timer_capability_t::max_base_hz
em_fract_u64_t max_base_hz
Definition: api/event_machine_timer.h:399
em_timer_ring_param_t::base_hz
em_fract_u64_t base_hz
Definition: api/event_machine_timer.h:310
em_tmo_stats_t::num_acks
uint64_t num_acks
Definition: api/event_machine_timer.h:370
em_timer_res_param_t::max_tmo
uint64_t max_tmo
Definition: api/event_machine_timer.h:299
em_tmo_create
em_tmo_t em_tmo_create(em_timer_t tmr, em_tmo_flag_t flags, em_queue_t queue)
Definition: event_machine_timer.c:1056
em_timer_capability_t::ring
struct em_timer_capability_t::@2 ring
em_timer_timeout_t
Definition: em_timer_types.h:76
em_tmo_get_userptr
void * em_tmo_get_userptr(em_event_t event, em_tmo_t *tmo)
Definition: event_machine_timer.c:1933
em_fract_u64_t::denom
uint64_t denom
Definition: api/event_machine_timer.h:275
em_tmo_args_t::userptr
void * userptr
Definition: api/event_machine_timer.h:410
em_timer_ring_param_t::clk_src
em_timer_clksrc_t clk_src
Definition: api/event_machine_timer.h:308
em_timer_capability_t::max_rings
uint32_t max_rings
Definition: api/event_machine_timer.h:393
em_timer_res_capability
em_status_t em_timer_res_capability(em_timer_res_param_t *res, em_timer_clksrc_t clk_src)
Definition: event_machine_timer.c:544
em_timer_ring_param_t
struct em_timer_ring_param_t em_timer_ring_param_t
em_timer_attr_t
Definition: api/event_machine_timer.h:335
em_timer_res_param_t::min_tmo
uint64_t min_tmo
Definition: api/event_machine_timer.h:297
em_timer_clksrc_t
em_timer_clksrc_t
Definition: event_machine_timer_hw_specific.h:95
EM_TMO_STATE_IDLE
@ EM_TMO_STATE_IDLE
Definition: api/event_machine_timer.h:242
EM_TMO_TYPE_PERIODIC
@ EM_TMO_TYPE_PERIODIC
Definition: api/event_machine_timer.h:253
em_timer_attr_init
void em_timer_attr_init(em_timer_attr_t *tmr_attr)
Definition: event_machine_timer.c:378
em_tmo_stats_t::num_late_ack
uint64_t num_late_ack
Definition: api/event_machine_timer.h:372
em_timer_capability_t::max_tmo
em_timer_res_param_t max_tmo
Definition: api/event_machine_timer.h:388
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
em_tmo_set_periodic
em_status_t em_tmo_set_periodic(em_tmo_t tmo, em_timer_tick_t start_abs, em_timer_tick_t period, em_event_t tmo_ev)
Definition: event_machine_timer.c:1402
em_tmo_get_type
em_tmo_type_t em_tmo_get_type(em_event_t event, em_tmo_t *tmo, bool reset)
Definition: event_machine_timer.c:1900
em_fract_u64_t::numer
uint64_t numer
Definition: api/event_machine_timer.h:272
em_fract_u64_t
struct em_fract_u64_t em_fract_u64_t
em_timer_ring_param_t::max_mul
uint64_t max_mul
Definition: api/event_machine_timer.h:312
em_tmo_state_t
em_tmo_state_t
Definition: api/event_machine_timer.h:240
em_timer_res_param_t::res_ns
uint64_t res_ns
Definition: api/event_machine_timer.h:293
em_timer_res_param_t
struct em_timer_res_param_t em_timer_res_param_t
em_tmo_get_timer
em_timer_t em_tmo_get_timer(em_tmo_t tmo)
Definition: event_machine_timer.c:1954
em_fract_u64_t::integer
uint64_t integer
Definition: api/event_machine_timer.h:269
em_timer_ring_param_t::res_ns
uint64_t res_ns
Definition: api/event_machine_timer.h:314
em_timer_get_all
int em_timer_get_all(em_timer_t *tmr_list, int max)
Definition: event_machine_timer.c:1754
em_timer_ring_attr_init
em_status_t em_timer_ring_attr_init(em_timer_attr_t *ring_attr, em_timer_clksrc_t clk_src, uint64_t base_hz, uint64_t max_mul, uint64_t res_ns)
Definition: event_machine_timer.c:444
em_timer_to_u64
uint64_t em_timer_to_u64(em_timer_t timer)
Definition: event_machine_timer.c:1968
em_timer_get_freq
uint64_t em_timer_get_freq(em_timer_t tmr)
Definition: event_machine_timer.c:1823
em_timer_res_param_t
Definition: api/event_machine_timer.h:289
em_timer_flag_t
em_timer_flag_t
Definition: event_machine_timer_hw_specific.h:57
em_timer_ns_to_tick
em_timer_tick_t em_timer_ns_to_tick(em_timer_t tmr, uint64_t ns)
Definition: event_machine_timer.c:1850
em_tmo_set_periodic_ring
em_status_t em_tmo_set_periodic_ring(em_tmo_t tmo, em_timer_tick_t start_abs, uint64_t multiplier, em_event_t tmo_ev)
Definition: event_machine_timer.c:1487
em_tmo_get_stats
em_status_t em_tmo_get_stats(em_tmo_t tmo, em_tmo_stats_t *stat)
Definition: event_machine_timer.c:1877
em_timer_capability_t::min_base_hz
em_fract_u64_t min_base_hz
Definition: api/event_machine_timer.h:397
em_timer_create
em_timer_t em_timer_create(const em_timer_attr_t *tmr_attr)
Definition: event_machine_timer.c:616
em_tmo_args_t
Definition: api/event_machine_timer.h:408
em_timer_attr_t::__internal_check
uint32_t __internal_check
Definition: api/event_machine_timer.h:359
em_tmo_stats_t
struct em_tmo_stats_t em_tmo_stats_t
em_tmo_type_t
em_tmo_type_t
Definition: api/event_machine_timer.h:250
em_timer_res_param_t::res_hz
uint64_t res_hz
Definition: api/event_machine_timer.h:295
em_timer_res_param_t::clk_src
em_timer_clksrc_t clk_src
Definition: api/event_machine_timer.h:291
em_tmo_to_u64
uint64_t em_tmo_to_u64(em_tmo_t tmo)
Definition: event_machine_timer.c:1973
em_tmo_cancel
em_status_t em_tmo_cancel(em_tmo_t tmo, em_event_t *cur_event)
Definition: event_machine_timer.c:1563
em_timer_attr_t::flags
em_timer_flag_t flags
Definition: api/event_machine_timer.h:343
EM_TMO_STATE_ACTIVE
@ EM_TMO_STATE_ACTIVE
Definition: api/event_machine_timer.h:243