This library provides a timer service to CNE Data Plane execution units that allows the execution of callback functions asynchronously.
- Timers can be periodic or single (one-shot).
- The timers can be loaded from one core and executed on another. This has to be specified in the call to cne_timer_reset().
- High precision is possible. NOTE: this depends on the call frequency to cne_timer_manage() that check the timer expiration for the local core.
- If not used in an application, for improved performance, it can be disabled at compilation time by not calling the cne_timer_manage() to improve performance.
This library provides an interface to add, delete and restart a timer. The API is based on the BSD callout(9) API with a few differences.
See the CNE architecture documentation for more information about the design of this library.
Definition in file cne_timer.h.
Reset and start the timer associated with the timer handle.
The cne_timer_reset() function resets and starts the timer associated with the timer handle tim. When the timer expires after ticks HPET cycles, the function specified by fct will be called with the argument arg on core tim_thread.
If the timer associated with the timer handle is already running (in the RUNNING state), the function will fail. The user has to check the return value of the function to see if there is a chance that the timer is in the RUNNING state.
If the timer is being configured on another core (the CONFIG state), it will also fail.
If the timer is pending or stopped, it will be rescheduled with the new parameters.
|tim||The timer handle. |
|ticks||The number of cycles (see cne_get_hpet_hz()) before the callback function is called. |
|type||The type can be either:|
- PERIODICAL: The timer is automatically reloaded after execution (returns to the PENDING state)
- SINGLE: The timer is one-shot, that is, the timer goes to a STOPPED state after execution.
|tim_thread||The ID of the thread where the timer callback function has to be executed. |
|fct||The callback function of the timer. |
|arg||The user argument of the callback function. |
- 0: Success; the timer is scheduled.
- (-1): Timer is in the RUNNING or CONFIG state.
Stop a timer.
The cne_timer_stop() function stops the timer associated with the timer handle tim. It may fail if the timer is currently running or being configured.
If the timer is pending or stopped (for instance, already expired), the function will succeed. The timer handle tim must have been initialized using cne_timer_init(), otherwise, undefined behavior will occur.
This function can be called safely from a timer callback. If it succeeds, the timer is not referenced anymore by the timer library and the timer structure can be freed (even in the callback function).
- 0: Success; the timer is stopped.
- (-1): The timer is in the RUNNING or CONFIG state.