Skip to content

Commit 5fd6021

Browse files
lifeixwenlingz
authored andcommitted
doc: hv: add comments to timer APIs for documentation
This patch adds more comment to describe functions that are interfaces to the other modules in the hypervisor. The comments are in doxygen-style for document generation. Tracked-On: #1595 Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent 2dbb0cb commit 5fd6021

File tree

3 files changed

+113
-53
lines changed

3 files changed

+113
-53
lines changed

doc/acrn.doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ INPUT = custom-doxygen/mainpage.md \
808808
../hypervisor/include/public/acrn_common.h \
809809
../hypervisor/include/public/acrn_hv_defs.h \
810810
../hypervisor/include/arch/x86/guest/vcpu.h \
811+
../hypervisor/include/arch/x86/timer.h \
811812
../hypervisor/arch/x86/trusty.c \
812813
../devicemodel/include/virtio.h \
813814
../hypervisor/include/arch/x86/ioapic.h \

doc/developer-guides/hld/hv-timer.rst

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,27 @@ tsc-deadline timer mode by writing the local APIC LVT register.
2424
Data Structures and APIs
2525
************************
2626

27-
.. note:: API link to hv_timer and per_cpu_timer structs in include/arch/x86/timer.h
28-
And to the function APIs there too.
29-
30-
Before adding a timer, we must initialize the timer with
31-
*initialize_timer*. The processor generates a timer interrupt when the
32-
value of timer-stamp counter is greater than or equal to the *fire_tsc*
33-
field. If you want to add a periodic timer, you should also pass the
34-
period (unit in tsc cycles), otherwise, period_in_cycle will be ignored.
35-
When the timer interrupt is generated, it will call the callback
36-
function *func* with parameter *priv_data*.
37-
38-
The *initialize_timer* function only initialize the timer data
39-
structure; it will not program the ``IA32_TSC_DEADLINE_MSR`` to generate
40-
the timer interrupt. If you want to generate a timer interrupt, you must
41-
call *add_timer* to add the timer to the *per_cpu_timer* timer_list. In
42-
return, we will chose the nearest expired timer on the timer_list and
43-
program ``IA32_TSC_DEADLINE_MSR`` by writing its value to fire_ts. Then
44-
when the fire_tsc expires, it raises the interrupt whose callback raises
45-
a softirq. We will handle the software interrupt before the VM reenters
46-
the guest. (Currently, the hypervisor only uses the timer for the
47-
console).
48-
49-
The timer softirq handler will check each expired timer on its
50-
timer_list. Before calling the expired timer callback handler, it will
51-
remove the timer from its logical cpu timer_list. After calling the
52-
timer callback handler, it will re-add the timer to the timer_list if
53-
it's a periodic timer. If you want to modify a timer before it expires,
54-
you should call del_timer to remove the timer from the timer_list, then
55-
call add_timer again after updating the timer fields.
56-
57-
.. note::
58-
59-
Only call initialize_timer only once for each timer.
60-
Don't call add_timer or del_timer in the timer callback function.
27+
Interfaces Design
28+
=================
29+
30+
.. doxygenfunction:: initialize_timer
31+
:project: Project ACRN
32+
33+
.. doxygenfunction:: timer_expired
34+
:project: Project ACRN
35+
36+
.. doxygenfunction:: add_timer
37+
:project: Project ACRN
38+
39+
.. doxygenfunction:: del_timer
40+
:project: Project ACRN
41+
42+
.. doxygenfunction:: timer_init
43+
:project: Project ACRN
44+
45+
.. doxygenfunction:: check_tsc
46+
:project: Project ACRN
47+
48+
.. doxygenfunction:: calibrate_tsc
49+
:project: Project ACRN
50+

hypervisor/include/arch/x86/timer.h

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,62 @@
77
#ifndef TIMER_H
88
#define TIMER_H
99

10+
/**
11+
* @brief Timer
12+
*
13+
* @defgroup timer ACRN Timer
14+
* @{
15+
*/
16+
1017
typedef void (*timer_handle_t)(void *data);
1118

19+
/**
20+
* @brief Definition of timer tick mode
21+
*/
1222
enum tick_mode {
13-
TICK_MODE_ONESHOT = 0,
14-
TICK_MODE_PERIODIC,
23+
TICK_MODE_ONESHOT = 0, /**< one-shot mode */
24+
TICK_MODE_PERIODIC, /**< periodic mode */
1525
};
1626

27+
/**
28+
* @brief Definition of timers for per-cpu
29+
*/
1730
struct per_cpu_timers {
18-
struct list_head timer_list; /* it's for runtime active timer list */
31+
struct list_head timer_list; /**< it's for runtime active timer list */
1932
};
2033

34+
/**
35+
* @brief Definition of timer
36+
*/
2137
struct hv_timer {
22-
struct list_head node; /* link all timers */
23-
enum tick_mode mode; /* timer mode: one-shot or periodic */
24-
uint64_t fire_tsc; /* tsc deadline to interrupt */
25-
uint64_t period_in_cycle; /* period of the periodic timer in unit of TSC cycles */
26-
timer_handle_t func; /* callback if time reached */
27-
void *priv_data; /* func private data */
38+
struct list_head node; /**< link all timers */
39+
enum tick_mode mode; /**< timer mode: one-shot or periodic */
40+
uint64_t fire_tsc; /**< tsc deadline to interrupt */
41+
uint64_t period_in_cycle; /**< period of the periodic timer in unit of TSC cycles */
42+
timer_handle_t func; /**< callback if time reached */
43+
void *priv_data; /**< func private data */
2844
};
2945

30-
/*
31-
* Don't initialize a timer twice if it has been add to the timer list
32-
* after call add_timer. If u want, delete the timer from the list first.
46+
/* External Interfaces */
47+
48+
/**
49+
* @brief Initialize a timer structure.
50+
*
51+
* @param[in] timer Pointer to timer.
52+
* @param[in] func irq callback if time reached.
53+
* @param[in] priv_data func private data.
54+
* @param[in] fire_tsc tsc deadline to interrupt.
55+
* @param[in] mode timer mode.
56+
* @param[in] period_in_cycle period of the periodic timer in unit of TSC cycles.
57+
*
58+
* @remark Don't initialize a timer twice if it has been added to the timer list
59+
* after calling add_timer. If you want to, delete the timer from the list first.
60+
*
61+
* @return None
3362
*/
3463
static inline void initialize_timer(struct hv_timer *timer,
35-
timer_handle_t func,
36-
void *priv_data,
37-
uint64_t fire_tsc,
38-
int mode,
39-
uint64_t period_in_cycle)
64+
timer_handle_t func, void *priv_data,
65+
uint64_t fire_tsc, int mode, uint64_t period_in_cycle)
4066
{
4167
if (timer != NULL) {
4268
timer->func = func;
@@ -48,19 +74,62 @@ static inline void initialize_timer(struct hv_timer *timer,
4874
}
4975
}
5076

77+
/**
78+
* @brief Check a timer whether expired.
79+
*
80+
* @param[in] timer Pointer to timer.
81+
*
82+
* @retval true if the timer is expired, false otherwise.
83+
*/
5184
static inline bool timer_expired(const struct hv_timer *timer)
5285
{
5386
return ((timer->fire_tsc == 0UL) || (rdtsc() >= timer->fire_tsc));
5487
}
5588

56-
/*
57-
* Don't call add_timer/del_timer in the timer callback function.
89+
/**
90+
* @brief Add a timer.
91+
*
92+
* @param[in] timer Pointer to timer.
93+
*
94+
* @retval 0 on success
95+
* @retval -EINVAL timer has an invalid value
96+
*
97+
* @remark Don't call it in the timer callback function or interrupt content.
5898
*/
5999
int add_timer(struct hv_timer *timer);
100+
101+
/**
102+
* @brief Delete a timer.
103+
*
104+
* @param[in] timer Pointer to timer.
105+
*
106+
* @return None
107+
*
108+
* @remark Don't call it in the timer callback function or interrupt content.
109+
*/
60110
void del_timer(struct hv_timer *timer);
61111

112+
/**
113+
* @brief Initialize timer.
114+
*
115+
* @return None
116+
*/
62117
void timer_init(void);
118+
119+
/**
120+
* @brief Check tsc to make sure rdtsc is enabled.
121+
*/
63122
void check_tsc(void);
123+
124+
/**
125+
* @brief Calibrate tsc.
126+
*
127+
* @return None
128+
*/
64129
void calibrate_tsc(void);
65130

131+
/**
132+
* @}
133+
*/
134+
66135
#endif /* TIMER_H */

0 commit comments

Comments
 (0)