perf/x86/intel: Fix handling of wakeup_events for multi-entry PEBS [Linux 4.9.175]

perf/x86/intel: Fix handling of wakeup_events for multi-entry PEBS [Linux 4.9.175]

This Linux kernel change "perf/x86/intel: Fix handling of wakeup_events for multi-entry PEBS" is included in the Linux 4.9.175 release. This change is authored by Stephane Eranian <eranian [at]> on Wed Mar 6 11:50:48 2019 -0800. The commit for this change in Linux stable tree is 88338ee (patch) which is from upstream commit 583feb0. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 583feb0.

perf/x86/intel: Fix handling of wakeup_events for multi-entry PEBS

[ Upstream commit 583feb08e7f7ac9d533b446882eb3a54737a6dbb ]

When an event is programmed with attr.wakeup_events=N (N>0), it means
the caller is interested in getting a user level notification after
N samples have been recorded in the kernel sampling buffer.

With precise events on Intel processors, the kernel uses PEBS.
The kernel tries minimize sampling overhead by verifying
if the event configuration is compatible with multi-entry PEBS mode.
If so, the kernel is notified only when the buffer has reached its threshold.
Other PEBS operates in single-entry mode, the kenrel is notified for each
PEBS sample.

The problem is that the current implementation look at frequency
mode and event sample_type but ignores the wakeup_events field. Thus,
it may not be possible to receive a notification after each precise event.

This patch fixes this problem by disabling multi-entry PEBS if wakeup_events
is non-zero.

Signed-off-by: Stephane Eranian <>
Signed-off-by: Peter Zijlstra (Intel) <>
Reviewed-by: Andi Kleen <>
Cc: Alexander Shishkin <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Jiri Olsa <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Cc: Vince Weaver <>
Signed-off-by: Ingo Molnar <>
Signed-off-by: Sasha Levin <>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/x86/events/intel/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 098ab77..a308290 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -2867,7 +2867,7 @@ static int intel_pmu_hw_config(struct perf_event *event)
        return ret;

    if (event->attr.precise_ip) {
-       if (!event->attr.freq) {
+       if (!(event->attr.freq || event->attr.wakeup_events)) {
            event->hw.flags |= PERF_X86_EVENT_AUTO_RELOAD;
            if (!(event->attr.sample_type &

Leave a Reply

Your email address will not be published. Required fields are marked *