DPDK  16.04.0
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 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 #define RTE_TIMER_STOP 0
75 #define RTE_TIMER_PENDING 1
76 #define RTE_TIMER_RUNNING 2
77 #define RTE_TIMER_CONFIG 3
79 #define RTE_TIMER_NO_OWNER -2
84 enum rte_timer_type {
85  SINGLE,
86  PERIODICAL
87 };
88 
94  struct {
95  uint16_t state;
96  int16_t owner;
97  };
98  uint32_t u32;
99 };
100 
101 #ifdef RTE_LIBRTE_TIMER_DEBUG
102 
105 struct rte_timer_debug_stats {
106  uint64_t reset;
107  uint64_t stop;
108  uint64_t manage;
109  uint64_t pending;
110 };
111 #endif
112 
113 struct rte_timer;
114 
118 typedef void (*rte_timer_cb_t)(struct rte_timer *, void *);
119 
120 #define MAX_SKIPLIST_DEPTH 10
121 
125 struct rte_timer
126 {
127  uint64_t expire;
128  struct rte_timer *sl_next[MAX_SKIPLIST_DEPTH];
129  volatile union rte_timer_status status;
130  uint64_t period;
132  void *arg;
133 };
134 
135 
136 #ifdef __cplusplus
137 
140 #define RTE_TIMER_INITIALIZER { \
141  0, \
142  {NULL}, \
143  {{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
144  0, \
145  NULL, \
146  NULL, \
147  }
148 #else
149 
152 #define RTE_TIMER_INITIALIZER { \
153  .status = {{ \
154  .state = RTE_TIMER_STOP, \
155  .owner = RTE_TIMER_NO_OWNER, \
156  }}, \
157  }
158 #endif
159 
166 void rte_timer_subsystem_init(void);
167 
178 void rte_timer_init(struct rte_timer *tim);
179 
222 int rte_timer_reset(struct rte_timer *tim, uint64_t ticks,
223  enum rte_timer_type type, unsigned tim_lcore,
224  rte_timer_cb_t fct, void *arg);
225 
226 
253 void
254 rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
255  enum rte_timer_type type, unsigned tim_lcore,
256  rte_timer_cb_t fct, void *arg);
257 
281 int rte_timer_stop(struct rte_timer *tim);
282 
283 
293 void rte_timer_stop_sync(struct rte_timer *tim);
294 
308 int rte_timer_pending(struct rte_timer *tim);
309 
321 void rte_timer_manage(void);
322 
329 void rte_timer_dump_stats(FILE *f);
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif /* _RTE_TIMER_H_ */