From: kan.liang@intel.com
To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com,
linux-kernel@vger.kernel.org
Cc: jolsa@kernel.org, wangnan0@huawei.com, hekuang@huawei.com,
namhyung@kernel.org, alexander.shishkin@linux.intel.com,
adrian.hunter@intel.com, ak@linux.intel.com,
Kan Liang <kan.liang@intel.com>
Subject: [PATCH 03/10] perf tool: new iterfaces to read event from ring buffer
Date: Tue, 10 Oct 2017 10:20:16 -0700 [thread overview]
Message-ID: <1507656023-177125-4-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1507656023-177125-1-git-send-email-kan.liang@intel.com>
From: Kan Liang <kan.liang@intel.com>
The perf_evlist__mmap_read only support forward mode. It needs a common
function to support both forward and backward mode.
The perf_evlist__mmap_read_backward is buggy.
Introduce a new mmap read interface to support both forward and backward
mode. It can read event one by one from the specific range of ring
buffer.
The standard process to mmap__read event would be as below.
perf_mmap__read_init
while (event = perf_mmap__read_event) {
//process the event
perf_mmap__consume
}
perf_mmap__read_done
The following patches will use it to replace the old interfaces.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/util/evlist.c | 41 +++++++++++++++++++++++++++++++++++++++++
tools/perf/util/evlist.h | 2 ++
2 files changed, 43 insertions(+)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7d23cf5..b36211e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -897,6 +897,47 @@ perf_mmap__read(struct perf_mmap *md, bool check_messup, u64 start,
return event;
}
+/*
+ * Read the first event in the specified range of the ring buffer.
+ * Used by most of the perf tools and tests
+ */
+union perf_event *
+perf_mmap__read_event(struct perf_mmap_read *read)
+{
+ struct perf_mmap *md = read->md;
+ union perf_event *event;
+
+ /*
+ * Check if event was unmapped due to a POLLHUP/POLLERR.
+ */
+ if (!refcount_read(&md->refcnt))
+ return NULL;
+
+ /* In backward, the ringbuffer is already paused. */
+ if (!read->backward) {
+ read->end = perf_mmap__read_head(md);
+ if (!read->end)
+ return NULL;
+ }
+
+ event = perf_mmap__read(md, !read->backward && read->overwrite,
+ read->start, read->end, &md->prev);
+ read->start = md->prev;
+ return event;
+}
+
+/*
+ * Mandatory for backward
+ * The direction of backward mmap__read_event is from head to tail.
+ * The last mmap__read_event will set tail to md->prev.
+ * Need to correct the md->prev.
+ */
+void
+perf_mmap__read_done(struct perf_mmap_read *read)
+{
+ read->md->prev = read->head;
+}
+
union perf_event *perf_mmap__read_forward(struct perf_mmap *md, bool check_messup)
{
u64 head;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 1ce4857..53baf26 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -207,6 +207,8 @@ int perf_mmap__read_init(struct perf_mmap *md, struct perf_mmap_read *read,
bool overwrite, bool backward);
int perf_mmap__read_to_file(struct perf_mmap_read *read,
struct perf_data_file *file);
+union perf_event *perf_mmap__read_event(struct perf_mmap_read *read);
+void perf_mmap__read_done(struct perf_mmap_read *read);
int perf_evlist__open(struct perf_evlist *evlist);
void perf_evlist__close(struct perf_evlist *evlist);
--
2.5.5
next prev parent reply other threads:[~2017-10-10 17:20 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 17:20 [PATCH 00/10] new mmap_read interfaces for " kan.liang
2017-10-10 17:20 ` [PATCH 01/10] perf record: new interfaces to read ring buffer to file kan.liang
2017-10-10 18:24 ` Arnaldo Carvalho de Melo
2017-10-10 18:30 ` Arnaldo Carvalho de Melo
2017-10-11 4:12 ` Liang, Kan
2017-10-11 14:45 ` Arnaldo Carvalho de Melo
2017-10-11 15:16 ` Liang, Kan
2017-10-10 17:20 ` [PATCH 02/10] perf tool: fix: Don't discard prev in backward mode kan.liang
2017-10-10 18:14 ` Arnaldo Carvalho de Melo
2017-10-10 18:18 ` Liang, Kan
2017-10-13 12:55 ` Liang, Kan
2017-10-13 13:13 ` Arnaldo Carvalho de Melo
2017-10-13 13:14 ` Liang, Kan
2017-10-10 18:23 ` Wangnan (F)
2017-10-10 18:50 ` Wangnan (F)
2017-10-10 19:50 ` Liang, Kan
2017-10-10 20:18 ` Wangnan (F)
2017-10-11 2:12 ` Liang, Kan
2017-10-11 14:57 ` Liang, Kan
2017-10-12 1:11 ` Wangnan (F)
2017-10-12 12:49 ` Liang, Kan
2017-10-12 14:43 ` Wangnan (F)
2017-10-10 19:36 ` Liang, Kan
2017-10-10 17:20 ` kan.liang [this message]
2017-10-10 18:15 ` [PATCH 03/10] perf tool: new iterfaces to read event from ring buffer Arnaldo Carvalho de Melo
2017-10-10 18:28 ` Liang, Kan
2017-10-10 18:34 ` Arnaldo Carvalho de Melo
2017-10-10 18:36 ` Arnaldo Carvalho de Melo
2017-10-10 19:00 ` Arnaldo Carvalho de Melo
2017-10-10 19:10 ` Wangnan (F)
2017-10-10 19:17 ` Arnaldo Carvalho de Melo
2017-10-10 19:22 ` Wangnan (F)
2017-10-10 19:55 ` Liang, Kan
2017-10-10 19:59 ` Wangnan (F)
2017-10-10 17:20 ` [PATCH 04/10] perf tool: perf_mmap__read_init wrapper for evlist kan.liang
2017-10-10 17:20 ` [PATCH 05/10] perf top: apply new mmap_read interfaces kan.liang
2017-10-10 17:20 ` [PATCH 06/10] perf trace: " kan.liang
2017-10-10 17:20 ` [PATCH 07/10] perf kvm: " kan.liang
2017-10-10 17:20 ` [PATCH 08/10] perf python: " kan.liang
2017-10-10 17:20 ` [PATCH 09/10] perf tests: " kan.liang
2017-10-10 17:20 ` [PATCH 10/10] perf tool: remove stale " kan.liang
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=1507656023-177125-4-git-send-email-kan.liang@intel.com \
--to=kan.liang@intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/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
Powered by JetHome