CNDP 22.08.0
Loading...
Searching...
No Matches
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
32
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
40extern "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
48
52enum 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
77struct cne_timer;
78
82typedef void (*cne_timer_cb_t)(struct cne_timer *, void *);
83
84#define MAX_SKIPLIST_DEPTH 10
85
89struct 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
137void cne_timer_init(struct cne_timer *tim);
138
180int 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
208void 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
234int cne_timer_stop(struct cne_timer *tim);
235
246
261
274
282
283#ifdef __cplusplus
284}
285#endif
286
287#endif /* _CNE_TIMER_H_ */
#define CNE_STD_C11
Definition cne_common.h:91
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_cb_t(struct cne_timer *, void *)
Definition cne_timer.h:82
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
CNE_ATOMIC(uint_least32_t) u32