diff options
author | Peter Zijlstra <peterz@infradead.org> | 2010-04-08 17:03:20 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-05-07 05:31:02 -0400 |
commit | ab608344bcbde4f55ec4cd911b686b0ce3eae076 (patch) | |
tree | ebd38efabfaab59d6de11a24143d70e1eec36fae | |
parent | 2b0b5c6fe9b383f3cf35a0a6371c9d577bd523ff (diff) |
perf, x86: Improve the PEBS ABI
Rename perf_event_attr::precise to perf_event_attr::precise_ip and
widen it to 2 bits. This new field describes the required precision of
the PERF_SAMPLE_IP field:
0 - SAMPLE_IP can have arbitrary skid
1 - SAMPLE_IP must have constant skid
2 - SAMPLE_IP requested to have 0 skid
3 - SAMPLE_IP must have 0 skid
And modify the Intel PEBS code accordingly. The PEBS implementation
now supports up to precise_ip == 2, where we perform the IP fixup.
Also s/PERF_RECORD_MISC_EXACT/&_IP/ to clarify its meaning, this bit
should be set for each PERF_SAMPLE_IP field known to match the actual
instruction triggering the event.
This new scheme allows for a PEBS mode that uses the buffer for more
than a single event.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | arch/x86/kernel/cpu/perf_event.c | 17 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/perf_event_intel.c | 4 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/perf_event_intel_ds.c | 12 | ||||
-rw-r--r-- | include/linux/perf_event.h | 23 | ||||
-rw-r--r-- | tools/perf/builtin-top.c | 2 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 25 |
6 files changed, 60 insertions, 23 deletions
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index 4a3f1f2b9b91..27fa9eeed024 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -488,6 +488,21 @@ static int x86_setup_perfctr(struct perf_event *event) | |||
488 | 488 | ||
489 | static int x86_pmu_hw_config(struct perf_event *event) | 489 | static int x86_pmu_hw_config(struct perf_event *event) |
490 | { | 490 | { |
491 | if (event->attr.precise_ip) { | ||
492 | int precise = 0; | ||
493 | |||
494 | /* Support for constant skid */ | ||
495 | if (x86_pmu.pebs) | ||
496 | precise++; | ||
497 | |||
498 | /* Support for IP fixup */ | ||
499 | if (x86_pmu.lbr_nr) | ||
500 | precise++; | ||
501 | |||
502 | if (event->attr.precise_ip > precise) | ||
503 | return -EOPNOTSUPP; | ||
504 | } | ||
505 | |||
491 | /* | 506 | /* |
492 | * Generate PMC IRQs: | 507 | * Generate PMC IRQs: |
493 | * (keep 'enabled' bit clear for now) | 508 | * (keep 'enabled' bit clear for now) |
@@ -1780,7 +1795,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs) | |||
1780 | } | 1795 | } |
1781 | 1796 | ||
1782 | if (regs->flags & PERF_EFLAGS_EXACT) | 1797 | if (regs->flags & PERF_EFLAGS_EXACT) |
1783 | misc |= PERF_RECORD_MISC_EXACT; | 1798 | misc |= PERF_RECORD_MISC_EXACT_IP; |
1784 | 1799 | ||
1785 | return misc; | 1800 | return misc; |
1786 | } | 1801 | } |
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c index a4b56ac425cb..fdbc652d3feb 100644 --- a/arch/x86/kernel/cpu/perf_event_intel.c +++ b/arch/x86/kernel/cpu/perf_event_intel.c | |||
@@ -563,7 +563,7 @@ static void intel_pmu_disable_event(struct perf_event *event) | |||
563 | 563 | ||
564 | x86_pmu_disable_event(event); | 564 | x86_pmu_disable_event(event); |
565 | 565 | ||
566 | if (unlikely(event->attr.precise)) | 566 | if (unlikely(event->attr.precise_ip)) |
567 | intel_pmu_pebs_disable(event); | 567 | intel_pmu_pebs_disable(event); |
568 | } | 568 | } |
569 | 569 | ||
@@ -615,7 +615,7 @@ static void intel_pmu_enable_event(struct perf_event *event) | |||
615 | return; | 615 | return; |
616 | } | 616 | } |
617 | 617 | ||
618 | if (unlikely(event->attr.precise)) | 618 | if (unlikely(event->attr.precise_ip)) |
619 | intel_pmu_pebs_enable(event); | 619 | intel_pmu_pebs_enable(event); |
620 | 620 | ||
621 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); | 621 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); |
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c index 35056f715e9e..18018d1311cd 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_ds.c +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c | |||
@@ -307,7 +307,7 @@ intel_pebs_constraints(struct perf_event *event) | |||
307 | { | 307 | { |
308 | struct event_constraint *c; | 308 | struct event_constraint *c; |
309 | 309 | ||
310 | if (!event->attr.precise) | 310 | if (!event->attr.precise_ip) |
311 | return NULL; | 311 | return NULL; |
312 | 312 | ||
313 | if (x86_pmu.pebs_constraints) { | 313 | if (x86_pmu.pebs_constraints) { |
@@ -330,7 +330,7 @@ static void intel_pmu_pebs_enable(struct perf_event *event) | |||
330 | cpuc->pebs_enabled |= 1ULL << hwc->idx; | 330 | cpuc->pebs_enabled |= 1ULL << hwc->idx; |
331 | WARN_ON_ONCE(cpuc->enabled); | 331 | WARN_ON_ONCE(cpuc->enabled); |
332 | 332 | ||
333 | if (x86_pmu.intel_cap.pebs_trap) | 333 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1) |
334 | intel_pmu_lbr_enable(event); | 334 | intel_pmu_lbr_enable(event); |
335 | } | 335 | } |
336 | 336 | ||
@@ -345,7 +345,7 @@ static void intel_pmu_pebs_disable(struct perf_event *event) | |||
345 | 345 | ||
346 | hwc->config |= ARCH_PERFMON_EVENTSEL_INT; | 346 | hwc->config |= ARCH_PERFMON_EVENTSEL_INT; |
347 | 347 | ||
348 | if (x86_pmu.intel_cap.pebs_trap) | 348 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1) |
349 | intel_pmu_lbr_disable(event); | 349 | intel_pmu_lbr_disable(event); |
350 | } | 350 | } |
351 | 351 | ||
@@ -485,7 +485,7 @@ static void __intel_pmu_pebs_event(struct perf_event *event, | |||
485 | regs.bp = pebs->bp; | 485 | regs.bp = pebs->bp; |
486 | regs.sp = pebs->sp; | 486 | regs.sp = pebs->sp; |
487 | 487 | ||
488 | if (intel_pmu_pebs_fixup_ip(regs)) | 488 | if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(®s)) |
489 | regs.flags |= PERF_EFLAGS_EXACT; | 489 | regs.flags |= PERF_EFLAGS_EXACT; |
490 | else | 490 | else |
491 | regs.flags &= ~PERF_EFLAGS_EXACT; | 491 | regs.flags &= ~PERF_EFLAGS_EXACT; |
@@ -518,7 +518,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) | |||
518 | 518 | ||
519 | WARN_ON_ONCE(!event); | 519 | WARN_ON_ONCE(!event); |
520 | 520 | ||
521 | if (!event->attr.precise) | 521 | if (!event->attr.precise_ip) |
522 | return; | 522 | return; |
523 | 523 | ||
524 | n = top - at; | 524 | n = top - at; |
@@ -570,7 +570,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | |||
570 | 570 | ||
571 | WARN_ON_ONCE(!event); | 571 | WARN_ON_ONCE(!event); |
572 | 572 | ||
573 | if (!event->attr.precise) | 573 | if (!event->attr.precise_ip) |
574 | continue; | 574 | continue; |
575 | 575 | ||
576 | if (__test_and_set_bit(bit, (unsigned long *)&status)) | 576 | if (__test_and_set_bit(bit, (unsigned long *)&status)) |
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 6be4a0f9137c..23cd0057a681 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -203,9 +203,19 @@ struct perf_event_attr { | |||
203 | enable_on_exec : 1, /* next exec enables */ | 203 | enable_on_exec : 1, /* next exec enables */ |
204 | task : 1, /* trace fork/exit */ | 204 | task : 1, /* trace fork/exit */ |
205 | watermark : 1, /* wakeup_watermark */ | 205 | watermark : 1, /* wakeup_watermark */ |
206 | precise : 1, /* OoO invariant counter */ | 206 | /* |
207 | 207 | * precise_ip: | |
208 | __reserved_1 : 48; | 208 | * |
209 | * 0 - SAMPLE_IP can have arbitrary skid | ||
210 | * 1 - SAMPLE_IP must have constant skid | ||
211 | * 2 - SAMPLE_IP requested to have 0 skid | ||
212 | * 3 - SAMPLE_IP must have 0 skid | ||
213 | * | ||
214 | * See also PERF_RECORD_MISC_EXACT_IP | ||
215 | */ | ||
216 | precise_ip : 2, /* skid constraint */ | ||
217 | |||
218 | __reserved_1 : 47; | ||
209 | 219 | ||
210 | union { | 220 | union { |
211 | __u32 wakeup_events; /* wakeup every n events */ | 221 | __u32 wakeup_events; /* wakeup every n events */ |
@@ -296,7 +306,12 @@ struct perf_event_mmap_page { | |||
296 | #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0) | 306 | #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0) |
297 | #define PERF_RECORD_MISC_GUEST_USER (5 << 0) | 307 | #define PERF_RECORD_MISC_GUEST_USER (5 << 0) |
298 | 308 | ||
299 | #define PERF_RECORD_MISC_EXACT (1 << 14) | 309 | /* |
310 | * Indicates that the content of PERF_SAMPLE_IP points to | ||
311 | * the actual instruction that triggered the event. See also | ||
312 | * perf_event_attr::precise_ip. | ||
313 | */ | ||
314 | #define PERF_RECORD_MISC_EXACT_IP (1 << 14) | ||
300 | /* | 315 | /* |
301 | * Reserve the last bit to indicate some extended misc field | 316 | * Reserve the last bit to indicate some extended misc field |
302 | */ | 317 | */ |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 3de397764cb3..ed9b5b6905fa 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -1021,7 +1021,7 @@ static void event__process_sample(const event_t *self, | |||
1021 | return; | 1021 | return; |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | if (self->header.misc & PERF_RECORD_MISC_EXACT) | 1024 | if (self->header.misc & PERF_RECORD_MISC_EXACT_IP) |
1025 | exact_samples++; | 1025 | exact_samples++; |
1026 | 1026 | ||
1027 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || | 1027 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index bc8b7e614207..ae7f5917935c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -654,10 +654,6 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr) | |||
654 | return EVT_FAILED; | 654 | return EVT_FAILED; |
655 | n = hex2u64(str + 1, &config); | 655 | n = hex2u64(str + 1, &config); |
656 | if (n > 0) { | 656 | if (n > 0) { |
657 | if (str[n+1] == 'p') { | ||
658 | attr->precise = 1; | ||
659 | n++; | ||
660 | } | ||
661 | *strp = str + n + 1; | 657 | *strp = str + n + 1; |
662 | attr->type = PERF_TYPE_RAW; | 658 | attr->type = PERF_TYPE_RAW; |
663 | attr->config = config; | 659 | attr->config = config; |
@@ -692,19 +688,29 @@ static enum event_result | |||
692 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) | 688 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) |
693 | { | 689 | { |
694 | const char *str = *strp; | 690 | const char *str = *strp; |
695 | int eu = 1, ek = 1, eh = 1; | 691 | int exclude = 0; |
692 | int eu = 0, ek = 0, eh = 0, precise = 0; | ||
696 | 693 | ||
697 | if (*str++ != ':') | 694 | if (*str++ != ':') |
698 | return 0; | 695 | return 0; |
699 | while (*str) { | 696 | while (*str) { |
700 | if (*str == 'u') | 697 | if (*str == 'u') { |
698 | if (!exclude) | ||
699 | exclude = eu = ek = eh = 1; | ||
701 | eu = 0; | 700 | eu = 0; |
702 | else if (*str == 'k') | 701 | } else if (*str == 'k') { |
702 | if (!exclude) | ||
703 | exclude = eu = ek = eh = 1; | ||
703 | ek = 0; | 704 | ek = 0; |
704 | else if (*str == 'h') | 705 | } else if (*str == 'h') { |
706 | if (!exclude) | ||
707 | exclude = eu = ek = eh = 1; | ||
705 | eh = 0; | 708 | eh = 0; |
706 | else | 709 | } else if (*str == 'p') { |
710 | precise++; | ||
711 | } else | ||
707 | break; | 712 | break; |
713 | |||
708 | ++str; | 714 | ++str; |
709 | } | 715 | } |
710 | if (str >= *strp + 2) { | 716 | if (str >= *strp + 2) { |
@@ -712,6 +718,7 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) | |||
712 | attr->exclude_user = eu; | 718 | attr->exclude_user = eu; |
713 | attr->exclude_kernel = ek; | 719 | attr->exclude_kernel = ek; |
714 | attr->exclude_hv = eh; | 720 | attr->exclude_hv = eh; |
721 | attr->precise_ip = precise; | ||
715 | return 1; | 722 | return 1; |
716 | } | 723 | } |
717 | return 0; | 724 | return 0; |