Received: by 10.223.185.116 with SMTP id b49csp3563422wrg; Tue, 13 Feb 2018 04:22:09 -0800 (PST) X-Google-Smtp-Source: AH8x225QXIJRx0ZNg1EnG/MW0teOswaJUoZQ7SwwrfB+jhbPvXAA1j+oEeHO2nsUka+Cqlfp8XZO X-Received: by 10.101.71.129 with SMTP id e1mr869670pgs.430.1518524529513; Tue, 13 Feb 2018 04:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524529; cv=none; d=google.com; s=arc-20160816; b=GZdnuCYWIU/LUa9Pfh0A2OIqBIWfs2uJwe+agEY61bPBPcfwe3xNPXIOzFFSBkkFrV LK+K5CU+eceZ/JTbRwmKtnxgNgrVFdzpnWu3KwC8gheYJULyzJh5hIAuzAf1DdDr2Oy3 qFrTVEUlg0v7CHWjjU/qS3v6o90fyPJ+qfZHSRaIP6XtQBVqHfTBvtiCZDQNCrKJjH20 3NSKtR6kdWDK/7KSHPDrwSY/XpB863HJrh/7rLiQbgSybZvsthm/ycFhX9R7XlcVTvpL QryUf7Pfl0gdiyMYC9B3YxMlYi24CppxApLC80xB9L7hm5wOIeHvUEzUKWMPHvSCBVKI XXDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=Q6J4u6pa7Tp6a849RS3DGozwaLpCBZgd3SWml4ATSLE=; b=YhffHyuhpL49a+fklvMEb+/hgEYcoI9+lcSuM76+hRMRcf3RMg57R/xGfZhrJVrOLN 4KHMoqBupr3NNDeo0hK8tOxA0Kw0ZrYUrnbXNPw/5xi7NiFZYcER+4oM/L3iVnsiTaXS GOrAfx2UAvs65KPnC5k/yVPFVMHTtazu8e0SDD+6Y2Q/JqwIePH0Sa+uzrHnPSYYzpPG VxgWVwWLAtCoYhSAUoz0j2QMAvN2eP0y/vyGZ02jScfSx4L66VvX2/A835/P+vVcuGbb j1MjPO8Rv0ExeVE5FuA+xRjR1+9VdqLIK1NxtsiXsevus3Cq2w/8sYiADROdtFY/zHlq +eow== 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 i11-v6si1433892plr.671.2018.02.13.04.21.55; Tue, 13 Feb 2018 04:22:09 -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 S935100AbeBMMVW (ORCPT + 99 others); Tue, 13 Feb 2018 07:21:22 -0500 Received: from terminus.zytor.com ([198.137.202.136]:40923 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934827AbeBMMVU (ORCPT ); Tue, 13 Feb 2018 07:21:20 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DCAt2M029519; Tue, 13 Feb 2018 04:10:55 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DCAsnp029516; Tue, 13 Feb 2018 04:10:54 -0800 Date: Tue, 13 Feb 2018 04:10:54 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: 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 Reply-To: tglx@linutronix.de, ak@linux.intel.com, hpa@zytor.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kan.liang@intel.com, yao.jin@linux.intel.com, acme@redhat.com, wangnan0@huawei.com, peterz@infradead.org, mingo@kernel.org, namhyung@kernel.org In-Reply-To: <1516310792-208685-17-git-send-email-kan.liang@intel.com> References: <1516310792-208685-17-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf top: Switch default mode to overwrite mode Git-Commit-ID: 73508fab8d06316e4dbd6cccfc9fcb21dde677b7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 73508fab8d06316e4dbd6cccfc9fcb21dde677b7 Gitweb: https://git.kernel.org/tip/73508fab8d06316e4dbd6cccfc9fcb21dde677b7 Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:31 -0800 Committer: Arnaldo Carvalho de Melo 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 Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Andi Kleen Cc: Jin Yao Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1516310792-208685-17-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- 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,