tle_timer.h revision aa97dd1c
1/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *		 http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * Copyright (c) 2016  Intel Corporation.
17 * Licensed under the Apache License, Version 2.0 (the "License");
18 * you may not use this file except in compliance with the License.
19 * You may obtain a copy of the License at:
20 *
21 *     http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 */
29
30#ifndef __tle_timer_h__
31#define __tle_timer_h__
32
33#include <stdint.h>
34#include <rte_config.h>
35#include <rte_debug.h>
36#include <rte_malloc.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/** @file
43 *	@brief timer definitions
44 *
45 * Design parameters:
46 *	granularity: configurable in terms of units (i.e. cycles or ms).
47 *	e.g. with 100ms tick
48 *	required max period: 2.5 hours => 150 minutes => 90,000 ticks
49 *	Rounding up to 256k ticks yields a two-level 512 slot-per-level
50 *	wheel, resulting in a 7-hour max period.
51 */
52
53struct tle_timer_wheel_args {
54	uint32_t tick_size; /** tick size in units */
55
56	int32_t socket_id; /**< socket ID to allocate memory for. */
57
58	uint32_t max_timer; /** maximum number of timers */
59};
60
61struct tle_timer_wheel;
62
63/** initialize a timer wheel */
64struct tle_timer_wheel *
65tle_timer_create(struct tle_timer_wheel_args *prm, uint64_t now);
66
67/** free a timer wheel */
68void
69tle_timer_free(struct tle_timer_wheel *tw);
70
71/** start a timer */
72void *
73tle_timer_start(struct tle_timer_wheel *tw, void *obj, uint64_t interval);
74
75/** stop a timer */
76void
77tle_timer_stop(struct tle_timer_wheel *tw, void *timer);
78
79/** run the timer wheel. Call in every tick_size cycles
80 * (e.g. equivalent of 100ms).
81 */
82void
83tle_timer_expire(struct tle_timer_wheel *tw, uint64_t now);
84
85/** bulk retrieve of expired timers */
86int
87tle_timer_get_expired_bulk(struct tle_timer_wheel *tw, void *timers[],
88	uint32_t num);
89
90#ifdef __cplusplus
91}
92#endif
93
94#endif /* __tle_timer_h__ */
95