• Kan Liang's avatar
    perf evsel: Support PERF_SAMPLE_BRANCH_HW_INDEX · d3f85437
    Kan Liang authored
    A new branch sample type PERF_SAMPLE_BRANCH_HW_INDEX has been introduced
    in latest kernel.
    
    Enable HW_INDEX by default in LBR call stack mode.
    
    If kernel doesn't support the sample type, switching it off.
    
    Add HW_INDEX in attr_fprintf as well. User can check whether the branch
    sample type is set via debug information or header.
    
    Committer testing:
    
    First collect some samples with LBR callchains, system wide, for a few
    seconds:
    
      # perf record --call-graph lbr -a sleep 5
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.625 MB perf.data (224 samples) ]
      #
    
    Now lets use 'perf evlist -v' to look at the branch_sample_type:
    
      # perf evlist -v
      cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES|HW_INDEX
      #
    
    So the machine has the kernel feature, and it was correctly added to
    perf_event_attr.branch_sample_type, for the default 'cycles' event.
    
    If we do it in another machine, where the kernel lacks the HW_INDEX
    feature, we get:
    
      # perf record --call-graph lbr -a sleep 2s
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 1.690 MB perf.data (499 samples) ]
      # perf evlist -v
      cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES
      #
    
    No HW_INDEX in attr.branch_sample_type.
    Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Michael Ellerman <mpe@ellerman.id.au>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Pavel Gerasimov <pavel.gerasimov@intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Vitaly Slobodskoy <vitaly.slobodskoy@intel.com>
    Link: http://lore.kernel.org/lkml/20200228163011.19358-3-kan.liang@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    d3f85437
evsel.c 65.7 KB