public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Kan Liang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, namhyung@kernel.org, mingo@kernel.org,
	ak@linux.intel.com, tglx@linutronix.de, jolsa@kernel.org,
	linux-kernel@vger.kernel.org, hpa@zytor.com, kan.liang@intel.com,
	acme@redhat.com, wangnan0@huawei.com, yao.jin@linux.intel.com
Subject: [tip:perf/urgent] perf top: Switch default mode to overwrite mode
Date: Tue, 13 Feb 2018 04:10:54 -0800	[thread overview]
Message-ID: <tip-73508fab8d06316e4dbd6cccfc9fcb21dde677b7@git.kernel.org> (raw)
In-Reply-To: <1516310792-208685-17-git-send-email-kan.liang@intel.com>

Commit-ID:  73508fab8d06316e4dbd6cccfc9fcb21dde677b7
Gitweb:     https://git.kernel.org/tip/73508fab8d06316e4dbd6cccfc9fcb21dde677b7
Author:     Kan Liang <kan.liang@intel.com>
AuthorDate: Thu, 18 Jan 2018 13:26:31 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 6 Feb 2018 10:11:51 -0300

perf top: Switch default mode to overwrite mode

perf_top__mmap_read() has a severe performance issue in the Knights
Landing/Mill platform, when monitoring heavy load systems. It costs
several minutes to finish, which is unacceptable.

Currently, 'perf top' uses the non overwrite mode. For non overwrite
mode, it tries to read everything in the ringbuffer and doesn't pause
it. Once there are lots of samples delivered persistently, the
processing time could be very long. Also, the latest samples could be
lost when the ringbuffer is full.

For overwrite mode, it takes a snapshot for the system by pausing the
ringbuffer, which could significantly reduce the processing time.  Also,
the overwrite mode always keep the latest samples.  Considering the real
time requirement for 'perf top', the overwrite mode is more suitable for
it.

Actually, 'perf top' was overwrite mode. It is changed to non overwrite
mode since commit 93fc64f14472 ("perf top: Switch to non overwrite
mode"). It's better to change it back to overwrite mode by default.

For the kernel which doesn't support overwrite mode, it will fall back
to non overwrite mode.

There would be some records lost in overwrite mode because of pausing
the ringbuffer. It has little impact for the accuracy of the snapshot
and can be tolerated.

For overwrite mode, unconditionally wait 100 ms before each snapshot. It
also reduces the overhead caused by pausing ringbuffer, especially on
light load system.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1516310792-208685-17-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-top.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5965306..2b4914f 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -809,15 +809,23 @@ static void perf_event__process_sample(struct perf_tool *tool,
 
 static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 {
+	struct record_opts *opts = &top->record_opts;
+	struct perf_evlist *evlist = top->evlist;
 	struct perf_sample sample;
 	struct perf_evsel *evsel;
+	struct perf_mmap *md;
 	struct perf_session *session = top->session;
 	union perf_event *event;
 	struct machine *machine;
+	u64 end, start;
 	int ret;
 
-	while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
-		ret = perf_evlist__parse_sample(top->evlist, event, &sample);
+	md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx];
+	if (perf_mmap__read_init(md, opts->overwrite, &start, &end) < 0)
+		return;
+
+	while ((event = perf_mmap__read_event(md, opts->overwrite, &start, end)) != NULL) {
+		ret = perf_evlist__parse_sample(evlist, event, &sample);
 		if (ret) {
 			pr_err("Can't parse sample, err = %d\n", ret);
 			goto next_event;
@@ -871,16 +879,28 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 		} else
 			++session->evlist->stats.nr_unknown_events;
 next_event:
-		perf_evlist__mmap_consume(top->evlist, idx);
+		perf_mmap__consume(md, opts->overwrite);
 	}
+
+	perf_mmap__read_done(md);
 }
 
 static void perf_top__mmap_read(struct perf_top *top)
 {
+	bool overwrite = top->record_opts.overwrite;
+	struct perf_evlist *evlist = top->evlist;
 	int i;
 
+	if (overwrite)
+		perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_DATA_PENDING);
+
 	for (i = 0; i < top->evlist->nr_mmaps; i++)
 		perf_top__mmap_read_idx(top, i);
+
+	if (overwrite) {
+		perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_EMPTY);
+		perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
+	}
 }
 
 /*
@@ -979,11 +999,6 @@ static int perf_top__start_counters(struct perf_top *top)
 		goto out_err;
 	}
 
-	if (opts->overwrite) {
-		ui__error("not support overwrite mode yet\n");
-		goto out_err;
-	}
-
 	perf_evlist__config(evlist, opts, &callchain_param);
 
 	evlist__for_each_entry(evlist, counter) {
@@ -1144,7 +1159,7 @@ static int __cmd_top(struct perf_top *top)
 
 		perf_top__mmap_read(top);
 
-		if (hits == top->samples)
+		if (opts->overwrite || (hits == top->samples))
 			ret = perf_evlist__poll(top->evlist, 100);
 
 		if (resize) {
@@ -1238,6 +1253,7 @@ int cmd_top(int argc, const char **argv)
 				.uses_mmap   = true,
 			},
 			.proc_map_timeout    = 500,
+			.overwrite	= 1,
 		},
 		.max_stack	     = sysctl_perf_event_max_stack,
 		.sym_pcnt_filter     = 5,

  reply	other threads:[~2018-02-13 12:21 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18 21:26 [PATCH V5 00/17] perf top overwrite mode kan.liang
2018-01-18 21:26 ` [PATCH V5 01/17] perf evlist: remove stale mmap read for backward kan.liang
2018-02-13 12:04   ` [tip:perf/urgent] perf evlist: Remove " tip-bot for Kan Liang
2018-02-16  9:34   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 02/17] perf mmap: fix: recalculate size for overwrite mode kan.liang
2018-02-01 21:23   ` Arnaldo Carvalho de Melo
2018-02-01 21:55     ` Liang, Kan
2018-02-13 12:04   ` [tip:perf/urgent] perf mmap: Recalculate " tip-bot for Kan Liang
2018-02-16  9:34   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 03/17] perf mmap: cleanup perf_mmap__push() kan.liang
2018-02-13 12:05   ` [tip:perf/urgent] perf mmap: Cleanup perf_mmap__push() tip-bot for Kan Liang
2018-02-16  9:35   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 04/17] perf mmap: introduce perf_mmap__read_init() kan.liang
2018-02-13 12:05   ` [tip:perf/urgent] perf mmap: Introduce perf_mmap__read_init() tip-bot for Kan Liang
2018-02-16  9:35   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 05/17] perf mmap: add new return value logic for perf_mmap__read_init() kan.liang
2018-02-13 12:06   ` [tip:perf/urgent] perf mmap: Add " tip-bot for Kan Liang
2018-02-16  9:36   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 06/17] perf mmap: discard 'prev' in perf_mmap__read() kan.liang
2018-02-13 12:06   ` [tip:perf/urgent] perf mmap: Discard " tip-bot for Kan Liang
2018-02-16  9:36   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 07/17] perf mmap: introduce perf_mmap__read_done kan.liang
2018-02-13 12:07   ` [tip:perf/urgent] perf mmap: Introduce perf_mmap__read_done() tip-bot for Kan Liang
2018-02-16  9:37   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 08/17] perf mmap: introduce perf_mmap__read_event() kan.liang
2018-02-13 12:07   ` [tip:perf/urgent] perf mmap: Introduce perf_mmap__read_event() tip-bot for Kan Liang
2018-02-16  9:37   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 09/17] perf test: update mmap read functions for backward-ring-buffer test kan.liang
2018-02-13 12:07   ` [tip:perf/urgent] perf test: Update " tip-bot for Kan Liang
2018-02-16  9:38   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 10/17] perf mmap: discard legacy interface for mmap read kan.liang
2018-02-13 12:08   ` [tip:perf/urgent] perf mmap: Discard " tip-bot for Kan Liang
2018-02-16  9:38   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 11/17] perf top: check per-event overwrite term kan.liang
2018-02-13 12:08   ` [tip:perf/urgent] perf top: Check " tip-bot for Kan Liang
2018-02-16  9:39   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 12/17] perf evsel: expose perf_missing_features.write_backward kan.liang
2018-02-02 14:26   ` Arnaldo Carvalho de Melo
2018-02-02 14:53     ` Liang, Kan
2018-01-18 21:26 ` [PATCH V5 13/17] perf top: add overwrite fall back kan.liang
2018-02-13 12:09   ` [tip:perf/urgent] perf top: Add " tip-bot for Kan Liang
2018-02-16  9:40   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 14/17] perf hists browser: add parameter to disable lost event warning kan.liang
2018-02-13 12:10   ` [tip:perf/urgent] perf hists browser: Add " tip-bot for Kan Liang
2018-02-16  9:40   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 15/17] perf top: remove lost events checking kan.liang
2018-02-13 12:10   ` [tip:perf/urgent] perf top: Remove " tip-bot for Kan Liang
2018-02-16  9:41   ` tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 16/17] perf top: switch default mode to overwrite mode kan.liang
2018-02-13 12:10   ` tip-bot for Kan Liang [this message]
2018-02-16  9:41   ` [tip:perf/urgent] perf top: Switch " tip-bot for Kan Liang
2018-01-18 21:26 ` [PATCH V5 17/17] perf top: check the latency of perf_top__mmap_read() kan.liang
2018-02-13 12:11   ` [tip:perf/urgent] perf top: Check " tip-bot for Kan Liang
2018-02-16  9:42   ` tip-bot for Kan Liang
2018-01-21 12:59 ` [PATCH V5 00/17] perf top overwrite mode Jiri Olsa

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=tip-73508fab8d06316e4dbd6cccfc9fcb21dde677b7@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wangnan0@huawei.com \
    --cc=yao.jin@linux.intel.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