From patchwork Mon Apr 7 15:04:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 27900 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C192220490 for ; Mon, 7 Apr 2014 15:05:49 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id s7sf4349139lbd.4 for ; Mon, 07 Apr 2014 08:05:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=YAp2CX8PfKPEddDYUX07BoQlANhazyv2ct8MXGw2TMw=; b=cmZHaQqOb6YijOyVGBrrxdNC4Q6DXsO8GSXTB+cqMGDBM8gj8T36T/EmKBwYt8wJSc nejuHmVu/l7m5qK+MkQKa6CL54xMW6CltfIBG3ofqJnv+Da82tibuQ+Epb/rSHjiZJtw bNNBE8nOH+eLlZghZ0Cs54PGS3ijiXaKs8uESr/b7Jn8LEq63vH1Eni51haiEwjMNGhX pTQXAnC6eogdPos8y9svpSI8w6ekhWlWg4A0ACNnL/Ub5gfG6TW0Cw9j3WwRmxBGtiv3 MhJZgIplgVTYBgRK0QmPtrCEWR8nNeFq+JeUJGX/hb6sd/zg8rK2gt+VBeH13NqLZqrR 4klQ== X-Gm-Message-State: ALoCoQnP2h/H9BhzUU8HgtdYq9mkU7fP+2eMKb6i9qsJGWhYNB8JZOr/NzQViGlLZ35MQsOZFvvY X-Received: by 10.112.136.162 with SMTP id qb2mr362513lbb.16.1396883148093; Mon, 07 Apr 2014 08:05:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.101 with SMTP id k92ls1775723qgf.64.gmail; Mon, 07 Apr 2014 08:05:48 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr14123vcd.45.1396883147962; Mon, 07 Apr 2014 08:05:47 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id dy7si2169211vec.72.2014.04.07.08.05.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:05:47 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id oz11so3608454veb.19 for ; Mon, 07 Apr 2014 08:05:47 -0700 (PDT) X-Received: by 10.220.89.4 with SMTP id c4mr2087vcm.53.1396883147871; Mon, 07 Apr 2014 08:05:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp169627vcv; Mon, 7 Apr 2014 08:05:47 -0700 (PDT) X-Received: by 10.66.240.4 with SMTP id vw4mr31377680pac.26.1396883146946; Mon, 07 Apr 2014 08:05:46 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nm5si8503490pbc.122.2014.04.07.08.05.46; Mon, 07 Apr 2014 08:05:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755402AbaDGPFW (ORCPT + 27 others); Mon, 7 Apr 2014 11:05:22 -0400 Received: from mail-ee0-f53.google.com ([74.125.83.53]:42350 "EHLO mail-ee0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755335AbaDGPFR (ORCPT ); Mon, 7 Apr 2014 11:05:17 -0400 Received: by mail-ee0-f53.google.com with SMTP id b57so711227eek.26 for ; Mon, 07 Apr 2014 08:05:16 -0700 (PDT) X-Received: by 10.14.115.195 with SMTP id e43mr2926062eeh.76.1396883116044; Mon, 07 Apr 2014 08:05:16 -0700 (PDT) Received: from localhost.localdomain (201-179-62-37.mobileinternet.proximus.be. [37.62.179.201]) by mx.google.com with ESMTPSA id o4sm42287649eef.20.2014.04.07.08.05.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:05:14 -0700 (PDT) From: Jean Pihet To: Borislav Petkov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter Cc: Robert Richter , Jean Pihet Subject: [PATCH 09/16] perf, persistent: Use unique event ids Date: Mon, 7 Apr 2014 17:04:31 +0200 Message-Id: <1396883078-25320-10-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> References: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jean.pihet@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.174 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org 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 Signed-off-by: Jean Pihet --- 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 6578acf..d04827c 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) {