Commit Graph

302 Commits

Author SHA1 Message Date
Michael Petlan c4f034f727 perf cpumap: Reduce transitive dependencies on libperf MAX_NR_CPUS
JIRA: https://issues.redhat.com/browse/RHEL-71187

upstream
========
commit 02b5ed8a6a7eb3c9eefe8f26c988e3fea6a69026
Author: Ian Rogers <irogers@google.com>
Date: Thu Dec 5 20:40:29 2024 -0800

description
===========
libperf exposes MAX_NR_CPUS via tools/lib/perf/include/internal/cpumap.h
which is internal.

The preferred dependency should be the definition in tools/perf/perf.h.

Add the includes of perf.h so that MAX_NR_CPUS can be hidden in libperf.

    Reviewed-by: Leo Yan <leo.yan@arm.com>
    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ben Gainey <ben.gainey@arm.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: Kyle Meyer <kyle.meyer@hpe.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/20241206044035.1062032-3-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2025-01-31 11:57:22 +01:00
Michael Petlan 6d67d37891 libsubcmd: Don't free the usage string
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 1a5efc9e13f357abc396dbf445b25d08914c8060
Author: Aditya Gupta <adityag@linux.ibm.com>
Date: Wed Sep 4 11:48:30 2024 +0530

description
===========
Currently, commands which depend on 'parse_options_subcommand()' don't
show the usage string, and instead show '(null)'

    $ ./perf sched
	Usage: (null)

    -D, --dump-raw-trace  dump raw trace in ASCII
    -f, --force           don't complain, do it
    -i, --input <file>    input file name
    -v, --verbose         be more verbose (show symbol address, etc)

'parse_options_subcommand()' is generally expected to initialise the usage
string, with information in the passed 'subcommands[]' array

This behaviour was changed in:

  230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")

Where the generated usage string is deallocated, and usage[0] string is
reassigned as NULL.

As discussed in [1], free the allocated usage string in the main
function itself, and don't reset usage string to NULL in
parse_options_subcommand

With this change, the behaviour is restored.

    $ ./perf sched
        Usage: perf sched [<options>] {record|latency|map|replay|script|timehist}

           -D, --dump-raw-trace  dump raw trace in ASCII
           -f, --force           don't complain, do it
           -i, --input <file>    input file name
           -v, --verbose         be more verbose (show symbol address, etc)

[1]: https://lore.kernel.org/linux-perf-users/htq5vhx6piet4nuq2mmhk7fs2bhfykv52dbppwxmo3s7du2odf@styd27tioc6e/

Fixes: 230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")
    Suggested-by: Namhyung Kim <namhyung@kernel.org>
    Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240904061836.55873-2-adityag@linux.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:43 +01:00
Michael Petlan b8d39186f3 perf sched timehist: Add --prio option
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 9b3a48bbe20d9692e0d456488cd3a6244cac3e3b
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Aug 19 11:30:16 2024 +0800

description
===========
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[1229630]        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: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:43 +01:00
Michael Petlan f0097ed8a2 perf sched timehist: Add --show-prio option
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 3fcd740990dee9404f4f6ebeb7a31f0066849e46
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Aug 19 11:30:15 2024 +0800

description
===========
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: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:43 +01:00
Michael Petlan e49350871c perf sched timehist: Remove redundant BUG_ON in timehist_sched_change_event()
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit b93fb9cf45a99042f4472678fc67afd1de47c32e
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Aug 12 21:26:06 2024 +0800

description
===========
The BUG_ON(thread__tid(thread) != 0) in timehist_sched_change_event() is
redundant, remove it.

No functional change.

Fixes: 07235f84ec ("perf sched timehist: Add -I/--idle-hist option")
    Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:42 +01:00
Michael Petlan 025bd70d47 perf sched timehist: Skip print non-idle task samples when only show idle events
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 575eec218059f90bf07a4e26b531fd6d54fe1769
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Aug 12 21:26:05 2024 +0800

description
===========
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: 07235f84ec ("perf sched timehist: Add -I/--idle-hist option")
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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.com
    Reviewed-and-tested-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:42 +01:00
Michael Petlan 2675c4a4d8 perf sched timehist: Fixed timestamp error when unable to confirm event sched_in time
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 39c243411bdb8fb35777adf49ee32549633c4e12
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Aug 19 10:47:20 2024 +0800

description
===========
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: 853b740711 ("perf sched timehist: Add option to specify time window of interest")
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:42 +01:00
Michael Petlan ca375a6618 perf sched timehist: Fix missing free of session in perf_sched__timehist()
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 6bdf5168b6fb19541b0c1862bdaa596d116c7bfb
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Tue Aug 6 10:35:33 2024 +0800

description
===========
When perf_time__parse_str() fails in perf_sched__timehist(),
need to free session that was previously created, fix it.

Fixes: 853b740711 ("perf sched timehist: Add option to specify time window of interest")
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung 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: 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/20240806023533.1316348-1-yangjihong@bytedance.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:38 +01:00
Michael Petlan ebe8f30f1b perf sched: Use perf_tool__init()
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 41860d49473c0c09dc0a2a4d148047f97aaa2539
Author: Ian Rogers <irogers@google.com>
Date: Mon Aug 12 13:47:10 2024 -0700

description
===========
Use perf_tool__init() so that more uses of 'struct perf_tool' can be const
and not relying on perf_tool__fill_defaults().

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Oliver Upton <oliver.upton@linux.dev>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Song Liu <song@kernel.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20240812204720.631678-19-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:37 +01:00
Michael Petlan 6d5468f9cf perf tool: Constify tool pointers
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 30f29bae9142f34e978a4861ed07aa512af21416
Author: Ian Rogers <irogers@google.com>
Date: Mon Aug 12 13:46:55 2024 -0700

description
===========
The tool pointer (to a struct largely of function pointers) is passed
around but is unchanged except at initialization. Change parameter and
variable types to be const to lower the possibilities of what could
happen with a tool.

    Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Adrian Hunter <adrian.hunter@intel.com>
    Tested-by: Leo Yan <leo.yan@arm.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Oliver Upton <oliver.upton@linux.dev>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Song Liu <song@kernel.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20240812204720.631678-4-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:36 +01:00
Michael Petlan 0e26cb0a10 perf sched map: Add --fuzzy-name option for fuzzy matching in task names
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 306f921e87fc647f1b65c9517d7c97cea854f4f3
Author: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Date: Sun Jul 7 23:57:16 2024 +0530

description
===========
The --fuzzy-name option can be used if fuzzy name matching is required.
For example, "taskname" can be matched to any string that contains
"taskname" as its substring.

Sample output for --task-name wdav --fuzzy-name
=============
 .  *A0  .   .   .   .   -   .   131040.641346 secs A0 => wdavdaemon:62509
 .   A0 *B0  .   .   .   -   .   131040.641378 secs B0 => wdavdaemon:62274
 .  *-   B0  .   .   .   -   .   131040.641379 secs
*C0  .   B0  .   .   .   .   .   131040.641572 secs C0 => wdavdaemon:62283
 C0  .   B0  .  *D0  .   .   .   131040.641572 secs D0 => wdavdaemon:62277
 C0  .   B0  .   D0  .  *E0  .   131040.641578 secs E0 => wdavdaemon:62270
*-   .   B0  .   D0  .   E0  .   131040.641581 secs

    Suggested-by: Chen Yu <yu.c.chen@intel.com>
    Reviewed-and-tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240707182716.22054-4-vineethr@linux.ibm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:00 +02:00
Michael Petlan bf0b3a4b82 perf sched map: Add support for multiple task names using CSV
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 9cc0afed6fdc46a96501baa49527fa00aaef37b1
Author: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Date: Sun Jul 7 23:57:15 2024 +0530

description
===========
To track the scheduling patterns of multiple tasks simultaneously,
multiple task names can be specified using a comma separator
without any whitespace.

Sample output for --task-name perf,wdavdaemon
=============
 .  *A0  .   .   .   .   -   .   131040.641346 secs A0 => wdavdaemon:62509
 .   A0 *B0  .   .   .   -   .   131040.641378 secs B0 => wdavdaemon:62274
 .  *-   B0  .   .   .   -   .   131040.641379 secs
*C0  .   B0  .   .   .   .   .   131040.641572 secs C0 => wdavdaemon:62283

...

 .  *-   .   .   .   .   .   .   131041.395649 secs
 .   .   .   .   .   .   .  *X2  131041.403969 secs X2 => perf:70211
 .   .   .   .   .   .   .  *-   131041.404006 secs

    Suggested-by: Namhyung Kim <namhyung@kernel.org>
    Reviewed-and-tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Cc: Chen Yu <yu.c.chen@intel.com>
    Link: https://lore.kernel.org/r/20240707182716.22054-3-vineethr@linux.ibm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:00 +02:00
Michael Petlan ea92de5a57 perf sched map: Add task-name option to filter the output map
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 3116d6091081ad6038db6d68bca9d7b84ba0b7f0
Author: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Date: Sun Jul 7 23:57:14 2024 +0530

description
===========
By default, perf sched map prints sched-in events for all the tasks
which may not be required all the time as it prints lot of symbols
and rows to the terminal.

With --task-name option, one could specify the specific task name
for which the map has to be shown. This would help in analyzing the
CPU usage patterns easier for that specific task. Since multiple
PID's might have the same task name, using task-name filter
would be more useful for debugging.

For other tasks, instead of printing the symbol, '-' is printed and
the same '.' is used to represent idle. '-' is used instead of symbol
for other tasks because it helps in clear visualization of task
of interest and secondly the symbol itself doesn't mean anything
because the sched-in of that symbol will not be printed(first sched-in
contains pid and the corresponding symbol).

When using the --task-name option, the sched-out time is represented
by a '*-'. Since not all task sched-in events are printed, the sched-out
time of the relevant task might be lost. This representation ensures
that the sched-out time of the interested task is not overlooked.

6.10.0-rc1
==========
*A0                              131040.639793 secs A0 => migration/0:19
*.                               131040.639801 secs .  => swapper:0
 .  *B0                          131040.639830 secs B0 => migration/1:24
 .  *.                           131040.639836 secs
 .   .  *C0                      131040.640108 secs C0 => migration/2:30
 .   .  *.                       131040.640163 secs
 .   .   .  *D0                  131040.640386 secs D0 => migration/3:36
 .   .   .  *.                   131040.640395 secs

6.10.0-rc1 + patch (--task-name wdavdaemon)
=============
 .  *A0  .   .   .   .   -   .   131040.641346 secs A0 => wdavdaemon:62509
 .   A0 *B0  .   .   .   -   .   131040.641378 secs B0 => wdavdaemon:62274
 -  *-   B0  .   .   .   -   .   131040.641379 secs
*C0  .   B0  .   .   .   .   .   131040.641572 secs C0 => wdavdaemon:62283
 C0  .   B0  .  *D0  .   .   .   131040.641572 secs D0 => wdavdaemon:62277
 C0  .   B0  .   D0  .  *E0  .   131040.641578 secs E0 => wdavdaemon:62270
*-   .   B0  .   D0  .   E0  .   131040.641581 secs
 .   .   B0  .   D0  .  *-   .   131040.641583 secs

    Reviewed-and-tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Cc: Chen Yu <yu.c.chen@intel.com>
    Link: https://lore.kernel.org/r/20240707182716.22054-2-vineethr@linux.ibm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:00 +02:00
Michael Petlan 436678c14f perf sched replay: Fix -r/--repeat command line option for infinity
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit a7cacaa0880e427642cb305010ea2a62c7b0e1ac
Author: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Date: Fri Jun 28 12:48:21 2024 +0530

description
===========
Currently, the -r/--repeat option accepts values from 0 and complains
for -1. The help section specifies:
-r, --repeat <n>      repeat the workload replay N times (-1: infinite)

The -r -1 option raises an error because replay_repeat is defined as
an unsigned int.

In the current implementation, the workload is repeated n times when
-r <n> is used, except when n is 0.

When -r is set to 0, the workload is also repeated once. This happens
because when -r=0, the run_one_test function is not called. (Note that
mutex unlocking, which is essential for child threads spawned to emulate
the workload, happens in run_one_test.) However, mutex unlocking is
still performed in the destroy_tasks function. Thus, -r=0 results in the
workload running once coincidentally.

To clarify and maintain the existing logic for -r >= 1 (which runs the
workload the specified number of times) and to fix the issue with infinite
runs, make -r=0 perform an infinite run.

    Reviewed-by: James Clark <james.clark@arm.com>
    Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Link: https://lore.kernel.org/r/20240628071821.15264-1-vineethr@linux.ibm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:00 +02:00
Michael Petlan a727f3ae25 perf: Timehist account sch delay for scheduled out running
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit d363c2a880c611eea3d754a618b6125bac7f3044
Author: Fernand Sieber <sieberf@amazon.com>
Date: Tue Jun 18 11:03:39 2024 +0200

description
===========
When using perf timehist, sch delay is only computed for a waking task,
not for a pre empted task. This patches changes sch delay to account for
both. This makes sense as testing scheduling policy need to consider the
effect of scheduling delay globally, not only for waking tasks.

Example of `perf timehist` report before the patch for `stress` task
competing with each other.

First column is wait time, second column sch delay, third column
runtime.

1.492060 [0000]  s    stress[81]                          1.999      0.000      2.000      R  next: stress[83]
1.494060 [0000]  s    stress[83]                          2.000      0.000      2.000      R  next: stress[81]
1.496060 [0000]  s    stress[81]                          2.000      0.000      2.000      R  next: stress[83]
1.498060 [0000]  s    stress[83]                          2.000      0.000      1.999      R  next: stress[81]

After the patch, it looks like this (note that all wait time is not zero
anymore):

1.492060 [0000]  s    stress[81]                          1.999      1.999      2.000      R  next: stress[83]
1.494060 [0000]  s    stress[83]                          2.000      2.000      2.000      R  next: stress[81]
1.496060 [0000]  s    stress[81]                          2.000      2.000      2.000      R  next: stress[83]
1.498060 [0000]  s    stress[83]                          2.000      2.000      1.999      R  next: stress[81]

    Signed-off-by: Fernand Sieber <sieberf@amazon.com>
    Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240618090339.87482-1-sieberf@amazon.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:58 +02:00
Michael Petlan e68eaf93a4 perf: sched map skips redundant lines with cpu filters
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 231295a186b60e779152ee88a2647a392307431a
Author: Fernand Sieber <sieberf@amazon.com>
Date: Fri Jun 14 09:35:17 2024 +0200

description
===========
perf sched map supports cpu filter.
However, even with cpu filters active, any context switch currently
corresponds to a separate line.
As result, context switches on irrelevant cpus result to redundant lines,
which makes the output particlularly difficult to read on wide
architectures.

Fix it by skipping printing for irrelevant CPUs.

Example snippet of output before fix:

  *B0       1.461147 secs
   B0
   B0
   B0
  *G0       1.517139 secs

After fix:

  *B0       1.461147 secs
  *G0       1.517139 secs

    Signed-off-by: Fernand Sieber <sieberf@amazon.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Reviewed-and-tested-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240614073517.94974-1-sieberf@amazon.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:57 +02:00
Michael Petlan 9b1e2eac72 perf sched: Rename 'switches' column header to 'count' and add usage description, options for latency
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 6fe61cb4aebb07ae1c6e8e136e39e76ca3363107
Author: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Date: Thu Mar 28 14:30:05 2024 +0530

description
===========
Rename 'Switches' to 'Count' and document metrics shown for perf
sched latency output. Also add options possible with perf sched
latency.

Initially, after seeing the output of 'perf sched latency', the term
'Switches' seemed like it's the number of context switches-in for a
particular task, but upon going through the code, it was observed that
it's actually keeping track of number of times a delay was calculated so
that it is used in calculation of the average delay.

Actually, the switches here is a subset of number of context switches-in
because there are some cases where the count is not incremented in
switch-in handler 'add_sched_in_event'. For example when a task is
switched-in while it's state is not ready to run(!= THREAD_WAIT_CPU).

commit d9340c1db3 ("perf sched: Display time in milliseconds,
reorganize output") changed it from the original count to switches.

So, renamed switches to count to make things a bit more clearer and
added the metrics description of latency in the document.

    Reviewed-by: Aditya Gupta <adityag@linux.ibm.com>
    Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
    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: Jiri Olsa <jolsa@kernel.org>
    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/20240328090005.8321-1-vineethr@linux.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:55 +02:00
Michael Petlan 2e6ffb794a perf evsel: Use evsel__name_is() helper
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 09d2056efe0c02b7a589915c004c6e925735d081
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Apr 1 14:27:24 2024 +0800

description
===========
Code cleanup, replace strcmp(evsel__name(evsel, {NAME})) with
evsel__name_is() helper.

No functional change.

Committer notes:

Fix this build error:

          trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
  -       assert(evsel__name_is(trace.syscalls.events.bpf_output), "__augmented_syscalls__");
  +       assert(evsel__name_is(trace.syscalls.events.bpf_output, "__augmented_syscalls__"));

    Reviewed-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Yang Jihong <yangjihong@bytedance.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@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/20240401062724.1006010-3-yangjihong@bytedance.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:45 +02:00
Michael Petlan 59d6853825 perf sched timehist: Fix -g/--call-graph option failure
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 6e4b398770d5023eb6383da9360a23bd537c155b
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Mon Apr 1 14:27:23 2024 +0800

description
===========
When 'perf sched' enables the call-graph recording, sample_type of dummy
event does not have PERF_SAMPLE_CALLCHAIN, timehist_check_attr() checks
that the evsel does not have a callchain, and set show_callchain to 0.

Currently 'perf sched timehist' only saves callchain when processing the
'sched:sched_switch event', timehist_check_attr() only needs to determine
whether the event has PERF_SAMPLE_CALLCHAIN.

Before:

  # perf sched record -g true
  [ perf record: Woken up 0 times to write data ]
  [ perf record: Captured and wrote 4.153 MB perf.data (7536 samples) ]
  # perf sched timehist
  Samples do not have callchains.
             time    cpu  task name                       wait time  sch delay   run time
                          [tid/pid]                          (msec)     (msec)     (msec)
  --------------- ------  ------------------------------  ---------  ---------  ---------
    147851.826019 [0000]  perf[285035]                        0.000      0.000      0.000
    147851.826029 [0000]  migration/0[15]                     0.000      0.003      0.009
    147851.826063 [0001]  perf[285035]                        0.000      0.000      0.000
    147851.826069 [0001]  migration/1[21]                     0.000      0.003      0.006
  <SNIP>

After:

  # perf sched record -g true
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 2.572 MB perf.data (822 samples) ]
  # perf sched timehist
         time cpu task name        waittime  sch delay  runtime
                    [tid/pid]        (msec)  (msec)    (msec)
  ----------- --- ---------------  --------  --------  -----
  4193.035164 [0] perf[277062]        0.000     0.000   0.000 __traceiter_sched_switch <- __traceiter_sched_switch <- __sched_text_start <- preempt_schedule_common <- __cond_resched <- __wait_for_common <- wait_for_completion
  4193.035174 [0] migration/0[15]     0.000     0.003   0.009 __traceiter_sched_switch <- __traceiter_sched_switch <- __sched_text_start <- smpboot_thread_fn <- kthread <- ret_from_fork
  4193.035207 [1] perf[277062]        0.000     0.000   0.000 __traceiter_sched_switch <- __traceiter_sched_switch <- __sched_text_start <- preempt_schedule_common <- __cond_resched <- __wait_for_common <- wait_for_completion
  4193.035214 [1] migration/1[21]     0.000     0.003   0.007 __traceiter_sched_switch <- __traceiter_sched_switch <- __sched_text_start <- smpboot_thread_fn <- kthread <- ret_from_fork
  <SNIP>

Fixes: 9c95e4ef06572349 ("perf evlist: Add evlist__findnew_tracking_event() helper")
    Reviewed-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Yang Jihong <yangjihong@bytedance.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@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>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Link: https://lore.kernel.org/r/20240401062724.1006010-2-yangjihong@bytedance.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:45 +02:00
Michael Petlan 0d81034a79 perf sched: Move curr_pid and cpu_last_switched initialization to perf_sched__{lat|map|replay}()
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit bd2cdf26b9ea000339d54adc82e87fdbf22c21c3
Author: Yang Jihong <yangjihong1@huawei.com>
Date: Tue Feb 6 08:32:27 2024 +0000

description
===========
The curr_pid and cpu_last_switched are used only for the
'perf sched replay/latency/map'. Put their initialization in
perf_sched__{lat|map|replay () to reduce unnecessary actions in other
commands.

Simple functional testing:

  # perf sched record perf bench sched messaging
  # Running 'sched/messaging' benchmark:
  # 20 sender and receiver processes per group
  # 10 groups == 400 processes run

       Total time: 0.209 [sec]
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 16.456 MB perf.data (147907 samples) ]

  # perf sched lat

   -------------------------------------------------------------------------------------------------------------------------------------------
    Task                  |   Runtime ms  | Switches | Avg delay ms    | Max delay ms    | Max delay start           | Max delay end          |
   -------------------------------------------------------------------------------------------------------------------------------------------
    sched-messaging:(401) |   2990.699 ms |    38705 | avg:   0.661 ms | max:  67.046 ms | max start: 456532.624830 s | max end: 456532.691876 s
    qemu-system-x86:(7)   |    179.764 ms |     2191 | avg:   0.152 ms | max:  21.857 ms | max start: 456532.576434 s | max end: 456532.598291 s
    sshd:48125            |      0.522 ms |        2 | avg:   0.037 ms | max:   0.046 ms | max start: 456532.514610 s | max end: 456532.514656 s
  <SNIP>
    ksoftirqd/11:82       |      0.063 ms |        1 | avg:   0.005 ms | max:   0.005 ms | max start: 456532.769366 s | max end: 456532.769371 s
    kworker/9:0-mm_:34624 |      0.233 ms |       20 | avg:   0.004 ms | max:   0.007 ms | max start: 456532.690804 s | max end: 456532.690812 s
    migration/13:93       |      0.000 ms |        1 | avg:   0.004 ms | max:   0.004 ms | max start: 456532.512669 s | max end: 456532.512674 s
   -----------------------------------------------------------------------------------------------------------------
    TOTAL:                |   3180.750 ms |    41368 |
   ---------------------------------------------------

  # echo $?
  0

  # perf sched map
    *A0                                                               456532.510141 secs A0 => migration/0:15
    *.                                                                456532.510171 secs .  => swapper:0
     .  *B0                                                           456532.510261 secs B0 => migration/1:21
     .  *.                                                            456532.510279 secs
  <SNIP>
     L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7 *L7  .   .   .   .    456532.785979 secs
     L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7 *L7  .   .   .    456532.786054 secs
     L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7 *L7  .   .    456532.786127 secs
     L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7 *L7  .    456532.786197 secs
     L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7  L7 *L7   456532.786270 secs
  # echo $?
  0

  # perf sched replay
  run measurement overhead: 108 nsecs
  sleep measurement overhead: 66473 nsecs
  the run test took 1000002 nsecs
  the sleep test took 1082686 nsecs
  nr_run_events:        49334
  nr_sleep_events:      50054
  nr_wakeup_events:     34701
  target-less wakeups:  165
  multi-target wakeups: 766
  task      0 (             swapper:         0), nr_events: 15419
  task      1 (             swapper:         1), nr_events: 1
  task      2 (             swapper:         2), nr_events: 1
  <SNIP>
  task    715 (     sched-messaging:    110248), nr_events: 1438
  task    716 (     sched-messaging:    110249), nr_events: 512
  task    717 (     sched-messaging:    110250), nr_events: 500
  task    718 (     sched-messaging:    110251), nr_events: 537
  task    719 (     sched-messaging:    110252), nr_events: 823
  ------------------------------------------------------------
  #1  : 1325.288, ravg: 1325.29, cpu: 7823.35 / 7823.35
  #2  : 1363.606, ravg: 1329.12, cpu: 7655.53 / 7806.56
  #3  : 1349.494, ravg: 1331.16, cpu: 7544.80 / 7780.39
  #4  : 1311.488, ravg: 1329.19, cpu: 7495.13 / 7751.86
  #5  : 1309.902, ravg: 1327.26, cpu: 7266.65 / 7703.34
  #6  : 1309.535, ravg: 1325.49, cpu: 7843.86 / 7717.39
  #7  : 1316.482, ravg: 1324.59, cpu: 7854.41 / 7731.09
  #8  : 1366.604, ravg: 1328.79, cpu: 7955.81 / 7753.57
  #9  : 1326.286, ravg: 1328.54, cpu: 7466.86 / 7724.90
  #10 : 1356.653, ravg: 1331.35, cpu: 7566.60 / 7709.07
  # echo $?
  0

    Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240206083228.172607-5-yangjihong1@huawei.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:24 +02:00
Michael Petlan 7e541ab343 perf sched: Move curr_thread initialization to perf_sched__map()
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit 5e895278697c014e95ae7ae5e79a72ef68c5184e
Author: Yang Jihong <yangjihong1@huawei.com>
Date: Tue Feb 6 08:32:26 2024 +0000

description
===========
The curr_thread is used only for the 'perf sched map'. Put initialization
in perf_sched__map() to reduce unnecessary actions in other commands.

Simple functional testing:

  # perf sched record perf bench sched messaging
  # Running 'sched/messaging' benchmark:
  # 20 sender and receiver processes per group
  # 10 groups == 400 processes run

       Total time: 0.197 [sec]
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 15.526 MB perf.data (140095 samples) ]

  # perf sched map
    *A0                                                               451264.532445 secs A0 => migration/0:15
    *.                                                                451264.532468 secs .  => swapper:0
     .  *B0                                                           451264.532537 secs B0 => migration/1:21
     .  *.                                                            451264.532560 secs
     .   .  *C0                                                       451264.532644 secs C0 => migration/2:27
     .   .  *.                                                        451264.532668 secs
     .   .   .  *D0                                                   451264.532753 secs D0 => migration/3:33
     .   .   .  *.                                                    451264.532778 secs
     .   .   .   .  *E0                                               451264.532861 secs E0 => migration/4:39
     .   .   .   .  *.                                                451264.532886 secs
     .   .   .   .   .  *F0                                           451264.532973 secs F0 => migration/5:45
  <SNIP>
     A7  A7  A7  A7  A7 *A7  .   .   .   .   .   .   .   .   .   .    451264.790785 secs
     A7  A7  A7  A7  A7  A7 *A7  .   .   .   .   .   .   .   .   .    451264.790858 secs
     A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .   .   .   .   .   .    451264.790934 secs
     A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .   .   .   .   .    451264.791004 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .   .   .   .    451264.791075 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .   .   .    451264.791143 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .   .    451264.791232 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .   .    451264.791336 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .   .    451264.791407 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7  .    451264.791484 secs
     A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7  A7 *A7   451264.791553 secs
  # echo $?
  0

    Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240206083228.172607-4-yangjihong1@huawei.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:24 +02:00
Michael Petlan 25382720ef perf sched: Fix memory leak in perf_sched__map()
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit ef76a5af819743d405674f6de5d0e63320ac653e
Author: Yang Jihong <yangjihong1@huawei.com>
Date: Tue Feb 6 08:32:25 2024 +0000

description
===========
perf_sched__map() needs to free memory of map_cpus, color_pids and
color_cpus in normal path and rollback allocated memory in error path.

    Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240206083228.172607-3-yangjihong1@huawei.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:24 +02:00
Michael Petlan 022432caff perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay()
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit c6907863519cf97ee09653cc8ec338a2328c2b6f
Author: Yang Jihong <yangjihong1@huawei.com>
Date: Tue Feb 6 08:32:24 2024 +0000

description
===========
The start_work_mutex and work_done_wait_mutex are used only for the
'perf sched replay'. Put their initialization in perf_sched__replay () to
reduce unnecessary actions in other commands.

Simple functional testing:

  # perf sched record perf bench sched messaging
  # Running 'sched/messaging' benchmark:
  # 20 sender and receiver processes per group
  # 10 groups == 400 processes run

       Total time: 0.197 [sec]
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 14.952 MB perf.data (134165 samples) ]

  # perf sched replay
  run measurement overhead: 108 nsecs
  sleep measurement overhead: 65658 nsecs
  the run test took 999991 nsecs
  the sleep test took 1079324 nsecs
  nr_run_events:        42378
  nr_sleep_events:      43102
  nr_wakeup_events:     31852
  target-less wakeups:  17
  multi-target wakeups: 712
  task      0 (             swapper:         0), nr_events: 10451
  task      1 (             swapper:         1), nr_events: 3
  task      2 (             swapper:         2), nr_events: 1
  <SNIP>
  task    717 (     sched-messaging:     74483), nr_events: 152
  task    718 (     sched-messaging:     74484), nr_events: 1944
  task    719 (     sched-messaging:     74485), nr_events: 73
  task    720 (     sched-messaging:     74486), nr_events: 163
  task    721 (     sched-messaging:     74487), nr_events: 942
  task    722 (     sched-messaging:     74488), nr_events: 78
  task    723 (     sched-messaging:     74489), nr_events: 1090
  ------------------------------------------------------------
  #1  : 1366.507, ravg: 1366.51, cpu: 7682.70 / 7682.70
  #2  : 1410.072, ravg: 1370.86, cpu: 7723.88 / 7686.82
  #3  : 1396.296, ravg: 1373.41, cpu: 7568.20 / 7674.96
  #4  : 1381.019, ravg: 1374.17, cpu: 7531.81 / 7660.64
  #5  : 1393.826, ravg: 1376.13, cpu: 7725.25 / 7667.11
  #6  : 1401.581, ravg: 1378.68, cpu: 7594.82 / 7659.88
  #7  : 1381.337, ravg: 1378.94, cpu: 7371.22 / 7631.01
  #8  : 1373.842, ravg: 1378.43, cpu: 7894.92 / 7657.40
  #9  : 1364.697, ravg: 1377.06, cpu: 7324.91 / 7624.15
  #10 : 1363.613, ravg: 1375.72, cpu: 7209.55 / 7582.69
  # echo $?
  0

    Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240206083228.172607-2-yangjihong1@huawei.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:24 +02:00
Michael Petlan 695540f2f5 perf sched: Commit to evsel__taskstate() to parse task state info
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit 68f87f24f953cf3147afa01ef123d8fd3c1162b6
Author: Ze Gao <zegao2021@gmail.com>
Date: Mon Jan 22 21:24:25 2024 -0500

description
===========
Now that we have evsel__taskstate() which no longer relies on the
hardcoded task state string and has good backward compatibility,
we have a good reason to use it.

Note TASK_STATE_TO_CHAR_STR and task bitmasks are useless now so
we remove them for good. And now we pass the state info back and
forth in a symbolic char which explains itself well instead.

    Signed-off-by: Ze Gao <zegao@tencent.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Link: https://lore.kernel.org/r/20240123022425.1611483-1-zegao@tencent.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:21 +02:00
Michael Petlan c275110143 perf sched: Sync state char array with the kernel
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit ccc606a7d3122200c102a250d2b73c394a7c3888
Author: Ze Gao <zegao2021@gmail.com>
Date: Mon Jan 22 02:08:56 2024 -0500

description
===========
Update state char array to match the latest kernel definitions and
remove unused state mapping macros.

Note this is the preparing patch for get rid of the way to parse
process state from raw bitmask value. Instead we are going to
parse it from the recorded tracepoint print format, and this change
marks why we're doing it.

    Signed-off-by: Ze Gao <zegao@tencent.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Link: https://lore.kernel.org/r/20240122070859.1394479-3-zegao@tencent.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:20 +02:00
Michael Petlan b3dd1b3bca libperf rc_check: Add RC_CHK_EQUAL
JIRA: https://issues.redhat.com/browse/RHEL-25824

upstream
========
commit 78c32f4cb12f9430e29402118635dcf972b7d325
Author: Ian Rogers <irogers@google.com>
Date: Tue Oct 24 15:23:07 2023 -0700

description
===========
Comparing pointers with reference count checking is tricky to avoid a
SEGV. Add a convenience macro to simplify and use.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: liuwenyu <liuwenyu7@huawei.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Song Liu <song@kernel.org>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Link: https://lore.kernel.org/r/20231024222353.3024098-5-irogers@google.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-04-03 19:37:06 +02:00
Michael Petlan 1cac3901d8 perf sched: Avoid large stack allocations
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 232418a0b2e8b8e72dac003b19352f1b647cdb31
Author: Ian Rogers <irogers@google.com>
Date: Fri May 26 20:43:19 2023 -0700

description
===========
Commit 5ded57ac1b ("perf inject: Remove static variables") moved
static variables to local, however, in this case 3 MAX_CPUS (4096)
sized arrays were moved onto the stack making the stack frame quite
large. Avoid the stack usage by dynamically allocating the arrays.

    Signed-off-by: Ian 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: Jiri Olsa <jolsa@kernel.org>
    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/20230527034324.2597593-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:54 +02:00
Michael Petlan 4fcac7ef38 perf callchain: Use pthread keys for tls callchain_cursor
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 8ab12a2038e36beda4062a8e7562a8cfe9655553
Author: Ian Rogers <irogers@google.com>
Date: Thu Jun 8 16:28:21 2023 -0700

description
===========
Pthread keys are more portable than __thread and allow the association
of a destructor with the key. Use the destructor to clean up TLS
callchain cursors to aid understanding memory leaks.

Committer notes:

Had to fixup a series of unconverted places and also check for the
return of get_tls_callchain_cursor() as it may fail and return NULL.

In that unlikely case we now either print something to a file, if the
caller was expecting to print a callchain, or return an error code to
state that resolving the callchain isn't possible.

In some cases this was made easier because thread__resolve_callchain()
already can fail for other reasons, so this new one (cursor == NULL) can
be added and the callers don't have to explicitely check for this new
condition.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ali Saidi <alisaidi@amazon.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brian Robbins <brianrob@linux.microsoft.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Ivan Babrou <ivan@cloudflare.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
    Cc: Yuan Can <yuancan@huawei.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230608232823.4027869-25-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:49 +02:00
Michael Petlan 6cba3b5df5 perf thread: Add reference count checking
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit f6005cafebab72f8c02100dc896d6cfd5b8918cb
Author: Ian Rogers <irogers@google.com>
Date: Thu Jun 8 16:28:04 2023 -0700

description
===========
Modify struct declaration and accessor functions for the reference
count checkers additional layer of indirection. Make sure pid_cmp in
builtin-sched.c uses the underlying/original struct in pointer
arithmetic, and not the temporary get/put indirection.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ali Saidi <alisaidi@amazon.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brian Robbins <brianrob@linux.microsoft.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Ivan Babrou <ivan@cloudflare.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
    Cc: Yuan Can <yuancan@huawei.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230608232823.4027869-8-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:43 +02:00
Michael Petlan dd3248cc46 perf addr_location: Add init/exit/copy functions
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 0dd5041c9a0eaf8c5c3fd46df4ee60f877799f44
Author: Ian Rogers <irogers@google.com>
Date: Thu Jun 8 16:28:03 2023 -0700

description
===========
struct addr_location holds references to multiple reference counted
objects. Add init/exit functions to make maintenance of those more
consistent with the rest of the code and to try to avoid
leaks. Modification of thread reference counts isn't included in this
change.

Committer notes:

I needed to initialize result to sample->ip to make sure is set to
something, fixing a compile time error, mostly keeping the previous
logic as build_alloc_func_list() already does debugging/error prints
about what went wrong if it takes the 'goto out'.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ali Saidi <alisaidi@amazon.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brian Robbins <brianrob@linux.microsoft.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Ivan Babrou <ivan@cloudflare.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
    Cc: Yuan Can <yuancan@huawei.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230608232823.4027869-7-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:43 +02:00
Michael Petlan 00a1b14546 perf thread: Add accessor functions for thread
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit ee84a3032b74055feed192a727e872b0a18d1140
Author: Ian Rogers <irogers@google.com>
Date: Thu Jun 8 16:28:00 2023 -0700

description
===========
Using accessors will make it easier to add reference count checking in
later patches.

Committer notes:

thread->nsinfo wasn't wrapped as it is used together with
nsinfo__zput(), where does a trick to set the field with a refcount
being dropped to NULL, and that doesn't work well with using
thread__nsinfo(thread), that loses the &thread->nsinfo pointer.

When refcount checking is added to 'struct thread', later in this
series, nsinfo__zput(RC_CHK_ACCESS(thread)->nsinfo) will be used to
check the thread pointer.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ali Saidi <alisaidi@amazon.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brian Robbins <brianrob@linux.microsoft.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Ivan Babrou <ivan@cloudflare.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
    Cc: Yuan Can <yuancan@huawei.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230608232823.4027869-4-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:42 +02:00
Michael Petlan 8b2775faa6 perf thread: Remove notion of dead threads
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 40826c45eb0b88565b5ea3fa98e6c251b193ad4b
Author: Ian Rogers <irogers@google.com>
Date: Thu Jun 8 16:27:58 2023 -0700

description
===========
The dead thread list is best effort. Threads live on it until the
reference count hits zero and they are removed. With correct reference
counting this should never happen. It is, however, part of the 'perf
sched' output that is now removed. If this is an issue we should
implement tracking of dead threads in a robust not best-effort way.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ali Saidi <alisaidi@amazon.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brian Robbins <brianrob@linux.microsoft.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Ivan Babrou <ivan@cloudflare.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
    Cc: Yuan Can <yuancan@huawei.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230608232823.4027869-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:02:41 +02:00
Michael Petlan 14484beb41 perf sched: Fix sched latency analysis incorrection when using 'sched:sched_wakeup'
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 4453deacf44615b2d45a0b5226ff132e830bd03d
Author: Chunxin Zang <zangchunxin@lixiang.com>
Date: Tue Mar 28 14:00:57 2023 +0800

description
===========
'perf sched latency' is incorrect to get process schedule latency when
it used 'sched:sched_wakeup' to analysis perf.data.

Because 'perf record' prefers to use 'sched:sched_waking' to
'sched:sched_wakeup' since commit d566a9c2d4 ("perf sched: Prefer
sched_waking event when it exists"). It's very reasonable to evaluate
process schedule latency.

Similarly, update sched latency/map/replay to use sched_waking events.

    Signed-off-by: Chunxin Zang <zangchunxin@lixiang.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20230328060038.2346935-1-zangchunxin@lixiang.com
    Signed-off-by: Jerry Zhou <zhouchunhua@lixiang.com>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 12:00:36 +02:00
Michael Petlan fc23b5da47 perf util: Move input_name to util
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit f12ad2727bbed890cbc2890470fb00c95b089b28
Author: Ian Rogers <irogers@google.com>
Date: Mon Apr 10 09:25:10 2023 -0700

description
===========
'input_name' is the name of the input perf.data file, it is used by data
convert and ui code. Move it to util to make it more consistent with
other global state.

    Signed-off-by: Ian 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: Chengdong Li <chengdongli@tencent.com>
    Cc: Denis Nikitin <denik@chromium.org>
    Cc: Florian Fischer <florian.fischer@muhq.space>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.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@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Martin Liška <mliska@suse.cz>
    Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Raul Silvera <rsilvera@google.com>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230410162511.3055900-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 12:00:18 +02:00
Michael Petlan cf4a544c87 perf tools: Use dedicated non-atomic clear/set bit helpers
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 49bd97c28b7e7f014a72821fd95fcf11e11599a4
Author: Sean Christopherson <seanjc@google.com>
Date: Sat Nov 19 01:34:46 2022 +0000

description
===========
Use the dedicated non-atomic helpers for {clear,set}_bit() and their
test variants, i.e. the double-underscore versions.  Depsite being
defined in atomic.h, and despite the kernel versions being atomic in the
kernel, tools' {clear,set}_bit() helpers aren't actually atomic.  Move
to the double-underscore versions so that the versions that are expected
to be atomic (for kernel developers) can be made atomic without
affecting users that don't want atomic operations.

No functional change intended.

    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: James Morse <james.morse@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Oliver Upton <oliver.upton@linux.dev>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Yury Norov <yury.norov@gmail.com>
    Cc: alexandru elisei <alexandru.elisei@arm.com>
    Cc: kvm@vger.kernel.org
    Cc: kvmarm@lists.cs.columbia.edu
    Cc: kvmarm@lists.linux.dev
    Cc: linux-arm-kernel@lists.infradead.org
    Link: http://lore.kernel.org/lkml/20221119013450.2643007-6-seanjc@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-05 10:02:18 +02:00
Michael Petlan bbe7137abb perf sched: Factor out destroy_tasks()
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 165da80296ea6bc996eea4551026e39a0109f71e
Author: Namhyung Kim <namhyung@kernel.org>
Date: Thu Sep 8 15:54:48 2022 -0700

description
===========
Add destroy_tasks() as a counterpart of create_tasks() and put the
thread safety notations there.  After join, it destroys semaphores too.

    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220908225448.4105056-1-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:40 +02:00
Michael Petlan 96fda8f393 perf sched: Fixes for thread safety analysis
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 59c266604922898ad8aa1ef881a60eb02fcb385f
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 26 09:42:40 2022 -0700

description
===========
Add annotations to describe lock behavior. Add unlocks so that mutexes
aren't conditionally held on exit from perf_sched__replay. Add an exit
variable so that thread_func can terminate, rather than leaving the
threads blocked on mutexes.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexandre Truong <alexandre.truong@arm.com>
    Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andres Freund <andres@anarazel.de>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: André Almeida <andrealmeid@igalia.com>
    Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
    Cc: Colin Ian King <colin.king@intel.com>
    Cc: Dario Petrillo <dario.pk1@gmail.com>
    Cc: Darren Hart <dvhart@infradead.org>
    Cc: Dave Marchevsky <davemarchevsky@fb.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Fangrui Song <maskray@google.com>
    Cc: Hewenliang <hewenliang4@huawei.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jason Wang <wangborong@cdjrlc.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kim Phillips <kim.phillips@amd.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Martin Liška <mliska@suse.cz>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Pavithra Gurushankar <gpavithrasha@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Remi Bernon <rbernon@codeweavers.com>
    Cc: Riccardo Mancini <rickyman7@gmail.com>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Tom Rix <trix@redhat.com>
    Cc: Weiguo Li <liwg06@foxmail.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: William Cohen <wcohen@redhat.com>
    Cc: Zechuan Chen <chenzechuan1@huawei.com>
    Cc: bpf@vger.kernel.org
    Cc: llvm@lists.linux.dev
    Cc: yaowenbin <yaowenbin1@huawei.com>
    Link: https://lore.kernel.org/r/20220826164242.43412-17-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:37 +02:00
Michael Petlan abd9daffb5 perf sched: Update use of pthread mutex
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 0bd14ac2d6aab7339c4b410543d978cd254b24f9
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 26 09:42:32 2022 -0700

description
===========
Switch to the use of mutex wrappers that provide better error
checking. Update cmd_sched so that we always explicitly destroy the
mutexes.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexandre Truong <alexandre.truong@arm.com>
    Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andres Freund <andres@anarazel.de>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: André Almeida <andrealmeid@igalia.com>
    Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
    Cc: Colin Ian King <colin.king@intel.com>
    Cc: Dario Petrillo <dario.pk1@gmail.com>
    Cc: Darren Hart <dvhart@infradead.org>
    Cc: Dave Marchevsky <davemarchevsky@fb.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Fangrui Song <maskray@google.com>
    Cc: Hewenliang <hewenliang4@huawei.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jason Wang <wangborong@cdjrlc.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kim Phillips <kim.phillips@amd.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Martin Liška <mliska@suse.cz>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Pavithra Gurushankar <gpavithrasha@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Remi Bernon <rbernon@codeweavers.com>
    Cc: Riccardo Mancini <rickyman7@gmail.com>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Tom Rix <trix@redhat.com>
    Cc: Weiguo Li <liwg06@foxmail.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: William Cohen <wcohen@redhat.com>
    Cc: Zechuan Chen <chenzechuan1@huawei.com>
    Cc: bpf@vger.kernel.org
    Cc: llvm@lists.linux.dev
    Cc: yaowenbin <yaowenbin1@huawei.com>
    Link: https://lore.kernel.org/r/20220826164242.43412-9-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:36 +02:00
Michael Petlan 33bb5c03b3 perf sched: Fix memory leaks in __cmd_record detected with -fsanitize=address
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit d72e5cf3cf69d4c68d3b54aea232451b0a8b69d3
Author: Ian Rogers <irogers@google.com>
Date: Wed Aug 24 07:57:33 2022 -0700

description
===========
An array of strings is passed to cmd_record but not freed. As
cmd_record modifies the array, add another array as a copy that can be
mutated allowing the original array contents to all be freed.

Detected with -fsanitize=address.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Link: https://lore.kernel.org/r/20220824145733.409005-1-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:26:04 +01:00
Michael Petlan 5252d1ffc3 perf sched latency: Fix subcommand matching error
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 628881ee06cb41a3c2c4e4e3f04ff3dc6779cd12
Author: Yang Jihong <yangjihong1@huawei.com>
Date: Mon Aug 8 17:24:08 2022 +0800

description
===========
perf sched latency use strncmp to match subcommands which matching does not
meet expectation.

Before:

  # perf sched lat1234 >/dev/null
  # echo $?
  0
  #

Solution: Use strstarts to match subcommand.

After:

   # perf sched lat1234

   Usage: perf sched [<options>] {record|latency|map|replay|script|timehist}

      -D, --dump-raw-trace  dump raw trace in ASCII
      -f, --force           don't complain, do it
      -i, --input <file>    input file name
      -v, --verbose         be more verbose (show symbol address, etc)

  # echo $?
  129
  #
  # perf sched lat >/dev/null
  # echo $?
  0
  #

    Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220808092408.107399-3-yangjihong1@huawei.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:57 +01:00
Michael Petlan c371ffa18c perf tools: Enhance the matching of sub-commands abbreviations
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit ae0f4eb34fc3014f7eba78fab90a0e98e441a4cd
Author: Wei Li <liwei391@huawei.com>
Date: Fri Mar 25 17:20:32 2022 +0800

description
===========
We support short command 'rec*' for 'record' and 'rep*' for 'report' in
lots of sub-commands, but the matching is not quite strict currnetly.

It may be puzzling sometime, like we mis-type a 'recport' to report but
it will perform 'record' in fact without any message.

To fix this, add a check to ensure that the short cmd is valid prefix
of the real command.

Committer testing:

  [root@quaco ~]# perf c2c re sleep 1

   Usage: perf c2c {record|report}

      -v, --verbose         be more verbose (show counter open errors, etc)

  # perf c2c rec sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.038 MB perf.data (16 samples) ]
  # perf c2c recport sleep 1

   Usage: perf c2c {record|report}

      -v, --verbose         be more verbose (show counter open errors, etc)

  # perf c2c record sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.038 MB perf.data (15 samples) ]
  # perf c2c records sleep 1

   Usage: perf c2c {record|report}

      -v, --verbose         be more verbose (show counter open errors, etc)

  #

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:22:55 +02:00
Michael Petlan 86ce88496c perf cpumap: Give CPUs their own type
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit 6d18804b963b78dcd53851f11e9080408b3d85c2
Author: Ian Rogers <irogers@google.com>
Date: Tue Jan 4 22:13:51 2022 -0800

description
===========
A common problem is confusing CPU map indices with the CPU, by wrapping
the CPU with a struct then this is avoided. This approach is similar to
atomic_t.

Committer notes:

To make it build with BUILD_BPF_SKEL=1 these files needed the
conversions to 'struct perf_cpu' usage:

  tools/perf/util/bpf_counter.c
  tools/perf/util/bpf_counter_cgroup.c
  tools/perf/util/bpf_ftrace.c

Also perf_env__get_cpu() was removed back in "perf cpumap: Switch
cpu_map__build_map to cpu function".

Additionally these needed to be fixed for the ARM builds to complete:

  tools/perf/arch/arm/util/cs-etm.c
  tools/perf/arch/arm64/util/pmu.c

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:36:01 +02:00
Michael Petlan 5ed18595ce perf cpumap: Move 'has' function to libperf
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit dfc66beff7fa95b9eb507ccb48fb325569bc2f74
Author: Ian Rogers <irogers@google.com>
Date: Tue Jan 4 22:13:23 2022 -0800

description
===========
Make the cpu map argument const for consistency with the rest of the
API. Modify cpu_map__idx accordingly.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:54 +02:00
Michael Petlan de451198af perf tools: Check vmlinux/kallsyms arguments in all tools
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit 7cc72553ac03ec20afe2dec91dce4624ccd379b8
Author: James Clark <james.clark@arm.com>
Date: Mon Oct 18 14:48:42 2021 +0100

description
===========
Only perf report checked the validity of these arguments so apply the
same check to all tools that read them for consistency.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:11 +02:00
Michael Petlan 1df7d85569 perf tools: Remove repipe argument from perf_session__new()
Bugzilla: https://bugzilla.redhat.com/2069070

upstream
========
commit 2681bd85a4b92788e265934d0d76bd56b5b08d16
Author: Namhyung Kim <namhyung@kernel.org>
Date: Mon Jul 19 15:31:49 2021 -0700

description
===========
The repipe argument is only used by perf inject and the all others
passes 'false'.  Let's remove it from the function signature and add
__perf_session__new() to be called from perf inject directly.

This is a preparation of the change the pipe input/output.

[ Fixed up some trivial conflicts as this patchset fell thru the cracks ;-( ]

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-04-25 12:33:02 +02:00
Yang Jihong b0f008551f perf sched: Fix record failure when CONFIG_SCHEDSTATS is not set
The tracepoints trace_sched_stat_{wait, sleep, iowait} are not exposed to user
if CONFIG_SCHEDSTATS is not set, "perf sched record" records the three events.
As a result, the command fails.

Before:

  #perf sched record sleep 1
  event syntax error: 'sched:sched_stat_wait'
                       \___ unknown tracepoint

  Error:  File /sys/kernel/tracing/events/sched/sched_stat_wait not found.
  Hint:   Perhaps this kernel misses some CONFIG_ setting to enable this feature?.

  Run 'perf list' for a list of valid events

   Usage: perf record [<options>] [<command>]
      or: perf record [<options>] -- <command> [<options>]

      -e, --event <event>   event selector. use 'perf list' to list available events

Solution:
  Check whether schedstat tracepoints are exposed. If no, these events are not recorded.

After:
  # perf sched record sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.163 MB perf.data (1091 samples) ]
  # perf sched report
  run measurement overhead: 4736 nsecs
  sleep measurement overhead: 9059979 nsecs
  the run test took 999854 nsecs
  the sleep test took 8945271 nsecs
  nr_run_events:        716
  nr_sleep_events:      785
  nr_wakeup_events:     0
  ...
  ------------------------------------------------------------

Fixes: 2a09b5de23 ("sched/fair: do not expose some tracepoints to user if CONFIG_SCHEDSTATS is not set")
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Yafang Shao <laoar.shao@gmail.com>
Link: http://lore.kernel.org/lkml/20210713112358.194693-1-yangjihong1@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-18 09:36:37 -03:00
Arnaldo Carvalho de Melo d08c84e01a perf sched: Cast PTHREAD_STACK_MIN to int as it may turn into sysconf(__SC_THREAD_STACK_MIN_VALUE)
In fedora rawhide the PTHREAD_STACK_MIN define may end up expanded to a
sysconf() call, and that will return 'long int', breaking the build:

    45 fedora:rawhide                : FAIL gcc version 11.1.1 20210623 (Red Hat 11.1.1-6) (GCC)
      builtin-sched.c: In function 'create_tasks':
      /git/perf-5.14.0-rc1/tools/include/linux/kernel.h:43:24: error: comparison of distinct pointer types lacks a cast [-Werror]
         43 |         (void) (&_max1 == &_max2);              \
            |                        ^~
      builtin-sched.c:673:34: note: in expansion of macro 'max'
        673 |                         (size_t) max(16 * 1024, PTHREAD_STACK_MIN));
            |                                  ^~~
      cc1: all warnings being treated as errors

  $ grep __sysconf /usr/include/*/*.h
  /usr/include/bits/pthread_stack_min-dynamic.h:extern long int __sysconf (int __name) __THROW;
  /usr/include/bits/pthread_stack_min-dynamic.h:#   define PTHREAD_STACK_MIN __sysconf (__SC_THREAD_STACK_MIN_VALUE)
  /usr/include/bits/time.h:extern long int __sysconf (int);
  /usr/include/bits/time.h:# define CLK_TCK ((__clock_t) __sysconf (2))	/* 2 is _SC_CLK_TCK */
  $

So cast it to int to cope with that.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-14 13:06:38 -03:00
Ingo Molnar 4d39c89f0b perf tools: Fix various typos in comments
Fix ~124 single-word typos and a few spelling errors in the perf tooling code,
accumulated over the years.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210321113734.GA248990@gmail.com
Link: http://lore.kernel.org/lkml/20210323160915.GA61903@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-03-23 17:13:43 -03:00
Arnaldo Carvalho de Melo b02736f776 perf evlist: Use the right prefix for 'struct evlist' 'find' methods
perf_evlist__ is for 'struct perf_evlist' methods, in tools/lib/perf/,
go on completing this split.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-11-30 09:48:07 -03:00
Joel Fernandes (Google) dc000c4593 perf sched: Show start of latency as well
The 'perf sched latency' tool is really useful at showing worst-case
latencies that task encountered since wakeup. However it shows only the
end of the latency. Often times the start of a latency is interesting as
it can show what else was going on at the time to cause the latency. I
certainly myself spending a lot of time backtracking to the start of the
latency in "perf sched script" which wastes a lot of time.

This patch therefore adds a new column "Max delay start". Considering
this, also rename "Maximum delay at" to "Max delay end" as its easier to
understand.

Example of the new output:

  ----------------------------------------------------------------------------------------------------------------------------------
   Task                  | Runtime ms  | Switches | Avg delay ms  | Max delay ms   | Max delay start         | Max delay end       |
  ----------------------------------------------------------------------------------------------------------------------------------
   MediaScannerSer:11936 |  651.296 ms |    67978 | avg: 0.113 ms | max: 77.250 ms | max start: 477.691360 s | max end: 477.768610 s
   audio@2.0-servi:(3)   |    0.000 ms |     3440 | avg: 0.034 ms | max: 72.267 ms | max start: 477.697051 s | max end: 477.769318 s
   AudioOut_1D:8112      |    0.000 ms |     2588 | avg: 0.083 ms | max: 64.020 ms | max start: 477.710740 s | max end: 477.774760 s
   Time-limited te:14973 | 7966.090 ms |    24807 | avg: 0.073 ms | max: 15.563 ms | max start: 477.162746 s | max end: 477.178309 s
   surfaceflinger:8049   |    9.680 ms |      603 | avg: 0.063 ms | max: 13.275 ms | max start: 476.931791 s | max end: 476.945067 s
   HeapTaskDaemon:(3)    | 1588.830 ms |     7040 | avg: 0.065 ms | max:  6.880 ms | max start: 473.666043 s | max end: 473.672922 s
   mount-passthrou:(3)   | 1370.809 ms |    68904 | avg: 0.011 ms | max:  6.524 ms | max start: 478.090630 s | max end: 478.097154 s
   ReferenceQueueD:(3)   |   11.794 ms |     1725 | avg: 0.014 ms | max:  6.521 ms | max start: 476.119782 s | max end: 476.126303 s
   writer:14077          |   18.410 ms |     1427 | avg: 0.036 ms | max:  6.131 ms | max start: 474.169675 s | max end: 474.175805 s

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20200925235634.4089867-1-joel@joelfernandes.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-10-13 11:01:42 -03:00