All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <linux-kernel@vger.kernel.org>, <kan.liang@intel.com>,
	<acme@kernel.org>, <jolsa@redhat.com>, <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Subject: [PATCH v2 7/8] perf tools: Don't discard prev in backward mode
Date: Sun, 3 Dec 2017 02:00:43 +0000	[thread overview]
Message-ID: <20171203020044.81680-8-wangnan0@huawei.com> (raw)
In-Reply-To: <20171203020044.81680-1-wangnan0@huawei.com>

Perf record can switch output. The new output should only store the
data after switching. However, in overwrite backward mode, the new
output still have the data from old output. That also brings extra
overhead.

At the end of mmap_read, the position of processed ring buffer is
saved in md->prev. Next mmap_read should be end in md->prev if it is
not overwriten. That avoids to process duplicate data.
However, the md->prev is discarded. So next mmap_read has to process
whole valid ring buffer, which probably include the old processed
data.

Avoid calling backward_rb_find_range() when md->prev is still
available.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Kan Liang <kan.liang@intel.com>
---
 tools/perf/util/mmap.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 3f262e7..5f8cb15 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -267,18 +267,6 @@ static int backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64
 	return -1;
 }
 
-static int rb_find_range(void *data, int mask, u64 head, u64 old,
-			 u64 *start, u64 *end, bool backward)
-{
-	if (!backward) {
-		*start = old;
-		*end = head;
-		return 0;
-	}
-
-	return backward_rb_find_range(data, mask, head, start, end);
-}
-
 int perf_mmap__push(struct perf_mmap *md, bool backward,
 		    void *to, int push(void *to, void *buf, size_t size))
 {
@@ -290,19 +278,28 @@ int perf_mmap__push(struct perf_mmap *md, bool backward,
 	void *buf;
 	int rc = 0;
 
-	if (rb_find_range(data, md->mask, head, old, &start, &end, backward))
-		return -1;
+	start = backward ? head : old;
+	end = backward ? old : head;
 
 	if (start == end)
 		return 0;
 
 	size = end - start;
 	if (size > (unsigned long)(md->mask) + 1) {
-		WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
+		if (!backward) {
+			WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
 
-		md->prev = head;
-		perf_mmap__consume(md, backward);
-		return 0;
+			md->prev = head;
+			perf_mmap__consume(md, backward);
+			return 0;
+		}
+
+		/*
+		 * Backward ring buffer is full. We still have a chance to read
+		 * most of data from it.
+		 */
+		if (backward_rb_find_range(data, md->mask, head, &start, &end))
+			return -1;
 	}
 
 	if ((start & md->mask) + size != (end & md->mask)) {
-- 
2.10.1

  parent reply	other threads:[~2017-12-03  2:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-03  2:00 [PATCH v2 0/8] perf tools: perf tools: Clarify overwrite and backward, bugfix Wang Nan
2017-12-03  2:00 ` [PATCH v2 1/8] perf tools: Remove 'overwrite' parameter from perf_evlist__mmap Wang Nan
2017-12-06 16:41   ` [tip:perf/core] perf evlist: " tip-bot for Wang Nan
2017-12-03  2:00 ` [PATCH v2 2/8] perf tools: Remove 'overwrite' parameter from perf_evlist__mmap_ex Wang Nan
2017-12-06 16:41   ` [tip:perf/core] perf evlist: " tip-bot for Wang Nan
2017-12-03  2:00 ` [PATCH v2 3/8] perf tools: Remove evlist->overwrite Wang Nan
2017-12-06 16:42   ` [tip:perf/core] perf evlist: " tip-bot for Wang Nan
2017-12-03  2:00 ` [PATCH v2 4/8] perf tools: Remove overwrite from arguments list of perf_mmap__push Wang Nan
2017-12-06 16:42   ` [tip:perf/core] perf mmap: " tip-bot for Wang Nan
2017-12-03  2:00 ` [PATCH v2 5/8] perf tools: Remove overwrite and check_messup from mmap read Wang Nan
2017-12-06 16:42   ` [tip:perf/core] perf mmap: " tip-bot for Wang Nan
2017-12-03  2:00 ` [PATCH v2 6/8] perf mmap: Fix perf backward recording Wang Nan
2017-12-04  5:37   ` Namhyung Kim
2017-12-04 15:44     ` Arnaldo Carvalho de Melo
2017-12-03  2:00 ` Wang Nan [this message]
2017-12-03  2:00 ` [PATCH v2 8/8] perf tools: Replace 'backward' to 'overwrite' in evlist, mmap and record Wang Nan
2017-12-04  5:39 ` [PATCH v2 0/8] perf tools: perf tools: Clarify overwrite and backward, bugfix Namhyung Kim

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=20171203020044.81680-8-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.