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
2476 2476
2477 if (READ_ONCE(x86_pmu.attr_rdpmc) &&2477 if (READ_ONCE(x86_pmu.attr_rdpmc) &&
2478 !(event->hw.flags & PERF_X86_EVENT_LARGE_PEBS))2478 !(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;
2480 2480
2481 return err;2481 return err;
2482}2482}
@@ -2510,7 +2510,7 @@ void perf_clear_dirty_counters(void) · 27 unmodified lines
2510 2510
2511static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm)2511static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm)
2512{2512{
2513 if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))2513 if (!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT))
2514 return;2514 return;
2515 2515
2516 /*2516 /*
@@ -2531,7 +2531,7 @@ static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm) · 14 unmodified lines
2531 2531
2532static void x86_pmu_event_unmapped(struct perf_event *event, struct mm_struct *mm)2532static void x86_pmu_event_unmapped(struct perf_event *event, struct mm_struct *mm)
2533{2533{
2534 if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))2534 if (!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT))
2535 return;2535 return;
2536 2536
2537 if (atomic_dec_and_test(&mm->context.perf_rdpmc_allowed))2537 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
2542{2542{
2543 struct hw_perf_event *hwc = &event->hw;2543 struct hw_perf_event *hwc = &event->hw;
2544 2544
2545 if (!(hwc->flags & PERF_X86_EVENT_RDPMC_ALLOWED))2545 if (!(hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT))
2546 return 0;2546 return 0;
2547 2547
2548 if (is_metric_idx(hwc->idx))2548 if (is_metric_idx(hwc->idx))
@@ -2725,7 +2725,7 @@ void arch_perf_update_userpage(struct perf_event *event, · 176 unmodified lines
2725 userpg->cap_user_time = 0;2725 userpg->cap_user_time = 0;
2726 userpg->cap_user_time_zero = 0;2726 userpg->cap_user_time_zero = 0;
2727 userpg->cap_user_rdpmc =2727 userpg->cap_user_rdpmc =
2728 !!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED);2728 !!(event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT);
2729 userpg->pmc_width = x86_pmu.cntval_bits;2729 userpg->pmc_width = x86_pmu.cntval_bits;
2730 2730
2731 if (!using_native_sched_clock() || !sched_clock_stable())2731 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
74#define PERF_X86_EVENT_PEBS_NA_HSW 0x0010 /* haswell style datala, unknown */74#define PERF_X86_EVENT_PEBS_NA_HSW 0x0010 /* haswell style datala, unknown */
75#define PERF_X86_EVENT_EXCL 0x0020 /* HT exclusivity on counter */75#define PERF_X86_EVENT_EXCL 0x0020 /* HT exclusivity on counter */
76#define PERF_X86_EVENT_DYNAMIC 0x0040 /* dynamic alloc'd constraint */76#define PERF_X86_EVENT_DYNAMIC 0x0040 /* dynamic alloc'd constraint */
77#define PERF_X86_EVENT_RDPMC_ALLOWED 0x0080 /* grant rdpmc permission */77
78#define PERF_X86_EVENT_EXCL_ACCT 0x0100 /* accounted EXCL event */78#define PERF_X86_EVENT_EXCL_ACCT 0x0100 /* accounted EXCL event */
79#define PERF_X86_EVENT_AUTO_RELOAD 0x0200 /* use PEBS auto-reload */79#define PERF_X86_EVENT_AUTO_RELOAD 0x0200 /* use PEBS auto-reload */
80#define PERF_X86_EVENT_LARGE_PEBS 0x0400 /* use large PEBS */80#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
129 int idx; /* index in shared_regs->regs[] */129 int idx; /* index in shared_regs->regs[] */
130};130};
131 131
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
132/**141/**
133 * struct hw_perf_event - performance event hardware details:142 * struct hw_perf_event - performance event hardware details:
134 */143 */