[PATCH] perf/core: Document {cpu|task}-clock event open behavior

From: Ravi Bangoria
Date: Wed Feb 28 2024 - 06:59:04 EST


The standard interface to invoke task-clock and cpu-clock pmu is through
software pmu (see perf_swevent_init()), since these pmus are not exposed
to the user via sysfs and thus user doesn't know their pmu->type. However,
current code allows user to open an event if user has passed correct type
in the perf event attribute. This is not easily apparent from the code and
thus worth to be documented.

Signed-off-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>
---
kernel/events/core.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f0f0f71213a1..4072bccab3ba 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11178,6 +11178,13 @@ static void cpu_clock_event_read(struct perf_event *event)

static int cpu_clock_event_init(struct perf_event *event)
{
+ /*
+ * The standard interface to invoke task-clock pmu is through software
+ * pmu(see perf_swevent_init()), since task-clock pmu is not exposed to
+ * the user via sysfs and thus user doesn't know perf_task_clock.type.
+ * However, allow user to open an event if user has passed correct type
+ * in the attribute.
+ */
if (event->attr.type != perf_cpu_clock.type)
return -ENOENT;

@@ -11260,6 +11267,13 @@ static void task_clock_event_read(struct perf_event *event)

static int task_clock_event_init(struct perf_event *event)
{
+ /*
+ * The standard interface to invoke task-clock pmu is through software
+ * pmu(see perf_swevent_init()), since task-clock pmu is not exposed to
+ * the user via sysfs and thus user doesn't know perf_task_clock.type.
+ * However, allow user to open an event if user has passed correct type
+ * in the attribute.
+ */
if (event->attr.type != perf_task_clock.type)
return -ENOENT;

--
2.34.1