dlwnsdus2@yahoo.com [nuttx]
2018-03-08 06:28:08 UTC
Hi, Everyone.
Those are issues we found during the usleep() test and needs to be reviewed.
When performing very small usleep(== 1 system tick), we thought that tickwait count is not correct.
So, please review below two patches.
1.
--------------------------------------------------------------------------------------
wdog: wd_start() - do not increment delay
There is no reason to increment delay and it causes problem of
sleeping for 1 tick longer.
Signed-off-by: Dmitrii Rodionov <***@samsung.com>
--- a/sched/wdog/wd_start.c
+++ b/sched/wdog/wd_start.c
@@ -267,16 +267,12 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...)
#endif
va_end(ap);
- /* Calculate delay+1, forcing the delay into a range that we can handle */
+ /* Handle negative delays */
if (delay <= 0)
{
delay = 1;
}
- else if (++delay <= 0)
- {
- delay--;
- }
#ifdef CONFIG_SCHED_TICKLESS
--------------------------------------------------------------------------------------
2.
--------------------------------------------------------------------------------------
Author: Junyeon LEE <***@samsung.com>
Date: Thu Mar 8 14:07:17 2018 +0000
kernel/signal: modify waitticks64 calculation.
The previous waittick64 calculation method calculates the value
one more than the expected value more frequently if the Timeout
and NSEC_PER_TICK value is very small.
So, we modify this calculation method similar to the waitmsec
calculation method.
Our problem case:
- NSEC_PER_TICK = 9,979,000
- timeout->tv_nsec = 10,000,000 (10ms)
- timeout->tv_sec = 0
In the above situation we expected 1 tick wait, but waittick value
is 2 and waits 20 ms.
Change-Id: I95ba6e6fe80cbaa9e1600a8762071c236dd50aad
Signed-off-by: Junyeon LEE <***@samsung.com>
--- a/sched/signal/sig_timedwait.c
+++ b/sched/signal/sig_timedwait.c
@@ -325,11 +325,11 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
*/
#ifdef CONFIG_HAVE_LONG_LONG
- uint64_t waitticks64 = ((uint64_t)timeout->tv_sec * NSEC_PER_SEC +
- (uint64_t)timeout->tv_nsec + NSEC_PER_TICK - 1) /
- NSEC_PER_TICK;
- DEBUGASSERT(waitticks64 <= UINT32_MAX);
- waitticks = (uint32_t)waitticks64;
+ uint64_t waitusec;
+
+ DEBUGASSERT(timeout->tv_sec < UINT64_MAX / USEC_PER_SEC);
+ waitusec = (uint64_t)timeout->tv_sec * USEC_PER_SEC + (timeout->tv_nsec + NSEC_PER_USEC - 1) / NSEC_PER_U
+ waitticks = (int32_t)USEC2TICK(waitusec);
#else
--------------------------------------------------------------------------------------
Thanks.
Those are issues we found during the usleep() test and needs to be reviewed.
When performing very small usleep(== 1 system tick), we thought that tickwait count is not correct.
So, please review below two patches.
1.
--------------------------------------------------------------------------------------
wdog: wd_start() - do not increment delay
There is no reason to increment delay and it causes problem of
sleeping for 1 tick longer.
Signed-off-by: Dmitrii Rodionov <***@samsung.com>
--- a/sched/wdog/wd_start.c
+++ b/sched/wdog/wd_start.c
@@ -267,16 +267,12 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...)
#endif
va_end(ap);
- /* Calculate delay+1, forcing the delay into a range that we can handle */
+ /* Handle negative delays */
if (delay <= 0)
{
delay = 1;
}
- else if (++delay <= 0)
- {
- delay--;
- }
#ifdef CONFIG_SCHED_TICKLESS
--------------------------------------------------------------------------------------
2.
--------------------------------------------------------------------------------------
Author: Junyeon LEE <***@samsung.com>
Date: Thu Mar 8 14:07:17 2018 +0000
kernel/signal: modify waitticks64 calculation.
The previous waittick64 calculation method calculates the value
one more than the expected value more frequently if the Timeout
and NSEC_PER_TICK value is very small.
So, we modify this calculation method similar to the waitmsec
calculation method.
Our problem case:
- NSEC_PER_TICK = 9,979,000
- timeout->tv_nsec = 10,000,000 (10ms)
- timeout->tv_sec = 0
In the above situation we expected 1 tick wait, but waittick value
is 2 and waits 20 ms.
Change-Id: I95ba6e6fe80cbaa9e1600a8762071c236dd50aad
Signed-off-by: Junyeon LEE <***@samsung.com>
--- a/sched/signal/sig_timedwait.c
+++ b/sched/signal/sig_timedwait.c
@@ -325,11 +325,11 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
*/
#ifdef CONFIG_HAVE_LONG_LONG
- uint64_t waitticks64 = ((uint64_t)timeout->tv_sec * NSEC_PER_SEC +
- (uint64_t)timeout->tv_nsec + NSEC_PER_TICK - 1) /
- NSEC_PER_TICK;
- DEBUGASSERT(waitticks64 <= UINT32_MAX);
- waitticks = (uint32_t)waitticks64;
+ uint64_t waitusec;
+
+ DEBUGASSERT(timeout->tv_sec < UINT64_MAX / USEC_PER_SEC);
+ waitusec = (uint64_t)timeout->tv_sec * USEC_PER_SEC + (timeout->tv_nsec + NSEC_PER_USEC - 1) / NSEC_PER_U
+ waitticks = (int32_t)USEC2TICK(waitusec);
#else
--------------------------------------------------------------------------------------
Thanks.