linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/21] perf metric: Fixes and allow modifiers
@ 2021-10-15 17:21 Ian Rogers
  2021-10-15 17:21 ` [PATCH v2 01/21] tools lib: Add list_sort Ian Rogers
                   ` (21 more replies)
  0 siblings, 22 replies; 38+ messages in thread
From: Ian Rogers @ 2021-10-15 17:21 UTC (permalink / raw)
  To: Andi Kleen, Jiri Olsa, Jin Yao, Namhyung Kim, John Garry,
	Kajol Jain, Paul A . Clarke, Arnaldo Carvalho de Melo,
	Riccardo Mancini, Kan Liang, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Kees Cook, Sami Tolvanen,
	Nick Desaulniers, Andrew Morton, Jacob Keller, Zhen Lei, ToastC,
	Joakim Zhang, Felix Fietkau, Jiapeng Chong, Song Liu,
	Fabian Hemmer, Alexander Antonov, Nicholas Fraser, Adrian Hunter,
	Denys Zagorui, Wan Jiabing, Thomas Richter, Sumanth Korikkar,
	Heiko Carstens, Changbin Du, linux-kernel, linux-perf-users,
	Andrew Kilroy
  Cc: Stephane Eranian, Ian Rogers

There are 4 main changes in this patch set:
 - perf metric: Modify resolution and recursion check.
 - perf parse-events: Add new "metric-id" term.
 - perf metrics: Modify setup and deduplication
 - perf metric: Allow modifiers on metrics.

In overview the changes start by trying to simplify the metric code,
then it fixes various bugs and finally it builds a new feature of
allowing metrics like:

$ perf stat -M IPC:u,IPC:k -a sleep 1

 Performance counter stats for 'system wide':

        93,269,988      inst_retired.any:k        #     0.26 IPC:k                  
       352,037,460      cpu_clk_unhalted.thread:k                                   
        70,317,865      inst_retired.any:u        #     0.76 IPC:u                  
        92,762,220      cpu_clk_unhalted.thread:u                                   

       1.003754577 seconds time elapsed

Previous complexity came from using the evsel->name as the identifier
for events in metrics, however, this name isn't stable and has issues
around wildcard expansion. These changes fix this by adding a
dedicated metric_id to evsels, performing deduplication on IDs before
event parsing and not handling all evsels on a single evlist.

The recursion and metric_ref logic is simplified, the first by moving
data from the heap to the stack, the latter by building in an array
rather than a linked list. This logic is integral to metric set up and
simplification makes the effects of the changes easier to follow, in
particular as there are fewer structs being maintained.

Event parsing is modified to allow qualifiers on kernel PMU events,
this is necessary to allow the metric-id to be added, but allows
qualifiers in other cases like specifying callgraph or a name.

There is a certain amount of comment adding and const-ification, this
is with a view to making the code more intention revealing and to aid
following its logic. For example, the pmu event tables should never
change and it'd be a bug if they ever did, it's therefore strange to
access it using non-const pointers.

The kernel list_sort.c/h are added for use sorting metrics in order to
deduplicate/reuse events from a larger group in a smaller one. This
was previously done by inserting in size order, but that only worked
within a metric group.

Some of the commit messages show the TopDownL1 metrics being used on a
SkylakeX machine. These metrics were removed by
c4ad8fabd03f76ed3a2a4c8aef6baf6cd4f24542 ("perf vendor events: Update
metrics for SkyLake Server") and the data was gathered with this patch
reverted.

v2. Add METADATA fixes to 'Add list_sort' suggested by
    Arnaldo Carvalho de Melo <acme@kernel.org>.
    Fix arm64 function declaration in 'Add const to pmu_events_map' found by
    Andrew Kilroy <andrew.kilroy@arm.com>.
    Add a static in 'Make pmu_event tables const' suggested by
    John Garry <john.garry@huawei.com>.
    Add acked-by: Andi Kleen <ak@linux.intel.com>.
    Fix/handle 0 events case in 'Modify setup and deduplication'.
    Fix a missed strdup that resulted in a double free in 'Allow modifiers on
    metrics.'

Ian Rogers (21):
  tools lib: Add list_sort.
  perf pmu: Add const to pmu_events_map.
  perf pmu: Make pmu_sys_event_tables const.
  perf pmu: Make pmu_event tables const.
  perf metric: Move runtime value to the expr context
  perf metric: Add documentation and rename a variable.
  perf metric: Add metric new and free
  perf metric: Only add a referenced metric once
  perf metric: Modify resolution and recursion check.
  perf metric: Comment data structures.
  perf metric: Document the internal 'struct metric'
  perf metric: Simplify metric_refs calculation.
  perf parse-events: Add const to evsel name
  perf parse-events: Add new "metric-id" term.
  perf parse-events: Allow config on kernel PMU events
  perf metric: Encode and use metric-id as qualifier
  perf expr: Add subset utility.
  perf metrics: Modify setup and deduplication
  perf metric: Switch fprintf to pr_err.
  perf parse-events: Identify broken modifiers.
  perf metric: Allow modifiers on metrics.

 tools/include/linux/list_sort.h       |   14 +
 tools/lib/list_sort.c                 |  252 +++++
 tools/perf/MANIFEST                   |    1 +
 tools/perf/arch/arm64/util/pmu.c      |    2 +-
 tools/perf/arch/powerpc/util/header.c |    2 +-
 tools/perf/check-headers.sh           |    2 +
 tools/perf/pmu-events/jevents.c       |    6 +-
 tools/perf/pmu-events/pmu-events.h    |    8 +-
 tools/perf/tests/expand-cgroup.c      |    2 +-
 tools/perf/tests/expr.c               |   29 +-
 tools/perf/tests/parse-metric.c       |    2 +-
 tools/perf/tests/pmu-events.c         |   59 +-
 tools/perf/util/Build                 |    5 +
 tools/perf/util/evsel.c               |   17 +
 tools/perf/util/evsel.h               |    2 +
 tools/perf/util/expr.c                |   56 +-
 tools/perf/util/expr.h                |   16 +-
 tools/perf/util/expr.l                |    6 +-
 tools/perf/util/expr.y                |    2 +-
 tools/perf/util/metricgroup.c         | 1461 ++++++++++++++-----------
 tools/perf/util/metricgroup.h         |   35 +-
 tools/perf/util/parse-events-hybrid.c |   34 +-
 tools/perf/util/parse-events-hybrid.h |    6 +-
 tools/perf/util/parse-events.c        |  166 +--
 tools/perf/util/parse-events.h        |   11 +-
 tools/perf/util/parse-events.l        |   18 +-
 tools/perf/util/parse-events.y        |   27 +-
 tools/perf/util/pfm.c                 |    3 +-
 tools/perf/util/pmu.c                 |   22 +-
 tools/perf/util/pmu.h                 |   10 +-
 tools/perf/util/python-ext-sources    |    1 +
 tools/perf/util/s390-sample-raw.c     |    6 +-
 tools/perf/util/stat-shadow.c         |   27 +-
 33 files changed, 1470 insertions(+), 840 deletions(-)
 create mode 100644 tools/include/linux/list_sort.h
 create mode 100644 tools/lib/list_sort.c

-- 
2.33.0.1079.g6e70778dc9-goog


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

end of thread, other threads:[~2021-10-26  8:19 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-15 17:21 [PATCH v2 00/21] perf metric: Fixes and allow modifiers Ian Rogers
2021-10-15 17:21 ` [PATCH v2 01/21] tools lib: Add list_sort Ian Rogers
2021-10-15 17:21 ` [PATCH v2 02/21] perf pmu: Add const to pmu_events_map Ian Rogers
2021-10-26  5:20   ` kajoljain
2021-10-15 17:21 ` [PATCH v2 03/21] perf pmu: Make pmu_sys_event_tables const Ian Rogers
2021-10-19 11:06   ` John Garry
2021-10-26  5:26   ` kajoljain
2021-10-15 17:21 ` [PATCH v2 04/21] perf pmu: Make pmu_event tables const Ian Rogers
2021-10-19 11:19   ` John Garry
2021-10-20 13:24     ` Arnaldo Carvalho de Melo
2021-10-26  6:18   ` kajoljain
2021-10-15 17:21 ` [PATCH v2 05/21] perf metric: Move runtime value to the expr context Ian Rogers
2021-10-26  8:10   ` kajoljain
2021-10-15 17:21 ` [PATCH v2 06/21] perf metric: Add documentation and rename a variable Ian Rogers
2021-10-26  8:18   ` kajoljain
2021-10-15 17:21 ` [PATCH v2 07/21] perf metric: Add metric new and free Ian Rogers
2021-10-19 11:30   ` John Garry
2021-10-15 17:21 ` [PATCH v2 08/21] perf metric: Only add a referenced metric once Ian Rogers
2021-10-15 17:21 ` [PATCH v2 09/21] perf metric: Modify resolution and recursion check Ian Rogers
2021-10-15 17:21 ` [PATCH v2 10/21] perf metric: Comment data structures Ian Rogers
2021-10-15 17:21 ` [PATCH v2 11/21] perf metric: Document the internal 'struct metric' Ian Rogers
2021-10-15 17:21 ` [PATCH v2 12/21] perf metric: Simplify metric_refs calculation Ian Rogers
2021-10-15 17:21 ` [PATCH v2 13/21] perf parse-events: Add const to evsel name Ian Rogers
2021-10-15 17:21 ` [PATCH v2 14/21] perf parse-events: Add new "metric-id" term Ian Rogers
2021-10-15 17:21 ` [PATCH v2 15/21] perf parse-events: Allow config on kernel PMU events Ian Rogers
2021-10-15 17:21 ` [PATCH v2 16/21] perf metric: Encode and use metric-id as qualifier Ian Rogers
2021-10-15 17:21 ` [PATCH v2 17/21] perf expr: Add subset utility Ian Rogers
2021-10-15 17:21 ` [PATCH v2 18/21] perf metrics: Modify setup and deduplication Ian Rogers
2021-10-15 17:21 ` [PATCH v2 19/21] perf metric: Switch fprintf to pr_err Ian Rogers
2021-10-15 17:21 ` [PATCH v2 20/21] perf parse-events: Identify broken modifiers Ian Rogers
2021-10-15 17:21 ` [PATCH v2 21/21] perf metric: Allow modifiers on metrics Ian Rogers
2021-10-19 15:06   ` Arnaldo Carvalho de Melo
2021-10-19 15:13     ` Arnaldo Carvalho de Melo
2021-10-19 15:17       ` Arnaldo Carvalho de Melo
2021-10-19 15:18         ` Arnaldo Carvalho de Melo
2021-10-19 20:00           ` Ian Rogers
2021-10-20  0:35             ` Arnaldo Carvalho de Melo
2021-10-20 14:31 ` [PATCH v2 00/21] perf metric: Fixes and allow modifiers Arnaldo Carvalho de Melo

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