summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/threadimpl.h
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/score/include/rtems/score/threadimpl.h
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/score/include/rtems/score/threadimpl.h')
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h67
1 files changed, 20 insertions, 47 deletions
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index ec9851dba0..3f8df856d5 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -578,36 +578,6 @@ RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_on_a_processor(
#endif
/**
- * @brief Returns @a true and sets time_of_context_switch to the
- * time of the last context switch when the thread is currently executing
- * in the system, otherwise @a false.
- */
-RTEMS_INLINE_ROUTINE bool _Thread_Get_time_of_last_context_switch(
- Thread_Control *the_thread,
- Timestamp_Control *time_of_context_switch
-)
-{
- bool retval = false;
-
- _Thread_Disable_dispatch();
- #ifndef RTEMS_SMP
- if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
- *time_of_context_switch = _Thread_Time_of_last_context_switch;
- retval = true;
- }
- #else
- if ( _Thread_Is_executing_on_a_processor( the_thread ) ) {
- *time_of_context_switch =
- _Thread_Get_CPU( the_thread )->time_of_last_context_switch;
- retval = true;
- }
- #endif
- _Thread_Enable_dispatch();
- return retval;
-}
-
-
-/**
* This function returns true if the_thread is the heir
* thread, and false otherwise.
*/
@@ -803,6 +773,20 @@ RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get_heir_and_make_it_executing(
return heir;
}
+RTEMS_INLINE_ROUTINE void _Thread_Update_CPU_time_used(
+ Thread_Control *the_thread,
+ Per_CPU_Control *cpu
+)
+{
+ Timestamp_Control last;
+ Timestamp_Control ran;
+
+ last = cpu->cpu_usage_timestamp;
+ _TOD_Get_uptime( &cpu->cpu_usage_timestamp );
+ _Timestamp_Subtract( &last, &cpu->cpu_usage_timestamp, &ran );
+ _Timestamp_Add_to( &the_thread->cpu_time_used, &ran );
+}
+
#if defined( RTEMS_SMP )
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_update_heir(
Per_CPU_Control *cpu_self,
@@ -810,6 +794,8 @@ RTEMS_INLINE_ROUTINE void _Thread_Dispatch_update_heir(
Thread_Control *heir
)
{
+ _Thread_Update_CPU_time_used( cpu_for_heir->heir, cpu_for_heir );
+
cpu_for_heir->heir = heir;
if ( cpu_for_heir == cpu_self ) {
@@ -820,23 +806,10 @@ RTEMS_INLINE_ROUTINE void _Thread_Dispatch_update_heir(
}
#endif
-RTEMS_INLINE_ROUTINE void _Thread_Update_cpu_time_used(
- Thread_Control *executing,
- Timestamp_Control *time_of_last_context_switch
-)
-{
- Timestamp_Control uptime;
- Timestamp_Control ran;
-
- _TOD_Get_uptime( &uptime );
- _Timestamp_Subtract(
- time_of_last_context_switch,
- &uptime,
- &ran
- );
- *time_of_last_context_switch = uptime;
- _Timestamp_Add_to( &executing->cpu_time_used, &ran );
-}
+void _Thread_Get_CPU_time_used(
+ Thread_Control *the_thread,
+ Timestamp_Control *cpu_time_used
+);
RTEMS_INLINE_ROUTINE void _Thread_Action_control_initialize(
Thread_Action_control *action_control