Commit Graph

194 Commits

Author SHA1 Message Date
Michael Petlan b222c9c01b perf callchain: Allow symbols to be optional when resolving a callchain
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 02b2705017d2e5ad32c23067d4b44477ec20b637
Author: Ian Rogers <irogers@google.com>
Date: Mon Sep 9 13:37:40 2024 -0700

description
===========
In uses like 'perf inject' it is not necessary to gather the symbol for
each call chain location, the map for the sample IP is wanted so that
build IDs and the like can be injected. Make gathering the symbol in the
callchain_cursor optional.

For a 'perf inject -B' command this lowers the peak RSS from 54.1MB to
29.6MB by avoiding loading symbols.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Colin Ian King <colin.i.king@gmail.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>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Link: https://lore.kernel.org/r/20240909203740.143492-5-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:44 +01:00
Michael Petlan f70efb35c6 perf inject: Lazy build-id mmap2 event insertion
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 64eed019f3fce1248cd29443c8a8635d317cb70f
Author: Ian Rogers <irogers@google.com>
Date: Mon Sep 9 13:37:39 2024 -0700

description
===========
Add -B option that lazily inserts mmap2 events thereby dropping all
mmap events without samples. This is similar to the behavior of -b
where only build_id events are inserted when a dso is accessed in a
sample.

File size savings can be significant in system-wide mode, consider:

  $ perf record -g -a -o perf.data sleep 1
  $ perf inject -B -i perf.data -o perf.new.data
  $ ls -al perf.data perf.new.data
           5147049 perf.data
           2248493 perf.new.data

Give test coverage of the new option in pipe test.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Colin Ian King <colin.i.king@gmail.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>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Link: https://lore.kernel.org/r/20240909203740.143492-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:44 +01:00
Michael Petlan 614e6e6dfc perf inject: Add new mmap2-buildid-all option
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit d762ba020d29ddb676805a90bf1450921817418f
Author: Ian Rogers <irogers@google.com>
Date: Mon Sep 9 13:37:38 2024 -0700

description
===========
Add an option that allows all mmap or mmap2 events to be rewritten as
mmap2 events with build IDs.

This is similar to the existing -b/--build-ids and --buildid-all options
except instead of adding a build_id event an existing mmap/mmap2 event
is used as a template and a new mmap2 event synthesized from it.

As mmap2 events are typical this avoids the insertion of build_id
events.

Add test coverage to the pipe test.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Colin Ian King <colin.i.king@gmail.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>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Link: https://lore.kernel.org/r/20240909203740.143492-3-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:44 +01:00
Michael Petlan 034cb5f15d perf inject: Fix build ID injection
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit ae39ba16554eb4a2d97f752847e93aa428438912
Author: Ian Rogers <irogers@google.com>
Date: Mon Sep 9 13:37:37 2024 -0700

description
===========
Build ID injection wasn't inserting a sample ID and aligning events to
64 bytes rather than 8. No sample ID means events are unordered and two
different build_id events for the same path, as happens when a file is
replaced, can't be differentiated.

Add in sample ID insertion for the build_id events alongside some
refactoring. The refactoring better aligns the function arguments for
different use cases, such as synthesizing build_id events without
needing to have a dso. The misc bits are explicitly passed as with
callchains the maps/dsos may span user and kernel land, so using
sample->cpumode isn't good enough.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Colin Ian King <colin.i.king@gmail.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>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Link: https://lore.kernel.org/r/20240909203740.143492-2-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:44 +01:00
Michael Petlan e75c6d8055 perf inject: Overhaul handling of pipe files
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 89d64e72732f3f970a048a46a7b60164b34dfc43
Author: Ian Rogers <irogers@google.com>
Date: Thu Aug 29 08:01:52 2024 -0700

description
===========
Previously inject->is_pipe was set if the input or output were a
pipe. Determining the input was a pipe had to be done prior to
starting the session and opening the file. This was done by comparing
the input file name with '-' but it fails if the pipe file is written
to disk.

Opening a pipe file from disk will correctly set perf_data.is_pipe, but
this is too late for 'perf inject' and results in a broken file. A
workaround is 'cat pipe_perf|perf inject -i - ...'.

This change removes inject->is_pipe and changes the dependent
conditions to use the is_pipe flag on the input
(inject->session->data) and output files (inject->output). This
ensures the is_pipe condition reflects things like the header being
read.

The change removes the use of perf file header repiping, that is
writing the file header out while reading it in. The case of input
pipe and output file cannot repipe as the attributes for the file are
unknown. To resolve this, write the file header when writing to disk
and as the attributes may be unknown, write them after the data.

Update sessions repipe variable to be trace_event_repipe as those are
the only events now impacted by it. Update __perf_session__new as the
repipe_fd no longer needs passing. Fully removing repipe from session
header reading will be done in a later change.

Committer testing:

  root@number:~# perf record -e syscalls:sys_enter_*sleep/max-stack=4/ -o - sleep 0.01 | perf report -i -
  # To display the perf.data header info, please use --header/--header-only options.
  #
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.050 MB - ]
  #
  # Total Lost Samples: 0
  #
  # Samples: 1  of event 'syscalls:sys_enter_clock_nanosleep'
  # Event count (approx.): 1
  #
  # Overhead  Command  Shared Object  Symbol
  # ........  .......  .............  ...............................
  #
     100.00%  sleep    libc.so.6      [.] clock_nanosleep@GLIBC_2.2.5
              |
              ---__libc_start_main@@GLIBC_2.34
                 __libc_start_call_main
                 0x562fc2560a9f
                 clock_nanosleep@GLIBC_2.2.5

  #
  # (Tip: Create an archive with symtabs to analyse on other machine: perf archive)
  #
  root@number:~# perf record -e syscalls:sys_enter_*sleep/max-stack=4/ -o - sleep 0.01 > pipe.data
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.050 MB - ]
  root@number:~# perf report --stdio -i pipe.data
  # To display the perf.data header info, please use --header/--header-only options.
  #
  #
  # Total Lost Samples: 0
  #
  # Samples: 1  of event 'syscalls:sys_enter_clock_nanosleep'
  # Event count (approx.): 1
  #
  # Overhead  Command  Shared Object  Symbol
  # ........  .......  .............  ...............................
  #
     100.00%  sleep    libc.so.6      [.] clock_nanosleep@GLIBC_2.2.5
              |
              ---__libc_start_main@@GLIBC_2.34
                 __libc_start_call_main
                 0x55f775975a9f
                 clock_nanosleep@GLIBC_2.2.5

  #
  # (Tip: To set sampling period of individual events use perf record -e cpu/cpu-cycles,period=100001/,cpu/branches,period=10001/ ...)
  #
  root@number:~#

    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@linaro.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Link: https://lore.kernel.org/r/20240829150154.37929-7-irogers@google.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 b46903f07a perf inject: Combine mmap and mmap2 handling
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 05c4cfeba097b986532c7a5609dcc5435c0a4dee
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 16 23:44:38 2024 -0700

description
===========
The handling of mmap and mmap2 events is near identical. Add a common
helper function and call that by the two event handling functions.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dominique Martinet <asmadeus@codewreck.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@linaro.org>
    Cc: Jann Horn <jannh@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Weilin Wang <weilin.wang@intel.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yunseong Kim <yskelg@gmail.com>
    Cc: Ze Gao <zegao2021@gmail.com>
    Link: https://lore.kernel.org/r/20240817064442.2152089-10-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:39 +01:00
Michael Petlan c692471c28 perf inject: Combine different mmap and mmap2 functions
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 048a7a9363a276ffc15e137ae8544d2cd7c28b67
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 16 23:44:37 2024 -0700

description
===========
There are repipe, build ID and JIT dump variants of the mmap and mmap2
repipe functions. The organization doesn't allow JIT dump to work with
build ID injection and the structure is less than clear. Combine the
function and enable the different behaviors based on ifs.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dominique Martinet <asmadeus@codewreck.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@linaro.org>
    Cc: Jann Horn <jannh@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Weilin Wang <weilin.wang@intel.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yunseong Kim <yskelg@gmail.com>
    Cc: Ze Gao <zegao2021@gmail.com>
    Link: https://lore.kernel.org/r/20240817064442.2152089-9-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:39 +01:00
Michael Petlan 88a82117cf perf inject: Combine build_ids and build_id_all into enum
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 0ed4c8c31139e3360c5db9f536e8ff37c1824f8a
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 16 23:44:36 2024 -0700

description
===========
It is clearer to have a single enum that determines how build ids are
injected, it also allows for future extension.

Set the header build ID feature whether lazy or all are generated,
previously only the lazy case would set it.

Allow parsing of known build IDs for either the lazy or all cases.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dominique Martinet <asmadeus@codewreck.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@linaro.org>
    Cc: Jann Horn <jannh@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Weilin Wang <weilin.wang@intel.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yunseong Kim <yskelg@gmail.com>
    Cc: Ze Gao <zegao2021@gmail.com>
    Link: https://lore.kernel.org/r/20240817064442.2152089-8-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:39 +01:00
Michael Petlan 8541ca49c3 perf dso: Constify dso_id
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit e4bb4caa54b24b839c21612d816b40673a75f6d4
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 16 23:44:33 2024 -0700

description
===========
The passed dso_id is copied and so is never an out argument. Remove
its mutability.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dominique Martinet <asmadeus@codewreck.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@linaro.org>
    Cc: Jann Horn <jannh@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Weilin Wang <weilin.wang@intel.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yunseong Kim <yskelg@gmail.com>
    Cc: Ze Gao <zegao2021@gmail.com>
    Link: https://lore.kernel.org/r/20240817064442.2152089-5-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:39 +01:00
Michael Petlan 34e40cdc57 perf inject: Inject build ids for entire call chain
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 3d557dd3f54e329556e880129d0181988893b00f
Author: Ian Rogers <irogers@google.com>
Date: Mon Aug 12 15:41:19 2024 -0700

description
===========
The DSO build id is injected when the dso is first encountered but the
checking for first encountered only looks at the sample->ip not the
entire callchain.

Use the callchain logic to ensure all build ids are inserted.

Fixes: 454c407ec1 ("perf: add perf-inject builtin")
    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Casey Chen <cachen@purestorage.com>
    Cc: Colin Ian King <colin.i.king@gmail.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>
    Cc: Tom Zanussi <tzanussi@gmail.com>
    Link: https://lore.kernel.org/r/20240812224119.744968-1-irogers@google.com
[ Split from a larger patch that introduced the API and use it ]
    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 61c8355696 perf inject: Use perf_tool__init()
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit a37c0436f3799d02f13781d5e1c836b956b8c05d
Author: Ian Rogers <irogers@google.com>
Date: Mon Aug 12 13:47:06 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-15-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 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 92fcd47209 perf inject: Fix leader sampling inserting additional samples
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 79bcd34e0f3da39fda841406ccc957405e724852
Author: Ian Rogers <irogers@google.com>
Date: Mon Jul 29 15:06:20 2024 -0700

description
===========
The processing of leader samples would turn an individual sample with
a group of read values into multiple samples. 'perf inject' would pass
through the additional samples increasing the output data file size:

  $ perf record -g -e "{instructions,cycles}:S" -o perf.orig.data true
  $ perf script -D -i perf.orig.data | sed -e 's/perf.orig.data/perf.data/g' > orig.txt
  $ perf inject -i perf.orig.data -o perf.new.data
  $ perf script -D -i perf.new.data | sed -e 's/perf.new.data/perf.data/g' > new.txt
  $ diff -u orig.txt new.txt
  --- orig.txt    2024-07-29 14:29:40.606576769 -0700
  +++ new.txt     2024-07-29 14:30:04.142737434 -0700
  ...
  -0xc550@perf.data [0x30]: event: 3
  +0xc550@perf.data [0xd0]: event: 9
  +.
  +. ... raw event: size 208 bytes
  +.  0000:  09 00 00 00 01 00 d0 00 fc 72 01 86 ff ff ff ff  .........r......
  +.  0010:  74 7d 2c 00 74 7d 2c 00 fb c3 79 f9 ba d5 05 00  t},.t},...y.....
  +.  0020:  e6 cb 1a 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
  +.  0030:  02 00 00 00 00 00 00 00 76 01 00 00 00 00 00 00  ........v.......
  +.  0040:  e6 cb 1a 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  +.  0050:  62 18 00 00 00 00 00 00 f6 cb 1a 00 00 00 00 00  b...............
  +.  0060:  00 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00  ................
  +.  0070:  80 ff ff ff ff ff ff ff fc 72 01 86 ff ff ff ff  .........r......
  +.  0080:  f3 0e 6e 85 ff ff ff ff 0c cb 7f 85 ff ff ff ff  ..n.............
  +.  0090:  bc f2 87 85 ff ff ff ff 44 af 7f 85 ff ff ff ff  ........D.......
  +.  00a0:  bd be 7f 85 ff ff ff ff 26 d0 7f 85 ff ff ff ff  ........&.......
  +.  00b0:  6d a4 ff 85 ff ff ff ff ea 00 20 86 ff ff ff ff  m......... .....
  +.  00c0:  00 fe ff ff ff ff ff ff 57 14 4f 43 fc 7e 00 00  ........W.OC.~..
  +
  +1642373909693435 0xc550 [0xd0]: PERF_RECORD_SAMPLE(IP, 0x1): 2915700/2915700: 0xffffffff860172fc period: 1 addr: 0
  +... FP chain: nr:12
  +.....  0: ffffffffffffff80
  +.....  1: ffffffff860172fc
  +.....  2: ffffffff856e0ef3
  +.....  3: ffffffff857fcb0c
  +.....  4: ffffffff8587f2bc
  +.....  5: ffffffff857faf44
  +.....  6: ffffffff857fbebd
  +.....  7: ffffffff857fd026
  +.....  8: ffffffff85ffa46d
  +.....  9: ffffffff862000ea
  +..... 10: fffffffffffffe00
  +..... 11: 00007efc434f1457
  +... sample_read:
  +.... group nr 2
  +..... id 00000000001acbe6, value 0000000000000176, lost 0
  +..... id 00000000001acbf6, value 0000000000001862, lost 0
  +
  +0xc620@perf.data [0x30]: event: 3
  ...

This behavior is incorrect as in the case above 'perf inject' should
have done nothing. Fix this behavior by disabling separating samples
for a tool that requests it. Only request this for `perf inject` so as
to not affect other perf tools. With the patch and the test above
there are no differences between the orig.txt and new.txt.

Fixes: e4caec0d1a ("perf evsel: Add PERF_SAMPLE_READ sample related processing")
    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Jiri Olsa <jolsa@redhat.com>
    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/20240729220620.2957754-1-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 8f6bf9b6c0 perf inject: Convert comma to semicolon
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 496cae1b3306e2ea7bbb8ca7ced082a2046afed9
Author: Chen Ni <nichen@iscas.ac.cn>
Date: Tue Jul 16 15:53:47 2024 +0800

description
===========
Replace a comma between expression statements by a semicolon.

    Reviewed-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
    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: 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/20240716075347.969041-1-nichen@iscas.ac.cn
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:33 +01:00
Michael Petlan fbcea1ecad perf dso: Add reference count checking and accessor functions
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit ee756ef7491eafd70f390343a1d90930af125a51
Author: Ian Rogers <irogers@google.com>
Date: Sat May 4 14:38:01 2024 -0700

description
===========
Add reference count checking to struct dso, this can help with
implementing correct reference counting discipline. To avoid
RC_CHK_ACCESS everywhere, add accessor functions for the variables in
struct dso.

The majority of the change is mechanical in nature and not easy to
split up.

Committer testing:

'perf test' up to this patch shows no regressions.

But:

  util/symbol.c: In function ‘dso__load_bfd_symbols’:
  util/symbol.c:1683:9: error: too few arguments to function ‘dso__set_adjust_symbols’
   1683 |         dso__set_adjust_symbols(dso);
        |         ^~~~~~~~~~~~~~~~~~~~~~~
  In file included from util/symbol.c:21:
  util/dso.h:268:20: note: declared here
    268 | static inline void dso__set_adjust_symbols(struct dso *dso, bool val)
        |                    ^~~~~~~~~~~~~~~~~~~~~~~
  make[6]: *** [/home/acme/git/perf-tools-next/tools/build/Makefile.build:106: /tmp/tmp.ZWHbQftdN6/util/symbol.o] Error 1
    MKDIR   /tmp/tmp.ZWHbQftdN6/tests/workloads/
  make[6]: *** Waiting for unfinished jobs....

This was updated:

  -       symbols__fixup_end(&dso->symbols, false);
  -       symbols__fixup_duplicate(&dso->symbols);
  -       dso->adjust_symbols = 1;
  +       symbols__fixup_end(dso__symbols(dso), false);
  +       symbols__fixup_duplicate(dso__symbols(dso));
  +       dso__set_adjust_symbols(dso);

But not build tested with BUILD_NONDISTRO and libbfd devel files installed
(binutils-devel on fedora).

Add the missing argument:

   	symbols__fixup_end(dso__symbols(dso), false);
   	symbols__fixup_duplicate(dso__symbols(dso));
  -	dso__set_adjust_symbols(dso);
  +	dso__set_adjust_symbols(dso, true);

    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Ben Gainey <ben.gainey@arm.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Chengen Du <chengen.du@canonical.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dima Kogan <dima@secretsauce.net>
    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: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Li Dong <lidong@vivo.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Paran Lee <p4ranlee@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Song Liu <song@kernel.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
    Link: https://lore.kernel.org/r/20240504213803.218974-6-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:53 +02:00
Michael Petlan d3ae765eab perf dsos: Introduce dsos__for_each_dso()
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 73f3fea2e11dbd92f49807ee1c33429674f71f13
Author: Ian Rogers <irogers@google.com>
Date: Tue Apr 9 23:42:05 2024 -0700

description
===========
To better abstract the dsos internals, introduce dsos__for_each_dso that
does a callback on each dso.

This also means the read lock can be correctly held.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Ben Gainey <ben.gainey@arm.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Chengen Du <chengen.du@canonical.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    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: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Li Dong <lidong@vivo.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Markus Elfring <Markus.Elfring@web.de>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Paran Lee <p4ranlee@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Song Liu <song@kernel.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
    Link: https://lore.kernel.org/r/20240410064214.2755936-4-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:48 +02:00
Michael Petlan f4b08752d6 perf dsos: Attempt to better abstract DSOs internals
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 83acca9f90c700bafd81229f2c2d5debcf6b27bc
Author: Ian Rogers <irogers@google.com>
Date: Tue Apr 9 23:42:03 2024 -0700

description
===========
Move functions from machine and build-id to dsos. Pass 'struct dsos'
rather than internal state.

Rename some functions to better represent which data structure they
operate on.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Anne Macedo <retpolanne@posteo.net>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Ben Gainey <ben.gainey@arm.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Chengen Du <chengen.du@canonical.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    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: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linux.dev>
    Cc: Li Dong <lidong@vivo.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Markus Elfring <Markus.Elfring@web.de>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Paran Lee <p4ranlee@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Song Liu <song@kernel.org>
    Cc: Sun Haiyong <sunhaiyong@loongson.cn>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yanteng Si <siyanteng@loongson.cn>
    Cc: Yicong Yang <yangyicong@hisilicon.com>
    Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
    Link: https://lore.kernel.org/r/20240410064214.2755936-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:48 +02:00
Michael Petlan 0dca068783 perf record: Lazy load kernel symbols
JIRA: https://issues.redhat.com/browse/RHEL-25824

upstream
========
commit 1a27fc01700fbff2f205000edf0d1d315b5f85cc
Author: Ian Rogers <irogers@google.com>
Date: Thu Nov 2 10:56:44 2023 -0700

description
===========
Commit 5b7ba82a75 ("perf symbols: Load kernel maps before using")
changed it so that loading a kernel DSO would cause the symbols for the
DSO to be eagerly loaded.

For 'perf record' this is overhead as the symbols won't be used. Add a
field to 'struct symbol_conf' to control the behavior and disable it for
'perf record' and 'perf inject'.

    Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Colin Ian King <colin.i.king@gmail.com>
    Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: K Prateek Nayak <kprateek.nayak@amd.com>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Li Dong <lidong@vivo.com>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Ming Wang <wangming01@loongson.cn>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Sean Christopherson <seanjc@google.com>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Cc: Vincent Whitchurch <vincent.whitchurch@axis.com>
    Cc: Wenyu Liu <liuwenyu7@huawei.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Link: https://lore.kernel.org/r/20231102175735.2272696-3-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-04-03 19:37:10 +02:00
Michael Petlan 2bad2ebe4d perf inject: Lazily allocate guest_event event_buf
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 892d00fba18a6dec2620165ce05e1697496f8381
Author: Ian Rogers <irogers@google.com>
Date: Fri May 26 20:43:22 2023 -0700

description
===========
The event_buf is 64kb (PERF_SAMPLE_SIZE_MAX) and stack allocated in
struct perf_inject. It is used for guest events that may not exist in
a file. Make the array allocation lazy to cut down on the stack usage.

    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-5-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:55 +02:00
Michael Petlan d44e5d7eb8 perf inject: Lazily allocate event_copy
Bugzilla: https://bugzilla.redhat.com/2233483

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

description
===========
The event_copy is 64kb (PERF_SAMPLE_SIZE_MAX) and stack allocated in
struct perf_inject. It is used for aux events that may not exist in a
file. Make the array allocation lazy to cut down on the stack usage.

    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-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:55 +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 00f5a06ff5 perf dso: Add dso__filename_with_chroot() to reduce number of accesses to dso->nsinfo members
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 7031edac9dbc0f880c9fbaa40ca08b5de34239c6
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Mon Apr 17 18:28:01 2023 -0300

description
===========
We'll need to reference count dso->nsinfo, so reduce the number of
direct accesses by having a shorter form of obtaining a filename with
a chroot (namespace one).

    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
    Cc: Dmitriy Vyukov <dvyukov@google.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Riccardo Mancini <rickyman7@gmail.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
    Link: https://lore.kernel.org/lkml/ZD26ZlqSbgSyH5lX@kernel.org
[ Used nsinfo__pid(dso->nsinfo), as it was already present ]
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 12:00:49 +02:00
Michael Petlan a7fce01e52 perf inject: Use zfree() to reduce chances of use after free
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 79b40a1b182bcca381bb59d0219e1dd681a64981
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Wed Apr 12 09:50:08 2023 -0300

description
===========
Do defensive programming by using zfree() to initialize freed pointers
to NULL, so that eventual use after free result in a NULL pointer deref
instead of more subtle behaviour.

    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 12:00:24 +02:00
Michael Petlan 4a6c7a0460 perf map: Add accessors for ->prot, ->priv and ->flags
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit ddee3f2bddc11f850f7f6fcfc04bc26ceeab23ce
Author: Ian Rogers <irogers@google.com>
Date: Tue Apr 4 13:59:45 2023 -0700

description
===========
Later changes will add reference count checking for 'struct map'. Add an
accessor so that the reference count check is only necessary in one
place.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Darren Hart <dvhart@infradead.org>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Dmitriy Vyukov <dvyukov@google.com>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Hao Luo <haoluo@google.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: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Miaoqian Lin <linmq006@gmail.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Riccardo Mancini <rickyman7@gmail.com>
    Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
    Cc: Song Liu <song@kernel.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Yury Norov <yury.norov@gmail.com>
    Link: https://lore.kernel.org/r/20230404205954.2245628-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:12 +02:00
Michael Petlan 0c196b90d9 perf map: Add accessor for dso
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 63df0e4bc368adbd12ed70ed4789d8d52d65661d
Author: Ian Rogers <irogers@google.com>
Date: Mon Mar 20 14:22:35 2023 -0700

description
===========
Later changes will add reference count checking for struct map, with
dso being the most frequently accessed variable. Add an accessor so
that the reference count check is only necessary in one place.

Additional changes:
 - add a dso variable to avoid repeated map__dso calls.
 - in builtin-mem.c dump_raw_samples, code only partially tested for
   dso == NULL. Make the possibility of NULL consistent.
 - in thread.c thread__memcpy fix use of spaces and use tabs.

Committer notes:

Did missing conversions on these files:

   tools/perf/arch/powerpc/util/skip-callchain-idx.c
   tools/perf/arch/powerpc/util/sym-handling.c
   tools/perf/ui/browsers/hists.c
   tools/perf/ui/gtk/annotate.c
   tools/perf/util/cs-etm.c
   tools/perf/util/thread.c
   tools/perf/util/unwind-libunwind-local.c
   tools/perf/util/unwind-libunwind.c

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Darren Hart <dvhart@infradead.org>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Dmitriy Vyukov <dvyukov@google.com>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: German Gomez <german.gomez@arm.com>
    Cc: Hao Luo <haoluo@google.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: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Miaoqian Lin <linmq006@gmail.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Riccardo Mancini <rickyman7@gmail.com>
    Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
    Cc: Song Liu <song@kernel.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Yury Norov <yury.norov@gmail.com>
    Link: https://lore.kernel.org/r/20230320212248.1175731-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:02 +02:00
Michael Petlan f8d0908a17 perf inject: Fix --buildid-all not to eat up MMAP2
Bugzilla: https://bugzilla.redhat.com/2177183

upstream
========
commit ce9f1c05d2edfa6cdf2c1a510495d333e11810a8
Author: Namhyung Kim <namhyung@kernel.org>
Date: Wed Feb 22 23:01:55 2023 -0800

description
===========
When MMAP2 has the PERF_RECORD_MISC_MMAP_BUILD_ID flag, it means the
record already has the build-id info.  So it marks the DSO as hit, to
skip if the same DSO is not processed if it happens to miss the build-id
later.

But it missed to copy the MMAP2 record itself so it'd fail to symbolize
samples for those regions.

For example, the following generates 249 MMAP2 events.

  $ perf record --buildid-mmap -o- true | perf report --stat -i- | grep MMAP2
           MMAP2 events:        249  (86.8%)

Adding perf inject should not change the number of events like this

  $ perf record --buildid-mmap -o- true | perf inject -b | \
  > perf report --stat -i- | grep MMAP2
           MMAP2 events:        249  (86.5%)

But when --buildid-all is used, it eats most of the MMAP2 events.

  $ perf record --buildid-mmap -o- true | perf inject -b --buildid-all | \
  > perf report --stat -i- | grep MMAP2
           MMAP2 events:          1  ( 2.5%)

With this patch, it shows the original number now.

  $ perf record --buildid-mmap -o- true | perf inject -b --buildid-all | \
  > perf report --stat -i- | grep MMAP2
           MMAP2 events:        249  (86.5%)

Committer testing:

Before:

  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf inject -b | perf report --stat -i- | grep MMAP2
           MMAP2 events:         58  (36.2%)
  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf report --stat -i- | grep MMAP2
           MMAP2 events:         58  (36.2%)
  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf inject -b --buildid-all | perf report --stat -i- | grep MMAP2
           MMAP2 events:          2  ( 1.9%)
  $

After:

  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf inject -b | perf report --stat -i- | grep MMAP2
           MMAP2 events:         58  (29.3%)
  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf report --stat -i- | grep MMAP2
           MMAP2 events:         58  (34.3%)
  $ perf record --buildid-mmap -o- perf stat --null sleep 1 2> /dev/null | perf inject -b --buildid-all | perf report --stat -i- | grep MMAP2
           MMAP2 events:         58  (38.4%)
  $

Fixes: f7fc0d1c91 ("perf inject: Do not inject BUILD_ID record if MMAP2 has it")
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20230223070155.54251-1-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-14 12:23:28 +02:00
Michael Petlan 6e0c877b14 perf inject: Use perf_data__read() for auxtrace
Bugzilla: https://bugzilla.redhat.com/2177183

upstream
========
commit 1746212daeba95e9ae1639227dc0c3591d41deeb
Author: Namhyung Kim <namhyung@kernel.org>
Date: Mon Jan 30 18:33:47 2023 -0800

description
===========
In copy_bytes(), it reads the data from the (input) fd and writes it to
the output file.  But it does with the read(2) unconditionally which
caused a problem of mixing buffered vs unbuffered I/O together.

You can see the problem when using pipes.

  $ perf record -e intel_pt// -o- true | perf inject -b > /dev/null
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]
  0x45c0 [0x30]: failed to process type: 71

It should use perf_data__read() to honor the 'use_stdio' setting.

Fixes: 601366678c ("perf data: Allow to use stdio functions for pipe mode")
    Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
    Reviewed-by: James Clark <james.clark@arm.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Link: https://lore.kernel.org/r/20230131023350.1903992-2-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-14 12:23:22 +02:00
Michael Petlan a2fe9a55f8 perf build: Use libtraceevent from the system
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 378ef0f5d9d7f4652d7a40e0711e8b845ada1cbd
Author: Ian Rogers <irogers@google.com>
Date: Mon Dec 5 14:59:39 2022 -0800

description
===========
Remove the LIBTRACEEVENT_DYNAMIC and LIBTRACEFS_DYNAMIC make command
line variables.

If libtraceevent isn't installed or NO_LIBTRACEEVENT=1 is passed to the
build, don't compile in libtraceevent and libtracefs support.

This also disables CONFIG_TRACE that controls "perf trace".

CONFIG_LIBTRACEEVENT is used to control enablement in Build/Makefiles,
HAVE_LIBTRACEEVENT is used in C code.

Without HAVE_LIBTRACEEVENT tracepoints are disabled and as such the
commands kmem, kwork, lock, sched and timechart are removed.  The
majority of commands continue to work including "perf test".

Committer notes:

Fixed up a tools/perf/util/Build reject and added:

  #include <traceevent/event-parse.h>

to tools/perf/util/scripting-engines/trace-event-perl.c.

Committer testing:

  $ rpm -qi libtraceevent-devel
  Name        : libtraceevent-devel
  Version     : 1.5.3
  Release     : 2.fc36
  Architecture: x86_64
  Install Date: Mon 25 Jul 2022 03:20:19 PM -03
  Group       : Unspecified
  Size        : 27728
  License     : LGPLv2+ and GPLv2+
  Signature   : RSA/SHA256, Fri 15 Apr 2022 02:11:58 PM -03, Key ID 999f7cbf38ab71f4
  Source RPM  : libtraceevent-1.5.3-2.fc36.src.rpm
  Build Date  : Fri 15 Apr 2022 10:57:01 AM -03
  Build Host  : buildvm-x86-05.iad2.fedoraproject.org
  Packager    : Fedora Project
  Vendor      : Fedora Project
  URL         : https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
  Bug URL     : https://bugz.fedoraproject.org/libtraceevent
  Summary     : Development headers of libtraceevent
  Description :
  Development headers of libtraceevent-libs
  $

Default build:

  $ ldd ~/bin/perf | grep tracee
  	libtraceevent.so.1 => /lib64/libtraceevent.so.1 (0x00007f1dcaf8f000)
  $

  # perf trace -e sched:* --max-events 10
       0.000 migration/0/17 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, dest_cpu: 1)
       0.005 migration/0/17 sched:sched_wake_idle_without_ipi(cpu: 1)
       0.011 migration/0/17 sched:sched_switch(prev_comm: "", prev_pid: 17 (migration/0), prev_state: 1, next_comm: "", next_prio: 120)
       1.173 :0/0 sched:sched_wakeup(comm: "", pid: 3138 (gnome-terminal-), prio: 120)
       1.180 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 3138 (gnome-terminal-), next_prio: 120)
       0.156 migration/1/21 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, orig_cpu: 1, dest_cpu: 2)
       0.160 migration/1/21 sched:sched_wake_idle_without_ipi(cpu: 2)
       0.166 migration/1/21 sched:sched_switch(prev_comm: "", prev_pid: 21 (migration/1), prev_state: 1, next_comm: "", next_prio: 120)
       1.183 :0/0 sched:sched_wakeup(comm: "", pid: 1602985 (kworker/u16:0-f), prio: 120, target_cpu: 1)
       1.186 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 1602985 (kworker/u16:0-f), next_prio: 120)
  #

Had to tweak tools/perf/util/setup.py to make sure the python binding
shared object links with libtraceevent if -DHAVE_LIBTRACEEVENT is
present in CFLAGS.

Building with NO_LIBTRACEEVENT=1 uncovered some more build failures:

- Make building of data-convert-bt.c to CONFIG_LIBTRACEEVENT=y

- perf-$(CONFIG_LIBTRACEEVENT) += scripts/

- bpf_kwork.o needs also to be dependent on CONFIG_LIBTRACEEVENT=y

- The python binding needed some fixups and util/trace-event.c can't be
  built and linked with the python binding shared object, so remove it
  in tools/perf/util/setup.py and exclude it from the list of
  dependencies in the python/perf.so Makefile.perf target.

Building without libtraceevent-devel installed uncovered more build
failures:

- The python binding tools/perf/util/python.c was assuming that
  traceevent/parse-events.h was always available, which was the case
  when we defaulted to using the in-kernel tools/lib/traceevent/ files,
  now we need to enclose it under ifdef HAVE_LIBTRACEEVENT, just like
  the other parts of it that deal with tracepoints.

- We have to ifdef the rules in the Build files with
  CONFIG_LIBTRACEEVENT=y to build builtin-trace.c and
  tools/perf/trace/beauty/ as we only ifdef setting CONFIG_TRACE=y when
  setting NO_LIBTRACEEVENT=1 in the make command line, not when we don't
  detect libtraceevent-devel installed in the system. Simplification here
  to avoid these two ways of disabling builtin-trace.c and not having
  CONFIG_TRACE=y when libtraceevent-devel isn't installed is the clean
  way.

From Athira:

<quote>
tools/perf/arch/powerpc/util/Build
-perf-y += kvm-stat.o
+perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
</quote>

Then, ditto for arm64 and s390, detected by container cross build tests.

- s/390 uses test__checkevent_tracepoint() that is now only available if
  HAVE_LIBTRACEEVENT is defined, enclose the callsite with ifder HAVE_LIBTRACEEVENT.

Also from Athira:

<quote>
With this change, I could successfully compile in these environment:
- Without libtraceevent-devel installed
- With libtraceevent-devel installed
- With “make NO_LIBTRACEEVENT=1”
</quote>

Then, finally rename CONFIG_TRACEEVENT to CONFIG_LIBTRACEEVENT for
consistency with other libraries detected in tools/perf/.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: bpf@vger.kernel.org
    Link: http://lore.kernel.org/lkml/20221205225940.3079667-3-irogers@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:24 +02:00
Michael Petlan d80b09edda perf dso: Hold lock when accessing nsinfo
Bugzilla: https://bugzilla.redhat.com/2177180

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

description
===========
There may be threads racing to update dso->nsinfo:

  https://lore.kernel.org/linux-perf-users/CAP-5=fWZH20L4kv-BwVtGLwR=Em3AOOT+Q4QGivvQuYn5AsPRg@mail.gmail.com/

Holding the dso->lock avoids use-after-free, memory leaks and other such
bugs. Apply the fix in:

  https://lore.kernel.org/linux-perf-users/20211118193714.2293728-1-irogers@google.com/

of there being a missing nsinfo__put now that the accesses are data race
free. Fixes test "Lookup mmap thread" when compiled with address
sanitizer.

    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-15-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 5c918368f0 perf inject: Add a command line option to specify build ids.
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 8012243e62b5e13bded3ce8a3b69d28f8ea694fe
Author: Raul Silvera <rsilvera@google.com>
Date: Mon Aug 15 22:59:22 2022 +0000

description
===========
This commit adds the option --known-build-ids to perf inject.
It allows the user to explicitly specify the build id for a given
path, instead of retrieving it from the current system. This is
useful in cases where a perf.data file is processed on a different
system from where it was collected, or if some of the binaries are
no longer available.

The build ids and paths are specified in pairs in the command line.
Using the file:// specifier, build ids can be loaded from a file
directly generated by perf buildid-list. This is convenient to copy
build ids from one perf.data file to another.

** Example: In this example we use perf record to create two
perf.data files, one with build ids and another without, and use
perf buildid-list and perf inject to copy the build ids from the
first file to the second.

 $ perf record ls /tmp
 $ perf record --no-buildid -o perf.data.no-buildid ls /tmp
 $ perf buildid-list > build-ids.txt
 $ perf inject -b --known-build-ids='file://build-ids.txt' \
        -i perf.data.no-buildid -o perf.data.buildid

    Signed-off-by: Raul Silvera <rsilvera@google.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    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: Mark Rutland <mark.rutland@arm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220815225922.2118745-1-rsilvera@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:34 +02:00
Michael Petlan 7da25bfdcc perf inject: Fix spelling mistake "theads" -> "threads"
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 8147f79ea575463d60ddc0735bceaef89bb34a4c
Author: Colin Ian King <colin.i.king@gmail.com>
Date: Thu Jul 21 13:45:28 2022 +0100

description
===========
There is a spelling mistake in a pr_err message. Fix it.

    Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
    Acked-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: kernel-janitors@vger.kernel.org
    Link: https://lore.kernel.org/r/20220721124528.20997-1-colin.i.king@gmail.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:51 +01:00
Michael Petlan 1953832714 perf inject: Add support for injecting guest sideband events
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 97406a7e4fa6e5cad3be80cd2188d8fb50a6ec75
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Mon Jul 11 12:32:07 2022 +0300

description
===========
Inject events from a perf.data file recorded in a virtual machine into
a perf.data file recorded on the host at the same time.

Only side band events (e.g. mmap, comm, fork, exit etc) and build IDs are
injected.  Additionally, the guest kcore_dir is copied as kcore_dir__
appended to the machine PID.

This is non-trivial because:
 o It is not possible to process 2 sessions simultaneously so instead
 events are first written to a temporary file.
 o To avoid conflict, guest sample IDs are replaced with new unused sample
 IDs.
 o Guest event's CPU is changed to be the host CPU because it is more
 useful for reporting and analysis.
 o Sample ID is mapped to machine PID which is recorded with VCPU in the
 id index. This is important to allow guest events to be related to the
 guest machine and VCPU.
 o Timestamps must be converted.
 o Events are inserted to obey finished-round ordering.

The anticipated use-case is:
 - start recording sideband events in a guest machine
 - start recording an AUX area trace on the host which can trace also the
 guest (e.g. Intel PT)
 - run test case on the guest
 - stop recording on the host
 - stop recording on the guest
 - copy the guest perf.data file to the host
 - inject the guest perf.data file sideband events into the host perf.data
 file using perf inject
 - the resulting perf.data file can now be used

Subsequent patches provide Intel PT support for this.

    Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: kvm@vger.kernel.org
    Link: https://lore.kernel.org/r/20220711093218.10967-25-adrian.hunter@intel.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:47 +01:00
Michael Petlan 5e6a34671e perf header: Record non-CPU PMU capabilities
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 2139f7424819818afc25fbfd0effda4babe235f6
Author: Ravi Bangoria <ravi.bangoria@amd.com>
Date: Sat Jun 4 10:15:16 2022 +0530

description
===========
PMUs advertise their capabilities via sysfs attribute files but
the perf tool currently parses only core(CPU) or hybrid core PMU
capabilities. Add support of recording non-core PMU capabilities
int perf.data header.

Note that a newly proposed HEADER_PMU_CAPS is replacing existing
HEADER_HYBRID_CPU_PMU_CAPS. Special care is taken for hybrid core
PMUs by writing their capabilities first in the perf.data header
to make sure new perf.data file being read by old perf tool does
not break.

    Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
    Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Ananth Narayan <ananth.narayan@amd.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Borislav Petkov <bp@alien8.de>
    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: Kim Phillips <kim.phillips@amd.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Robert Richter <rrichter@amd.com>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Santosh Shukla <santosh.shukla@amd.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: like.xu.linux@gmail.com
    Cc: x86@kernel.org
    Link: https://lore.kernel.org/r/20220604044519.594-6-ravi.bangoria@amd.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:42 +01:00
Michael Petlan d7493e1c75 perf record: Add finished init event
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 3812d2987733c5a00e103be4e23d63ec9342043a
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Fri Jun 10 14:33:15 2022 +0300

description
===========
In preparation for recording sideband events in a virtual machine guest so
that they can be injected into a host perf.data file.

This is needed to enable injecting events after the initial synthesized
user events (that have an all zero id sample) but before regular events.

Committer notes:

Add entry about PERF_RECORD_FINISHED_INIT to
tools/perf/Documentation/perf.data-file-format.txt.

Committer testing:

Before:

  # perf report -D | grep FINISHED
  0 0x5910 [0x8]: PERF_RECORD_FINISHED_ROUND
    FINISHED_ROUND events:          1  ( 0.5%)
  #

After:

  # perf record -- sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.020 MB perf.data (7 samples) ]
  # perf report -D | grep FINISHED
  0 0x5068 [0x8]: PERF_RECORD_FINISHED_INIT: unhandled!
  0 0x5390 [0x8]: PERF_RECORD_FINISHED_ROUND
    FINISHED_ROUND events:          1  ( 0.5%)
     FINISHED_INIT events:          1  ( 0.5%)
  #

    Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
    Acked-by: Ian Rogers <irogers@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20220610113316.6682-5-adrian.hunter@intel.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:42 +01:00
Michael Petlan fb167c7e50 perf inject: Adjust output data offset for backward compatibility
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 37ed2cddcbf1b52b03b9b2344c752ed867fa3539
Author: Raul Silvera <rsilvera@google.com>
Date: Tue Jun 21 15:27:25 2022 +0000

description
===========
When 'perf inject' creates a new file, it reuses the data offset from
the input file. If there has been a change on the size of the header, as
happened in v5.12 -> v5.13, the new offsets will be wrong, resulting in
a corrupted output file.

This change adds the function perf_session__data_offset to compute the
data offset based on the current header size, and uses that instead of
the offset from the original input file.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:23:14 +02:00
Michael Petlan 47283f020e perf inject: Fix missing free in copy_kcore_dir()
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 342cb0d80613719c5e5ac30619e54b9a3fd83625
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Mon Jun 20 13:39:04 2022 +0300

description
===========
Free string allocated by asprintf().

Fixes: d8fc08550929bb84 ("perf inject: Keep a copy of kcore_dir")

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:23:13 +02:00
Michael Petlan 9f3534a80b perf inject: Keep a copy of kcore_dir
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit d8fc08550929bb845c13cfefcc632a69fcf79b2c
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Fri May 20 16:24:04 2022 +0300

description
===========
If the input perf.data has a kcore_dir, copy it into the output, since
at least the kallsyms in the kcore_dir will be useful to the output.

Example:

 Before:

  $ ls -lR perf.data-from-desktop
  perf.data-from-desktop:
  total 916
  -rw------- 1 user user 931756 May 19 09:55 data
  drwx------ 2 user user   4096 May 19 09:55 kcore_dir

  perf.data-from-desktop/kcore_dir:
  total 42952
  -r-------- 1 user user  7582467 May 19 09:55 kallsyms
  -r-------- 1 user user 36388864 May 19 09:55 kcore
  -r-------- 1 user user     4828 May 19 09:55 modules

  $ perf inject -i perf.data-from-desktop -o injected-perf.data

  $ ls -lR injected-perf.data
  -rw------- 1 user user 931320 May 20 15:08 injected-perf.data

 After:

  $ perf inject -i perf.data-from-desktop -o injected-perf.data

  $ ls -lR injected-perf.data
  injected-perf.data:
  total 916
  -rw------- 1 user user 931320 May 20 15:21 data
  drwx------ 2 user user   4096 May 20 15:21 kcore_dir

  injected-perf.data/kcore_dir:
  total 42952
  -r-------- 1 user user  7582467 May 20 15:21 kallsyms
  -r-------- 1 user user 36388864 May 20 15:21 kcore
  -r-------- 1 user user     4828 May 20 15:21 modules

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:23:07 +02:00
Michael Petlan 4a6946707a perf inject: Keep some features sections from input file
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 180b3d06263ce70dd0622681237cf5c0555d9ca0
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Fri May 20 16:24:02 2022 +0300

description
===========
perf inject overwrites feature sections with information from the current
machine. It makes more sense to keep original information that describes
the machine or software when perf record was run.

Example: perf.data from "Desktop" injected on "nuc11"

 Before:

  $ perf script --header-only -i perf.data-from-desktop | head -15
  # ========
  # captured on    : Thu May 19 09:55:50 2022
  # header version : 1
  # data offset    : 1208
  # data size      : 837480
  # feat offset    : 838688
  # hostname : Desktop
  # os release : 5.13.0-41-generic
  # perf version : 5.18.rc5.gac837f7ca7ed
  # arch : x86_64
  # nrcpus online : 28
  # nrcpus avail : 28
  # cpudesc : Intel(R) Core(TM) i9-9940X CPU @ 3.30GHz
  # cpuid : GenuineIntel,6,85,4
  # total memory : 65548656 kB

  $ perf inject -i perf.data-from-desktop -o injected-perf.data

  $ perf script --header-only -i injected-perf.data | head -15
  # ========
  # captured on    : Fri May 20 15:06:55 2022
  # header version : 1
  # data offset    : 1208
  # data size      : 837480
  # feat offset    : 838688
  # hostname : nuc11
  # os release : 5.17.5-local
  # perf version : 5.18.rc5.g0f828fdeb9af
  # arch : x86_64
  # nrcpus online : 8
  # nrcpus avail : 8
  # cpudesc : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  # cpuid : GenuineIntel,6,140,1
  # total memory : 16012124 kB

 After:

  $ perf inject -i perf.data-from-desktop -o injected-perf.data

  $ perf script --header-only -i injected-perf.data | head -15
  # ========
  # captured on    : Fri May 20 15:08:54 2022
  # header version : 1
  # data offset    : 1208
  # data size      : 837480
  # feat offset    : 838688
  # hostname : Desktop
  # os release : 5.13.0-41-generic
  # perf version : 5.18.rc5.gac837f7ca7ed
  # arch : x86_64
  # nrcpus online : 28
  # nrcpus avail : 28
  # cpudesc : Intel(R) Core(TM) i9-9940X CPU @ 3.30GHz
  # cpuid : GenuineIntel,6,85,4
  # total memory : 65548656 kB

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:23:07 +02:00
Michael Petlan b88d4c978d perf namespaces: Add functions to access nsinfo
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit bcaf0a97858de7ab21e2bb877e5ac25a7e050525
Author: Ian Rogers <irogers@google.com>
Date: Fri Feb 11 02:34:06 2022 -0800

description
===========
Having functions to access nsinfo reduces the places where reference
counting checking needs to be added.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:22:47 +02:00
Michael Petlan 0a3a4e4a7e perf report: Output data file name in raw trace dump
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 2292083f5956803efe923c8696ca51bf7d4bde53
Author: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Date: Mon Jan 17 21:34:36 2022 +0300

description
===========
Print path and name of a data file into raw dump (-D)
<file_offset>@<path/file>:

  0x2226a@perf.data [0x30]: event: 9
or
  0x15cc36@perf.data/data.7 [0x30]: event: 9

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:22:46 +02:00
Michael Petlan 6ec84fc7c6 perf inject: Try chroot directory when reading build-id
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 75d48c56703dcce45cf4d7262dbf7113c5e6607f
Author: Namhyung Kim <namhyung@kernel.org>
Date: Tue Feb 1 23:08:27 2022 -0800

description
===========
When reading build-id from a DSO, it should consider if it's from a
chroot task.  In that case, the path is different so it needs to prepend
the root directory to access the file correctly.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:22:44 +02:00
Michael Petlan 34a5a90980 perf tools: Remove redundant err variable
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit f0ac5b85810a69104ee6bc939bcbaecfe4db9a3e
Author: Minghao Chi <chi.minghao@zte.com.cn>
Date: Wed Jan 12 08:01:09 2022 +0000

description
===========
Return value from perf_event__process_tracing_data() directly instead
of taking this in another redundant variable.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:36:08 +02:00
Michael Petlan fa91759183 perf inject: Fix segfault due to perf_data__fd() without open
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit c271a55b0c6029fed0cac909fa57999a11467132
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Mon Dec 13 10:48:29 2021 +0200

description
===========
The fixed commit attempts to get the output file descriptor even if the
file was never opened e.g.

  $ perf record uname
  Linux
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ]
  $ perf inject -i perf.data --vm-time-correlation=dry-run
  Segmentation fault (core dumped)
  $ gdb --quiet perf
  Reading symbols from perf...
  (gdb) r inject -i perf.data --vm-time-correlation=dry-run
  Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

  Program received signal SIGSEGV, Segmentation fault.
  __GI___fileno (fp=0x0) at fileno.c:35
  35      fileno.c: No such file or directory.
  (gdb) bt
  #0  __GI___fileno (fp=0x0) at fileno.c:35
  #1  0x00005621e48dd987 in perf_data__fd (data=0x7fff4c68bd08) at util/data.h:72
  #2  perf_data__fd (data=0x7fff4c68bd08) at util/data.h:69
  #3  cmd_inject (argc=<optimized out>, argv=0x7fff4c69c1f0) at builtin-inject.c:1017
  #4  0x00005621e4936783 in run_builtin (p=0x5621e4ee6878 <commands+600>, argc=4, argv=0x7fff4c69c1f0) at perf.c:313
  #5  0x00005621e4897d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365
  #6  run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409
  #7  main (argc=4, argv=0x7fff4c69c1f0) at perf.c:539
  (gdb)

Fixes: 0ae03893623dd1dd ("perf tools: Pass a fd to perf_file_header__read_pipe()")

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:36 +02:00
Michael Petlan 147ef40079 perf inject: Fix segfault due to close without open
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit 0c8e32fe48f549eef27c8c6b0a63530f83c3a643
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Mon Dec 13 10:48:28 2021 +0200

description
===========
The fixed commit attempts to close inject.output even if it was never
opened e.g.

  $ perf record uname
  Linux
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ]
  $ perf inject -i perf.data --vm-time-correlation=dry-run
  Segmentation fault (core dumped)
  $ gdb --quiet perf
  Reading symbols from perf...
  (gdb) r inject -i perf.data --vm-time-correlation=dry-run
  Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

  Program received signal SIGSEGV, Segmentation fault.
  0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48
  48      iofclose.c: No such file or directory.
  (gdb) bt
  #0  0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48
  #1  0x0000557fc7b74f92 in perf_data__close (data=data@entry=0x7ffcdafa6578) at util/data.c:376
  #2  0x0000557fc7a6b807 in cmd_inject (argc=<optimized out>, argv=<optimized out>) at builtin-inject.c:1085
  #3  0x0000557fc7ac4783 in run_builtin (p=0x557fc8074878 <commands+600>, argc=4, argv=0x7ffcdafb6a60) at perf.c:313
  #4  0x0000557fc7a25d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365
  #5  run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409
  #6  main (argc=4, argv=0x7ffcdafb6a60) at perf.c:539
  (gdb)

Fixes: 02e6246f53 ("perf inject: Close inject.output on exit")

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:35 +02:00
Michael Petlan 4a9e1288db perf inject: Fix itrace space allowed for new attributes
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit c29d9792607e67ed8a3f6e9db0d96836d885a8c5
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Thu Nov 25 09:14:57 2021 +0200

description
===========
The space allowed for new attributes can be too small if existing header
information is large. That can happen, for example, if there are very
many CPUs, due to having an event ID per CPU per event being stored in the
header information.

Fix by adding the existing header.data_offset. Also increase the extra
space allowed to 8KiB and align to a 4KiB boundary for neatness.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:31 +02:00
Michael Petlan cd0c54396d perf inject: Add vmlinux and ignore-vmlinux arguments
Bugzilla: https://bugzilla.redhat.com/2069073

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

description
===========
Other perf tools allow specifying the path to vmlinux. 'perf inject'
didn't have this argument which made some auxtrace workflows difficult.

Also add --ignore-vmlinux for consistency with other tools.

[ Added the perf-inject man page entries for these options, as noted by Denis ]

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:12 +02:00
Michael Petlan d2b1c92483 perf tools: Add support for PERF_RECORD_AUX_OUTPUT_HW_ID
Bugzilla: https://bugzilla.redhat.com/2069073

upstream
========
commit 61750473589b6f8adc35007c8261986043907f13
Author: Adrian Hunter <adrian.hunter@intel.com>
Date: Tue Sep 7 19:39:02 2021 +0300

description
===========
The PERF_RECORD_AUX_OUTPUT_HW_ID event provides a way to match AUX output
data like Intel PT PEBS-via-PT back to the event that it came from, by
providing a hardware ID that is present in the AUX output.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-05-16 11:35:02 +02:00
Michael Petlan f8ed20f6c5 perf inject: Fix output from a file to a pipe
Bugzilla: https://bugzilla.redhat.com/2069070

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

description
===========
When the input is a regular file but the output is a pipe, it should
write a pipe header.  But just repiping would write a portion of the
existing header which is different in 'size' value.  So we need to
prevent it and write a new pipe header along with other information
like event attributes and features.

This can handle something like this:

  # perf record -a -B sleep 1

  # perf inject -b -i perf.data | perf report -i -

Factor out perf_event__synthesize_for_pipe() to be shared between perf
record and inject.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-04-25 12:33:02 +02:00
Michael Petlan d79e8ac763 perf inject: Fix output from a pipe to a file
Bugzilla: https://bugzilla.redhat.com/2069070

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

description
===========
Sometimes it needs to save the perf inject data to a file for debugging.
But normally it assumes the same format for input and output, so the end
result cannot be used due to a broken format.

  # perf record -a -o - sleep 1 | perf inject -b -o my.data

  # perf report -i my.data --stdio
  0x208 [0]: failed to process type: 0 [Invalid argument]
  Error:
  failed to process sample
  # To display the perf.data header info, please use --header/--header-only options.
  #

In this case, it thought the data has a regular file header since the
output is not a pipe.  But actually it doesn't have one and has a pipe
file header.  At the end of the session, it tries to rewrite the regular
file header with updated features and it overwrites the data just
follows the pipe header.

Fix it by checking either the input and the output is a pipe.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-04-25 12:33:02 +02:00