DPDK  17.11.10
rte_timer.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_TIMER_H_
35 #define _RTE_TIMER_H_
36 
66 #include <stdio.h>
67 #include <stdint.h>
68 #include <stddef.h>
69 #include <rte_common.h>
70 #include <rte_config.h>
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
76 #define RTE_TIMER_STOP 0
77 #define RTE_TIMER_PENDING 1
78 #define RTE_TIMER_RUNNING 2
79 #define RTE_TIMER_CONFIG 3
81 #define RTE_TIMER_NO_OWNER -2
86 enum rte_timer_type {
87  SINGLE,
88  PERIODICAL
89 };
90 
97  struct {
98  uint16_t state;
99  int16_t owner;
100  };
101  uint32_t u32;
102 };
103 
104 #ifdef RTE_LIBRTE_TIMER_DEBUG
105 
108 struct rte_timer_debug_stats {
109  uint64_t reset;
110  uint64_t stop;
111  uint64_t manage;
112  uint64_t pending;
113 };
114 #endif
115 
116 struct rte_timer;
117 
121 typedef void (*rte_timer_cb_t)(struct rte_timer *, void *);
122 
123 #define MAX_SKIPLIST_DEPTH 10
124 
128 struct rte_timer
129 {
130  uint64_t expire;
131  struct rte_timer *sl_next[MAX_SKIPLIST_DEPTH];
132  volatile union rte_timer_status status;
133  uint64_t period;
135  void *arg;
136 };
137 
138 
139 #ifdef __cplusplus
140 
143 #define RTE_TIMER_INITIALIZER { \
144  0, \
145  {NULL}, \
146  {{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
147  0, \
148  NULL, \
149  NULL, \
150  }
151 #else
152 
155 #define RTE_TIMER_INITIALIZER { \
156  .status = {{ \
157  .state = RTE_TIMER_STOP, \
158  .owner = RTE_TIMER_NO_OWNER, \
159  }}, \
160  }
161 #endif
162 
169 void rte_timer_subsystem_init(void);
170 
181 void rte_timer_init(struct rte_timer *tim);
182 
225 int rte_timer_reset(struct rte_timer *tim, uint64_t ticks,
226  enum rte_timer_type type, unsigned tim_lcore,
227  rte_timer_cb_t fct, void *arg);
228 
229 
256 void
257 rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
258  enum rte_timer_type type, unsigned tim_lcore,
259  rte_timer_cb_t fct, void *arg);
260 
284 int rte_timer_stop(struct rte_timer *tim);
285 
286 
296 void rte_timer_stop_sync(struct rte_timer *tim);
297 
311 int rte_timer_pending(struct rte_timer *tim);
312 
324 void rte_timer_manage(void);
325 
332 void rte_timer_dump_stats(FILE *f);
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 
338 #endif /* _RTE_TIMER_H_ */
int rte_timer_pending(struct rte_timer *tim)
void rte_timer_subsystem_init(void)
void rte_timer_stop_sync(struct rte_timer *tim)
rte_timer_cb_t f
Definition: rte_timer.h:134
rte_timer_type
Definition: rte_timer.h:86
volatile union rte_timer_status status
Definition: rte_timer.h:132
void * arg
Definition: rte_timer.h:135
int16_t owner
Definition: rte_timer.h:99
void rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks, enum rte_timer_type type, unsigned tim_lcore, rte_timer_cb_t fct, void *arg)
int rte_timer_reset(struct rte_timer *tim, uint64_t ticks, enum rte_timer_type type, unsigned tim_lcore, rte_timer_cb_t fct, void *arg)
uint16_t state
Definition: rte_timer.h:98
int rte_timer_stop(struct rte_timer *tim)
void(* rte_timer_cb_t)(struct rte_timer *, void *)
Definition: rte_timer.h:121
uint64_t expire
Definition: rte_timer.h:130
void rte_timer_init(struct rte_timer *tim)
void rte_timer_dump_stats(FILE *f)
#define RTE_STD_C11
Definition: rte_common.h:66
uint32_t u32
Definition: rte_timer.h:101
uint64_t period
Definition: rte_timer.h:133
void rte_timer_manage(void)