diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-07-18 21:31:49 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-07-18 21:31:49 +0000 |
commit | 793dd46d64ec6e0fac46395cdf53cf053366b93e (patch) | |
tree | 33ad52b4cd81cacb37143ba8550a58296b078724 /cpukit | |
parent | 2007-07-18 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-793dd46d64ec6e0fac46395cdf53cf053366b93e.tar.bz2 |
2007-07-18 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/Makefile.am, libmisc/cpuuse/cpuusagereport.c,
libmisc/cpuuse/cpuusagereset.c: Fix bug where cpu usage calculation
was always using uptime not time since last cpu usage reset when
using nanoseconds granularity.
* libmisc/cpuuse/cpuusagedata.c: New file.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/ChangeLog | 8 | ||||
-rw-r--r-- | cpukit/libmisc/Makefile.am | 2 | ||||
-rw-r--r-- | cpukit/libmisc/cpuuse/cpuusagedata.c | 33 | ||||
-rw-r--r-- | cpukit/libmisc/cpuuse/cpuusagereport.c | 17 | ||||
-rw-r--r-- | cpukit/libmisc/cpuuse/cpuusagereset.c | 7 |
5 files changed, 58 insertions, 9 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 7164bfd3dd..2edb068fdc 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,11 @@ +2007-07-18 Joel Sherrill <joel.sherrill@oarcorp.com> + + * libmisc/Makefile.am, libmisc/cpuuse/cpuusagereport.c, + libmisc/cpuuse/cpuusagereset.c: Fix bug where cpu usage calculation + was always using uptime not time since last cpu usage reset when + using nanoseconds granularity. + * libmisc/cpuuse/cpuusagedata.c: New file. + 2007-07-13 Joel Sherrill <joel.sherrill@oarcorp.com> * libcsupport/src/mount.c: Allow null for output parameter. diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 32a2f6abce..0402cd5f87 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -20,7 +20,7 @@ EXTRA_DIST += cpuuse/README noinst_LIBRARIES += libcpuuse.a libcpuuse_a_SOURCES = cpuuse/cpuusagereport.c cpuuse/cpuusagereset.c \ - cpuuse/cpuuse.h + cpuuse/cpuuse.h cpuuse/cpuusagedata.c ## devnull diff --git a/cpukit/libmisc/cpuuse/cpuusagedata.c b/cpukit/libmisc/cpuuse/cpuusagedata.c new file mode 100644 index 0000000000..277d7f9c5e --- /dev/null +++ b/cpukit/libmisc/cpuuse/cpuusagedata.c @@ -0,0 +1,33 @@ +/* + * CPU Usage Reporter - Shared Data + * + * 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$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems.h> + +#include <rtems/cpuuse.h> + +#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ + defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) + #include <rtems/score/timespec.h> + +#endif + +#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + struct timespec CPU_usage_Uptime_at_last_reset; +#else + uint32_t CPU_usage_Ticks_at_last_reset; +#endif + diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 89f264db40..75258165e6 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -35,8 +35,10 @@ #define PERCENT_FMT "%04" PRId32 #endif -#ifndef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS - uint32_t CPU_usage_Ticks_at_last_reset; +#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + extern struct timespec CPU_usage_Uptime_at_last_reset; +#else + extern uint32_t CPU_usage_Ticks_at_last_reset; #endif /*PAGE @@ -53,7 +55,7 @@ void rtems_cpu_usage_report( void ) char name[5]; uint32_t ival, fval; #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS - struct timespec uptime; + struct timespec uptime, total; #else uint32_t total_units = 0; #endif @@ -65,6 +67,7 @@ void rtems_cpu_usage_report( void ) */ #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS _TOD_Get_uptime( &uptime ); + _Timespec_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); #else for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { if ( !_Objects_Information_table[ api_index ] ) @@ -107,7 +110,7 @@ void rtems_cpu_usage_report( void ) printk( "0x%08" PRIx32 " %4s ", the_thread->Object.id, name ); #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS - _Timespec_Divide( &the_thread->cpu_time_used, &uptime, &ival, &fval ); + _Timespec_Divide( &the_thread->cpu_time_used, &total, &ival, &fval ); printk( "%" PRId32 ".%06d" /* cpu time used */ @@ -135,9 +138,9 @@ void rtems_cpu_usage_report( void ) } #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS - printk( "Uptime %d.%06d seconds\n\n", - uptime.tv_sec, - uptime.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND + printk( "Time since last reset %d.%06d seconds\n", + total.tv_sec, + total.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND ); #else printk( diff --git a/cpukit/libmisc/cpuuse/cpuusagereset.c b/cpukit/libmisc/cpuuse/cpuusagereset.c index 6622b93c90..3f351b1c51 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereset.c +++ b/cpukit/libmisc/cpuuse/cpuusagereset.c @@ -40,10 +40,15 @@ static void CPU_usage_Per_thread_handler( */ void rtems_cpu_usage_reset( void ) { - #ifndef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS + extern struct timespec CPU_usage_Uptime_at_last_reset; + + _TOD_Get_uptime( &CPU_usage_Uptime_at_last_reset ); + #else extern uint32_t CPU_usage_Ticks_at_last_reset; CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot; + #endif rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler); |