diff options
author | Wu Zhangjin <wuzhangjin@gmail.com> | 2009-11-20 07:34:32 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-12-16 20:57:23 -0500 |
commit | 538f19526e40ce7a5a296fad6a3121409c890adc (patch) | |
tree | bbdf5a55a08dafaf2497a241703e944563241ddc /scripts | |
parent | e6299d2677e600f6a0bf93bbb89f20d3de5252de (diff) |
MIPS: Tracing: Add dynamic function tracer support
With dynamic function tracer, by default, _mcount is defined as an
"empty" function, it returns directly without any more action . When
enabling it in user-space, it will jump to a real tracing
function(ftrace_caller), and do the real job for us.
Differ from the static function tracer, dynamic function tracer provides
two functions ftrace_make_call()/ftrace_make_nop() to enable/disable the
tracing of some indicated kernel functions(set_ftrace_filter).
In the -v4 version, the implementation of this support is basically the same as
X86 version does: _mcount is implemented as an empty function and ftrace_caller
is implemented as a real tracing function respectively.
But in this version, to support module tracing with the help of
-mlong-calls in arch/mips/Makefile:
MODFLAGS += -mlong-calls.
The stuff becomes a little more complex. We need to cope with two
different type of calling to _mcount.
For the kernel part, the calling to _mcount(result of "objdump -hdr
vmlinux"). is like this:
108: 03e0082d move at,ra
10c: 0c000000 jal 0 <fpcsr_pending>
10c: R_MIPS_26 _mcount
10c: R_MIPS_NONE *ABS*
10c: R_MIPS_NONE *ABS*
110: 00020021 nop
For the module with -mlong-calls, it looks like this:
c: 3c030000 lui v1,0x0
c: R_MIPS_HI16 _mcount
c: R_MIPS_NONE *ABS*
c: R_MIPS_NONE *ABS*
10: 64630000 daddiu v1,v1,0
10: R_MIPS_LO16 _mcount
10: R_MIPS_NONE *ABS*
10: R_MIPS_NONE *ABS*
14: 03e0082d move at,ra
18: 0060f809 jalr v1
In the kernel version, there is only one "_mcount" string for every
kernel function, so, we just need to match this one in mcount_regex of
scripts/recordmcount.pl, but in the module version, we need to choose
one of the two to match. Herein, I choose the first one with
"R_MIPS_HI16 _mcount".
and In the kernel verion, without module tracing support, we just need
to replace "jal _mcount" by "jal ftrace_caller" to do real tracing, and
filter the tracing of some kernel functions via replacing it by a nop
instruction.
but as we have described before, the instruction "jal ftrace_caller" only left
32bit length for the address of ftrace_caller, it will fail when calling from
the module space. so, herein, we must replace something else.
the basic idea is loading the address of ftrace_caller to v1 via changing these
two instructions:
lui v1,0x0
addiu v1,v1,0
If we want to enable the tracing, we need to replace the above instructions to:
lui v1, HI_16BIT_ftrace_caller
addiu v1, v1, LOW_16BIT_ftrace_caller
If we want to stop the tracing of the indicated kernel functions, we
just need to replace the "jalr v1" to a nop instruction. but we need to
replace two instructions and encode the above two instructions
oursevles.
Is there a simpler solution? Yes! Here it is, in this version, we put _mcount
and ftrace_caller together, which means the address of _mcount and
ftrace_caller is the same:
_mcount:
ftrace_caller:
j ftrace_stub
nop
...(do real tracing here)...
ftrace_stub:
jr ra
move ra, at
By default, the kernel functions call _mcount, and then jump to ftrace_stub and
return. and when we want to do real tracing, we just need to remove that "j
ftrace_stub", and it will run through the two "nop" instructions and then do
the real tracing job.
what about filtering job? we just need to do this:
lui v1, hi_16bit_of_mcount <--> b 1f (0x10000004)
addiu v1, v1, low_16bit_of_mcount
move at, ra
jalr v1
nop
1f: (rec->ip + 12)
In linux-mips64, there will be some local symbols, whose name are
prefixed by $L, which need to be filtered. thanks goes to Steven for
writing the mips64-specific function_regex.
In a conclusion, with RISC, things becomes easier with such a "stupid"
trick, RISC is something like K.I.S.S, and also, there are lots of
"simple" tricks in the whole ftrace support, thanks goes to Steven and
the other folks for providing such a wonderful tracing framework!
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Cc: Nicholas Mc Guire <der.herr@hofr.at>
Cc: zhangfx@lemote.com
Cc: Wu Zhangjin <wuzhangjin@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: http://patchwork.linux-mips.org/patch/675/
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/recordmcount.pl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl index ab368e8a007d..92f09fe9639e 100755 --- a/scripts/recordmcount.pl +++ b/scripts/recordmcount.pl | |||
@@ -295,6 +295,58 @@ if ($arch eq "x86_64") { | |||
295 | $ld .= " -m elf64_sparc"; | 295 | $ld .= " -m elf64_sparc"; |
296 | $cc .= " -m64"; | 296 | $cc .= " -m64"; |
297 | $objcopy .= " -O elf64-sparc"; | 297 | $objcopy .= " -O elf64-sparc"; |
298 | } elsif ($arch eq "mips") { | ||
299 | # To enable module support, we need to enable the -mlong-calls option | ||
300 | # of gcc for module, after using this option, we can not get the real | ||
301 | # offset of the calling to _mcount, but the offset of the lui | ||
302 | # instruction or the addiu one. herein, we record the address of the | ||
303 | # first one, and then we can replace this instruction by a branch | ||
304 | # instruction to jump over the profiling function to filter the | ||
305 | # indicated functions, or swith back to the lui instruction to trace | ||
306 | # them, which means dynamic tracing. | ||
307 | # | ||
308 | # c: 3c030000 lui v1,0x0 | ||
309 | # c: R_MIPS_HI16 _mcount | ||
310 | # c: R_MIPS_NONE *ABS* | ||
311 | # c: R_MIPS_NONE *ABS* | ||
312 | # 10: 64630000 daddiu v1,v1,0 | ||
313 | # 10: R_MIPS_LO16 _mcount | ||
314 | # 10: R_MIPS_NONE *ABS* | ||
315 | # 10: R_MIPS_NONE *ABS* | ||
316 | # 14: 03e0082d move at,ra | ||
317 | # 18: 0060f809 jalr v1 | ||
318 | # | ||
319 | # for the kernel: | ||
320 | # | ||
321 | # 10: 03e0082d move at,ra | ||
322 | # 14: 0c000000 jal 0 <loongson_halt> | ||
323 | # 14: R_MIPS_26 _mcount | ||
324 | # 14: R_MIPS_NONE *ABS* | ||
325 | # 14: R_MIPS_NONE *ABS* | ||
326 | # 18: 00020021 nop | ||
327 | if ($is_module eq "0") { | ||
328 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | ||
329 | } else { | ||
330 | $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$"; | ||
331 | } | ||
332 | $objdump .= " -Melf-trad".$endian."mips "; | ||
333 | |||
334 | if ($endian eq "big") { | ||
335 | $endian = " -EB "; | ||
336 | $ld .= " -melf".$bits."btsmip"; | ||
337 | } else { | ||
338 | $endian = " -EL "; | ||
339 | $ld .= " -melf".$bits."ltsmip"; | ||
340 | } | ||
341 | |||
342 | $cc .= " -mno-abicalls -fno-pic -mabi=" . $bits . $endian; | ||
343 | $ld .= $endian; | ||
344 | |||
345 | if ($bits == 64) { | ||
346 | $function_regex = | ||
347 | "^([0-9a-fA-F]+)\\s+<(.|[^\$]L.*?|\$[^L].*?|[^\$][^L].*?)>:"; | ||
348 | $type = ".dword"; | ||
349 | } | ||
298 | } elsif ($arch eq "microblaze") { | 350 | } elsif ($arch eq "microblaze") { |
299 | # Microblaze calls '_mcount' instead of plain 'mcount'. | 351 | # Microblaze calls '_mcount' instead of plain 'mcount'. |
300 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | 352 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; |