[rtems commit] cpuuse: Use rtems_task_iterate()

Sebastian Huber sebh at rtems.org
Wed Nov 2 08:13:57 UTC 2016


Module:    rtems
Branch:    master
Commit:    4cf58905b825ea8d2b9d677dc32d529390052d3a
Changeset: http://git.rtems.org/rtems/commit/?id=4cf58905b825ea8d2b9d677dc32d529390052d3a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Oct 31 14:45:30 2016 +0100

cpuuse: Use rtems_task_iterate()

Update #2423.

---

 cpukit/libmisc/cpuuse/cpuusagereport.c | 117 +++++++++++++++++----------------
 1 file changed, 59 insertions(+), 58 deletions(-)

diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index 370eb05..e3157e8 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -26,13 +26,59 @@
 
 #include <rtems/cpuuse.h>
 #include <rtems/printer.h>
-#include <rtems/score/objectimpl.h>
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/todimpl.h>
-#include <rtems/score/watchdogimpl.h>
 
 #include "cpuuseimpl.h"
 
+typedef struct {
+  const rtems_printer *printer;
+  Timestamp_Control    total;
+  Timestamp_Control    uptime_at_last_reset;
+} cpu_usage_context;
+
+static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
+{
+  cpu_usage_context *ctx;
+  char               name[ 13 ];
+  uint32_t           ival;
+  uint32_t           fval;
+  Timestamp_Control  uptime;
+  Timestamp_Control  used;
+  uint32_t           seconds;
+  uint32_t           nanoseconds;
+
+  ctx = arg;
+  rtems_object_get_name( the_thread->Object.id, sizeof( name ), name );
+
+  rtems_printf(
+    ctx->printer,
+    " 0x%08" PRIx32 " | %-38s |",
+    the_thread->Object.id,
+    name
+  );
+
+  _Thread_Get_CPU_time_used( the_thread, &used );
+  _TOD_Get_uptime( &uptime );
+  _Timestamp_Subtract( &ctx->uptime_at_last_reset, &uptime, &ctx->total );
+  _Timestamp_Divide( &used, &ctx->total, &ival, &fval );
+
+  /*
+   * Print the information
+   */
+
+  seconds = _Timestamp_Get_seconds( &used );
+  nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
+    TOD_NANOSECONDS_PER_MICROSECOND;
+  rtems_printf( ctx->printer,
+    "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
+    seconds, nanoseconds,
+    ival, fval
+  );
+
+  return false;
+}
+
 /*
  *  rtems_cpu_usage_report
  */
@@ -40,22 +86,19 @@ void rtems_cpu_usage_report_with_plugin(
   const rtems_printer *printer
 )
 {
-  uint32_t             i;
-  uint32_t             api_index;
-  Thread_Control      *the_thread;
-  Objects_Information *information;
-  char                 name[13];
-  uint32_t             ival, fval;
-  Timestamp_Control    uptime, total, used, uptime_at_last_reset;
-  uint32_t             seconds, nanoseconds;
+  cpu_usage_context  ctx;
+  uint32_t           seconds;
+  uint32_t           nanoseconds;
+
+  ctx.printer = printer;
 
   /*
    *  When not using nanosecond CPU usage resolution, we have to count
    *  the number of "ticks" we gave credit for to give the user a rough
    *  guideline as to what each number means proportionally.
    */
-  _Timestamp_Set_to_zero( &total );
-  uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
+  _Timestamp_Set_to_zero( &ctx.total );
+  ctx.uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
 
   rtems_printf(
      printer,
@@ -66,52 +109,10 @@ void rtems_cpu_usage_report_with_plugin(
      "------------+----------------------------------------+---------------+---------\n"
   );
 
-  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
-    #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
-      if ( !_Objects_Information_table[ api_index ] )
-        continue;
-    #endif
-
-    information = _Objects_Information_table[ api_index ][ 1 ];
-    if ( information ) {
-      for ( i=1 ; i <= information->maximum ; i++ ) {
-        the_thread = (Thread_Control *)information->local_table[ i ];
-
-        if ( !the_thread )
-          continue;
-
-        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
-
-        rtems_printf(
-          printer,
-          " 0x%08" PRIx32 " | %-38s |",
-          the_thread->Object.id,
-          name
-        );
-
-        _Thread_Get_CPU_time_used( the_thread, &used );
-        _TOD_Get_uptime( &uptime );
-        _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
-        _Timestamp_Divide( &used, &total, &ival, &fval );
-
-        /*
-         * Print the information
-         */
-
-        seconds = _Timestamp_Get_seconds( &used );
-        nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
-          TOD_NANOSECONDS_PER_MICROSECOND;
-        rtems_printf( printer,
-          "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
-          seconds, nanoseconds,
-          ival, fval
-        );
-      }
-    }
-  }
-
-  seconds = _Timestamp_Get_seconds( &total );
-  nanoseconds = _Timestamp_Get_nanoseconds( &total ) /
+  rtems_task_iterate( cpu_usage_visitor, &ctx );
+
+  seconds = _Timestamp_Get_seconds( &ctx.total );
+  nanoseconds = _Timestamp_Get_nanoseconds( &ctx.total ) /
     TOD_NANOSECONDS_PER_MICROSECOND;
   rtems_printf(
      printer,




More information about the vc mailing list