You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xiaoxiang781216 (via GitHub)" <gi...@apache.org> on 2023/01/27 13:04:45 UTC

[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8270: fs/procfs: fix the issue of /proc/cpuload in SMP

xiaoxiang781216 commented on code in PR #8270:
URL: https://github.com/apache/nuttx/pull/8270#discussion_r1088939550


##########
fs/procfs/fs_procfscpuload.c:
##########
@@ -201,26 +201,46 @@ static ssize_t cpuload_read(FAR struct file *filep, FAR char *buffer,
 
   if (filep->f_pos == 0)
     {
-      struct cpuload_s cpuload;
+      uint32_t total = 0;
+      uint32_t active = 0;
       uint32_t intpart;
       uint32_t fracpart;
 
       /* Sample the counts for the IDLE thread.  clock_cpuload should only
        * fail if the PID is not valid.  This, however, should never happen
        * for the IDLE thread.
        */
+#ifdef CONFIG_SMP
+      struct cpuload_s cpuloads[CONFIG_SMP_NCPUS];
+      uint32_t i;
+
+      for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+        {
+          DEBUGVERIFY(clock_cpuload(i, &cpuloads[i]));
+          active += cpuloads[i].active;
+        }
+
+      total = cpuloads[0].total;
+#else
+      struct cpuload_s cpuload;
 
       DEBUGVERIFY(clock_cpuload(0, &cpuload));
+      active = cpuload.active;
+      total = cpuload.total;
+#endif
+
+      if (active > total)
+          active = total;

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org