sched/note: specify note event for heap instrumentation
1. Add NOTE_HEAP_ prefix for heap note event. 2. Use note type as heap instrumentation parameter. Signed-off-by: xuxingliang <xuxingliang@xiaomi.com> Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
parent
8fecd0385b
commit
0663ac1483
|
@ -186,7 +186,7 @@ static void mm_delayfree(struct mm_heap_s *heap, void *mem, bool delay)
|
|||
int size = host_mallocsize(mem);
|
||||
atomic_fetch_sub(&heap->aordblks, 1);
|
||||
atomic_fetch_sub(&heap->uordblks, size);
|
||||
sched_note_heap(false, heap, mem, size);
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, mem, size);
|
||||
host_free(mem);
|
||||
}
|
||||
}
|
||||
|
@ -388,10 +388,10 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem,
|
|||
{
|
||||
if (oldmem != NULL)
|
||||
{
|
||||
sched_note_heap(false, heap, oldmem, oldsize);
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize);
|
||||
}
|
||||
|
||||
sched_note_heap(true, heap, mem, newsize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, mem, newsize);
|
||||
}
|
||||
|
||||
do
|
||||
|
@ -483,7 +483,7 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size)
|
|||
}
|
||||
|
||||
size = host_mallocsize(mem);
|
||||
sched_note_heap(true, heap, mem, size);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, mem, size);
|
||||
atomic_fetch_add(&heap->aordblks, 1);
|
||||
atomic_fetch_add(&heap->uordblks, size);
|
||||
usmblks = atomic_load(&heap->usmblks);
|
||||
|
|
|
@ -1355,7 +1355,8 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_HEAP
|
||||
void sched_note_heap(bool alloc, FAR void *heap, FAR void *mem, size_t size)
|
||||
void sched_note_heap(uint8_t event, FAR void *heap, FAR void *mem,
|
||||
size_t size)
|
||||
{
|
||||
FAR struct note_driver_s **driver;
|
||||
struct note_heap_s note;
|
||||
|
@ -1371,7 +1372,7 @@ void sched_note_heap(bool alloc, FAR void *heap, FAR void *mem, size_t size)
|
|||
|
||||
for (driver = g_note_drivers; *driver; driver++)
|
||||
{
|
||||
if (note_heap(*driver, alloc, heap, mem, size))
|
||||
if (note_heap(*driver, event, heap, mem, size))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -1383,9 +1384,8 @@ void sched_note_heap(bool alloc, FAR void *heap, FAR void *mem, size_t size)
|
|||
|
||||
if (!formatted)
|
||||
{
|
||||
enum note_type_e type = alloc ? NOTE_ALLOC : NOTE_FREE;
|
||||
formatted = true;
|
||||
note_common(tcb, ¬e.nmm_cmn, sizeof(note), type);
|
||||
note_common(tcb, ¬e.nmm_cmn, sizeof(note), event);
|
||||
note.heap = heap;
|
||||
note.mem = mem;
|
||||
note.size = size;
|
||||
|
|
|
@ -1086,8 +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_ALLOC:
|
||||
case NOTE_FREE:
|
||||
case NOTE_HEAP_ALLOC:
|
||||
case NOTE_HEAP_FREE:
|
||||
{
|
||||
FAR struct note_heap_s *nmm = (FAR struct note_heap_s *)p;
|
||||
FAR struct noteram_dump_task_context_s *tctx;
|
||||
|
@ -1100,7 +1100,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
|
|||
tctx = noteram_dump_find_task_context(ctx, pid);
|
||||
if (tctx != NULL)
|
||||
{
|
||||
tctx->mm_used += note->nc_type == NOTE_FREE ?
|
||||
tctx->mm_used += note->nc_type == NOTE_HEAP_FREE ?
|
||||
-nmm->size : nmm->size;
|
||||
used = tctx->mm_used;
|
||||
}
|
||||
|
@ -1108,7 +1108,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
|
|||
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_ALLOC],
|
||||
pid, used, name[note->nc_type - NOTE_HEAP_ALLOC],
|
||||
nmm->heap, nmm->size, nmm->mem);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -92,7 +92,7 @@ struct note_driver_ops_s
|
|||
FAR void *handler, bool enter);
|
||||
#endif
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_HEAP
|
||||
CODE void (*heap)(FAR struct note_driver_s *drv, bool alloc,
|
||||
CODE void (*heap)(FAR struct note_driver_s *drv, uint8_t event,
|
||||
FAR void *heap, FAR void *mem, size_t size);
|
||||
#endif
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
||||
|
|
|
@ -188,9 +188,8 @@ enum note_type_e
|
|||
NOTE_SYSCALL_LEAVE,
|
||||
NOTE_IRQ_ENTER,
|
||||
NOTE_IRQ_LEAVE,
|
||||
NOTE_ALLOC,
|
||||
NOTE_FREE,
|
||||
NOTE_REALLOC,
|
||||
NOTE_HEAP_ALLOC,
|
||||
NOTE_HEAP_FREE,
|
||||
NOTE_DUMP_STRING,
|
||||
NOTE_DUMP_BINARY,
|
||||
NOTE_DUMP_BEGIN,
|
||||
|
@ -385,6 +384,14 @@ struct note_irqhandler_s
|
|||
uint8_t nih_irq; /* IRQ number */
|
||||
};
|
||||
|
||||
struct note_heap_s
|
||||
{
|
||||
struct note_common_s nmm_cmn; /* Common note parameters */
|
||||
FAR void *heap;
|
||||
FAR void *mem;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct note_string_s
|
||||
{
|
||||
struct note_common_s nst_cmn; /* Common note parameters */
|
||||
|
@ -405,14 +412,6 @@ struct note_binary_s
|
|||
#define SIZEOF_NOTE_BINARY(n) (sizeof(struct note_binary_s) + \
|
||||
((n) - 1) * sizeof(uint8_t))
|
||||
|
||||
struct note_heap_s
|
||||
{
|
||||
struct note_common_s nmm_cmn; /* Common note parameters */
|
||||
FAR void *heap;
|
||||
FAR void *mem;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct note_counter_s
|
||||
{
|
||||
long int value;
|
||||
|
@ -556,9 +555,10 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter);
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_HEAP
|
||||
void sched_note_heap(bool alloc, FAR void *heap, FAR void *mem, size_t size);
|
||||
void sched_note_heap(uint8_t event, FAR void *heap, FAR void *mem,
|
||||
size_t size);
|
||||
#else
|
||||
# define sched_note_heap(a,h,m,s)
|
||||
# define sched_note_heap(e,h,m,s)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
||||
|
|
|
@ -128,7 +128,7 @@ void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay)
|
|||
/* Update heap statistics */
|
||||
|
||||
heap->mm_curused -= nodesize;
|
||||
sched_note_heap(false, heap, mem, nodesize);
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, mem, nodesize);
|
||||
|
||||
/* Check if the following node is free and, if so, merge it */
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||
{
|
||||
MM_ADD_BACKTRACE(heap, node);
|
||||
ret = kasan_unpoison(ret, nodesize - MM_ALLOCNODE_OVERHEAD);
|
||||
sched_note_heap(true, heap, ret, nodesize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize);
|
||||
#ifdef CONFIG_MM_FILL_ALLOCATIONS
|
||||
memset(ret, MM_ALLOC_MAGIC, alignsize - MM_ALLOCNODE_OVERHEAD);
|
||||
#endif
|
||||
|
|
|
@ -281,7 +281,8 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||
|
||||
alignedchunk = (uintptr_t)kasan_unpoison((FAR const void *)alignedchunk,
|
||||
size - MM_ALLOCNODE_OVERHEAD);
|
||||
sched_note_heap(true, heap, (FAR void *)alignedchunk, size);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, (FAR void *)alignedchunk, size);
|
||||
|
||||
DEBUGASSERT(alignedchunk % alignment == 0);
|
||||
return (FAR void *)alignedchunk;
|
||||
}
|
||||
|
|
|
@ -383,8 +383,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
heap->mm_maxused = heap->mm_curused;
|
||||
}
|
||||
|
||||
sched_note_heap(false, heap, oldmem, oldsize);
|
||||
sched_note_heap(true, heap, newmem, newsize);
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, newmem, newsize);
|
||||
mm_unlock(heap);
|
||||
MM_ADD_BACKTRACE(heap, (FAR char *)newmem - MM_SIZEOF_ALLOCNODE);
|
||||
|
||||
|
|
|
@ -510,8 +510,8 @@ static void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem,
|
|||
{
|
||||
/* Update heap statistics */
|
||||
|
||||
heap->mm_curused -= mm_malloc_size(heap, mem);
|
||||
sched_note_heap(false, heap, mem, size);
|
||||
heap->mm_curused -= size;
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, mem, size);
|
||||
tlsf_free(heap->mm_tlsf, mem);
|
||||
}
|
||||
|
||||
|
@ -1189,7 +1189,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||
#endif
|
||||
|
||||
ret = kasan_unpoison(ret, nodesize);
|
||||
sched_note_heap(true, heap, ret, nodesize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize);
|
||||
|
||||
#ifdef CONFIG_MM_FILL_ALLOCATIONS
|
||||
memset(ret, 0xaa, nodesize);
|
||||
|
@ -1269,7 +1269,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||
memdump_backtrace(heap, buf);
|
||||
#endif
|
||||
ret = kasan_unpoison(ret, nodesize);
|
||||
sched_note_heap(true, heap, ret, nodesize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize);
|
||||
}
|
||||
|
||||
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
|
||||
|
@ -1397,8 +1397,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
memdump_backtrace(heap, buf);
|
||||
#endif
|
||||
|
||||
sched_note_heap(false, heap, oldmem, oldsize);
|
||||
sched_note_heap(true, heap, newmem, newsize);
|
||||
sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize);
|
||||
sched_note_heap(NOTE_HEAP_ALLOC, heap, newmem, newsize);
|
||||
}
|
||||
|
||||
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
|
||||
|
|
|
@ -1290,7 +1290,7 @@ config SCHED_INSTRUMENTATION_HEAP
|
|||
---help---
|
||||
Enables additional hooks for heap allocation.
|
||||
|
||||
void sched_note_heap(bool alloc, FAR void* heap, FAR void *mem, size_t size)
|
||||
void sched_note_heap(uint8_t event, FAR void* heap, FAR void *mem, size_t size);
|
||||
|
||||
config SCHED_INSTRUMENTATION_DUMP
|
||||
bool "Use note dump for instrumentation"
|
||||
|
|
Loading…
Reference in New Issue