Received: by 10.223.176.46 with SMTP id f43csp35119wra; Thu, 18 Jan 2018 13:32:01 -0800 (PST) X-Google-Smtp-Source: ACJfBovRQvEWwEvP2FQx0GnwJ5EP8xTlxXwzroZRl0M8GsFLna6KhBneFaQyh4LfXSbKuJ7Uoi/1 X-Received: by 10.99.96.23 with SMTP id u23mr37989482pgb.40.1516311121010; Thu, 18 Jan 2018 13:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311120; cv=none; d=google.com; s=arc-20160816; b=TXGmMpw/60ZV+R8Bu0sL/WYgjUinPuGMqr1bvP7OKq4F0rvNy+AwVdaGmAeZf++7Wd BifsqITQzln4Pm7yMPLYxaqGtgaJVwpVutoe/N2QmwVjUgGxDEf1UBjSvhEH2aeMgGyH ALimQW23ME0LExHkhy1GQDgyhuJiMKYDtg+zxlRgTTMjEaIDj6j3iMOU05xFHfd+vLmA 3eM9J0aXAz8VtgEVGaTCgUhfahmjxwpERRHx+4+FbaJJTkB7gouESzjby7T/sivvBR5/ Ey4ldp1hxK/M+bYB14nICUDY/fYLHaLxlQeJjTHRAMkGUO+q7xn5jWFJl4tWIFbi6bTr 9gGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=VrOsfT/i1YLNRy49fb63UDPjAiSKFg9uXaBf13zG0+I=; b=eRXEHHJWddcQqMqCHzMPrigCSxF6fqP595auO2e+IK5g/XYO4insUwk6oATXvLTYhd P1Pw7sYSNJ3Y3Vm+2iW+Ix6cy9NxidJbYRTgKDeUGMOovPU3Pgxqp305idIfcUvqpoc8 g16OTs/KGK5jXJlvjelV2Ftc2NiJNAnaCY3VOTamqRu9vqaDDSgVs4Soa0INqTO940IA KU75hYskP7zFrMpzUS95j7oRKuC5+5eTqnhC6xoWk+Ghe1z1XgKRXjTk9XhlZEfCm0Vr 73Vyq+imBdMDJ2y2LbExt59mZJKczh4wavEG2Yz+HaQdswJERRLUSSRrCjlHOQ1QroRZ 3yaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22si2988029pfl.178.2018.01.18.13.31.46; Thu, 18 Jan 2018 13:32:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754709AbeARV3v (ORCPT + 99 others); Thu, 18 Jan 2018 16:29:51 -0500 Received: from mga04.intel.com ([192.55.52.120]:47419 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932307AbeARV1m (ORCPT ); Thu, 18 Jan 2018 16:27:42 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2018 13:27:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477298" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:40 -0800 From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: wangnan0@huawei.com, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, Kan Liang Subject: [PATCH V5 16/17] perf top: switch default mode to overwrite mode Date: Thu, 18 Jan 2018 13:26:31 -0800 Message-Id: <1516310792-208685-17-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516310792-208685-1-git-send-email-kan.liang@intel.com> References: <1516310792-208685-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang perf_top__mmap_read has severe performance issue in Knights Landing/Mill, when monitoring in heavy load system. It costs several minutes to finish, which is unacceptable. Currently, perf top is non overwrite mode. For non overwrite mode, it tries to read everything in the ringbuffer and doesn't pause the ringbuffer. 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 reducing 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 perf top. 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 could be tolerant. For overwrite mode, unconditionally wait 100 ms before each snapshot. It also reduce the overhead caused by pausing ringbuffer, especially on light load system. Signed-off-by: Kan Liang --- 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 1dd3b63..465a699 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, -- 2.5.5