From patchwork Thu Aug 22 14:13:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19408 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 91B66248E6 for ; Thu, 22 Aug 2013 14:14:38 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id 1sf1688955qee.6 for ; Thu, 22 Aug 2013 07:14:38 -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=bz3pKJmuR9p8fKuO2uszIsl58g9ZcKyztQ99yCUsbe0=; b=NxFefCiFFGsVQg4u5z3BYyBGECkl1usvehmE8Ntg1MYRZGld+mmljHRN6LSy47Wcsl tZsELvsl4vPG+S0GWMYfLQbbA/YC41uKSaosfDnf6OCEWfGFMITo1peBtusuaM6RfXnk MB+uGYks4vTeWeah8P7wGIT5zLArC/FYKhC7fJZVAxiWWiNipeJkflyY5QT4XWO2QM43 dWnyd4u05KSrjXX2q5rL3pxvnJD6HTfi04iBF+uTQbaOjUSkUxQEUkM0wdF6h1R8Ax6c VxkYRXSiJiiThpLjLhJ3y+EIDA7SjPTq4kg1P9gZWvUd51gB3Rq0sYnGq/BjcvuVT7AS uHtA== 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=bz3pKJmuR9p8fKuO2uszIsl58g9ZcKyztQ99yCUsbe0=; b=Xy+/LZ0pnTGS+FSGlECpz7mWlIkoIUkn/tHy+g+lBQMS/uVsYfCB0/XWi1PvPR0c7M OXg4/e6iigLhWAGU++Mmwjvjv6CELKRVqgfG9MNlCENavxN3J2OaI5qH1EAs5asy4pY+ gykZiXJIjhelgiFaPkADvgtUsBTAlaiSPnsCmPMMNIK5XNde6n0MrZtOX5h6rGhvmcJ6 JmnfcSt91EnqRc9BECp/Fpr4HvMviMnoqE2u7dGseH+2jioFPO+csKTuo/Odk9m4NqQG femmtwWcdM9WqnGtOLvkRIbBPSH/5OFikSl9MbToQltP+BcTr6dPVtWqwqbE26tGD9V1 MLYw== X-Received: by 10.224.173.4 with SMTP id n4mr13069755qaz.3.1377180878393; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.97.199 with SMTP id ec7ls1161216qeb.26.gmail; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) X-Received: by 10.52.30.48 with SMTP id p16mr9837603vdh.25.1377180878310; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) Received: from mail-vb0-x231.google.com (mail-vb0-x231.google.com [2607:f8b0:400c:c02::231]) by mx.google.com with ESMTPS id tg9si4005851vcb.107.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: neutral (google.com: 2607:f8b0:400c:c02::231 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::231; Received: by mail-vb0-f49.google.com with SMTP id w16so1254770vbb.8 for ; Thu, 22 Aug 2013 07:14:38 -0700 (PDT) X-Gm-Message-State: ALoCoQnZU9HNTOLoERViuJUjDleIWMqZGPZqvubbLF5JhGCOitftwCFPL5TVSxSyXvG77fmQF1tV X-Received: by 10.220.80.78 with SMTP id s14mr118081vck.28.1377180878208; Thu, 22 Aug 2013 07:14:38 -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 u4csp33200vcz; Thu, 22 Aug 2013 07:14:37 -0700 (PDT) X-Received: by 10.205.26.67 with SMTP id rl3mr301073bkb.41.1377180877064; Thu, 22 Aug 2013 07:14:37 -0700 (PDT) Received: from mail-bk0-x22f.google.com (mail-bk0-x22f.google.com [2a00:1450:4008:c01::22f]) by mx.google.com with ESMTPS id qv10si2301704bkb.242.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::22f as permitted sender) client-ip=2a00:1450:4008:c01::22f; Received: by mail-bk0-f47.google.com with SMTP id mx12so699766bkb.6 for ; Thu, 22 Aug 2013 07:14:36 -0700 (PDT) X-Received: by 10.204.189.144 with SMTP id de16mr2590154bkb.26.1377180875958; Thu, 22 Aug 2013 07:14:35 -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:35 -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 01/12] perf, mmap: Factor out ring_buffer_detach_all() Date: Thu, 22 Aug 2013 16:13:16 +0200 Message-Id: <1377180807-12758-2-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::231 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 Factor out a function to detach all events from a ringbuffer. No functional changes. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- kernel/events/core.c | 82 ++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 928fae7c..5dcc5fe 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3775,6 +3775,49 @@ static void ring_buffer_detach(struct perf_event *event, struct ring_buffer *rb) spin_unlock_irqrestore(&rb->event_lock, flags); } +static void ring_buffer_detach_all(struct ring_buffer *rb) +{ + struct perf_event *event; +again: + rcu_read_lock(); + list_for_each_entry_rcu(event, &rb->event_list, rb_entry) { + if (!atomic_long_inc_not_zero(&event->refcount)) { + /* + * This event is en-route to free_event() which will + * detach it and remove it from the list. + */ + continue; + } + rcu_read_unlock(); + + mutex_lock(&event->mmap_mutex); + /* + * Check we didn't race with perf_event_set_output() which can + * swizzle the rb from under us while we were waiting to + * acquire mmap_mutex. + * + * If we find a different rb; ignore this event, a next + * iteration will no longer find it on the list. We have to + * still restart the iteration to make sure we're not now + * iterating the wrong list. + */ + if (event->rb == rb) { + rcu_assign_pointer(event->rb, NULL); + ring_buffer_detach(event, rb); + ring_buffer_put(rb); /* can't be last, we still have one */ + } + mutex_unlock(&event->mmap_mutex); + put_event(event); + + /* + * Restart the iteration; either we're on the wrong list or + * destroyed its integrity by doing a deletion. + */ + goto again; + } + rcu_read_unlock(); +} + static void ring_buffer_wakeup(struct perf_event *event) { struct ring_buffer *rb; @@ -3867,44 +3910,7 @@ static void perf_mmap_close(struct vm_area_struct *vma) * into the now unreachable buffer. Somewhat complicated by the * fact that rb::event_lock otherwise nests inside mmap_mutex. */ -again: - rcu_read_lock(); - list_for_each_entry_rcu(event, &rb->event_list, rb_entry) { - if (!atomic_long_inc_not_zero(&event->refcount)) { - /* - * This event is en-route to free_event() which will - * detach it and remove it from the list. - */ - continue; - } - rcu_read_unlock(); - - mutex_lock(&event->mmap_mutex); - /* - * Check we didn't race with perf_event_set_output() which can - * swizzle the rb from under us while we were waiting to - * acquire mmap_mutex. - * - * If we find a different rb; ignore this event, a next - * iteration will no longer find it on the list. We have to - * still restart the iteration to make sure we're not now - * iterating the wrong list. - */ - if (event->rb == rb) { - rcu_assign_pointer(event->rb, NULL); - ring_buffer_detach(event, rb); - ring_buffer_put(rb); /* can't be last, we still have one */ - } - mutex_unlock(&event->mmap_mutex); - put_event(event); - - /* - * Restart the iteration; either we're on the wrong list or - * destroyed its integrity by doing a deletion. - */ - goto again; - } - rcu_read_unlock(); + ring_buffer_detach_all(rb); /* * It could be there's still a few 0-ref events on the list; they'll