perf tools: Fixup end address of modules
Namhyung Kim
maintainerPATCH 1/1 perf tools: Fixup end address of modules
In machine__create_module(), it reads /proc/modules to get a list of modules in the system. The file shows the start address (of text) and the size of the module so it uses the info to reconstruct system memory maps for symbol resolution.
But module memory consists of multiple segments and they can be scaterred. Currently perf tools assume they are contiguous and see some overlaps. This can confuse the tool when it finds a map containing a given address.
As we mostly care about the function symbols in the text segment, it can fixup the size or end address of modules when there's an overlap. We can use maps__fixup_end() which updates the end address using the start address of the next map.
Ideally it should be able to track other segments (like data/rodata), but that would require some changes in /proc/modules IMHO.
--- tools/perf/util/machine.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/machine.c +2 -0
@@ -1468,6 +1468,8 @@ static int machine__create_modules(struct machine *machine)if (modules__parse (modules, machine, machine__create_module))return -1 ; +maps__fixup_end (machine__kernel_maps (machine)); +if (!machine__set_modules_path (machine))return 0 ;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Quoted 8 lines · Namhyung Kim
In
machine__create_module(), it reads/proc/modulesto get a list of modules in the system. The file shows the start address (of text) and the size of the module so it uses the info to reconstruct system memory maps for symbol resolution.But module memory consists of multiple segments and they can be scaterred. Currently perf tools assume they are contiguous and see some
nit: s/scaterred/scattered/
Quoted 11 lines
overlaps. This can confuse the tool when it finds a map containing a given address.
As we mostly care about the function symbols in the text segment, it can fixup the size or end address of modules when there's an overlap. We can use
maps__fixup_end()which updates the end address using the start address of the next map.Ideally it should be able to track other segments (like data/rodata), but that would require some changes in
/proc/modulesIMHO.
Quoted 7 lines
Reported-by Blake Jones <[email protected]>Cc Luis Chamberlain <[email protected]>Cc Petr Pavlu <[email protected]>Cc Sami Tolvanen <[email protected]>Cc Daniel Gomez <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Thanks,
Ian
Quoted 20 lines
--- tools/perf/util/machine.c | 2 ++ 1 file changed, 2 insertions(+)tools/perf/util/machine.c +2
-1@@ -1468,6 +1468,8 @@ static int machine__create_modules(struct machine *machine)if (modules__parse (modules, machine, machine__create_module))return -1 ; +maps__fixup_end (machine__kernel_maps (machine)); +if (!machine__set_modules_path (machine))return 0 ; --2.47.1.613.gc27f4b7a9f-goog
Quoted 31 lines · Ian Rogers
Quoted 8 lines · Namhyung Kim
In
machine__create_module(), it reads/proc/modulesto get a list of modules in the system. The file shows the start address (of text) and the size of the module so it uses the info to reconstruct system memory maps for symbol resolution.But module memory consists of multiple segments and they can be scaterred. Currently perf tools assume they are contiguous and see some
nit: s/scaterred/scattered/
Quoted 11 lines
overlaps. This can confuse the tool when it finds a map containing a given address.
As we mostly care about the function symbols in the text segment, it can fixup the size or end address of modules when there's an overlap. We can use
maps__fixup_end()which updates the end address using the start address of the next map.Ideally it should be able to track other segments (like data/rodata), but that would require some changes in
/proc/modulesIMHO.Quoted 7 lines
Reported-by Blake Jones <[email protected]>Cc Luis Chamberlain <[email protected]>Cc Petr Pavlu <[email protected]>Cc Sami Tolvanen <[email protected]>Cc Daniel Gomez <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Quoted 1 line
Acked-by Ian Rogers <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo