sched/note: add note when mm add new region

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
xuxingliang 2024-07-03 13:28:42 +08:00 committed by Xiang Xiao
parent 0663ac1483
commit eac6a8597f
5 changed files with 25 additions and 4 deletions

View File

@ -230,6 +230,7 @@ struct mm_heap_s *mm_initialize(const char *name,
procfs_register_meminfo(&heap->mm_procfs);
#endif
sched_note_heap(NOTE_HEAP_ADD, heap, heap_start, heap_size);
return heap;
}
@ -251,6 +252,10 @@ struct mm_heap_s *mm_initialize(const char *name,
void mm_uninitialize(struct mm_heap_s *heap)
{
sched_note_heap(NOTE_HEAP_REMOVE, heap, heap_start,
(uintptr_t)heap->mm_heapend[0] -
(uintptr_t)heap->mm_heapstart[0]);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
procfs_unregister_meminfo(&heap->mm_procfs);
#endif

View File

@ -1086,6 +1086,8 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_HEAP
case NOTE_HEAP_ADD:
case NOTE_HEAP_REMOVE:
case NOTE_HEAP_ALLOC:
case NOTE_HEAP_FREE:
{
@ -1094,21 +1096,22 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
int used = 0;
FAR const char *name[] =
{
"malloc", "free"
"add", "remove", "malloc", "free"
};
tctx = noteram_dump_find_task_context(ctx, pid);
if (tctx != NULL)
{
tctx->mm_used += note->nc_type == NOTE_HEAP_FREE ?
-nmm->size : nmm->size;
tctx->mm_used += note->nc_type == NOTE_HEAP_FREE ? -nmm->size
: note->nc_type == NOTE_HEAP_ALLOC ? nmm->size
: 0;
used = tctx->mm_used;
}
ret += noteram_dump_header(s, &nmm->nmm_cmn, ctx);
ret += lib_sprintf(s, "tracing_mark_write: C|%d|Heap Usage|%d|%s"
": heap: %p size:%" PRIiPTR ", address: %p\n",
pid, used, name[note->nc_type - NOTE_HEAP_ALLOC],
pid, used, name[note->nc_type - NOTE_HEAP_ADD],
nmm->heap, nmm->size, nmm->mem);
}
break;

View File

@ -188,6 +188,8 @@ enum note_type_e
NOTE_SYSCALL_LEAVE,
NOTE_IRQ_ENTER,
NOTE_IRQ_LEAVE,
NOTE_HEAP_ADD,
NOTE_HEAP_REMOVE,
NOTE_HEAP_ALLOC,
NOTE_HEAP_FREE,
NOTE_DUMP_STRING,

View File

@ -30,6 +30,7 @@
#include <assert.h>
#include <debug.h>
#include <nuttx/sched_note.h>
#include <nuttx/mm/mm.h>
#include <nuttx/mm/kasan.h>
@ -202,6 +203,8 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
mm_addfreechunk(heap, node);
heap->mm_curused += 2 * MM_SIZEOF_ALLOCNODE;
mm_unlock(heap);
sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize);
}
/****************************************************************************
@ -367,6 +370,9 @@ void mm_uninitialize(FAR struct mm_heap_s *heap)
for (i = 0; i < CONFIG_MM_REGIONS; i++)
{
kasan_unregister(heap->mm_heapstart[i]);
sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i],
(uintptr_t)heap->mm_heapend[i] -
(uintptr_t)heap->mm_heapstart[i]);
}
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)

View File

@ -600,6 +600,8 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
tlsf_add_pool(heap->mm_tlsf, heapstart, heapsize);
mm_unlock(heap);
sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize);
}
/****************************************************************************
@ -1439,6 +1441,9 @@ void mm_uninitialize(FAR struct mm_heap_s *heap)
for (i = 0; i < CONFIG_MM_REGIONS; i++)
{
kasan_unregister(heap->mm_heapstart[i]);
sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i],
(uintptr_t)heap->mm_heapend[i] -
(uintptr_t)heap->mm_heapstart[i]);
}
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)