From patchwork Sat Feb 24 00:19:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 10240063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7DC9C6056E for ; Sat, 24 Feb 2018 00:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CE3B29A92 for ; Sat, 24 Feb 2018 00:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6163429A9D; Sat, 24 Feb 2018 00:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CC4C629A92 for ; Sat, 24 Feb 2018 00:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=XeLkgfRzbL9F36TPI50uPQIxfACTSmmp7v0URlNyQfQ=; b=Jon fWctH02y/Vl/FXDsFNDkfr203de3CszzTC9x5eJN9mr8Io45/FlbNfgvRbL1fevObLzQctGyLNBX1 m6Y11YLc1rgLDNQWlo7j3YSZODVlDGOt6YpfRjoFlv4r9bsp77b7oFzF9uIqGlSlVswXzrOoDFmzz i20IGuMA69GGvzg+hj+1UwBLkANDmTJArdU46TuFtGRNQFukmHm/BU8DDDA8OKtdW5vTvjrfRLOQh vLJdSso3ZflEgN1zCzLulp1zO/d0Qgv7RBM189MrATp8gi8KS0TIvc3I1aW+L/NNATlg8B4LjJgAt QNRI+bvoybCMEaqOXdfrIwxRHuGjBtA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epNZM-0007KW-5m; Sat, 24 Feb 2018 00:20:04 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epNZF-0007Hs-QP for linux-arm-kernel@lists.infradead.org; Sat, 24 Feb 2018 00:19:59 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5CE3C60A24; Sat, 24 Feb 2018 00:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519431585; bh=uVjJ+e0vphYmNA5CsKXTRgGJfo1/NXJlhngcLBErFbQ=; h=From:To:Cc:Subject:Date:From; b=YIZRRJjLqu10pERBWli3nmIdIcAK6yHVa/zq3+LNW4cMbUWVTzITUwhnTKQOYRoyp djfKWPQzQwYIAHOeYZ8jT6tdWvPDxC7CvRfDKc67F2Ieg1qm7+Kybb0Kx1QPzOY1FX +w7AHSxdWgJIGoLqkfumWgbKLJ1wBOrJEc6a99jE= Received: from skannan1-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skannan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4837E602B6; Sat, 24 Feb 2018 00:19:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519431584; bh=uVjJ+e0vphYmNA5CsKXTRgGJfo1/NXJlhngcLBErFbQ=; h=From:To:Cc:Subject:Date:From; b=c7svz/J3dQ6NNNUhgkDRYbMPOdCoIV2uuvbZDpo88H7libIR606kykmnxRpxbRzMq 4LgQEYO+DfW9Cd6m+LfwYa+CLFK60XvBlBtZOpJiiOfUni2EsSiM7e/Etc/BGaTopL 5fgCSbRH74LAlRRhwdkWkCgRXJzjD1+WzDz8/0rc= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4837E602B6 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=skannan@codeaurora.org From: Saravana Kannan To: mark.rutland@arm.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: [PATCH v1 1/2] perf/core: Add API to look up PMU type by name Date: Fri, 23 Feb 2018 16:19:37 -0800 Message-Id: <1519431578-11995-1-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_161957_901813_19ADEC7D X-CRM114-Status: GOOD ( 14.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: skannan@codeaurora.org, avilaj@codeaurora.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 *