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:
Jussi Kivilinna 2017-04-21 08:51:31 -06:00 committed by Gregory Nutt
parent 325ba1a803
commit c57d49f420
16 changed files with 48 additions and 28 deletions

View File

@ -199,6 +199,14 @@ typedef uint64_t systime_t;
typedef uint32_t systime_t;
#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
****************************************************************************/

View File

@ -98,9 +98,10 @@ void weak_function clock_timer(void);
int clock_abstime2ticks(clockid_t clockid,
FAR const struct timespec *abstime,
FAR int *ticks);
int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks);
int clock_ticks2time(int ticks, FAR struct timespec *reltime);
FAR ssystime_t *ticks);
int clock_time2ticks(FAR const 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,
FAR const struct timespec *ts2,
FAR struct timespec *ts3);

View File

@ -99,7 +99,7 @@ static long compare_timespec(FAR const struct timespec *a,
****************************************************************************/
int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime,
FAR int *ticks)
FAR ssystime_t *ticks)
{
struct timespec currtime;
struct timespec reltime;

View File

@ -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;
remainder = ticks - TICK_PER_SEC * reltime->tv_sec;

View File

@ -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
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.
*/
*ticks = (int)((relnsec + NSEC_PER_TICK - 1) / NSEC_PER_TICK);
*ticks = (ssystime_t)((relnsec + NSEC_PER_TICK - 1) / NSEC_PER_TICK);
return OK;
#else
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.
*/
*ticks = (int)((relusec + USEC_PER_TICK - 1) / USEC_PER_TICK);
*ticks = (ssystime_t)((relusec + USEC_PER_TICK - 1) / USEC_PER_TICK);
return OK;
#endif
}

View File

@ -230,7 +230,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
if (mqdes->msgq->msglist.head == NULL)
{
int ticks;
ssystime_t ticks;
/* Convert the timespec to clock ticks. We must have interrupts
* disabled here so that this time stays valid until the wait begins.

View File

@ -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_msg_s *mqmsg = NULL;
irqstate_t flags;
int ticks;
ssystime_t ticks;
int result;
int ret = ERROR;

View File

@ -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();
irqstate_t flags;
uint16_t oldstate;
int ticks;
ssystime_t ticks;
int mypid = (int)getpid();
int ret = OK;
int status;

View File

@ -358,8 +358,8 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
if (policy == SCHED_SPORADIC)
{
FAR struct sporadic_s *sporadic;
int repl_ticks;
int budget_ticks;
ssystime_t repl_ticks;
ssystime_t budget_ticks;
/* Convert timespec values to system clock ticks */

View File

@ -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_max_repl = (int)sporadic->max_repl;
clock_ticks2time((int)sporadic->repl_period, &param->sched_ss_repl_period);
clock_ticks2time((int)sporadic->budget, &param->sched_ss_init_budget);
clock_ticks2time((ssystime_t)sporadic->repl_period,
&param->sched_ss_repl_period);
clock_ticks2time((ssystime_t)sporadic->budget,
&param->sched_ss_init_budget);
}
else
{

View File

@ -134,8 +134,8 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
{
FAR struct sporadic_s *sporadic;
irqstate_t flags;
int repl_ticks;
int budget_ticks;
ssystime_t repl_ticks;
ssystime_t budget_ticks;
if (param->sched_ss_max_repl < 1 ||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)

View File

@ -180,8 +180,8 @@ int sched_setscheduler(pid_t pid, int policy,
case SCHED_SPORADIC:
{
FAR struct sporadic_s *sporadic;
int repl_ticks;
int budget_ticks;
ssystime_t repl_ticks;
ssystime_t budget_ticks;
if (param->sched_ss_max_repl < 1 ||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)

View File

@ -98,7 +98,7 @@ int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime)
{
FAR struct tcb_s *rtcb = this_task();
irqstate_t flags;
int ticks;
ssystime_t ticks;
int errcode;
int ret = ERROR;

View File

@ -170,7 +170,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
{
systime_t elapsed;
systime_t remaining;
int ticks;
ssystime_t ticks;
/* REVISIT: The conversion from time to ticks and back could
* 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.
*/
if (elapsed >= (uint32_t)ticks)
if (elapsed >= (systime_t)ticks)
{
remaining = 0;
}
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);

View File

@ -86,7 +86,7 @@
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
{
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
int ticks;
ssystime_t ticks;
if (!timer || !value)
{

View File

@ -304,7 +304,7 @@ int timer_settime(timer_t timerid, int flags,
{
FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid;
irqstate_t intflags;
int delay;
ssystime_t delay;
int ret = OK;
/* 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)
{
(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
{
@ -379,6 +383,10 @@ int timer_settime(timer_t timerid, int flags,
if (delay > 0)
{
/* REVISIT: Should pt_last be ssystime_t? Should wd_start delay be
* ssystime_t?
*/
timer->pt_last = delay;
ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout,
1, (uint32_t)((wdparm_t)timer));