summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/ratemonperiod.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-05-21 19:28:55 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-05-21 19:28:55 +0000
commitec2078d670f0fc9fbfe4a968b05454d88ddd526f (patch)
tree79525730500e4197ba4cded7b776baca5001f9c4 /cpukit/rtems/src/ratemonperiod.c
parent2007-05-21 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-ec2078d670f0fc9fbfe4a968b05454d88ddd526f.tar.bz2
2007-05-21 Joel Sherrill <joel.sherrill@oarcorp.com>
* rtems/src/ratemonperiod.c: Fix math ordering bug which resulted in a negative value in some circumstances. Also cleaned up to share uptime declaration.
Diffstat (limited to 'cpukit/rtems/src/ratemonperiod.c')
-rw-r--r--cpukit/rtems/src/ratemonperiod.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c
index 872930e035..50a0a2d912 100644
--- a/cpukit/rtems/src/ratemonperiod.c
+++ b/cpukit/rtems/src/ratemonperiod.c
@@ -76,20 +76,23 @@ void _Rate_monotonic_Update_statistics(
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{
- struct timespec ran;
+ struct timespec ran, used;
- /* executed = current cpu usage - value at start of period */
- _Timespec_Subtract(
- &the_period->owner_executed_at_period,
- &_Thread_Executing->cpu_time_used,
- &executed
- );
+ /* Grab CPU usage when the thread got switched in */
+ used = _Thread_Executing->cpu_time_used;
/* How much time time since last context switch */
_Timespec_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran);
/* executed += ran */
- _Timespec_Add_to( &executed, &ran );
+ _Timespec_Add_to( &used, &ran );
+
+ /* executed = current cpu usage - value at start of period */
+ _Timespec_Subtract(
+ &the_period->owner_executed_at_period,
+ &used,
+ &executed
+ );
}
#else
ticks_executed_since_last_period = the_period->owner->ticks_executed -
@@ -103,6 +106,7 @@ void _Rate_monotonic_Update_statistics(
stats = &the_period->Statistics;
stats->count++;
+
if ( the_period->state == RATE_MONOTONIC_EXPIRED )
stats->missed_count++;
@@ -214,29 +218,38 @@ rtems_status_code rtems_rate_monotonic_period(
_ISR_Disable( level );
switch ( the_period->state ) {
- case RATE_MONOTONIC_INACTIVE:
+ case RATE_MONOTONIC_INACTIVE: {
+ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
+ defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
+ struct timespec uptime;
+ #endif
+
/*
* No need to update statistics -- there are not a period active
*/
_ISR_Enable( level );
+
+ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
+ defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
+ _TOD_Get_uptime( &uptime );
+ #endif
+
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
/*
* Since the statistics didn't update the starting time,
* we do it here.
*/
- _TOD_Get_uptime( &the_period->time_at_period );
+ the_period->time_at_period = uptime;
#else
the_period->time_at_period = _Watchdog_Ticks_since_boot;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{
- struct timespec ran, uptime;
+ struct timespec ran;
- _TOD_Get_uptime( &uptime );
-
the_period->owner_executed_at_period =
_Thread_Executing->cpu_time_used;
@@ -268,7 +281,7 @@ rtems_status_code rtems_rate_monotonic_period(
_Watchdog_Insert_ticks( &the_period->Timer, length );
_Thread_Enable_dispatch();
return RTEMS_SUCCESSFUL;
-
+ }
case RATE_MONOTONIC_ACTIVE:
/*