[PATCH 1/2] libmisc/top: Fix the idle time and priorities on SMP

chrisj at rtems.org chrisj at rtems.org
Thu Dec 12 23:23:01 UTC 2019


From: Chris Johns <chrisj at rtems.org>

- This patch is based on the patch attached to #3552 submitted
  by jameszxj.

Closes #3552
---
 cpukit/libmisc/cpuuse/cpuusagetop.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c
index 96e364bf93..7dbed6b810 100644
--- a/cpukit/libmisc/cpuuse/cpuusagetop.c
+++ b/cpukit/libmisc/cpuuse/cpuusagetop.c
@@ -41,6 +41,9 @@
 #include <rtems/score/watchdogimpl.h>
 #include <rtems/score/wkspace.h>
 
+#include <rtems/rtems/tasksimpl.h>
+#include <rtems/scheduler.h>
+
 #include "cpuuseimpl.h"
 
 /*
@@ -171,8 +174,11 @@ task_usage(Thread_Control* thread, void* arg)
   rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
   Timestamp_Control     usage;
   Timestamp_Control     current = data->zero;
+  uint32_t              cpu_max;
   int                   j;
 
+  cpu_max = rtems_configuration_get_maximum_processors();
+
   data->stack_size += thread->Start.Initial_stack.size;
 
   _Thread_Get_CPU_time_used(thread, &usage);
@@ -194,10 +200,10 @@ task_usage(Thread_Control* thread, void* arg)
   _Timestamp_Add_to(&data->total, &usage);
   _Timestamp_Add_to(&data->current, &current);
 
-  if (thread->Object.id == 0x09010001)
+  if (thread->Object.id >= 0x09010001 && thread->Object.id < (0x09010001 + cpu_max))
   {
-    data->idle = usage;
-    data->current_idle = current;
+    data->idle += usage;
+    data->current_idle += current;
   }
 
   /*
@@ -424,6 +430,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
       Thread_Control*   thread = data->tasks[i];
       Timestamp_Control usage;
       Timestamp_Control current_usage;
+      const Scheduler_Control *scheduler;
 
       if (thread == NULL)
         break;
@@ -444,12 +451,14 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
       if (name[0] == '\0')
         snprintf(name, sizeof(name) - 1, "(%p)", thread->Start.Entry.Kinds.Numeric.entry);
 
+      scheduler = _Thread_Scheduler_get_home( thread );
+
       rtems_printf(data->printer,
-                   " 0x%08" PRIx32 " | %-19s |  %3" PRId64 " |  %3" PRId64 "   | ",
+                   " 0x%08" PRIx32 " | %-19s |  %3" PRId32 " |  %3" PRId32 "   | ",
                    thread->Object.id,
                    name,
-                   _Thread_Get_unmapped_real_priority(thread),
-                   _Thread_Get_unmapped_priority(thread));
+                   _RTEMS_Priority_From_core(scheduler, thread->Real_priority.priority),
+                   _RTEMS_Priority_From_core(scheduler, _Thread_Get_priority(thread)));
 
       usage = data->usage[i];
       current_usage = data->current_usage[i];
-- 
2.23.0



More information about the devel mailing list