• Namhyung Kim's avatar
    perf lock contention: Allow to change stack depth and skip · 96532a83
    Namhyung Kim authored
    It needs stack traces to find callers of locks.  To minimize the
    performance overhead it only collects up to 8 entries for each stack
    trace.  And it skips first 3 entries as they came from BPF, tracepoint
    and lock functions which are not interested for most users.
    
    But it turned out that those numbers are different in some
    configuration.  Using fixed number can result in non meaningful caller
    names.  Let's make them adjustable with --stack-depth and --skip-stack
    options.
    
    On my setup, the default output is like below:
    
      # /perf lock con -ab -F contended,wait_total sleep 3
       contended   total wait         type   caller
    
              28      4.55 ms     rwlock:W   __bpf_trace_contention_begin+0xb
              33      1.67 ms     rwlock:W   __bpf_trace_contention_begin+0xb
              12    580.28 us     spinlock   __bpf_trace_contention_begin+0xb
              60    240.54 us      rwsem:R   __bpf_trace_contention_begin+0xb
              27     64.45 us     spinlock   __bpf_trace_contention_begin+0xb
    
    If I change the stack skip to 5, the result will be like:
    
      # perf lock con -ab -F contended,wait_total --stack-skip 5 sleep 3
       contended   total wait         type   caller
    
              32    715.45 us     spinlock   folio_lruvec_lock_irqsave+0x61
              26    550.22 us     spinlock   folio_lruvec_lock_irqsave+0x61
              15    486.93 us      rwsem:R   mmap_read_lock+0x13
              12    139.66 us      rwsem:W   vm_mmap_pgoff+0x93
               1      7.04 us     spinlock   tick_do_update_jiffies64+0x25
    Signed-off-by: default avatarNamhyung 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: Peter Zijlstra <peterz@infradead.org>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: bpf@vger.kernel.org
    Link: https://lore.kernel.org/r/20220912055314.744552-4-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    96532a83
lock-contention.h 3.43 KB