From patchwork Mon Apr 7 15:04:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 27898 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1CC2320490 for ; Mon, 7 Apr 2014 15:05:21 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id i17sf20486509qcy.7 for ; Mon, 07 Apr 2014 08:05:21 -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=Ngl8arhhZT0U7RzPk+CqevAxbR0m92kbx19ehyeU56M=; b=X5YbHhMLJV4nGq6KSoQb8mhEjGaUcMKqekPBaqGgg2Pm+cxspC4tw9iDAYIH4DY4/6 g1JsgKSFCe4F3vkSNn369syTvovZpMaBf4vI73i0BXZjTcPnMzxuUdAl7gB527prmUPX /ycZFC+Gb73fs+TY/gy0Hew2917dahyDd3qPpCjy0ypHvuHEBFDYPNLiTvHLdyNCdSCN aAr8ueAennEAREJ8qwkbPpOWX8WIwjgWyWrqWvxv/judU3cUonJ0Ao0pHBhf5qQYBqL4 rHkX6jE1gx/11iXPkKSBGFB5I1YnhsvvNs2eRKibu3N3r2mXRSQzyvnvnC4Bm0Czqhv0 3SrA== X-Gm-Message-State: ALoCoQn2CrvcWwJzOTz5HJGaWJ5J3jVjFqlO9Bp8dFM5MHbcgyzmfht6KneHej9kr3Y2T4mxxDuy X-Received: by 10.52.29.171 with SMTP id l11mr14429812vdh.0.1396883121711; Mon, 07 Apr 2014 08:05:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.183 with SMTP id 52ls1800150qgv.38.gmail; Mon, 07 Apr 2014 08:05:21 -0700 (PDT) X-Received: by 10.220.59.65 with SMTP id k1mr3137953vch.22.1396883121630; Mon, 07 Apr 2014 08:05:21 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id ls10si2164675vec.172.2014.04.07.08.05.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:05:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so5534926vcb.1 for ; Mon, 07 Apr 2014 08:05:21 -0700 (PDT) X-Received: by 10.220.159.4 with SMTP id h4mr24620737vcx.1.1396883121548; Mon, 07 Apr 2014 08:05:21 -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 v8csp169588vcv; Mon, 7 Apr 2014 08:05:20 -0700 (PDT) X-Received: by 10.66.180.200 with SMTP id dq8mr8377732pac.104.1396883120612; Mon, 07 Apr 2014 08:05:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yl4si8497382pbc.126.2014.04.07.08.05.19; Mon, 07 Apr 2014 08:05:20 -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 S1755277AbaDGPFH (ORCPT + 27 others); Mon, 7 Apr 2014 11:05:07 -0400 Received: from mail-ee0-f52.google.com ([74.125.83.52]:51032 "EHLO mail-ee0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752575AbaDGPE7 (ORCPT ); Mon, 7 Apr 2014 11:04:59 -0400 Received: by mail-ee0-f52.google.com with SMTP id e49so707423eek.25 for ; Mon, 07 Apr 2014 08:04:58 -0700 (PDT) X-Received: by 10.15.68.136 with SMTP id w8mr3418119eex.5.1396883098437; Mon, 07 Apr 2014 08:04:58 -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.04.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:04:57 -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 02/16] perf, mmap: Factor out try_get_event()/put_event() Date: Mon, 7 Apr 2014 17:04:24 +0200 Message-Id: <1396883078-25320-3-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.220.170 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 Implement try_get_event() as counter part to put_event(). Put both in internal.h to make it available to other perf files. Signed-off-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Jean Pihet --- kernel/events/core.c | 9 +++------ kernel/events/internal.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 8867236..5eaba42 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3311,13 +3311,10 @@ EXPORT_SYMBOL_GPL(perf_event_release_kernel); /* * Called when the last reference to the file is gone. */ -static void put_event(struct perf_event *event) +void __put_event(struct perf_event *event) { struct task_struct *owner; - if (!atomic_long_dec_and_test(&event->refcount)) - return; - rcu_read_lock(); owner = ACCESS_ONCE(event->owner); /* @@ -3884,7 +3881,7 @@ static void ring_buffer_detach_all(struct ring_buffer *rb) again: rcu_read_lock(); list_for_each_entry_rcu(event, &rb->event_list, rb_entry) { - if (!atomic_long_inc_not_zero(&event->refcount)) { + if (!try_get_event(event)) { /* * This event is en-route to free_event() which will * detach it and remove it from the list. @@ -7606,7 +7603,7 @@ inherit_event(struct perf_event *parent_event, if (IS_ERR(child_event)) return child_event; - if (!atomic_long_inc_not_zero(&parent_event->refcount)) { + if (!try_get_event(parent_event)) { free_event(child_event); return NULL; } diff --git a/kernel/events/internal.h b/kernel/events/internal.h index 569b2187..3bd89d4 100644 --- a/kernel/events/internal.h +++ b/kernel/events/internal.h @@ -195,4 +195,16 @@ static inline bool arch_perf_have_user_stack_dump(void) #define perf_user_stack_pointer(regs) 0 #endif /* CONFIG_HAVE_PERF_USER_STACK_DUMP */ +static inline bool try_get_event(struct perf_event *event) +{ + return atomic_long_inc_not_zero(&event->refcount) != 0; +} +extern void __put_event(struct perf_event *event); +static inline void put_event(struct perf_event *event) +{ + if (!atomic_long_dec_and_test(&event->refcount)) + return; + __put_event(event); +} + #endif /* _KERNEL_EVENTS_INTERNAL_H */