diff mbox

[v1,1/2] perf/core: Add API to look up PMU type by name

Message ID 1519431578-11995-1-git-send-email-skannan@codeaurora.org (mailing list archive)
State New, archived
Headers show

Commit Message

Saravana Kannan Feb. 24, 2018, 12:19 a.m. UTC
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(+)

Comments

Peter Zijlstra Feb. 24, 2018, 8:08 a.m. UTC | #1
On Fri, Feb 23, 2018 at 04:19:37PM -0800, Saravana Kannan wrote:
> 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;
> +}

Not without an in-tree user.
diff mbox

Patch

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
  *