2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TIMER_H
|
|
|
|
#define TIMER_H
|
|
|
|
|
2018-04-23 13:48:22 +08:00
|
|
|
typedef int (*timer_handle_t)(void *);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-04-25 15:14:44 +08:00
|
|
|
enum tick_mode {
|
|
|
|
TICK_MODE_ONESHOT = 0,
|
|
|
|
TICK_MODE_PERIODIC,
|
|
|
|
};
|
|
|
|
|
2018-06-05 15:25:07 +08:00
|
|
|
struct per_cpu_timers {
|
|
|
|
struct list_head timer_list; /* it's for runtime active timer list */
|
|
|
|
};
|
2018-04-25 15:14:44 +08:00
|
|
|
|
2018-04-25 14:26:33 +08:00
|
|
|
struct timer {
|
|
|
|
struct list_head node; /* link all timers */
|
2018-04-25 15:14:44 +08:00
|
|
|
int mode; /* timer mode: one-shot or periodic */
|
2018-04-25 14:26:33 +08:00
|
|
|
uint64_t fire_tsc; /* tsc deadline to interrupt */
|
2018-04-25 15:14:44 +08:00
|
|
|
uint64_t period_in_cycle; /* period of the periodic timer in unit of TSC cycles */
|
2018-04-25 14:26:33 +08:00
|
|
|
timer_handle_t func; /* callback if time reached */
|
|
|
|
void *priv_data; /* func private data */
|
|
|
|
};
|
|
|
|
|
2018-04-25 16:47:12 +08:00
|
|
|
/*
|
|
|
|
* Don't initialize a timer twice if it has been add to the timer list
|
|
|
|
* after call add_timer. If u want, delete the timer from the list first.
|
|
|
|
*/
|
2018-04-25 14:26:33 +08:00
|
|
|
static inline void initialize_timer(struct timer *timer,
|
|
|
|
timer_handle_t func,
|
|
|
|
void *priv_data,
|
2018-04-25 15:14:44 +08:00
|
|
|
uint64_t fire_tsc,
|
|
|
|
int mode,
|
|
|
|
uint64_t period_in_cycle)
|
2018-04-25 14:26:33 +08:00
|
|
|
{
|
2018-06-19 14:06:47 +08:00
|
|
|
if (timer != NULL) {
|
2018-04-25 14:26:33 +08:00
|
|
|
timer->func = func;
|
|
|
|
timer->priv_data = priv_data;
|
|
|
|
timer->fire_tsc = fire_tsc;
|
2018-04-25 15:14:44 +08:00
|
|
|
timer->mode = mode;
|
|
|
|
timer->period_in_cycle = period_in_cycle;
|
2018-05-08 13:59:51 +08:00
|
|
|
INIT_LIST_HEAD(&timer->node);
|
2018-04-25 14:26:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 16:47:12 +08:00
|
|
|
/*
|
|
|
|
* Don't call add_timer/del_timer in the timer callback function.
|
|
|
|
*/
|
2018-04-25 14:26:33 +08:00
|
|
|
int add_timer(struct timer *timer);
|
|
|
|
void del_timer(struct timer *timer);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-06-20 15:42:52 +08:00
|
|
|
void timer_softirq(uint16_t pcpu_id);
|
2018-03-07 20:57:14 +08:00
|
|
|
void timer_init(void);
|
|
|
|
void timer_cleanup(void);
|
|
|
|
void check_tsc(void);
|
2018-04-23 13:24:12 +08:00
|
|
|
void calibrate_tsc(void);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
#endif /* TIMER_H */
|