Skip to content

Commit 369461c

Browse files
robherringwilldeacon
authored andcommitted
x86: perf: Move RDPMC event flag to a common definition
In preparation to enable user counter access on arm64 and to move some of the user access handling to perf core, create a common event flag for user counter access and convert x86 to use it. Since the architecture specific flags start at the LSB, starting at the MSB for common flags. Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Kan Liang <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: [email protected] Cc: "H. Peter Anvin" <[email protected]> Cc: [email protected] 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 d58071a commit 369461c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

arch/x86/events/core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ static int x86_pmu_event_init(struct perf_event *event)
24762476

24772477
if (READ_ONCE(x86_pmu.attr_rdpmc) &&
24782478
!(event->hw.flags & PERF_X86_EVENT_LARGE_PEBS))
2479-
event->hw.flags |= PERF_X86_EVENT_RDPMC_ALLOWED;
2479+
event->hw.flags |= PERF_EVENT_FLAG_USER_READ_CNT;
24802480

24812481
return err;
24822482
}
@@ -2510,7 +2510,7 @@ void perf_clear_dirty_counters(void)
25102510

25112511
static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm)
25122512
{
2513-
if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
2513+
if (!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT))
25142514
return;
25152515

25162516
/*
@@ -2531,7 +2531,7 @@ static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm)
25312531

25322532
static void x86_pmu_event_unmapped(struct perf_event *event, struct mm_struct *mm)
25332533
{
2534-
if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
2534+
if (!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT))
25352535
return;
25362536

25372537
if (atomic_dec_and_test(&mm->context.perf_rdpmc_allowed))
@@ -2542,7 +2542,7 @@ static int x86_pmu_event_idx(struct perf_event *event)
25422542
{
25432543
struct hw_perf_event *hwc = &event->hw;
25442544

2545-
if (!(hwc->flags & PERF_X86_EVENT_RDPMC_ALLOWED))
2545+
if (!(hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT))
25462546
return 0;
25472547

25482548
if (is_metric_idx(hwc->idx))
@@ -2725,7 +2725,7 @@ void arch_perf_update_userpage(struct perf_event *event,
27252725
userpg->cap_user_time = 0;
27262726
userpg->cap_user_time_zero = 0;
27272727
userpg->cap_user_rdpmc =
2728-
!!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED);
2728+
!!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT);
27292729
userpg->pmc_width = x86_pmu.cntval_bits;
27302730

27312731
if (!using_native_sched_clock() || !sched_clock_stable())

arch/x86/events/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static inline bool constraint_match(struct event_constraint *c, u64 ecode)
7474
#define PERF_X86_EVENT_PEBS_NA_HSW 0x0010 /* haswell style datala, unknown */
7575
#define PERF_X86_EVENT_EXCL 0x0020 /* HT exclusivity on counter */
7676
#define PERF_X86_EVENT_DYNAMIC 0x0040 /* dynamic alloc'd constraint */
77-
#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0080 /* grant rdpmc permission */
77+
7878
#define PERF_X86_EVENT_EXCL_ACCT 0x0100 /* accounted EXCL event */
7979
#define PERF_X86_EVENT_AUTO_RELOAD 0x0200 /* use PEBS auto-reload */
8080
#define PERF_X86_EVENT_LARGE_PEBS 0x0400 /* use large PEBS */

include/linux/perf_event.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ struct hw_perf_event_extra {
129129
int idx; /* index in shared_regs->regs[] */
130130
};
131131

132+
/**
133+
* hw_perf_event::flag values
134+
*
135+
* PERF_EVENT_FLAG_ARCH bits are reserved for architecture-specific
136+
* usage.
137+
*/
138+
#define PERF_EVENT_FLAG_ARCH 0x0000ffff
139+
#define PERF_EVENT_FLAG_USER_READ_CNT 0x80000000
140+
132141
/**
133142
* struct hw_perf_event - performance event hardware details:
134143
*/

0 commit comments

Comments
 (0)