summaryrefslogtreecommitdiffstats
path: root/cpukit
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
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')
-rw-r--r--cpukit/ChangeLog7
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereport.c42
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereset.c1
-rw-r--r--cpukit/score/src/timespecdivide.c4
4 files changed, 36 insertions, 18 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index d6910e4549..9fa534013c 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
2007-07-24 Ralf Corsépius <ralf.corsepius@rtems.org>
* shttpd/Makefile.am: Prefix all non-public symbols with _shttp_.
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;
diff --git a/cpukit/score/src/timespecdivide.c b/cpukit/score/src/timespecdivide.c
index 74d6cdbc78..c40d02757f 100644
--- a/cpukit/score/src/timespecdivide.c
+++ b/cpukit/score/src/timespecdivide.c
@@ -17,6 +17,8 @@
#include "config.h"
#endif
+#include <stdio.h>
+
#include <rtems/system.h>
#include <sys/types.h>
#include <rtems/score/timespec.h>
@@ -50,7 +52,7 @@ void _Timespec_Divide(
* Put it back in the timespec result
*/
- answer = (left * 1000) / right;
+ answer = (left * 100000) / right;
*fval_percentage = answer % 1000;
*ival_percentage = answer / 1000;