Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 06 Feb 2019 01:27:34 -0000 Received: from mga03.intel.com ([134.134.136.65]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1grBwn-0003yA-9y for speck@linutronix.de; Wed, 06 Feb 2019 02:24:17 +0100 From: Andi Kleen Subject: [MODERATED] [PATCH v2 7/8] PERFv2 Date: Tue, 5 Feb 2019 17:24:01 -0800 Message-Id: <62292403cca4e428755d8debd4a4bb214e1d1b47.1549416008.git.ak@linux.intel.com> In-Reply-To: References: In-Reply-To: References: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: speck@linutronix.de Cc: Andi Kleen List-ID: When the system only has three counters HLE (EL) is also not available. Detect that there are only three counters and then automatically disable el-starts for --transaction. This avoids event multiplexing in this situation with no loss of information. Signed-off-by: Andi Kleen --- tools/perf/builtin-stat.c | 30 ++++++++++++++++++++++-------- tools/perf/util/pmu.c | 10 ++++++++++ tools/perf/util/pmu.h | 1 + 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c94f5ed135f1..59a5bf0389b7 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -104,6 +104,18 @@ static const char *transaction_attrs = { "}:W" }; +static const char *transaction_noel_attrs = { + "task-clock," + "{" + "instructions," + "cycles," + "cpu/cycles-t/," + "cpu/tx-start/," + "cpu/cycles-ct/" + "}:W" +}; + + /* More limited version when the CPU does not have all events. */ static const char * transaction_limited_attrs = { "task-clock," @@ -1160,6 +1172,8 @@ static int add_default_attributes(void) return 0; if (transaction_run) { + const char *attrs = transaction_limited_attrs; + /* Handle -T as -M transaction. Once platform specific metrics * support has been added to the json files, all archictures * will use this approach. To determine transaction support @@ -1173,16 +1187,16 @@ static int add_default_attributes(void) } if (pmu_have_event("cpu", "cycles-ct") && - pmu_have_event("cpu", "el-start")) - err = parse_events(evsel_list, transaction_attrs, - &errinfo); - else - err = parse_events(evsel_list, - transaction_limited_attrs, - &errinfo); + pmu_have_event("cpu", "el-start")) { + if (pmu_num_counters("cpu") == 3) + attrs = transaction_noel_attrs; + else + attrs = transaction_attrs; + } + err = parse_events(evsel_list, attrs, &errinfo); if (err) { fprintf(stderr, "Cannot set up transaction events\n"); - parse_events_print_error(&errinfo, transaction_attrs); + parse_events_print_error(&errinfo, attrs); return -1; } return 0; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 11a234740632..5e17409b7ff6 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1495,3 +1495,13 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, va_end(args); return ret; } + +int pmu_num_counters(const char *pname) +{ + unsigned long num; + struct perf_pmu *pmu = perf_pmu__find(pname); + + if (pmu && perf_pmu__scan_file(pmu, "caps/num_counter", "%ld", &num) == 1) + return num; + return -1; +} diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 76fecec7b3f9..6e772243fd1d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -85,6 +85,7 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); void print_pmu_events(const char *event_glob, bool name_only, bool quiet, bool long_desc, bool details_flag); bool pmu_have_event(const char *pname, const char *name); +int pmu_num_counters(const char *); int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4); -- 2.17.2