mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
sched/hrtimer: Replace hrtimer_gettime with clock_systime_nsec.
This commit move the hrtimer_gettime to clock_systime_nsec to improve the code reusability. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
committed by
GUIDINGLI
parent
65bc3db624
commit
89dbed25a0
@@ -733,6 +733,28 @@ clock_t clock_systime_ticks(void);
|
|||||||
|
|
||||||
void clock_systime_timespec(FAR struct timespec *ts);
|
void clock_systime_timespec(FAR struct timespec *ts);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: clock_systime_nsec
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return the current value of the system timer counter as
|
||||||
|
* uint64_t nanoseconds.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* ts - Location to return the time
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current system time in nanoseconds.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline_function uint64_t clock_systime_nsec(void)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_systime_timespec(&ts);
|
||||||
|
return clock_time2nsec(&ts);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: clock_cpuload
|
* Name: clock_cpuload
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -110,30 +110,6 @@ void hrtimer_process(uint64_t now);
|
|||||||
* Inline Functions
|
* Inline Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: hrtimer_gettime
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Get the current high-resolution time in nanoseconds.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* Current time in nanoseconds.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static inline_function
|
|
||||||
uint64_t hrtimer_gettime(void)
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
/* Get current time from platform-specific timer */
|
|
||||||
|
|
||||||
clock_systime_timespec(&ts);
|
|
||||||
|
|
||||||
/* Convert timespec to nanoseconds */
|
|
||||||
|
|
||||||
return clock_time2nsec(&ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: hrtimer_reprogram
|
* Name: hrtimer_reprogram
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hrtimer->expired = hrtimer_gettime() + expired;
|
hrtimer->expired = clock_systime_nsec() + expired;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure expiration time does not overflow */
|
/* Ensure expiration time does not overflow */
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ void nxsched_process_timer(void)
|
|||||||
HRTIMER_MODE_REL);
|
HRTIMER_MODE_REL);
|
||||||
}
|
}
|
||||||
|
|
||||||
hrtimer_process(hrtimer_gettime());
|
hrtimer_process(clock_systime_nsec());
|
||||||
#else
|
#else
|
||||||
/* Fallback: process one scheduler tick */
|
/* Fallback: process one scheduler tick */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user