CNDP
22.08.0
|
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <cne_common.h>
#include <cne_atomic.h>
Go to the source code of this file.
Data Structures | |
union | cne_timer_status |
struct | cne_timer_debug_stats |
struct | cne_timer |
Macros | |
#define | CNE_TIMER_STOP 0 |
#define | CNE_TIMER_PENDING 1 |
#define | CNE_TIMER_RUNNING 2 |
#define | CNE_TIMER_CONFIG 3 |
#define | CNE_TIMER_NO_OWNER -2 |
#define | CNE_TIMER_INITIALIZER |
Typedefs | |
typedef void(* | cne_timer_cb_t) (struct cne_timer *, void *) |
Enumerations | |
enum | cne_timer_type |
Functions | |
void | cne_timer_subsystem_init (void) |
void | cne_timer_init (struct cne_timer *tim) |
int | cne_timer_reset (struct cne_timer *tim, uint64_t ticks, enum cne_timer_type type, unsigned tim_thread, cne_timer_cb_t fct, void *arg) |
void | cne_timer_reset_sync (struct cne_timer *tim, uint64_t ticks, enum cne_timer_type type, unsigned tim_thread, cne_timer_cb_t fct, void *arg) |
int | cne_timer_stop (struct cne_timer *tim) |
void | cne_timer_stop_sync (struct cne_timer *tim) |
int | cne_timer_pending (struct cne_timer *tim) |
void | cne_timer_manage (void) |
void | cne_timer_dump_stats (FILE *f) |
CNE Timer
This library provides a timer service to CNE Data Plane execution units that allows the execution of callback functions asynchronously.
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.
#define CNE_TIMER_STOP 0 |
State: timer is stopped.
Definition at line 43 of file cne_timer.h.
#define CNE_TIMER_PENDING 1 |
State: timer is scheduled.
Definition at line 44 of file cne_timer.h.
#define CNE_TIMER_RUNNING 2 |
State: timer function is running.
Definition at line 45 of file cne_timer.h.
#define CNE_TIMER_CONFIG 3 |
State: timer is being configured.
Definition at line 46 of file cne_timer.h.
#define CNE_TIMER_NO_OWNER -2 |
Timer has no owner.
Definition at line 47 of file cne_timer.h.
#define CNE_TIMER_INITIALIZER |
A static initializer for a timer structure.
Definition at line 110 of file cne_timer.h.
typedef void(* cne_timer_cb_t) (struct cne_timer *, void *) |
Callback function type for timer expiry.
Definition at line 82 of file cne_timer.h.
enum cne_timer_type |
Timer type: Periodic or single (one-shot).
Definition at line 52 of file cne_timer.h.
void cne_timer_subsystem_init | ( | void | ) |
Initialize the timer library.
Initializes internal variables (list, locks and so on) for the CNE timer library.
void cne_timer_init | ( | struct cne_timer * | tim | ) |
Initialize a timer handle.
The cne_timer_init() function initializes the timer handle tim for use. No operations can be performed on a timer before it is initialized.
tim | The timer to initialize. |
int cne_timer_reset | ( | struct cne_timer * | tim, |
uint64_t | ticks, | ||
enum cne_timer_type | type, | ||
unsigned | tim_thread, | ||
cne_timer_cb_t | fct, | ||
void * | arg | ||
) |
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:
|
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. |
void cne_timer_reset_sync | ( | struct cne_timer * | tim, |
uint64_t | ticks, | ||
enum cne_timer_type | type, | ||
unsigned | tim_thread, | ||
cne_timer_cb_t | fct, | ||
void * | arg | ||
) |
Loop until cne_timer_reset() succeeds.
Reset and start the timer associated with the timer handle. Always succeed. See cne_timer_reset() for details.
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:
|
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. |
int cne_timer_stop | ( | struct cne_timer * | tim | ) |
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).
tim | The timer handle. |
void cne_timer_stop_sync | ( | struct cne_timer * | tim | ) |
Loop until cne_timer_stop() succeeds.
After a call to this function, the timer identified by tim is stopped. See cne_timer_stop() for details.
tim | The timer handle. |
int cne_timer_pending | ( | struct cne_timer * | tim | ) |
Test if a timer is pending.
The cne_timer_pending() function tests the PENDING status of the timer handle tim. A PENDING timer is one that has been scheduled and whose function has not yet been called.
tim | The timer handle. |
void cne_timer_manage | ( | void | ) |
Manage the timer list and execute callback functions.
This function must be called periodically from CNE threads main_loop(). It browses the list of pending timers and runs all timers that are expired.
The precision of the timer depends on the call frequency of this function. However, the more often the function is called, the more CPU resources it will use.
void cne_timer_dump_stats | ( | FILE * | f | ) |
Dump statistics about timers.
f | A pointer to a file for output |