Skip to content

perf tools: Remaining bits of data type profiling (v6)

Namhyung Kim linux-perf-users linux-toolchains linux-trace-devel lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest14 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14perf dwarf-aux: Add die_collect_vars()tools/perf/util/dwarf-aux.c tools/perf/util/dwarf-aux.h+107 -280 replies
2/14perf dwarf-aux: Handle type transfer for memory accesstools/perf/util/dwarf-aux.c tools/perf/util/dwarf-aux.h+116 -00 replies
3/14perf annotate-data: Introduce struct data_loc_infotools/perf/util/annotate-data.c tools/perf/util/annotate-data.h tools/perf/util/annotate.c+91 -600 replies
4/14perf map: Add map__objdump_2rip()tools/perf/util/map.c tools/perf/util/map.h+20 -00 replies
5/14perf annotate: Add annotate_get_basic_blocks()tools/perf/util/annotate.c tools/perf/util/annotate.h+235 -30 replies
6/14perf annotate-data: Maintain variable type infotools/perf/util/annotate-data.c tools/perf/util/annotate-data.h tools/perf/util/dwarf-aux.c+188 -00 replies
7/14perf annotate-data: Add update_insn_state()tools/perf/util/annotate-data.c tools/perf/util/annotate-data.h tools/perf/util/annotate.c+140 -20 replies
8/14perf annotate-data: Handle global variable accesstools/perf/util/annotate-data.c tools/perf/util/annotate-data.h tools/perf/util/annotate.c +1 more+83 -220 replies
9/14perf annotate-data: Handle call instructionstools/perf/util/annotate-data.c+43 -20 replies
10/14perf annotate-data: Implement instruction trackingtools/perf/util/annotate-data.c+232 -00 replies
11/14perf annotate: Parse x86 segment register locationtools/perf/util/annotate.c tools/perf/util/annotate.h+32 -20 replies
12/14perf annotate-data: Handle this-cpu variables in kerneltools/perf/util/annotate.c tools/perf/util/annotate.h+35 -00 replies
13/14perf annotate-data: Track instructions with a this-cpu variabletools/perf/util/annotate-data.c+60 -240 replies
14/14perf annotate-data: Add stack canary typetools/perf/util/annotate-data.h tools/perf/util/annotate.c+25 -00 replies

Reviews trailers per patch

2 of 14 patches have a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/14A-b
2/14A-b
3/14
4/14
5/14
6/14
7/14
8/14
9/14
10/14
11/14
12/14
13/14
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCHSET 00/14] perf tools: Remaining bits of data type profiling (v6)

Hello,

This is the last part of the data type profiling series.
So far we added the basic pointer variable support, and direct access to global/local variables. Now it's time to add instruction tracking. :)

For the history and background, you can refer to the previous version
[1] and the LWN article [2].

* Changes from v5
- rename register state from scratch to caller_saved
- change comment in map__objdump_2rip()

Basically it needs to track variable (and its type) assignment to get a type of memory access at the sampled instruction. Compilers don't generate DWARF information for every memory accesses so it cannot find all the necessary information from DWARF. Therefore, it follows the path to the sample in the function, and update type information at each location when the instruction moves it.

For the DWARF search, it has a list of scope entries (subroutines or blocks) that covers the sample already. So it can use the scopes to find the shortest path to the sample instruction.

Let's say we have this. It got 5 scopes but couldn't find a matching variable for the sample.

      +----------------  scope[0] subprogram
      |
      | +--------------  scope[1] lexical_block
      | |
      | | +------------  scope[2] inlined_subroutine
      | | |
      | | | +----------  scope[3] inlined_subroutine
      | | | |
      | | | | +--------  scope[4] lexical_block
      | | | | |
      | | | | |     ***  target instruction
      ...

Then it starts with the closest scope (at index 4), and find the shortest path from the start of the scope to the target instruction. Along the way, it updates type information in the scope and see if the location at the target instruction has the type. If so, it can return with the type.

Otherwise, it goes to the scope[3] and find the shortest path from the start of scope[3] to the start of scope[4]. And then it can combine the existing shortest path from the scope[4] to the target with the new path. Now it can start from the scope[3] with new variables and types. It can repeat this algorithm for the outer scopes.

I did it this way because mostly it was able to find a type in the closest scope. So it can avoid unnecessary work for outer scopes.

And it added a basic per-cpu variable support for this CPU on x86_64 which uses %gs segment register. Also it can detect the stack-canary pattern which is added by compiler to detect stack overflow.

The code is available at 'perf/data-profile-v6' branch in the tree below. I've dropped the debug patch at the end in this series but you can find it in the git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung

Cc Ben Woodard <[email protected]>
Cc Joe Mario <[email protected]>
CC Kees Cook <[email protected]>
Cc David Blaikie <[email protected]>
Cc Xu Liu <[email protected]>
Cc Kan Liang <[email protected]>
Cc Ravi Bangoria <[email protected]>
Cc Mark Wielaard <[email protected]>
Cc Jason Merrill <[email protected]>
Cc Jose E. Marchesi <[email protected]>
Cc William Huang <[email protected]>

[1] https://lore.kernel.org/linux-perf-users/[email protected]/
[2] https://lwn.net/Articles/955709/

Namhyung Kim (14):
perf dwarf-aux: Add die_collect_vars()
perf dwarf-aux: Handle type transfer for memory access perf annotate-data: Introduce struct data_loc_info perf map: Add map__objdump_2rip()
perf annotate: Add annotate_get_basic_blocks()
perf annotate-data: Maintain variable type info
perf annotate-data: Add update_insn_state()
perf annotate-data: Handle global variable access perf annotate-data: Handle call instructions
perf annotate-data: Implement instruction tracking perf annotate: Parse x86 segment register location perf annotate-data: Handle this-cpu variables in kernel perf annotate-data: Track instructions with a this-cpu variable perf annotate-data: Add stack canary type

 tools/perf/util/annotate-data.c | 710 ++++++++++++++++++++++++++++++--
 tools/perf/util/annotate-data.h |  87 +++-
 tools/perf/util/annotate.c      | 366 ++++++++++++++--
 tools/perf/util/annotate.h      |  38 ++
 tools/perf/util/dwarf-aux.c     | 232 +++++++++--
 tools/perf/util/dwarf-aux.h     |  23 ++
 tools/perf/util/map.c           |  17 +
 tools/perf/util/map.h           |   3 +
 8 files changed, 1370 insertions(+), 106 deletions(-)
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog