Received: by 10.223.176.46 with SMTP id f43csp34581wra; Thu, 18 Jan 2018 13:31:26 -0800 (PST) X-Google-Smtp-Source: ACJfBovTnDkhrBSA1toloIDFDCYDIfEvMGBEba32pyxXUtvptN1TSSHVmHzK1Mjk9UR+S63gyj1n X-Received: by 10.101.81.7 with SMTP id f7mr38322507pgq.423.1516311086266; Thu, 18 Jan 2018 13:31:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311086; cv=none; d=google.com; s=arc-20160816; b=l2zcSOxxdaRNiSzdEwAEWMBD6f6IV/zRkWb2TM3iA4aV3lGWiN92sfGSfjT8HTSeJt urD0T8B4nKGYCoZtQcQX2WHPZ9qGya74WwUYHs1d4ra+Xuq8iMSReeKXGxEAmdnZxhcE ZqxrJuqx7i43Y+RgaiYDqqwuvM2DQbAlet0xVN5NZ9OdTl2PcRue+Tg4TirzRbecYknH FrBUc73imAjYnN3xaDE+G95jgGyaJCto+4h0R0J9LuCqrFuCFaTTOy49N/2OA33YniVp sqJBYGqad41el4nf+cSKU70XnwRqa5sGvWNOt7Hsf6WYtIvIOFXWQi0G9mSwJ1hkZfCa 8DNA== 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=C/8KtRTg9wsm5IK6SJCX1uB7c1vcPZC7Iopg5q83fLE=; b=X+NKQ1yx0TU86sWn5+0BUc6lmSvQBDFRz3NYp6pJ0p9yVUNyzZAhYFepTyl7mqRRSJ lcR2yhXe8OwCrIBweVzQ2mD0TQPVDqep6ba/4QCo+lJ9pjxUyszmA3eJ1OOBF8OiQobx n9PiiYV4BqQFuWGU2oFm8tPy7eOX1WmIB11RypKxguFpTOvxThK9rWCcSCs69pBfMBfK 4sbhFlXDo26zwI4Uqft+B4T/SKHnw3NzkcxViW4pNXxBwSvtvDBOIDqAMepUDKOumJWu ff1cyOCOg04qnX5P87IsKJKWXTSvGBGcj1P7yHFdD+oTncyTFU1sDDMu0oDfGJRW19kT 5+Hg== 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 s23si6764845pgn.713.2018.01.18.13.31.12; Thu, 18 Jan 2018 13:31:26 -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 S1754870AbeARV2s (ORCPT + 99 others); Thu, 18 Jan 2018 16:28:48 -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 S1754334AbeARV1h (ORCPT ); Thu, 18 Jan 2018 16:27:37 -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:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477270" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:35 -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 11/17] perf top: check per-event overwrite term Date: Thu, 18 Jan 2018 13:26:26 -0800 Message-Id: <1516310792-208685-12-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 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 --- 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..c86eee4 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) { -- 2.5.5