CNDP  22.08.0
cne_timer.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2010-2022 Intel Corporation
3  */
4 
5 #ifndef _CNE_TIMER_H_
6 #define _CNE_TIMER_H_
7 
33 #include <stdio.h> // for FILE
34 #include <stdint.h> // for uint64_t, int16_t, uint16_t
35 #include <stddef.h>
36 #include <cne_common.h> // for CNE_STD_C11
37 #include <cne_atomic.h> // for atomic_uint_least32_t
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define CNE_TIMER_STOP 0
44 #define CNE_TIMER_PENDING 1
45 #define CNE_TIMER_RUNNING 2
46 #define CNE_TIMER_CONFIG 3
47 #define CNE_TIMER_NO_OWNER -2
52 enum cne_timer_type { SINGLE, PERIODICAL };
53 
60  struct {
61  uint16_t state;
62  int16_t owner;
63  };
64  CNE_ATOMIC(uint_least32_t) u32;
65 };
66 
71  uint64_t reset;
72  uint64_t stop;
73  uint64_t manage;
74  uint64_t pending;
75 };
76 
77 struct cne_timer;
78 
82 typedef void (*cne_timer_cb_t)(struct cne_timer *, void *);
83 
84 #define MAX_SKIPLIST_DEPTH 10
85 
89 struct cne_timer {
90  uint64_t expire;
91  struct cne_timer *sl_next[MAX_SKIPLIST_DEPTH];
92  volatile union cne_timer_status status;
93  uint64_t period;
95  void *arg;
96 };
97 
98 #ifdef __cplusplus
102 #define CNE_TIMER_INITIALIZER \
103  { \
104  0, {NULL}, {{CNE_TIMER_STOP, CNE_TIMER_NO_OWNER}}, 0, NULL, NULL, \
105  }
106 #else
110 #define CNE_TIMER_INITIALIZER \
111  { \
112  .status = {{ \
113  .state = CNE_TIMER_STOP, \
114  .owner = CNE_TIMER_NO_OWNER, \
115  }}, \
116  }
117 #endif
118 
126 
137 void cne_timer_init(struct cne_timer *tim);
138 
180 int cne_timer_reset(struct cne_timer *tim, uint64_t ticks, enum cne_timer_type type,
181  unsigned tim_thread, cne_timer_cb_t fct, void *arg);
182 
208 void cne_timer_reset_sync(struct cne_timer *tim, uint64_t ticks, enum cne_timer_type type,
209  unsigned tim_thread, cne_timer_cb_t fct, void *arg);
210 
234 int cne_timer_stop(struct cne_timer *tim);
235 
245 void cne_timer_stop_sync(struct cne_timer *tim);
246 
260 int cne_timer_pending(struct cne_timer *tim);
261 
273 void cne_timer_manage(void);
274 
281 void cne_timer_dump_stats(FILE *f);
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /* _CNE_TIMER_H_ */
#define CNE_STD_C11
Definition: cne_common.h:91
void(* cne_timer_cb_t)(struct cne_timer *, void *)
Definition: cne_timer.h:82
cne_timer_type
Definition: cne_timer.h:52
void cne_timer_stop_sync(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_subsystem_init(void)
int cne_timer_pending(struct cne_timer *tim)
void cne_timer_init(struct cne_timer *tim)
void cne_timer_manage(void)
void cne_timer_dump_stats(FILE *f)
uint64_t period
Definition: cne_timer.h:93
struct cne_timer * sl_next[MAX_SKIPLIST_DEPTH]
Definition: cne_timer.h:91
void * arg
Definition: cne_timer.h:95
volatile union cne_timer_status status
Definition: cne_timer.h:92
uint64_t expire
Definition: cne_timer.h:90
cne_timer_cb_t f
Definition: cne_timer.h:94
int16_t owner
Definition: cne_timer.h:62
CNE_ATOMIC(uint_least32_t) u32
uint16_t state
Definition: cne_timer.h:61