DPDK  17.05.2
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 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 #define RTE_TIMER_STOP 0
76 #define RTE_TIMER_PENDING 1
77 #define RTE_TIMER_RUNNING 2
78 #define RTE_TIMER_CONFIG 3
80 #define RTE_TIMER_NO_OWNER -2
85 enum rte_timer_type {
86  SINGLE,
87  PERIODICAL
88 };
89 
96  struct {
97  uint16_t state;
98  int16_t owner;
99  };
100  uint32_t u32;
101 };
102 
103 #ifdef RTE_LIBRTE_TIMER_DEBUG
104 
107 struct rte_timer_debug_stats {
108  uint64_t reset;
109  uint64_t stop;
110  uint64_t manage;
111  uint64_t pending;
112 };
113 #endif
114 
115 struct rte_timer;
116 
120 typedef void (*rte_timer_cb_t)(struct rte_timer *, void *);
121 
122 #define MAX_SKIPLIST_DEPTH 10
123 
127 struct rte_timer
128 {
129  uint64_t expire;
130  struct rte_timer *sl_next[MAX_SKIPLIST_DEPTH];
131  volatile union rte_timer_status status;
132  uint64_t period;
134  void *arg;
135 };
136 
137 
138 #ifdef __cplusplus
139 
142 #define RTE_TIMER_INITIALIZER { \
143  0, \
144  {NULL}, \
145  {{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
146  0, \
147  NULL, \
148  NULL, \
149  }
150 #else
151 
154 #define RTE_TIMER_INITIALIZER { \
155  .status = {{ \
156  .state = RTE_TIMER_STOP, \
157  .owner = RTE_TIMER_NO_OWNER, \
158  }}, \
159  }
160 #endif
161 
168 void rte_timer_subsystem_init(void);
169 
180 void rte_timer_init(struct rte_timer *tim);
181 
224 int rte_timer_reset(struct rte_timer *tim, uint64_t ticks,
225  enum rte_timer_type type, unsigned tim_lcore,
226  rte_timer_cb_t fct, void *arg);
227 
228 
255 void
256 rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
257  enum rte_timer_type type, unsigned tim_lcore,
258  rte_timer_cb_t fct, void *arg);
259 
283 int rte_timer_stop(struct rte_timer *tim);
284 
285 
295 void rte_timer_stop_sync(struct rte_timer *tim);
296 
310 int rte_timer_pending(struct rte_timer *tim);
311 
323 void rte_timer_manage(void);
324 
331 void rte_timer_dump_stats(FILE *f);
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* _RTE_TIMER_H_ */