Received: by 10.223.185.116 with SMTP id b49csp3562138wrg; Tue, 13 Feb 2018 04:21:04 -0800 (PST) X-Google-Smtp-Source: AH8x224wx0FYWie6o+6ToSniRBbRrKGShbZHm7cSdx5Y4pczZS8ay1KFBOwAfRns8vO42/6v0rRp X-Received: by 10.98.89.28 with SMTP id n28mr1087339pfb.164.1518524464605; Tue, 13 Feb 2018 04:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524464; cv=none; d=google.com; s=arc-20160816; b=E+H576NJVaHQJ98Q3owLz3SIXtKr1/qhDdbXhLja+ffDzo5pjXBGXqkBnvbcmkJYeC +Mb2crCIedlG7RARmYoyIEoKyqRsH+H+JwXzCsi2NUaMzGT2NCzv/YtUT4eOxzi++td4 KrfKxX4prxy5i3jRrEgXuW8ZBFcKEzq8yc09stf1aqfjx7QD5BAKGLQRUaeuX2EKiQjJ 7GOTxCkW+uXN/CaDJmebWSOEp9NmEtxQ8aH/ScvOQNJJL4LFLvtWvjtnhCDKtuospNE3 NMJrjdnZT4nAHmug/7wuTxJ7NrNJ5HA/2IcMxaJ1H5e/gp0tG6ehLZ3bd+VjF87/2QG2 iltw== 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=jQdce/oN61nHl9Ihlo2+iXdopm1rr5Ni70SRPV0tp10=; b=inzwrUCQ+qdgEs0GyuMruKoNTLArwOTPmEe0ELc3mzyzNSGzMlREN32gT9bh/06+q6 +upPzvA5rTKz2vmIvSs0CWNyKvGJuvbuOY2P4WUDeqPeh8uXiCf+GqThkx+qR3z/UUpf iE6mk89asPT33/mBUXDbZSFTtyxBr3J+R9XT2X/LhZg/BRnJNQHpoQGokvr8cEWEqYHU chvZfCjfu/YgXxyKRgkepxcUj23Gvke8xkI20E9tLDhDRP9MxDnNYVY3VwGp/BljTYRp rQ6xIn/TY2PIXmAQaRswmO1atpVAFCssJQqecOEIOaVmOSMhzqvHc61HmgtwpK3cgZzo 68+w== 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 d8si717633pfk.160.2018.02.13.04.20.50; Tue, 13 Feb 2018 04:21:04 -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 S935153AbeBMMTI (ORCPT + 99 others); Tue, 13 Feb 2018 07:19:08 -0500 Received: from terminus.zytor.com ([198.137.202.136]:57833 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934918AbeBMMTG (ORCPT ); Tue, 13 Feb 2018 07:19:06 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DC8ijD029058; Tue, 13 Feb 2018 04:08:44 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DC8iVv029055; Tue, 13 Feb 2018 04:08:44 -0800 Date: Tue, 13 Feb 2018 04:08:44 -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: mingo@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, peterz@infradead.org, jolsa@kernel.org, tglx@linutronix.de, namhyung@kernel.org, wangnan0@huawei.com, kan.liang@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, acme@redhat.com Reply-To: jolsa@kernel.org, tglx@linutronix.de, namhyung@kernel.org, wangnan0@huawei.com, mingo@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, peterz@infradead.org, linux-kernel@vger.kernel.org, acme@redhat.com, kan.liang@intel.com, hpa@zytor.com In-Reply-To: <1516310792-208685-12-git-send-email-kan.liang@intel.com> References: <1516310792-208685-12-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf top: Check per-event overwrite term Git-Commit-ID: e6b33238e03466ca9b096368226f29fb4aec627a 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: e6b33238e03466ca9b096368226f29fb4aec627a Gitweb: https://git.kernel.org/tip/e6b33238e03466ca9b096368226f29fb4aec627a Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:26 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 6 Feb 2018 10:11:50 -0300 perf top: Check per-event overwrite term Per-event overwrite term is not forbidden in 'perf top', which can bring problems. Because 'perf top' only support non-overwrite mode now. Add new rules and check regarding to overwrite term for 'perf top'. - All events either have same per-event term or don't have per-event mode setting. Otherwise, it will error out. - Per-event overwrite term should be consistent as opts->overwrite. If not, updating the opts->overwrite according to per-event term. Make it possible to support either non-overwrite or overwrite mode. The overwrite mode is forbidden now, which will be removed when the overwrite mode is supported later. Signed-off-by: Kan Liang Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Jin Yao Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1516310792-208685-12-git-send-email-kan.liang@intel.com [ Renamed perf_top_overwrite_check to perf_top__overwrite_check, to follow existing convention ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index c6ccda5..1778379 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -881,6 +881,68 @@ static void perf_top__mmap_read(struct perf_top *top) perf_top__mmap_read_idx(top, i); } +/* + * Check per-event overwrite term. + * perf top should support consistent term for all events. + * - All events don't have per-event term + * E.g. "cpu/cpu-cycles/,cpu/instructions/" + * Nothing change, return 0. + * - All events have same per-event term + * E.g. "cpu/cpu-cycles,no-overwrite/,cpu/instructions,no-overwrite/ + * Using the per-event setting to replace the opts->overwrite if + * they are different, then return 0. + * - Events have different per-event term + * E.g. "cpu/cpu-cycles,overwrite/,cpu/instructions,no-overwrite/" + * Return -1 + * - Some of the event set per-event term, but some not. + * E.g. "cpu/cpu-cycles/,cpu/instructions,no-overwrite/" + * Return -1 + */ +static int perf_top__overwrite_check(struct perf_top *top) +{ + struct record_opts *opts = &top->record_opts; + struct perf_evlist *evlist = top->evlist; + struct perf_evsel_config_term *term; + struct list_head *config_terms; + struct perf_evsel *evsel; + int set, overwrite = -1; + + evlist__for_each_entry(evlist, evsel) { + set = -1; + config_terms = &evsel->config_terms; + list_for_each_entry(term, config_terms, list) { + if (term->type == PERF_EVSEL__CONFIG_TERM_OVERWRITE) + set = term->val.overwrite ? 1 : 0; + } + + /* no term for current and previous event (likely) */ + if ((overwrite < 0) && (set < 0)) + continue; + + /* has term for both current and previous event, compare */ + if ((overwrite >= 0) && (set >= 0) && (overwrite != set)) + return -1; + + /* no term for current event but has term for previous one */ + if ((overwrite >= 0) && (set < 0)) + return -1; + + /* has term for current event */ + if ((overwrite < 0) && (set >= 0)) { + /* if it's first event, set overwrite */ + if (evsel == perf_evlist__first(evlist)) + overwrite = set; + else + return -1; + } + } + + if ((overwrite >= 0) && (opts->overwrite != overwrite)) + opts->overwrite = overwrite; + + return 0; +} + static int perf_top__start_counters(struct perf_top *top) { char msg[BUFSIZ]; @@ -888,6 +950,17 @@ static int perf_top__start_counters(struct perf_top *top) struct perf_evlist *evlist = top->evlist; struct record_opts *opts = &top->record_opts; + if (perf_top__overwrite_check(top)) { + ui__error("perf top only support consistent per-event " + "overwrite setting for all events\n"); + 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) {