linux-stable/tools/perf/arch/x86/util
Ian Rogers 347c2f0a09 perf parse-events: Sort and group parsed events
This change is intended to be a no-op for most current cases, the
default sort order is the order the events were parsed. Where it
varies is in how groups are handled. Previously an uncore and core
event that are grouped would most often cause the group to be removed:

```
$ perf stat -e '{instructions,uncore_imc_free_running_0/data_total/}' -a sleep 1
WARNING: grouped events cpus do not match, disabling group:
  anon group { instructions, uncore_imc_free_running_0/data_total/ }
...
```

However, when wildcards are used the events should be re-sorted and
re-grouped in parse_events__set_leader, but this currently fails for
simple examples:

```
$ perf stat -e '{uncore_imc_free_running/data_read/,uncore_imc_free_running/data_write/}' -a sleep 1

 Performance counter stats for 'system wide':

     <not counted> MiB  uncore_imc_free_running/data_read/
     <not counted> MiB  uncore_imc_free_running/data_write/

       1.000996992 seconds time elapsed
```

A futher failure mode, fixed in this patch, is to force topdown events
into a group.

This change moves sorting the evsels in the evlist after parsing. It
requires parsing to set up groups. First the evsels are sorted
respecting the existing groupings and parse order, but also reordering
to ensure evsels of the same PMU and group appear together. So that
software and aux events respect groups, their pmu_name is taken from
the group leader. The sorting is done with list_sort removing a memory
allocation.

After sorting a pass is done to correct the group leaders and for
topdown events ensuring they have a group leader.

This fixes the problems seen before:

```
$ perf stat -e '{uncore_imc_free_running/data_read/,uncore_imc_free_running/data_write/}' -a sleep 1

 Performance counter stats for 'system wide':

            727.42 MiB  uncore_imc_free_running/data_read/
             81.84 MiB  uncore_imc_free_running/data_write/

       1.000948615 seconds time elapsed
```

As well as making groups not fail for cases like:

```
$ perf stat -e '{imc_free_running_0/data_total/,imc_free_running_1/data_total/}' -a sleep 1

 Performance counter stats for 'system wide':

            256.47 MiB  imc_free_running_0/data_total/
            256.48 MiB  imc_free_running_1/data_total/

       1.001165442 seconds time elapsed
```

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
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: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20230312021543.3060328-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-03-13 17:42:26 -03:00
..
archinsn.c tools/perf: Convert to insn_decode() 2021-03-15 12:41:26 +01:00
auxtrace.c perf pmu: Earlier PMU auxtrace initialization 2023-03-13 15:12:19 -03:00
Build perf build: Use libtraceevent from the system 2022-12-14 11:16:12 -03:00
cpuid.h perf tsc: Add arch TSC frequency information 2022-07-25 12:28:00 -03:00
dwarf-regs.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
event.c perf event x86: Add retire_lat when synthesizing PERF_SAMPLE_WEIGHT_STRUCT 2023-02-06 14:56:22 -03:00
evlist.c perf parse-events: Sort and group parsed events 2023-03-13 17:42:26 -03:00
evsel.c perf evsel: Add arch_evsel__hw_name() 2022-07-29 13:41:19 -03:00
evsel.h perf record: Support sample-read topdown metric group for hybrid platforms 2022-06-03 21:30:10 +02:00
header.c perf tsc: Add arch TSC frequency information 2022-07-25 12:28:00 -03:00
intel-bts.c perf tools: Do not pass NULL to parse_events() 2022-08-10 14:30:09 -03:00
intel-pt.c perf build: Use libtraceevent from the system 2022-12-14 11:16:12 -03:00
iostat.c perf stat: Pass through 'struct outstate' 2022-11-24 09:40:37 -03:00
kvm-stat.c perf x86 kvm-stat: Support to analyze kvm MSR 2021-05-12 12:43:12 -03:00
machine.c tools: Fix off-by 1 relative directory includes 2020-03-06 08:36:46 -03:00
mem-events.c perf mem/c2c: Add load store event mappings for AMD 2022-10-06 16:30:06 -03:00
perf_regs.c perf regs x86: Fix arch__intr_reg_mask() for the hybrid platform 2022-05-21 14:45:19 -03:00
pmu.c perf pmu: Earlier PMU auxtrace initialization 2023-03-13 15:12:19 -03:00
topdown.c perf stat: Implement --topdown using json metrics 2023-02-19 08:07:24 -03:00
topdown.h perf stat: Add TopdownL1 metric as a default if present 2023-02-19 08:07:19 -03:00
tsc.c perf arch x86: Add missing stdlib.h to get free() prototype 2022-10-27 16:37:26 -03:00
unwind-libdw.c perf tools: Move 'struct perf_sample' to a separate header file to disentangle headers 2022-10-31 11:06:41 -03:00
unwind-libunwind.c perf unwind: Fix libunwind build failure on i386 systems 2019-09-26 21:59:38 +02:00