From: Jean Pihet <jean.pihet@linaro.org>
To: Borislav Petkov <bp@alien8.de>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Arnaldo Carvalho de Melo <acme@infradead.org>,
Jiri Olsa <jolsa@redhat.com>,
linux-kernel@vger.kernel.org, Robert Richter <rric@kernel.org>
Cc: Robert Richter <robert.richter@linaro.org>,
Jean Pihet <jean.pihet@linaro.org>
Subject: [PATCH 01/16] perf, mmap: Factor out ring_buffer_detach_all()
Date: Mon, 7 Apr 2014 17:04:23 +0200 [thread overview]
Message-ID: <1396883078-25320-2-git-send-email-jean.pihet@linaro.org> (raw)
In-Reply-To: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org>
From: Robert Richter <robert.richter@linaro.org>
Factor out a function to detach all events from a ringbuffer. No
functional changes.
Signed-off-by: Robert Richter <robert.richter@linaro.org>
Signed-off-by: Robert Richter <rric@kernel.org>
Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
---
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
--
1.7.11.7
next prev parent reply other threads:[~2014-04-07 15:12 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-07 15:04 [PATCH v4 00/16] perf, persistent: Add persistent events Jean Pihet
2014-04-07 15:04 ` Jean Pihet [this message]
2014-04-07 15:04 ` [PATCH 02/16] perf, mmap: Factor out try_get_event()/put_event() Jean Pihet
2014-04-07 15:04 ` [PATCH 03/16] perf, mmap: Factor out perf_alloc/free_rb() Jean Pihet
2014-04-22 14:25 ` Peter Zijlstra
2014-04-07 15:04 ` [PATCH 04/16] perf, mmap: Factor out perf_get_fd() Jean Pihet
2014-04-22 14:27 ` Peter Zijlstra
2014-04-25 13:54 ` Robert Richter
2014-04-25 14:43 ` Peter Zijlstra
2014-04-25 14:52 ` Peter Zijlstra
2014-04-29 15:34 ` Robert Richter
2014-04-07 15:04 ` [PATCH 05/16] perf: Add persistent events Jean Pihet
2014-04-07 15:04 ` [PATCH 06/16] mce, x86: Enable " Jean Pihet
2014-04-07 15:04 ` [PATCH 07/16] perf, persistent: Implementing a persistent pmu Jean Pihet
2014-04-07 15:04 ` [PATCH 08/16] perf, persistent: Exposing persistent events using sysfs Jean Pihet
2014-04-07 15:04 ` [PATCH 09/16] perf, persistent: Use unique event ids Jean Pihet
2014-04-07 15:04 ` [PATCH 10/16] perf, persistent: Implement reference counter for events Jean Pihet
2014-04-07 15:04 ` [PATCH 11/16] perf, persistent: Dynamically resize list of sysfs entries Jean Pihet
2014-04-07 15:04 ` [PATCH 12/16] perf, persistent: ioctl functions to control persistency Jean Pihet
2014-04-07 15:04 ` [PATCH 13/16] perf tools: Rename flex conditions to avoid name conflicts Jean Pihet
2014-04-07 15:04 ` [PATCH 14/16] perf tools: Modify event parser to update event attribute by index Jean Pihet
2014-04-07 15:04 ` [PATCH 15/16] perf tools: Add attr<num> syntax to event parser Jean Pihet
2014-04-07 15:04 ` [PATCH 16/16] perf tools: Retry mapping buffers readonly on EACCES Jean Pihet
2014-04-17 12:44 ` [PATCH v4 00/16] perf, persistent: Add persistent events Jean Pihet
2014-04-17 12:50 ` Borislav Petkov
2014-04-17 13:17 ` Jean Pihet
2014-04-17 13:21 ` Borislav Petkov
2014-04-22 8:20 ` Jean Pihet
2014-04-22 10:07 ` Jean Pihet
2014-04-22 10:20 ` Borislav Petkov
2014-05-06 12:39 ` Robert Richter
2014-05-06 18:50 ` Borislav Petkov
2014-05-06 18:53 ` Borislav Petkov
2014-05-07 16:44 ` Robert Richter
2014-05-08 18:23 ` Borislav Petkov
2014-05-09 9:17 ` Robert Richter
2014-05-06 18:58 ` Borislav Petkov
2014-05-07 17:01 ` Robert Richter
2014-05-08 18:36 ` Borislav Petkov
2014-05-09 8:52 ` Robert Richter
2014-05-09 10:17 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1396883078-25320-2-git-send-email-jean.pihet@linaro.org \
--to=jean.pihet@linaro.org \
--cc=acme@infradead.org \
--cc=bp@alien8.de \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=robert.richter@linaro.org \
--cc=rric@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®