mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
sched/hrtimer: Update the comments.
This commit updated the comments. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
committed by
Donny(董九柱)
parent
3eedf5f22b
commit
dac48484ce
+30
-23
@@ -113,17 +113,14 @@ extern "C"
|
|||||||
* Name: hrtimer_init
|
* Name: hrtimer_init
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize a high-resolution timer instance. This function sets the
|
* Initialize a high-resolution timer instance.
|
||||||
* expiration callback and its argument. The timer is initialized in the
|
|
||||||
* inactive state and is not armed until hrtimer_start() is called.
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* hrtimer - Pointer to the hrtimer instance to be initialized
|
* hrtimer - Pointer to the hrtimer instance to be initialized
|
||||||
* func - Expiration callback function
|
|
||||||
* arg - Argument passed to the callback
|
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define hrtimer_init(hrtimer) memset(hrtimer, 0, sizeof(hrtimer_t))
|
#define hrtimer_init(hrtimer) memset(hrtimer, 0, sizeof(hrtimer_t))
|
||||||
@@ -132,14 +129,23 @@ extern "C"
|
|||||||
* Name: hrtimer_cancel
|
* Name: hrtimer_cancel
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Cancel a high-resolution timer asynchronously. This function set the
|
* Cancel a high-resolution timer asynchronously.
|
||||||
|
*
|
||||||
|
* If the timer is currently pending, it will be removed from the
|
||||||
|
* hrtimer queue and will not be executed.
|
||||||
|
*
|
||||||
|
* If the timer callback is currently executing. This function set the
|
||||||
* timer to the cancelled state. The caller will acquire the limited
|
* timer to the cancelled state. The caller will acquire the limited
|
||||||
* ownership of the hrtimer, which allow the caller restart the hrtimer,
|
* ownership of the hrtimer, which allow the caller restart the hrtimer,
|
||||||
* but the callback function may still be executing on another CPU, which
|
* but the callback function may still be executing on another CPU,
|
||||||
* prevent the caller from freeing the hrtimer. The caller must call
|
* which prevent the caller from freeing the hrtimer.
|
||||||
* `hrtimer_cancel` to wait for the callback to be finished. Please use
|
* The caller must call `hrtimer_cancel_sync` to wait for the callback
|
||||||
* the function with care. Concurrency errors are prone to occur in this
|
* to be finished. Please use the function with care.
|
||||||
* use case.
|
* Concurrency errors are prone to occur in this use case.
|
||||||
|
*
|
||||||
|
* If the canceled timer was the earliest expired timer in the queue,
|
||||||
|
* the expiration of the underlying hardware timer will be updated to the
|
||||||
|
* expiration time of the next earliest timer
|
||||||
*
|
*
|
||||||
* This function is non-blocking and does not wait for a running callback
|
* This function is non-blocking and does not wait for a running callback
|
||||||
* to finish.
|
* to finish.
|
||||||
@@ -151,11 +157,8 @@ extern "C"
|
|||||||
* OK (0) on success; a negated errno value on failure.
|
* OK (0) on success; a negated errno value on failure.
|
||||||
* > 0 on if the timer callback is running.
|
* > 0 on if the timer callback is running.
|
||||||
*
|
*
|
||||||
* Assumptions/Notes:
|
* Assumptions:
|
||||||
* - This function acquires the global hrtimer spinlock to protect both
|
* - The hrtimer is not NULL.
|
||||||
* the red-black tree and the timer state.
|
|
||||||
* - The caller must ensure that the timer structure is not freed until
|
|
||||||
* it is guaranteed that any running callback has returned.
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -165,13 +168,16 @@ int hrtimer_cancel(FAR hrtimer_t *hrtimer);
|
|||||||
* Name: hrtimer_cancel_sync
|
* Name: hrtimer_cancel_sync
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Cancel a high-resolution timer and wait until it becomes inactive.
|
|
||||||
*
|
|
||||||
* Cancel a high-resolution timer and synchronously wait the callback to
|
* Cancel a high-resolution timer and synchronously wait the callback to
|
||||||
* be finished. This function set the timer to the cancelled state and wait
|
* be finished.
|
||||||
* for all references to be released. The caller will then acquire full
|
*
|
||||||
* ownership of the hrtimer. After the function returns, the caller can
|
* If the timer callback is running, this function set the timer to the
|
||||||
* safely deallocate the hrtimer.
|
* cancelled state and wait for all all references to be released.
|
||||||
|
* The caller will then acquire full ownership of the hrtimer. After the
|
||||||
|
* function returns, the caller can safely deallocate the hrtimer.
|
||||||
|
* - If sleeping is allowed (normal task context), yields CPU briefly
|
||||||
|
* to avoid busy-waiting.
|
||||||
|
* - Otherwise (interrupt or idle task context), spins until completion.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* hrtimer - Pointer to the high-resolution timer instance to cancel.
|
* hrtimer - Pointer to the high-resolution timer instance to cancel.
|
||||||
@@ -193,13 +199,14 @@ int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer);
|
|||||||
* a relative timeout, depending on the selected mode.
|
* a relative timeout, depending on the selected mode.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* hrtimer - Timer instance to start
|
* hrtimer - Pointer to high-resolution timer.
|
||||||
* func - Expiration callback function
|
* func - Expiration callback function
|
||||||
* expired - Expiration time in nanoseconds
|
* expired - Expiration time in nanoseconds
|
||||||
* mode - HRTIMER_MODE_ABS or HRTIMER_MODE_REL
|
* mode - HRTIMER_MODE_ABS or HRTIMER_MODE_REL
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* OK on success; a negated errno value on failure.
|
* OK on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||||
|
|||||||
+13
-4
@@ -116,7 +116,8 @@ extern uintptr_t g_hrtimer_running[CONFIG_SMP_NCPUS];
|
|||||||
* now - The current time (nsecs).
|
* now - The current time (nsecs).
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void hrtimer_process(uint64_t now);
|
void hrtimer_process(uint64_t now);
|
||||||
@@ -141,6 +142,7 @@ void hrtimer_process(uint64_t now);
|
|||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* The underlying timer start function returns 0 on success.
|
* The underlying timer start function returns 0 on success.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline_function void hrtimer_reprogram(uint64_t next_expired)
|
static inline_function void hrtimer_reprogram(uint64_t next_expired)
|
||||||
@@ -174,15 +176,21 @@ static inline_function void hrtimer_reprogram(uint64_t next_expired)
|
|||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Compare two high-resolution timer nodes to determine their ordering
|
* Compare two high-resolution timer nodes to determine their ordering
|
||||||
* in the container. Used internally by the RB-tree macros.
|
* in the hrtimer queue. Used internally by the RB-tree macros.
|
||||||
|
*
|
||||||
|
* Note that RB-tree can not guarantee that timers with the same expired
|
||||||
|
* time will be processed in a FIFO order. However, this violation
|
||||||
|
* of the sorted queue invariant is acceptable and can not affect the
|
||||||
|
* functional correctness for the hrtimer.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* a - Pointer to the first hrtimer node.
|
* a - Pointer to the first hrtimer node.
|
||||||
* b - Pointer to the second hrtimer node.
|
* b - Pointer to the second hrtimer node.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* <0 if a expires before b
|
* <0 if a expires before b.
|
||||||
* >=0 if a expires after b
|
* >=0 if a expires after b.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_HRTIMER_TREE
|
#ifdef CONFIG_HRTIMER_TREE
|
||||||
@@ -304,6 +312,7 @@ static inline_function bool hrtimer_insert(FAR hrtimer_t *hrtimer)
|
|||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Pointer to the earliest timer, or NULL if none are pending.
|
* Pointer to the earliest timer, or NULL if none are pending.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline_function FAR hrtimer_t *hrtimer_get_first(void)
|
static inline_function FAR hrtimer_t *hrtimer_get_first(void)
|
||||||
|
|||||||
@@ -67,11 +67,8 @@
|
|||||||
* OK (0) on success; a negated errno value on failure.
|
* OK (0) on success; a negated errno value on failure.
|
||||||
* > 0 on if the timer callback is running.
|
* > 0 on if the timer callback is running.
|
||||||
*
|
*
|
||||||
* Assumptions/Notes:
|
* Assumptions:
|
||||||
* - This function acquires the global hrtimer spinlock to protect
|
* - The hrtimer is not NULL.
|
||||||
* the container.
|
|
||||||
* - The caller must ensure that the timer structure is not freed until
|
|
||||||
* it is guaranteed that any running callback has returned.
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -42,19 +42,19 @@ uintptr_t g_hrtimer_running[CONFIG_SMP_NCPUS];
|
|||||||
|
|
||||||
/* Global spinlock protecting the high-resolution timer subsystem.
|
/* Global spinlock protecting the high-resolution timer subsystem.
|
||||||
*
|
*
|
||||||
* This spinlock serializes access to the hrtimer container and
|
* This spinlock serializes access to the hrtimer queue and
|
||||||
* protects timer state transitions. It must be held whenever the
|
* protects timer state transitions. It must be held whenever the
|
||||||
* timer container is modified.
|
* timer queue is modified.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
seqcount_t g_hrtimer_lock = SEQLOCK_INITIALIZER;
|
seqcount_t g_hrtimer_lock = SEQLOCK_INITIALIZER;
|
||||||
|
|
||||||
/* Container for all active high-resolution timers.
|
/* HRTimer queue for all active high-resolution timers.
|
||||||
*
|
*
|
||||||
* When CONFIG_HRTIMER_TREE is enabled, timers are stored in a container.
|
* When CONFIG_HRTIMER_TREE is enabled, timers are stored in a queue.
|
||||||
* When disabled, timers are stored in a linked list.
|
* When disabled, timers are stored in a linked list.
|
||||||
*
|
*
|
||||||
* The container is ordered by absolute expiration time in
|
* The queue is ordered by absolute expiration time in
|
||||||
* both configurations.
|
* both configurations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -90,11 +90,11 @@ struct list_node g_hrtimer_list =
|
|||||||
* Name: RB_GENERATE
|
* Name: RB_GENERATE
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Instantiate the container helper functions for the hrtimer
|
* Instantiate the queue helper functions for the hrtimer
|
||||||
* subsystem.
|
* subsystem.
|
||||||
*
|
*
|
||||||
* This macro generates the static inline functions required to
|
* This macro generates the static inline functions required to
|
||||||
* manipulate the hrtimer container, including insertion,
|
* manipulate the hrtimer queue, including insertion,
|
||||||
* removal, and lookup operations.
|
* removal, and lookup operations.
|
||||||
*
|
*
|
||||||
* Note: This is only compiled when CONFIG_HRTIMER_TREE is enabled.
|
* Note: This is only compiled when CONFIG_HRTIMER_TREE is enabled.
|
||||||
|
|||||||
@@ -40,9 +40,9 @@
|
|||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Process all expired high-resolution timers. This function repeatedly
|
* Process all expired high-resolution timers. This function repeatedly
|
||||||
* retrieves the earliest timer from the active timer container, checks
|
* retrieves the earliest timer from the active timer queue, checks
|
||||||
* if it has expired relative to the current time, removes it from the
|
* if it has expired relative to the current time, removes it from the
|
||||||
* container, and invokes its callback function. Processing continues
|
* queue, and invokes its callback function. Processing continues
|
||||||
* until:
|
* until:
|
||||||
*
|
*
|
||||||
* 1. No additional timers have expired, or
|
* 1. No additional timers have expired, or
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
* None.
|
* None.
|
||||||
*
|
*
|
||||||
* Assumptions/Notes:
|
* Assumptions/Notes:
|
||||||
* - This function acquires a spinlock to protect the timer container.
|
* - This function acquires a spinlock to protect the timer queue.
|
||||||
* - Timer callbacks are invoked with interrupts enabled
|
* - Timer callbacks are invoked with interrupts enabled
|
||||||
* to avoid deadlocks.
|
* to avoid deadlocks.
|
||||||
* - DEBUGASSERT ensures that timer callbacks are valid.
|
* - DEBUGASSERT ensures that timer callbacks are valid.
|
||||||
|
|||||||
@@ -43,20 +43,16 @@
|
|||||||
* in nanoseconds.
|
* in nanoseconds.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* hrtimer - Pointer to the hrtimer structure.
|
* hrtimer - Pointer to the hrtimer.
|
||||||
* func - Expiration callback function.
|
* func - Expiration callback function.
|
||||||
* expired - Expiration time in nanoseconds. Interpretation
|
* expired - Expiration time in nanoseconds.
|
||||||
* depends on mode.
|
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* OK (0) on success, or a negated errno value on failure.
|
* OK (0) on success, or a negated errno value on failure.
|
||||||
*
|
*
|
||||||
* Assumptions/Notes:
|
* Assumptions:
|
||||||
* - This function disables interrupts briefly via spinlock to safely
|
* - hrtimer is not NULL and func is not NULL.
|
||||||
* insert the timer into the container.
|
*
|
||||||
* - Absolute mode sets the timer to expire at the given absolute time.
|
|
||||||
* - Relative mode sets the timer to expire after 'ns'
|
|
||||||
* nanoseconds from the current time.
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||||
@@ -72,7 +68,7 @@ int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
|||||||
|
|
||||||
flags = write_seqlock_irqsave(&g_hrtimer_lock);
|
flags = write_seqlock_irqsave(&g_hrtimer_lock);
|
||||||
|
|
||||||
/* Ensure no core can write the hrtimer. */
|
/* Ensure no running core can write the hrtimer. */
|
||||||
|
|
||||||
hrtimer_cancel_running(hrtimer);
|
hrtimer_cancel_running(hrtimer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user