From patchwork Thu Aug 22 14:13:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19409 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C7462248E6 for ; Thu, 22 Aug 2013 14:14:40 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hf12sf1552292vcb.11 for ; Thu, 22 Aug 2013 07:14:40 -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=5gjXr6mMKBqUgn7gqmxhtCiXUk0HN1fjYcJPSQn92m4=; b=q3u/jnbQ4gur1F9a5AfBfztvj1YOys076K7rfO0eW8g7AsOjhZ85QkSXh7OlrACSOc Dn8e5VZtkPgdYQtedaHCaUvvO9ka8/whGLn/0zgKy8ef3MkJZQcEyhPHLTA2mtaEcPuV CDRjtdJ9dBA3Ab3wTDsScvXnCq67t9qOQIlm29y9PFt7c3ptRkpp2tjFE2e0XiSEMH+v RsYzqOqdkFMoldIP7MEDyVnvDZTvbbwHIUhRQ8Rd/+VyQ7n6G3hpMM2EzdJLtoAGw/1d Fk/LIhLJSaiMmTvscPMUGBBiRWm+4WM/xyNromk0+knlxJW5Pm3DjJX8a9W41imQ4AnT I2TA== 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=5gjXr6mMKBqUgn7gqmxhtCiXUk0HN1fjYcJPSQn92m4=; b=Ov7a4hgcb98AxJga0M0dl+qrbcPmLtPbA2gIpZQuGNvx4fX2qc7JNzFEL41B/Hi3EY X7x50M6o1AI20bht2ruK+l7wzjpp87zj9I9hRlh11bxl3kUrbcaNd86o/auH4f7tjXFj IaRgsL2a6UOjYfKNzK8u2bK9PKDWx1+Bv8VsvQ9qWEzyNTbRPhl/RooaApIvp/IZfPn7 w+wf5RX/P0z+OHsALT4RaAN/xLjEJcNy7beyQmtGlHFKJMra3rjbIbDze7zhXwS36Tpa cpt6oTTIOPCz1dhqEiYQIlv9hg6FQQ++Kfv+D1IJoWisSZtCAdEVgG/R0VMJNQng/EUD hi8Q== X-Received: by 10.236.4.69 with SMTP id 45mr4539146yhi.20.1377180880575; Thu, 22 Aug 2013 07:14:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.105.161 with SMTP id gn1ls1158920qeb.27.gmail; Thu, 22 Aug 2013 07:14:40 -0700 (PDT) X-Received: by 10.52.227.6 with SMTP id rw6mr9889058vdc.19.1377180880435; Thu, 22 Aug 2013 07:14:40 -0700 (PDT) Received: from mail-vb0-x22c.google.com (mail-vb0-x22c.google.com [2607:f8b0:400c:c02::22c]) by mx.google.com with ESMTPS id sk7si4000775vdc.155.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:40 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::22c 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:c02::22c; Received: by mail-vb0-f44.google.com with SMTP id e13so1272115vbg.17 for ; Thu, 22 Aug 2013 07:14:40 -0700 (PDT) X-Gm-Message-State: ALoCoQmSC2L7KxzH0oHJMPEbtC2aIbrLWQfJdw5Re8fPkMJ6nSw/Wh0TTJEurs9BX3T7CUX47mjo X-Received: by 10.220.11.7 with SMTP id r7mr11695748vcr.12.1377180880358; Thu, 22 Aug 2013 07:14:40 -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 u4csp33202vcz; Thu, 22 Aug 2013 07:14:39 -0700 (PDT) X-Received: by 10.204.71.133 with SMTP id h5mr10786380bkj.0.1377180878788; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) Received: from mail-bk0-x236.google.com (mail-bk0-x236.google.com [2a00:1450:4008:c01::236]) by mx.google.com with ESMTPS id ri6si2301492bkb.250.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::236 as permitted sender) client-ip=2a00:1450:4008:c01::236; Received: by mail-bk0-f54.google.com with SMTP id mz12so719984bkb.27 for ; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) X-Received: by 10.205.5.6 with SMTP id oe6mr2278073bkb.36.1377180877789; Thu, 22 Aug 2013 07:14:37 -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:36 -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 02/12] perf, mmap: Factor out try_get_event()/put_event() Date: Thu, 22 Aug 2013 16:13:17 +0200 Message-Id: <1377180807-12758-3-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:c02::22c 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 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 --- 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 5dcc5fe..c9a5d4c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3242,13 +3242,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); /* @@ -3781,7 +3778,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. @@ -7445,7 +7442,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 ca65997..96a07d2 100644 --- a/kernel/events/internal.h +++ b/kernel/events/internal.h @@ -178,4 +178,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 */