mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
clock: Add new type ssystime_t for relative 64-bit ticks, change ticks<->time conversion functions to use ssystime_t
This commit is contained in:
committed by
Gregory Nutt
parent
325ba1a803
commit
c57d49f420
@@ -199,6 +199,14 @@ typedef uint64_t systime_t;
|
|||||||
typedef uint32_t systime_t;
|
typedef uint32_t systime_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* This type used to hold relative ticks that may have negative value */
|
||||||
|
|
||||||
|
#ifdef CONFIG_SYSTEM_TIME64
|
||||||
|
typedef int64_t ssystime_t;
|
||||||
|
#else
|
||||||
|
typedef int32_t ssystime_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
+4
-3
@@ -98,9 +98,10 @@ void weak_function clock_timer(void);
|
|||||||
|
|
||||||
int clock_abstime2ticks(clockid_t clockid,
|
int clock_abstime2ticks(clockid_t clockid,
|
||||||
FAR const struct timespec *abstime,
|
FAR const struct timespec *abstime,
|
||||||
FAR int *ticks);
|
FAR ssystime_t *ticks);
|
||||||
int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks);
|
int clock_time2ticks(FAR const struct timespec *reltime,
|
||||||
int clock_ticks2time(int ticks, FAR struct timespec *reltime);
|
FAR ssystime_t *ticks);
|
||||||
|
int clock_ticks2time(ssystime_t ticks, FAR struct timespec *reltime);
|
||||||
void clock_timespec_add(FAR const struct timespec *ts1,
|
void clock_timespec_add(FAR const struct timespec *ts1,
|
||||||
FAR const struct timespec *ts2,
|
FAR const struct timespec *ts2,
|
||||||
FAR struct timespec *ts3);
|
FAR struct timespec *ts3);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ static long compare_timespec(FAR const struct timespec *a,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime,
|
int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime,
|
||||||
FAR int *ticks)
|
FAR ssystime_t *ticks)
|
||||||
{
|
{
|
||||||
struct timespec currtime;
|
struct timespec currtime;
|
||||||
struct timespec reltime;
|
struct timespec reltime;
|
||||||
|
|||||||
@@ -63,9 +63,9 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int clock_ticks2time(int ticks, FAR struct timespec *reltime)
|
int clock_ticks2time(ssystime_t ticks, FAR struct timespec *reltime)
|
||||||
{
|
{
|
||||||
int remainder;
|
ssystime_t remainder;
|
||||||
|
|
||||||
reltime->tv_sec = ticks / TICK_PER_SEC;
|
reltime->tv_sec = ticks / TICK_PER_SEC;
|
||||||
remainder = ticks - TICK_PER_SEC * reltime->tv_sec;
|
remainder = ticks - TICK_PER_SEC * reltime->tv_sec;
|
||||||
|
|||||||
@@ -67,7 +67,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks)
|
int clock_time2ticks(FAR const struct timespec *reltime,
|
||||||
|
FAR ssystime_t *ticks)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_HAVE_LONG_LONG
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
int64_t relnsec;
|
int64_t relnsec;
|
||||||
@@ -83,7 +84,7 @@ int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks)
|
|||||||
* that is greater than or equal to the exact number of tick.
|
* that is greater than or equal to the exact number of tick.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*ticks = (int)((relnsec + NSEC_PER_TICK - 1) / NSEC_PER_TICK);
|
*ticks = (ssystime_t)((relnsec + NSEC_PER_TICK - 1) / NSEC_PER_TICK);
|
||||||
return OK;
|
return OK;
|
||||||
#else
|
#else
|
||||||
int32_t relusec;
|
int32_t relusec;
|
||||||
@@ -110,7 +111,7 @@ int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks)
|
|||||||
* that is greater than or equal to the exact number of tick.
|
* that is greater than or equal to the exact number of tick.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*ticks = (int)((relusec + USEC_PER_TICK - 1) / USEC_PER_TICK);
|
*ticks = (ssystime_t)((relusec + USEC_PER_TICK - 1) / USEC_PER_TICK);
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
|
|||||||
|
|
||||||
if (mqdes->msgq->msglist.head == NULL)
|
if (mqdes->msgq->msglist.head == NULL)
|
||||||
{
|
{
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
|
|
||||||
/* Convert the timespec to clock ticks. We must have interrupts
|
/* Convert the timespec to clock ticks. We must have interrupts
|
||||||
* disabled here so that this time stays valid until the wait begins.
|
* disabled here so that this time stays valid until the wait begins.
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio,
|
|||||||
FAR struct mqueue_inode_s *msgq;
|
FAR struct mqueue_inode_s *msgq;
|
||||||
FAR struct mqueue_msg_s *mqmsg = NULL;
|
FAR struct mqueue_msg_s *mqmsg = NULL;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
int result;
|
int result;
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex,
|
|||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
uint16_t oldstate;
|
uint16_t oldstate;
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
int mypid = (int)getpid();
|
int mypid = (int)getpid();
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
int status;
|
int status;
|
||||||
|
|||||||
@@ -358,8 +358,8 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
|
|||||||
if (policy == SCHED_SPORADIC)
|
if (policy == SCHED_SPORADIC)
|
||||||
{
|
{
|
||||||
FAR struct sporadic_s *sporadic;
|
FAR struct sporadic_s *sporadic;
|
||||||
int repl_ticks;
|
ssystime_t repl_ticks;
|
||||||
int budget_ticks;
|
ssystime_t budget_ticks;
|
||||||
|
|
||||||
/* Convert timespec values to system clock ticks */
|
/* Convert timespec values to system clock ticks */
|
||||||
|
|
||||||
|
|||||||
@@ -127,8 +127,10 @@ int sched_getparam (pid_t pid, FAR struct sched_param *param)
|
|||||||
param->sched_ss_low_priority = (int)sporadic->low_priority;
|
param->sched_ss_low_priority = (int)sporadic->low_priority;
|
||||||
param->sched_ss_max_repl = (int)sporadic->max_repl;
|
param->sched_ss_max_repl = (int)sporadic->max_repl;
|
||||||
|
|
||||||
clock_ticks2time((int)sporadic->repl_period, ¶m->sched_ss_repl_period);
|
clock_ticks2time((ssystime_t)sporadic->repl_period,
|
||||||
clock_ticks2time((int)sporadic->budget, ¶m->sched_ss_init_budget);
|
¶m->sched_ss_repl_period);
|
||||||
|
clock_ticks2time((ssystime_t)sporadic->budget,
|
||||||
|
¶m->sched_ss_init_budget);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
|
|||||||
{
|
{
|
||||||
FAR struct sporadic_s *sporadic;
|
FAR struct sporadic_s *sporadic;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int repl_ticks;
|
ssystime_t repl_ticks;
|
||||||
int budget_ticks;
|
ssystime_t budget_ticks;
|
||||||
|
|
||||||
if (param->sched_ss_max_repl < 1 ||
|
if (param->sched_ss_max_repl < 1 ||
|
||||||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
|
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
|
||||||
|
|||||||
@@ -180,8 +180,8 @@ int sched_setscheduler(pid_t pid, int policy,
|
|||||||
case SCHED_SPORADIC:
|
case SCHED_SPORADIC:
|
||||||
{
|
{
|
||||||
FAR struct sporadic_s *sporadic;
|
FAR struct sporadic_s *sporadic;
|
||||||
int repl_ticks;
|
ssystime_t repl_ticks;
|
||||||
int budget_ticks;
|
ssystime_t budget_ticks;
|
||||||
|
|
||||||
if (param->sched_ss_max_repl < 1 ||
|
if (param->sched_ss_max_repl < 1 ||
|
||||||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
|
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime)
|
|||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
int errcode;
|
int errcode;
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
|
|||||||
{
|
{
|
||||||
systime_t elapsed;
|
systime_t elapsed;
|
||||||
systime_t remaining;
|
systime_t remaining;
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
|
|
||||||
/* REVISIT: The conversion from time to ticks and back could
|
/* REVISIT: The conversion from time to ticks and back could
|
||||||
* be avoided. clock_timespec_subtract() would be used instead
|
* be avoided. clock_timespec_subtract() would be used instead
|
||||||
@@ -192,16 +192,16 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
|
|||||||
* amount of time that we failed to wait.
|
* amount of time that we failed to wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (elapsed >= (uint32_t)ticks)
|
if (elapsed >= (systime_t)ticks)
|
||||||
{
|
{
|
||||||
remaining = 0;
|
remaining = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remaining = (uint32_t)ticks - elapsed;
|
remaining = (systime_t)ticks - elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)clock_ticks2time((int)remaining, rmtp);
|
(void)clock_ticks2time((ssystime_t)remaining, rmtp);
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
|
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
|
||||||
{
|
{
|
||||||
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
|
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
|
||||||
int ticks;
|
ssystime_t ticks;
|
||||||
|
|
||||||
if (!timer || !value)
|
if (!timer || !value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ int timer_settime(timer_t timerid, int flags,
|
|||||||
{
|
{
|
||||||
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
|
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
|
||||||
irqstate_t intflags;
|
irqstate_t intflags;
|
||||||
int delay;
|
ssystime_t delay;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
/* Some sanity checks */
|
/* Some sanity checks */
|
||||||
@@ -332,7 +332,11 @@ int timer_settime(timer_t timerid, int flags,
|
|||||||
|
|
||||||
if (value->it_interval.tv_sec > 0 || value->it_interval.tv_nsec > 0)
|
if (value->it_interval.tv_sec > 0 || value->it_interval.tv_nsec > 0)
|
||||||
{
|
{
|
||||||
(void)clock_time2ticks(&value->it_interval, &timer->pt_delay);
|
(void)clock_time2ticks(&value->it_interval, &delay);
|
||||||
|
|
||||||
|
/* REVISIT: Should pt_delay be ssystime_t? */
|
||||||
|
|
||||||
|
timer->pt_delay = (int)delay;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -379,6 +383,10 @@ int timer_settime(timer_t timerid, int flags,
|
|||||||
|
|
||||||
if (delay > 0)
|
if (delay > 0)
|
||||||
{
|
{
|
||||||
|
/* REVISIT: Should pt_last be ssystime_t? Should wd_start delay be
|
||||||
|
* ssystime_t?
|
||||||
|
*/
|
||||||
|
|
||||||
timer->pt_last = delay;
|
timer->pt_last = delay;
|
||||||
ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout,
|
ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout,
|
||||||
1, (uint32_t)((wdparm_t)timer));
|
1, (uint32_t)((wdparm_t)timer));
|
||||||
|
|||||||
Reference in New Issue
Block a user