History

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.

Rob Herring committed 4 years ago

Commit 369461c1 parent d58071a3 files · +15 −6Browse files

Unified · Split

3 files
  1. arch/x86/events/core.c +5 −5
  2. arch/x86/events/perf_event.h +1 −1
  3. include/linux/perf_event.h +9 −0
arch/x86/events/core.c+5−5
@@ -2476,7 +2476,7 @@ static int x86_pmu_event_init(struct perf_event *event) · 2475 unmodified lines
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) · 27 unmodified lines
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) · 14 unmodified lines
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) · 4 unmodified lines
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, · 176 unmodified lines
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+1−1
@@ -74,7 +74,7 @@ static inline bool constraint_match(struct event_constraint *c, u64 ecode) · 73 unmodified lines
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+9−0
@@ -129,6 +129,15 @@ struct hw_perf_event_extra { · 128 unmodified lines
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 */