From patchwork Mon Apr 7 15:04:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 27913 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E571C20490 for ; Mon, 7 Apr 2014 15:13:00 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id x10sf23314616pdj.10 for ; Mon, 07 Apr 2014 08:13:00 -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=BIiwXjWGajhJd9p6jXWwofJ6McKEL6a87cSCCHksjPw=; b=NiSksn1W9rru5FEd6dXh4AdXq3FBFMQy11sWP6rkiFhrNZvLfiyMZ0CE+RMx54lnmw j7C0lxwvK9Pzswc5ZkHCV9iWbLKYwhcZBtANNRHbHHd1nftWQnPEWBafr9YTj7SGo8RA 3jH6lg4+LNm/C8dUiB4H7H2+6bhj+nPGqd9QUmmcByN0MkKPSf4sohFZlzQrafmZbz// okatC8x9t4L/TCuRqetQEbgXJOtzkIjtpdvpSsEZvf+3rIOiKGK0879JZJnypdxX/9dc jXf8YcJ8hmirf3JzcefXM6YUCzLJxJ4hEksaXMJXdqr0NZBaV/WxgXCRVv2j8oujnnv+ n2Ug== X-Gm-Message-State: ALoCoQnhLni7QUXK2FbX2Cm9qy2WJtiTz9V0yr7sE7rFdWdKsdAXkt/y2/dE3Y/QduVj29ORg2KA X-Received: by 10.66.222.105 with SMTP id ql9mr15180250pac.9.1396883580164; Mon, 07 Apr 2014 08:13:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.202 with SMTP id e68ls1227335qgf.12.gmail; Mon, 07 Apr 2014 08:13:00 -0700 (PDT) X-Received: by 10.220.98.143 with SMTP id q15mr43374vcn.38.1396883580060; Mon, 07 Apr 2014 08:13:00 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id x7si2171245vel.162.2014.04.07.08.13.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:13:00 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 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.178; Received: by mail-vc0-f178.google.com with SMTP id im17so5242935vcb.23 for ; Mon, 07 Apr 2014 08:13:00 -0700 (PDT) X-Received: by 10.52.138.112 with SMTP id qp16mr529657vdb.40.1396883579962; Mon, 07 Apr 2014 08:12:59 -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 v8csp170257vcv; Mon, 7 Apr 2014 08:12:59 -0700 (PDT) X-Received: by 10.68.197.66 with SMTP id is2mr31596841pbc.96.1396883578920; Mon, 07 Apr 2014 08:12:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si8504037pad.227.2014.04.07.08.12.58; Mon, 07 Apr 2014 08:12:58 -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 S1755580AbaDGPMu (ORCPT + 27 others); Mon, 7 Apr 2014 11:12:50 -0400 Received: from mail-ee0-f43.google.com ([74.125.83.43]:41387 "EHLO mail-ee0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754713AbaDGPE5 (ORCPT ); Mon, 7 Apr 2014 11:04:57 -0400 Received: by mail-ee0-f43.google.com with SMTP id e53so742896eek.16 for ; Mon, 07 Apr 2014 08:04:56 -0700 (PDT) X-Received: by 10.14.87.7 with SMTP id x7mr3419425eee.44.1396883096333; Mon, 07 Apr 2014 08:04:56 -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.53 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:04:55 -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 01/16] perf, mmap: Factor out ring_buffer_detach_all() Date: Mon, 7 Apr 2014 17:04:23 +0200 Message-Id: <1396883078-25320-2-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.178 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 Factor out a function to detach all events from a ringbuffer. No functional changes. Signed-off-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Jean Pihet --- 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 661951a..8867236 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3878,6 +3878,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; @@ -3970,44 +4013,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