linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 00/23] perf intel-pt: Better support for perf record --cpu
@ 2022-05-06 12:25 Adrian Hunter
  2022-05-06 12:25 ` [PATCH V2 01/23] perf intel-pt: Add a test for system-wide side band Adrian Hunter
                   ` (23 more replies)
  0 siblings, 24 replies; 70+ messages in thread
From: Adrian Hunter @ 2022-05-06 12:25 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Ian Rogers, Alexey Bayduraev, Namhyung Kim, Leo Yan,
	linux-kernel

Hi

Here are V2 patches to support capturing Intel PT sideband events such as
mmap, task, context switch, text poke etc, on every CPU even when tracing
selected user_requested_cpus.  That is, when using the perf record -C or
 --cpu option.

This is needed for:
1. text poke: a text poke on any CPU affects all CPUs
2. tracing user space: a user space process can migrate between CPUs so
mmap events that happen on a different CPU can be needed to decode a
user_requested_cpus CPU.

For example:

	Trace on CPU 1:

	perf record --kcore -C 1 -e intel_pt// &

	Start a task on CPU 0:

	taskset 0x1 testprog &

	Migrate it to CPU 1:

	taskset -p 0x2 <testprog pid>

	Stop tracing:

	kill %1

	Prior to these changes there will be errors decoding testprog
	in userspace because the comm and mmap events for testprog will not
	have been captured.

There is quite a bit of preparation:

The first patch is a small Intel PT test for system-wide side band.  The
test fails before the patches are applied, passed afterwards.

      perf intel-pt: Add a test for system-wide side band [new in V1]

The next 5 patches stop auxtrace mixing up mmap idx between evlist and
evsel.  That is going to matter when
evlist->all_cpus != evlist->user_requested_cpus != evsel->cpus:

      libperf evsel: Factor out perf_evsel__ioctl() [now applied]
      libperf evsel: Add perf_evsel__enable_thread()
      perf evlist: Use libperf functions in evlist__enable_event_idx()
      perf auxtrace: Move evlist__enable_event_idx() to auxtrace.c
      perf auxtrace: Do not mix up mmap idx

The next 6 patches stop attempts to auxtrace mmap when it is not an
auxtrace event e.g. when mmapping the CPUs on which only sideband is
captured:

      libperf evlist: Remove ->idx() per_cpu parameter
      libperf evlist: Move ->idx() into mmap_per_evsel()
      libperf evlist: Add evsel as a parameter to ->idx()
      perf auxtrace: Record whether an auxtrace mmap is needed
      perf auxctrace: Add mmap_needed to auxtrace_mmap_params
      perf auxtrace: Remove auxtrace_mmap_params__set_idx() per_cpu parameter

The next 5 patches switch to setting up dummy event maps before adding the
evsel so that the evsel is subject to map propagation, primarily to cause
addition of the evsel's CPUs to all_cpus.

      perf evlist: Factor out evlist__dummy_event()
      perf evlist: Add evlist__add_system_wide_dummy()
      perf record: Use evlist__add_system_wide_dummy() in record__config_text_poke()
      perf intel-pt: Use evlist__add_system_wide_dummy() for switch tracking
      perf intel-pt: Track sideband system-wide when needed

The remaining patches make more significant changes.

First change from using user_requested_cpus to using all_cpus where necessary:

      perf tools: Allow all_cpus to be a superset of user_requested_cpus

Secondly, mmap all per-thread and all per-cpu events:

      libperf evlist: Allow mixing per-thread and per-cpu mmaps
      libperf evlist: Check nr_mmaps is correct [new in V1]

Stop using system_wide flag for uncore because it will not work anymore:

      perf stat: Add requires_cpu flag for uncore
      libperf evsel: Add comments for booleans [new in V1]

Finally change map propagation so that system-wide events retain their cpus and
(dummy) threads:

      perf tools: Allow system-wide events to keep their own CPUs
      perf tools: Allow system-wide events to keep their own threads


Changes in V2:

	Added some Acked-by: Ian Rogers <irogers@google.com>

      libperf evsel: Add perf_evsel__enable_thread()
	Use perf_cpu_map__for_each_cpu()

      perf auxtrace: Add mmap_needed to auxtrace_mmap_params
	Add documentation comment for mmap_needed

      perf auxtrace: Remove auxtrace_mmap_params__set_idx() per_cpu parameter
	Fix missing auxtrace_mmap_params__set_idx change

      libperf evlist: Check nr_mmaps is correct
	Remove unused code

      libperf evsel: Add comments for booleans
	Amend comments

      perf evlist: Add evlist__add_dummy_on_all_cpus()
	Rename evlist__add_system_wide -> evlist__add_on_all_cpus
	Changed patch subject accordingly

      perf record: Use evlist__add_dummy_on_all_cpus() in record__config_text_poke()
	Rename evlist__add_system_wide -> evlist__add_on_all_cpus
	Changed patch subject accordingly

      perf intel-pt: Use evlist__add_dummy_on_all_cpus() for switch tracking
	Rename evlist__add_system_wide -> evlist__add_on_all_cpus
	Changed patch subject accordingly

Changes in V1:

      perf intel-pt: Add a test for system-wide side band
	New patch

      libperf evsel: Factor out perf_evsel__ioctl()
	Dropped because it has been applied.

      libperf evsel: Add perf_evsel__enable_thread()
	Rename variable i -> idx

      perf auxtrace: Do not mix up mmap idx
	Rename variable cpu to cpu_map_idx

      perf tools: Allow all_cpus to be a superset of user_requested_cpus
	Add Acked-by: Ian Rogers <irogers@google.com>

      libperf evlist: Allow mixing per-thread and per-cpu mmaps
	Fix perf_evlist__nr_mmaps() calculation

      libperf evlist: Check nr_mmaps is correct
	New patch

      libperf evsel: Add comments for booleans
	New patch

      perf tools: Allow system-wide events to keep their own CPUs
      perf tools: Allow system-wide events to keep their own threads


Adrian Hunter (23):
      perf intel-pt: Add a test for system-wide side band
      libperf evsel: Add perf_evsel__enable_thread()
      perf evlist: Use libperf functions in evlist__enable_event_idx()
      perf auxtrace: Move evlist__enable_event_idx() to auxtrace.c
      perf auxtrace: Do not mix up mmap idx
      libperf evlist: Remove ->idx() per_cpu parameter
      libperf evlist: Move ->idx() into mmap_per_evsel()
      libperf evlist: Add evsel as a parameter to ->idx()
      perf auxtrace: Record whether an auxtrace mmap is needed
      perf auxtrace: Add mmap_needed to auxtrace_mmap_params
      perf auxtrace: Remove auxtrace_mmap_params__set_idx() per_cpu parameter
      perf evlist: Factor out evlist__dummy_event()
      perf evlist: Add evlist__add_dummy_on_all_cpus()
      perf record: Use evlist__add_dummy_on_all_cpus() in record__config_text_poke()
      perf intel-pt: Use evlist__add_dummy_on_all_cpus() for switch tracking
      perf intel-pt: Track sideband system-wide when needed
      perf tools: Allow all_cpus to be a superset of user_requested_cpus
      libperf evlist: Allow mixing per-thread and per-cpu mmaps
      libperf evlist: Check nr_mmaps is correct
      perf stat: Add requires_cpu flag for uncore
      libperf evsel: Add comments for booleans
      perf tools: Allow system-wide events to keep their own CPUs
      perf tools: Allow system-wide events to keep their own threads

 tools/lib/perf/evlist.c                  |  80 ++++++++++-------------
 tools/lib/perf/evsel.c                   |  15 +++++
 tools/lib/perf/include/internal/evlist.h |   3 +-
 tools/lib/perf/include/internal/evsel.h  |  10 +++
 tools/lib/perf/include/perf/evsel.h      |   1 +
 tools/perf/arch/arm/util/cs-etm.c        |   1 +
 tools/perf/arch/arm64/util/arm-spe.c     |   1 +
 tools/perf/arch/s390/util/auxtrace.c     |   1 +
 tools/perf/arch/x86/util/intel-bts.c     |   1 +
 tools/perf/arch/x86/util/intel-pt.c      |  32 ++++------
 tools/perf/builtin-record.c              |  39 +++++-------
 tools/perf/builtin-stat.c                |   5 +-
 tools/perf/tests/shell/test_intel_pt.sh  |  71 +++++++++++++++++++++
 tools/perf/util/auxtrace.c               |  31 +++++++--
 tools/perf/util/auxtrace.h               |  10 +--
 tools/perf/util/evlist.c                 | 106 +++++++++++++++----------------
 tools/perf/util/evlist.h                 |   7 +-
 tools/perf/util/evsel.c                  |   1 +
 tools/perf/util/evsel.h                  |   1 +
 tools/perf/util/mmap.c                   |   4 +-
 tools/perf/util/parse-events.c           |   2 +-
 21 files changed, 261 insertions(+), 161 deletions(-)
 create mode 100755 tools/perf/tests/shell/test_intel_pt.sh


Regards
Adrian

^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2022-05-17 23:31 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 12:25 [PATCH V2 00/23] perf intel-pt: Better support for perf record --cpu Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 01/23] perf intel-pt: Add a test for system-wide side band Adrian Hunter
2022-05-10 17:18   ` Arnaldo Carvalho de Melo
2022-05-10 17:21     ` Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 02/23] libperf evsel: Add perf_evsel__enable_thread() Adrian Hunter
2022-05-06 17:06   ` Ian Rogers
2022-05-10 17:19   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 03/23] perf evlist: Use libperf functions in evlist__enable_event_idx() Adrian Hunter
2022-05-10 17:23   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 04/23] perf auxtrace: Move evlist__enable_event_idx() to auxtrace.c Adrian Hunter
2022-05-10 17:24   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 05/23] perf auxtrace: Do not mix up mmap idx Adrian Hunter
2022-05-10 17:25   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 06/23] libperf evlist: Remove ->idx() per_cpu parameter Adrian Hunter
2022-05-10 17:26   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 07/23] libperf evlist: Move ->idx() into mmap_per_evsel() Adrian Hunter
2022-05-10 17:26   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 08/23] libperf evlist: Add evsel as a parameter to ->idx() Adrian Hunter
2022-05-10 17:26   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 09/23] perf auxtrace: Record whether an auxtrace mmap is needed Adrian Hunter
2022-05-10 17:27   ` Arnaldo Carvalho de Melo
2022-05-06 12:25 ` [PATCH V2 10/23] perf auxtrace: Add mmap_needed to auxtrace_mmap_params Adrian Hunter
2022-05-06 20:16   ` Ian Rogers
2022-05-11  7:02     ` Adrian Hunter
2022-05-11  7:01   ` [PATCH V3 " Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 11/23] perf auxtrace: Remove auxtrace_mmap_params__set_idx() per_cpu parameter Adrian Hunter
2022-05-06 20:19   ` Ian Rogers
2022-05-06 12:25 ` [PATCH V2 12/23] perf evlist: Factor out evlist__dummy_event() Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 13/23] perf evlist: Add evlist__add_dummy_on_all_cpus() Adrian Hunter
2022-05-06 13:47   ` Ian Rogers
2022-05-06 15:07     ` Adrian Hunter
2022-05-06 15:35       ` Ian Rogers
2022-05-10 14:55         ` Adrian Hunter
2022-05-10 16:19           ` Ian Rogers
2022-05-10 16:24           ` Arnaldo Carvalho de Melo
2022-05-10 17:32             ` Adrian Hunter
2022-05-11  7:02   ` [PATCH V3 " Adrian Hunter
2022-05-11 22:50     ` Namhyung Kim
2022-05-12  4:33       ` Adrian Hunter
2022-05-12  5:01         ` Namhyung Kim
2022-05-06 12:25 ` [PATCH V2 14/23] perf record: Use evlist__add_dummy_on_all_cpus() in record__config_text_poke() Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 15/23] perf intel-pt: Use evlist__add_dummy_on_all_cpus() for switch tracking Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 16/23] perf intel-pt: Track sideband system-wide when needed Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 17/23] perf tools: Allow all_cpus to be a superset of user_requested_cpus Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 18/23] libperf evlist: Allow mixing per-thread and per-cpu mmaps Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 19/23] libperf evlist: Check nr_mmaps is correct Adrian Hunter
2022-05-06 20:20   ` Ian Rogers
2022-05-06 12:25 ` [PATCH V2 20/23] perf stat: Add requires_cpu flag for uncore Adrian Hunter
2022-05-06 12:25 ` [PATCH V2 21/23] libperf evsel: Add comments for booleans Adrian Hunter
2022-05-06 20:51   ` Ian Rogers
2022-05-11  7:03     ` Adrian Hunter
2022-05-12  5:34       ` Ian Rogers
2022-05-12 11:40         ` Adrian Hunter
2022-05-06 12:26 ` [PATCH V2 22/23] perf tools: Allow system-wide events to keep their own CPUs Adrian Hunter
2022-05-12  5:27   ` Namhyung Kim
2022-05-12 10:34     ` Adrian Hunter
2022-05-12 18:53       ` Namhyung Kim
2022-05-13  4:48         ` Adrian Hunter
2022-05-13 14:12           ` Liang, Kan
2022-05-13 15:21             ` Adrian Hunter
2022-05-13 15:46               ` Liang, Kan
2022-05-13 16:11                 ` Adrian Hunter
2022-05-13 16:42                   ` Namhyung Kim
2022-05-13 17:32                     ` Liang, Kan
2022-05-14 13:35           ` Arnaldo Carvalho de Melo
2022-05-17 23:31             ` Namhyung Kim
2022-05-06 12:26 ` [PATCH V2 23/23] perf tools: Allow system-wide events to keep their own threads Adrian Hunter
2022-05-08 15:08 ` [PATCH V2 00/23] perf intel-pt: Better support for perf record --cpu Leo Yan
2022-05-09  5:44   ` Adrian Hunter
2022-05-09  8:46     ` Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).