perf: Add PERF_SAMPLE_PHYS_ADDR
Subsystems (3)
PATCH v7 1/1 perf: Add PERF_SAMPLE_PHYS_ADDR
From: Kan Liang <[email protected]>
For understanding how the workload maps to memory channels and hardware behavior, it's very important to collect address maps with physical addresses. For example, 3D XPoint access can only be found by filtering the physical address.
Add a new sample type for physical address.
perf already has a facility to collect data virtual address. This patch introduces a function to convert the virtual address to physical address. The function is quite generic and can be extended to any architecture as long as a virtual address is provided.
- For kernel direct mapping addresses, virt_to_phys is used to convert the virtual addresses to physical address.
- For user virtual addresses, __get_user_pages_fast is used to walk the pages tables for user physical address.
- This does not work for vmalloc addresses right now. These are not resolved, but code to do that could be added.
The new sample type requires collecting the virtual address. The virtual address will not be output unless SAMPLE_ADDR is applied.
For security, the physical address can only be exposed to root or privileged user.
---
This patch is kernel patch.
The user space patch can be found here.
https://www.spinics.net/lists/kernel/msg2587093.html
Changes since V6
- Requires collecting the virtual address for SAMPLE_PHYS_ADDR (PeterZ)
- Reflow the changelog (PeterZ)
arch/powerpc/perf/core-book3s.c | 3 ++- arch/x86/events/intel/ds.c | 2 +- arch/x86/events/perf_event.h | 2 +- include/linux/perf_event.h | 2 ++ include/uapi/linux/perf_event.h | 4 +++- kernel/events/core.c | 47 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 4 deletions(-)
arch/powerpc/perf/core-book3s.c +2 -1
@@ -2039,7 +2039,8 @@ static void record_and_restart(struct perf_event *event, unsigned long val,perf_sample_data_init (&data, ~0ULL , event->hw.last_period); -if (event->attr.sample_type &PERF_SAMPLE_ADDR ) +if (event->attr.sample_type & + (PERF_SAMPLE_ADDR |PERF_SAMPLE_PHYS_ADDR ))perf_get_data_addr (regs, &data.addr);if (event->attr.sample_type &PERF_SAMPLE_BRANCH_STACK ) {
arch/x86/events/intel/ds.c +1 -1
@@ -1175,7 +1175,7 @@ static void setup_pebs_sample_data(struct perf_event *event,else regs->flags &= ~PERF_EFLAGS_EXACT ; -if ((sample_type &PERF_SAMPLE_ADDR ) && +if ((sample_type & (PERF_SAMPLE_ADDR |PERF_SAMPLE_PHYS_ADDR )) && x86_pmu.intel_cap.pebs_format >=1 ) data->addr = pebs->dla;
arch/x86/events/perf_event.h +1 -1
@@ -91,7 +91,7 @@ struct amd_nb { (PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_ADDR | \PERF_SAMPLE_ID |PERF_SAMPLE_CPU |PERF_SAMPLE_STREAM_ID | \PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_IDENTIFIER | \ -PERF_SAMPLE_TRANSACTION ) +PERF_SAMPLE_TRANSACTION |PERF_SAMPLE_PHYS_ADDR )/* * A debug store configuration.
include/linux/perf_event.h +2 -0
@@ -944,6 +944,8 @@ struct perf_sample_data {struct perf_regs regs_intr;u64 stack_user_size; + +u64 phys_addr; }____cacheline_aligned ;/* default value for data source */
include/uapi/linux/perf_event.h +3 -1
@@ -139,8 +139,9 @@ enum perf_event_sample_format {PERF_SAMPLE_IDENTIFIER =1U <<16 ,PERF_SAMPLE_TRANSACTION =1U <<17 ,PERF_SAMPLE_REGS_INTR =1U <<18 , +PERF_SAMPLE_PHYS_ADDR =1U <<19 , - PERF_SAMPLE_MAX = 1U << 19, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */ };/*
@@ -814,6 +815,7 @@ enum perf_event_type {* { u64 transaction; } && PERF_SAMPLE_TRANSACTION * { u64 abi; # enum perf_sample_regs_abi * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR +* { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR * }; */ PERF_RECORD_SAMPLE = 9,
kernel/events/core.c +47 -0
77 lines not on this page · raw message
Signature · 1 line
2.4.3