1. 28 May, 2020 40 commits
    • Xie XiuQi's avatar
      perf util: Fix memory leak of prefix_if_not_in · 07e9a6f5
      Xie XiuQi authored
      Need to free "str" before return when asprintf() failed to avoid memory
      leak.
      Signed-off-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Hongbo Yao <yaohongbo@huawei.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Li Bin <huawei.libin@huawei.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lore.kernel.org/lkml/20200521133218.30150-4-liwei391@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      07e9a6f5
    • Changbin Du's avatar
      perf ftrace: Detect workload failure · 51a09d8f
      Changbin Du authored
      Currently there's no error message prompted if we failed to start
      workload.  And we still get some trace which is confusing. Let's tell
      users what happened.
      
      Committer testing:
      
      Before:
      
          # perf ftrace nonsense |& head
           5)               |  switch_mm_irqs_off() {
           5)   0.400 us    |    load_new_mm_cr3();
           5)   3.261 us    |  }
           ------------------------------------------
           5)    <idle>-0    =>   <...>-3494
           ------------------------------------------
      
           5)               |  finish_task_switch() {
           5)   ==========> |
           5)               |    smp_irq_work_interrupt() {
          # type nonsense
          -bash: type: nonsense: not found
          #
      
      After:
      
        # perf ftrace nonsense |& head
        workload failed: No such file or directory
        # type nonsense
        -bash: type: nonsense: not found
        #
      Signed-off-by: default avatarChangbin Du <changbin.du@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Link: http://lore.kernel.org/lkml/20200510150628.16610-3-changbin.du@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      51a09d8f
    • Changbin Du's avatar
      perf ftrace: Trace system wide if no target is given · 452b0d16
      Changbin Du authored
      This align ftrace to other perf sub-commands that if no target specified
      then we trace all functions.
      Signed-off-by: default avatarChangbin Du <changbin.du@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Link: http://lore.kernel.org/lkml/20200510150628.16610-2-changbin.du@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      452b0d16
    • Gustavo A. R. Silva's avatar
      perf branch: Replace zero-length array with flexible-array · ffe7428e
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array
      member[1][2], introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning in
      case the flexible array does not occur last in the structure, which will
      help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by this
      change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle and audited _manually_.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520191613.GA26869@embeddedorSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ffe7428e
    • Paul A. Clarke's avatar
      perf config: Add stat.big-num support · d778a778
      Paul A. Clarke authored
      Add support for new "stat.big-num" boolean option.
      
      This allows a user to set a default for "--no-big-num" for "perf stat"
      commands.
      
      --
        $ perf config stat.big-num
        $ perf stat --event cycles /bin/true
      
         Performance counter stats for '/bin/true':
      
                   778,849      cycles
        [...]
        $ perf config stat.big-num=false
        $ perf config stat.big-num
        stat.big-num=false
        $ perf stat --event cycles /bin/true
      
         Performance counter stats for '/bin/true':
      
                    769622      cycles
        [...]
      --
      
      There is an interaction with "--field-separator" that must be
      accommodated, such that specifying "--big-num --field-separator={x}"
      still reports an invalid combination of options.
      
      Documentation for perf-config and perf-stat updated.
      Signed-off-by: default avatarPaul Clarke <pc@us.ibm.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Link: http://lore.kernel.org/lkml/1589991815-17951-1-git-send-email-pc@us.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d778a778
    • Wang ShaoBo's avatar
      perf bpf-loader: Add missing '*' for key_scan_pos · 04f9bf2b
      Wang ShaoBo authored
      key_scan_pos is a pointer for getting scan position in
      bpf__obj_config_map() for each BPF map configuration term,
      but it's misused when error not happened.
      
      Committer notes:
      
      The point is that the only user of this is:
      
        tools/perf/util/parse-events.c
          err = bpf__config_obj(obj, term, parse_state->evlist, &error_pos);
            if (err) bpf__strerror_config_obj(obj, term, parse_state->evlist, &error_pos, err, errbuf, sizeof(errbuf));
      
      And then:
      
      int bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused,
                                   struct parse_events_term *term __maybe_unused,
                                   struct evlist *evlist __maybe_unused,
                                   int *error_pos __maybe_unused, int err,
                                   char *buf, size_t size)
      {
              bpf__strerror_head(err, buf, size);
              bpf__strerror_entry(BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE,
                                  "Can't use this config term with this map type");
              bpf__strerror_end(buf, size);
              return 0;
      }
      
      So this is infrastructure that Wang Nan put in place for providing
      better error messages but that he ended up not using, so I'll apply the
      fix, its correct even not fixing any real problem at this time.
      
      Fixes: 066dacbf ("perf bpf: Add API to set values to map entries in a bpf object")
      Signed-off-by: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Cheng Jian <cj.chengjian@huawei.com>
      Cc: Hanjun Guo <guohanjun@huawei.com>
      Cc: Li Bin <huawei.libin@huawei.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Xie XiuQi <xiexiuqi@huawei.com>
      Cc: bpf@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20200520033216.48310-1-bobo.shaobowang@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      04f9bf2b
    • Jin Yao's avatar
      perf stat: Report summary for interval mode · c7e5b328
      Jin Yao authored
      Currently 'perf stat' supports to print counts at regular interval (-I),
      but it's not very easy for user to get the overall statistics.
      
      The patch uses 'evsel->prev_raw_counts' to get counts for summary.  Copy
      the counts to 'evsel->counts' after printing the interval results.
      Next, we just follow the non-interval processing.
      
      Let's see some examples,
      
       root@kbl-ppc:~# perf stat -e cycles -I1000 --interval-count 2
       #           time             counts unit events
            1.000412064          2,281,114      cycles
            2.001383658          2,547,880      cycles
      
        Performance counter stats for 'system wide':
      
                4,828,994      cycles
      
              2.002860349 seconds time elapsed
      
       root@kbl-ppc:~# perf stat -e cycles,instructions -I1000 --interval-count 2
       #           time             counts unit events
            1.000389902          1,536,093      cycles
            1.000389902            420,226      instructions              #    0.27  insn per cycle
            2.001433453          2,213,952      cycles
            2.001433453            735,465      instructions              #    0.33  insn per cycle
      
        Performance counter stats for 'system wide':
      
                3,750,045      cycles
                1,155,691      instructions              #    0.31  insn per cycle
      
              2.003023361 seconds time elapsed
      
       root@kbl-ppc:~# perf stat -M CPI,IPC -I1000 --interval-count 2
       #           time             counts unit events
            1.000435121            905,303      inst_retired.any          #      2.9 CPI
            1.000435121          2,663,333      cycles
            1.000435121            914,702      inst_retired.any          #      0.3 IPC
            1.000435121          2,676,559      cpu_clk_unhalted.thread
            2.001615941          1,951,092      inst_retired.any          #      1.8 CPI
            2.001615941          3,551,357      cycles
            2.001615941          1,950,837      inst_retired.any          #      0.5 IPC
            2.001615941          3,551,044      cpu_clk_unhalted.thread
      
        Performance counter stats for 'system wide':
      
                2,856,395      inst_retired.any          #      2.2 CPI
                6,214,690      cycles
                2,865,539      inst_retired.any          #      0.5 IPC
                6,227,603      cpu_clk_unhalted.thread
      
              2.003403078 seconds time elapsed
      
      Committer testing:
      
      Before:
      
        # perf stat -e cycles -I1000 --interval-count 2
        #           time             counts unit events
             1.000618627         26,877,408      cycles
             2.001417968        233,672,829      cycles
        #
      
      After:
      
        # perf stat -e cycles -I1000 --interval-count 2
        #           time             counts unit events
             1.001531815      5,341,388,792      cycles
             2.002936530        100,073,912      cycles
      
         Performance counter stats for 'system wide':
      
             5,441,462,704      cycles
      
               2.004893794 seconds time elapsed
      
        #
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520042737.24160-6-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c7e5b328
    • Jin Yao's avatar
      perf stat: Save aggr value to first member of prev_raw_counts · 905365f4
      Jin Yao authored
      To collect the overall statistics for interval mode, we copy the counts
      from evsel->prev_raw_counts to evsel->counts.
      
      For AGGR_GLOBAL mode, because the perf_stat_process_counter creates aggr
      values from per cpu values, but the per cpu values are 0, so the
      calculated aggr values will be always 0.
      
      This patch uses a trick that saves the previous aggr value to the first
      member of perf_counts, then aggr calculation in process_counter_values
      can work correctly for AGGR_GLOBAL.
      
       v6:
       ---
       Add comments in perf_evlist__save_aggr_prev_raw_counts.
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520042737.24160-5-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      905365f4
    • Jin Yao's avatar
      perf stat: Copy counts from prev_raw_counts to evsel->counts · 297767ac
      Jin Yao authored
      It would be useful to support the overall statistics for perf-stat
      interval mode. For example, report the summary at the end of "perf-stat
      -I" output.
      
      But since perf-stat can support many aggregation modes, such as
      --per-thread, --per-socket, -M and etc, we need a solution which doesn't
      bring much complexity.
      
      The idea is to use 'evsel->prev_raw_counts' which is updated in each
      interval and it's saved with the latest counts. Before reporting the
      summary, we copy the counts from evsel->prev_raw_counts to
      evsel->counts, and next we just follow non-interval processing.
      
       v5:
       ---
       Don't save the previous aggr value to the member of [cpu0,thread0]
       in perf_counts. Originally that was a trick because the
       perf_stat_process_counter would create aggr values from per cpu
       values. But we don't need to do that all the time. We will
       handle it in next patch.
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520042737.24160-4-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      297767ac
    • Jin Yao's avatar
      perf counts: Reset prev_raw_counts counts · cf4d9bd6
      Jin Yao authored
      When we want to reset the evsel->prev_raw_counts, zeroing the aggr is
      not enough, we need to reset the perf_counts too.
      
      The perf_counts__reset zeros the perf_counts, and it should zero the
      aggr too. This patch changes perf_counts__reset to non-static, and calls
      it in evsel__reset_prev_raw_counts to reset the prev_raw_counts.
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520042737.24160-3-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cf4d9bd6
    • Jin Yao's avatar
      perf stat: Fix wrong per-thread runtime stat for interval mode · 72f02a94
      Jin Yao authored
        root@kbl-ppc:~# perf stat --per-thread -e cycles,instructions -I1000 --interval-count 2
             1.004171683             perf-3696              8,747,311      cycles
                ...
             1.004171683             perf-3696                691,730      instructions              #    0.08  insn per cycle
                ...
             2.006490373             perf-3696              1,749,936      cycles
                ...
             2.006490373             perf-3696              1,484,582      instructions              #    0.28  insn per cycle
                ...
      
      Let's see interval 2.006490373
      
        perf-3696              1,749,936      cycles
        perf-3696              1,484,582      instructions              #    0.28  insn per cycle
      
      insn per cycle = 1,484,582 / 1,749,936 = 0.85.
      
      But now it's 0.28, that's not correct.
      
      stat_config.stats[] records the per-thread runtime stat. But for
      interval mode, it should be reset for each interval.
      
      So now, with this patch,
      
        root@kbl-ppc:~# perf stat --per-thread -e cycles,instructions -I1000 --interval-count 2
             1.005818121             perf-8633              9,898,045      cycles
                ...
             1.005818121             perf-8633                693,298      instructions              #    0.07  insn per cycle
                ...
             2.007863743             perf-8633              1,551,619      cycles
                ...
             2.007863743             perf-8633              1,317,514      instructions              #    0.85  insn per cycle
                ...
      
      Let's check interval 2.007863743.
      
      insn per cycle = 1,317,514 / 1,551,619 = 0.85. It's correct.
      
      This patch creates runtime_stat_reset, places it next to
      untime_stat_new/runtime_stat_delete and moves all runtime_stat
      functions before process_interval.
      
      Committer testing:
      
      After the patch:
      
        # perf stat --per-thread -e cycles,instructions -I1000 --interval-count 2  |& grep sssd_nss-1130
           2.011309774  sssd_nss-1130   56,585  cycles
           2.011309774  sssd_nss-1130   13,121  instructions  # 0.23 insn per cycle
        # python
        >>> 13121.0 / 56585
        0.23188124061146947
        >>>
      
      Fixes: commit 14e72a21 ("perf stat: Update or print per-thread stats")
      Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520042737.24160-2-yao.jin@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      72f02a94
    • Ian Rogers's avatar
      perf expr: Allow numbers to be followed by a dot · a45badc7
      Ian Rogers authored
      Metrics like UNC_M_POWER_SELF_REFRESH encode 100 as "100." and
      consequently the 100 is treated as a symbol. Alter the regular
      expression to allow the dot to be before or after the number.
      
      Note, this passed the pmu-events test as that tests the validity of a
      number using strtod rather than lex code. strtod allows the dot after.
      
      Add a test for this behavior.
      
      Fixes: 26226a97 (perf expr: Move expr lexer to flex)
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Paul Clarke <pc@us.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a45badc7
    • Ian Rogers's avatar
      perf metricgroup: Make 'evlist_used' variable a bitmap instead of array of bools · 45db55f2
      Ian Rogers authored
      Use a bitmap rather than an array of bools.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrii Nakryiko <andriin@fb.com>
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Paul Clarke <pc@us.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: bpf@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20200520072814.128267-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      45db55f2
    • Jiri Olsa's avatar
      perf stat: Fail on extra comma while parsing events · ae762641
      Jiri Olsa authored
      Ian reported that we allow to parse following:
      
        $ perf stat -e ,cycles true
      
      which is wrong and we should fail, like we do with this fix:
      
        $ perf stat -e ,cycles true
        event syntax error: ',cycles'
                              \___ parser error
      
      The reason is that we don't have rule for ',' in 'event' start condition
      and it's matched and accepted by default rule.
      
      Add scanner debug support (that Ian already added for expr code),
      which was really useful for finding this. It's enabled together with
      bison debug via 'make PARSER_DEBUG=1'.
      Reported-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200520074050.156988-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ae762641
    • Paul A. Clarke's avatar
      perf script: Better align register values in dump · 498ef715
      Paul A. Clarke authored
      Before:
      
        $ perf script --dump-raw-trace
        [...]
        2492031077254920 0x1e08 [0x308]: PERF_RECORD_SAMPLE(IP, 0x1): 47557/47557: 0xc00000000012eeb0 period: 1 addr: 0
        ... user regs: mask 0x1fffffffffff ABI 64-bit
        .... r0    0xb
        .... r1    0x7ffff3b90fa0
        .... r2    0x7fffbabf7300
        .... r3    0x7ffff3b9ed60
        .... r4    0x7ffff3b95cc0
        .... r5    0x1000c5a2940
        .... r6    0xfefefefefefefeff
        .... r7    0x7f7f7f7f7f7f7f7f
        .... r8    0x7ffff3b9ed60
        .... r9    0x0
        [...]
      
      After:
      
        [...]
        2492031077254920 0x1e08 [0x308]: PERF_RECORD_SAMPLE(IP, 0x1): 47557/47557: 0xc00000000012eeb0 period: 1 addr: 0
        ... user regs: mask 0x1fffffffffff ABI 64-bit
        .... r0    0x000000000000000b
        .... r1    0x00007ffff3b90fa0
        .... r2    0x00007fffbabf7300
        .... r3    0x00007ffff3b9ed60
        .... r4    0x00007ffff3b95cc0
        .... r5    0x000001000c5a2940
        .... r6    0xfefefefefefefeff
        .... r7    0x7f7f7f7f7f7f7f7f
        .... r8    0x00007ffff3b9ed60
        .... r9    0x0000000000000000
        [...]
      
      Committer testing:
      
      Full set of instructions, testing on x86_64:
      
        # perf record -I
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 2.855 MB perf.data (4902 samples) ]
        # perf evlist -v
        cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD|REGS_INTR, read_format: ID, disabled: 1, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, sample_regs_intr: 0xff0fff
        dummy:HG: type: 1, size: 120, config: 0x9, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ID|CPU|PERIOD|REGS_INTR, read_format: ID, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, sample_regs_intr: 0xff0fff
        #
      
      Before:
      
        # perf script --dump-raw-trace
        [...]
        0 1542674658099675 0x1cb700 [0xe0]: PERF_RECORD_SAMPLE(IP, 0x4001): 1825/1825: 0xffffffff9506e544 period: 1 addr: 0
        ... intr regs: mask 0xff0fff ABI 64-bit
        .... AX    0xf
        .... BX    0xffff96e1064125a0
        .... CX    0x38f
        .... DX    0x7
        .... SI    0xf
        .... DI    0x38f
        .... BP    0x1
        .... SP    0xfffffe000000bdf0
        .... IP    0xffffffff9506e544
        .... FLAGS 0xa
        .... CS    0x10
        .... SS    0x18
        .... R8    0x0
        .... R9    0x0
        .... R10   0xfffffe00000260c8
        .... R11   0xfffffe000000bef8
        .... R12   0x1
        .... R13   0x64
        .... R14   0x390
        .... R15   0xffff96e1064125a0
         ... thread: perf:1825
         ...... dso: /proc/kcore
                    perf  1825 [000] 1542674.658099:          1   cycles:  ffffffff9506e544 native_write_msr+0x4 (vmlinux
        [...]
      
      After:
      
        # perf script --dump-raw-trace
        [...]
        0 1542674658096068 0x1cb620 [0xe0]: PERF_RECORD_SAMPLE(IP, 0x4001): 1825/1825: 0xffffffff9506e544 period: 1 addr: 0
        ... intr regs: mask 0xff0fff ABI 64-bit
        .... AX    0x000000000000000f
        .... BX    0xffff96e1064125a0
        .... CX    0x000000000000038f
        .... DX    0x0000000000000007
        .... SI    0x000000000000000f
        .... DI    0x000000000000038f
        .... BP    0x0000000000000000
        .... SP    0xffffb3e788fb7c20
        .... IP    0xffffffff9506e544
        .... FLAGS 0x000000000000000a
        .... CS    0x0000000000000010
        .... SS    0x0000000000000018
        .... R8    0x00057b0deeffdfe3
        .... R9    0xffff96e106432480
        .... R10   0x0000000000000000
        .... R11   0xffff96e106412cc0
        .... R12   0xffffb3e788fb7d00
        .... R13   0xffff96e106432408
        .... R14   0xffff96e106432400
        .... R15   0xffff96e0e09a4800
         ... thread: perf:1825
         ...... dso: /proc/kcore
                    perf  1825 [000] 1542674.658096:          1   cycles:  ffffffff9506e544 native_write_msr+0x4 (vmlinux)
        [...]
      Signed-off-by: default avatarPaul Clarke <pc@us.ibm.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      LPU-Reference: 1589911102-9460-1-git-send-email-pc@us.ibm.com
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      498ef715
    • Paul A. Clarke's avatar
      perf stat: POWER9 metrics: expand "ICT" acronym · acd1ac23
      Paul A. Clarke authored
      Uses of "ICT" and "Ict" are expanded to "Instruction Completion Table".
      Signed-off-by: default avatarPaul Clarke <pc@us.ibm.com>
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Sukadev Bhattiprolu <sukadev@linux.ibm.com>
      Link: http://lore.kernel.org/lkml/1589915886-22992-1-git-send-email-pc@us.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      acd1ac23
    • Gustavo A. R. Silva's avatar
      perf tools: Replace zero-length array with flexible-array · 6549a8c0
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array
      member[1][2], introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning in
      case the flexible array does not occur last in the structure, which will
      help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by this
      change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200515172926.GA31976@embeddedorSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6549a8c0
    • Adrian Hunter's avatar
      perf intel-pt: Use allocated branch stack for PEBS sample · 961224db
      Adrian Hunter authored
      To avoid having struct branch_stack as a non-last structure member,
      use allocated branch stack for PEBS sample.
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Acked-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/2540ed9a-89f1-6d59-10c9-a66cc90db5d2@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      961224db
    • Alexey Budankov's avatar
      perf docs: Introduce security.txt file to document related issues · bd7c1c66
      Alexey Budankov authored
      Publish instructions on how to apply LSM hooks for access control to
      perf_event_open() syscall on Fedora distro with Targeted SELinux policy
      and then manage access to the syscall.
      Signed-off-by: default avatarAlexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: linux-security-module@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Link: http://lore.kernel.org/lkml/290ded0a-c422-3749-5180-918fed1ee30f@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      bd7c1c66
    • Alexey Budankov's avatar
      perf tool: Make perf tool aware of SELinux access control · c1034eb0
      Alexey Budankov authored
      Implement selinux sysfs check to see the system is in enforcing mode and
      print warning message with pointer to check audit logs.
      Signed-off-by: default avatarAlexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: linux-security-module@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Link: http://lore.kernel.org/lkml/819338ce-d160-4a2f-f1aa-d756a2e7c6fc@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c1034eb0
    • Alexey Budankov's avatar
      perf docs: Extend CAP_SYS_ADMIN with CAP_PERFMON where needed · a885f3cc
      Alexey Budankov authored
      Extend CAP_SYS_ADMIN with CAP_PERFMON in the docs.
      Signed-off-by: default avatarAlexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: linux-security-module@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Link: http://lore.kernel.org/lkml/3b19cf79-f02d-04b4-b8b1-0039ac023b2c@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a885f3cc
    • Ian Rogers's avatar
      perf expr: Migrate expr ids table to a hashmap · ded80bda
      Ian Rogers authored
      Use a hashmap between a char* string and a double* value. While bpf's
      hashmap entries are size_t in size, we can't guarantee sizeof(size_t) >=
      sizeof(double). Avoid a memory allocation when gathering ids by making
      0.0 a special value encoded as NULL.
      
      Original map suggestion by Andi Kleen:
      
        https://lore.kernel.org/lkml/20200224210308.GQ160988@tassilo.jf.intel.com/
      
      and seconded by Jiri Olsa:
      
        https://lore.kernel.org/lkml/20200423112915.GH1136647@krava/
      
      Committer notes:
      
      There are fixes that need to land upstream before we can use libbpf's
      headers, for now use our copy unconditionally, since the data structures
      at this point are exactly the same, no problem.
      
      When the fixes for libbpf's hashmap land upstream, we can fix this up.
      
      Testing it:
      
      Building with LIBBPF=1, i.e. the default:
      
        $ perf -vv | grep -i bpf
                           bpf: [ on  ]  # HAVE_LIBBPF_SUPPORT
        $ nm ~/bin/perf | grep -i libbpf_ | wc -l
        39
        $ nm ~/bin/perf | grep -i hashmap_ | wc -l
        17
        $
      
      Explicitely building without LIBBPF:
      
        $ perf -vv | grep -i bpf
                           bpf: [ OFF ]  # HAVE_LIBBPF_SUPPORT
        $
        $ nm ~/bin/perf | grep -i libbpf_ | wc -l
        0
        $ nm ~/bin/perf | grep -i hashmap_ | wc -l
        9
        $
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrii Nakryiko <andriin@fb.com>
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Fastabend <john.fastabend@gmail.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: kp singh <kpsingh@chromium.org>
      Cc: netdev@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20200515221732.44078-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ded80bda
    • Ian Rogers's avatar
      perf tools: Grab a copy of libbpf's hashmap · eee19501
      Ian Rogers authored
      Allow use of hashmap in perf. Modify perf's check-headers.sh script to
      check that the files are kept in sync, in the same way kernel headers
      are checked. This will warn if they are out of sync at the start of a
      perf build.
      
      Committer note:
      
      This starts out of synch as a fix went thru the bpf tree, namely the one
      removing the needless libbpf_internal.h include in hashmap.h.
      
      There is also another change related to __WORDSIZE, that as is in
      tools/lib/bpf/hashmap.h causes the tools/perf/ build to fail in systems
      such as Alpine Linus, that uses the Musl libc, so we need an alternative
      way of having __WORDSIZE available, use the one used by
      tools/include/linux/bitops.h, that builds in all the systems I have
      build containers for.
      
      These differences will be resolved at some point, so keep the warning in
      check-headers.sh as a reminder.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Fastabend <john.fastabend@gmail.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: kp singh <kpsingh@chromium.org>
      Cc: netdev@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20200515221732.44078-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      eee19501
    • Jiri Olsa's avatar
      perf stat: Fix duration_time value for higher intervals · ea9eb1f4
      Jiri Olsa authored
      Joakim reported wrong duration_time value for interval bigger
      than 4000 [1].
      
      The problem is in the interval value we pass to update_stats
      function, which is typed as 'unsigned int' and overflows when
      we get over 2^32 (happens between intervals 4000 and 5000).
      
      Retyping the passed value to unsigned long long.
      
      [1] https://www.spinics.net/lists/linux-perf-users/msg11777.html
      
      Fixes: b90f1333 ("perf stat: Update walltime_nsecs_stats in interval mode")
      Reported-by: default avatarJoakim Zhang <qiangqing.zhang@nxp.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200518131445.3745083-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ea9eb1f4
    • Jiri Olsa's avatar
      perf trace: Fix compilation error for make NO_LIBBPF=1 DEBUG=1 · beb64203
      Jiri Olsa authored
      The perf compilation fails for NO_LIBBPF=1 DEBUG=1 with:
      
        $ make NO_LIBBPF=1 DEBUG=1
          BUILD:   Doing 'make -j8' parallel build
          CC       builtin-trace.o
          LD       perf-in.o
          LINK     perf
        /usr/bin/ld: perf-in.o: in function `trace__find_bpf_map_by_name':
        /home/jolsa/kernel/linux-perf/tools/perf/builtin-trace.c:4608: undefined reference to `bpf_object__find_map_by_name'
        collect2: error: ld returned 1 exit status
        make[2]: *** [Makefile.perf:631: perf] Error 1
        make[1]: *** [Makefile.perf:225: sub-make] Error 2
        make: *** [Makefile:70: all] Error 2
      
      Move trace__find_bpf_map_by_name calls under HAVE_LIBBPF_SUPPORT ifdef
      and add make test for this.
      
      Committer notes:
      
      Add missing:
      
        run += make_no_libbpf_DEBUG
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200518141027.3765877-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      beb64203
    • Ian Rogers's avatar
      perf beauty: Allow the CC used in the arch errno names script to acccept CFLAGS · 6d1f9162
      Ian Rogers authored
      Allow the CC compiler to accept a CFLAGS environment variable.  This
      doesn't change the code generated but makes it easier to integrate
      running the shell script in build systems like bazel.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexios Zavras <alexios.zavras@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Igor Lubashev <ilubashe@akamai.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Wei Li <liwei391@huawei.com>
      Link: http://lore.kernel.org/lkml/20200306071110.130202-4-irogers@google.com
      [ split from a larger patch ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6d1f9162
    • Ian Rogers's avatar
      perf trace: Fix the selection for architectures to generate the errno name tables · 7597ce89
      Ian Rogers authored
      Make the architecture test directory agree with the code comment.
      
      Committer notes:
      
      This was split from a larger patch.
      
      The code was assuming the developer always worked from tools/perf/, so make sure we
      do the test -d having $toolsdir/perf/arch/$arch, to match the intent expressed in the comment,
      just above that loop.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexios Zavras <alexios.zavras@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Igor Lubashev <ilubashe@akamai.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Wei Li <liwei391@huawei.com>
      Link: http://lore.kernel.org/lkml/20200306071110.130202-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7597ce89
    • Ian Rogers's avatar
      perf test: Improve pmu event metric testing · 06392aaa
      Ian Rogers authored
      Break pmu-events test into 2 and add a test to verify that all pmu
      metric expressions simply parse. Try to parse all metric ids/events,
      skip/warn if metrics for the current architecture fail to parse. To
      support warning for a skip, and an ability for a subtest to describe why
      it skips.
      
      Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
      ivybridge.
      
      May skip/warn on other architectures if metrics are invalid. In
      particular s390 is untested, but its expressions are trivial. The
      untested architectures with expressions are power8, cascadelakex,
      tremontx, skylake, jaketown, ivytown and variants of haswell and
      broadwell.
      
      v3. addresses review comments from John Garry <john.garry@huawei.com>,
      Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
      <acme@kernel.org>.
      v2. changes the commit message as event parsing errors no longer cause
      the test to fail.
      
      Committer notes:
      
      Check the return value of strtod() to fix the build in systems where
      that function is declared with attribute warn_unused_result.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Paul Clarke <pc@us.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
      [ split from a larger patch ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      06392aaa
    • Ian Rogers's avatar
      perf test: Provide a subtest callback to ask for the reason for skipping a subtest · 3b536651
      Ian Rogers authored
      Now subtests can inform why a test was skipped. The upcoming patch
      improvint PMU event metric testing will use it.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Paul Clarke <pc@us.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
      [ split from a larger patch ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3b536651
    • Ian Rogers's avatar
      perf parse-events: Make add PMU verbose output clearer · 4ac22b48
      Ian Rogers authored
      On a CPU like skylakex an uncore_iio_0 PMU may alias with
      uncore_iio_free_running_0. The latter PMU doesn't support fc_mask as a
      parameter and so pmu_config_term fails. Typically parse_events_add_pmu
      is called in a loop where if one alias succeeds errors are ignored,
      however, if multiple errors occur parse_events__handle_error will
      currently give a WARN_ONCE.
      
      This change removes the WARN_ONCE in parse_events__handle_error and
      makes it a pr_debug. It adds verbose messages to parse_events_add_pmu
      warning that non-fatal errors may occur, while giving details on the pmu
      and config terms for useful context. pmu_config_term is altered so the
      failing term and pmu are present in the case of the 'unknown term' error
      which makes spotting the free_running case more straightforward.
      
      Before:
      
        $ perf --debug verbose=3 stat -M llc_misses.pcie_read sleep 1
        Using CPUID GenuineIntel-6-55-4
        metric expr unc_iio_data_req_of_cpu.mem_read.part0 + unc_iio_data_req_of_cpu.mem_read.part1 + unc_iio_data_req_of_cpu.mem_read.part2 + unc_iio_data_req_of_cpu.mem_read.part3 for LLC_MISSES.PCIE_READ
        found event unc_iio_data_req_of_cpu.mem_read.part0
        found event unc_iio_data_req_of_cpu.mem_read.part1
        found event unc_iio_data_req_of_cpu.mem_read.part2
        found event unc_iio_data_req_of_cpu.mem_read.part3
        metric expr unc_iio_data_req_of_cpu.mem_read.part0 + unc_iio_data_req_of_cpu.mem_read.part1 + unc_iio_data_req_of_cpu.mem_read.part2 + unc_iio_data_req_of_cpu.mem_read.part3 for LLC_MISSES.PCIE_READ
        found event unc_iio_data_req_of_cpu.mem_read.part0
        found event unc_iio_data_req_of_cpu.mem_read.part1
        found event unc_iio_data_req_of_cpu.mem_read.part2
        found event unc_iio_data_req_of_cpu.mem_read.part3
        adding {unc_iio_data_req_of_cpu.mem_read.part0,unc_iio_data_req_of_cpu.mem_read.part1,unc_iio_data_req_of_cpu.mem_read.part2,unc_iio_data_req_of_cpu.mem_read.part3}:W,{unc_iio_data_req_of_cpu.mem_read.part0,unc_iio_data_req_of_cpu.mem_read.part1,unc_iio_data_req_of_cpu.mem_read.part2,unc_iio_data_req_of_cpu.mem_read.part3}:W
        intel_pt default config: tsc,mtc,mtc_period=3,psb_period=3,pt,branch
        WARNING: multiple event parsing errors
        ...
        Invalid event/parameter 'fc_mask'
        ...
      
      After:
      
        $ perf --debug verbose=3 stat -M llc_misses.pcie_read sleep 1
        Using CPUID GenuineIntel-6-55-4
        metric expr unc_iio_data_req_of_cpu.mem_read.part0 + unc_iio_data_req_of_cpu.mem_read.part1 + unc_iio_data_req_of_cpu.mem_read.part2 + unc_iio_data_req_of_cpu.mem_read.part3 for LLC_MISSES.PCIE_READ
        found event unc_iio_data_req_of_cpu.mem_read.part0
        found event unc_iio_data_req_of_cpu.mem_read.part1
        found event unc_iio_data_req_of_cpu.mem_read.part2
        found event unc_iio_data_req_of_cpu.mem_read.part3
        metric expr unc_iio_data_req_of_cpu.mem_read.part0 + unc_iio_data_req_of_cpu.mem_read.part1 + unc_iio_data_req_of_cpu.mem_read.part2 + unc_iio_data_req_of_cpu.mem_read.part3 for LLC_MISSES.PCIE_READ
        found event unc_iio_data_req_of_cpu.mem_read.part0
        found event unc_iio_data_req_of_cpu.mem_read.part1
        found event unc_iio_data_req_of_cpu.mem_read.part2
        found event unc_iio_data_req_of_cpu.mem_read.part3
        adding {unc_iio_data_req_of_cpu.mem_read.part0,unc_iio_data_req_of_cpu.mem_read.part1,unc_iio_data_req_of_cpu.mem_read.part2,unc_iio_data_req_of_cpu.mem_read.part3}:W,{unc_iio_data_req_of_cpu.mem_read.part0,unc_iio_data_req_of_cpu.mem_read.part1,unc_iio_data_req_of_cpu.mem_read.part2,unc_iio_data_req_of_cpu.mem_read.part3}:W
        intel_pt default config: tsc,mtc,mtc_period=3,psb_period=3,pt,branch
        Attempting to add event pmu 'uncore_iio_free_running_5' with 'unc_iio_data_req_of_cpu.mem_read.part0,' that may result in non-fatal errors
        After aliases, add event pmu 'uncore_iio_free_running_5' with 'fc_mask,ch_mask,umask,event,' that may result in non-fatal errors
        Attempting to add event pmu 'uncore_iio_free_running_3' with 'unc_iio_data_req_of_cpu.mem_read.part0,' that may result in non-fatal errors
        After aliases, add event pmu 'uncore_iio_free_running_3' with 'fc_mask,ch_mask,umask,event,' that may result in non-fatal errors
        Attempting to add event pmu 'uncore_iio_free_running_1' with 'unc_iio_data_req_of_cpu.mem_read.part0,' that may result in non-fatal errors
        After aliases, add event pmu 'uncore_iio_free_running_1' with 'fc_mask,ch_mask,umask,event,' that may result in non-fatal errors
        Multiple errors dropping message: unknown term 'fc_mask' for pmu 'uncore_iio_free_running_3' (valid terms: event,umask,config,config1,config2,name,period,percore)
        ...
      
        So before you see a 'WARNING: multiple event parsing errors' and
        'Invalid event/parameter'. After you see 'Attempting... that may result
        in non-fatal errors' then 'Multiple errors...' with details that
        'fc_mask' wasn't known to a free running counter. While not completely
        clean, this makes it clearer that an error hasn't really occurred.
      
      v2. addresses review feedback from Jiri Olsa <jolsa@redhat.com>.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lore.kernel.org/lkml/20200513220635.54700-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      4ac22b48
    • Ian Rogers's avatar
      perf expr: Fix memory leaks in metric bison · 63657578
      Ian Rogers authored
      Add a destructor for strings to reclaim memory in the event of errors.
      Free the ID given for a lookup, it was previously strdup-ed in the lex
      code.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200513000318.15166-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      63657578
    • Ravi Bangoria's avatar
      perf powerpc: Don't ignore sym-handling.c file · 39548e50
      Ravi Bangoria authored
      Commit 7eec00a7 ("perf symbols: Consolidate symbol fixup issue")
      removed powerpc specific sym-handling.c file from Build. This wasn't
      caught by build CI because all functions in this file are declared
      as __weak in common code. Fix it.
      
      Fixes: 7eec00a7 ("perf symbols: Consolidate symbol fixup issue")
      Reported-by: default avatarSandipan Das <sandipan@linux.ibm.com>
      Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Reviewed-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Acked-by: default avatarSandipan Das <sandipan@linux.ibm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: http://lore.kernel.org/lkml/20200509112113.174745-1-ravi.bangoria@linux.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      39548e50
    • Ian Rogers's avatar
      perf expr: Test parsing of floating point numbers · 63f11355
      Ian Rogers authored
      Add test for fix in:
      commit 5741da3dee4c ("perf expr: Parse numbers as doubles")
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Paul Clarke <pc@us.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200513062752.3681-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      63f11355
    • Anand K Mistry's avatar
      perf record: Use an eventfd to wakeup when done · da231338
      Anand K Mistry authored
      The setting and checking of 'done' contains a rare race where the signal
      handler setting 'done' is run after checking to break the loop, but
      before waiting in evlist__poll(). In this case, the main loop won't wake
      up until either another signal is sent, or the perf data fd causes a
      wake up.
      
      The following simple script can trigger this condition (but you might
      need to run it for several hours):
      
      for ((i = 0; i >= 0; i++)) ; do
        echo "Loop $i"
        delay=$(echo "scale=4; 0.1 * $RANDOM/32768" | bc)
        ./perf record -- sleep 30000000 >/dev/null&
        pid=$!
        sleep $delay
        kill -TERM $pid
        echo "PID $pid"
        wait $pid
      done
      
      At some point, the loop will stall. Adding logging, even though perf has
      received the SIGTERM and set 'done = 1', perf will remain sleeping until
      a second signal is sent.
      
      Committer notes:
      
      Make this dependent on HAVE_EVENTFD_SUPPORT, so that we continue
      building on older systems without the eventfd syscall.
      Signed-off-by: default avatarAnand K Mistry <amistry@google.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200513122012.v3.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeidSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      da231338
    • Arnaldo Carvalho de Melo's avatar
      tools feature: Rename HAVE_EVENTFD to HAVE_EVENTFD_SUPPORT · ba35fe93
      Arnaldo Carvalho de Melo authored
      To be consistent with other such auto-detected features.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Anand K Mistry <amistry@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ba35fe93
    • Arnaldo Carvalho de Melo's avatar
      perf evsel: Initialize evsel->per_pkg_mask to NULL in evsel__init() · f0aef475
      Arnaldo Carvalho de Melo authored
      Just like with the other fields, this probably isn't fixing anything
      observable as evsel__new() uses zalloc() for the whole 'struct evsel',
      but since evsels can be embedded in larger structures and maybe those
      larger structures don't use zalloc() for some reason, init it to NULL
      just in case.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f0aef475
    • Ian Rogers's avatar
      perf evsel: Fix 2 memory leaks · 3efc899d
      Ian Rogers authored
      If allocated, perf_pkg_mask and metric_events need freeing.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200512235918.10732-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3efc899d
    • Arnaldo Carvalho de Melo's avatar
      perf parse-events: Fix incorrect conversion of 'if () free()' to 'zfree()' · 7fcdccd4
      Arnaldo Carvalho de Melo authored
      When applying a patch by Ian I incorrectly converted to zfree() an
      expression that involved testing some other struct member, not the one
      being freed, which lead to bugs reproduceable by:
      
        $ perf stat -e i/bs,tsc,L2/o sleep 1
        WARNING: multiple event parsing errors
        Segmentation fault (core dumped)
        $
      
      Fix it by restoring the test for pos->free_str before freeing
      pos->val.str, but continue using zfree(&pos->val.str) to set that member
      to NULL after freeing it.
      Reported-by: default avatarIan Rogers <irogers@google.com>
      Fixes: e8dfb818 ("perf parse-events: Fix memory leaks found on parse_events")
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: clang-built-linux@googlegroups.com
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7fcdccd4
    • Jiri Olsa's avatar
      perf tools: Fix is_bpf_image function logic · e12a89ef
      Jiri Olsa authored
      Adrian reported that is_bpf_image is not working the way it was intended
      - passing on trampolines and dispatcher names. Instead it returned true
      for all the bpf names.
      
      The reason even this logic worked properly is that all bpf objects, even
      trampolines and dispatcher, were assigned DSO_BINARY_TYPE__BPF_IMAGE
      binary_type.
      
      The later for bpf_prog objects, the binary_type was fixed in bpf load
      event processing, which is executed after the ksymbol code.
      
      Fixing the is_bpf_image logic, so it properly recognizes trampoline and
      dispatcher objects.
      
      Fixes: 3c29d448 ("perf annotate: Add basic support for bpf_image")
      Reported-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200512122310.3154754-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e12a89ef
    • Ian Rogers's avatar
      perf c2c: Fix 'perf c2c record -e list' to show the default events used · b027cc6f
      Ian Rogers authored
      When the event is passed as list, the default events should be listed as
      per 'perf mem record -e list'. Previous behavior is:
      
        $ perf c2c record -e list
        failed: event 'list' not found, use '-e list' to get list of available events
      
         Usage: perf c2c record [<options>] [<command>]
            or: perf c2c record [<options>] -- <command> [<options>]
      
            -e, --event <event>   event selector. Use 'perf mem record -e list' to list available events
        $
      
      New behavior:
      
        $ perf c2c record -e list
        ldlat-loads  : available
        ldlat-stores : available
      
      v3: is a rebase.
      v2: addresses review comments by Jiri Olsa.
      
      https://lore.kernel.org/lkml/20191127081844.GH32367@krava/Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20200507220604.3391-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b027cc6f