linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/9] perf report: Add latency and parallelism profiling
@ 2025-02-13  9:08 Dmitry Vyukov
  2025-02-13  9:08 ` [PATCH v7 1/9] perf report: Add machine parallelism Dmitry Vyukov
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Dmitry Vyukov @ 2025-02-13  9:08 UTC (permalink / raw)
  To: namhyung, irogers, acme, ak; +Cc: linux-perf-users, linux-kernel, Dmitry Vyukov

There are two notions of time: wall-clock time and CPU time.
For a single-threaded program, or a program running on a single-core
machine, these notions are the same. However, for a multi-threaded/
multi-process program running on a multi-core machine, these notions are
significantly different. Each second of wall-clock time we have
number-of-cores seconds of CPU time.

Currently perf only allows to profile CPU time. Perf (and all other
existing profilers to the be best of my knowledge) does not allow to
profile wall-clock time.

Optimizing CPU overhead is useful to improve 'throughput', while
optimizing wall-clock overhead is useful to improve 'latency'.
These profiles are complementary and are not interchangeable.
Examples of where latency profile is needed:
 - optimzing build latency
 - optimizing server request latency
 - optimizing ML training/inference latency
 - optimizing running time of any command line program

CPU profile is useless for these use cases at best (if a user understands
the difference), or misleading at worst (if a user tries to use a wrong
profile for a job).

This series add latency and parallelization profiling.
See the added documentation and flags descriptions for details.

Brief outline of the implementation:
 - add context switch collection during record
 - calculate number of threads running on CPUs (parallelism level)
   during report
 - divide each sample weight by the parallelism level
This effectively models that we were taking 1 sample per unit of
wall-clock time.

We still default to the CPU profile, so it's up to users to learn
about the second profiling mode and use it when appropriate.

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Changes in v7:
 - add comment perf_hpp__init() re was_taken logic
 - add tips.txt example with time/time-quantum
 - rebased to perf-tools-next HEAD

Changes in v6:
 - remove latency column in perf_hpp__cancel_latency if
   sort order is specified, but does not include latency
 - add tests
 - rebased to perf-tools-next HEAD

Changes in v5:
 - fixed formatting of latency field in --stdout mode
 - added description of --latency flag in Documentation flags

Changes in v4:
 - added "Shrink struct hist_entry size" commit
 - rebased to perf-tools-next HEAD

Changes in v3:
 - rebase and split into patches
 - rename 'wallclock' to 'latency' everywhere
 - don't enable latency profiling by default,
   instead add record/report --latency flag

Dmitry Vyukov (9):
  perf report: Add machine parallelism
  perf report: Add parallelism sort key
  perf report: Switch filtered from u8 to u16
  perf report: Add parallelism filter
  perf report: Add latency output field
  perf report: Add --latency flag
  perf report: Add latency and parallelism profiling documentation
  perf test: Add tests for latency and parallelism profiling
  perf hist: Shrink struct hist_entry size

 .../callchain-overhead-calculation.txt        |   5 +-
 .../cpu-and-latency-overheads.txt             |  85 +++++++++++++
 tools/perf/Documentation/perf-record.txt      |   4 +
 tools/perf/Documentation/perf-report.txt      |  54 +++++---
 tools/perf/Documentation/tips.txt             |   4 +
 tools/perf/builtin-record.c                   |  20 +++
 tools/perf/builtin-report.c                   |  39 ++++++
 tools/perf/tests/shell/base_report/setup.sh   |  18 ++-
 .../tests/shell/base_report/test_basic.sh     |  52 ++++++++
 tools/perf/ui/browsers/hists.c                |  27 ++--
 tools/perf/ui/hist.c                          | 117 ++++++++++++------
 tools/perf/util/addr_location.c               |   1 +
 tools/perf/util/addr_location.h               |   7 +-
 tools/perf/util/event.c                       |  11 ++
 tools/perf/util/events_stats.h                |   2 +
 tools/perf/util/hist.c                        |  90 +++++++++++---
 tools/perf/util/hist.h                        |  32 ++++-
 tools/perf/util/machine.c                     |   7 ++
 tools/perf/util/machine.h                     |   6 +
 tools/perf/util/sample.h                      |   2 +-
 tools/perf/util/session.c                     |  12 ++
 tools/perf/util/session.h                     |   1 +
 tools/perf/util/sort.c                        |  69 ++++++++++-
 tools/perf/util/sort.h                        |   3 +-
 tools/perf/util/symbol.c                      |  34 +++++
 tools/perf/util/symbol_conf.h                 |   8 +-
 26 files changed, 614 insertions(+), 96 deletions(-)
 create mode 100644 tools/perf/Documentation/cpu-and-latency-overheads.txt


base-commit: ee8aef2d232142e5fdfed9c16132815969a0bf81
-- 
2.48.1.502.g6dc24dfdaf-goog


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

end of thread, other threads:[~2025-02-19 20:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-13  9:08 [PATCH v7 0/9] perf report: Add latency and parallelism profiling Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 1/9] perf report: Add machine parallelism Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 2/9] perf report: Add parallelism sort key Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 3/9] perf report: Switch filtered from u8 to u16 Dmitry Vyukov
2025-02-18 18:46   ` Namhyung Kim
2025-02-13  9:08 ` [PATCH v7 4/9] perf report: Add parallelism filter Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 5/9] perf report: Add latency output field Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 6/9] perf report: Add --latency flag Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 7/9] perf report: Add latency and parallelism profiling documentation Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 8/9] perf test: Add tests for latency and parallelism profiling Dmitry Vyukov
2025-02-13  9:08 ` [PATCH v7 9/9] perf hist: Shrink struct hist_entry size Dmitry Vyukov
2025-02-14 18:05 ` [PATCH v7 0/9] perf report: Add latency and parallelism profiling Andi Kleen
2025-02-18  6:27   ` Dmitry Vyukov
2025-02-19 20:32 ` Namhyung Kim

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).