xref: /f-stack/dpdk/lib/librte_timer/rte_timer.h (revision 2d9fd380)
1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606  * Copyright(c) 2010-2014 Intel Corporation
3a9643ea8Slogwang  */
4a9643ea8Slogwang 
5a9643ea8Slogwang #ifndef _RTE_TIMER_H_
6a9643ea8Slogwang #define _RTE_TIMER_H_
7a9643ea8Slogwang 
8a9643ea8Slogwang /**
9a9643ea8Slogwang  * @file
10a9643ea8Slogwang  RTE Timer
11a9643ea8Slogwang  *
12a9643ea8Slogwang  * This library provides a timer service to RTE Data Plane execution
13a9643ea8Slogwang  * units that allows the execution of callback functions asynchronously.
14a9643ea8Slogwang  *
15a9643ea8Slogwang  * - Timers can be periodic or single (one-shot).
16a9643ea8Slogwang  * - The timers can be loaded from one core and executed on another. This has
17a9643ea8Slogwang  *   to be specified in the call to rte_timer_reset().
18a9643ea8Slogwang  * - High precision is possible. NOTE: this depends on the call frequency to
19a9643ea8Slogwang  *   rte_timer_manage() that check the timer expiration for the local core.
20a9643ea8Slogwang  * - If not used in an application, for improved performance, it can be
21a9643ea8Slogwang  *   disabled at compilation time by not calling the rte_timer_manage()
22a9643ea8Slogwang  *   to improve performance.
23a9643ea8Slogwang  *
24a9643ea8Slogwang  * The timer library uses the rte_get_hpet_cycles() function that
25a9643ea8Slogwang  * uses the HPET, when available, to provide a reliable time reference. [HPET
26a9643ea8Slogwang  * routines are provided by EAL, which falls back to using the chip TSC (time-
27a9643ea8Slogwang  * stamp counter) as fallback when HPET is not available]
28a9643ea8Slogwang  *
29a9643ea8Slogwang  * This library provides an interface to add, delete and restart a
30a9643ea8Slogwang  * timer. The API is based on the BSD callout(9) API with a few
31a9643ea8Slogwang  * differences.
32a9643ea8Slogwang  *
33a9643ea8Slogwang  * See the RTE architecture documentation for more information about the
34a9643ea8Slogwang  * design of this library.
35a9643ea8Slogwang  */
36a9643ea8Slogwang 
37a9643ea8Slogwang #include <stdio.h>
38a9643ea8Slogwang #include <stdint.h>
39a9643ea8Slogwang #include <stddef.h>
402bfe3f2eSlogwang #include <rte_common.h>
412bfe3f2eSlogwang #include <rte_config.h>
424418919fSjohnjiang #include <rte_spinlock.h>
43a9643ea8Slogwang 
44a9643ea8Slogwang #ifdef __cplusplus
45a9643ea8Slogwang extern "C" {
46a9643ea8Slogwang #endif
47a9643ea8Slogwang 
48a9643ea8Slogwang #define RTE_TIMER_STOP    0 /**< State: timer is stopped. */
49a9643ea8Slogwang #define RTE_TIMER_PENDING 1 /**< State: timer is scheduled. */
50a9643ea8Slogwang #define RTE_TIMER_RUNNING 2 /**< State: timer function is running. */
51a9643ea8Slogwang #define RTE_TIMER_CONFIG  3 /**< State: timer is being configured. */
52a9643ea8Slogwang 
53a9643ea8Slogwang #define RTE_TIMER_NO_OWNER -2 /**< Timer has no owner. */
54a9643ea8Slogwang 
55a9643ea8Slogwang /**
56a9643ea8Slogwang  * Timer type: Periodic or single (one-shot).
57a9643ea8Slogwang  */
58a9643ea8Slogwang enum rte_timer_type {
59a9643ea8Slogwang 	SINGLE,
60a9643ea8Slogwang 	PERIODICAL
61a9643ea8Slogwang };
62a9643ea8Slogwang 
63a9643ea8Slogwang /**
64a9643ea8Slogwang  * Timer status: A union of the state (stopped, pending, running,
65a9643ea8Slogwang  * config) and an owner (the id of the lcore that owns the timer).
66a9643ea8Slogwang  */
67a9643ea8Slogwang union rte_timer_status {
682bfe3f2eSlogwang 	RTE_STD_C11
69a9643ea8Slogwang 	struct {
70a9643ea8Slogwang 		uint16_t state;  /**< Stop, pending, running, config. */
71a9643ea8Slogwang 		int16_t owner;   /**< The lcore that owns the timer. */
72a9643ea8Slogwang 	};
73a9643ea8Slogwang 	uint32_t u32;            /**< To atomic-set status + owner. */
74a9643ea8Slogwang };
75a9643ea8Slogwang 
76a9643ea8Slogwang #ifdef RTE_LIBRTE_TIMER_DEBUG
77a9643ea8Slogwang /**
78a9643ea8Slogwang  * A structure that stores the timer statistics (per-lcore).
79a9643ea8Slogwang  */
80a9643ea8Slogwang struct rte_timer_debug_stats {
81a9643ea8Slogwang 	uint64_t reset;   /**< Number of success calls to rte_timer_reset(). */
82a9643ea8Slogwang 	uint64_t stop;    /**< Number of success calls to rte_timer_stop(). */
83a9643ea8Slogwang 	uint64_t manage;  /**< Number of calls to rte_timer_manage(). */
84a9643ea8Slogwang 	uint64_t pending; /**< Number of pending/running timers. */
85a9643ea8Slogwang };
86a9643ea8Slogwang #endif
87a9643ea8Slogwang 
88a9643ea8Slogwang struct rte_timer;
89a9643ea8Slogwang 
90a9643ea8Slogwang /**
91a9643ea8Slogwang  * Callback function type for timer expiry.
92a9643ea8Slogwang  */
93a9643ea8Slogwang typedef void (*rte_timer_cb_t)(struct rte_timer *, void *);
94a9643ea8Slogwang 
95a9643ea8Slogwang #define MAX_SKIPLIST_DEPTH 10
96a9643ea8Slogwang 
97a9643ea8Slogwang /**
98a9643ea8Slogwang  * A structure describing a timer in RTE.
99a9643ea8Slogwang  */
100a9643ea8Slogwang struct rte_timer
101a9643ea8Slogwang {
102a9643ea8Slogwang 	uint64_t expire;       /**< Time when timer expire. */
103a9643ea8Slogwang 	struct rte_timer *sl_next[MAX_SKIPLIST_DEPTH];
104a9643ea8Slogwang 	volatile union rte_timer_status status; /**< Status of timer. */
105a9643ea8Slogwang 	uint64_t period;       /**< Period of timer (0 if not periodic). */
106a9643ea8Slogwang 	rte_timer_cb_t f;      /**< Callback function. */
107a9643ea8Slogwang 	void *arg;             /**< Argument to callback function. */
108a9643ea8Slogwang };
109a9643ea8Slogwang 
110a9643ea8Slogwang 
111a9643ea8Slogwang #ifdef __cplusplus
112a9643ea8Slogwang /**
113a9643ea8Slogwang  * A C++ static initializer for a timer structure.
114a9643ea8Slogwang  */
115a9643ea8Slogwang #define RTE_TIMER_INITIALIZER {             \
116a9643ea8Slogwang 	0,                                      \
117a9643ea8Slogwang 	{NULL},                                 \
118a9643ea8Slogwang 	{{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
119a9643ea8Slogwang 	0,                                      \
120a9643ea8Slogwang 	NULL,                                   \
121a9643ea8Slogwang 	NULL,                                   \
122a9643ea8Slogwang 	}
123a9643ea8Slogwang #else
124a9643ea8Slogwang /**
125a9643ea8Slogwang  * A static initializer for a timer structure.
126a9643ea8Slogwang  */
127a9643ea8Slogwang #define RTE_TIMER_INITIALIZER {                      \
128a9643ea8Slogwang 		.status = {{                         \
129a9643ea8Slogwang 			.state = RTE_TIMER_STOP,     \
130a9643ea8Slogwang 			.owner = RTE_TIMER_NO_OWNER, \
131a9643ea8Slogwang 		}},                                  \
132a9643ea8Slogwang 	}
133a9643ea8Slogwang #endif
134a9643ea8Slogwang 
135a9643ea8Slogwang /**
1364418919fSjohnjiang  * Allocate a timer data instance in shared memory to track a set of pending
1374418919fSjohnjiang  * timer lists.
1384418919fSjohnjiang  *
1394418919fSjohnjiang  * @param id_ptr
1404418919fSjohnjiang  *   Pointer to variable into which to write the identifier of the allocated
1414418919fSjohnjiang  *   timer data instance.
1424418919fSjohnjiang  *
1434418919fSjohnjiang  * @return
1444418919fSjohnjiang  *   - 0: Success
1454418919fSjohnjiang  *   - -ENOSPC: maximum number of timer data instances already allocated
1464418919fSjohnjiang  */
1474418919fSjohnjiang int rte_timer_data_alloc(uint32_t *id_ptr);
1484418919fSjohnjiang 
1494418919fSjohnjiang /**
1504418919fSjohnjiang  * Deallocate a timer data instance.
1514418919fSjohnjiang  *
1524418919fSjohnjiang  * @param id
1534418919fSjohnjiang  *   Identifier of the timer data instance to deallocate.
1544418919fSjohnjiang  *
1554418919fSjohnjiang  * @return
1564418919fSjohnjiang  *   - 0: Success
1574418919fSjohnjiang  *   - -EINVAL: invalid timer data instance identifier
1584418919fSjohnjiang  */
1594418919fSjohnjiang int rte_timer_data_dealloc(uint32_t id);
1604418919fSjohnjiang 
1614418919fSjohnjiang /**
162a9643ea8Slogwang  * Initialize the timer library.
163a9643ea8Slogwang  *
164a9643ea8Slogwang  * Initializes internal variables (list, locks and so on) for the RTE
165a9643ea8Slogwang  * timer library.
1664418919fSjohnjiang  *
1674418919fSjohnjiang  * @note
1684418919fSjohnjiang  *   This function must be called in every process before using the library.
1694418919fSjohnjiang  *
1704418919fSjohnjiang  * @return
1714418919fSjohnjiang  *   - 0: Success
1724418919fSjohnjiang  *   - -ENOMEM: Unable to allocate memory needed to initialize timer
1734418919fSjohnjiang  *      subsystem
174a9643ea8Slogwang  */
1754418919fSjohnjiang int rte_timer_subsystem_init(void);
1764418919fSjohnjiang 
1774418919fSjohnjiang /**
1784418919fSjohnjiang  * Free timer subsystem resources.
1794418919fSjohnjiang  */
1804418919fSjohnjiang void rte_timer_subsystem_finalize(void);
181a9643ea8Slogwang 
182a9643ea8Slogwang /**
183a9643ea8Slogwang  * Initialize a timer handle.
184a9643ea8Slogwang  *
185a9643ea8Slogwang  * The rte_timer_init() function initializes the timer handle *tim*
186a9643ea8Slogwang  * for use. No operations can be performed on a timer before it is
187a9643ea8Slogwang  * initialized.
188a9643ea8Slogwang  *
189a9643ea8Slogwang  * @param tim
190a9643ea8Slogwang  *   The timer to initialize.
191a9643ea8Slogwang  */
192a9643ea8Slogwang void rte_timer_init(struct rte_timer *tim);
193a9643ea8Slogwang 
194a9643ea8Slogwang /**
195a9643ea8Slogwang  * Reset and start the timer associated with the timer handle.
196a9643ea8Slogwang  *
197a9643ea8Slogwang  * The rte_timer_reset() function resets and starts the timer
198a9643ea8Slogwang  * associated with the timer handle *tim*. When the timer expires after
199a9643ea8Slogwang  * *ticks* HPET cycles, the function specified by *fct* will be called
200a9643ea8Slogwang  * with the argument *arg* on core *tim_lcore*.
201a9643ea8Slogwang  *
202a9643ea8Slogwang  * If the timer associated with the timer handle is already running
203a9643ea8Slogwang  * (in the RUNNING state), the function will fail. The user has to check
204a9643ea8Slogwang  * the return value of the function to see if there is a chance that the
205a9643ea8Slogwang  * timer is in the RUNNING state.
206a9643ea8Slogwang  *
207a9643ea8Slogwang  * If the timer is being configured on another core (the CONFIG state),
208a9643ea8Slogwang  * it will also fail.
209a9643ea8Slogwang  *
210a9643ea8Slogwang  * If the timer is pending or stopped, it will be rescheduled with the
211a9643ea8Slogwang  * new parameters.
212a9643ea8Slogwang  *
213a9643ea8Slogwang  * @param tim
214a9643ea8Slogwang  *   The timer handle.
215a9643ea8Slogwang  * @param ticks
216a9643ea8Slogwang  *   The number of cycles (see rte_get_hpet_hz()) before the callback
217a9643ea8Slogwang  *   function is called.
218a9643ea8Slogwang  * @param type
219a9643ea8Slogwang  *   The type can be either:
220a9643ea8Slogwang  *   - PERIODICAL: The timer is automatically reloaded after execution
221a9643ea8Slogwang  *     (returns to the PENDING state)
222a9643ea8Slogwang  *   - SINGLE: The timer is one-shot, that is, the timer goes to a
223a9643ea8Slogwang  *     STOPPED state after execution.
224a9643ea8Slogwang  * @param tim_lcore
225a9643ea8Slogwang  *   The ID of the lcore where the timer callback function has to be
226a9643ea8Slogwang  *   executed. If tim_lcore is LCORE_ID_ANY, the timer library will
227a9643ea8Slogwang  *   launch it on a different core for each call (round-robin).
228a9643ea8Slogwang  * @param fct
229a9643ea8Slogwang  *   The callback function of the timer.
230a9643ea8Slogwang  * @param arg
231a9643ea8Slogwang  *   The user argument of the callback function.
232a9643ea8Slogwang  * @return
233a9643ea8Slogwang  *   - 0: Success; the timer is scheduled.
234a9643ea8Slogwang  *   - (-1): Timer is in the RUNNING or CONFIG state.
235a9643ea8Slogwang  */
236a9643ea8Slogwang int rte_timer_reset(struct rte_timer *tim, uint64_t ticks,
237a9643ea8Slogwang 		    enum rte_timer_type type, unsigned tim_lcore,
238a9643ea8Slogwang 		    rte_timer_cb_t fct, void *arg);
239a9643ea8Slogwang 
240a9643ea8Slogwang /**
241a9643ea8Slogwang  * Loop until rte_timer_reset() succeeds.
242a9643ea8Slogwang  *
243a9643ea8Slogwang  * Reset and start the timer associated with the timer handle. Always
244a9643ea8Slogwang  * succeed. See rte_timer_reset() for details.
245a9643ea8Slogwang  *
246a9643ea8Slogwang  * @param tim
247a9643ea8Slogwang  *   The timer handle.
248a9643ea8Slogwang  * @param ticks
249a9643ea8Slogwang  *   The number of cycles (see rte_get_hpet_hz()) before the callback
250a9643ea8Slogwang  *   function is called.
251a9643ea8Slogwang  * @param type
252a9643ea8Slogwang  *   The type can be either:
253a9643ea8Slogwang  *   - PERIODICAL: The timer is automatically reloaded after execution
254a9643ea8Slogwang  *     (returns to the PENDING state)
255a9643ea8Slogwang  *   - SINGLE: The timer is one-shot, that is, the timer goes to a
256a9643ea8Slogwang  *     STOPPED state after execution.
257a9643ea8Slogwang  * @param tim_lcore
258a9643ea8Slogwang  *   The ID of the lcore where the timer callback function has to be
259a9643ea8Slogwang  *   executed. If tim_lcore is LCORE_ID_ANY, the timer library will
260a9643ea8Slogwang  *   launch it on a different core for each call (round-robin).
261a9643ea8Slogwang  * @param fct
262a9643ea8Slogwang  *   The callback function of the timer.
263a9643ea8Slogwang  * @param arg
264a9643ea8Slogwang  *   The user argument of the callback function.
2650c6bd470Sfengbojiang  *
2660c6bd470Sfengbojiang  * @note
2670c6bd470Sfengbojiang  *   This API should not be called inside a timer's callback function to
2680c6bd470Sfengbojiang  *   reset another timer; doing so could hang in certain scenarios. Instead,
2690c6bd470Sfengbojiang  *   the rte_timer_reset() API can be called directly and its return code
2700c6bd470Sfengbojiang  *   can be checked for success or failure.
271a9643ea8Slogwang  */
272a9643ea8Slogwang void
273a9643ea8Slogwang rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
274a9643ea8Slogwang 		     enum rte_timer_type type, unsigned tim_lcore,
275a9643ea8Slogwang 		     rte_timer_cb_t fct, void *arg);
276a9643ea8Slogwang 
277a9643ea8Slogwang /**
278a9643ea8Slogwang  * Stop a timer.
279a9643ea8Slogwang  *
280a9643ea8Slogwang  * The rte_timer_stop() function stops the timer associated with the
281a9643ea8Slogwang  * timer handle *tim*. It may fail if the timer is currently running or
282a9643ea8Slogwang  * being configured.
283a9643ea8Slogwang  *
284a9643ea8Slogwang  * If the timer is pending or stopped (for instance, already expired),
285a9643ea8Slogwang  * the function will succeed. The timer handle tim must have been
286a9643ea8Slogwang  * initialized using rte_timer_init(), otherwise, undefined behavior
287a9643ea8Slogwang  * will occur.
288a9643ea8Slogwang  *
289a9643ea8Slogwang  * This function can be called safely from a timer callback. If it
290a9643ea8Slogwang  * succeeds, the timer is not referenced anymore by the timer library
291a9643ea8Slogwang  * and the timer structure can be freed (even in the callback
292a9643ea8Slogwang  * function).
293a9643ea8Slogwang  *
294a9643ea8Slogwang  * @param tim
295a9643ea8Slogwang  *   The timer handle.
296a9643ea8Slogwang  * @return
297a9643ea8Slogwang  *   - 0: Success; the timer is stopped.
298a9643ea8Slogwang  *   - (-1): The timer is in the RUNNING or CONFIG state.
299a9643ea8Slogwang  */
300a9643ea8Slogwang int rte_timer_stop(struct rte_timer *tim);
301a9643ea8Slogwang 
302a9643ea8Slogwang /**
303a9643ea8Slogwang  * Loop until rte_timer_stop() succeeds.
304a9643ea8Slogwang  *
305a9643ea8Slogwang  * After a call to this function, the timer identified by *tim* is
306a9643ea8Slogwang  * stopped. See rte_timer_stop() for details.
307a9643ea8Slogwang  *
308a9643ea8Slogwang  * @param tim
309a9643ea8Slogwang  *   The timer handle.
3100c6bd470Sfengbojiang  *
3110c6bd470Sfengbojiang  * @note
3120c6bd470Sfengbojiang  *   This API should not be called inside a timer's callback function to
3130c6bd470Sfengbojiang  *   stop another timer; doing so could hang in certain scenarios. Instead, the
3140c6bd470Sfengbojiang  *   rte_timer_stop() API can be called directly and its return code can
3150c6bd470Sfengbojiang  *   be checked for success or failure.
316a9643ea8Slogwang  */
317a9643ea8Slogwang void rte_timer_stop_sync(struct rte_timer *tim);
318a9643ea8Slogwang 
319a9643ea8Slogwang /**
320a9643ea8Slogwang  * Test if a timer is pending.
321a9643ea8Slogwang  *
322a9643ea8Slogwang  * The rte_timer_pending() function tests the PENDING status
323a9643ea8Slogwang  * of the timer handle *tim*. A PENDING timer is one that has been
324a9643ea8Slogwang  * scheduled and whose function has not yet been called.
325a9643ea8Slogwang  *
326a9643ea8Slogwang  * @param tim
327a9643ea8Slogwang  *   The timer handle.
328a9643ea8Slogwang  * @return
329a9643ea8Slogwang  *   - 0: The timer is not pending.
330a9643ea8Slogwang  *   - 1: The timer is pending.
331a9643ea8Slogwang  */
332a9643ea8Slogwang int rte_timer_pending(struct rte_timer *tim);
333a9643ea8Slogwang 
334a9643ea8Slogwang /**
335*2d9fd380Sjfb8856606  * @warning
336*2d9fd380Sjfb8856606  * @b EXPERIMENTAL: this API may change without prior notice
337*2d9fd380Sjfb8856606  *
338*2d9fd380Sjfb8856606  * Time until the next timer on the current lcore
339*2d9fd380Sjfb8856606  * This function gives the ticks until the next timer will be active.
340*2d9fd380Sjfb8856606  *
341*2d9fd380Sjfb8856606  * @return
342*2d9fd380Sjfb8856606  *   - -EINVAL: invalid timer data instance identifier
343*2d9fd380Sjfb8856606  *   - -ENOENT: no timer pending
344*2d9fd380Sjfb8856606  *   - 0: a timer is pending and will run at next rte_timer_manage()
345*2d9fd380Sjfb8856606  *   - >0: ticks until the next timer is ready
346*2d9fd380Sjfb8856606  */
347*2d9fd380Sjfb8856606 __rte_experimental
348*2d9fd380Sjfb8856606 int64_t rte_timer_next_ticks(void);
349*2d9fd380Sjfb8856606 
350*2d9fd380Sjfb8856606 /**
351a9643ea8Slogwang  * Manage the timer list and execute callback functions.
352a9643ea8Slogwang  *
353a9643ea8Slogwang  * This function must be called periodically from EAL lcores
354a9643ea8Slogwang  * main_loop(). It browses the list of pending timers and runs all
355a9643ea8Slogwang  * timers that are expired.
356a9643ea8Slogwang  *
357a9643ea8Slogwang  * The precision of the timer depends on the call frequency of this
358a9643ea8Slogwang  * function. However, the more often the function is called, the more
359a9643ea8Slogwang  * CPU resources it will use.
3604418919fSjohnjiang  *
3614418919fSjohnjiang  * @return
3624418919fSjohnjiang  *   - 0: Success
3634418919fSjohnjiang  *   - -EINVAL: timer subsystem not yet initialized
364a9643ea8Slogwang  */
3654418919fSjohnjiang int rte_timer_manage(void);
366a9643ea8Slogwang 
367a9643ea8Slogwang /**
368a9643ea8Slogwang  * Dump statistics about timers.
369a9643ea8Slogwang  *
370a9643ea8Slogwang  * @param f
371a9643ea8Slogwang  *   A pointer to a file for output
3724418919fSjohnjiang  * @return
3734418919fSjohnjiang  *   - 0: Success
3744418919fSjohnjiang  *   - -EINVAL: timer subsystem not yet initialized
375a9643ea8Slogwang  */
3764418919fSjohnjiang int rte_timer_dump_stats(FILE *f);
3774418919fSjohnjiang 
3784418919fSjohnjiang /**
3794418919fSjohnjiang  * This function is the same as rte_timer_reset(), except that it allows a
3804418919fSjohnjiang  * caller to specify the rte_timer_data instance containing the list to which
3814418919fSjohnjiang  * the timer should be added.
3824418919fSjohnjiang  *
3834418919fSjohnjiang  * @see rte_timer_reset()
3844418919fSjohnjiang  *
3854418919fSjohnjiang  * @param timer_data_id
3864418919fSjohnjiang  *   An identifier indicating which instance of timer data should be used for
3874418919fSjohnjiang  *   this operation.
3884418919fSjohnjiang  * @param tim
3894418919fSjohnjiang  *   The timer handle.
3904418919fSjohnjiang  * @param ticks
3914418919fSjohnjiang  *   The number of cycles (see rte_get_hpet_hz()) before the callback
3924418919fSjohnjiang  *   function is called.
3934418919fSjohnjiang  * @param type
3944418919fSjohnjiang  *   The type can be either:
3954418919fSjohnjiang  *   - PERIODICAL: The timer is automatically reloaded after execution
3964418919fSjohnjiang  *     (returns to the PENDING state)
3974418919fSjohnjiang  *   - SINGLE: The timer is one-shot, that is, the timer goes to a
3984418919fSjohnjiang  *     STOPPED state after execution.
3994418919fSjohnjiang  * @param tim_lcore
4004418919fSjohnjiang  *   The ID of the lcore where the timer callback function has to be
4014418919fSjohnjiang  *   executed. If tim_lcore is LCORE_ID_ANY, the timer library will
4024418919fSjohnjiang  *   launch it on a different core for each call (round-robin).
4034418919fSjohnjiang  * @param fct
4044418919fSjohnjiang  *   The callback function of the timer. This parameter can be NULL if (and
4054418919fSjohnjiang  *   only if) rte_timer_alt_manage() will be used to manage this timer.
4064418919fSjohnjiang  * @param arg
4074418919fSjohnjiang  *   The user argument of the callback function.
4084418919fSjohnjiang  * @return
4094418919fSjohnjiang  *   - 0: Success; the timer is scheduled.
4104418919fSjohnjiang  *   - (-1): Timer is in the RUNNING or CONFIG state.
4114418919fSjohnjiang  *   - -EINVAL: invalid timer_data_id
4124418919fSjohnjiang  */
4134418919fSjohnjiang int
4144418919fSjohnjiang rte_timer_alt_reset(uint32_t timer_data_id, struct rte_timer *tim,
4154418919fSjohnjiang 		    uint64_t ticks, enum rte_timer_type type,
4164418919fSjohnjiang 		    unsigned int tim_lcore, rte_timer_cb_t fct, void *arg);
4174418919fSjohnjiang 
4184418919fSjohnjiang /**
4194418919fSjohnjiang  * This function is the same as rte_timer_stop(), except that it allows a
4204418919fSjohnjiang  * caller to specify the rte_timer_data instance containing the list from which
4214418919fSjohnjiang  * this timer should be removed.
4224418919fSjohnjiang  *
4234418919fSjohnjiang  * @see rte_timer_stop()
4244418919fSjohnjiang  *
4254418919fSjohnjiang  * @param timer_data_id
4264418919fSjohnjiang  *   An identifier indicating which instance of timer data should be used for
4274418919fSjohnjiang  *   this operation.
4284418919fSjohnjiang  * @param tim
4294418919fSjohnjiang  *   The timer handle.
4304418919fSjohnjiang  * @return
4314418919fSjohnjiang  *   - 0: Success; the timer is stopped.
4324418919fSjohnjiang  *   - (-1): The timer is in the RUNNING or CONFIG state.
4334418919fSjohnjiang  *   - -EINVAL: invalid timer_data_id
4344418919fSjohnjiang  */
4354418919fSjohnjiang int
4364418919fSjohnjiang rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim);
4374418919fSjohnjiang 
4384418919fSjohnjiang /**
4394418919fSjohnjiang  * Callback function type for rte_timer_alt_manage().
4404418919fSjohnjiang  */
4414418919fSjohnjiang typedef void (*rte_timer_alt_manage_cb_t)(struct rte_timer *tim);
4424418919fSjohnjiang 
4434418919fSjohnjiang /**
4444418919fSjohnjiang  * Manage a set of timer lists and execute the specified callback function for
4454418919fSjohnjiang  * all expired timers. This function is similar to rte_timer_manage(), except
4464418919fSjohnjiang  * that it allows a caller to specify the timer_data instance that should
4474418919fSjohnjiang  * be operated on, as well as a set of lcore IDs identifying which timer lists
4484418919fSjohnjiang  * should be processed.  Callback functions of individual timers are ignored.
4494418919fSjohnjiang  *
4504418919fSjohnjiang  * @see rte_timer_manage()
4514418919fSjohnjiang  *
4524418919fSjohnjiang  * @param timer_data_id
4534418919fSjohnjiang  *   An identifier indicating which instance of timer data should be used for
4544418919fSjohnjiang  *   this operation.
4554418919fSjohnjiang  * @param poll_lcores
4564418919fSjohnjiang  *   An array of lcore ids identifying the timer lists that should be processed.
4574418919fSjohnjiang  *   NULL is allowed - if NULL, the timer list corresponding to the lcore
4584418919fSjohnjiang  *   calling this routine is processed (same as rte_timer_manage()).
4594418919fSjohnjiang  * @param n_poll_lcores
4604418919fSjohnjiang  *   The size of the poll_lcores array. If 'poll_lcores' is NULL, this parameter
4614418919fSjohnjiang  *   is ignored.
4624418919fSjohnjiang  * @param f
4634418919fSjohnjiang  *   The callback function which should be called for all expired timers.
4644418919fSjohnjiang  * @return
4654418919fSjohnjiang  *   - 0: success
4664418919fSjohnjiang  *   - -EINVAL: invalid timer_data_id
4674418919fSjohnjiang  */
4684418919fSjohnjiang int
4694418919fSjohnjiang rte_timer_alt_manage(uint32_t timer_data_id, unsigned int *poll_lcores,
4704418919fSjohnjiang 		     int n_poll_lcores, rte_timer_alt_manage_cb_t f);
4714418919fSjohnjiang 
4724418919fSjohnjiang /**
4734418919fSjohnjiang  * Callback function type for rte_timer_stop_all().
4744418919fSjohnjiang  */
4754418919fSjohnjiang typedef void (*rte_timer_stop_all_cb_t)(struct rte_timer *tim, void *arg);
4764418919fSjohnjiang 
4774418919fSjohnjiang /**
4784418919fSjohnjiang  * Walk the pending timer lists for the specified lcore IDs, and for each timer
4794418919fSjohnjiang  * that is encountered, stop it and call the specified callback function to
4804418919fSjohnjiang  * process it further.
4814418919fSjohnjiang  *
4824418919fSjohnjiang  * @param timer_data_id
4834418919fSjohnjiang  *   An identifier indicating which instance of timer data should be used for
4844418919fSjohnjiang  *   this operation.
4854418919fSjohnjiang  * @param walk_lcores
4864418919fSjohnjiang  *   An array of lcore ids identifying the timer lists that should be processed.
4874418919fSjohnjiang  * @param nb_walk_lcores
4884418919fSjohnjiang  *   The size of the walk_lcores array.
4894418919fSjohnjiang  * @param f
4904418919fSjohnjiang  *   The callback function which should be called for each timers. Can be NULL.
4914418919fSjohnjiang  * @param f_arg
4924418919fSjohnjiang  *   An arbitrary argument that will be passed to f, if it is called.
4934418919fSjohnjiang  * @return
4944418919fSjohnjiang  *   - 0: success
4954418919fSjohnjiang  *   - EINVAL: invalid timer_data_id
4964418919fSjohnjiang  */
4974418919fSjohnjiang int
4984418919fSjohnjiang rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
4994418919fSjohnjiang 		   int nb_walk_lcores, rte_timer_stop_all_cb_t f, void *f_arg);
5004418919fSjohnjiang 
5014418919fSjohnjiang /**
5024418919fSjohnjiang  * This function is the same as rte_timer_dump_stats(), except that it allows
5034418919fSjohnjiang  * the caller to specify the rte_timer_data instance that should be used.
5044418919fSjohnjiang  *
5054418919fSjohnjiang  * @see rte_timer_dump_stats()
5064418919fSjohnjiang  *
5074418919fSjohnjiang  * @param timer_data_id
5084418919fSjohnjiang  *   An identifier indicating which instance of timer data should be used for
5094418919fSjohnjiang  *   this operation.
5104418919fSjohnjiang  * @param f
5114418919fSjohnjiang  *   A pointer to a file for output
5124418919fSjohnjiang  * @return
5134418919fSjohnjiang  *   - 0: success
5144418919fSjohnjiang  *   - -EINVAL: invalid timer_data_id
5154418919fSjohnjiang  */
5164418919fSjohnjiang int
5174418919fSjohnjiang rte_timer_alt_dump_stats(uint32_t timer_data_id, FILE *f);
518a9643ea8Slogwang 
519a9643ea8Slogwang #ifdef __cplusplus
520a9643ea8Slogwang }
521a9643ea8Slogwang #endif
522a9643ea8Slogwang 
523a9643ea8Slogwang #endif /* _RTE_TIMER_H_ */
524