Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can GNU LD print memory usage by memory space, rather then just as a bulk percentage?

Tags:

c

memory

linker

ld

I'm working on an embedded project on an ARM mcu that has a custom linker file with several different memory spaces:

/* Memory Spaces Definitions */
MEMORY
{
  rom      (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00200000
  data_tcm (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00008000
  prog_tcm (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00008000
  ram      (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00050000
  sdram    (rw)  : ORIGIN = 0x70000000, LENGTH = 0x00200000
}

Specifically, I have a number of different memory devices with different characteristics (TCM, plain RAM (with a D-Cache in the way), and an external SDRAM), all mapped as part of the same address space.

I'm specifically placing different variables in the different memory spaces, depending on the requirements (am I DMA'ing into it, do I have cache-coherence issues, do I expect to overflow the D-cache, etc...).

If I exceed any one of the sections, I get a linker error. However, unless I do so, the linker only prints the memory usage as bulk percentage:

            Program Memory Usage    :   33608 bytes   1.6 % Full
            Data Memory Usage       :   2267792 bytes   91.1 % Full

Given that I have 3 actively used memory spaces, and I know for a fact that I'm using 100% of one of them (the SDRAM), it's kind of a useless output.

Is there any way to make the linker output the percentage of use for each memory space individually? Right now, I have to manually open the .map file, search for the section header, and then manually subtract the size from the total available memory specified in the .ld file.

While this is kind of a minor thing, it'd sure be nice to just have the linker do:

Program Memory Usage    :   33608 bytes   1.6 % Full
Data Memory Usage       :   2267792 bytes   91.1 % Full
    data_dtcm           :   xxx bytes   xx % Full
    ram                 :   xxx bytes   xx % Full
    sdram               :   xxx bytes   xx % Full

This is with GCC-ARM, and therefore GCC-LD.

like image 662
Fake Name Avatar asked Dec 30 '16 01:12

Fake Name


People also ask

How do I check memory usage on PID?

The ps command can also be used to monitor memory usage of individual processes. The ps v PID command provides the most comprehensive report on memory-related statistics for an individual process, such as: Page faults. Size of working segment that has been touched.


1 Answers

Arrrgh, so of course, I find the answer right after asking the question:

--print-memory-usage

Used as -Wl,--print-memory-usage, you get the following:

    Memory region         Used Size  Region Size  %age Used
                 rom:       31284 B         2 MB      1.49%
            data_tcm:       26224 B        32 KB     80.03%
            prog_tcm:          0 GB        32 KB      0.00%
                 ram:      146744 B       320 KB     44.78%
               sdram:          2 MB         2 MB    100.00%
like image 194
Fake Name Avatar answered Oct 07 '22 01:10

Fake Name