diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-09-01 18:24:47 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-09-01 18:24:47 +0000 |
commit | cae389ba36b9e4a27bad0e6a40b72abc92b3b693 (patch) | |
tree | 2a25083cdcd93c4523992003599ceff5971a1e33 /cpukit | |
parent | 2011-09-01 Petr Benes <benesp16@fel.cvut.cz> (diff) | |
download | rtems-cae389ba36b9e4a27bad0e6a40b72abc92b3b693.tar.bz2 |
2011-09-01 Joel Sherrill <joel.sherrilL@OARcorp.com>
PR 1895/cpukit
* score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c,
score/src/timespectoticks.c: Ensure time conversions to ticks do not
ignore partial tick and return 1 less than desired.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/ChangeLog | 7 | ||||
-rw-r--r-- | cpukit/score/src/coretodmsecstoticks.c | 17 | ||||
-rw-r--r-- | cpukit/score/src/coretodusectoticks.c | 17 | ||||
-rw-r--r-- | cpukit/score/src/timespectoticks.c | 18 |
4 files changed, 49 insertions, 10 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 2665f81dc4..c0a4058047 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,10 @@ +2011-09-01 Joel Sherrill <joel.sherrilL@OARcorp.com> + + PR 1895/cpukit + * score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c, + score/src/timespectoticks.c: Ensure time conversions to ticks do not + ignore partial tick and return 1 less than desired. + 2011-09-01 Petr Benes <benesp16@fel.cvut.cz> PR 1895/cpukit diff --git a/cpukit/score/src/coretodmsecstoticks.c b/cpukit/score/src/coretodmsecstoticks.c index cddd3d646d..0b6fa6dede 100644 --- a/cpukit/score/src/coretodmsecstoticks.c +++ b/cpukit/score/src/coretodmsecstoticks.c @@ -1,4 +1,4 @@ -/* COPYRIGHT (c) 1989-2008. +/* COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -21,5 +21,18 @@ uint32_t TOD_MILLISECONDS_TO_TICKS( uint32_t milliseconds ) { - return (milliseconds / rtems_configuration_get_milliseconds_per_tick()); + uint32_t ticks; + uint32_t milliseconds_per_tick; + + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + milliseconds_per_tick = rtems_configuration_get_milliseconds_per_tick(); + ticks = milliseconds / milliseconds_per_tick; + if ( (milliseconds % milliseconds_per_tick) != 0 ) + ticks += 1; + + return ticks; } diff --git a/cpukit/score/src/coretodusectoticks.c b/cpukit/score/src/coretodusectoticks.c index be2cbd7024..b62e15cd27 100644 --- a/cpukit/score/src/coretodusectoticks.c +++ b/cpukit/score/src/coretodusectoticks.c @@ -1,4 +1,4 @@ -/* COPYRIGHT (c) 1989-2008. +/* COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -21,5 +21,18 @@ uint32_t TOD_MICROSECONDS_TO_TICKS( uint32_t microseconds ) { - return (microseconds / rtems_configuration_get_microseconds_per_tick()); + uint32_t ticks; + uint32_t microseconds_per_tick; + + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + microseconds_per_tick = rtems_configuration_get_microseconds_per_tick(); + ticks = microseconds / microseconds_per_tick; + if ( (microseconds % microseconds_per_tick) != 0 ) + ticks += 1; + + return ticks; } diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c index ddd82e67a7..10d462976b 100644 --- a/cpukit/score/src/timespectoticks.c +++ b/cpukit/score/src/timespectoticks.c @@ -35,16 +35,22 @@ uint32_t _Timespec_To_ticks( ) { uint32_t ticks; + uint32_t nanoseconds_per_tick; if ( (time->tv_sec == 0) && (time->tv_nsec == 0) ) return 0; - ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + nanoseconds_per_tick = rtems_configuration_get_nanoseconds_per_tick(); + ticks += time->tv_nsec / nanoseconds_per_tick; - ticks += time->tv_nsec / rtems_configuration_get_nanoseconds_per_tick(); + if ( (time->tv_nsec % nanoseconds_per_tick) != 0 ) + ticks += 1; - if (ticks) - return ticks; - - return 1; + return ticks; } |