Hi,
   1. "data->current_idle" and "data->idle" should be 
initialize (_Timestamp_Set_to_zero), or the " Load Average" will not be right.
   2. On z7020 board, SMP mode, the RPRI and CPRI of idle seems not 
reasonable.


 ID         | NAME        
        | RPRI | CPRI   | TIME    
            | TOTAL   | CURRENT
------------+---------------------+---------------+---------------------+---------+--^^----
 0x09010001 | IDLE              
  |  2147483647 |  2147483647   | 
4.372973            |  53.157 |  99.998
 0x09010002 | IDLE              
  |  2147483647 |  2147483647   | 
3.620072            |  44.005 |  99.862

 0x0a010002 | WDOG              
  |    3 |    3   | 0.000028    
        |   0.000 |   0.000
 0x0a010003 | QSPI              
  |  100 |  100   | 0.228549      
      |   2.778 |   0.000
 0x0a010004 | TIME              
  |   98 |   98   | 0.002924    
        |   0.035 |   0.132







------------------ Original ------------------
From:&nbsp;"Sebastian Huber"<sebastian.hu...@embedded-brains.de&gt;;
Date:&nbsp;Fri, Dec 13, 2019 03:08 PM
To:&nbsp;"rtems-devel"<rtems-de...@rtems.org&gt;;

Subject:&nbsp;[PATCH v2] libmisc/top: Fix the idle time and priorities on SMP



From: Chris Johns <chr...@rtems.org&gt;

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

Closes #3552
---
&nbsp;cpukit/libmisc/cpuuse/cpuusagetop.c | 31 ++++++++++++++++++++++---------
&nbsp;1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c 
b/cpukit/libmisc/cpuuse/cpuusagetop.c
index 96e364bf93..146b9801a4 100644
--- a/cpukit/libmisc/cpuuse/cpuusagetop.c
+++ b/cpukit/libmisc/cpuuse/cpuusagetop.c
@@ -36,10 +36,12 @@
&nbsp;#include <rtems/malloc.h&gt;
&nbsp;#include <rtems/score/objectimpl.h&gt;
&nbsp;#include <rtems/score/protectedheap.h&gt;
+#include <rtems/score/schedulerimpl.h&gt;
&nbsp;#include <rtems/score/threadimpl.h&gt;
&nbsp;#include <rtems/score/todimpl.h&gt;
&nbsp;#include <rtems/score/watchdogimpl.h&gt;
&nbsp;#include <rtems/score/wkspace.h&gt;
+#include <rtems/rtems/tasksimpl.h&gt;
&nbsp;
&nbsp;#include "cpuuseimpl.h"
&nbsp;
@@ -194,10 +196,10 @@ task_usage(Thread_Control* thread, void* arg)
&nbsp;&nbsp; _Timestamp_Add_to(&amp;data-&gt;total, &amp;usage);
&nbsp;&nbsp; _Timestamp_Add_to(&amp;data-&gt;current, &amp;current);
&nbsp;
-&nbsp; if (thread-&gt;Object.id == 0x09010001)
+&nbsp; if (thread-&gt;is_idle)
&nbsp;&nbsp; {
-&nbsp;&nbsp;&nbsp; data-&gt;idle = usage;
-&nbsp;&nbsp;&nbsp; data-&gt;current_idle = current;
+&nbsp;&nbsp;&nbsp; data-&gt;idle += usage;
+&nbsp;&nbsp;&nbsp; data-&gt;current_idle += current;
&nbsp;&nbsp; }
&nbsp;
&nbsp;&nbsp; /*
@@ -421,9 +423,13 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i < data-&gt;task_count; i++)
&nbsp;&nbsp;&nbsp;&nbsp; {
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread_Control*&nbsp;&nbsp; thread = 
data-&gt;tasks[i];
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Timestamp_Control usage;
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Timestamp_Control current_usage;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Thread_Control*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thread = 
data-&gt;tasks[i];
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Timestamp_Control&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; usage;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Timestamp_Control&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_usage;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread_queue_Context&nbsp;&nbsp;&nbsp;&nbsp; 
queue_context;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const Scheduler_Control *scheduler;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Priority_Control&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real_priority;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Priority_Control&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (thread == NULL)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;
@@ -444,12 +450,19 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (name[0] == '\0')
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; snprintf(name, sizeof(name) - 
1, "(%p)", thread-&gt;Start.Entry.Kinds.Numeric.entry);
&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
_Thread_queue_Context_initialize(&amp;queue_context);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _Thread_Wait_acquire(thread, 
&amp;queue_context);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scheduler = _Thread_Scheduler_get_home(thread);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real_priority = 
thread-&gt;Real_priority.priority;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority = _Thread_Get_priority(thread);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _Thread_Wait_release(thread, 
&amp;queue_context);
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rtems_printf(data-&gt;printer,
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 " 0x%08" PRIx32 " | %-19s |&nbsp; %3" PRId64 " |&nbsp; %3" PRId64 
"&nbsp;&nbsp; | ",
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 " 0x%08" PRIx32 " | %-19s |&nbsp; %3" PRId32 " |&nbsp; %3" PRId32 
"&nbsp;&nbsp; | ",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 thread-&gt;Object.id,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 name,
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 _Thread_Get_unmapped_real_priority(thread),
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 _Thread_Get_unmapped_priority(thread));
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 _RTEMS_Priority_From_core(scheduler, real_priority),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 _RTEMS_Priority_From_core(scheduler, priority));
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; usage = data-&gt;usage[i];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_usage = data-&gt;current_usage[i];
-- 
2.16.4

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel
_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to