1. 03 Sep, 2024 18 commits
    • Ian Rogers's avatar
      perf pmu: Merge boolean sysfs event option parsing · beef8fb2
      Ian Rogers authored
      Merge perf_pmu__parse_per_pkg() and perf_pmu__parse_snapshot() that do the
      same parsing except for the file suffix used.
      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: Ananth Narayan <ananth.narayan@amd.com>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Gautham Shenoy <gautham.shenoy@amd.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: K Prateek Nayak <kprateek.nayak@amd.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: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Link: https://lore.kernel.org/r/20240718003025.1486232-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      beef8fb2
    • Yang Jihong's avatar
      perf sched timehist: Add --prio option · 9b3a48bb
      Yang Jihong authored
      The --prio option is used to only show events for the given task priority(ies).
      The default is to show events for all priority tasks, which is consistent with
      the previous behavior.
      
      Testcase:
        # perf sched record nice -n 9 perf bench sched messaging -l 10000
        # Running 'sched/messaging' benchmark:
        # 20 sender and receiver processes per group
        # 10 groups == 400 processes run
      
             Total time: 3.435 [sec]
        [ perf record: Woken up 270 times to write data ]
        [ perf record: Captured and wrote 618.688 MB perf.data (5729036 samples) ]
      
        # perf sched timehist -h
      
         Usage: perf sched timehist [<options>]
      
            -C, --cpu <cpu>       list of cpus to profile
            -D, --dump-raw-trace  dump raw trace in ASCII
            -f, --force           don't complain, do it
            -g, --call-graph      Display call chains if present (default on)
            -I, --idle-hist       Show idle events only
            -i, --input <file>    input file name
            -k, --vmlinux <file>  vmlinux pathname
            -M, --migrations      Show migration events
            -n, --next            Show next task
            -p, --pid <pid[,pid...]>
                                  analyze events only for given process id(s)
            -s, --summary         Show only syscall summary with statistics
            -S, --with-summary    Show all syscalls and summary with statistics
            -t, --tid <tid[,tid...]>
                                  analyze events only for given thread id(s)
            -V, --cpu-visual      Add CPU visual
            -v, --verbose         be more verbose (show symbol address, etc)
            -w, --wakeups         Show wakeup events
                --kallsyms <file>
                                  kallsyms pathname
                --max-stack <n>   Maximum number of functions to display backtrace.
                --prio <prio>     analyze events only for given task priority(ies)
                --show-prio       Show task priority
                --state           Show task state when sched-out
                --symfs <directory>
                                  Look for files with symbols relative to this directory
                --time <str>      Time span for analysis (start,stop)
      
        # perf sched timehist --prio 140
        Samples of sched_switch event do not have callchains.
        Invalid prio string
      
        # perf sched timehist --show-prio --prio 129
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       prio      wait time  sch delay   run time
                                [tid/pid]                                    (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  --------  ---------  ---------  ---------
         2090450.765421 [0002]  sched-messaging[1229618]        129           0.000      0.000      0.029
         2090450.765445 [0007]  sched-messaging[1229616]        129           0.000      0.062      0.043
         2090450.765448 [0014]  sched-messaging[1229619]        129           0.000      0.000      0.032
         2090450.765478 [0013]  sched-messaging[1229617]        129           0.000      0.065      0.048
         2090450.765503 [0014]  sched-messaging[1229622]        129           0.000      0.000      0.017
         2090450.765550 [0002]  sched-messaging[1229624]        129           0.000      0.000      0.021
         2090450.765562 [0007]  sched-messaging[1229621]        129           0.000      0.071      0.028
         2090450.765570 [0005]  sched-messaging[1229620]        129           0.000      0.064      0.066
         2090450.765583 [0001]  sched-messaging[1229625]        129           0.000      0.001      0.031
         2090450.765595 [0013]  sched-messaging[1229623]        129           0.000      0.060      0.028
         2090450.765637 [0014]  sched-messaging[1229628]        129           0.000      0.000      0.019
         2090450.765665 [0007]  sched-messaging[1229627]        129           0.000      0.038      0.030
        <SNIP>
      
        # perf sched timehist --show-prio --prio 0,120-129
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       prio      wait time  sch delay   run time
                                [tid/pid]                                    (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  --------  ---------  ---------  ---------
         2090450.763231 [0000]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763235 [0000]  migration/0[15]                 0             0.000      0.001      0.003
         2090450.763263 [0001]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763268 [0001]  migration/1[21]                 0             0.000      0.001      0.004
         2090450.763302 [0002]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763309 [0002]  migration/2[27]                 0             0.000      0.001      0.007
         2090450.763338 [0003]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763343 [0003]  migration/3[33]                 0             0.000      0.001      0.004
         2090450.763459 [0004]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763469 [0004]  migration/4[39]                 0             0.000      0.002      0.010
         2090450.763496 [0005]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763501 [0005]  migration/5[45]                 0             0.000      0.001      0.004
         2090450.763613 [0006]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763622 [0006]  migration/6[51]                 0             0.000      0.001      0.008
         2090450.763652 [0007]  perf[1229608]                   120           0.000      0.000      0.000
         2090450.763660 [0007]  migration/7[57]                 0             0.000      0.001      0.008
        <SNIP>
         2090450.765665 [0001]  <idle>                          120           0.031      0.031      0.081
         2090450.765665 [0007]  sched-messaging[1229627]        129           0.000      0.038      0.030
         2090450.765667 [0000]  s1-perf[8235/7168]              120           0.008      0.000      0.004
         2090450.765684 [0013]  <idle>                          120           0.028      0.028      0.088
         2090450.765685 [0001]  sched-messaging[1229630a]        129           0.000      0.001      0.020
         2090450.765688 [0000]  <idle>                          120           0.004      0.004      0.020
         2090450.765689 [0002]  <idle>                          120           0.021      0.021      0.138
         2090450.765691 [0005]  sched-messaging[1229626]        129           0.000      0.085      0.029
      Signed-off-by: default avatarYang Jihong <yangjihong@bytedance.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240819033016.2427235-3-yangjihong@bytedance.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9b3a48bb
    • Yang Jihong's avatar
      perf sched timehist: Add --show-prio option · 3fcd7409
      Yang Jihong authored
      The --show-prio option is used to display the priority of task.
      
      It is disabled by default, which is consistent with original behavior.
      
      The display format is xxx (priority does not change during task running)
      or xxx->yyy (priority changes during task running)
      
      Testcase:
      
        # perf sched record nice -n 9 true
        [ perf record: Woken up 0 times to write data ]
        [ perf record: Captured and wrote 0.497 MB perf.data ]
      
        # perf sched timehist -h
      
         Usage: perf sched timehist [<options>]
      
            -C, --cpu <cpu>       list of cpus to profile
            -D, --dump-raw-trace  dump raw trace in ASCII
            -f, --force           don't complain, do it
            -g, --call-graph      Display call chains if present (default on)
            -I, --idle-hist       Show idle events only
            -i, --input <file>    input file name
            -k, --vmlinux <file>  vmlinux pathname
            -M, --migrations      Show migration events
            -n, --next            Show next task
            -p, --pid <pid[,pid...]>
                                  analyze events only for given process id(s)
            -s, --summary         Show only syscall summary with statistics
            -S, --with-summary    Show all syscalls and summary with statistics
            -t, --tid <tid[,tid...]>
                                  analyze events only for given thread id(s)
            -V, --cpu-visual      Add CPU visual
            -v, --verbose         be more verbose (show symbol address, etc)
            -w, --wakeups         Show wakeup events
                --kallsyms <file>
                                  kallsyms pathname
                --max-stack <n>   Maximum number of functions to display backtrace.
                --show-prio       Show task priority
                --state           Show task state when sched-out
                --symfs <directory>
                                  Look for files with symbols relative to this directory
                --time <str>      Time span for analysis (start,stop)
      
        # perf sched timehist
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
           23952.006537 [0000]  perf[534]                           0.000      0.000      0.000
           23952.006593 [0000]  migration/0[19]                     0.000      0.014      0.056
           23952.006899 [0001]  perf[534]                           0.000      0.000      0.000
           23952.006947 [0001]  migration/1[22]                     0.000      0.015      0.047
           23952.007138 [0002]  perf[534]                           0.000      0.000      0.000
        <SNIP>
      
        # perf sched timehist --show-prio
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       prio      wait time  sch delay   run time
                                [tid/pid]                                    (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  --------  ---------  ---------  ---------
           23952.006537 [0000]  perf[534]                       120           0.000      0.000      0.000
           23952.006593 [0000]  migration/0[19]                 0             0.000      0.014      0.056
           23952.006899 [0001]  perf[534]                       120           0.000      0.000      0.000
        <SNIP>
           23952.034843 [0003]  nice[535]                       120->129      0.189      0.024     23.314
        <SNIP>
           23952.053838 [0005]  rcu_preempt[16]                 120           3.993      0.000      0.023
           23952.053990 [0005]  <idle>                          120           0.023      0.023      0.152
           23952.054137 [0006]  <idle>                          120           1.427      1.427     17.855
           23952.054278 [0007]  <idle>                          120           0.506      0.506      1.650
      Signed-off-by: default avatarYang Jihong <yangjihong@bytedance.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240819033016.2427235-2-yangjihong@bytedance.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3fcd7409
    • Yang Jihong's avatar
      perf sched timehist: Remove redundant BUG_ON in timehist_sched_change_event() · b93fb9cf
      Yang Jihong authored
      The BUG_ON(thread__tid(thread) != 0) in timehist_sched_change_event() is
      redundant, remove it.
      
      No functional change.
      
      Fixes: 07235f84 ("perf sched timehist: Add -I/--idle-hist option")
      Reviewed-by: default avatarMadadi Vineeth Reddy <vineethr@linux.ibm.com>
      Signed-off-by: default avatarYang Jihong <yangjihong@bytedance.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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>
      Link: https://lore.kernel.org/r/20240812132606.3126490-2-yangjihong@bytedance.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b93fb9cf
    • Yang Jihong's avatar
      perf sched timehist: Skip print non-idle task samples when only show idle events · 575eec21
      Yang Jihong authored
      when only show idle events, runtime stats of non-idle tasks is not updated,
      and the value is 0, there is no need to print non-idle samples.
      
      Before:
      
        # perf sched timehist -I
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
         2090450.763235 [0000]  migration/0[15]                     0.000      0.000      0.000
         2090450.763268 [0001]  migration/1[21]                     0.000      0.000      0.000
         2090450.763309 [0002]  migration/2[27]                     0.000      0.000      0.000
         2090450.763343 [0003]  migration/3[33]                     0.000      0.000      0.000
         2090450.763469 [0004]  migration/4[39]                     0.000      0.000      0.000
         2090450.763501 [0005]  migration/5[45]                     0.000      0.000      0.000
         2090450.763622 [0006]  migration/6[51]                     0.000      0.000      0.000
         2090450.763660 [0007]  migration/7[57]                     0.000      0.000      0.000
         2090450.763741 [0009]  migration/9[69]                     0.000      0.000      0.000
         2090450.763862 [0010]  migration/10[75]                    0.000      0.000      0.000
         2090450.763894 [0011]  migration/11[81]                    0.000      0.000      0.000
         2090450.764021 [0012]  migration/12[87]                    0.000      0.000      0.000
         2090450.764056 [0013]  migration/13[93]                    0.000      0.000      0.000
         2090450.764135 [0014]  migration/14[99]                    0.000      0.000      0.000
         2090450.764163 [0015]  migration/15[105]                   0.000      0.000      0.000
         2090450.764292 [0016]  migration/16[111]                   0.000      0.000      0.000
         2090450.764371 [0017]  migration/17[117]                   0.000      0.000      0.000
         2090450.764422 [0018]  migration/18[123]                   0.000      0.000      0.000
         2090450.764490 [0000]  <idle>                              0.000      0.000      1.255
         2090450.764505 [0000]  s1-perf[8235/7168]                  0.000      0.000      0.000
         2090450.764571 [0016]  <idle>                              0.000      0.000      0.278
         2090450.764588 [0010]  <idle>                              0.000      0.000      0.725
         2090450.764590 [0016]  s1-agent[7179/7162]                 0.000      0.000      0.000
         2090450.764635 [0000]  <idle>                              0.015      0.015      0.129
         2090450.764637 [0017]  <idle>                              0.000      0.000      0.266
         2090450.764639 [0000]  s1-perf[8235/7168]                  0.000      0.000      0.000
         2090450.764668 [0017]  s1-agent[7180/7162]                 0.000      0.000      0.000
         2090450.764669 [0000]  <idle>                              0.003      0.003      0.029
         2090450.764672 [0000]  s1-perf[8235/7168]                  0.000      0.000      0.000
         2090450.764683 [0000]  <idle>                              0.003      0.003      0.010
      
      After:
      
        # perf sched timehist -I
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
         2090450.764490 [0000]  <idle>                              0.000      0.000      1.255
         2090450.764571 [0016]  <idle>                              0.000      0.000      0.278
         2090450.764588 [0010]  <idle>                              0.000      0.000      0.725
         2090450.764635 [0000]  <idle>                              0.015      0.015      0.129
         2090450.764637 [0017]  <idle>                              0.000      0.000      0.266
         2090450.764669 [0000]  <idle>                              0.003      0.003      0.029
         2090450.764683 [0000]  <idle>                              0.003      0.003      0.010
         2090450.764688 [0016]  <idle>                              0.019      0.019      0.097
         2090450.764694 [0000]  <idle>                              0.001      0.001      0.009
         2090450.764706 [0000]  <idle>                              0.001      0.001      0.010
         2090450.764725 [0002]  <idle>                              0.000      0.000      1.415
         2090450.764728 [0000]  <idle>                              0.002      0.002      0.019
         2090450.764823 [0000]  <idle>                              0.003      0.003      0.091
         2090450.764838 [0019]  <idle>                              0.000      0.000      0.154
         2090450.764865 [0002]  <idle>                              0.109      0.109      0.029
         2090450.764866 [0000]  <idle>                              0.012      0.012      0.030
         2090450.764880 [0002]  <idle>                              0.013      0.013      0.001
         2090450.764880 [0000]  <idle>                              0.002      0.002      0.011
         2090450.764896 [0000]  <idle>                              0.001      0.001      0.013
         2090450.764903 [0019]  <idle>                              0.063      0.063      0.002
         2090450.764908 [0019]  <idle>                              0.003      0.003      0.001
      
      Fixes: 07235f84 ("perf sched timehist: Add -I/--idle-hist option")
      Signed-off-by: default avatarYang Jihong <yangjihong@bytedance.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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>
      Link: https://lore.kernel.org/r/20240812132606.3126490-1-yangjihong@bytedance.comReviewed-and-tested-by: default avatarMadadi Vineeth Reddy <vineethr@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      575eec21
    • Andi Kleen's avatar
      perf script: Minimize "not reaching sample" for '-F +brstackinsn' · bf0db8c7
      Andi Kleen authored
      In some situations 'perf script -F +brstackinsn' sees a lot of "not
      reaching sample" messages.
      
      This happens when the last LBR block before the sample contains a branch
      that is not in the LBR, and the instruction dumping stops.
      
        $ perf record -b  emacs -Q --batch '()'
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.396 MB perf.data (443 samples) ]
        $ perf script -F +brstackinsn
        ...
                00007f0ab2d171a4        insn: 41 0f 94 c0
                00007f0ab2d171a8        insn: 83 fa 01
                00007f0ab2d171ab        insn: 74 d3                     # PRED 6 cycles [313] 1.00 IPC
                00007f0ab2d17180        insn: 45 84 c0
                00007f0ab2d17183        insn: 74 28
                ... not reaching sample ...
      
        $ perf script -F +brstackinsn | grep -c reach
        136
        $
      
      This is a problem for further analysis that wants to see the full code
      upto the sample.
      
      There are two common cases where the message is bogus:
      
      - The LBR only logs taken branches, but the branch might be a
        conditional branch that is not taken (that is the most common case
        actually)
      
      - The LBR sampling uses a filter ignoring some branches, but the perf
        script check checks for all branches.
      
      This patch fixes these two conditions, by only checking for conditional
      branches, as well as checking the perf_event_attr's branch filter
      attributes.
      
      For the test case above it fixes all the messages:
      
        $ ./perf script -F +brstackinsn | grep -c reach
        0
      
      Note that there are still conditions when the message is hit --
      sometimes there can be a unconditional branch that misses the LBR update
      before the sample -- but they are much more rare now.
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Link: https://lore.kernel.org/r/20240229161828.386397-1-ak@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      bf0db8c7
    • Namhyung Kim's avatar
      perf record offcpu: Constify control data for BPF · 8b3b1bb3
      Namhyung Kim authored
      The control knobs set before loading BPF programs should be declared as
      'const volatile' so that it can be optimized by the BPF core.
      
      Committer testing:
      
        root@x1:~# perf record --off-cpu
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 1.807 MB perf.data (5645 samples) ]
      
        root@x1:~# perf evlist
        cpu_atom/cycles/P
        cpu_core/cycles/P
        offcpu-time
        dummy:u
        root@x1:~# perf evlist -v
        cpu_atom/cycles/P: type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0xa00000000, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, disabled: 1, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1
        cpu_core/cycles/P: type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0x400000000, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, disabled: 1, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1
        offcpu-time: type: 1 (software), size: 136, config: 0xa (PERF_COUNT_SW_BPF_OUTPUT), { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, disabled: 1, inherit: 1, freq: 1, sample_id_all: 1
        dummy:u: type: 1 (software), size: 136, config: 0x9 (PERF_COUNT_SW_DUMMY), { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|IDENTIFIER, read_format: ID|LOST, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
        root@x1:~# perf trace -e bpf --max-events 5 perf record --off-cpu
             0.000 ( 0.015 ms): :2949124/2949124 bpf(cmd: 36, uattr: 0x7ffefc6dbe30, size: 8)          = -1 EOPNOTSUPP (Operation not supported)
             0.031 ( 0.115 ms): :2949124/2949124 bpf(cmd: PROG_LOAD, uattr: 0x7ffefc6dbb60, size: 148) = 14
             0.159 ( 0.037 ms): :2949124/2949124 bpf(cmd: PROG_LOAD, uattr: 0x7ffefc6dbc20, size: 148) = 14
            23.868 ( 0.144 ms): perf/2949124 bpf(cmd: PROG_LOAD, uattr: 0x7ffefc6dbad0, size: 148)     = 14
            24.027 ( 0.014 ms): perf/2949124 bpf(uattr: 0x7ffefc6dbc80, size: 80)                      = 14
        root@x1:~#
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240902200515.2103769-6-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8b3b1bb3
    • Namhyung Kim's avatar
      perf lock contention: Constify control data for BPF · 4afdc00c
      Namhyung Kim authored
      The control knobs set before loading BPF programs should be declared as
      'const volatile' so that it can be optimized by the BPF core.
      
      Committer testing:
      
        root@x1:~# perf lock contention --use-bpf
         contended   total wait     max wait     avg wait         type   caller
      
                 5     31.57 us     14.93 us      6.31 us        mutex   btrfs_delayed_update_inode+0x43
                 1     16.91 us     16.91 us     16.91 us      rwsem:R   btrfs_tree_read_lock_nested+0x1b
                 1     15.13 us     15.13 us     15.13 us     spinlock   btrfs_getattr+0xd1
                 1      6.65 us      6.65 us      6.65 us      rwsem:R   btrfs_tree_read_lock_nested+0x1b
                 1      4.34 us      4.34 us      4.34 us     spinlock   process_one_work+0x1a9
        root@x1:~#
        root@x1:~# perf trace -e bpf --max-events 10 perf lock contention --use-bpf
             0.000 ( 0.013 ms): :2948281/2948281 bpf(cmd: 36, uattr: 0x7ffd5f12d730, size: 8)          = -1 EOPNOTSUPP (Operation not supported)
             0.024 ( 0.120 ms): :2948281/2948281 bpf(cmd: PROG_LOAD, uattr: 0x7ffd5f12d460, size: 148) = 16
             0.158 ( 0.034 ms): :2948281/2948281 bpf(cmd: PROG_LOAD, uattr: 0x7ffd5f12d520, size: 148) = 16
            26.653 ( 0.154 ms): perf/2948281 bpf(cmd: PROG_LOAD, uattr: 0x7ffd5f12d3d0, size: 148)     = 16
            26.825 ( 0.014 ms): perf/2948281 bpf(uattr: 0x7ffd5f12d580, size: 80)                      = 16
            87.924 ( 0.038 ms): perf/2948281 bpf(cmd: BTF_LOAD, uattr: 0x7ffd5f12d400, size: 40)       = 16
            87.988 ( 0.006 ms): perf/2948281 bpf(cmd: BTF_LOAD, uattr: 0x7ffd5f12d470, size: 40)       = 16
            88.019 ( 0.006 ms): perf/2948281 bpf(cmd: BTF_LOAD, uattr: 0x7ffd5f12d250, size: 40)       = 16
            88.029 ( 0.172 ms): perf/2948281 bpf(cmd: PROG_LOAD, uattr: 0x7ffd5f12d320, size: 148)     = 17
            88.217 ( 0.005 ms): perf/2948281 bpf(cmd: BTF_LOAD, uattr: 0x7ffd5f12d4d0, size: 40)       = 16
        root@x1:~#
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240902200515.2103769-5-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      4afdc00c
    • Namhyung Kim's avatar
      perf kwork: Constify control data for BPF · 066fd840
      Namhyung Kim authored
      The control knobs set before loading BPF programs should be declared as
      'const volatile' so that it can be optimized by the BPF core.
      
      Committer testing:
      
        root@x1:~# perf kwork report --use-bpf
        Starting trace, Hit <Ctrl+C> to stop and report
        ^C
          Kwork Name                     | Cpu  | Total Runtime | Count     | Max runtime   | Max runtime start   | Max runtime end     |
         --------------------------------------------------------------------------------------------------------------------------------
          (w)intel_atomic_commit_work [  | 0009 |     18.680 ms |         2 |     18.553 ms |     362410.681580 s |     362410.700133 s |
          (w)pm_runtime_work             | 0007 |     13.300 ms |         1 |     13.300 ms |     362410.254996 s |     362410.268295 s |
          (w)intel_atomic_commit_work [  | 0009 |      9.846 ms |         2 |      9.717 ms |     362410.172352 s |     362410.182069 s |
          (w)acpi_ec_event_processor     | 0002 |      8.106 ms |         1 |      8.106 ms |     362410.463187 s |     362410.471293 s |
          (s)SCHED:7                     | 0000 |      1.351 ms |       106 |      0.063 ms |     362410.658017 s |     362410.658080 s |
          i915:157                       | 0008 |      0.994 ms |        13 |      0.361 ms |     362411.222125 s |     362411.222486 s |
          (s)SCHED:7                     | 0001 |      0.703 ms |        98 |      0.047 ms |     362410.245004 s |     362410.245051 s |
          (s)SCHED:7                     | 0005 |      0.674 ms |        42 |      0.074 ms |     362411.483039 s |     362411.483113 s |
          (s)NET_RX:3                    | 0001 |      0.556 ms |        10 |      0.079 ms |     362411.066388 s |     362411.066467 s |
        <SNIP>
      
        root@x1:~# perf trace -e bpf --max-events 5 perf kwork report --use-bpf
             0.000 ( 0.016 ms): perf/2948007 bpf(cmd: 36, uattr: 0x7ffededa6660, size: 8)          = -1 EOPNOTSUPP (Operation not supported)
             0.026 ( 0.106 ms): perf/2948007 bpf(cmd: PROG_LOAD, uattr: 0x7ffededa6390, size: 148) = 12
             0.152 ( 0.032 ms): perf/2948007 bpf(cmd: PROG_LOAD, uattr: 0x7ffededa6450, size: 148) = 12
            26.247 ( 0.138 ms): perf/2948007 bpf(cmd: PROG_LOAD, uattr: 0x7ffededa6300, size: 148) = 12
            26.396 ( 0.012 ms): perf/2948007 bpf(uattr: 0x7ffededa64b0, size: 80)                  = 12
        Starting trace, Hit <Ctrl+C> to stop and report
        root@x1:~#
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: Yang Jihong <yangjihong@bytedance.com>
      Link: https://lore.kernel.org/r/20240902200515.2103769-4-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      066fd840
    • Namhyung Kim's avatar
      perf ftrace latency: Constify control data for BPF · ac5a23b2
      Namhyung Kim authored
      The control knobs set before loading BPF programs should be declared as
      'const volatile' so that it can be optimized by the BPF core.
      
      Committer testing:
      
        root@x1:~# perf ftrace latency --use-bpf -T schedule
        ^C#   DURATION     |      COUNT | GRAPH                                          |
             0 - 1    us |          0 |                                                |
             1 - 2    us |          0 |                                                |
             2 - 4    us |          0 |                                                |
             4 - 8    us |          0 |                                                |
             8 - 16   us |          1 |                                                |
            16 - 32   us |          5 |                                                |
            32 - 64   us |          2 |                                                |
            64 - 128  us |          6 |                                                |
           128 - 256  us |          7 |                                                |
           256 - 512  us |          5 |                                                |
           512 - 1024 us |         22 | #                                              |
             1 - 2    ms |         36 | ##                                             |
             2 - 4    ms |         68 | #####                                          |
             4 - 8    ms |         22 | #                                              |
             8 - 16   ms |         91 | #######                                        |
            16 - 32   ms |         11 |                                                |
            32 - 64   ms |         26 | ##                                             |
            64 - 128  ms |        213 | #################                              |
           128 - 256  ms |         19 | #                                              |
           256 - 512  ms |         14 | #                                              |
           512 - 1024 ms |          5 |                                                |
             1 - ...   s |          8 |                                                |
        root@x1:~#
      
        root@x1:~# perf trace -e bpf perf ftrace latency --use-bpf -T schedule
           0.000 ( 0.015 ms): perf/2944525 bpf(cmd: 36, uattr: 0x7ffe80de7b40, size: 8)                          = -1 EOPNOTSUPP (Operation not supported)
           0.025 ( 0.102 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7870, size: 148)                 = 8
           0.136 ( 0.026 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7930, size: 148)                 = 8
           0.174 ( 0.026 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de77e0, size: 148)                 = 8
           0.205 ( 0.010 ms): perf/2944525 bpf(uattr: 0x7ffe80de7990, size: 80)                                  = 8
           0.227 ( 0.011 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7810, size: 40)                   = 8
           0.244 ( 0.004 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7880, size: 40)                   = 8
           0.257 ( 0.006 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7660, size: 40)                   = 8
           0.265 ( 0.058 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7730, size: 148)                 = 9
           0.330 ( 0.004 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de78e0, size: 40)                   = 8
           0.337 ( 0.003 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7890, size: 40)                   = 8
           0.343 ( 0.004 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7880, size: 40)                   = 8
           0.349 ( 0.003 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de78b0, size: 40)                   = 8
           0.355 ( 0.004 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7890, size: 40)                   = 8
           0.361 ( 0.003 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de78b0, size: 40)                   = 8
           0.367 ( 0.003 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7880, size: 40)                   = 8
           0.373 ( 0.014 ms): perf/2944525 bpf(cmd: BTF_LOAD, uattr: 0x7ffe80de7a00, size: 40)                   = 8
           0.390 ( 0.358 ms): perf/2944525 bpf(uattr: 0x7ffe80de7950, size: 80)                                  = 9
           0.763 ( 0.014 ms): perf/2944525 bpf(uattr: 0x7ffe80de7950, size: 80)                                  = 9
           0.783 ( 0.011 ms): perf/2944525 bpf(uattr: 0x7ffe80de7950, size: 80)                                  = 9
           0.798 ( 0.017 ms): perf/2944525 bpf(uattr: 0x7ffe80de7950, size: 80)                                  = 9
           0.819 ( 0.003 ms): perf/2944525 bpf(uattr: 0x7ffe80de7700, size: 80)                                  = 9
           0.824 ( 0.047 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de76c0, size: 148)                 = 10
           0.878 ( 0.008 ms): perf/2944525 bpf(uattr: 0x7ffe80de7950, size: 80)                                  = 9
           0.891 ( 0.014 ms): perf/2944525 bpf(cmd: MAP_UPDATE_ELEM, uattr: 0x7ffe80de79e0, size: 32)            = 0
           0.910 ( 0.103 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7880, size: 148)                 = 9
           1.016 ( 0.143 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7880, size: 148)                 = 10
           3.777 ( 0.068 ms): perf/2944525 bpf(cmd: PROG_LOAD, uattr: 0x7ffe80de7570, size: 148)                 = 12
           3.848 ( 0.003 ms): perf/2944525 bpf(cmd: LINK_CREATE, uattr: 0x7ffe80de7550, size: 64)                = -1 EBADF (Bad file descriptor)
           3.859 ( 0.006 ms): perf/2944525 bpf(cmd: LINK_CREATE, uattr: 0x7ffe80de77c0, size: 64)                = 12
           6.504 ( 0.010 ms): perf/2944525 bpf(cmd: LINK_CREATE, uattr: 0x7ffe80de77c0, size: 64)                = 14
      ^C#   DURATION     |      COUNT | GRAPH                                          |
           0 - 1    us |          0 |                                                |
           1 - 2    us |          0 |                                                |
           2 - 4    us |          1 |                                                |
           4 - 8    us |          3 |                                                |
           8 - 16   us |          3 |                                                |
          16 - 32   us |         11 |                                                |
          32 - 64   us |          9 |                                                |
          64 - 128  us |         17 |                                                |
         128 - 256  us |         30 | #                                              |
         256 - 512  us |         20 |                                                |
         512 - 1024 us |         42 | #                                              |
           1 - 2    ms |        151 | ######                                         |
           2 - 4    ms |        106 | ####                                           |
           4 - 8    ms |         18 |                                                |
           8 - 16   ms |        149 | ######                                         |
          16 - 32   ms |         30 | #                                              |
          32 - 64   ms |         17 |                                                |
          64 - 128  ms |        360 | ###############                                |
         128 - 256  ms |         52 | ##                                             |
         256 - 512  ms |         18 |                                                |
         512 - 1024 ms |         28 | #                                              |
           1 - ...   s |          5 |                                                |
        root@x1:~#
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240902200515.2103769-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ac5a23b2
    • Namhyung Kim's avatar
      perf stat: Constify control data for BPF · 76d36854
      Namhyung Kim authored
      The control knobs set before loading BPF programs should be declared as
      'const volatile' so that it can be optimized by the BPF core.
      
      Committer testing:
      
        root@x1:~# perf stat --bpf-counters -e cpu_core/cycles/,cpu_core/instructions/ sleep 1
      
         Performance counter stats for 'sleep 1':
      
                 2,442,583      cpu_core/cycles/
                 2,494,425      cpu_core/instructions/
      
               1.002687372 seconds time elapsed
      
               0.001126000 seconds user
               0.001166000 seconds sys
      
        root@x1:~# perf trace -e bpf --max-events 10 perf stat --bpf-counters -e cpu_core/cycles/,cpu_core/instructions/ sleep 1
             0.000 ( 0.019 ms): perf/2944119 bpf(cmd: OBJ_GET, uattr: 0x7fffdf5cdd40, size: 20)            = 5
             0.021 ( 0.002 ms): perf/2944119 bpf(cmd: OBJ_GET_INFO_BY_FD, uattr: 0x7fffdf5cdcd0, size: 16) = 0
             0.030 ( 0.005 ms): perf/2944119 bpf(cmd: MAP_LOOKUP_ELEM, uattr: 0x7fffdf5ceda0, size: 32)    = 0
             0.037 ( 0.004 ms): perf/2944119 bpf(cmd: LINK_GET_FD_BY_ID, uattr: 0x7fffdf5ced80, size: 12)  = -1 ENOENT (No such file or directory)
             0.189 ( 0.004 ms): perf/2944119 bpf(cmd: 36, uattr: 0x7fffdf5cec10, size: 8)                  = -1 EOPNOTSUPP (Operation not supported)
             0.201 ( 0.095 ms): perf/2944119 bpf(cmd: PROG_LOAD, uattr: 0x7fffdf5ce940, size: 148)         = 10
             0.305 ( 0.026 ms): perf/2944119 bpf(cmd: PROG_LOAD, uattr: 0x7fffdf5cea00, size: 148)         = 10
             0.347 ( 0.012 ms): perf/2944119 bpf(cmd: BTF_LOAD, uattr: 0x7fffdf5ce8e0, size: 40)           = 10
             0.364 ( 0.004 ms): perf/2944119 bpf(cmd: BTF_LOAD, uattr: 0x7fffdf5ce950, size: 40)           = 10
             0.376 ( 0.006 ms): perf/2944119 bpf(cmd: BTF_LOAD, uattr: 0x7fffdf5ce730, size: 40)           = 10
        root@x1:~#
         Performance counter stats for 'sleep 1':
      
                   271,221      cpu_core/cycles/
                   139,150      cpu_core/instructions/
      
               1.002881677 seconds time elapsed
      
               0.001318000 seconds user
               0.001314000 seconds sys
      
        root@x1:~#
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240902200515.2103769-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      76d36854
    • Ian Rogers's avatar
      perf test: Make watchpoint data 32-bits on i386 · 18f41f1b
      Ian Rogers authored
      i386 only supports watchpoints up to size 4, 8 bytes causes extra
      counts and test failures.
      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: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: David Ahern <dsa@cumulusnetworks.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Junhao He <hejunhao3@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yang Jihong <yangjihong@bytedance.com>
      Link: https://lore.kernel.org/r/20240831070415.506194-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      18f41f1b
    • Ian Rogers's avatar
      perf test: Skip uprobe test if probe command isn't present · 91235380
      Ian Rogers authored
      The probe command is dependent on libelf. Skip the test if the
      required probe command isn't present.
      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: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: David Ahern <dsa@cumulusnetworks.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Junhao He <hejunhao3@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yang Jihong <yangjihong@bytedance.com>
      Link: https://lore.kernel.org/r/20240831070415.506194-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      91235380
    • Ian Rogers's avatar
      perf time-utils: Fix 32-bit nsec parsing · 38e2648a
      Ian Rogers authored
      The "time utils" test fails in 32-bit builds:
        ...
        parse_nsec_time("18446744073.709551615")
        Failed. ptime 4294967295709551615 expected 18446744073709551615
        ...
      
      Switch strtoul to strtoull as an unsigned long in 32-bit build isn't
      64-bits.
      
      Fixes: c284d669 ("perf tools: Move parse_nsec_time to time-utils.c")
      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: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: David Ahern <dsa@cumulusnetworks.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Junhao He <hejunhao3@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yang Jihong <yangjihong@bytedance.com>
      Link: https://lore.kernel.org/r/20240831070415.506194-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      38e2648a
    • Ian Rogers's avatar
      perf pmus: Fix name comparisons on 32-bit systems · 6c99903e
      Ian Rogers authored
      The hex PMU suffix maybe 64-bit but the comparisons were "unsigned
      long" or 32-bit on 32-bit systems. This was causing the "PMU name
      comparison" test to fail in a 32-bit build.
      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: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: David Ahern <dsa@cumulusnetworks.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Junhao He <hejunhao3@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yang Jihong <yangjihong@bytedance.com>
      Link: https://lore.kernel.org/r/20240831070415.506194-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6c99903e
    • Steinar H. Gunderson's avatar
      perf annotate: LLVM-based disassembler · 04885681
      Steinar H. Gunderson authored
      Support using LLVM as a disassembler method, allowing helperless
      annotation in non-distro builds. (It is also much faster than
      using libbfd or bfd objdump on binaries with a lot of debug
      information.)
      
      This is nearly identical to the output of llvm-objdump; there are
      some very rare whitespace differences, some minor changes to demangling
      (since we use perf's regular demangling and not LLVM's own) and
      the occasional case where llvm-objdump makes a different choice
      when multiple symbols share the same address.
      
      It should work across all of LLVM's supported architectures, although
      I've only tested 64-bit x86, and finding the right triple from perf's
      idea of machine architecture can sometimes be a bit tricky. Ideally, we
      should have some way of finding the triplet just from the file itself.
      
      Committer notes:
      
      Address this on 32-bit systems by using PRIu64 from inttypes.h
      
           3    17.58 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
            util/llvm-c-helpers.cpp: In function ‘char* make_symbol_relative_string(dso*, const char*, u64, u64)’:
            util/llvm-c-helpers.cpp:150:52: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘u64’ {aka
        +‘long long unsigned int’} [-Werror=format=]
              150 |                 snprintf(buf, sizeof(buf), "%s+0x%lx",
                  |                                                  ~~^
                  |                                                    |
                  |                                                    long unsigned int
                  |                                                  %llx
              151 |                          demangled ? demangled : sym_name, addr - base_addr);
                  |                                                            ~~~~~~~~~~~~~~~~
                  |                                                                 |
                  |                                                                 u64 {aka long long unsigned int}
            cc1plus: all warnings being treated as errors
      Signed-off-by: default avatarSteinar H. Gunderson <sesse@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Link: https://lore.kernel.org/r/20240803152008.2818485-3-sesse@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      04885681
    • Steinar H. Gunderson's avatar
      perf annotate: Split out read_symbol() · 6eca7c5a
      Steinar H. Gunderson authored
      The Capstone disassembler code has a useful code snippet to read the
      bytes for a given code symbol into memory. Split it out into its own
      function, so that the LLVM disassembler can use it in the next patch.
      Signed-off-by: default avatarSteinar H. Gunderson <sesse@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Link: https://lore.kernel.org/r/20240803152008.2818485-2-sesse@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6eca7c5a
    • Steinar H. Gunderson's avatar
      perf report: Support LLVM for addr2line() · c3f8644c
      Steinar H. Gunderson authored
      In addition to the existing support for libbfd and calling out to
      an external addr2line command, add support for using libllvm directly.
      
      This is both faster than libbfd, and can be enabled in distro builds
      (the LLVM license has an explicit provision for GPLv2 compatibility).
      
      Thus, it is set as the primary choice if available.
      
      As an example, running 'perf report' on a medium-size profile with
      DWARF-based backtraces took 58 seconds with LLVM, 78 seconds with
      libbfd, 153 seconds with external llvm-addr2line, and I got tired and
      aborted the test after waiting for 55 minutes with external bfd
      addr2line (which is the default for perf as compiled by distributions
      today).
      
      Evidently, for this case, the bfd addr2line process needs 18 seconds (on
      a 5.2 GHz Zen 3) to load the .debug ELF in question, hits the 1-second
      timeout and gets killed during initialization, getting restarted anew
      every time. Having an in-process addr2line makes this much more robust.
      
      As future extensions, libllvm can be used in many other places where
      we currently use libbfd or other libraries:
      
       - Symbol enumeration (in particular, for PE binaries).
       - Demangling (including non-Itanium demangling, e.g. Microsoft
         or Rust).
       - Disassembling (perf annotate).
      
      However, these are much less pressing; most people don't profile PE
      binaries, and perf has non-bfd paths for ELF. The same with demangling;
      the default _cxa_demangle path works fine for most users, and while bfd
      objdump can be slow on large binaries, it is possible to use
      --objdump=llvm-objdump to get the speed benefits.  (It appears
      LLVM-based demangling is very simple, should we want that.)
      
      Tested with LLVM 14, 15, 16, 18 and 19. For some reason, LLVM 12 was not
      correctly detected using feature_check, and thus was not tested.
      
      Committer notes:
      
       Added the name and a __maybe_unused to address:
      
         1    13.50 almalinux:8                   : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-22) (GCC)
          util/srcline.c: In function 'dso__free_a2l':
          util/srcline.c:184:20: error: parameter name omitted
           void dso__free_a2l(struct dso *)
                              ^~~~~~~~~~~~
          make[3]: *** [/git/perf-6.11.0-rc3/tools/build/Makefile.build:158: util] Error 2
      Signed-off-by: default avatarSteinar H. Gunderson <sesse@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Ian Rogers <irogers@google.com>
      Link: https://lore.kernel.org/r/20240803152008.2818485-1-sesse@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c3f8644c
  2. 02 Sep, 2024 1 commit
  3. 30 Aug, 2024 8 commits
    • Yang Jihong's avatar
      perf sched timehist: Fixed timestamp error when unable to confirm event sched_in time · 39c24341
      Yang Jihong authored
      If sched_in event for current task is not recorded, sched_in timestamp
      will be set to end_time of time window interest, causing an error in
      timestamp show. In this case, we choose to ignore this event.
      
      Test scenario:
      
        perf[1229608] does not record the first sched_in event, run time and sch delay are both 0
      
        # perf sched timehist
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
         2090450.763231 [0000]  perf[1229608]                       0.000      0.000      0.000
         2090450.763235 [0000]  migration/0[15]                     0.000      0.001      0.003
         2090450.763263 [0001]  perf[1229608]                       0.000      0.000      0.000
         2090450.763268 [0001]  migration/1[21]                     0.000      0.001      0.004
         2090450.763302 [0002]  perf[1229608]                       0.000      0.000      0.000
         2090450.763309 [0002]  migration/2[27]                     0.000      0.001      0.007
         2090450.763338 [0003]  perf[1229608]                       0.000      0.000      0.000
         2090450.763343 [0003]  migration/3[33]                     0.000      0.001      0.004
      
      Before:
      
        arbitrarily specify a time window of interest, timestamp will be set to an incorrect value
      
        # perf sched timehist --time 100,200
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
             200.000000 [0000]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0001]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0002]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0003]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0004]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0005]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0006]  perf[1229608]                       0.000      0.000      0.000
             200.000000 [0007]  perf[1229608]                       0.000      0.000      0.000
      
       After:
      
        # perf sched timehist --time 100,200
        Samples of sched_switch event do not have callchains.
                   time    cpu  task name                       wait time  sch delay   run time
                                [tid/pid]                          (msec)     (msec)     (msec)
        --------------- ------  ------------------------------  ---------  ---------  ---------
      
      Fixes: 853b7407 ("perf sched timehist: Add option to specify time window of interest")
      Signed-off-by: default avatarYang Jihong <yangjihong@bytedance.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: David Ahern <dsa@cumulusnetworks.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240819024720.2405244-1-yangjihong@bytedance.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      39c24341
    • Namhyung Kim's avatar
      perf lock contention: Fix spinlock and rwlock accounting · 74fd69a3
      Namhyung Kim authored
      The spinlock and rwlock use a single-element per-cpu array to track
      current locks due to performance reason.  But this means the key is
      always available and it cannot simply account lock stats in the array
      because some of them are invalid.
      
      In fact, the contention_end() program in the BPF invalidates the entry
      by setting the 'lock' value to 0 instead of deleting the entry for the
      hashmap.  So it should skip entries with the lock value of 0 in the
      account_end_timestamp().
      
      Otherwise, it'd have spurious high contention on an idle machine:
      
        $ sudo perf lock con -ab -Y spinlock sleep 3
         contended   total wait     max wait     avg wait         type   caller
      
                 8      4.72 s       1.84 s     590.46 ms     spinlock   rcu_core+0xc7
                 8      1.87 s       1.87 s     233.48 ms     spinlock   process_one_work+0x1b5
                 2      1.87 s       1.87 s     933.92 ms     spinlock   worker_thread+0x1a2
                 3      1.81 s       1.81 s     603.93 ms     spinlock   tmigr_update_events+0x13c
                 2      1.72 s       1.72 s     861.98 ms     spinlock   tick_do_update_jiffies64+0x25
                 6     42.48 us     13.02 us      7.08 us     spinlock   futex_q_lock+0x2a
                 1     13.03 us     13.03 us     13.03 us     spinlock   futex_wake+0xce
                 1     11.61 us     11.61 us     11.61 us     spinlock   rcu_core+0xc7
      
      I don't believe it has contention on a spinlock longer than 1 second.
      After this change, it only reports some small contentions.
      
        $ sudo perf lock con -ab -Y spinlock sleep 3
         contended   total wait     max wait     avg wait         type   caller
      
                 4    133.51 us     43.29 us     33.38 us     spinlock   tick_do_update_jiffies64+0x25
                 4     69.06 us     31.82 us     17.27 us     spinlock   process_one_work+0x1b5
                 2     50.66 us     25.77 us     25.33 us     spinlock   rcu_core+0xc7
                 1     28.45 us     28.45 us     28.45 us     spinlock   rcu_core+0xc7
                 1     24.77 us     24.77 us     24.77 us     spinlock   tmigr_update_events+0x13c
                 1     23.34 us     23.34 us     23.34 us     spinlock   raw_spin_rq_lock_nested+0x15
      
      Fixes: b5711042 ("perf lock contention: Use per-cpu array map for spinlocks")
      Reported-by: default avatarXi Wang <xii@google.com>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: bpf@vger.kernel.org
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240828052953.1445862-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      74fd69a3
    • Namhyung Kim's avatar
      perf lock contention: Do not fail EEXIST for update · 36cddd10
      Namhyung Kim authored
      When it updates the lock stat for the first time, it needs to create an
      element in the BPF hash map.
      
      But if there's a concurrent thread waiting for the same lock (like for
      rwsem or rwlock), it might race with the thread and possibly fail to
      update with -EEXIST.
      
      In that case, it can lookup the map again and put the data there instead
      of failing.
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20240830065150.1758962-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      36cddd10
    • Namhyung Kim's avatar
      perf lock contention: Simplify spinlock check · 05a5dd1d
      Namhyung Kim authored
      The LCB_F_SPIN bit is used for spinlock, rwlock and optimistic spinning
      in mutex.  In get_tstamp_elem() it needs to check spinlock and rwlock
      only.  As mutex sets the LCB_F_MUTEX, it can check those two bits and
      reduce the number of operations.
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20240830065150.1758962-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      05a5dd1d
    • Namhyung Kim's avatar
      perf lock contention: Handle error in a single place · 10d6c57c
      Namhyung Kim authored
      It has some duplicate codes to do the same job.  Let's add a label and
      goto there to handle errors in a single place.
      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: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20240830065150.1758962-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      10d6c57c
    • Ian Rogers's avatar
      perf test: Additional pipe tests with pipe output written to a file · ccb90046
      Ian Rogers authored
      Additional pipe tests where piped files are written to disk. This
      means that spotting a file name of "-" isn't a sufficient "is pipe?"
      test.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ccb90046
    • Ian Rogers's avatar
      perf header: Remove repipe option · 2d57c32b
      Ian Rogers authored
      No longer used by `perf inject` the repipe_fd is always -1 and repipe
      is always false. Remove the options and associated code knowing the
      constant values of the removed variables.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2d57c32b
    • Ian Rogers's avatar
      perf inject: Overhaul handling of pipe files · 89d64e72
      Ian Rogers authored
      Previously inject->is_pipe was set if the input or output were a
      pipe. Determining the input was a pipe had to be done prior to
      starting the session and opening the file. This was done by comparing
      the input file name with '-' but it fails if the pipe file is written
      to disk.
      
      Opening a pipe file from disk will correctly set perf_data.is_pipe, but
      this is too late for 'perf inject' and results in a broken file. A
      workaround is 'cat pipe_perf|perf inject -i - ...'.
      
      This change removes inject->is_pipe and changes the dependent
      conditions to use the is_pipe flag on the input
      (inject->session->data) and output files (inject->output). This
      ensures the is_pipe condition reflects things like the header being
      read.
      
      The change removes the use of perf file header repiping, that is
      writing the file header out while reading it in. The case of input
      pipe and output file cannot repipe as the attributes for the file are
      unknown. To resolve this, write the file header when writing to disk
      and as the attributes may be unknown, write them after the data.
      
      Update sessions repipe variable to be trace_event_repipe as those are
      the only events now impacted by it. Update __perf_session__new as the
      repipe_fd no longer needs passing. Fully removing repipe from session
      header reading will be done in a later change.
      
      Committer testing:
      
        root@number:~# perf record -e syscalls:sys_enter_*sleep/max-stack=4/ -o - sleep 0.01 | perf report -i -
        # To display the perf.data header info, please use --header/--header-only options.
        #
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.050 MB - ]
        #
        # Total Lost Samples: 0
        #
        # Samples: 1  of event 'syscalls:sys_enter_clock_nanosleep'
        # Event count (approx.): 1
        #
        # Overhead  Command  Shared Object  Symbol
        # ........  .......  .............  ...............................
        #
           100.00%  sleep    libc.so.6      [.] clock_nanosleep@GLIBC_2.2.5
                    |
                    ---__libc_start_main@@GLIBC_2.34
                       __libc_start_call_main
                       0x562fc2560a9f
                       clock_nanosleep@GLIBC_2.2.5
      
        #
        # (Tip: Create an archive with symtabs to analyse on other machine: perf archive)
        #
        root@number:~# perf record -e syscalls:sys_enter_*sleep/max-stack=4/ -o - sleep 0.01 > pipe.data
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.050 MB - ]
        root@number:~# perf report --stdio -i pipe.data
        # To display the perf.data header info, please use --header/--header-only options.
        #
        #
        # Total Lost Samples: 0
        #
        # Samples: 1  of event 'syscalls:sys_enter_clock_nanosleep'
        # Event count (approx.): 1
        #
        # Overhead  Command  Shared Object  Symbol
        # ........  .......  .............  ...............................
        #
           100.00%  sleep    libc.so.6      [.] clock_nanosleep@GLIBC_2.2.5
                    |
                    ---__libc_start_main@@GLIBC_2.34
                       __libc_start_call_main
                       0x55f775975a9f
                       clock_nanosleep@GLIBC_2.2.5
      
        #
        # (Tip: To set sampling period of individual events use perf record -e cpu/cpu-cycles,period=100001/,cpu/branches,period=10001/ ...)
        #
        root@number:~#
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      89d64e72
  4. 29 Aug, 2024 12 commits
    • Ian Rogers's avatar
      perf header: Allow attributes to be written after data · e9a7053d
      Ian Rogers authored
      With a file, to write data an offset needs to be known. Typically data
      follows the event attributes in a file.
      
      However, if processing a pipe the number of event attributes may not be
      known.
      
      It is convenient in that case to write the attributes after the data.
      
      Expand perf_session__do_write_header() to allow this when the data
      offset and size are known.
      
      This approach may be useful for more than just taking a pipe file to
      write into a data file, `perf inject --itrace` will reserve and
      additional 8kb for attributes, which would be unnecessary if the
      attributes were written after the data.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-6-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e9a7053d
    • Ian Rogers's avatar
      perf header: Fail read if header sections overlap · 10df481f
      Ian Rogers authored
      Buggy perf.data files can have the attributes and data
      overlapping.
      
      For example, when processing pipe data the attributes aren't known and
      so file offset header calculations can consider them not present.
      
      Later this can cause the attributes to overwrite the data. This can be
      seen in:
      
        $ perf record -o - true > a.data
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.059 MB - ]
        $ perf inject -i a.data -o b.data
        $ perf report --stats -i b.data
        0x68 [0]: failed to process type: 510379 [Invalid argument]
        Error:
        failed to process sample
        $
      
      This change makes reading the corrupt file fail:
      
        $ perf report --stats -i b.data
        Perf file header corrupt: Attributes and data overlap
        incompatible file format (rerun with -v to learn more)
        $
      
      Which is more informative.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      10df481f
    • Ian Rogers's avatar
      perf header: Add kerneldoc to 'struct perf_file_header' · d71bbe79
      Ian Rogers authored
      Some of the values are a little strange so add documentation to
      resolve ambiguity.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d71bbe79
    • Ian Rogers's avatar
      perf session: Document 'struct perf_session' and constify its 'auxtrace' member · d9c99310
      Ian Rogers authored
      perf_session is a central data structure to the tool so let's comment
      it. The auxtrace callbacks are never modified in session so constify.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yanteng Si <siyanteng@loongson.cn>
      Cc: Yicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20240829150154.37929-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d9c99310
    • James Clark's avatar
      perf: cs-etm: Print queue number in raw trace dump · 022aa67b
      James Clark authored
      Now that we have overlapping trace IDs it's also useful to know what the
      queue number is to be able to distinguish the source of the trace so
      print it inline. Hide it behind the -v option because it might not be
      obvious to users what the queue number is.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-8-james.clark@linaro.orgSigned-off-by: default avatarJames Clark <james.clark@linaro.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      022aa67b
    • James Clark's avatar
      perf: cs-etm: Support version 0.1 of HW_ID packets · 1506af6d
      James Clark authored
      v0.1 HW_ID packets have a new field that describes which sink each CPU
      writes to. Use the sink ID to link trace ID maps to each other so that
      mappings are shared wherever the sink is shared.
      
      Also update the error message to show that overlapping IDs aren't an
      error in per-thread mode, just not supported. In the future we can
      use the CPU ID from the AUX records, or watch for changing sink IDs on
      HW_ID packets to use the correct decoders.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-7-james.clark@linaro.orgSigned-off-by: default avatarJames Clark <james.clark@linaro.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1506af6d
    • James Clark's avatar
      perf: cs-etm: Only save valid trace IDs into files · 940007ce
      James Clark authored
      This isn't a bug because Perf always masks with
      CORESIGHT_TRACE_ID_VAL_MASK before using these values, but to avoid it
      looking like it could be, make an effort to not save bad values.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Signed-off-by: default avatarJames Clark <james.clark@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-6-james.clark@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      940007ce
    • James Clark's avatar
      perf: cs-etm: Create decoders based on the trace ID mappings · 19c3e4db
      James Clark authored
      Now that each queue has a unique set of trace ID mappings, use this
      list to create the decoders. In unformatted mode just add a single
      mapping so only one decoder is made.
      
      Previously each queue would have a decoder created for each traced CPU
      on the system but this won't work anymore because CPUs can have
      overlapping trace IDs.
      
      This also means that the CORESIGHT_TRACE_ID_UNUSED_FLAG isn't needed
      any more. If mappings aren't added then decoders aren't created, rather
      than needing a flag to suppress creation.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-5-james.clark@linaro.orgSigned-off-by: default avatarJames Clark <james.clark@linaro.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      19c3e4db
    • James Clark's avatar
      perf: cs-etm: Move traceid_list to each queue · 77c123f5
      James Clark authored
      The global list won't work for per-sink trace ID allocations, so put a
      list in each queue where the IDs will be unique to that queue.
      
      To keep the same behavior as before, for version 0 of the HW_ID packets,
      copy all the HW_ID mappings into all queues.
      
      This change doesn't effect the decoders, only trace ID lookups on the
      Perf side. The decoders are still created with global mappings which
      will be fixed in a later commit.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-4-james.clark@linaro.orgSigned-off-by: default avatarJames Clark <james.clark@linaro.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      77c123f5
    • James Clark's avatar
      perf: cs-etm: Allocate queues for all CPUs · 57880a79
      James Clark authored
      Make cs_etm__setup_queue() setup a queue even if it's empty, and
      pre-allocate queues based on the max CPU that was recorded. In per-CPU
      mode aux queues are indexed based on CPU ID even if all CPUs aren't
      recorded, sparse queue arrays aren't used.
      
      This will allow HW_IDs to be saved even if no aux data was received in
      that queue without having to call cs_etm__setup_queue() from two
      different places.
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-3-james.clark@linaro.orgSigned-off-by: default avatarJames Clark <james.clark@linaro.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      57880a79
    • James Clark's avatar
      perf cs-etm: Create decoders after both AUX and HW_ID search passes · b6aa0de9
      James Clark authored
      Both of these passes gather information about how to create the
      decoders. AUX records determine formatted/unformatted, and the HW_IDs
      determine the traceID/metadata mappings.
      
      Therefore it makes sense to cache the information and wait until both
      passes are over until creating the decoders, rather than creating them
      at the first HW_ID found.
      
      This will allow a simplification of the creation process where
      cs_etm_queue->traceid_list will exclusively used to create the decoders,
      rather than the current two methods depending on whether the trace is
      formatted or not.
      
      Previously the sample CPU from the AUX record was used to initialize
      the decoder CPU, but actually sample CPU == AUX queue index in per-CPU
      mode, so saving the sample CPU isn't required.
      
      Similarly formatted/unformatted was used upfront to create the decoders,
      but now it's cached until later.
      Reviewed-by: default avatarAnshuman Khandual <anshuman.khandual@arm.com>
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Signed-off-by: default avatarJames Clark <james.clark@linaro.org>
      Tested-by: default avatarGanapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
      Tested-by: default avatarLeo Yan <leo.yan@arm.com>
      Acked-by: default avatarSuzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20240722101202.26915-2-james.clark@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b6aa0de9
    • Arnaldo Carvalho de Melo's avatar
      Revert "tools build: Remove leftover libcap tests that prevents fast path... · 0fd77ae4
      Arnaldo Carvalho de Melo authored
      Revert "tools build: Remove leftover libcap tests that prevents fast path feature detection from working"
      
      Ian pointed out that the libcap feature test is also used by bpftool, so
      we can't remove it just because perf stopped using it, revert the
      removal of the feature test.
      
      Since both perf and libcap uses the fast path feature detection
      (tools/build/feature/test-all.c), probably the best thing is to keep
      libcap-devel when building perf even it not being used there.
      
      This reverts commit 47b3b643.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0fd77ae4
  5. 28 Aug, 2024 1 commit