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

commit 464d2845872e32e531b629211df8818a9df98910
Author: yinshengkai <[email protected]>
AuthorDate: Fri May 24 12:03:21 2024 +0800

    drivers/note: simplify notesnap_dump logic
    
    RTOSXMDPYX-969
    
    Crash at startup, index is 0 will cause loop printing
    
    Signed-off-by: yinshengkai <[email protected]>
---
 drivers/note/notesnap_driver.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/note/notesnap_driver.c b/drivers/note/notesnap_driver.c
index 413ea836d4..c56d1d598d 100644
--- a/drivers/note/notesnap_driver.c
+++ b/drivers/note/notesnap_driver.c
@@ -368,40 +368,28 @@ int notesnap_register(void)
 
 void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
 {
+  size_t index = g_notesnap.index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
   size_t i;
-  size_t index = atomic_load(&g_notesnap.index) %
-                 CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
-  clock_t lastcount = g_notesnap.buffer[index].count;
-  struct timespec lasttime =
-  {
-    0
-  };
 
   /* Stop recording while dumping */
 
   atomic_store(&g_notesnap.dumping, true);
 
-  for (i = index; i != index - 1;
-       i == CONFIG_DRIVERS_NOTESNAP_NBUFFERS - 1 ? i = 0 : i++)
+  for (i = 0; i < CONFIG_DRIVERS_NOTESNAP_NBUFFERS; i++)
     {
-      FAR struct notesnap_chunk_s *note = &g_notesnap.buffer[i];
-
+      FAR struct notesnap_chunk_s *note = &g_notesnap.buffer
+          [(index + i) % CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
       struct timespec time;
-      clock_t elapsed = note->count < lastcount ?
-                        note->count + CLOCK_MAX - lastcount :
-                        note->count - lastcount;
-      perf_convert(elapsed, &time);
-      clock_timespec_add(&lasttime, &time, &lasttime);
-      lastcount = note->count;
 
+      perf_convert(note->count, &time);
       lib_sprintf(stream,
                   "snapshoot: [%u.%09u] "
 #ifdef CONFIG_SMP
                   "[CPU%d] "
 #endif
                   "[%d] %-16s %#" PRIxPTR "\n",
-                  (unsigned)lasttime.tv_sec,
-                  (unsigned)lasttime.tv_nsec,
+                  (unsigned)time.tv_sec,
+                  (unsigned)time.tv_nsec,
 #ifdef CONFIG_SMP
                   note->cpu,
 #endif

Reply via email to