Commit ebebbf08 authored by Kan Liang's avatar Kan Liang Committed by Arnaldo Carvalho de Melo

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 93fc64f1 ("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: default avatarKan Liang <kan.liang@intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Tested-by: default avatarArnaldo 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a1ff5b05
...@@ -809,15 +809,23 @@ static void perf_event__process_sample(struct perf_tool *tool, ...@@ -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) 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_sample sample;
struct perf_evsel *evsel; struct perf_evsel *evsel;
struct perf_mmap *md;
struct perf_session *session = top->session; struct perf_session *session = top->session;
union perf_event *event; union perf_event *event;
struct machine *machine; struct machine *machine;
u64 end, start;
int ret; int ret;
while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx];
ret = perf_evlist__parse_sample(top->evlist, event, &sample); 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) { if (ret) {
pr_err("Can't parse sample, err = %d\n", ret); pr_err("Can't parse sample, err = %d\n", ret);
goto next_event; goto next_event;
...@@ -871,16 +879,28 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) ...@@ -871,16 +879,28 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
} else } else
++session->evlist->stats.nr_unknown_events; ++session->evlist->stats.nr_unknown_events;
next_event: 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) static void perf_top__mmap_read(struct perf_top *top)
{ {
bool overwrite = top->record_opts.overwrite;
struct perf_evlist *evlist = top->evlist;
int i; int i;
if (overwrite)
perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_DATA_PENDING);
for (i = 0; i < top->evlist->nr_mmaps; i++) for (i = 0; i < top->evlist->nr_mmaps; i++)
perf_top__mmap_read_idx(top, 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) ...@@ -979,11 +999,6 @@ static int perf_top__start_counters(struct perf_top *top)
goto out_err; goto out_err;
} }
if (opts->overwrite) {
ui__error("not support overwrite mode yet\n");
goto out_err;
}
perf_evlist__config(evlist, opts, &callchain_param); perf_evlist__config(evlist, opts, &callchain_param);
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
...@@ -1144,7 +1159,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1144,7 +1159,7 @@ static int __cmd_top(struct perf_top *top)
perf_top__mmap_read(top); perf_top__mmap_read(top);
if (hits == top->samples) if (opts->overwrite || (hits == top->samples))
ret = perf_evlist__poll(top->evlist, 100); ret = perf_evlist__poll(top->evlist, 100);
if (resize) { if (resize) {
...@@ -1238,6 +1253,7 @@ int cmd_top(int argc, const char **argv) ...@@ -1238,6 +1253,7 @@ int cmd_top(int argc, const char **argv)
.uses_mmap = true, .uses_mmap = true,
}, },
.proc_map_timeout = 500, .proc_map_timeout = 500,
.overwrite = 1,
}, },
.max_stack = sysctl_perf_event_max_stack, .max_stack = sysctl_perf_event_max_stack,
.sym_pcnt_filter = 5, .sym_pcnt_filter = 5,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment