From nobody Fri Nov 29 04:49:21 2024 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42388170A3D for ; Wed, 25 Sep 2024 14:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273735; cv=none; b=gwdKvJjx9XSSBJ6ayTVB5JfGcRpo14FeXavNHK2nPZf1EjJtTvoGZh2XbqBP0T0YCfltQBA0VbzWfTVxHD+YJVZwNAlAhObE4QYktl4Bfedea2HwFtKkQd6lWmr+hkIXi+S55n0r4+T6F+1k1d8WH7EeQsGoGuHJ7qvFQyVc1gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273735; c=relaxed/simple; bh=CZjug4qzzjkcwqgXO8YtS5X6ejJ3H+6DA66IyZYZ/ME=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UWRlrzF1hF+XU068VPUyqYsm/UnBB95b+GAMHYPwPOTcoENUkRVO8E46io0pBJHMyaFBfMb4F7PyRikId48/r8OOxEhNSBTccpP+Mb2CyS/jMlQMFGtW5fBUvHbKFkeXVbtXcYMBT+s6B/g5SeExr/KuscRqda0Xax7mfuVS0b4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=fjyRTaq0; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fjyRTaq0" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5365928acd0so3631815e87.2 for ; Wed, 25 Sep 2024 07:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727273731; x=1727878531; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=20vjXBMSvILK4XIhd9J/lLgwlLG9hMcO1A1HFzrb3DA=; b=fjyRTaq0LFzL9udAOkRCbB8sUCpm9F3YIe35pP/KhynXmE7ddeztq5/8au/NEyS789 OMpWZekqVqMjSG8D1jp57FuiZA32FHNOi7ujWcFgw+a/GABWCsQwA255tYl2xxEIWPu8 5ghumO13hQL2+Pe4HezlPhTjbhIRjH5AngVLIinaC+0QbbAQnipLIDjU3gnYDGWNcJtB 9/uLpwGLmFspi0rql2Ny6b1KqHUQZ1Z5DVFBNMJJgQ80N/CvpjuaUpGl8AgB+ODYxl4j CK7m61YH7bh1+9njYVW4h3PgmatpYH4UlKg4VeYbgsFAnIopA+rAdNIvO6e1Fe/O9+tn G4Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727273731; x=1727878531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=20vjXBMSvILK4XIhd9J/lLgwlLG9hMcO1A1HFzrb3DA=; b=lxbIp/JGAyAFok/tKJhfXpQJxELHoyF+tpRf7jjhkTZbr3hKQwOkurdRECc7xznRfH DyWfM2kAo2flyQ4S4LwEZJXg1igJGoeYrvtbM/2IptkRnsg07yh08A0m61xXPc2vOub/ 6kPumJj6LP+9bUmEyowbudi2mh8sWyT8M0RtFDE25oMSLK27otsT5sAS+6HekLpiv2iT Kji43nbSAQuAnLCkbC3G70NbuYW2fbwVAbvRpKkxYTWxcS+t+m32C3yz9KxMogoNLK2T N+4YcLthDPuquvMJu2dle291zO/NBGgkAfqKp0kgtg6Yw7M9x3tlJUfY6d0lNGswx5oQ Y/GQ== X-Forwarded-Encrypted: i=1; AJvYcCXgKZxHBZc3aVtVWe7iv8R4PYp2gpdqbz33eBi6n0ee2c9zlSbG7/ooWGQ90Cm2jsgDSdJcxR/llFckw6A=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5IYEDPXO9Pz5eVwfTSCUv3E5wYte6TaBveb1/vguf4SemKLJ+ d5kcJeAfiI3uOq+1Xc1zo5NVCE+//oqbCQDl4wY4WguugT0Jbj7ukN4Io8c+0rE= X-Google-Smtp-Source: AGHT+IFX11aAx90T6JtlI8kp+EhCMIkldkiSJ21zk188cmmPI+fgddWDUAw2qeJvnIphJxa4/TRzWA== X-Received: by 2002:a05:6512:39c7:b0:533:42ae:c985 with SMTP id 2adb3069b0e04-5387753181dmr2079003e87.25.1727273731153; Wed, 25 Sep 2024 07:15:31 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4968f4sm1888005a12.27.2024.09.25.07.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 07:15:30 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Yang Li , Yang Jihong , Colin Ian King , Athira Rajeev , Howard Chu , Ze Gao , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 3/7] perf stat: Remove evlist__add_default_attrs use strings Date: Wed, 25 Sep 2024 15:13:41 +0100 Message-Id: <20240925141357.1033087-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925141357.1033087-1-james.clark@linaro.org> References: <20240925141357.1033087-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ian Rogers add_default_atttributes would add evsels by having pre-created perf_event_attr, however, this needed fixing for hybrid as the extended PMU type was necessary for each core PMU. The logic for this was in an arch specific x86 function and wasn't present for ARM, meaning that default events weren't being opened on all PMUs on ARM. Change the creation of the default events to use parse_events and strings as that will open the events on all PMUs. Rather than try to detect events on PMUs before parsing, parse the event but skip its output in stat-display. The previous order of hardware events was: cycles, stalled-cycles-frontend, stalled-cycles-backend, instructions. As instructions is a more fundamental concept the order is changed to: instructions, cycles, stalled-cycles-frontend, stalled-cycles-backend. Closes: https://lore.kernel.org/lkml/CAP-5=3DfVABSBZnsmtRn1uF-k-G1GWM-L5Sgi= inhPTfHbQsKXb_g@mail.gmail.com/ Acked-by: Namhyung Kim Signed-off-by: Ian Rogers [Don't display unsupported default events] Acked-by: Kan Liang Signed-off-by: James Clark --- tools/perf/arch/x86/util/evlist.c | 74 +------- tools/perf/builtin-stat.c | 291 ++++++++++++------------------ tools/perf/util/evlist.c | 43 ----- tools/perf/util/evlist.h | 12 -- tools/perf/util/stat-display.c | 8 + tools/perf/util/stat-shadow.c | 4 +- 6 files changed, 125 insertions(+), 307 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index cebdd483149e..3a4bf13b1759 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -1,78 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include "util/pmu.h" -#include "util/pmus.h" -#include "util/evlist.h" -#include "util/parse-events.h" -#include "util/event.h" +#include +#include "../../../util/evlist.h" +#include "../../../util/evsel.h" #include "topdown.h" #include "evsel.h" =20 -static int ___evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - LIST_HEAD(head); - size_t i =3D 0; - - for (i =3D 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - if (perf_pmus__num_core_pmus() =3D=3D 1) - return evlist__add_attrs(evlist, attrs, nr_attrs); - - for (i =3D 0; i < nr_attrs; i++) { - struct perf_pmu *pmu =3D NULL; - - if (attrs[i].type =3D=3D PERF_TYPE_SOFTWARE) { - struct evsel *evsel =3D evsel__new(attrs + i); - - if (evsel =3D=3D NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - continue; - } - - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - struct perf_cpu_map *cpus; - struct evsel *evsel; - - evsel =3D evsel__new(attrs + i); - if (evsel =3D=3D NULL) - goto out_delete_partial_list; - evsel->core.attr.config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; - cpus =3D perf_cpu_map__get(pmu->cpus); - evsel->core.cpus =3D cpus; - evsel->core.own_cpus =3D perf_cpu_map__get(cpus); - evsel->pmu_name =3D strdup(pmu->name); - list_add_tail(&evsel->core.node, &head); - } - } - - evlist__splice_list_tail(evlist, &head); - - return 0; - -out_delete_partial_list: - { - struct evsel *evsel, *n; - - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); - } - return -1; -} - -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - if (!nr_attrs) - return 0; - - return ___evlist__add_default_attrs(evlist, attrs, nr_attrs); -} - int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs) { if (topdown_sys_has_perf_metrics() && diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 689a3d43c258..ceec0a96d5f0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1814,130 +1814,25 @@ static int perf_stat_init_aggr_mode_file(struct pe= rf_stat *st) } =20 /* - * Add default attributes, if there were no attributes specified or + * Add default events, if there were no attributes specified or * if -d/--detailed, -d -d or -d -d -d is used: */ -static int add_default_attributes(void) +static int add_default_events(void) { - struct perf_event_attr default_attrs0[] =3D { - - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_TASK_CLOCK }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_CONTEXT_SWITCH= ES }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_CPU_MIGRATIONS= }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_PAGE_FAULTS }, - - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_CPU_CYCLES }, -}; - struct perf_event_attr frontend_attrs[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_STALLED_CYCLES= _FRONTEND }, -}; - struct perf_event_attr backend_attrs[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_STALLED_CYCLES= _BACKEND }, -}; - struct perf_event_attr default_attrs1[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_INSTRUCTIONS = }, - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_BRANCH_INSTRUC= TIONS }, - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_BRANCH_MISSES = }, - -}; - -/* - * Detailed stats (-d), covering the L1 and last level data caches: - */ - struct perf_event_attr detailed_attrs[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_LL << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_LL << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, -}; - -/* - * Very detailed stats (-d -d), covering the instruction cache and the TLB= caches: - */ - struct perf_event_attr very_detailed_attrs[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - -}; + const char *pmu =3D parse_events_option_args.pmu_filter ?: "all"; + struct parse_events_error err; + struct evlist *evlist =3D evlist__new(); + struct evsel *evsel; + int ret =3D 0; =20 -/* - * Very, very detailed stats (-d -d -d), adding prefetch events: - */ - struct perf_event_attr very_very_detailed_attrs[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, -}; + if (!evlist) + return -ENOMEM; =20 - struct perf_event_attr default_null_attrs[] =3D {}; - const char *pmu =3D parse_events_option_args.pmu_filter ?: "all"; + parse_events_error__init(&err); =20 /* Set attrs if no event is selected and !null_run: */ if (stat_config.null_run) - return 0; + goto out; =20 if (transaction_run) { /* Handle -T as -M transaction. Once platform specific metrics @@ -1947,9 +1842,10 @@ static int add_default_attributes(void) */ if (!metricgroup__has_metric(pmu, "transaction")) { pr_err("Missing transaction metrics\n"); - return -1; + ret =3D -1; + goto out; } - return metricgroup__parse_groups(evsel_list, pmu, "transaction", + ret =3D metricgroup__parse_groups(evlist, pmu, "transaction", stat_config.metric_no_group, stat_config.metric_no_merge, stat_config.metric_no_threshold, @@ -1957,6 +1853,7 @@ static int add_default_attributes(void) stat_config.system_wide, stat_config.hardware_aware_grouping, &stat_config.metric_events); + goto out; } =20 if (smi_cost) { @@ -1964,26 +1861,29 @@ static int add_default_attributes(void) =20 if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) { pr_err("freeze_on_smi is not supported.\n"); - return -1; + ret =3D -1; + goto out; } =20 if (!smi) { if (sysfs__write_int(FREEZE_ON_SMI_PATH, 1) < 0) { - fprintf(stderr, "Failed to set freeze_on_smi.\n"); - return -1; + pr_err("Failed to set freeze_on_smi.\n"); + ret =3D -1; + goto out; } smi_reset =3D true; } =20 if (!metricgroup__has_metric(pmu, "smi")) { pr_err("Missing smi metrics\n"); - return -1; + ret =3D -1; + goto out; } =20 if (!force_metric_only) stat_config.metric_only =3D true; =20 - return metricgroup__parse_groups(evsel_list, pmu, "smi", + ret =3D metricgroup__parse_groups(evlist, pmu, "smi", stat_config.metric_no_group, stat_config.metric_no_merge, stat_config.metric_no_threshold, @@ -1991,6 +1891,7 @@ static int add_default_attributes(void) stat_config.system_wide, stat_config.hardware_aware_grouping, &stat_config.metric_events); + goto out; } =20 if (topdown_run) { @@ -2003,21 +1904,23 @@ static int add_default_attributes(void) if (!max_level) { pr_err("Topdown requested but the topdown metric groups aren't present.= \n" "(See perf list the metric groups have names like TopdownL1)\n"); - return -1; + ret =3D -1; + goto out; } if (stat_config.topdown_level > max_level) { pr_err("Invalid top-down metrics level. The max level is %u.\n", max_le= vel); - return -1; - } else if (!stat_config.topdown_level) + ret =3D -1; + goto out; + } else if (!stat_config.topdown_level) { stat_config.topdown_level =3D 1; - + } if (!stat_config.interval && !stat_config.metric_only) { fprintf(stat_config.output, "Topdown accuracy may decrease when measuring long periods.\n" "Please print the result regularly, e.g. -I1000\n"); } str[8] =3D stat_config.topdown_level + '0'; - if (metricgroup__parse_groups(evsel_list, + if (metricgroup__parse_groups(evlist, pmu, str, /*metric_no_group=3D*/false, /*metric_no_merge=3D*/false, @@ -2025,41 +1928,49 @@ static int add_default_attributes(void) stat_config.user_requested_cpu_list, stat_config.system_wide, stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) - return -1; + &stat_config.metric_events) < 0) { + ret =3D -1; + goto out; + } } =20 if (!stat_config.topdown_level) stat_config.topdown_level =3D 1; =20 - if (!evsel_list->core.nr_entries) { + if (!evlist->core.nr_entries && !evsel_list->core.nr_entries) { /* No events so add defaults. */ if (target__has_cpu(&target)) - default_attrs0[0].config =3D PERF_COUNT_SW_CPU_CLOCK; + ret =3D parse_events(evlist, "cpu-clock", &err); + else + ret =3D parse_events(evlist, "task-clock", &err); + if (ret) + goto out; + + ret =3D parse_events(evlist, + "context-switches," + "cpu-migrations," + "page-faults," + "instructions," + "cycles," + "stalled-cycles-frontend," + "stalled-cycles-backend," + "branches," + "branch-misses", + &err); + if (ret) + goto out; =20 - if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0) - return -1; - if (perf_pmus__have_event("cpu", "stalled-cycles-frontend")) { - if (evlist__add_default_attrs(evsel_list, frontend_attrs) < 0) - return -1; - } - if (perf_pmus__have_event("cpu", "stalled-cycles-backend")) { - if (evlist__add_default_attrs(evsel_list, backend_attrs) < 0) - return -1; - } - if (evlist__add_default_attrs(evsel_list, default_attrs1) < 0) - return -1; /* * Add TopdownL1 metrics if they exist. To minimize * multiplexing, don't request threshold computation. */ if (metricgroup__has_metric(pmu, "Default")) { struct evlist *metric_evlist =3D evlist__new(); - struct evsel *metric_evsel; - - if (!metric_evlist) - return -1; =20 + if (!metric_evlist) { + ret =3D -ENOMEM; + goto out; + } if (metricgroup__parse_groups(metric_evlist, pmu, "Default", /*metric_no_group=3D*/false, /*metric_no_merge=3D*/false, @@ -2067,43 +1978,65 @@ static int add_default_attributes(void) stat_config.user_requested_cpu_list, stat_config.system_wide, stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) - return -1; - - evlist__for_each_entry(metric_evlist, metric_evsel) { - metric_evsel->skippable =3D true; - metric_evsel->default_metricgroup =3D true; + &stat_config.metric_events) < 0) { + ret =3D -1; + goto out; } - evlist__splice_list_tail(evsel_list, &metric_evlist->core.entries); + + evlist__for_each_entry(metric_evlist, evsel) + evsel->default_metricgroup =3D true; + + evlist__splice_list_tail(evlist, &metric_evlist->core.entries); evlist__delete(metric_evlist); } - - /* Platform specific attrs */ - if (evlist__add_default_attrs(evsel_list, default_null_attrs) < 0) - return -1; } =20 /* Detailed events get appended to the event list: */ =20 - if (detailed_run < 1) - return 0; - - /* Append detailed run extra attributes: */ - if (evlist__add_default_attrs(evsel_list, detailed_attrs) < 0) - return -1; - - if (detailed_run < 2) - return 0; - - /* Append very detailed run extra attributes: */ - if (evlist__add_default_attrs(evsel_list, very_detailed_attrs) < 0) - return -1; - - if (detailed_run < 3) - return 0; - - /* Append very, very detailed run extra attributes: */ - return evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); + if (!ret && detailed_run >=3D 1) { + /* + * Detailed stats (-d), covering the L1 and last level data + * caches: + */ + ret =3D parse_events(evlist, + "L1-dcache-loads," + "L1-dcache-load-misses," + "LLC-loads," + "LLC-load-misses", + &err); + } + if (!ret && detailed_run >=3D 2) { + /* + * Very detailed stats (-d -d), covering the instruction cache + * and the TLB caches: + */ + ret =3D parse_events(evlist, + "L1-icache-loads," + "L1-icache-load-misses," + "dTLB-loads," + "dTLB-load-misses," + "iTLB-loads," + "iTLB-load-misses", + &err); + } + if (!ret && detailed_run >=3D 3) { + /* + * Very, very detailed stats (-d -d -d), adding prefetch events: + */ + ret =3D parse_events(evlist, + "L1-dcache-prefetches," + "L1-dcache-prefetch-misses", + &err); + } +out: + if (!ret) { + evlist__for_each_entry(evlist, evsel) + evsel->skippable =3D true; + } + parse_events_error__exit(&err); + evlist__splice_list_tail(evsel_list, &evlist->core.entries); + evlist__delete(evlist); + return ret; } =20 static const char * const stat_record_usage[] =3D { @@ -2760,7 +2693,7 @@ int cmd_stat(int argc, const char **argv) } } =20 - if (add_default_attributes()) + if (add_default_events()) goto out; =20 if (stat_config.cgroup_list) { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f14b7e6ff1dc..bace277fa77d 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -319,49 +319,6 @@ struct evsel *evlist__add_sched_switch(struct evlist *= evlist, bool system_wide) } #endif =20 -int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs= , size_t nr_attrs) -{ - struct evsel *evsel, *n; - LIST_HEAD(head); - size_t i; - - for (i =3D 0; i < nr_attrs; i++) { - evsel =3D evsel__new_idx(attrs + i, evlist->core.nr_entries + i); - if (evsel =3D=3D NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - } - - evlist__splice_list_tail(evlist, &head); - - return 0; - -out_delete_partial_list: - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); - return -1; -} - -int __evlist__add_default_attrs(struct evlist *evlist, struct perf_event_a= ttr *attrs, size_t nr_attrs) -{ - size_t i; - - for (i =3D 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - return evlist__add_attrs(evlist, attrs, nr_attrs); -} - -__weak int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - if (!nr_attrs) - return 0; - - return __evlist__add_default_attrs(evlist, attrs, nr_attrs); -} - struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id) { struct evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index bcc1c6984bb5..371dc740ff7a 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -102,18 +102,6 @@ void evlist__delete(struct evlist *evlist); void evlist__add(struct evlist *evlist, struct evsel *entry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); =20 -int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs= , size_t nr_attrs); - -int __evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, size_t nr_attrs); - -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs); - -#define evlist__add_default_attrs(evlist, array) \ - arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) - int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); =20 int evlist__add_dummy(struct evlist *evlist); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index cbff43ff8d0f..5402998881c4 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -7,6 +7,7 @@ #include #include "color.h" #include "counts.h" +#include "debug.h" #include "evlist.h" #include "evsel.h" #include "stat.h" @@ -967,6 +968,13 @@ static bool should_skip_zero_counter(struct perf_stat_= config *config, struct perf_cpu cpu; int idx; =20 + /* + * Skip unsupported default events when not verbose. (default events + * are all marked 'skippable'). + */ + if (verbose =3D=3D 0 && counter->skippable && !counter->supported) + return true; + /* * Skip value 0 when enabling --per-thread globally, * otherwise it will have too many 0 output. diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 99376c12dd8e..dd709a731574 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -76,7 +76,7 @@ void perf_stat__reset_shadow_stats(void) memset(&ru_stats, 0, sizeof(ru_stats)); } =20 -static enum stat_type evsel__stat_type(const struct evsel *evsel) +static enum stat_type evsel__stat_type(struct evsel *evsel) { /* Fake perf_hw_cache_op_id values for use with evsel__match. */ u64 PERF_COUNT_hw_cache_l1d_miss =3D PERF_COUNT_HW_CACHE_L1D | @@ -152,7 +152,7 @@ static const char *get_ratio_color(const double ratios[= 3], double val) =20 static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat= _type type) { - const struct evsel *cur; + struct evsel *cur; int evsel_ctx =3D evsel_context(evsel); =20 evlist__for_each_entry(evsel->evlist, cur) { --=20 2.34.1