• Adrian Hunter's avatar
    perf intel-pt: Add support for text poke events · b22f90aa
    Adrian Hunter authored
    Select text poke events when available and the kernel is being traced.
    Process text poke events to invalidate entries in Intel PT's instruction
    cache.
    
    Example:
    
      The example requires kernel config:
        CONFIG_PROC_SYSCTL=y
        CONFIG_SCHED_DEBUG=y
        CONFIG_SCHEDSTATS=y
    
      Before:
    
        # perf record -o perf.data.before --kcore -a -e intel_pt//k -m,64M &
        # cat /proc/sys/kernel/sched_schedstats
        0
        # echo 1 > /proc/sys/kernel/sched_schedstats
        # cat /proc/sys/kernel/sched_schedstats
        1
        # echo 0 > /proc/sys/kernel/sched_schedstats
        # cat /proc/sys/kernel/sched_schedstats
        0
        # kill %1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 3.341 MB perf.data.before ]
        [1]+  Terminated                 perf record -o perf.data.before --kcore -a -e intel_pt//k -m,64M
        # perf script -i perf.data.before --itrace=e >/dev/null
        Warning:
        474 instruction trace errors
    
      After:
    
        # perf record -o perf.data.after --kcore -a -e intel_pt//k -m,64M &
        # cat /proc/sys/kernel/sched_schedstats
        0
        # echo 1 > /proc/sys/kernel/sched_schedstats
        # cat /proc/sys/kernel/sched_schedstats
        1
        # echo 0 > /proc/sys/kernel/sched_schedstats
        # cat /proc/sys/kernel/sched_schedstats
        0
        # kill %1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 2.646 MB perf.data.after ]
        [1]+  Terminated                 perf record -o perf.data.after --kcore -a -e intel_pt//k -m,64M
        # perf script -i perf.data.after --itrace=e >/dev/null
    
    Example:
    
      The example requires kernel config:
        # CONFIG_FUNCTION_TRACER is not set
    
      Before:
        # perf record --kcore -m,64M -o t1 -a -e intel_pt//k &
        # perf probe __schedule
        Added new event:
          probe:__schedule     (on __schedule)
    
        You can now use it in all perf tools, such as:
    
                perf record -e probe:__schedule -aR sleep 1
    
        # perf record -e probe:__schedule -aR sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.026 MB perf.data (68 samples) ]
        # perf probe -d probe:__schedule
        Removed event: probe:__schedule
        # kill %1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 41.268 MB t1 ]
        [1]+  Terminated                 perf record --kcore -m,64M -o t1 -a -e intel_pt//k
        # perf script -i t1 --itrace=e >/dev/null
        Warning:
        207 instruction trace errors
    
      After:
        # perf record --kcore -m,64M -o t1 -a -e intel_pt//k &
        # perf probe __schedule
        Added new event:
          probe:__schedule     (on __schedule)
    
        You can now use it in all perf tools, such as:
    
            perf record -e probe:__schedule -aR sleep 1
    
        # perf record -e probe:__schedule -aR sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.028 MB perf.data (107 samples) ]
        # perf probe -d probe:__schedule
        Removed event: probe:__schedule
        # kill %1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 39.978 MB t1 ]
        [1]+  Terminated                 perf record --kcore -m,64M -o t1 -a -e intel_pt//k
        # perf script -i t1 --itrace=e >/dev/null
        # perf script -i t1 --no-itrace -D | grep 'POKE\|KSYMBOL'
        6 565303693547 0x291f18 [0x50]: PERF_RECORD_KSYMBOL addr ffffffffc027a000 len 4096 type 2 flags 0x0 name kprobe_insn_page
        6 565303697010 0x291f68 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffc027a000 old len 0 new len 6
        6 565303838278 0x291fa8 [0x50]: PERF_RECORD_KSYMBOL addr ffffffffc027c000 len 4096 type 2 flags 0x0 name kprobe_optinsn_page
        6 565303848286 0x291ff8 [0xa0]: PERF_RECORD_TEXT_POKE addr 0xffffffffc027c000 old len 0 new len 106
        6 565369336743 0x292af8 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffff88ab8890 old len 5 new len 5
        7 566434327704 0x217c208 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffff88ab8890 old len 5 new len 5
        6 566456313475 0x293198 [0xa0]: PERF_RECORD_TEXT_POKE addr 0xffffffffc027c000 old len 106 new len 0
        6 566456314935 0x293238 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffc027a000 old len 6 new len 0
    
    Example:
    
      The example requires kernel config:
        CONFIG_FUNCTION_TRACER=y
    
      Before:
        # perf record --kcore -m,64M -o t1 -a -e intel_pt//k &
        # perf probe __kmalloc
        Added new event:
          probe:__kmalloc      (on __kmalloc)
    
        You can now use it in all perf tools, such as:
    
            perf record -e probe:__kmalloc -aR sleep 1
    
        # perf record -e probe:__kmalloc -aR sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.022 MB perf.data (6 samples) ]
        # perf probe -d probe:__kmalloc
        Removed event: probe:__kmalloc
        # kill %1
        [ perf record: Woken up 2 times to write data ]
        [ perf record: Captured and wrote 43.850 MB t1 ]
        [1]+  Terminated                 perf record --kcore -m,64M -o t1 -a -e intel_pt//k
        # perf script -i t1 --itrace=e >/dev/null
        Warning:
        8 instruction trace errors
    
      After:
        # perf record --kcore -m,64M -o t1 -a -e intel_pt//k &
        # perf probe __kmalloc
        Added new event:
          probe:__kmalloc      (on __kmalloc)
    
        You can now use it in all perf tools, such as:
    
                perf record -e probe:__kmalloc -aR sleep 1
    
        # perf record -e probe:__kmalloc -aR sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.037 MB perf.data (206 samples) ]
        # perf probe -d probe:__kmalloc
        Removed event: probe:__kmalloc
        # kill %1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 41.442 MB t1 ]
        [1]+  Terminated                 perf record --kcore -m,64M -o t1 -a -e intel_pt//k
        # perf script -i t1 --itrace=e >/dev/null
        # perf script -i t1 --no-itrace -D | grep 'POKE\|KSYMBOL'
        5 312216133258 0x8bafe0 [0x50]: PERF_RECORD_KSYMBOL addr ffffffffc0360000 len 415 type 2 flags 0x0 name ftrace_trampoline
        5 312216133494 0x8bb030 [0x1d8]: PERF_RECORD_TEXT_POKE addr 0xffffffffc0360000 old len 0 new len 415
        5 312216229563 0x8bb208 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac6016f5 old len 5 new len 5
        5 312216239063 0x8bb248 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac601803 old len 5 new len 5
        5 312216727230 0x8bb288 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffabbea190 old len 5 new len 5
        5 312216739322 0x8bb2c8 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac6016f5 old len 5 new len 5
        5 312216748321 0x8bb308 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac601803 old len 5 new len 5
        7 313287163462 0x2817430 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac6016f5 old len 5 new len 5
        7 313287174890 0x2817470 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac601803 old len 5 new len 5
        7 313287818979 0x28174b0 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffabbea190 old len 5 new len 5
        7 313287829357 0x28174f0 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac6016f5 old len 5 new len 5
        7 313287841246 0x2817530 [0x40]: PERF_RECORD_TEXT_POKE addr 0xffffffffac601803 old len 5 new len 5
    Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: x86@kernel.org
    Link: http://lore.kernel.org/lkml/20200512121922.8997-14-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    b22f90aa
intel-pt.c 86.6 KB