diff options
| author | Kan Liang <kan.liang@linux.intel.com> | 2025-03-14 20:26:56 +0300 |
|---|---|---|
| committer | Peter Zijlstra <peterz@infradead.org> | 2025-03-17 13:23:37 +0300 |
| commit | 506e64e710ff9573fd2b86686528762b7901b5e4 (patch) | |
| tree | 273a8f513ff1aca1aeb0947f5f31a1ae52c8a398 /include/linux | |
| parent | fdfda868ee3b5da1fbdb7710b731e09d8dd3a615 (diff) | |
| download | linux-506e64e710ff9573fd2b86686528762b7901b5e4.tar.xz | |
perf: attach/detach PMU specific data
The LBR call stack data has to be saved/restored during context switch
to fix the shorter LBRs call stacks issue in the system-wide mode.
Allocate PMU specific data and attach them to the corresponding
task_struct during LBR call stack monitoring.
When a LBR call stack event is accounted, the perf_ctx_data for the
related tasks will be allocated/attached by attach_perf_ctx_data().
When a LBR call stack event is unaccounted, the perf_ctx_data for
related tasks will be detached/freed by detach_perf_ctx_data().
The LBR call stack event could be a per-task event or a system-wide
event.
- For a per-task event, perf only allocates the perf_ctx_data for the
current task. If the allocation fails, perf will error out.
- For a system-wide event, perf has to allocate the perf_ctx_data for
both the existing tasks and the upcoming tasks.
The allocation for the existing tasks is done in perf_event_alloc().
If any allocation fails, perf will error out.
The allocation for the new tasks will be done in perf_event_fork().
A global reader/writer semaphore, global_ctx_data_rwsem, is added to
address the global race.
- The perf_ctx_data only be freed by the last LBR call stack event.
The number of the per-task events is tracked by refcount of each task.
Since the system-wide events impact all tasks, it's not practical to
go through the whole task list to update the refcount for each
system-wide event. The number of system-wide events is tracked by a
global variable global_ctx_data_ref.
Suggested-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250314172700.438923-3-kan.liang@linux.intel.com
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/perf_event.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 75d9b1e93f39..2551170c0d18 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -676,11 +676,12 @@ struct swevent_hlist { #define PERF_ATTACH_GROUP 0x0002 #define PERF_ATTACH_TASK 0x0004 #define PERF_ATTACH_TASK_DATA 0x0008 -#define PERF_ATTACH_ITRACE 0x0010 +#define PERF_ATTACH_GLOBAL_DATA 0x0010 #define PERF_ATTACH_SCHED_CB 0x0020 #define PERF_ATTACH_CHILD 0x0040 #define PERF_ATTACH_EXCLUSIVE 0x0080 #define PERF_ATTACH_CALLCHAIN 0x0100 +#define PERF_ATTACH_ITRACE 0x0200 struct bpf_prog; struct perf_cgroup; |
