DPDK  24.07.0
rte_timer.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_TIMER_H_
6 #define _RTE_TIMER_H_
7 
37 #include <stdio.h>
38 #include <stdint.h>
39 
40 #include <rte_common.h>
41 #include <rte_spinlock.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define RTE_TIMER_STOP 0
48 #define RTE_TIMER_PENDING 1
49 #define RTE_TIMER_RUNNING 2
50 #define RTE_TIMER_CONFIG 3
52 #define RTE_TIMER_NO_OWNER -2
57 enum rte_timer_type {
58  SINGLE,
59  PERIODICAL
60 };
61 
67  struct {
68  RTE_ATOMIC(uint16_t) state;
69  RTE_ATOMIC(int16_t) owner;
70  };
71  RTE_ATOMIC(uint32_t) u32;
72 };
73 
74 #ifdef RTE_LIBRTE_TIMER_DEBUG
75 
78 struct rte_timer_debug_stats {
79  uint64_t reset;
80  uint64_t stop;
81  uint64_t manage;
82  uint64_t pending;
83 };
84 #endif
85 
86 struct rte_timer;
87 
91 typedef void (*rte_timer_cb_t)(struct rte_timer *, void *);
92 
93 #define MAX_SKIPLIST_DEPTH 10
94 
98 struct rte_timer
99 {
100  uint64_t expire;
101  struct rte_timer *sl_next[MAX_SKIPLIST_DEPTH];
102  volatile union rte_timer_status status;
103  uint64_t period;
105  void *arg;
106 };
107 
108 
109 #ifdef __cplusplus
110 
113 #define RTE_TIMER_INITIALIZER { \
114  0, \
115  {NULL}, \
116  {{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
117  0, \
118  NULL, \
119  NULL, \
120  }
121 #else
122 
125 #define RTE_TIMER_INITIALIZER { \
126  .status = {{ \
127  .state = RTE_TIMER_STOP, \
128  .owner = RTE_TIMER_NO_OWNER, \
129  }}, \
130  }
131 #endif
132 
145 int rte_timer_data_alloc(uint32_t *id_ptr);
146 
157 int rte_timer_data_dealloc(uint32_t id);
158 
174 int rte_timer_subsystem_init(void);
175 
180 
191 void rte_timer_init(struct rte_timer *tim);
192 
235 int rte_timer_reset(struct rte_timer *tim, uint64_t ticks,
236  enum rte_timer_type type, unsigned tim_lcore,
237  rte_timer_cb_t fct, void *arg);
238 
271 void
272 rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
273  enum rte_timer_type type, unsigned tim_lcore,
274  rte_timer_cb_t fct, void *arg);
275 
299 int rte_timer_stop(struct rte_timer *tim);
300 
316 void rte_timer_stop_sync(struct rte_timer *tim);
317 
331 int rte_timer_pending(struct rte_timer *tim);
332 
343 int64_t rte_timer_next_ticks(void);
344 
360 int rte_timer_manage(void);
361 
371 int rte_timer_dump_stats(FILE *f);
372 
408 int
409 rte_timer_alt_reset(uint32_t timer_data_id, struct rte_timer *tim,
410  uint64_t ticks, enum rte_timer_type type,
411  unsigned int tim_lcore, rte_timer_cb_t fct, void *arg);
412 
430 int
431 rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim);
432 
436 typedef void (*rte_timer_alt_manage_cb_t)(struct rte_timer *tim);
437 
463 int
464 rte_timer_alt_manage(uint32_t timer_data_id, unsigned int *poll_lcores,
465  int n_poll_lcores, rte_timer_alt_manage_cb_t f);
466 
470 typedef void (*rte_timer_stop_all_cb_t)(struct rte_timer *tim, void *arg);
471 
492 int
493 rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
494  int nb_walk_lcores, rte_timer_stop_all_cb_t f, void *f_arg);
495 
511 int
512 rte_timer_alt_dump_stats(uint32_t timer_data_id, FILE *f);
513 
514 #ifdef __cplusplus
515 }
516 #endif
517 
518 #endif /* _RTE_TIMER_H_ */
int rte_timer_pending(struct rte_timer *tim)
void rte_timer_stop_sync(struct rte_timer *tim)
void(* rte_timer_alt_manage_cb_t)(struct rte_timer *tim)
Definition: rte_timer.h:436
rte_timer_cb_t f
Definition: rte_timer.h:104
rte_timer_type
Definition: rte_timer.h:57
int rte_timer_manage(void)
void * arg
Definition: rte_timer.h:105
void rte_timer_subsystem_finalize(void)
int16_t owner
Definition: rte_timer.h:69
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:68
int rte_timer_subsystem_init(void)
int rte_timer_stop(struct rte_timer *tim)
int rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores, int nb_walk_lcores, rte_timer_stop_all_cb_t f, void *f_arg)
void(* rte_timer_cb_t)(struct rte_timer *, void *)
Definition: rte_timer.h:91
int rte_timer_alt_manage(uint32_t timer_data_id, unsigned int *poll_lcores, int n_poll_lcores, rte_timer_alt_manage_cb_t f)
uint64_t expire
Definition: rte_timer.h:100
int rte_timer_alt_dump_stats(uint32_t timer_data_id, FILE *f)
int rte_timer_data_dealloc(uint32_t id)
void rte_timer_init(struct rte_timer *tim)
int rte_timer_alt_reset(uint32_t timer_data_id, struct rte_timer *tim, uint64_t ticks, enum rte_timer_type type, unsigned int tim_lcore, rte_timer_cb_t fct, void *arg)
uint32_t u32
Definition: rte_timer.h:71
uint64_t period
Definition: rte_timer.h:103
void(* rte_timer_stop_all_cb_t)(struct rte_timer *tim, void *arg)
Definition: rte_timer.h:470
int rte_timer_data_alloc(uint32_t *id_ptr)
int rte_timer_dump_stats(FILE *f)
int64_t rte_timer_next_ticks(void)
int rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim)