diff mbox series

[U-Boot] spl: add debug print for early malloc usage

Message ID 20190226212752.1373-1-simon.k.r.goldschmidt@gmail.com
State Accepted
Commit 438dcabb75d6b9b0e7f887befb753d1863f14deb
Delegated to: Tom Rini
Headers show
Series [U-Boot] spl: add debug print for early malloc usage | expand

Commit Message

Simon Goldschmidt Feb. 26, 2019, 9:27 p.m. UTC
To find out how big the early malloc heap must be in SPL, add a debug
print statement that dumps its usage before switching to relocated heap
in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

 common/spl/spl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Tom Rini Feb. 28, 2019, 11:56 p.m. UTC | #1
On Tue, Feb 26, 2019 at 10:27:52PM +0100, Simon Goldschmidt wrote:

> To find out how big the early malloc heap must be in SPL, add a debug
> print statement that dumps its usage before switching to relocated heap
> in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.
> 
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

Applied to u-boot/master, thanks!
Marek Vasut March 1, 2019, 10:30 a.m. UTC | #2
On 2/26/19 10:27 PM, Simon Goldschmidt wrote:
> To find out how big the early malloc heap must be in SPL, add a debug
> print statement that dumps its usage before switching to relocated heap
> in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.
> 
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> ---
> 
>  common/spl/spl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 2e2af1b28e..88d4b8a9bf 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -728,6 +728,8 @@ ulong spl_relocate_stack_gd(void)
>  
>  #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
>  	if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
> +		debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
> +		      gd->malloc_ptr, gd->malloc_ptr / 1024);

Shouldn't this use %p ?

>  		ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
>  		gd->malloc_base = ptr;
>  		gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
>
Simon Goldschmidt March 1, 2019, 10:37 a.m. UTC | #3
On Fri, Mar 1, 2019 at 11:30 AM Marek Vasut <marex@denx.de> wrote:
>
> On 2/26/19 10:27 PM, Simon Goldschmidt wrote:
> > To find out how big the early malloc heap must be in SPL, add a debug
> > print statement that dumps its usage before switching to relocated heap
> > in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.
> >
> > Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> > ---
> >
> >  common/spl/spl.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/common/spl/spl.c b/common/spl/spl.c
> > index 2e2af1b28e..88d4b8a9bf 100644
> > --- a/common/spl/spl.c
> > +++ b/common/spl/spl.c
> > @@ -728,6 +728,8 @@ ulong spl_relocate_stack_gd(void)
> >
> >  #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
> >       if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
> > +             debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
> > +                   gd->malloc_ptr, gd->malloc_ptr / 1024);
>
> Shouldn't this use %p ?

Despite its name, 'gd->malloc_ptr' is of type 'unsigned long', so I
think this is
correct. After all, I only copied the code from other places where the heap
usage is dumped, too.

Regards,
Simon

>
> >               ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
> >               gd->malloc_base = ptr;
> >               gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
> >
>
>
> --
> Best regards,
> Marek Vasut
Marek Vasut March 1, 2019, 10:45 a.m. UTC | #4
On 3/1/19 11:37 AM, Simon Goldschmidt wrote:
> On Fri, Mar 1, 2019 at 11:30 AM Marek Vasut <marex@denx.de> wrote:
>>
>> On 2/26/19 10:27 PM, Simon Goldschmidt wrote:
>>> To find out how big the early malloc heap must be in SPL, add a debug
>>> print statement that dumps its usage before switching to relocated heap
>>> in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.
>>>
>>> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
>>> ---
>>>
>>>  common/spl/spl.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/common/spl/spl.c b/common/spl/spl.c
>>> index 2e2af1b28e..88d4b8a9bf 100644
>>> --- a/common/spl/spl.c
>>> +++ b/common/spl/spl.c
>>> @@ -728,6 +728,8 @@ ulong spl_relocate_stack_gd(void)
>>>
>>>  #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
>>>       if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
>>> +             debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
>>> +                   gd->malloc_ptr, gd->malloc_ptr / 1024);
>>
>> Shouldn't this use %p ?
> 
> Despite its name, 'gd->malloc_ptr' is of type 'unsigned long', so I
> think this is
> correct. After all, I only copied the code from other places where the heap
> usage is dumped, too.

Isn't that broken on some arm64 systems then ? :)
Simon Goldschmidt March 1, 2019, 10:50 a.m. UTC | #5
On Fri, Mar 1, 2019 at 11:45 AM Marek Vasut <marex@denx.de> wrote:
>
> On 3/1/19 11:37 AM, Simon Goldschmidt wrote:
> > On Fri, Mar 1, 2019 at 11:30 AM Marek Vasut <marex@denx.de> wrote:
> >>
> >> On 2/26/19 10:27 PM, Simon Goldschmidt wrote:
> >>> To find out how big the early malloc heap must be in SPL, add a debug
> >>> print statement that dumps its usage before switching to relocated heap
> >>> in spl_relocate_stack_gd() via CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN.
> >>>
> >>> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> >>> ---
> >>>
> >>>  common/spl/spl.c | 2 ++
> >>>  1 file changed, 2 insertions(+)
> >>>
> >>> diff --git a/common/spl/spl.c b/common/spl/spl.c
> >>> index 2e2af1b28e..88d4b8a9bf 100644
> >>> --- a/common/spl/spl.c
> >>> +++ b/common/spl/spl.c
> >>> @@ -728,6 +728,8 @@ ulong spl_relocate_stack_gd(void)
> >>>
> >>>  #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
> >>>       if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
> >>> +             debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
> >>> +                   gd->malloc_ptr, gd->malloc_ptr / 1024);
> >>
> >> Shouldn't this use %p ?
> >
> > Despite its name, 'gd->malloc_ptr' is of type 'unsigned long', so I
> > think this is
> > correct. After all, I only copied the code from other places where the heap
> > usage is dumped, too.
>
> Isn't that broken on some arm64 systems then ? :)

I don't think it's broken for 'ptr' as that seems to be the offset into
the malloc pool.

Some 64-bit platforms migth have a problem with gd->malloc_base being
unsigned long though - I don't know the size of unsigned long on arm64.

Regards,
Simon
diff mbox series

Patch

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 2e2af1b28e..88d4b8a9bf 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -728,6 +728,8 @@  ulong spl_relocate_stack_gd(void)
 
 #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
 	if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
+		debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
+		      gd->malloc_ptr, gd->malloc_ptr / 1024);
 		ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
 		gd->malloc_base = ptr;
 		gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;