linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] perf/core: Add API to look up PMU type by name
@ 2018-02-24  0:19 Saravana Kannan
  2018-02-24  0:19 ` [PATCH v1 2/2] perf/core: Add support for PMUs that can be read from any CPU Saravana Kannan
  2018-02-24  8:08 ` [PATCH v1 1/2] perf/core: Add API to look up PMU type by name Peter Zijlstra
  0 siblings, 2 replies; 13+ messages in thread
From: Saravana Kannan @ 2018-02-24  0:19 UTC (permalink / raw)
  To: mark.rutland, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim
  Cc: skannan, avilaj, linux-arm-kernel, linux-kernel

When the event numbers registered by multiple PMUs overlap, the
attr->type value passed to perf_event_create_kernel_counter() is used
to determine which PMU to use to create a perf_event.

However, when the PMU in question is not a standard PMU (defined in
perf_type_id), there is no way for a kernel client to look up the PMU
type for the PMU of interest and set the attr->type appropriately.

So, add an API to look up the PMU type by name. That way, the kernel
APIs can function in a fashion similar to the user space interface.

Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
---
 kernel/events/core.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 96db9ae..5d3df58 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10310,6 +10310,29 @@ static int perf_event_set_clock(struct perf_event *event, clockid_t clk_id)
 	return err;
 }
 
+int perf_find_pmu_type_by_name(const char *name)
+{
+	struct pmu *pmu;
+	int ret = -1;
+
+	mutex_lock(&pmus_lock);
+
+	list_for_each_entry(pmu, &pmus, entry) {
+		if (!pmu->name || pmu->type < 0)
+			continue;
+
+		if (!strcmp(name, pmu->name)) {
+			ret = pmu->type;
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&pmus_lock);
+
+	return ret;
+}
+
 /**
  * perf_event_create_kernel_counter
  *
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-03-07 16:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-24  0:19 [PATCH v1 1/2] perf/core: Add API to look up PMU type by name Saravana Kannan
2018-02-24  0:19 ` [PATCH v1 2/2] perf/core: Add support for PMUs that can be read from any CPU Saravana Kannan
2018-02-24  0:56   ` Saravana Kannan
2018-02-24  8:41   ` Peter Zijlstra
2018-02-27  1:53     ` skannan
2018-02-27 11:52       ` Mark Rutland
2018-03-03 15:41       ` Peter Zijlstra
2018-03-07 16:39         ` Jeremy Linton
2018-02-25 14:38   ` Mark Rutland
2018-02-27  2:11     ` skannan
2018-02-27 11:43       ` Mark Rutland
2018-02-27 23:15         ` skannan
2018-02-24  8:08 ` [PATCH v1 1/2] perf/core: Add API to look up PMU type by name Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).