mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
mm: Move procfs_register_meminfo into common place
to avoid the code duplication and ensure the consistent behaviour Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
David Sidrane
parent
817259ec2d
commit
b1f711f790
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/fs/procfs.h>
|
||||
#include <nuttx/mm/mm.h>
|
||||
|
||||
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||
@@ -59,16 +58,7 @@ struct mm_heap_s g_kmmheap;
|
||||
|
||||
void kmm_initialize(FAR void *heap_start, size_t 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
|
||||
mm_initialize(&g_kmmheap, "Kmem", heap_start, heap_size);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MM_KERNEL_HEAP */
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/fs/procfs.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
@@ -207,6 +209,10 @@ struct mm_heap_impl_s
|
||||
#else
|
||||
FAR struct mm_delaynode_s *mm_delaylist[1];
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
|
||||
struct procfs_meminfo_entry_s mm_procfs;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Functions contained in mm_sem.c ******************************************/
|
||||
|
||||
@@ -161,14 +161,14 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
size_t heapsize)
|
||||
void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
|
||||
FAR void *heapstart, size_t heapsize)
|
||||
{
|
||||
FAR struct mm_heap_impl_s *heap_impl;
|
||||
uintptr_t heap_adj;
|
||||
int i;
|
||||
|
||||
minfo("Heap: start=%p size=%zu\n", heapstart, heapsize);
|
||||
minfo("Heap: name=%s, start=%p size=%zu\n", name, heapstart, heapsize);
|
||||
|
||||
/* First ensure the memory to be used is aligned */
|
||||
|
||||
@@ -216,4 +216,13 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
/* Add the initial region of memory to the heap */
|
||||
|
||||
mm_addregion(heap, heapstart, heapsize);
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
|
||||
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
|
||||
heap_impl->mm_procfs.name = name;
|
||||
heap_impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo;
|
||||
heap_impl->mm_procfs.user_data = heap;
|
||||
procfs_register_meminfo(&heap_impl->mm_procfs);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ FAR void *mm_sbrk(FAR struct mm_heap_s *heap, intptr_t incr,
|
||||
{
|
||||
/* No... then initialize it now */
|
||||
|
||||
mm_initialize(heap, (FAR void *)allocbase, bytesize);
|
||||
mm_initialize(heap, "Umem", (FAR void *)allocbase, bytesize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/fs/procfs.h>
|
||||
#include <nuttx/mm/mm.h>
|
||||
|
||||
#include "umm_heap/umm_heap.h"
|
||||
@@ -82,17 +81,5 @@
|
||||
|
||||
void umm_initialize(FAR void *heap_start, size_t heap_size)
|
||||
{
|
||||
mm_initialize(USR_HEAP, heap_start, heap_size);
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
|
||||
#if (defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \
|
||||
defined(CONFIG_BUILD_FLAT)
|
||||
static struct procfs_meminfo_entry_s g_umm_procfs;
|
||||
|
||||
g_umm_procfs.name = "Umem";
|
||||
g_umm_procfs.mallinfo = (void *)mm_mallinfo;
|
||||
g_umm_procfs.user_data = USR_HEAP;
|
||||
procfs_register_meminfo(&g_umm_procfs);
|
||||
#endif
|
||||
#endif
|
||||
mm_initialize(USR_HEAP, "Umem", heap_start, heap_size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user