diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-03-03 07:02:03 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-03-17 08:27:47 +0100 |
commit | d37adfe5dd82cc3c933eb521b8f800c342af0e52 (patch) | |
tree | 5f4a77976b9ae35594d00b0bb58e18bb62a9b541 /cpukit/libcsupport/src/__times.c | |
parent | bsp/realview_pbx_a9_qemu: Fix compiler flags (diff) | |
download | rtems-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 '')
-rw-r--r-- | cpukit/libcsupport/src/__times.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/cpukit/libcsupport/src/__times.c b/cpukit/libcsupport/src/__times.c index ea6d1c65a7..a30f720f20 100644 --- a/cpukit/libcsupport/src/__times.c +++ b/cpukit/libcsupport/src/__times.c @@ -26,9 +26,11 @@ #include <rtems.h> #include <sys/times.h> -#include <time.h> #include <sys/time.h> -#include <errno.h> + +#include <string.h> +#include <time.h> + #include <rtems/seterr.h> #include <rtems/score/todimpl.h> #include <rtems/score/timestamp.h> @@ -42,11 +44,12 @@ clock_t _times( ) { rtems_interval ticks, us_per_tick; - Thread_Control *executing; if ( !ptms ) rtems_set_errno_and_return_minus_one( EFAULT ); + memset( ptms, 0, sizeof( *ptms ) ); + /* * This call does not depend on TOD being initialized and can't fail. */ @@ -62,11 +65,12 @@ clock_t _times( * this thread. */ { + Timestamp_Control cpu_time_used; Timestamp_Control per_tick; uint32_t ticks_of_executing; uint32_t fractional_ticks; - Per_CPU_Control *cpu_self; + _Thread_Get_CPU_time_used( _Thread_Get_executing(), &cpu_time_used ); _Timestamp_Set( &per_tick, rtems_configuration_get_microseconds_per_tick() / @@ -74,25 +78,17 @@ clock_t _times( (rtems_configuration_get_nanoseconds_per_tick() % TOD_NANOSECONDS_PER_SECOND) ); - - cpu_self = _Thread_Dispatch_disable(); - executing = _Thread_Executing; - _Thread_Update_cpu_time_used( - executing, - &_Thread_Time_of_last_context_switch - ); _Timestamp_Divide( - &executing->cpu_time_used, + &cpu_time_used, &per_tick, &ticks_of_executing, &fractional_ticks ); - _Thread_Dispatch_enable( cpu_self ); + ptms->tms_utime = ticks_of_executing * us_per_tick; } + ptms->tms_stime = ticks * us_per_tick; - ptms->tms_cutime = 0; - ptms->tms_cstime = 0; return ticks * us_per_tick; } |