diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-05-17 22:46:45 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-05-17 22:46:45 +0000 |
commit | c3330a88ee5d674b09dded32ef1ccba26a9c3034 (patch) | |
tree | f7f247449fc18bc299ef695c3503f9b7790db97a /cpukit/score/src | |
parent | Add .rh clause to extra_arg. (diff) | |
download | rtems-c3330a88ee5d674b09dded32ef1ccba26a9c3034.tar.bz2 |
2007-05-17 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, configure.ac, libcsupport/src/__times.c,
libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c,
rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c,
rtems/src/ratemonresetall.c, rtems/src/ratemontimeout.c,
score/Makefile.am, score/include/rtems/score/thread.h,
score/include/rtems/score/timespec.h, score/src/threaddispatch.c,
score/src/threadinitialize.c, score/src/threadtickletimeslice.c,
score/src/timespecdivide.c: Add nanoseconds granularity to the rate
monotonic period statistics and CPU usage statistics. This capability
is enabled by default although may be conditionally disabled by the
user. It could be too much overhead on small targets but it does not
appear to be bad in early testing. Its impact on code size has not
been evaluated either. It is possible that both forms of statistics
gathering could be disabled with further tweaking of the conditional
compilation.
* score/src/timespecdividebyinteger.c: New file.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r-- | cpukit/score/src/threaddispatch.c | 19 | ||||
-rw-r--r-- | cpukit/score/src/threadinitialize.c | 27 | ||||
-rw-r--r-- | cpukit/score/src/threadtickletimeslice.c | 11 | ||||
-rw-r--r-- | cpukit/score/src/timespecdivide.c | 31 | ||||
-rw-r--r-- | cpukit/score/src/timespecdividebyinteger.c | 52 |
5 files changed, 111 insertions, 29 deletions
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c index 136433be17..4c903b6c2a 100644 --- a/cpukit/score/src/threaddispatch.c +++ b/cpukit/score/src/threaddispatch.c @@ -2,7 +2,7 @@ * Thread Handler * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -30,6 +30,11 @@ #include <rtems/score/userext.h> #include <rtems/score/wkspace.h> +#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + + #include <rtems/score/timespec.h> +#endif + /*PAGE * * _Thread_Dispatch @@ -78,7 +83,17 @@ void _Thread_Dispatch( void ) heir->cpu_time_budget = _Thread_Ticks_per_timeslice; _ISR_Enable( level ); - heir->ticks_executed++; + #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + { + struct timespec uptime, ran; + _TOD_Get_uptime( &uptime ); + _Timespec_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran); + _Timespec_Add_to( &executing->cpu_time_used, &ran ); + _Thread_Time_of_last_context_switch = uptime; + } + #else + heir->ticks_executed++; + #endif /* * Switch libc's task specific data. diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index e61cbac19a..f3e13a4944 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -187,17 +187,26 @@ boolean _Thread_Initialize( break; } - the_thread->Start.isr_level = isr_level; + the_thread->Start.isr_level = isr_level; + + the_thread->current_state = STATES_DORMANT; + the_thread->Wait.queue = NULL; + the_thread->resource_count = 0; + the_thread->suspend_count = 0; + the_thread->real_priority = priority; + the_thread->Start.initial_priority = priority; + _Thread_Set_priority( the_thread, priority ); - the_thread->current_state = STATES_DORMANT; - the_thread->Wait.queue = NULL; - the_thread->resource_count = 0; - the_thread->suspend_count = 0; - the_thread->real_priority = priority; - the_thread->Start.initial_priority = priority; - the_thread->ticks_executed = 0; + /* + * Initialize the CPU usage statistics + */ - _Thread_Set_priority( the_thread, priority ); + #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + the_thread->cpu_time_used.tv_sec = 0; + the_thread->cpu_time_used.tv_nsec = 0; + #else + the_thread->ticks_executed = 0; + #endif /* * Open the object diff --git a/cpukit/score/src/threadtickletimeslice.c b/cpukit/score/src/threadtickletimeslice.c index 0666066b28..41f08aa8d0 100644 --- a/cpukit/score/src/threadtickletimeslice.c +++ b/cpukit/score/src/threadtickletimeslice.c @@ -49,11 +49,12 @@ void _Thread_Tickle_timeslice( void ) executing = _Thread_Executing; - /* - * Increment the number of ticks this thread has been executing - */ - - executing->ticks_executed++; + #ifndef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + /* + * Increment the number of ticks this thread has been executing + */ + executing->ticks_executed++; + #endif /* * If the thread is not preemptible or is not ready, then diff --git a/cpukit/score/src/timespecdivide.c b/cpukit/score/src/timespecdivide.c index 0535c22e11..74d6cdbc78 100644 --- a/cpukit/score/src/timespecdivide.c +++ b/cpukit/score/src/timespecdivide.c @@ -23,30 +23,35 @@ #include <rtems/score/tod.h> void _Timespec_Divide( - const struct timespec *time, - uint32_t iterations, - struct timespec *result + const struct timespec *lhs, + const struct timespec *rhs, + uint32_t *ival_percentage, + uint32_t *fval_percentage ) { - uint64_t t; + uint64_t left, right, answer; /* * For math simplicity just convert the timespec to nanoseconds * in a 64-bit integer. */ - t = time->tv_sec * TOD_NANOSECONDS_PER_SECOND; - t += time->tv_nsec; + left = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND; + left += lhs->tv_nsec; + right = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND; + right += rhs->tv_nsec; - /* - * Divide to get nanoseconds per iteration - */ - - t /= iterations; + if ( rhs == 0 ) { + *ival_percentage = 0; + *ival_percentage = 0; + return; + } /* * Put it back in the timespec result */ - result->tv_sec = t / TOD_NANOSECONDS_PER_SECOND; - result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND; + answer = (left * 1000) / right; + + *fval_percentage = answer % 1000; + *ival_percentage = answer / 1000; } diff --git a/cpukit/score/src/timespecdividebyinteger.c b/cpukit/score/src/timespecdividebyinteger.c new file mode 100644 index 0000000000..eecd7c4e30 --- /dev/null +++ b/cpukit/score/src/timespecdividebyinteger.c @@ -0,0 +1,52 @@ +/** + * @file score/src/timespecdividebyinteger.c + */ + +/* + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <sys/types.h> +#include <rtems/score/timespec.h> +#include <rtems/score/tod.h> + +void _Timespec_Divide_by_integer( + const struct timespec *time, + uint32_t iterations, + struct timespec *result +) +{ + uint64_t t; + + /* + * For math simplicity just convert the timespec to nanoseconds + * in a 64-bit integer. + */ + t = time->tv_sec * TOD_NANOSECONDS_PER_SECOND; + t += time->tv_nsec; + + /* + * Divide to get nanoseconds per iteration + */ + + t /= iterations; + + /* + * Put it back in the timespec result + */ + + result->tv_sec = t / TOD_NANOSECONDS_PER_SECOND; + result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND; +} |