diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-08-07 18:00:38 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-08-07 18:00:38 -0600 |
commit | f4f8030be0af79250de05d323106dd34a5e7dc85 (patch) | |
tree | ac6ac62508e391422efee525bc3c438206e31259 /nuttx/sched | |
parent | f39ae5a8b656f320d99f391972e8b81a8c2d52fd (diff) | |
download | px4-nuttx-f4f8030be0af79250de05d323106dd34a5e7dc85.tar.gz px4-nuttx-f4f8030be0af79250de05d323106dd34a5e7dc85.tar.bz2 px4-nuttx-f4f8030be0af79250de05d323106dd34a5e7dc85.zip |
Change all time conversions. Yech. New timer units in microseconds breaks all existing logic that used milliseconds in the conversions. Something likely got broken doing this, probably because I confused a MSEC2TICK conversion with a TICK2MSEC conversion. Also, the tickless OS no appears fully functional and passes the OS test on the simulator with no errors
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/Kconfig | 3 | ||||
-rw-r--r-- | nuttx/sched/clock_getres.c | 13 | ||||
-rw-r--r-- | nuttx/sched/clock_gettime.c | 4 | ||||
-rw-r--r-- | nuttx/sched/clock_initialize.c | 4 | ||||
-rw-r--r-- | nuttx/sched/clock_systimer.c | 6 | ||||
-rw-r--r-- | nuttx/sched/pthread_create.c | 2 | ||||
-rw-r--r-- | nuttx/sched/sched_processtimer.c | 4 | ||||
-rw-r--r-- | nuttx/sched/sched_setscheduler.c | 2 | ||||
-rw-r--r-- | nuttx/sched/sched_timerexpiration.c | 18 | ||||
-rw-r--r-- | nuttx/sched/sched_unlock.c | 16 | ||||
-rw-r--r-- | nuttx/sched/sig_timedwait.c | 2 |
11 files changed, 38 insertions, 36 deletions
diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index 7568e6f25..4f7a88bd3 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -93,6 +93,9 @@ config USEC_PER_TICK The default, 100 microseconds, will provide for a range of delays up to 120 hours. + This value should never be less than the underlying resolution of + the timer. Error may ensue. + if !SCHED_TICKLESS config SYSTEMTICK_EXTCLK diff --git a/nuttx/sched/clock_getres.c b/nuttx/sched/clock_getres.c index a76b14ab6..edbc87bf0 100644 --- a/nuttx/sched/clock_getres.c +++ b/nuttx/sched/clock_getres.c @@ -88,7 +88,6 @@ int clock_getres(clockid_t clock_id, struct timespec *res) { - uint32_t time_res; int ret = OK; sdbg("clock_id=%d\n", clock_id); @@ -103,18 +102,12 @@ int clock_getres(clockid_t clock_id, struct timespec *res) } else { - /* Get the clock resolution in nanoseconds */ - - time_res = MSEC_PER_TICK * NSEC_PER_MSEC; - - /* And return this as a timespec. */ + /* Form the timspec using clock resolution in nanoseconds */ res->tv_sec = 0; - res->tv_nsec = time_res; + res->tv_nsec = NSEC_PER_TICK; - sdbg("Returning res=(%d,%d) time_res=%d\n", - (int)res->tv_sec, (int)res->tv_nsec, - (int)time_res); + sdbg("Returning res=(%d,%d)\n", (int)res->tv_sec, (int)res->tv_nsec); } return ret; diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c index 7f6cdba62..5244bc531 100644 --- a/nuttx/sched/clock_gettime.c +++ b/nuttx/sched/clock_gettime.c @@ -124,7 +124,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) { /* Get the time since power-on in seconds and milliseconds */ - msecs = MSEC_PER_TICK * clock_systimer(); + msecs = TICK2MSEC(clock_systimer()); secs = msecs / MSEC_PER_SEC; /* Return the elapsed time in seconds and nanoseconds */ @@ -174,7 +174,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * when the time-of-day was last set. */ - msecs = MSEC_PER_TICK * (clock_systimer() - g_tickbias); + msecs = TICK2MSEC((clock_systimer() - g_tickbias)); sdbg("msecs = %d g_tickbias=%d\n", (int)msecs, (int)g_tickbias); diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c index 0b21fd56a..374e675ac 100644 --- a/nuttx/sched/clock_initialize.c +++ b/nuttx/sched/clock_initialize.c @@ -266,7 +266,7 @@ void clock_synchronize(void) * Description: * This function must be called once every time the real time clock * interrupt occurs. The interval of this clock interrupt must be - * MSEC_PER_TICK + * USEC_PER_TICK * ****************************************************************************/ @@ -277,4 +277,4 @@ void clock_timer(void) g_system_timer++; } -#endif
\ No newline at end of file +#endif diff --git a/nuttx/sched/clock_systimer.c b/nuttx/sched/clock_systimer.c index 126c12ce6..65487da6e 100644 --- a/nuttx/sched/clock_systimer.c +++ b/nuttx/sched/clock_systimer.c @@ -87,8 +87,7 @@ uint32_t clock_systimer(void) /* Convert to a 64- then 32-bit value */ - tmp = (1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000) / - MSEC_PER_TICK; + tmp = MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); return (uint32_t)(tmp & 0x00000000ffffffff); #else @@ -136,8 +135,7 @@ uint64_t clock_systimer64(void) /* Convert to a 64- then 32-bit value */ - return (1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000) / - MSEC_PER_TICK; + return MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); #else /* Return the current system time */ diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 8c9292cfc..78142a6ed 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -381,7 +381,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, if (policy == SCHED_RR) { ptcb->cmn.flags |= TCB_FLAG_ROUND_ROBIN; - ptcb->cmn.timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + ptcb->cmn.timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } #endif diff --git a/nuttx/sched/sched_processtimer.c b/nuttx/sched/sched_processtimer.c index e16d17e71..a8a3b917f 100644 --- a/nuttx/sched/sched_processtimer.c +++ b/nuttx/sched/sched_processtimer.c @@ -115,7 +115,7 @@ static inline void sched_process_timeslice(void) { /* Reset the timeslice in any case. */ - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); /* We know we are at the head of the ready to run * prioritized list. We must be the highest priority @@ -170,7 +170,7 @@ static inline void sched_process_timeslice(void) * The timer interrupt logic itself is implemented in the * architecture specific code, but must call the following OS * function periodically -- the calling interval must be - * MSEC_PER_TICK + * USEC_PER_TICK * * Inputs: * None diff --git a/nuttx/sched/sched_setscheduler.c b/nuttx/sched/sched_setscheduler.c index 682f50530..cabf81bec 100644 --- a/nuttx/sched/sched_setscheduler.c +++ b/nuttx/sched/sched_setscheduler.c @@ -157,7 +157,7 @@ int sched_setscheduler(pid_t pid, int policy, /* Set round robin scheduling */ tcb->flags |= TCB_FLAG_ROUND_ROBIN; - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } else { diff --git a/nuttx/sched/sched_timerexpiration.c b/nuttx/sched/sched_timerexpiration.c index 7f2a5b863..03cdfceef 100644 --- a/nuttx/sched/sched_timerexpiration.c +++ b/nuttx/sched/sched_timerexpiration.c @@ -171,7 +171,7 @@ sched_process_timeslice(unsigned int ticks, bool noswitches) { /* Reset the timeslice. */ - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); ret = rtcb->timeslice; /* We know we are at the head of the ready to run @@ -287,7 +287,7 @@ static void sched_timer_process(unsigned int ticks, bool noswitches) * understand. */ - msecs = MSEC_PER_TICK * nextime; + msecs = TICK2MSEC(nextime); secs = msecs / MSEC_PER_SEC; nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC; @@ -327,7 +327,11 @@ static void sched_timer_process(unsigned int ticks, bool noswitches) void sched_timer_expiration(void) { - sched_timer_process(g_timer_interval, false); + unsigned int elapsed; + + elapsed = g_timer_interval; + g_timer_interval = 0; + sched_timer_process(elapsed, false); } /**************************************************************************** @@ -358,6 +362,7 @@ void sched_timer_reassess(void) { struct timespec ts; unsigned int ticks; + unsigned int elapsed; /* Get the time remaining on the interval timer and cancel the timer. */ @@ -367,13 +372,16 @@ void sched_timer_reassess(void) ticks = SEC2TICK(ts.tv_sec); ticks += NSEC2TICK(ts.tv_nsec); + DEBUGASSERT(ticks <= g_timer_interval); /* Handle the partial timer. This will reassess all timer conditions and * re-start the interval timer with the correct delay. Context switches * are not permitted in this case because we are not certain of the * calling conditions. */ - - sched_timer_process(g_timer_interval - ticks, true); + + elapsed = g_timer_interval - ticks; + g_timer_interval = 0; + sched_timer_process(elapsed, true); } #endif /* CONFIG_SCHED_TICKLESS */ diff --git a/nuttx/sched/sched_unlock.c b/nuttx/sched/sched_unlock.c index 91aa555ef..df3b966e7 100644 --- a/nuttx/sched/sched_unlock.c +++ b/nuttx/sched/sched_unlock.c @@ -45,7 +45,7 @@ #include "os_internal.h" /************************************************************************ - * Definitions + * Pre-processor Definitions ************************************************************************/ /************************************************************************ @@ -65,7 +65,7 @@ ************************************************************************/ /************************************************************************ - * Private Functionss + * Private Functions ************************************************************************/ /************************************************************************ @@ -125,11 +125,11 @@ int sched_unlock(void) } #if CONFIG_RR_INTERVAL > 0 - /* If (1) the task that was running running supported round-robin - * scheduling and (2) if its time slice has already expired, but (3) - * it could not slice out because pre-emption was disabled, then - * we need to swap the task out now and reassess the interval timer - * for the next time slice. + /* If (1) the task that was running supported round-robin + * scheduling and (2) if its time slice has already expired, but + * (3) it could not slice out because pre-emption was disabled, + * then we need to swap the task out now and reassess the interval + * timer for the next time slice. */ if ((rtcb->flags & TCB_FLAG_ROUND_ROBIN) != 0 && @@ -144,7 +144,7 @@ int sched_unlock(void) if (rtcb != (FAR struct tcb_s*)g_readytorun.head) { - rtcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; + rtcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } #ifdef CONFIG_SCHED_TICKLESS else diff --git a/nuttx/sched/sig_timedwait.c b/nuttx/sched/sig_timedwait.c index 3952e42c2..85b870642 100644 --- a/nuttx/sched/sig_timedwait.c +++ b/nuttx/sched/sig_timedwait.c @@ -254,7 +254,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, DEBUGASSERT(timeout->tv_sec < UINT32_MAX / MSEC_PER_SEC); waitmsec = timeout->tv_sec * MSEC_PER_SEC + (timeout->tv_nsec + NSEC_PER_MSEC - 1) / NSEC_PER_MSEC; - waitticks = (waitmsec + MSEC_PER_TICK - 1) / MSEC_PER_TICK; + waitticks = MSEC2TICK(waitmsec); #endif /* Create a watchdog */ |