Skip to content

Commit 82ff0c0

Browse files
robherringwilldeacon
authored andcommitted
perf: Add a counter for number of user access events in context
On arm64, user space counter access will be controlled differently compared to x86. On x86, access in the strictest mode is enabled for all tasks in an MM when any event is mmap'ed. For arm64, access is explicitly requested for an event and only enabled when the event's context is active. This avoids hooks into the arch context switch code and gives better control of when access is enabled. In order to configure user space access when the PMU is enabled, it is necessary to know if any event (currently active or not) in the current context has user space accessed enabled. Add a counter similar to other counters in the context to avoid walking the event list every time. Reviewed-by: Mark Rutland <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 369461c commit 82ff0c0

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

include/linux/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ struct perf_event_context {
831831

832832
int nr_events;
833833
int nr_active;
834+
int nr_user;
834835
int is_active;
835836
int nr_stat;
836837
int nr_freq;

kernel/events/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,8 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
18081808

18091809
list_add_rcu(&event->event_entry, &ctx->event_list);
18101810
ctx->nr_events++;
1811+
if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT)
1812+
ctx->nr_user++;
18111813
if (event->attr.inherit_stat)
18121814
ctx->nr_stat++;
18131815

@@ -1999,6 +2001,8 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
19992001
event->attach_state &= ~PERF_ATTACH_CONTEXT;
20002002

20012003
ctx->nr_events--;
2004+
if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT)
2005+
ctx->nr_user--;
20022006
if (event->attr.inherit_stat)
20032007
ctx->nr_stat--;
20042008

0 commit comments

Comments
 (0)