diff options
-rw-r--r-- | common/Kconfig | 4 | ||||
-rw-r--r-- | common/cmd_misc.c | 31 | ||||
-rw-r--r-- | common/dlmalloc.c | 58 |
3 files changed, 86 insertions, 7 deletions
diff --git a/common/Kconfig b/common/Kconfig index 2735602262..f7ded5cb33 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -159,6 +159,10 @@ config CMD_LOADS bool prompt "loads" +config CMD_MALLOCINFO + bool + prompt "mallocinfo" + config CMD_SAVES bool depends on CMD_LOADS diff --git a/common/cmd_misc.c b/common/cmd_misc.c index e6c6a6e415..f810594f8e 100644 --- a/common/cmd_misc.c +++ b/common/cmd_misc.c @@ -28,6 +28,7 @@ #include <command.h> #include <clock.h> +#ifdef CONFIG_CMD_SLEEP int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { uint64_t start; @@ -46,6 +47,30 @@ int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } +U_BOOT_CMD( + sleep , 2, 2, do_sleep, + "sleep - delay execution for some time\n", + "N\n" + " - delay execution for N seconds (N is _decimal_ !!!)\n" +); +#endif + +#ifdef CONFIG_CMD_MALLOCINFO +int do_mallocinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + malloc_stats(); + + return 0; +} + +U_BOOT_CMD( + mallocinfo , 1, 2, do_mallocinfo, + "mallocinfo - print info about malloc usage\n", + "N\n" + " - print info about malloc usage\n" +); +#endif + /* Implemented in $(CPU)/interrupts.c */ #if (CONFIG_COMMANDS & CFG_CMD_IRQ) int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); @@ -57,9 +82,3 @@ U_BOOT_CMD( ); #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */ -U_BOOT_CMD( - sleep , 2, 2, do_sleep, - "sleep - delay execution for some time\n", - "N\n" - " - delay execution for N seconds (N is _decimal_ !!!)\n" -); diff --git a/common/dlmalloc.c b/common/dlmalloc.c index d65e6dbe82..22ef06d776 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1,7 +1,8 @@ #include <malloc.h> -#include <common.h> +#include <config.h> +#include <stdio.h> /* Emulation of sbrk for WIN32 @@ -1932,6 +1933,46 @@ size_t malloc_usable_size(mem) Void_t* mem; /* Utility to update current_mallinfo for malloc_stats and mallinfo() */ +#ifdef CONFIG_CMD_MALLOCINFO +static void malloc_update_mallinfo() +{ + int i; + mbinptr b; + mchunkptr p; +#if DEBUG + mchunkptr q; +#endif + + INTERNAL_SIZE_T avail = chunksize(top); + int navail = ((long)(avail) >= (long)MINSIZE)? 1 : 0; + + for (i = 1; i < NAV; ++i) + { + b = bin_at(i); + for (p = last(b); p != b; p = p->bk) + { +#if DEBUG + check_free_chunk(p); + for (q = next_chunk(p); + q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; + q = next_chunk(q)) + check_inuse_chunk(q); +#endif + avail += chunksize(p); + navail++; + } + } + + current_mallinfo.ordblks = navail; + current_mallinfo.uordblks = sbrked_mem - avail; + current_mallinfo.fordblks = avail; +#if HAVE_MMAP + current_mallinfo.hblks = n_mmaps; +#endif + current_mallinfo.hblkhd = mmapped_mem; + current_mallinfo.keepcost = chunksize(top); + +} @@ -1955,7 +1996,22 @@ size_t malloc_usable_size(mem) Void_t* mem; mallinfo returns a copy of updated current mallinfo. */ +void malloc_stats() +{ + malloc_update_mallinfo(); + printf("max system bytes = %10u\n", + (unsigned int)(max_total_mem)); + printf("system bytes = %10u\n", + (unsigned int)(sbrked_mem + mmapped_mem)); + printf("in use bytes = %10u\n", + (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); +#if HAVE_MMAP + fprintf(stderr, "max mmap regions = %10u\n", + (unsigned int)max_n_mmaps); +#endif +} +#endif /* CONFIG_CMD_MALLOCINFO */ |