This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new bf957348ef [BugFix]Command "critmon" error
bf957348ef is described below

commit bf957348ef73a7f379fa13fdef1d6cfefbee3107
Author: wangzhi16 <[email protected]>
AuthorDate: Wed Aug 14 20:36:18 2024 +0800

    [BugFix]Command "critmon" error
    
    Command "critmon" has some format errors and information errors, such as:
    
    PRE-EMPTION CALLER            CSECTION CALLER               RUN         
TIME             PID   DESCRIPTION
    1.679000000                   3.704000000
                             None None             0     CPU0 IDLE
    0.002000000                   0.003000000
                             None None             1     CPU1 IDLE
    0.000000000                   0.000000000
                             None None             2     CPU2 IDLE
    0.000000000                   0.000000000
                             None None             3     CPU3 IDLE
    0.001000000                   0.001000000
                             None None             4     hpwork
    0.002000000                   0.006000000
                             None None             5     nsh_main
    0.000000000                   0.000000000
                             None None             6     critmon
    
    After bug fix:
    
    PRE-EMPTION CALLER            CSECTION CALLER               RUN             
 TIME             PID   DESCRIPTION
    None                          None                          
---------------- ---------------- ----  CPU 0
    None                          None                          
---------------- ---------------- ----  CPU 1
    None                          None                          
---------------- ---------------- ----  CPU 2
    None                          None                          
---------------- ---------------- ----  CPU 3
    None                          None                          0.238000000     
 6.982000000      0     CPU0 IDLE
    None                          None                          0.461000000     
 13.089000000     1     CPU1 IDLE
    None                          None                          0.000000000     
 0.000000000      2     CPU2 IDLE
    None                          None                          0.000000000     
 0.000000000      3     CPU3 IDLE
    None                          None                          0.000000000     
 0.001000000      4     hpwork
    None                          None                          0.000000000     
 0.010000000      5     nsh_main
    None                          None                          0.000000000     
 0.000000000      46    critmon
    
    Signed-off-by: wangzhi16 <[email protected]>
---
 fs/procfs/fs_procfscritmon.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/fs/procfs/fs_procfscritmon.c b/fs/procfs/fs_procfscritmon.c
index 5187dc91ed..8884babb3a 100644
--- a/fs/procfs/fs_procfscritmon.c
+++ b/fs/procfs/fs_procfscritmon.c
@@ -188,6 +188,21 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s 
*attr,
 
   totalsize = 0;
 
+  /* Generate output for CPU Serial Number */
+
+  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d", cpu);
+  copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
+
+  totalsize += copysize;
+  buffer    += copysize;
+  buflen    -= copysize;
+
+  if (buflen <= 0)
+    {
+      return totalsize;
+    }
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
   /* Convert the for maximum time pre-emption disabled */
 
   if (g_premp_max[cpu] > 0)
@@ -206,15 +221,16 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s 
*attr,
 
   /* Generate output for maximum time pre-emption disabled */
 
-  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d,%lu.%09lu,",
-                             cpu, (unsigned long)maxtime.tv_sec,
+  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
+                             (unsigned long)maxtime.tv_sec,
                              (unsigned long)maxtime.tv_nsec);
   copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
 
   totalsize += copysize;
   buffer    += copysize;
+  buflen    -= copysize;
 
-  if (totalsize >= buflen)
+  if (buflen <= 0)
     {
       return totalsize;
     }
@@ -237,12 +253,26 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s 
*attr,
 
   /* Generate output for maximum time in a critical section */
 
-  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%lu.%09lu\n",
+  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
                              (unsigned long)maxtime.tv_sec,
                              (unsigned long)maxtime.tv_nsec);
   copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
 
   totalsize += copysize;
+  buffer    += copysize;
+  buflen    -= copysize;
+
+  if (buflen <= 0)
+    {
+      return totalsize;
+    }
+#endif
+
+  linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "\n");
+  copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
+
+  totalsize += copysize;
+
   return totalsize;
 }
 
@@ -280,8 +310,6 @@ static ssize_t critmon_read(FAR struct file *filep, FAR 
char *buffer,
         {
           break;
         }
-
-      offset += nbytes;
     }
 
   if (ret > 0)

Reply via email to