Skip to content

Memory cleanup - #1023

Merged
mmaka1 merged 1 commit into
thesofproject:masterfrom
abonislawski:memory_cleanup
Feb 28, 2019
Merged

mmaka1 merged 1 commit into
thesofproject:masterfrom
abonislawski:memory_cleanup

Conversation

@abonislawski

Copy link
Copy Markdown
Member

Memory cleanup.
One shared memory block SOF_FW for SOF_TEXT, SOF_DATA and SOF_BSS sections.
Moved fw_ready near to .rodata and .data
Used linker symbols to obtain real BSS size in alloc.h
Removed setting of .text_size for APL manifes

@mmaka1 mmaka1 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great first step towards compact fw memory footprint that would not require manual adjustments. However there are some sections still defined statically, i.e. heaps and stack.

This is the linker and rimage output for the default apl configuration (w/ dmic on):

        18      0xbe010400      0xbe02a156      105814  TEXT    .text
        20      0xbe02b000      0xbe040d1c      89372   DATA    .rodata
        21      0xbe040d40      0xbe043898      11096   DATA    .data
        22      0xbe043898      0xbe043904      108     DATA    .fw_ready
        23      0xbe044000      0xbe045108      4360    BSS     .bss
        33      0xbe051000      0xbe05e000      53248   HEAP    .system_heap
        34      0xbe05e000      0xbe064800      26624   HEAP    .system_runtime_heap
        35      0xbe064800      0xbe072800      57344   HEAP    .runtime_heap
        36      0xbe072800      0xbe07f000      51200   HEAP    .buffer_heap
        37      0xbe07f000      0xbe080000      4096    HEAP    .sof_stack
        38      0x20000000      0x2000e4bc      58556   NOTE    .static_log_entries

...

        Totals  Start           End             Size
        TEXT    0xbe010000      0xbe02a156      0x1a156
        DATA    0xbe02b000      0xbe043904      0x18904
        BSS     0xbe044000      0xbe045108      0x1108

And this is the output w/o dmic:

        18      0xbe010400      0xbe028486      98438   TEXT    .text
        20      0xbe029000      0xbe03d69c      83612   DATA    .rodata
        21      0xbe03d6c0      0xbe040058      10648   DATA    .data
        22      0xbe040058      0xbe0400c4      108     DATA    .fw_ready
        23      0xbe041000      0xbe0420f8      4344    BSS     .bss
        33      0xbe051000      0xbe05e000      53248   HEAP    .system_heap
...

As you can see, rodata+data and the bss is automatically adjusted while the system_heap stays @ 0xbe051000. Heaps are followed by the stack and location of the latter determines the SOF_MEMORY_SIZE which is used by the memory power management code in the cnl boot_loader.

So there are a couple of things to do in order to save on memory power in cnl/icl/...:

  1. Let the linker pack heaps and stacks into the large hpsram segment as well. This will require to use similar 'start' and 'end' linker variables for the heap initialization code as in case of the bss writeback on smp.
  2. Make sure the third segment (called bss) in the fw manifest includes heaps and stacks as well.
  3. Adjust the boot loader code to compute the set of memory banks powered based on the manifest content (see parse_module()) instead of using static SOF_MEMORY_SIZE. Note: easier way may be to add another linker variable at the end of the stack segment and use this one as the SOF_MEMORY_SIZE replacement. With the latter approach (2) is not required but still nice to have and could be done in the next iteration anyway to be able to determine actual sram occupation directly from the manifest.

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR, but please add more detail in the commit messages. I'd expect to see details why and what is being changed. Does SueCreek need this too ?

@abonislawski abonislawski changed the title Memory cleanup [WIP] Memory cleanup Feb 25, 2019
@abonislawski

abonislawski commented Feb 25, 2019 •

Copy link
Copy Markdown
Member Author

@mmaka1 thanks, very good ideas. I have extended commits with this. All 3 steps are done, latest one just not commited (need to make sure that the current changes are good enough and fix problems).
@lgirdwood I have extended commit messages as you requested, please check it.
About SueCreek @mmaka1 please share some details to @lgirdwood

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good, just have minor comments. My only outstanding larger change is that the CNL changes should be duplicated for SUE.

} >sof_fw :sof_fw_phdr

.rodata : ALIGN(4)
.rodata : ALIGN(4096)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind the section alignment to 4K (others also be aligned to 4k too) ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood The FW manifest assumes that its "segments" are aligned, so every section that begins that FW manifest "segment" (text/rodata/bss) is aligned. It is historically connected with the virtual mem address space management (via TLB).
Regarding SUE, yes this is a good idea that SUE follows the CNL approach. Once it is done and tested for CNL which is the first iteration goal, should be very easy to replicate by a SUE developer.

#define SOF_FW_START (HP_SRAM_VECBASE_RESET + 0x400)
#define SOF_FW_BASE (SOF_FW_START)
#define SOF_FW_SIZE (0x41000 - 0x400)
#define SOF_FW_SIZE (0x90000 - 0x400)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a macro for the 0x90000 ? I'm assuming it's maximum possible size for text ?? It would also be good to have macro for 0x400 offset too if you have time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a max size for all var-size sections (text/rodata/bss). All "fixed" size sections (stacks, heaps) are moved to the beginning of the mem space (right after mem windows and other fixed size elements) and followed by one large sof_fw_size area defined for linker so it packs everything var-size like .text, .rodata, .data, .bss into that one (with the alignment you noticed that is preserved for the fw manifest representation).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmaka1 ok, makes sense, but we need to call it something like SOF_FW_MAX_SIZE with a comment e.g.

/* max size for all var-size sections (text/rodata/bss) */
#define SOF_FW_MAX_SIZE 0x90000

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood yes, in the next update I will introduce new section for fixed-size things (heaps, stack) and this sof_fw will be for var-size sections. I will include proper comments like in your example.

@abonislawski
abonislawski force-pushed the memory_cleanup branch 3 times, most recently from 0505354 to 56ee9a3 Compare February 28, 2019 15:28
One shared memory block SOF_FW for SOF_TEXT, SOF_DATA and SOF_BSS sections.
Moved fw_ready near to .rodata and .data
Removed setting of .text_size for APL manifes
Updated rom.x.in (SOF_BSS_DATA_START is no longer in use)
Used linker symbols to obtain real BSS size in alloc.h

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@linux.intel.com>
@mmaka1 mmaka1 changed the title [WIP] Memory cleanup Memory cleanup Feb 28, 2019
@mmaka1

mmaka1 commented Feb 28, 2019

Copy link
Copy Markdown

Let's do the fixed part (heaps+stacks) move in the next iteration. This would require some changes to the memory initialization routine as the current use of stack by the boot loader is a bit unreliable (will be submitting a PR for that soon...). The buffer heap should be more dynamic in the next iter of implementation to make bigger difference on the power consumed (small one at the beginning, adjusted at run-time + mem pwr bank management on demand).

@mmaka1
mmaka1 merged commit 6cc7527 into thesofproject:master Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants