From patchwork Thu Aug 22 14:13:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f200.google.com (mail-ye0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 70943248E6 for ; Thu, 22 Aug 2013 14:14:52 +0000 (UTC) Received: by mail-ye0-f200.google.com with SMTP id r5sf1525381yen.7 for ; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:delivered-to:sender:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=FIkci1LoeJqYfNXuFG1RZtm6ouu8144SKpzAjib/OVo=; b=i0wnwSd0dcn+M9wsm+/+QMdDHCZCE0Tn2OiB31QHVyPDOH4veEO5XFFKGSdxTTVGV8 qX66tgm5LLXp4bvIJLKOiVt7Nap28Xy887VdJgzNRxW30NchF4LHx0EcvPCgI7ONvLbL poZO87c8tIY5+wPEZEAHg0uClJgh6HAGaYR17wNWiHMWwhEvKr8HB5tK7ujsdZgPUiQq bvn1Osih6qiV3CKnO9EYlFmMjnhCGy4f/E7MmcZByuqcmmadXMqevujviEUu0Y46MKxU jCdg5GtqBvqKX2vtdHskowvwCtr0ZCiS7cMsNA42qcIau7SZUnGlAal92bD+nkjf0x+L sUPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:sender:from:to:cc :subject:date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=FIkci1LoeJqYfNXuFG1RZtm6ouu8144SKpzAjib/OVo=; b=QUb9EspoB+j1fndDHzAd5OQ0WsejZrktgbDvRYgael+kid+xlM4Bjeo+ScM8DvrEUW h0H/AiI6jQ2o965j/lHwwi4epiOQXs95jbOlYCrSYiKSkxYIv/9isHU+wDiM0Qnk/ybU WMJqyqDo6qr5CqT0EFCjz53P2AqD2XnW7R590DobJVLBqaFT7MkXcZ+oESm+fQ/TMZtN 9a/arviiqBoJdjEUiO/sztAemKMcavwUUMOnmCpv8o6zQ9BChkLUEnJvBean+U3Dco1B dtFH8VIA7dgdStt3qINYZFU2sJuAfCNvRuxM326tU7OCta1BeZeQ3nmmY75ZszzLdF50 LuVQ== X-Received: by 10.224.173.4 with SMTP id n4mr13070360qaz.3.1377180892223; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.196 with SMTP id w4ls1072501qen.71.gmail; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) X-Received: by 10.58.207.103 with SMTP id lv7mr496585vec.33.1377180892094; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id fb4si4019997veb.12.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:52 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22e; Received: by mail-ve0-f174.google.com with SMTP id d10so1524203vea.19 for ; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) X-Gm-Message-State: ALoCoQkIQ0xznuIwGAXIjM71KjFkm+MR+ZVW5Qz8VDRkInINdJpGeiJEc3l1dAKscZ5+fDN0aGg7 X-Received: by 10.58.165.70 with SMTP id yw6mr11801108veb.19.1377180891983; Thu, 22 Aug 2013 07:14:51 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp33221vcz; Thu, 22 Aug 2013 07:14:51 -0700 (PDT) X-Received: by 10.205.120.78 with SMTP id fx14mr10651447bkc.7.1377180890544; Thu, 22 Aug 2013 07:14:50 -0700 (PDT) Received: from mail-bk0-x231.google.com (mail-bk0-x231.google.com [2a00:1450:4008:c01::231]) by mx.google.com with ESMTPS id ec1si2299994bkb.303.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:50 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::231 as permitted sender) client-ip=2a00:1450:4008:c01::231; Received: by mail-bk0-f49.google.com with SMTP id r7so689303bkg.8 for ; Thu, 22 Aug 2013 07:14:49 -0700 (PDT) X-Received: by 10.204.69.12 with SMTP id x12mr10618752bki.14.1377180889523; Thu, 22 Aug 2013 07:14:49 -0700 (PDT) Received: from rric.localhost (g224195237.adsl.alicedsl.de. [92.224.195.237]) by mx.google.com with ESMTPSA id jh13sm3079991bkb.13.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:48 -0700 (PDT) Sender: Robert Richter From: Robert Richter To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Borislav Petkov , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter , Robert Richter Subject: [PATCH v3 09/12] perf, persistent: Use unique event ids Date: Thu, 22 Aug 2013 16:13:24 +0200 Message-Id: <1377180807-12758-10-git-send-email-rric@kernel.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1377180807-12758-1-git-send-email-rric@kernel.org> References: <1377180807-12758-1-git-send-email-rric@kernel.org> X-Original-Sender: rric.net@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Robert Richter Tracepoints have a unique attr.config value. But, this is not sufficient to support all event types. For this we need to generate unique event ids. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- kernel/events/persistent.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c index aca1e98..f23270b 100644 --- a/kernel/events/persistent.c +++ b/kernel/events/persistent.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "internal.h" @@ -13,10 +14,37 @@ struct pevent { int id; }; +static struct idr event_idr; +static struct mutex event_lock; static struct pmu persistent_pmu; static DEFINE_PER_CPU(struct list_head, pevents); static DEFINE_PER_CPU(struct mutex, pevents_lock); +static inline struct pevent *find_event(int id) +{ + struct pevent *pevent; + rcu_read_lock(); + pevent = idr_find(&event_idr, id); + rcu_read_lock(); + return pevent; +} + +static inline int get_event_id(struct pevent *pevent) +{ + int event_id; + mutex_lock(&event_lock); + event_id = idr_alloc(&event_idr, pevent, 1, INT_MAX, GFP_KERNEL); + mutex_unlock(&event_lock); + return event_id; +} + +static inline void put_event_id(int id) +{ + mutex_lock(&event_lock); + idr_remove(&event_idr, id); + mutex_unlock(&event_lock); +} + /* Must be protected with pevents_lock. */ static struct perf_event *__pevent_find(int cpu, int id) { @@ -128,13 +156,16 @@ persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) struct pevent *pevent; char id_buf[32]; int cpu; - int ret = 0; + int ret; pevent = kzalloc(sizeof(*pevent), GFP_KERNEL); if (!pevent) return -ENOMEM; - pevent->id = attr->config; + ret = get_event_id(pevent); + if (ret < 0) + goto fail; + pevent->id = ret; if (!name) { snprintf(id_buf, sizeof(id_buf), "%d", pevent->id); @@ -163,6 +194,9 @@ persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) fail: for_each_possible_cpu(cpu) persistent_event_close(cpu, pevent); + + if (pevent->id) + put_event_id(pevent->id); kfree(pevent->name); kfree(pevent); @@ -306,6 +340,8 @@ void __init perf_register_persistent(void) { int cpu; + idr_init(&event_idr); + mutex_init(&event_lock); perf_pmu_register(&persistent_pmu, "persistent", PERF_TYPE_PERSISTENT); for_each_possible_cpu(cpu) {