@@ -461,7 +461,12 @@ struct perf_event_attr {
inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */
remove_on_exec : 1, /* event is removed from task on exec */
sigtrap : 1, /* send synchronous SIGTRAP on event */
- __reserved_1 : 26;
+ /*
+ * Add a limited amount of jitter on each alternate period, where
+ * the jitter is between [0, (2<<jitter_alt_period) - 1]
+ */
+ jitter_alt_period : 3,
+ __reserved_1 : 23;
union {
__u32 wakeup_events; /* wakeup every n events */
@@ -15,6 +15,7 @@
#include <linux/idr.h>
#include <linux/file.h>
#include <linux/poll.h>
+#include <linux/random.h>
#include <linux/slab.h>
#include <linux/hash.h>
#include <linux/tick.h>
@@ -9878,7 +9879,10 @@ static int __perf_event_overflow(struct perf_event *event,
if (event->attr.alt_sample_period) {
bool using_alt = hwc->using_alt_sample_period;
u64 sample_period = (using_alt ? event->attr.sample_period
- : event->attr.alt_sample_period);
+ : event->attr.alt_sample_period)
+ + (event->attr.jitter_alt_period
+ ? get_random_u32_below(2 << event->attr.jitter_alt_period)
+ : 0);
hwc->sample_period = sample_period;
hwc->using_alt_sample_period = !using_alt;
@@ -12803,6 +12807,9 @@ SYSCALL_DEFINE5(perf_event_open,
}
}
+ if (attr.jitter_alt_period && !attr.alt_sample_period)
+ return -EINVAL;
+
/* Only privileged users can get physical addresses */
if ((attr.sample_type & PERF_SAMPLE_PHYS_ADDR)) {
err = perf_allow_kernel(&attr);