summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-07-29 17:25:50 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-08-01 16:45:44 +0200
commit1e51fa5f4de9f15a99e3cb1fd1787f1861304e7e (patch)
tree2704821edf18abd2392e7e9ceeae4ad196487a20
parenttmtests/tm27: Fixes for RTEMS_DEBUG (diff)
downloadrtems-1e51fa5f4de9f15a99e3cb1fd1787f1861304e7e.tar.bz2
score: Add and use _Thread_Update_cpu_time_used()
Fix _times().
-rw-r--r--cpukit/libcsupport/src/__times.c20
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h19
-rw-r--r--cpukit/score/src/threaddispatch.c15
-rw-r--r--testsuites/psxtests/psxtimes01/init.c9
4 files changed, 43 insertions, 20 deletions
diff --git a/cpukit/libcsupport/src/__times.c b/cpukit/libcsupport/src/__times.c
index f143bb8209..4596453d56 100644
--- a/cpukit/libcsupport/src/__times.c
+++ b/cpukit/libcsupport/src/__times.c
@@ -29,6 +29,7 @@
#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
#include <rtems/score/timestamp.h>
#endif
+#include <rtems/score/threadimpl.h>
/**
* POSIX 1003.1b 4.5.2 - Get Process Times
@@ -38,6 +39,7 @@ clock_t _times(
)
{
rtems_interval ticks;
+ Thread_Control *executing;
if ( !ptms )
rtems_set_errno_and_return_minus_one( EFAULT );
@@ -59,7 +61,7 @@ clock_t _times(
#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
{
Timestamp_Control per_tick;
- uint32_t ticks;
+ uint32_t ticks_of_executing;
uint32_t fractional_ticks;
_Timestamp_Set(
@@ -70,16 +72,24 @@ clock_t _times(
TOD_NANOSECONDS_PER_SECOND)
);
+ _Thread_Disable_dispatch();
+ executing = _Thread_Executing;
+ _Thread_Update_cpu_time_used(
+ executing,
+ &_Thread_Time_of_last_context_switch
+ );
_Timestamp_Divide(
- &_Thread_Get_executing()->cpu_time_used,
+ &executing->cpu_time_used,
&per_tick,
- &ticks,
+ &ticks_of_executing,
&fractional_ticks
);
- ptms->tms_utime = ticks;
+ _Thread_Enable_dispatch();
+ ptms->tms_utime = ticks_of_executing / 100;
}
#else
- ptms->tms_utime = _Thread_Get_executing()->cpu_time_used;
+ executing = _Thread_Get_executing();
+ ptms->tms_utime = executing->cpu_time_used;
#endif
ptms->tms_stime = ticks;
ptms->tms_cutime = 0;
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index f5a0ff9faa..e818bc8c50 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -23,6 +23,7 @@
#include <rtems/score/isr.h>
#include <rtems/score/objectimpl.h>
#include <rtems/score/statesimpl.h>
+#include <rtems/score/tod.h>
#ifdef __cplusplus
extern "C" {
@@ -651,6 +652,24 @@ RTEMS_INLINE_ROUTINE void _Thread_Signal_notification( Thread_Control *thread )
}
}
+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 );
+}
+
#if !defined(__DYNAMIC_REENT__)
/**
* This routine returns the C library re-enterant pointer.
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c
index c5d0a2199b..09b5dbe105 100644
--- a/cpukit/score/src/threaddispatch.c
+++ b/cpukit/score/src/threaddispatch.c
@@ -105,17 +105,10 @@ void _Thread_Dispatch( void )
_ISR_Enable( level );
#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
- {
- Timestamp_Control uptime, ran;
- _TOD_Get_uptime( &uptime );
- _Timestamp_Subtract(
- &_Thread_Time_of_last_context_switch,
- &uptime,
- &ran
- );
- _Timestamp_Add_to( &executing->cpu_time_used, &ran );
- _Thread_Time_of_last_context_switch = uptime;
- }
+ _Thread_Update_cpu_time_used(
+ executing,
+ &_Thread_Time_of_last_context_switch
+ );
#else
{
_TOD_Get_uptime( &_Thread_Time_of_last_context_switch );
diff --git a/testsuites/psxtests/psxtimes01/init.c b/testsuites/psxtests/psxtimes01/init.c
index 640fe57979..d3089353fa 100644
--- a/testsuites/psxtests/psxtimes01/init.c
+++ b/testsuites/psxtests/psxtimes01/init.c
@@ -32,6 +32,7 @@ rtems_task Init(
clock_t difference;
struct tms start_tm;
struct tms end_tm;
+ int interval = 5;
puts( "\n\n*** TEST TIMES 01 ***" );
@@ -53,7 +54,7 @@ rtems_task Init(
rtems_test_assert( start != 0 );
rtems_test_assert( now != 0 );
- rtems_test_spin_for_ticks(5);
+ rtems_test_spin_for_ticks( interval );
puts( "_times( &end_tm ) -- OK" );
end = _times( &end_tm );
@@ -61,10 +62,10 @@ rtems_task Init(
puts( "Check various values" );
difference = end - start;
- rtems_test_assert( difference >= 5 );
+ rtems_test_assert( difference >= interval );
- rtems_test_assert( end_tm.tms_utime >= start_tm.tms_utime );
- rtems_test_assert( end_tm.tms_stime >= start_tm.tms_stime );
+ rtems_test_assert( end_tm.tms_utime - start_tm.tms_utime >= interval );
+ rtems_test_assert( end_tm.tms_stime - start_tm.tms_stime >= interval );
rtems_test_assert( end_tm.tms_cutime == 0 );
rtems_test_assert( end_tm.tms_cstime == 0 );