linux-stable/drivers/perf
Peter Zijlstra bd27568117 perf: Rewrite core context handling
There have been various issues and limitations with the way perf uses
(task) contexts to track events. Most notable is the single hardware
PMU task context, which has resulted in a number of yucky things (both
proposed and merged).

Notably:
 - HW breakpoint PMU
 - ARM big.little PMU / Intel ADL PMU
 - Intel Branch Monitoring PMU
 - AMD IBS PMU
 - S390 cpum_cf PMU
 - PowerPC trace_imc PMU

*Current design:*

Currently we have a per task and per cpu perf_event_contexts:

  task_struct::perf_events_ctxp[] <-> perf_event_context <-> perf_cpu_context
       ^                                 |    ^     |           ^
       `---------------------------------'    |     `--> pmu ---'
                                              v           ^
                                         perf_event ------'

Each task has an array of pointers to a perf_event_context. Each
perf_event_context has a direct relation to a PMU and a group of
events for that PMU. The task related perf_event_context's have a
pointer back to that task.

Each PMU has a per-cpu pointer to a per-cpu perf_cpu_context, which
includes a perf_event_context, which again has a direct relation to
that PMU, and a group of events for that PMU.

The perf_cpu_context also tracks which task context is currently
associated with that CPU and includes a few other things like the
hrtimer for rotation etc.

Each perf_event is then associated with its PMU and one
perf_event_context.

*Proposed design:*

New design proposed by this patch reduce to a single task context and
a single CPU context but adds some intermediate data-structures:

  task_struct::perf_event_ctxp -> perf_event_context <- perf_cpu_context
       ^                           |   ^ ^
       `---------------------------'   | |
                                       | |    perf_cpu_pmu_context <--.
                                       | `----.    ^                  |
                                       |      |    |                  |
                                       |      v    v                  |
                                       | ,--> perf_event_pmu_context  |
                                       | |                            |
                                       | |                            |
                                       v v                            |
                                  perf_event ---> pmu ----------------'

With the new design, perf_event_context will hold all events for all
pmus in the (respective pinned/flexible) rbtrees. This can be achieved
by adding pmu to rbtree key:

  {cpu, pmu, cgroup, group_index}

Each perf_event_context carries a list of perf_event_pmu_context which
is used to hold per-pmu-per-context state. For example, it keeps track
of currently active events for that pmu, a pmu specific task_ctx_data,
a flag to tell whether rotation is required or not etc.

Additionally, perf_cpu_pmu_context is used to hold per-pmu-per-cpu
state like hrtimer details to drive the event rotation, a pointer to
perf_event_pmu_context of currently running task and some other
ancillary information.

Each perf_event is associated to it's pmu, perf_event_context and
perf_event_pmu_context.

Further optimizations to current implementation are possible. For
example, ctx_resched() can be optimized to reschedule only single pmu
events.

Much thanks to Ravi for picking this up and pushing it towards
completion.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20221008062424.313-1-ravi.bangoria@amd.com
2022-10-27 20:12:16 +02:00
..
hisilicon drivers/perf: hisi: add driver for HNS3 PMU 2022-07-06 11:25:53 +01:00
Kconfig drivers/perf: ALIBABA_UNCORE_DRW_PMU should depend on ACPI 2022-10-07 14:47:44 +01:00
Makefile drivers/perf: add DDR Sub-System Driveway PMU driver for Yitian 710 SoC 2022-09-22 14:09:10 +01:00
alibaba_uncore_drw_pmu.c drivers/perf: fix return value check in ali_drw_pmu_probe() 2022-10-07 14:47:38 +01:00
apple_m1_cpu_pmu.c drivers/perf: Add Apple icestorm/firestorm CPU PMU driver 2022-03-08 13:32:48 +00:00
arm-cci.c perf/arm-cci: Use the bitmap API to allocate bitmaps 2022-07-06 11:02:58 +01:00
arm-ccn.c drivers/perf:Directly use ida_alloc()/free() 2022-06-23 15:44:45 +01:00
arm-cmn.c perf/arm-cmn: Add more bits to child node address offset field 2022-09-22 14:30:00 +01:00
arm_dmc620_pmu.c perf/arm-dmc620: Use irq_set_affinity() 2021-05-24 11:01:59 +01:00
arm_dsu_pmu.c ACPI: Drop parent field from struct acpi_device 2022-08-24 20:55:24 +02:00
arm_pmu.c perf: Rewrite core context handling 2022-10-27 20:12:16 +02:00
arm_pmu_acpi.c perf: check return value of armpmu_request_irq() 2022-05-06 15:04:48 +01:00
arm_pmu_platform.c perf/arm_pmu_platform: fix tests for platform_get_irq() failure 2022-09-01 12:01:40 +01:00
arm_smmuv3_pmu.c perf/smmuv3: Don't cast parameter in bit operations 2022-02-15 16:51:26 +00:00
arm_spe_pmu.c Perf events updates for v6.1: 2022-10-10 09:27:46 -07:00
fsl_imx8_ddr_perf.c drivers/perf: Directly use ida_alloc()/free() 2022-06-23 15:44:45 +01:00
marvell_cn10k_ddr_pmu.c perf/marvell: Fix !CONFIG_OF build for CN10K DDR PMU driver 2022-03-09 12:31:00 +00:00
marvell_cn10k_tad_pmu.c perf/marvell_cn10k: Fix TAD PMU register offset 2022-06-24 13:21:38 +01:00
qcom_l2_pmu.c perf: qcom_l2_pmu: Refactor _UID handling to use acpi_dev_uid_to_integer() 2022-09-19 18:34:42 +02:00
qcom_l3_pmu.c ACPI: Drop parent field from struct acpi_device 2022-08-24 20:55:24 +02:00
riscv_pmu.c perf: riscv_pmu{,_sbi}: Miscallenous improvement & fixes 2022-08-12 07:17:38 -07:00
riscv_pmu_legacy.c RISC-V Patches for the 6.1 Merge Window, Part 1 2022-10-09 13:24:01 -07:00
riscv_pmu_sbi.c RISC-V: Re-enable counter access from userspace 2022-10-13 11:18:39 -07:00
thunderx2_pmu.c perf: Replace acpi_bus_get_device() 2022-02-08 15:14:53 +00:00
xgene_pmu.c perf: replace bitmap_weight with bitmap_empty where appropriate 2022-02-15 14:38:57 +00:00