From patchwork Thu Aug 22 14:13:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19416 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f197.google.com (mail-ye0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A9B32248E6 for ; Thu, 22 Aug 2013 14:14:53 +0000 (UTC) Received: by mail-ye0-f197.google.com with SMTP id q7sf1526973yen.0 for ; Thu, 22 Aug 2013 07:14:53 -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=Ky37eWvWTNz1+qrPzUNjBx2o+MJmSzFhb80eChEcwxM=; b=TC/vW+ut3vr1RetVCmNdiol8Y8iTe7Uz/CfFn61IVWVuD+kqhvYRy9F96mHQZcZLz4 yERVTqkqun9525oyb+gYvyNEaltJdMnKaiRLa87jn2YkVDtpXYP+8mYIOTUWtMgSdNSe GCdBcRHSe5aMWxSh72kWH0IbSdzgmSLuzspJlW/wyr2cfYrayKbTnVOhw8CIcpTpYxDy 9NKrhE/mFUXCziOkgu/HEPYKc9+5y6iuL0SWljJ4VJjbecKzYabboL1L4Q3LoHZx9KPH tv6sTqxsope7SsFFkTfip7Gsd+pXfcaZ2tdSoPhiyqpjsgklzhRtPaUZC789icIGu/rT BmKA== 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=Ky37eWvWTNz1+qrPzUNjBx2o+MJmSzFhb80eChEcwxM=; b=YY5gXrdwyOWA0h4bH29AxSlxKoCTxZG23ErKaE/xQafDn1VArANd9AG7bo3GUbiGHB qVA9BOtoQAMiAUbcAr2PuauNGzAeJpoOJ9sJSCjhLhA24AGx+B5tL2E5hdH0upmr8BXO xvkGW3NB5JA6dUF+EhevMlx7wV4gjlM0T2jfDsqaj/mdlTv9yayhpRIOiZ3d5epcmgk4 CRSAkmFAwjbzhbzPjftpmiCRJYXa+1xxvgPBl/aMLlQgBou5YhDT2DhkujUmeLJrl4Ue Jr+N1Z8Hq+pcR9eQa3b5PoUuSRWdenJsvaz/pSsl1x9OyWSt4JQ2yIEl9ozflOx12VAE /Ctg== X-Received: by 10.224.137.68 with SMTP id v4mr13053577qat.1.1377180893480; Thu, 22 Aug 2013 07:14:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.74.198 with SMTP id w6ls1189047qev.9.gmail; Thu, 22 Aug 2013 07:14:53 -0700 (PDT) X-Received: by 10.58.237.105 with SMTP id vb9mr11706317vec.2.1377180893375; Thu, 22 Aug 2013 07:14:53 -0700 (PDT) Received: from mail-vc0-x233.google.com (mail-vc0-x233.google.com [2607:f8b0:400c:c03::233]) by mx.google.com with ESMTPS id de6si4005968vcb.109.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:53 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::233 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:c03::233; Received: by mail-vc0-f179.google.com with SMTP id ht10so1090788vcb.24 for ; Thu, 22 Aug 2013 07:14:53 -0700 (PDT) X-Gm-Message-State: ALoCoQlEEa81tQRn01dkHbvrJLP3J4NGW0sLS5nHgSaJpngRuVPiK/Ub5B2gL1qq45Y4cJYo34RJ X-Received: by 10.220.10.194 with SMTP id q2mr11606252vcq.2.1377180893281; Thu, 22 Aug 2013 07:14:53 -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 u4csp33223vcz; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) X-Received: by 10.205.14.197 with SMTP id pr5mr7047181bkb.25.1377180892690; Thu, 22 Aug 2013 07:14:52 -0700 (PDT) Received: from mail-bk0-x232.google.com (mail-bk0-x232.google.com [2a00:1450:4008:c01::232]) by mx.google.com with ESMTPS id ox8si2302147bkb.238.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: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::232 as permitted sender) client-ip=2a00:1450:4008:c01::232; Received: by mail-bk0-f50.google.com with SMTP id mz11so700419bkb.23 for ; Thu, 22 Aug 2013 07:14:51 -0700 (PDT) X-Received: by 10.204.234.5 with SMTP id ka5mr4948002bkb.5.1377180891387; Thu, 22 Aug 2013 07:14:51 -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:50 -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 10/12] perf, persistent: Implement reference counter for events Date: Thu, 22 Aug 2013 16:13:25 +0200 Message-Id: <1377180807-12758-11-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:c03::233 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 We need this later for proper event removal. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- kernel/events/persistent.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/kernel/events/persistent.c b/kernel/events/persistent.c index f23270b..70446ae 100644 --- a/kernel/events/persistent.c +++ b/kernel/events/persistent.c @@ -9,6 +9,7 @@ #define CPU_BUFFER_NR_PAGES ((512 * 1024) / PAGE_SIZE) struct pevent { + atomic_t refcount; struct perf_pmu_events_attr sysfs; char *name; int id; @@ -130,6 +131,7 @@ static int persistent_event_open(int cpu, struct pevent *pevent, if (ret) goto fail; + atomic_inc(&pevent->refcount); atomic_inc(&event->mmap_count); /* All workie, enable event now */ @@ -144,8 +146,11 @@ static int persistent_event_open(int cpu, struct pevent *pevent, static void persistent_event_close(int cpu, struct pevent *pevent) { struct perf_event *event = pevent_del(pevent, cpu); - if (event) + if (event) { + /* Safe, the caller holds &pevent->refcount too. */ + atomic_dec(&pevent->refcount); persistent_event_release(event); + } } static int pevent_sysfs_register(struct pevent *event); @@ -162,6 +167,8 @@ persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) if (!pevent) return -ENOMEM; + atomic_set(&pevent->refcount, 1); + ret = get_event_id(pevent); if (ret < 0) goto fail; @@ -187,21 +194,21 @@ persistent_open(char *name, struct perf_event_attr *attr, int nr_pages) } ret = pevent_sysfs_register(pevent); - if (ret) - goto fail; - - return 0; + if (!ret) + goto out; fail: for_each_possible_cpu(cpu) persistent_event_close(cpu, pevent); - if (pevent->id) - put_event_id(pevent->id); - kfree(pevent->name); - kfree(pevent); - pr_err("%s: Error adding persistent event: %d\n", __func__, ret); +out: + if (atomic_dec_and_test(&pevent->refcount)) { + if (pevent->id) + put_event_id(pevent->id); + kfree(pevent->name); + kfree(pevent); + } return ret; }