[PATCH 1/3] perf: disable sampled events if no PMU interrupt

From: Vince Weaver
Date: Fri May 16 2014 - 17:08:23 EST



Add common code to generate ENOTSUPP at event creation time if an
architecture attempts to create a sampled event and PERF_PMU_NO_INTERRUPT
is set.

This adds a new pmu->capabilities flag.
Initially we only support PERF_PMU_NO_INTERRUPT (to indicate a PMU
has no support for generating hardware interrupts) but there are
other capabilities that can be added later.

Signed-off-by: Vince Weaver <vincent.weaver@xxxxxxxxx>

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 3356abc..2164763 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -251,9 +251,20 @@ struct pmu {
* flush branch stack on context-switches (needed in cpu-wide mode)
*/
void (*flush_branch_stack) (void);
+
+ /*
+ * various common per-pmu feature flags
+ */
+ int capabilities;
+
};

/**
+ * struct pmu->capabilites flags
+ */
+#define PERF_PMU_NO_INTERRUPT 1
+
+/**
* enum perf_event_active_state - the states of a event
*/
enum perf_event_active_state {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f83a71a..f5d8554 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7072,6 +7072,13 @@ SYSCALL_DEFINE5(perf_event_open,
}
}

+ if (is_sampling_event(event)) {
+ if (event->pmu->capabilities & PERF_PMU_NO_INTERRUPT) {
+ err = -ENOTSUPP;
+ goto err_alloc;
+ }
+ }
+
account_event(event);

/*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/