perf: Save PMU specific data in task_struct
Subsystems (5)
PATCH v8 1/6 perf: Save PMU specific data in task_struct
From: Kan Liang <[email protected]>
Some PMU specific data has to be saved/restored during context switch, e.g. LBR call stack data. Currently, the data is saved in event context structure, but only for per-process event. For system-wide event, because of missing the LBR call stack data after context switch, LBR callstacks are always shorter in comparison to per-process mode.
For example,
Per-process mode:
$perf record --call-graph lbr -- taskset -c 0 ./tchain_edit
- 99.90% 99.86% tchain_edit tchain_edit [.] f3
99.86% _start
__libc_start_main
generic_start_main
main
f1
- f2
f3System-wide mode: $perf record --call-graph lbr -a -- taskset -c 0 ./tchain_edit
- 99.88% 99.82% tchain_edit tchain_edit [.] f3
- 62.02% main
f1
f2
f3
- 28.83% f1
- f2
f3
- 28.83% f1
- f2
f3
- 8.88% generic_start_main
main
f1
f2
f3It isn't practical to simply allocate the data for system-wide event in CPU context structure for all tasks. We have no idea which CPU a task will be scheduled to. The duplicated LBR data has to be maintained on every CPU context structure. That's a huge waste. Otherwise, the LBR data still lost if the task is scheduled to another CPU.
Save the pmu specific data in task_struct. The size of pmu specific data is 788 bytes for LBR call stack. Usually, the overall amount of threads doesn't exceed a few thousands. For 10K threads, keeping LBR data would consume additional ~8MB. The additional space will only be allocated during LBR call stack monitoring. It will be released when the monitoring is finished.
Furthermore, moving task_ctx_data from perf_event_context to task_struct can reduce complexity and make things clearer. E.g. perf doesn't need to swap task_ctx_data on optimized context switch path.
This patch set is just the first step. There could be other optimization/extension on top of this patch set. E.g. for cgroup profiling, perf just needs to save/store the LBR call stack information for tasks in specific cgroup. That could reduce the additional space. Also, the LBR call stack can be available for software events, or allow even debugging use cases, like LBRs on crash later.
The Kmem cache of pmu specific data is saved in struct perf_ctx_data. It's required when child task allocates the space.
The refcount in struct perf_ctx_data is used to track the users of pmu specific data.
---
The whole patch set was posted several years ago. But it's buried in the LKML without merging. I've received several requests recently to fix the LBR issue with system-wide events. Rebase and repost it.
- Rebase on top of Peter's perf/core branch.
commit 347b40fa96a1 ("perf: Extend per event callchain limit to branch stack")
The V6 can be found here.
https://lore.kernel.org/lkml/[email protected]/
include/linux/perf_event.h | 30 ++++++++++++++++++++++++++++++ include/linux/sched.h | 2 ++ kernel/events/core.c | 1 + 3 files changed, 33 insertions(+)
include/linux/perf_event.h +30 -0
@@ -1021,6 +1021,36 @@ struct perf_event_context {local_t nr_no_switch_fast; }; +/** +* struct perf_ctx_data - PMU specific data for a task +* @rcu_head: To avoid the race on free PMU specific data +* @refcount: To track users +* @global: To track system-wide users +* @ctx_cache: Kmem cache of PMU specific data +* @data: PMU specific data +* +* Currently, the struct is only used in Intel LBR call stack mode to +* save/restore the call stack of a task on context switches. +* The data only be allocated when Intel LBR call stack mode is enabled. +* The data will be freed when the mode is disabled. The rcu_head is +* used to prevent the race on free the data. +* The content of the data will only be accessed in context switch, which +* should be protected by rcu_read_lock(). +* +* Careful: Struct perf_ctx_data is added as a pointor in struct task_struct. +* When system-wide Intel LBR call stack mode is enabled, a buffer with +* constant size will be allocated for each task. +* Also, system memory consumption can further grow when the size of +* struct perf_ctx_data enlarges. +*/ +struct perf_ctx_data { +struct rcu_head rcu_head; +refcount_t refcount; +int global; +struct kmem_cache *ctx_cache; +void *data; +}; +struct perf_cpu_pmu_context {struct perf_event_pmu_context epc;struct perf_event_pmu_context *task_epc;
include/linux/sched.h +2 -0
@@ -65,6 +65,7 @@ struct mempolicy;struct nameidata ;struct nsproxy ;struct perf_event_context ; +struct perf_ctx_data ;struct pid_namespace ;struct pipe_inode_info ;struct rcu_node ;
@@ -1311,6 +1312,7 @@ struct task_struct {struct perf_event_context *perf_event_ctxp;struct mutex perf_event_mutex;struct list_head perf_event_list; +struct perf_ctx_data __rcu *perf_ctx_data;#endif #ifdef CONFIG_DEBUG_PREEMPT unsigned long preempt_disable_ip;
kernel/events/core.c +1 -0
@@ -14061,6 +14061,7 @@ int perf_event_init_task(struct task_struct *child, u64 clone_flags) child->perf_event_ctxp =NULL ;mutex_init (&child->perf_event_mutex);INIT_LIST_HEAD (&child->perf_event_list); + child->perf_ctx_data =NULL ; ret =perf_event_init_context (child, clone_flags);if (ret) {
Signature · 1 line
2.38.1
PATCH v8 2/6 perf: attach/detach PMU specific data
From: Kan Liang <[email protected]>
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.
--- kernel/events/core.c | 287 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 287 insertions(+)
kernel/events/core.c +287 -0
@@ -55,6 +55,7 @@#include <linux/pgtable.h> #include <linux/buildid.h> #include <linux/task_work.h> +#include <linux/percpu-rwsem.h> #include "internal.h"
@@ -5212,6 +5213,222 @@ static void unaccount_freq_event(void)atomic_dec (&nr_freq_events); } + +static struct perf_ctx_data * +alloc_perf_ctx_data (struct kmem_cache *ctx_cache,bool global) +{ +struct perf_ctx_data *cd; + + cd =kzalloc (sizeof (*cd),GFP_KERNEL ); +if (!cd) +return NULL ; + + cd->data =kmem_cache_zalloc (ctx_cache,GFP_KERNEL ); +if (!cd->data) { +kfree (cd); +return NULL ; + } + + cd->global = global; + cd->ctx_cache = ctx_cache; +refcount_set (&cd->refcount,1 ); + +return cd; +} + +static void free_perf_ctx_data (struct perf_ctx_data *cd) +{ +kmem_cache_free (cd->ctx_cache, cd->data); +kfree (cd); +} + +static void __free_perf_ctx_data_rcu (struct rcu_head *rcu_head) +{ +struct perf_ctx_data *cd; + + cd = container_of(rcu_head, struct perf_ctx_data, rcu_head); +free_perf_ctx_data (cd); +} + +static inline void perf_free_ctx_data_rcu (struct perf_ctx_data *cd) +{ +call_rcu (&cd->rcu_head, __free_perf_ctx_data_rcu); +} + +static int +attach_task_ctx_data (struct task_struct *task,struct kmem_cache *ctx_cache, +bool global) +{ +struct perf_ctx_data *cd, *old =NULL ; + + cd =alloc_perf_ctx_data (ctx_cache, global); +if (!cd) +return -ENOMEM ; + +for (;;) { +if (try_cmpxchg ((struct perf_ctx_data **)&task->perf_ctx_data, &old, cd)) { +if (old) +perf_free_ctx_data_rcu (old); +return 0 ; + } + +if (!old) { +/* +* After seeing a dead @old, we raced with +* removal and lost, try again to install @cd. +*/ +continue ; + } + +if (refcount_inc_not_zero (&old->refcount)) { +free_perf_ctx_data (cd);/* unused */ +return 0 ; + } + +/* +* @old is a dead object, refcount==0 is stable, try and +* replace it with @cd. +*/ + } +return 0 ; +} + +static void __detach_global_ctx_data (void ); +DEFINE_STATIC_PERCPU_RWSEM (global_ctx_data_rwsem); +static refcount_t global_ctx_data_ref; + +static int +attach_global_ctx_data (struct kmem_cache *ctx_cache) +{ +if (refcount_inc_not_zero (&global_ctx_data_ref)) +return 0 ; + +percpu_down_write (&global_ctx_data_rwsem); +if (!refcount_inc_not_zero (&global_ctx_data_ref)) { +struct task_struct *g, *p; +struct perf_ctx_data *cd; +int ret; + +again: +/* Allocate everything */ +rcu_read_lock (); +for_each_process_thread (g, p) { + cd =rcu_dereference (p->perf_ctx_data); +if (cd && !cd->global) { + cd->global =1 ; +if (!refcount_inc_not_zero (&cd->refcount)) + cd =NULL ; + } +if (!cd) { +get_task_struct (p); +rcu_read_unlock (); + + ret =attach_task_ctx_data (p, ctx_cache, true); +put_task_struct (p); +if (ret) { +__detach_global_ctx_data (); +return ret; + } + goto again; + } + } +rcu_read_unlock (); + +refcount_set (&global_ctx_data_ref,1 ); + } +percpu_up_write (&global_ctx_data_rwsem); + +return 0 ; +} + +static int +attach_perf_ctx_data (struct perf_event *event) +{ +struct task_struct *task = event->hw.target; +struct kmem_cache *ctx_cache = event->pmu->task_ctx_cache; + +if (!ctx_cache) +return -ENOMEM ; + +if (task) +return attach_task_ctx_data (task, ctx_cache, false); +else +return attach_global_ctx_data (ctx_cache); +} + +static void +detach_task_ctx_data (struct task_struct *p) +{ +struct perf_ctx_data *cd; + +rcu_read_lock (); + cd =rcu_dereference (p->perf_ctx_data); +if (!cd || !refcount_dec_and_test (&cd->refcount)) { +rcu_read_unlock (); +return ; + } +rcu_read_unlock (); + +/* +* The old ctx_data may be lost because of the race. +* Nothing is required to do for the case. +* See attach_task_ctx_data(). +*/ +if (try_cmpxchg ((struct perf_ctx_data **)&p->perf_ctx_data, &cd,NULL )) +perf_free_ctx_data_rcu (cd); +} + +static void __detach_global_ctx_data (void ) +{ +struct task_struct *g, *p; +struct perf_ctx_data *cd; + +again: +rcu_read_lock (); +for_each_process_thread (g, p) { + cd =rcu_dereference (p->perf_ctx_data); +if (!cd || !cd->global) +continue ; + cd->global =0 ; +get_task_struct (p); +rcu_read_unlock (); + +detach_task_ctx_data (p); +put_task_struct (p); + goto again; + } +rcu_read_unlock (); +} + +static void detach_global_ctx_data (void ) +{ +if (refcount_dec_not_one (&global_ctx_data_ref)) +return ; + +percpu_down_write (&global_ctx_data_rwsem); +if (!refcount_dec_and_test (&global_ctx_data_ref)) + goto unlock; + +/* remove everything */ +__detach_global_ctx_data (); + +unlock: +percpu_up_write (&global_ctx_data_rwsem); +} + +static void detach_perf_ctx_data (struct perf_event *event) +{ +struct task_struct *task = event->hw.target; + +if (!event->pmu->task_ctx_cache) +return ; + +if (task) +detach_task_ctx_data (task); +else +detach_global_ctx_data (); +} +static void unaccount_event (struct perf_event *event) {bool dec = false;
@@ -5249,6 +5466,8 @@ static void unaccount_event(struct perf_event *event)atomic_dec (&nr_bpf_events);if (event->attr.text_poke)atomic_dec (&nr_text_poke_events); +if (event->attach_state &PERF_ATTACH_TASK_DATA ) +detach_perf_ctx_data (event);if (dec) {if (!atomic_add_unless (&perf_sched_count,-1 ,1 ))
@@ -5382,6 +5601,9 @@ static void perf_pending_task_sync(struct perf_event *event)/* vs perf_event_alloc() error */ static void __free_event (struct perf_event *event) { +if (event->security) +security_perf_event_free (event); +if (event->attach_state &PERF_ATTACH_CALLCHAIN )put_callchain_buffers ();
@@ -8598,10 +8820,62 @@ static void perf_event_task(struct task_struct *task, task_ctx); } +/* +* Allocate data for a new task when profiling system-wide +* events which require PMU specific data +*/ +static void +perf_event_alloc_task_data (struct task_struct *child, +struct task_struct *parent) +{ +struct kmem_cache *ctx_cache =NULL ; +struct perf_ctx_data *cd; + +if (!refcount_read (&global_ctx_data_ref)) +return ; + +rcu_read_lock (); + cd =rcu_dereference (parent->perf_ctx_data); +if (cd) + ctx_cache = cd->ctx_cache; +rcu_read_unlock (); + +if (!ctx_cache) +return ; + +percpu_down_read (&global_ctx_data_rwsem); + +rcu_read_lock (); + cd =rcu_dereference (child->perf_ctx_data); + +if (!cd) { +/* +* A system-wide event may be unaccount, +* when attaching the perf_ctx_data. +*/ +if (!refcount_read (&global_ctx_data_ref)) + goto rcu_unlock; +rcu_read_unlock (); +attach_task_ctx_data (child, ctx_cache, true); + goto up_rwsem; + } + +if (!cd->global) { + cd->global =1 ; +refcount_inc (&cd->refcount); + } + +rcu_unlock: +rcu_read_unlock (); +up_rwsem: +percpu_up_read (&global_ctx_data_rwsem); +} +void perf_event_fork (struct task_struct *task) {perf_event_task (task,NULL ,1 );perf_event_namespaces (task); +perf_event_alloc_task_data (task, current); }/*
@@ -12551,6 +12825,12 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,if (err)return ERR_PTR (err); +if (event->attach_state &PERF_ATTACH_TASK_DATA ) { + err =attach_perf_ctx_data (event); +if (err) +return ERR_PTR (err); + } +/* symmetric to unaccount_event() in _free_event() */ account_event (event);
@@ -13628,6 +13908,13 @@ void perf_event_exit_task(struct task_struct *child)* At this point we need to send EXIT events to cpu contexts. */ perf_event_task (child,NULL ,0 ); + +/* +* Detach the perf_ctx_data for the system-wide event. +*/ +percpu_down_read (&global_ctx_data_rwsem); +detach_task_ctx_data (child); +percpu_up_read (&global_ctx_data_rwsem); } static void perf_free_event(struct perf_event *event,
Signature · 1 line
2.38.1
Peter Zijlstra
maintainerRe: [PATCH V8 2/6] perf: attach/detach PMU specific data
Quoted 21 lines · On Wed, Mar 12, 2025 at 11:25:21AM -0700, [email protected] wrote:
(quoted diff) +21
-0+static int +attach_global_ctx_data(struct kmem_cache *ctx_cache) +{ + if (refcount_inc_not_zero(&global_ctx_data_ref)) + return 0; + + percpu_down_write(&global_ctx_data_rwsem); + if (!refcount_inc_not_zero(&global_ctx_data_ref)) { + struct task_struct *g, *p; + struct perf_ctx_data *cd; + int ret; + +again: + /* Allocate everything */ + rcu_read_lock(); + for_each_process_thread(g, p) { + cd = rcu_dereference(p->perf_ctx_data); + if (cd && !cd->global) { + cd->global = 1; + if (!refcount_inc_not_zero(&cd->refcount)) + cd = NULL;
Review
Quoted 10 lines
(quoted diff) +10
-0+ } + if (!cd) { + get_task_struct(p); + rcu_read_unlock(); + + ret = attach_task_ctx_data(p, ctx_cache, true); + put_task_struct(p); + if (ret) { + __detach_global_ctx_data(); + return ret;
AFAICT this returns with global_ctx_data_rwsem taken, no?
Review
Quoted 12 lines
(quoted diff) +12
-0+ } + goto again; + } + } + rcu_read_unlock(); + + refcount_set(&global_ctx_data_ref, 1); + } + percpu_up_write(&global_ctx_data_rwsem); + + return 0; +}
Can we rework this with guards? A little something like so?
---
kernel/events/core.c +28 -36
@@ -5233,18 +5233,20 @@ static refcount_t global_ctx_data_ref;static int attach_global_ctx_data (struct kmem_cache *ctx_cache) { +struct task_struct *g, *p; +struct perf_ctx_data *cd; +int ret; +if (refcount_inc_not_zero (&global_ctx_data_ref))return 0 ; -percpu_down_write (&global_ctx_data_rwsem); -if (!refcount_inc_not_zero (&global_ctx_data_ref)) { -struct task_struct *g, *p; -struct perf_ctx_data *cd; -int ret; +guard (percpu_write)(&global_ctx_data_rwsem); +if (refcount_inc_not_zero (&global_ctx_data_ref)) +return 0 ; again: -/* Allocate everything */ -rcu_read_lock (); +/* Allocate everything */ + scoped_guard (rcu) {for_each_process_thread (g, p) { cd =rcu_dereference (p->perf_ctx_data);if (cd && !cd->global) {
@@ -5254,24 +5256,23 @@ attach_global_ctx_data(struct kmem_cache }if (!cd) {get_task_struct (p); -rcu_read_unlock (); - - ret =attach_task_ctx_data (p, ctx_cache, true); -put_task_struct (p); -if (ret) { -__detach_global_ctx_data (); -return ret; - } - goto again; + goto alloc; } } -rcu_read_unlock (); - -refcount_set (&global_ctx_data_ref,1 ); } -percpu_up_write (&global_ctx_data_rwsem); + +refcount_set (&global_ctx_data_ref,1 );return 0 ; + +alloc: + ret =attach_task_ctx_data (p, ctx_cache, true); +put_task_struct (p); +if (ret) { +__detach_global_ctx_data (); +return ret; + } + goto again; } static int
@@ -5338,15 +5339,12 @@ static void detach_global_ctx_data(void)if (refcount_dec_not_one (&global_ctx_data_ref))return ; -percpu_down_write (&global_ctx_data_rwsem); +guard (perpcu_write)(&global_ctx_data_rwsem);if (!refcount_dec_and_test (&global_ctx_data_ref)) - goto unlock; +return ;/* remove everything */ __detach_global_ctx_data (); - -unlock: -percpu_up_write (&global_ctx_data_rwsem); }static void detach_perf_ctx_data (struct perf_event *event)
@@ -8776,9 +8774,9 @@ perf_event_alloc_task_data(struct task_sif (!ctx_cache)return ; -percpu_down_read (&global_ctx_data_rwsem); +guard (percpu_read)(&global_ctx_data_rwsem); +guard (rcu)(); -rcu_read_lock (); cd =rcu_dereference (child->perf_ctx_data);if (!cd) {
@@ -8787,21 +8785,16 @@ perf_event_alloc_task_data(struct task_s* when attaching the perf_ctx_data. */ if (!refcount_read (&global_ctx_data_ref)) - goto rcu_unlock; +return ;rcu_read_unlock ();attach_task_ctx_data (child, ctx_cache, true); - goto up_rwsem; +return ; }if (!cd->global) { cd->global =1 ;refcount_inc (&cd->refcount); } - -rcu_unlock: -rcu_read_unlock (); -up_rwsem: -percpu_up_read (&global_ctx_data_rwsem); }void perf_event_fork (struct task_struct *task)
@@ -13845,9 +13838,8 @@ void perf_event_exit_task(struct task_st/* * Detach the perf_ctx_data for the system-wide event. */ -percpu_down_read (&global_ctx_data_rwsem); +guard (percpu_read)(&global_ctx_data_rwsem);detach_task_ctx_data (child); -percpu_up_read (&global_ctx_data_rwsem); } static void perf_free_event(struct perf_event *event,
include/linux/percpu-rwsem.h +8 -0
@@ -8,6 +8,7 @@#include <linux/wait.h> #include <linux/rcu_sync.h> #include <linux/lockdep.h> +#include <linux/cleanup.h> struct percpu_rw_semaphore {struct rcu_sync rss;
@@ -125,6 +126,13 @@ extern bool percpu_is_read_locked(struct percpu_rw_semaphore *);extern void percpu_down_write (struct percpu_rw_semaphore *);extern void percpu_up_write (struct percpu_rw_semaphore *); +DEFINE_GUARD(percpu_read, struct perpcu_rw_semaphore *, + perpcu_down_read(_T), percpu_up_read(_T)) +DEFINE_GUARD_COND(perpcu_read, _try, percpu_down_read_trylock(_T)) + +DEFINE_GUARD(percpu_write, struct percpu_rw_semaphore *, + percpu_down_write(_T), perpcu_up_write(_T)) +static inline bool percpu_is_write_locked (struct percpu_rw_semaphore *sem) {return atomic_read (&sem->block);
Re: [PATCH V8 2/6] perf: attach/detach PMU specific data
Quoted 27 lines · Peter Zijlstra
Quoted 25 lines · On Wed, Mar 12, 2025 at 11:25:21AM -0700, [email protected] wrote:
(quoted diff) +25
-0+static int +attach_global_ctx_data(struct kmem_cache *ctx_cache) +{ + if (refcount_inc_not_zero(&global_ctx_data_ref)) + return 0; + + percpu_down_write(&global_ctx_data_rwsem); + if (!refcount_inc_not_zero(&global_ctx_data_ref)) { + struct task_struct *g, *p; + struct perf_ctx_data *cd; + int ret; + +again: + /* Allocate everything */ + rcu_read_lock(); + for_each_process_thread(g, p) { + cd = rcu_dereference(p->perf_ctx_data); + if (cd && !cd->global) { + cd->global = 1; + if (!refcount_inc_not_zero(&cd->refcount)) + cd = NULL; + } + if (!cd) { + get_task_struct(p); + rcu_read_unlock();
Quoted 8 lines
kernel/events/core.c attach_global_ctx_data(struct kmem_cache · line 5273
Quoted 6 lines
kernel/events/core.c +6
-0+ + ret =attach_task_ctx_data (p, ctx_cache, true); +put_task_struct (p); +if (ret) { +__detach_global_ctx_data (); +return ret;AFAICT this returns with
global_ctx_data_rwsemtaken, no?
Ah, yes
Quoted 16 lines
Review
Quoted 13 lines
(quoted diff) +12
-0+ } + goto again; + } + } + rcu_read_unlock(); + + refcount_set(&global_ctx_data_ref, 1); + } + percpu_up_write(&global_ctx_data_rwsem); + + return 0; +}Can we rework this with guards? A little something like so?
Yes. I will do more test and send a V9.
Thanks,
Kan
Quoted 160 lines
---
kernel/events/core.c +28
-36@@ -5233,18 +5233,20 @@ static refcount_t global_ctx_data_ref;static int attach_global_ctx_data (struct kmem_cache *ctx_cache) { +struct task_struct *g, *p; +struct perf_ctx_data *cd; +int ret; +if (refcount_inc_not_zero (&global_ctx_data_ref))return 0 ; -percpu_down_write (&global_ctx_data_rwsem); -if (!refcount_inc_not_zero (&global_ctx_data_ref)) { -struct task_struct *g, *p; -struct perf_ctx_data *cd; -int ret; +guard (percpu_write)(&global_ctx_data_rwsem); +if (refcount_inc_not_zero (&global_ctx_data_ref)) +return 0 ; again: -/* Allocate everything */ -rcu_read_lock (); +/* Allocate everything */ + scoped_guard (rcu) {for_each_process_thread (g, p) { cd =rcu_dereference (p->perf_ctx_data);if (cd && !cd->global) {@@ -5254,24 +5256,23 @@ attach_global_ctx_data(struct kmem_cache }if (!cd) {get_task_struct (p); -rcu_read_unlock (); - - ret =attach_task_ctx_data (p, ctx_cache, true); -put_task_struct (p); -if (ret) { -__detach_global_ctx_data (); -return ret; - } - goto again; + goto alloc; } } -rcu_read_unlock (); - -refcount_set (&global_ctx_data_ref,1 ); } -percpu_up_write (&global_ctx_data_rwsem); + +refcount_set (&global_ctx_data_ref,1 );return 0 ; + +alloc: + ret =attach_task_ctx_data (p, ctx_cache, true); +put_task_struct (p); +if (ret) { +__detach_global_ctx_data (); +return ret; + } + goto again; } static int@@ -5338,15 +5339,12 @@ static void detach_global_ctx_data(void)if (refcount_dec_not_one (&global_ctx_data_ref))return ; -percpu_down_write (&global_ctx_data_rwsem); +guard (perpcu_write)(&global_ctx_data_rwsem);if (!refcount_dec_and_test (&global_ctx_data_ref)) - goto unlock; +return ;/* remove everything */ __detach_global_ctx_data (); - -unlock: -percpu_up_write (&global_ctx_data_rwsem); }static void detach_perf_ctx_data (struct perf_event *event)@@ -8776,9 +8774,9 @@ perf_event_alloc_task_data(struct task_sif (!ctx_cache)return ; -percpu_down_read (&global_ctx_data_rwsem); +guard (percpu_read)(&global_ctx_data_rwsem); +guard (rcu)(); -rcu_read_lock (); cd =rcu_dereference (child->perf_ctx_data);if (!cd) {@@ -8787,21 +8785,16 @@ perf_event_alloc_task_data(struct task_s* when attaching the perf_ctx_data. */ if (!refcount_read (&global_ctx_data_ref)) - goto rcu_unlock; +return ;rcu_read_unlock ();attach_task_ctx_data (child, ctx_cache, true); - goto up_rwsem; +return ; }if (!cd->global) { cd->global =1 ;refcount_inc (&cd->refcount); } - -rcu_unlock: -rcu_read_unlock (); -up_rwsem: -percpu_up_read (&global_ctx_data_rwsem); }void perf_event_fork (struct task_struct *task)@@ -13845,9 +13838,8 @@ void perf_event_exit_task(struct task_st/* * Detach the perf_ctx_data for the system-wide event. */ -percpu_down_read (&global_ctx_data_rwsem); +guard (percpu_read)(&global_ctx_data_rwsem);detach_task_ctx_data (child); -percpu_up_read (&global_ctx_data_rwsem); } static void perf_free_event(struct perf_event *event,include/linux/percpu-rwsem.h +8
-0@@ -8,6 +8,7 @@#include <linux/wait.h> #include <linux/rcu_sync.h> #include <linux/lockdep.h> +#include <linux/cleanup.h> struct percpu_rw_semaphore {struct rcu_sync rss;@@ -125,6 +126,13 @@ extern bool percpu_is_read_locked(struct percpu_rw_semaphore *);extern void percpu_down_write (struct percpu_rw_semaphore *);extern void percpu_up_write (struct percpu_rw_semaphore *); +DEFINE_GUARD(percpu_read, struct perpcu_rw_semaphore *, + perpcu_down_read(_T), percpu_up_read(_T)) +DEFINE_GUARD_COND(perpcu_read, _try, percpu_down_read_trylock(_T)) + +DEFINE_GUARD(percpu_write, struct percpu_rw_semaphore *, + percpu_down_write(_T), perpcu_up_write(_T)) +static inline bool percpu_is_write_locked (struct percpu_rw_semaphore *sem) {return atomic_read (&sem->block);
kernel test robot
build botRe: [PATCH V8 2/6] perf: attach/detach PMU specific data
In reply to [email protected]kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/perf/core]
[also build test ERROR on next-20250312]
[cannot apply to perf-tools-next/perf-tools-next perf-tools/perf-tools linus/master acme/perf/core v6.14-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/kan-liang-linux-intel-com/perf-attach-detach-PMU-specific-data/20250313-022851 base: tip/perf/core patch link: https://lore.kernel.org/r/20250312182525.4078433-2-kan.liang%40linux.intel.com patch subject: [PATCH V8 2/6] perf: attach/detach PMU specific data config: i386-buildonly-randconfig-005-20250313 (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> kernel/events/core.c:5604:13: error: no member named 'security' in 'struct perf_event'
5604 | if (event->security)
| ~~~~~ ^1 error generated.
vim +5604 kernel/events/core.c
5600
5601 /* vs perf_event_alloc() error */
5602 static void __free_event(struct perf_event *event)
5603 {
> 5604 if (event->security)
5605 security_perf_event_free(event);
5606
5607 if (event->attach_state & PERF_ATTACH_CALLCHAIN)
5608 put_callchain_buffers();
5609
5610 kfree(event->addr_filter_ranges);
5611
5612 if (event->attach_state & PERF_ATTACH_EXCLUSIVE)
5613 exclusive_event_destroy(event);
5614
5615 if (is_cgroup_event(event))
5616 perf_detach_cgroup(event);
5617
5618 if (event->destroy)
5619 event->destroy(event);
5620
5621 /*
5622 * Must be after ->destroy(), due to uprobe_perf_close() using
5623 * hw.target.
5624 */
5625 if (event->hw.target)
5626 put_task_struct(event->hw.target);
5627
5628 if (event->pmu_ctx) {
5629 /*
5630 * put_pmu_ctx() needs an event->ctx reference, because of
5631 * epc->ctx.
5632 */
5633 WARN_ON_ONCE(!event->ctx);
5634 WARN_ON_ONCE(event->pmu_ctx->ctx != event->ctx);
5635 put_pmu_ctx(event->pmu_ctx);
5636 }
5637
5638 /*
5639 * perf_event_free_task() relies on put_ctx() being 'last', in
5640 * particular all task references must be cleaned up.
5641 */
5642 if (event->ctx)
5643 put_ctx(event->ctx);
5644
5645 if (event->pmu)
5646 module_put(event->pmu->module);
5647
5648 call_rcu(&event->rcu_head, free_event_rcu);
5649 }
5650
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH V8 2/6] perf: attach/detach PMU specific data
In reply to [email protected]kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/perf/core]
[also build test ERROR on next-20250312]
[cannot apply to perf-tools-next/perf-tools-next perf-tools/perf-tools linus/master acme/perf/core v6.14-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/kan-liang-linux-intel-com/perf-attach-detach-PMU-specific-data/20250313-022851 base: tip/perf/core patch link: https://lore.kernel.org/r/20250312182525.4078433-2-kan.liang%40linux.intel.com patch subject: [PATCH V8 2/6] perf: attach/detach PMU specific data config: csky-randconfig-002-20250313 (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: csky-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
kernel/events/core.c: In function '__free_event':
>> kernel/events/core.c:5604:18: error: 'struct perf_event' has no member named 'security'
5604 | if (event->security)
| ^~vim +5604 kernel/events/core.c
5600
5601 /* vs perf_event_alloc() error */
5602 static void __free_event(struct perf_event *event)
5603 {
> 5604 if (event->security)
5605 security_perf_event_free(event);
5606
5607 if (event->attach_state & PERF_ATTACH_CALLCHAIN)
5608 put_callchain_buffers();
5609
5610 kfree(event->addr_filter_ranges);
5611
5612 if (event->attach_state & PERF_ATTACH_EXCLUSIVE)
5613 exclusive_event_destroy(event);
5614
5615 if (is_cgroup_event(event))
5616 perf_detach_cgroup(event);
5617
5618 if (event->destroy)
5619 event->destroy(event);
5620
5621 /*
5622 * Must be after ->destroy(), due to uprobe_perf_close() using
5623 * hw.target.
5624 */
5625 if (event->hw.target)
5626 put_task_struct(event->hw.target);
5627
5628 if (event->pmu_ctx) {
5629 /*
5630 * put_pmu_ctx() needs an event->ctx reference, because of
5631 * epc->ctx.
5632 */
5633 WARN_ON_ONCE(!event->ctx);
5634 WARN_ON_ONCE(event->pmu_ctx->ctx != event->ctx);
5635 put_pmu_ctx(event->pmu_ctx);
5636 }
5637
5638 /*
5639 * perf_event_free_task() relies on put_ctx() being 'last', in
5640 * particular all task references must be cleaned up.
5641 */
5642 if (event->ctx)
5643 put_ctx(event->ctx);
5644
5645 if (event->pmu)
5646 module_put(event->pmu->module);
5647
5648 call_rcu(&event->rcu_head, free_event_rcu);
5649 }
5650
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH V8 2/6] perf: attach/detach PMU specific data
Hi Intel folks,
On Thu, Mar 13, 2025 at 07:46:26AM +0800, kernel test robot wrote:
...
Quoted 7 lines
url: https://github.com/intel-lab-lkp/linux/commits/kan-liang-linux-intel-com/perf-attach-detach-PMU-specific-data/20250313-022851 base: tip/perf/core patch link: https://lore.kernel.org/r/20250312182525.4078433-2-kan.liang%40linux.intel.com patch subject: [PATCH V8 2/6] perf: attach/detach PMU specific data config: csky-randconfig-002-20250313 (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: csky-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
I am noticing a number of recent reports that are being sent to our mailing list ([email protected]) when the compiler is not clang, is something wrong with your filtering? Here are a number of examples:
https://lore.kernel.org/[email protected]/
https://lore.kernel.org/[email protected]/
https://lore.kernel.org/[email protected]/
https://lore.kernel.org/[email protected]/
https://lore.kernel.org/[email protected]/
https://lore.kernel.org/[email protected]/
Cheers,
Nathan
Re: [PATCH V8 2/6] perf: attach/detach PMU specific data
Quoted 12 lines · Nathan Chancellor
Hi Intel folks,
On Thu, Mar 13, 2025 at 07:46:26AM +0800, kernel test robot wrote:
...Quoted 7 lines
url: https://github.com/intel-lab-lkp/linux/commits/kan-liang-linux-intel-com/perf-attach-detach-PMU-specific-data/20250313-022851 base: tip/perf/core patch link: https://lore.kernel.org/r/20250312182525.4078433-2-kan.liang%40linux.intel.com patch subject: [PATCH V8 2/6] perf: attach/detach PMU specific data config: csky-randconfig-002-20250313 (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: csky-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
Quoted 3 lines
I am noticing a number of recent reports that are being sent to our mailing list ([email protected]) when the compiler is not clang, is something wrong with your filtering? Here are a number of examples:
Sorry, there's a bug introduced in the bot but not noticed, I will fix it asap.
PATCH v8 3/6 perf: Supply task information to sched_task()
In reply to [email protected]From: Kan Liang <[email protected]>
To save/restore LBR call stack data in system-wide mode, the task_struct information is required.
Extend the parameters of sched_task() to supply task_struct information.
When schedule in, the LBR call stack data for new task will be restored. When schedule out, the LBR call stack data for old task will be saved. Only need to pass the required task_struct information.
--- arch/powerpc/perf/core-book3s.c | 8 ++++++-- arch/x86/events/amd/brs.c | 3 ++- arch/x86/events/amd/lbr.c | 3 ++- arch/x86/events/core.c | 5 +++-- arch/x86/events/intel/core.c | 4 ++-- arch/x86/events/intel/lbr.c | 3 ++- arch/x86/events/perf_event.h | 14 +++++++++----- include/linux/perf_event.h | 2 +- kernel/events/core.c | 20 +++++++++++--------- 9 files changed, 38 insertions(+), 24 deletions(-)
arch/powerpc/perf/core-book3s.c +6 -2
@@ -132,7 +132,10 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)static inline void power_pmu_bhrb_enable (struct perf_event *event) {}static inline void power_pmu_bhrb_disable (struct perf_event *event) {} -static void power_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) {} +static void power_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) +{ +}static inline void power_pmu_bhrb_read (struct perf_event *event,struct cpu_hw_events *cpuhw) {}static void pmao_restore_workaround (bool ebb) { }#endif /* CONFIG_PPC32 */
@@ -444,7 +447,8 @@ static void power_pmu_bhrb_disable(struct perf_event *event)/* Called from ctxsw to prevent one process's branch entries to * mingle with the other process's entries during context switch. */ -static void power_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +static void power_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) {if (!ppmu->bhrb_nr)return ;
arch/x86/events/amd/brs.c +2 -1
@@ -381,7 +381,8 @@ static void amd_brs_poison_buffer(void)* On ctxswin, sched_in = true, called after the PMU has started * On ctxswout, sched_in = false, called before the PMU is stopped */ -void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);
arch/x86/events/amd/lbr.c +2 -1
@@ -371,7 +371,8 @@ void amd_pmu_lbr_del(struct perf_event *event)perf_sched_cb_dec (event->pmu); } -void amd_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +void amd_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);
arch/x86/events/core.c +3 -2
@@ -2638,9 +2638,10 @@ static const struct attribute_group *x86_pmu_attr_groups[] = { NULL, }; -static void x86_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +static void x86_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) { -static_call_cond (x86_pmu_sched_task)(pmu_ctx, sched_in); +static_call_cond (x86_pmu_sched_task)(pmu_ctx, task, sched_in); } static void x86_pmu_swap_task_ctx(struct perf_event_pmu_context *prev_epc,
arch/x86/events/intel/core.c +2 -2
@@ -5294,10 +5294,10 @@ static void intel_pmu_cpu_dead(int cpu) }static void intel_pmu_sched_task (struct perf_event_pmu_context *pmu_ctx, -bool sched_in) +struct task_struct *task,bool sched_in) {intel_pmu_pebs_sched_task (pmu_ctx, sched_in); -intel_pmu_lbr_sched_task (pmu_ctx, sched_in); +intel_pmu_lbr_sched_task (pmu_ctx, task, sched_in); } static void intel_pmu_swap_task_ctx(struct perf_event_pmu_context *prev_epc,
arch/x86/events/intel/lbr.c +2 -1
@@ -539,7 +539,8 @@ void intel_pmu_lbr_swap_task_ctx(struct perf_event_pmu_context *prev_epc, task_context_opt(next_ctx_data)->lbr_callstack_users); } -void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);void *task_ctx;
arch/x86/events/perf_event.h +9 -5
@@ -875,7 +875,7 @@ struct x86_pmu {void (*check_microcode)(void );void (*sched_task)(struct perf_event_pmu_context *pmu_ctx, -bool sched_in); +struct task_struct *task,bool sched_in);/* * Intel Arch Perfmon v2+
@@ -1408,7 +1408,8 @@ void amd_pmu_lbr_reset(void);void amd_pmu_lbr_read (void );void amd_pmu_lbr_add (struct perf_event *event);void amd_pmu_lbr_del (struct perf_event *event); -void amd_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in); +void amd_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in);void amd_pmu_lbr_enable_all (void );void amd_pmu_lbr_disable_all (void );int amd_pmu_lbr_hw_config (struct perf_event *event);
@@ -1462,7 +1463,8 @@ static inline void amd_pmu_brs_del(struct perf_event *event) perf_sched_cb_dec(event->pmu); } -void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in); +void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in);#else static inline int amd_brs_init (void ) {
@@ -1487,7 +1489,8 @@ static inline void amd_pmu_brs_del(struct perf_event *event) { } -static inline void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in) +static inline void amd_pmu_brs_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in) { }
@@ -1670,7 +1673,8 @@ void intel_pmu_lbr_save_brstack(struct perf_sample_data *data,void intel_pmu_lbr_swap_task_ctx (struct perf_event_pmu_context *prev_epc,struct perf_event_pmu_context *next_epc); -void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,bool sched_in); +void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx, +struct task_struct *task,bool sched_in);u64 lbr_from_signext_quirk_wr (u64 val);
include/linux/perf_event.h +1 -1
@@ -494,7 +494,7 @@ struct pmu {* context-switches callback */ void (*sched_task) (struct perf_event_pmu_context *pmu_ctx, -bool sched_in); +struct task_struct *task,bool sched_in);/* * Kmem cache of PMU specific data
kernel/events/core.c +11 -9
@@ -3613,7 +3613,8 @@ static void perf_event_swap_task_ctx_data(struct perf_event_context *prev_ctx, } } -static void perf_ctx_sched_task_cb (struct perf_event_context *ctx,bool sched_in) +static void perf_ctx_sched_task_cb (struct perf_event_context *ctx, +struct task_struct *task,bool sched_in) {struct perf_event_pmu_context *pmu_ctx;struct perf_cpu_pmu_context *cpc;
@@ -3622,7 +3623,7 @@ static void perf_ctx_sched_task_cb(struct perf_event_context *ctx, bool sched_in cpc =this_cpc (pmu_ctx->pmu);if (cpc->sched_cb_usage && pmu_ctx->pmu->sched_task) - pmu_ctx->pmu->sched_task (pmu_ctx, sched_in); + pmu_ctx->pmu->sched_task (pmu_ctx, task, sched_in); } }
@@ -3685,7 +3686,7 @@ perf_event_context_sched_out(struct task_struct *task, struct task_struct *next)WRITE_ONCE (ctx->task, next);WRITE_ONCE (next_ctx->task, task); -perf_ctx_sched_task_cb (ctx, false); +perf_ctx_sched_task_cb (ctx, task, false);perf_event_swap_task_ctx_data (ctx, next_ctx);perf_ctx_enable (ctx, false);
@@ -3715,7 +3716,7 @@ perf_event_context_sched_out(struct task_struct *task, struct task_struct *next)perf_ctx_disable (ctx, false); inside_switch: -perf_ctx_sched_task_cb (ctx, false); +perf_ctx_sched_task_cb (ctx, task, false);task_ctx_sched_out (ctx,NULL ,EVENT_ALL );perf_ctx_enable (ctx, false);
@@ -3757,7 +3758,8 @@ void perf_sched_cb_inc(struct pmu *pmu)* PEBS requires this to provide PID/TID information. This requires we flush * all queued PEBS records before we context switch to a new task. */ -static void __perf_pmu_sched_task (struct perf_cpu_pmu_context *cpc,bool sched_in) +static void __perf_pmu_sched_task (struct perf_cpu_pmu_context *cpc, +struct task_struct *task,bool sched_in) {struct perf_cpu_context *cpuctx =this_cpu_ptr (&perf_cpu_context);struct pmu *pmu;
@@ -3771,7 +3773,7 @@ static void __perf_pmu_sched_task(struct perf_cpu_pmu_context *cpc, bool sched_iperf_ctx_lock (cpuctx, cpuctx->task_ctx);perf_pmu_disable (pmu); - pmu->sched_task (cpc->task_epc, sched_in); + pmu->sched_task (cpc->task_epc, task, sched_in);perf_pmu_enable (pmu);perf_ctx_unlock (cpuctx, cpuctx->task_ctx);
@@ -3789,7 +3791,7 @@ static void perf_pmu_sched_task(struct task_struct *prev,return ;list_for_each_entry (cpc,this_cpu_ptr (&sched_cb_list), sched_cb_entry) -__perf_pmu_sched_task (cpc, sched_in); +__perf_pmu_sched_task (cpc, sched_in ? next : prev, sched_in); } static void perf_event_switch(struct task_struct *task,
@@ -4083,7 +4085,7 @@ static void perf_event_context_sched_in(struct task_struct *task)perf_ctx_lock (cpuctx, ctx);perf_ctx_disable (ctx, false); -perf_ctx_sched_task_cb (ctx, true); +perf_ctx_sched_task_cb (ctx, task, true);perf_ctx_enable (ctx, false);perf_ctx_unlock (cpuctx, ctx);
@@ -4114,7 +4116,7 @@ static void perf_event_context_sched_in(struct task_struct *task)perf_event_sched_in (cpuctx, ctx,NULL ); -perf_ctx_sched_task_cb (cpuctx->task_ctx, true); +perf_ctx_sched_task_cb (cpuctx->task_ctx, task, true);if (!RB_EMPTY_ROOT (&ctx->pinned_groups.tree))perf_ctx_enable (&cpuctx->ctx, false);
Signature · 1 line
2.38.1
kernel test robot
build botRe: [PATCH V8 3/6] perf: Supply task information to sched_task()
kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/perf/core]
[also build test ERROR on next-20250312]
[cannot apply to perf-tools-next/perf-tools-next perf-tools/perf-tools linus/master acme/perf/core v6.14-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/kan-liang-linux-intel-com/perf-attach-detach-PMU-specific-data/20250313-022851 base: tip/perf/core patch link: https://lore.kernel.org/r/20250312182525.4078433-3-kan.liang%40linux.intel.com patch subject: [PATCH V8 3/6] perf: Supply task information to sched_task() config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from arch/s390/kernel/perf_pai_crypto.c:18:
In file included from include/linux/perf_event.h:25:
In file included from arch/s390/include/asm/perf_event.h:14:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/s390/include/asm/elf.h:181:
In file included from arch/s390/include/asm/mmu_context.h:11:
In file included from arch/s390/include/asm/pgalloc.h:18:
In file included from include/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> arch/s390/kernel/perf_pai_crypto.c:578:18: error: incompatible function pointer types initializing 'void (*)(struct perf_event_pmu_context *, struct task_struct *, bool)' (aka 'void (*)(struct perf_event_pmu_context *, struct task_struct *, _Bool)') with an expression of type 'void (struct perf_event_pmu_context *, bool)' (aka 'void (struct perf_event_pmu_context *, _Bool)') [-Wincompatible-function-pointer-types] 578 | .sched_task = paicrypt_sched_task,
| ^~~~~~~~~~~~~~~~~~~
3 warnings and 1 error generated.
--
In file included from arch/s390/kernel/perf_pai_ext.c:19:
In file included from include/linux/perf_event.h:25:
In file included from arch/s390/include/asm/perf_event.h:14:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/s390/include/asm/elf.h:181:
In file included from arch/s390/include/asm/mmu_context.h:11:
In file included from arch/s390/include/asm/pgalloc.h:18:
In file included from include/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> arch/s390/kernel/perf_pai_ext.c:604:18: error: incompatible function pointer types initializing 'void (*)(struct perf_event_pmu_context *, struct task_struct *, bool)' (aka 'void (*)(struct perf_event_pmu_context *, struct task_struct *, _Bool)') with an expression of type 'void (struct perf_event_pmu_context *, bool)' (aka 'void (struct perf_event_pmu_context *, _Bool)') [-Wincompatible-function-pointer-types] 604 | .sched_task = paiext_sched_task,
| ^~~~~~~~~~~~~~~~~
3 warnings and 1 error generated.
vim +578 arch/s390/kernel/perf_pai_crypto.c
39d62336f5c126a Thomas Richter 2022-05-04 568
39d62336f5c126a Thomas Richter 2022-05-04 569 /* Performance monitoring unit for mapped counters */
39d62336f5c126a Thomas Richter 2022-05-04 570 static struct pmu paicrypt = {
92ea686840ac5e2 Thomas Richter 2024-02-29 571 .task_ctx_nr = perf_hw_context,
39d62336f5c126a Thomas Richter 2022-05-04 572 .event_init = paicrypt_event_init,
39d62336f5c126a Thomas Richter 2022-05-04 573 .add = paicrypt_add,
39d62336f5c126a Thomas Richter 2022-05-04 574 .del = paicrypt_del,
39d62336f5c126a Thomas Richter 2022-05-04 575 .start = paicrypt_start,
39d62336f5c126a Thomas Richter 2022-05-04 576 .stop = paicrypt_stop,
39d62336f5c126a Thomas Richter 2022-05-04 577 .read = paicrypt_read,
39d62336f5c126a Thomas Richter 2022-05-04 @578 .sched_task = paicrypt_sched_task,
39d62336f5c126a Thomas Richter 2022-05-04 579 .attr_groups = paicrypt_attr_groups
39d62336f5c126a Thomas Richter 2022-05-04 580 };39d62336f5c126a Thomas Richter 2022-05-04 581
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v8 4/6 perf/x86/lbr: Fix shorter LBRs call stacks for the system-wide mode
In reply to [email protected]From: Kan Liang <[email protected]>
In the system-wide mode, LBR callstacks are shorter in comparison to the per-process mode.
LBR MSRs are reset during a context switch in the system-wide mode. For the LBR call stack, the LBRs should be always saved/restored during a context switch.
Use the space in task_struct to save/restore the LBR call stack data.
For a system-wide event, it's unnecessagy to update the lbr_callstack_users for each threads. Add a variable in x86_pmu to indicate whether the system-wide event is active.
--- arch/x86/events/intel/lbr.c | 47 ++++++++++++++++++++++++++++++------ arch/x86/events/perf_event.h | 1 + 2 files changed, 40 insertions(+), 8 deletions(-)
arch/x86/events/intel/lbr.c +39 -8
@@ -422,11 +422,17 @@ static __always_inline bool lbr_is_reset_in_cstate(void *ctx)return !rdlbr_from (((struct x86_perf_task_context *)ctx)->tos,NULL ); } +static inline bool has_lbr_callstack_users (void *ctx) +{ +return task_context_opt (ctx)->lbr_callstack_users || + x86_pmu.lbr_callstack_users; +} +static void __intel_pmu_lbr_restore (void *ctx) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); -if (task_context_opt (ctx)->lbr_callstack_users ==0 || +if (!has_lbr_callstack_users (ctx) ||task_context_opt (ctx)->lbr_stack_state ==LBR_NONE ) {intel_pmu_lbr_reset ();return ;
@@ -503,7 +509,7 @@ static void __intel_pmu_lbr_save(void *ctx) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); -if (task_context_opt (ctx)->lbr_callstack_users ==0 ) { +if (!has_lbr_callstack_users (ctx)) {task_context_opt (ctx)->lbr_stack_state =LBR_NONE ;return ; }
@@ -543,6 +549,7 @@ void intel_pmu_lbr_sched_task(struct perf_event_pmu_context *pmu_ctx, struct task_struct *task, bool sched_in) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +struct perf_ctx_data *ctx_data;void *task_ctx;if (!cpuc->lbr_users)
@@ -553,14 +560,18 @@ void intel_pmu_lbr_sched_task(struct perf_event_pmu_context *pmu_ctx,* the task was scheduled out, restore the stack. Otherwise flush * the LBR stack. */ - task_ctx = pmu_ctx ? pmu_ctx->task_ctx_data :NULL ; +rcu_read_lock (); + ctx_data =rcu_dereference (task->perf_ctx_data); + task_ctx = ctx_data ? ctx_data->data :NULL ;if (task_ctx) {if (sched_in)__intel_pmu_lbr_restore (task_ctx);else __intel_pmu_lbr_save (task_ctx); +rcu_read_unlock ();return ; } +rcu_read_unlock ();/* * Since a context switch can flip the address space and LBR entries
@@ -589,9 +600,19 @@ void intel_pmu_lbr_add(struct perf_event *event) cpuc->br_sel = event->hw.branch_reg.reg; -if (branch_user_callstack (cpuc->br_sel) && event->pmu_ctx->task_ctx_data) -task_context_opt (event->pmu_ctx->task_ctx_data)->lbr_callstack_users++; +if (branch_user_callstack (cpuc->br_sel)) { +if (event->attach_state &PERF_ATTACH_TASK ) { +struct task_struct *task = event->hw.target; +struct perf_ctx_data *ctx_data; +rcu_read_lock (); + ctx_data =rcu_dereference (task->perf_ctx_data); +if (ctx_data) +task_context_opt (ctx_data->data)->lbr_callstack_users++; +rcu_read_unlock (); + }else + x86_pmu.lbr_callstack_users++; + }/* * Request pmu::sched_task() callback, which will fire inside the * regular perf event scheduling, so that call will:
@@ -665,9 +686,19 @@ void intel_pmu_lbr_del(struct perf_event *event)if (!x86_pmu.lbr_nr)return ; -if (branch_user_callstack (cpuc->br_sel) && - event->pmu_ctx->task_ctx_data) -task_context_opt (event->pmu_ctx->task_ctx_data)->lbr_callstack_users--; +if (branch_user_callstack (cpuc->br_sel)) { +if (event->attach_state &PERF_ATTACH_TASK ) { +struct task_struct *task = event->hw.target; +struct perf_ctx_data *ctx_data; + +rcu_read_lock (); + ctx_data =rcu_dereference (task->perf_ctx_data); +if (ctx_data) +task_context_opt (ctx_data->data)->lbr_callstack_users--; +rcu_read_unlock (); + }else + x86_pmu.lbr_callstack_users--; + }if (event->hw.flags &PERF_X86_EVENT_LBR_SELECT ) cpuc->lbr_select =0 ;
arch/x86/events/perf_event.h +1 -0
@@ -920,6 +920,7 @@ struct x86_pmu {const int *lbr_sel_map;/* lbr_select mappings */ int *lbr_ctl_map;/* LBR_CTL mappings */ }; +u64 lbr_callstack_users;/* lbr callstack system wide users */ bool lbr_double_abort;/* duplicated lbr aborts */ bool lbr_pt_coexist;/* (LBR|BTS) may coexist with PT */
Signature · 1 line
2.38.1
PATCH v8 5/6 perf/x86: Remove swap_task_ctx()
In reply to [email protected]From: Kan Liang <[email protected]>
The pmu specific data is saved in task_struct now. It doesn't need to swap between context.
Remove swap_task_ctx() support.
--- arch/x86/events/core.c | 9 --------- arch/x86/events/intel/core.c | 7 ------- arch/x86/events/intel/lbr.c | 23 ----------------------- arch/x86/events/perf_event.h | 11 ----------- 4 files changed, 50 deletions(-)
arch/x86/events/core.c +0 -9
@@ -87,7 +87,6 @@ DEFINE_STATIC_CALL_NULL(x86_pmu_commit_scheduling, *x86_pmu.commit_scheduling);DEFINE_STATIC_CALL_NULL (x86_pmu_stop_scheduling, *x86_pmu.stop_scheduling);DEFINE_STATIC_CALL_NULL (x86_pmu_sched_task, *x86_pmu.sched_task); -DEFINE_STATIC_CALL_NULL (x86_pmu_swap_task_ctx, *x86_pmu.swap_task_ctx);DEFINE_STATIC_CALL_NULL (x86_pmu_drain_pebs, *x86_pmu.drain_pebs);DEFINE_STATIC_CALL_NULL (x86_pmu_pebs_aliases, *x86_pmu.pebs_aliases);
@@ -2039,7 +2038,6 @@ static void x86_pmu_static_call_update(void)static_call_update (x86_pmu_stop_scheduling, x86_pmu.stop_scheduling);static_call_update (x86_pmu_sched_task, x86_pmu.sched_task); -static_call_update (x86_pmu_swap_task_ctx, x86_pmu.swap_task_ctx);static_call_update (x86_pmu_drain_pebs, x86_pmu.drain_pebs);static_call_update (x86_pmu_pebs_aliases, x86_pmu.pebs_aliases);
@@ -2644,12 +2642,6 @@ static void x86_pmu_sched_task(struct perf_event_pmu_context *pmu_ctx,static_call_cond (x86_pmu_sched_task)(pmu_ctx, task, sched_in); } -static void x86_pmu_swap_task_ctx (struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc) -{ -static_call_cond (x86_pmu_swap_task_ctx)(prev_epc, next_epc); -} -void perf_check_microcode (void ) {if (x86_pmu.check_microcode)
@@ -2714,7 +2706,6 @@ static struct pmu pmu = { .event_idx = x86_pmu_event_idx, .sched_task = x86_pmu_sched_task, - .swap_task_ctx = x86_pmu_swap_task_ctx, .check_period = x86_pmu_check_period, .aux_output_match = x86_pmu_aux_output_match,
arch/x86/events/intel/core.c +0 -7
@@ -5300,12 +5300,6 @@ static void intel_pmu_sched_task(struct perf_event_pmu_context *pmu_ctx,intel_pmu_lbr_sched_task (pmu_ctx, task, sched_in); } -static void intel_pmu_swap_task_ctx (struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc) -{ -intel_pmu_lbr_swap_task_ctx (prev_epc, next_epc); -} -static int intel_pmu_check_period (struct perf_event *event,u64 value) {return intel_pmu_has_bts_period (event, value) ? -EINVAL :0 ;
@@ -5474,7 +5468,6 @@ static __initconst const struct x86_pmu intel_pmu = { .guest_get_msrs = intel_guest_get_msrs, .sched_task = intel_pmu_sched_task, - .swap_task_ctx = intel_pmu_swap_task_ctx, .check_period = intel_pmu_check_period,
arch/x86/events/intel/lbr.c +0 -23
@@ -522,29 +522,6 @@ static void __intel_pmu_lbr_save(void *ctx) cpuc->last_log_id = ++task_context_opt (ctx)->log_id; } -void intel_pmu_lbr_swap_task_ctx (struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc) -{ -void *prev_ctx_data, *next_ctx_data; - -swap (prev_epc->task_ctx_data, next_epc->task_ctx_data); - -/* -* Architecture specific synchronization makes sense in case -* both prev_epc->task_ctx_data and next_epc->task_ctx_data -* pointers are allocated. -*/ - - prev_ctx_data = next_epc->task_ctx_data; - next_ctx_data = prev_epc->task_ctx_data; - -if (!prev_ctx_data || !next_ctx_data) -return ; - -swap (task_context_opt (prev_ctx_data)->lbr_callstack_users, -task_context_opt (next_ctx_data)->lbr_callstack_users); -} -void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,struct task_struct *task,bool sched_in) {
arch/x86/events/perf_event.h +0 -11
@@ -958,14 +958,6 @@ struct x86_pmu {*/ int num_topdown_events; -/* -* perf task context (i.e. struct perf_event_pmu_context::task_ctx_data) -* switch helper to bridge calls from perf/core to perf/x86. -* See struct pmu::swap_task_ctx() usage for examples; -*/ -void (*swap_task_ctx)(struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc); -/* * AMD bits */
@@ -1671,9 +1663,6 @@ void intel_pmu_lbr_save_brstack(struct perf_sample_data *data,struct cpu_hw_events *cpuc, struct perf_event *event); -void intel_pmu_lbr_swap_task_ctx (struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc); -void intel_pmu_lbr_sched_task (struct perf_event_pmu_context *pmu_ctx,struct task_struct *task,bool sched_in);
Signature · 1 line
2.38.1
PATCH v8 6/6 perf: Clean up pmu specific data
In reply to [email protected]From: Kan Liang <[email protected]>
The pmu specific data is saved in task_struct now. Remove it from event context structure.
Remove swap_task_ctx() as well.
--- include/linux/perf_event.h | 12 ------ kernel/events/core.c | 76 ++------------------------------------ 2 files changed, 3 insertions(+), 85 deletions(-)
include/linux/perf_event.h +0 -12
@@ -501,16 +501,6 @@ struct pmu {*/ struct kmem_cache *task_ctx_cache; -/* -* PMU specific parts of task perf event context (i.e. ctx->task_ctx_data) -* can be synchronized using this function. See Intel LBR callstack support -* implementation and Perf core context switch handling callbacks for usage -* examples. -*/ -void (*swap_task_ctx) (struct perf_event_pmu_context *prev_epc, -struct perf_event_pmu_context *next_epc); -/* optional */ -/* * Set up pmu-private data structures for an AUX area */
@@ -932,7 +922,6 @@ struct perf_event_pmu_context {atomic_t refcount;/* event <-> epc */ struct rcu_head rcu_head; -void *task_ctx_data;/* pmu specific data */ /* * Set when one or more (plausibly active) event can't be scheduled * due to pmu overcommit or pmu constraints, except tolerant to
@@ -980,7 +969,6 @@ struct perf_event_context {int nr_user;int is_active; -int nr_task_data;int nr_stat;int nr_freq;int rotate_disable;
kernel/events/core.c +3 -73
137 lines not on this page · raw message
Signature · 1 line
2.38.1
Peter Zijlstra
maintainerI'm sorry, but since I spotted a bug in the second patch, I'm going to reply and suggest some overall changes.
Quoted 15 lines · On Wed, Mar 12, 2025 at 11:25:20AM -0700, [email protected] wrote:
include/linux/perf_event.h +7
-0@@ -1021,6 +1021,36 @@ struct perf_event_context {local_t nr_no_switch_fast; }; +/** +* struct perf_ctx_data - PMU specific data for a task +* @rcu_head: To avoid the race on free PMU specific data +* @refcount: To track users +* @global: To track system-wide users +* @ctx_cache: Kmem cache of PMU specific data +* @data: PMU specific data
include/linux/perf_event.h struct perf_event_context { · line 1040
Quoted 10 lines
include/linux/perf_event.h +10
-0+* +* Currently, the struct is only used in Intel LBR call stack mode to +* save/restore the call stack of a task on context switches. +* The data only be allocated when Intel LBR call stack mode is enabled. +* The data will be freed when the mode is disabled. The rcu_head is +* used to prevent the race on free the data. +* The content of the data will only be accessed in context switch, which +* should be protected by rcu_read_lock(). +* +* Careful: Struct perf_ctx_data is added as a pointor in struct task_struct.
pointer
include/linux/perf_event.h struct perf_event_context { · line 1052
Quoted 12 lines
include/linux/perf_event.h +12
-0+* When system-wide Intel LBR call stack mode is enabled, a buffer with +* constant size will be allocated for each task. +* Also, system memory consumption can further grow when the size of +* struct perf_ctx_data enlarges. +*/ +struct perf_ctx_data { +struct rcu_head rcu_head; +refcount_t refcount; +int global; +struct kmem_cache *ctx_cache; +void *data; +};
I can't remember why this is complicated like this. Why do we have a kmemcache and yet another data pointer in there?
Specifically, why can't we do something like:
struct perf_ctx_data {
struct rcu_head rcu;
refcount_t refcount;
int global;
char data[];
};and simply allocate the whole thing as a single allocation?
So then the allocation is something like:
cd = kzalloc(sizeof(*cd) + event->pmu->task_ctx_size, GFP_KERNEL);
Quoted 3 lines · Peter Zijlstra
I'm sorry, but since I spotted a bug in the second patch, I'm going to reply and suggest some overall changes.
Sure. Thanks.
Quoted 31 lines · On Wed, Mar 12, 2025 at 11:25:20AM -0700, [email protected] wrote:
Quoted 16 lines
include/linux/perf_event.h +7
-0@@ -1021,6 +1021,36 @@ struct perf_event_context {local_t nr_no_switch_fast; }; +/** +* struct perf_ctx_data - PMU specific data for a task +* @rcu_head: To avoid the race on free PMU specific data +* @refcount: To track users +* @global: To track system-wide users +* @ctx_cache: Kmem cache of PMU specific data +* @data: PMU specific data include/linux/perf_event.h struct perf_event_context { · line 1040
Quoted 10 lines
include/linux/perf_event.h +10
-0+* +* Currently, the struct is only used in Intel LBR call stack mode to +* save/restore the call stack of a task on context switches. +* The data only be allocated when Intel LBR call stack mode is enabled. +* The data will be freed when the mode is disabled. The rcu_head is +* used to prevent the race on free the data. +* The content of the data will only be accessed in context switch, which +* should be protected by rcu_read_lock(). +* +* Careful: Struct perf_ctx_data is added as a pointor in struct task_struct. pointer
Quoted 15 lines
include/linux/perf_event.h struct perf_event_context { · line 1052
Quoted 12 lines
include/linux/perf_event.h +12
-0+* When system-wide Intel LBR call stack mode is enabled, a buffer with +* constant size will be allocated for each task. +* Also, system memory consumption can further grow when the size of +* struct perf_ctx_data enlarges. +*/ +struct perf_ctx_data { +struct rcu_head rcu_head; +refcount_t refcount; +int global; +struct kmem_cache *ctx_cache; +void *data; +};I can't remember why this is complicated like this. Why do we have a kmemcache and yet another data pointer in there?
The kmem_cache is introduced to address the alignment requirement for Arch LBR.
https://lore.kernel.org/lkml/159420190705.4006.11190540790919295173.tip-bot2@tip-bot2/
When users do system-wide profiling, perf has to allocate a buffer when forking a thread or delete a buffer when deleting a thread. The pmu->task_ctx_cache is required. Perf has to search the perf_event_list every time to find the proper PMU.
So the *ctx_cache is introduced to avoid the search.
Thanks,
Kan
Quoted 17 lines
Specifically, why can't we do something like:
struct perf_ctx_data { struct rcu_head rcu; refcount_t refcount; int global; char data[]; };and simply allocate the whole thing as a single allocation?
So then the allocation is something like:
cd = kzalloc(sizeof(*cd) + event->pmu->task_ctx_size, GFP_KERNEL);
Peter Zijlstra
maintainerQuoted 3 lines · Kan
The
kmem_cacheis introduced to address the alignment requirement for Arch LBR.
https://lore.kernel.org/lkml/159420190705.4006.11190540790919295173.tip-bot2@tip-bot2/
Urgh, okay. Please stick that in a comment somewhere.