You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2021/02/12 11:16:15 UTC

[incubator-nuttx] 03/07: procfs: Use procfs_register_meminfo for "Kmem"

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

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

commit 929e4380528803ba1e1c4464a53e1d49bbc7de26
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Fri Feb 12 14:10:07 2021 +0900

    procfs: Use procfs_register_meminfo for "Kmem"
---
 fs/procfs/fs_procfsmeminfo.c | 23 -----------------------
 mm/kmm_heap/kmm_initialize.c | 12 +++++++++++-
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c
index f89cc45..67d0724 100644
--- a/fs/procfs/fs_procfsmeminfo.c
+++ b/fs/procfs/fs_procfsmeminfo.c
@@ -319,29 +319,6 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
         }
     }
 
-#ifdef CONFIG_MM_KERNEL_HEAP
-  if (totalsize < buflen)
-    {
-      struct mallinfo mem;
-
-      buffer    += copysize;
-      buflen    -= copysize;
-
-      /* Show kernel heap information */
-
-      mem        = kmm_mallinfo();
-      linesize   = snprintf(procfile->line, MEMINFO_LINELEN,
-                            "Kmem:  %11lu%11lu%11lu%11lu\n",
-                            (unsigned long)mem.arena,
-                            (unsigned long)mem.uordblks,
-                            (unsigned long)mem.fordblks,
-                            (unsigned long)mem.mxordblk);
-      copysize   = procfs_memcpy(procfile->line, linesize, buffer, buflen,
-                                 &offset);
-      totalsize += copysize;
-    }
-#endif
-
 #ifdef CONFIG_MM_PGALLOC
   if (totalsize < buflen)
     {
diff --git a/mm/kmm_heap/kmm_initialize.c b/mm/kmm_heap/kmm_initialize.c
index 1e1daef..7ff5f66 100644
--- a/mm/kmm_heap/kmm_initialize.c
+++ b/mm/kmm_heap/kmm_initialize.c
@@ -24,6 +24,7 @@
 
 #include <nuttx/config.h>
 
+#include <nuttx/fs/procfs.h>
 #include <nuttx/mm/mm.h>
 
 #ifdef CONFIG_MM_KERNEL_HEAP
@@ -58,7 +59,16 @@ struct mm_heap_s g_kmmheap;
 
 void kmm_initialize(FAR void *heap_start, size_t heap_size)
 {
-  return mm_initialize(&g_kmmheap, heap_start, heap_size);
+  mm_initialize(&g_kmmheap, heap_start, heap_size);
+
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
+  static struct procfs_meminfo_entry_s g_kmm_procfs;
+
+  g_kmm_procfs.name = "Kmem";
+  g_kmm_procfs.mallinfo = (void *)mm_mallinfo;
+  g_kmm_procfs.user_data = &g_kmmheap;
+  procfs_register_meminfo(&g_kmm_procfs);
+#endif
 }
 
 #endif /* CONFIG_MM_KERNEL_HEAP */