summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/cpuuse
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-07-24 21:37:39 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-07-24 21:37:39 +0000
commit3462c3432604442c5535488dad080153322f7a18 (patch)
tree8c0e3c3f4aa7ebfcdf3677daa90e103ad41dbdb2 /cpukit/libmisc/cpuuse
parent2007-07-24 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-3462c3432604442c5535488dad080153322f7a18.tar.bz2
2007-07-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c, score/src/timespecdivide.c: Fix various math and reporting bugs. Now the time appears to be reported correctly and add up to what is expected.
Diffstat (limited to 'cpukit/libmisc/cpuuse')
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereport.c42
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereset.c1
2 files changed, 26 insertions, 17 deletions
diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index 75258165e6..9c9bd4aef2 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#include <ctype.h>
#include <inttypes.h>
@@ -29,10 +30,6 @@
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
#include <rtems/score/timespec.h>
-
- /* We print to 1/10's of milliseconds */
- #define NANOSECONDS_DIVIDER 100000
- #define PERCENT_FMT "%04" PRId32
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
@@ -55,7 +52,7 @@ void rtems_cpu_usage_report( void )
char name[5];
uint32_t ival, fval;
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
- struct timespec uptime, total;
+ struct timespec uptime, total, ran;
#else
uint32_t total_units = 0;
#endif
@@ -86,7 +83,7 @@ void rtems_cpu_usage_report( void )
printk( "CPU Usage by thread\n"
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
- " ID NAME SECONDS PERCENT\n"
+ " ID NAME SECONDS PERCENT\n"
#else
" ID NAME TICKS PERCENT\n"
#endif
@@ -110,16 +107,26 @@ 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, &total, &ival, &fval );
-
- printk(
- "%" PRId32 ".%06d" /* cpu time used */
- " %3" PRId32 ".%02" PRId32 "\n", /* percentage */
- the_thread->cpu_time_used.tv_sec,
- the_thread->cpu_time_used.tv_nsec /
- TOD_NANOSECONDS_PER_MICROSECOND,
- ival,
- fval
+ /*
+ * If this is the currently executing thread, account for time
+ * since the last context switch.
+ */
+ ran = the_thread->cpu_time_used;
+ if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
+ struct timespec used;
+ _Timespec_Subtract(
+ &_Thread_Time_of_last_context_switch, &uptime, &used
+ );
+ _Timespec_Add_to( &ran, &used );
+ };
+ _Timespec_Divide( &ran, &total, &ival, &fval );
+
+ /*
+ * Print the information
+ */
+ printk("%2" PRId32 ".%06" PRId32 " %3" PRId32 ".%02" PRId32 "\n",
+ ran.tv_sec, ran.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND,
+ ival, fval
);
#else
ival = (total_units) ?
@@ -138,7 +145,8 @@ void rtems_cpu_usage_report( void )
}
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
- printk( "Time since last reset %d.%06d seconds\n",
+ printk( "Time since last CPU Usage reset %" PRId32
+ ".%06" PRId32 " seconds\n",
total.tv_sec,
total.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND
);
diff --git a/cpukit/libmisc/cpuuse/cpuusagereset.c b/cpukit/libmisc/cpuuse/cpuusagereset.c
index 3f351b1c51..3acfd2c452 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereset.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereset.c
@@ -44,6 +44,7 @@ void rtems_cpu_usage_reset( void )
extern struct timespec CPU_usage_Uptime_at_last_reset;
_TOD_Get_uptime( &CPU_usage_Uptime_at_last_reset );
+ _Thread_Time_of_last_context_switch = CPU_usage_Uptime_at_last_reset;
#else
extern uint32_t CPU_usage_Ticks_at_last_reset;