diff options
author | Namhyung Kim <namhyung@kernel.org> | 2024-03-18 22:51:09 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2024-03-21 10:41:29 -0300 |
commit | 02e17ca917423c622da10ac6bd0924c17462962e (patch) | |
tree | 0fc1b47c027f4bb792325434dcdea60087c4bd82 /tools/perf/util/annotate.c | |
parent | cbaf89a8c5b467f99dd930f24a698f3fa338b012 (diff) | |
download | linux-02e17ca917423c622da10ac6bd0924c17462962e.tar.gz linux-02e17ca917423c622da10ac6bd0924c17462962e.tar.bz2 linux-02e17ca917423c622da10ac6bd0924c17462962e.zip |
perf annotate-data: Handle this-cpu variables in kernel
On x86, the kernel gets the current task using the current macro like
below:
#define current get_current()
static __always_inline struct task_struct *get_current(void)
{
return this_cpu_read_stable(pcpu_hot.current_task);
}
So it returns the current_task field of struct pcpu_hot which is the
first member. On my build, it's located at 0x32940.
$ nm vmlinux | grep pcpu_hot
0000000000032940 D pcpu_hot
And the current macro generates the instructions like below:
mov %gs:0x32940, %rcx
So the %gs segment register points to the beginning of the per-cpu
region of this cpu and it points the variable with a constant.
Let's update the instruction location info to have a segment register
and handle %gs in kernel to look up a global variable. Pretend it as
a global variable by changing the register number to DWARF_REG_PC.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240319055115.4063940-18-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r-- | tools/perf/util/annotate.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3aa3a3b987ad..e4121acb4f88 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -3921,6 +3921,13 @@ retry: op_loc->offset, dl); } + /* This CPU access in kernel - pretend PC-relative addressing */ + if (map__dso(ms->map)->kernel && arch__is(arch, "x86") && + op_loc->segment == INSN_SEG_X86_GS && op_loc->imm) { + dloc.var_addr = op_loc->offset; + op_loc->reg1 = DWARF_REG_PC; + } + mem_type = find_data_type(&dloc); if (mem_type) istat->good++; |