You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/08/08 01:52:00 UTC

(nuttx-apps) branch master updated (c87c7c24a -> 875f2fcc1)

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

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


    from c87c7c24a iozone:add CMakefile.txt
     new 3b6f6ab4e ramspeed:Fix the mem leak caused by not releasing memory when the task exits under the -a option
     new e04782816 ramspeed:Add log printing & improve test accuracy & optional test cases
     new 875f2fcc1 ramspeed:Fix memleak due to double malloc.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 benchmarks/ramspeed/Kconfig         |  1 +
 benchmarks/ramspeed/ramspeed_main.c | 75 ++++++++++++++++++++++++++++---------
 2 files changed, 58 insertions(+), 18 deletions(-)


(nuttx-apps) 02/03: ramspeed:Add log printing & improve test accuracy & optional test cases

Posted by xi...@apache.org.
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-apps.git

commit e04782816fb251ab37e824a05fa0f85f620cc089
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Wed Apr 10 12:06:20 2024 +0800

    ramspeed:Add log printing & improve test accuracy & optional test cases
    
    1.Add more print logs
    
    ramspeed -w 0x61ba15c0 -s 524288 -n 10000 -i
    RAM Speed: Write address: 0x0x61ba15c0
    RAM Speed: Read address: 0x0
    RAM Speed: Size: 524288 bytes
    RAM Speed: Value: 0x00
    RAM Speed: Repeat number: 10000
    RAM Speed: Interrupts disabled: true
    
    2.Improve test accuracy, now print in double type in us time unit
    
    ______Perform 32 Bytes access______
    RAM Speed: system memset():      Rate = 625000.000 KB/s [cost: 0.500 ms]
    RAM Speed: internal memset():    Rate = 240384.615 KB/s [cost: 1.300 ms]
    
    3. Optional test item, if we do not pass in the src address, only memset will be executed
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 benchmarks/ramspeed/Kconfig         |  1 +
 benchmarks/ramspeed/ramspeed_main.c | 61 +++++++++++++++++++++++++++++--------
 2 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/benchmarks/ramspeed/Kconfig b/benchmarks/ramspeed/Kconfig
index 86e890e42..19c5b47c7 100644
--- a/benchmarks/ramspeed/Kconfig
+++ b/benchmarks/ramspeed/Kconfig
@@ -6,6 +6,7 @@
 config BENCHMARK_RAMSPEED
 	tristate "RAM Speed Test"
 	default n
+	depends on LIBC_FLOATINGPOINT
 	---help---
 		Enable a simple RAM speed test.
 
diff --git a/benchmarks/ramspeed/ramspeed_main.c b/benchmarks/ramspeed/ramspeed_main.c
index 9343de9a4..7c1b1c3d3 100644
--- a/benchmarks/ramspeed/ramspeed_main.c
+++ b/benchmarks/ramspeed/ramspeed_main.c
@@ -203,11 +203,45 @@ static void parse_commandline(int argc, FAR char **argv,
         }
     }
 
-  if (info->dest == NULL || info->src == NULL || info->size == 0)
+  if ((info->dest == NULL && !info->allocate_rw_address) || info->size == 0)
     {
       printf(RAMSPEED_PREFIX "Missing required arguments\n");
-      show_usage(argv[0], EXIT_FAILURE);
+      goto out;
+    }
+  else
+    {
+      /* We need to automatically apply for memory */
+
+      printf(RAMSPEED_PREFIX "Allocate RW buffers on heap\n");
+      info->dest = malloc(info->size);
+      if (info->dest == NULL)
+        {
+          printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
+          goto out;
+        }
+
+      info->src = malloc(info->size);
+      if (info->src == NULL)
+        {
+          printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
+          goto out;
+        }
     }
+
+  /* Print info */
+
+  printf(RAMSPEED_PREFIX "Write address: %p\n", info->dest);
+  printf(RAMSPEED_PREFIX "Read address: %p\n", info->src);
+  printf(RAMSPEED_PREFIX "Size: %zu bytes\n", info->size);
+  printf(RAMSPEED_PREFIX "Value: 0x%02x\n", info->value);
+  printf(RAMSPEED_PREFIX "Repeat number: %" PRIu32 "\n", info->repeat_num);
+  printf(RAMSPEED_PREFIX "Interrupts disabled: %s\n",
+         info->irq_disable ? "true" : "false");
+
+  return;
+
+out:
+    show_usage(argv[0], EXIT_FAILURE);
 }
 
 /****************************************************************************
@@ -217,10 +251,10 @@ static void parse_commandline(int argc, FAR char **argv,
 static uint32_t get_timestamp(void)
 {
   struct timespec ts;
-  uint32_t ms;
+  uint32_t us;
   clock_gettime(CLOCK_MONOTONIC, &ts);
-  ms = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
-  return ms;
+  us = ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+  return us;
 }
 
 /****************************************************************************
@@ -376,7 +410,7 @@ static void internal_memset(FAR void *dst, uint8_t v, size_t len)
 static void print_rate(FAR const char *name, uint64_t bytes,
                        uint32_t cost_time)
 {
-  uint32_t rate;
+  double rate;
   if (cost_time == 0)
     {
       printf(RAMSPEED_PREFIX
@@ -385,10 +419,10 @@ static void print_rate(FAR const char *name, uint64_t bytes,
       return;
     }
 
-  rate = bytes * 1000 / cost_time / 1024;
+  rate = (double)bytes / 1024 / (cost_time / 1000000.0);
   printf(RAMSPEED_PREFIX
-         "%s Rate = %" PRIu32 " KB/s\t[cost: %" PRIu32 "ms]\n",
-         name, rate, cost_time);
+         "%s Rate = %.3f KB/s\t[cost: %.3f ms]\n",
+         name, rate, cost_time / 1000.0f);
 }
 
 /****************************************************************************
@@ -535,9 +569,12 @@ int main(int argc, FAR char *argv[])
 
   parse_commandline(argc, argv, &ramspeed);
 
-  memcpy_speed_test(ramspeed.dest, ramspeed.src,
-                    ramspeed.size, ramspeed.repeat_num,
-                    ramspeed.irq_disable);
+  if (ramspeed.src != NULL)
+    {
+      memcpy_speed_test(ramspeed.dest, ramspeed.src,
+                        ramspeed.size, ramspeed.repeat_num,
+                        ramspeed.irq_disable);
+    }
 
   memset_speed_test(ramspeed.dest, ramspeed.value,
                     ramspeed.size, ramspeed.repeat_num,


(nuttx-apps) 03/03: ramspeed:Fix memleak due to double malloc.

Posted by xi...@apache.org.
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-apps.git

commit 875f2fcc1e4aed074d75172ad3d4aaef39edf937
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Thu Apr 11 20:40:49 2024 +0800

    ramspeed:Fix memleak due to double malloc.
    
      if (allocate_rw_address)
        {
          info->dest = malloc(info->size);
          info->src = malloc(info->size);
        }
      if ((info->dest == NULL && !info->allocate_rw_address) || info->size == 0)
        {
          printf(RAMSPEED_PREFIX "Missing required arguments\n");
          goto out;
        }
      else
        {
          /* We need to automatically apply for memory */
          printf(RAMSPEED_PREFIX "Allocate RW buffers on heap\n");
          info->dest = malloc(info->size);
          if (info->dest == NULL)
            {
              printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
              goto out;
            }
          info->src = malloc(info->size);
          if (info->src == NULL)
            {
              printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
              goto out;
            }
        }
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 benchmarks/ramspeed/ramspeed_main.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/benchmarks/ramspeed/ramspeed_main.c b/benchmarks/ramspeed/ramspeed_main.c
index 7c1b1c3d3..2432f67d8 100644
--- a/benchmarks/ramspeed/ramspeed_main.c
+++ b/benchmarks/ramspeed/ramspeed_main.c
@@ -187,22 +187,6 @@ static void parse_commandline(int argc, FAR char **argv,
         }
     }
 
-  if (info->allocate_rw_address)
-    {
-      info->dest = malloc(info->size);
-      if (info->dest == NULL)
-        {
-          printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
-        }
-
-      info->src = malloc(info->size);
-      if (info->src == NULL)
-        {
-          free(info->dest);
-          printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
-        }
-    }
-
   if ((info->dest == NULL && !info->allocate_rw_address) || info->size == 0)
     {
       printf(RAMSPEED_PREFIX "Missing required arguments\n");


(nuttx-apps) 01/03: ramspeed:Fix the mem leak caused by not releasing memory when the task exits under the -a option

Posted by xi...@apache.org.
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-apps.git

commit 3b6f6ab4e6e4279ed596ffc3e0a0997591a854a4
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Wed Apr 3 16:44:57 2024 +0800

    ramspeed:Fix the mem leak caused by not releasing memory when the task exits under the -a option
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 benchmarks/ramspeed/ramspeed_main.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/benchmarks/ramspeed/ramspeed_main.c b/benchmarks/ramspeed/ramspeed_main.c
index 24706e11b..9343de9a4 100644
--- a/benchmarks/ramspeed/ramspeed_main.c
+++ b/benchmarks/ramspeed/ramspeed_main.c
@@ -87,6 +87,7 @@ struct ramspeed_s
   uint8_t value;
   uint32_t repeat_num;
   bool irq_disable;
+  bool allocate_rw_address;
 };
 
 /****************************************************************************
@@ -130,7 +131,6 @@ static void parse_commandline(int argc, FAR char **argv,
                               FAR struct ramspeed_s *info)
 {
   int ch;
-  bool allocate_rw_address = false;
 
   memset(info, 0, sizeof(struct ramspeed_s));
   info->repeat_num = 100;
@@ -146,7 +146,7 @@ static void parse_commandline(int argc, FAR char **argv,
       switch (ch)
         {
           case 'a':
-            allocate_rw_address = true;
+            info->allocate_rw_address = true;
             break;
           case 'r':
             OPTARG_TO_VALUE(info->src, const void *, 16);
@@ -187,10 +187,20 @@ static void parse_commandline(int argc, FAR char **argv,
         }
     }
 
-  if (allocate_rw_address)
+  if (info->allocate_rw_address)
     {
       info->dest = malloc(info->size);
+      if (info->dest == NULL)
+        {
+          printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
+        }
+
       info->src = malloc(info->size);
+      if (info->src == NULL)
+        {
+          free(info->dest);
+          printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
+        }
     }
 
   if (info->dest == NULL || info->src == NULL || info->size == 0)
@@ -533,5 +543,13 @@ int main(int argc, FAR char *argv[])
                     ramspeed.size, ramspeed.repeat_num,
                     ramspeed.irq_disable);
 
+  /* Check if alloc from heap? */
+
+  if (ramspeed.allocate_rw_address)
+    {
+      free(ramspeed.dest);
+      free((void *)ramspeed.src);
+    }
+
   return EXIT_SUCCESS;
 }