summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/ratemonperiod.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-03 07:02:03 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-17 08:27:47 +0100
commitd37adfe5dd82cc3c933eb521b8f800c342af0e52 (patch)
tree5f4a77976b9ae35594d00b0bb58e18bb62a9b541 /cpukit/rtems/src/ratemonperiod.c
parentbsp/realview_pbx_a9_qemu: Fix compiler flags (diff)
downloadrtems-d37adfe5dd82cc3c933eb521b8f800c342af0e52.tar.bz2
score: Fix CPU time used by executing threads
The CPU time used of a thread was previously maintained per-processor mostly during _Thread_Dispatch(). However, on SMP configurations the actual processor of a thread is difficult to figure out since thread dispatching is a highly asynchronous process (e.g. via inter-processor interrupts). Only the intended processor of a thread is known to the scheduler easily. Do the CPU usage accounting during thread heir updates in the context of the scheduler operations. Provide the function _Thread_Get_CPU_time_used() to get the CPU usage of a thread using proper locks to get a consistent value. Close #2627.
Diffstat (limited to 'cpukit/rtems/src/ratemonperiod.c')
-rw-r--r--cpukit/rtems/src/ratemonperiod.c75
1 files changed, 20 insertions, 55 deletions
diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c
index 58be148f19..2a4b4ebde2 100644
--- a/cpukit/rtems/src/ratemonperiod.c
+++ b/cpukit/rtems/src/ratemonperiod.c
@@ -45,74 +45,39 @@ bool _Rate_monotonic_Get_status(
/*
* Determine cpu usage since period initiated.
*/
- used = owning_thread->cpu_time_used;
+ _Thread_Get_CPU_time_used( owning_thread, &used );
- if (owning_thread == _Thread_Executing) {
-
- Timestamp_Control ran;
-
- /* How much time time since last context switch */
- _Timestamp_Subtract(
- &_Thread_Time_of_last_context_switch, &uptime, &ran
- );
-
- /* cpu usage += ran */
- _Timestamp_Add_to( &used, &ran );
-
- /*
- * The cpu usage info was reset while executing. Can't
- * determine a status.
- */
- if (_Timestamp_Less_than(&used, &the_period->cpu_usage_period_initiated))
- return false;
+ /*
+ * The cpu usage info was reset while executing. Can't
+ * determine a status.
+ */
+ if ( _Timestamp_Less_than( &used, &the_period->cpu_usage_period_initiated ) )
+ return false;
- /* used = current cpu usage - cpu usage at start of period */
- _Timestamp_Subtract(
- &the_period->cpu_usage_period_initiated,
- &used,
- cpu_since_last_period
- );
- }
+ /* used = current cpu usage - cpu usage at start of period */
+ _Timestamp_Subtract(
+ &the_period->cpu_usage_period_initiated,
+ &used,
+ cpu_since_last_period
+ );
return true;
}
void _Rate_monotonic_Restart( Rate_monotonic_Control *the_period )
{
- Thread_Control *owning_thread = the_period->owner;
- Timestamp_Control uptime;
- ISR_Level level;
-
- _TOD_Get_uptime( &uptime );
+ ISR_Level level;
/*
* Set the starting point and the CPU time used for the statistics.
*/
- the_period->time_period_initiated = uptime;
- the_period->cpu_usage_period_initiated = owning_thread->cpu_time_used;
-
- /*
- * We need to take into account how much time the
- * executing thread has run since the last context switch. When this
- * routine is invoked from rtems_rate_monotonic_period, the owner will
- * be the executing thread. When this routine is invoked from
- * _Rate_monotonic_Timeout, it will not.
- */
- if (owning_thread == _Thread_Executing) {
- Timestamp_Control ran;
-
- /*
- * Adjust the CPU time used to account for the time since last
- * context switch.
- */
- _Timestamp_Subtract(
- &_Thread_Time_of_last_context_switch, &uptime, &ran
- );
-
- _Timestamp_Add_to( &the_period->cpu_usage_period_initiated, &ran );
- }
+ _TOD_Get_uptime( &the_period->time_period_initiated );
+ _Thread_Get_CPU_time_used(
+ the_period->owner,
+ &the_period->cpu_usage_period_initiated
+ );
- _Scheduler_Release_job( owning_thread, the_period->next_length );
+ _Scheduler_Release_job( the_period->owner, the_period->next_length );
_ISR_Disable( level );
_Watchdog_Per_CPU_insert_relative(