From patchwork Fri Oct 6 18:38:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115110 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2106562qgn; Fri, 6 Oct 2017 11:40:01 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCOkK4nOG3p66wXK0vDqDnm5ltcL88qKw+n7fiahKelWAWG6lfwwasGuat+/UFNL07B/fz+ X-Received: by 10.98.139.76 with SMTP id j73mr3088447pfe.265.1507315201317; Fri, 06 Oct 2017 11:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507315201; cv=none; d=google.com; s=arc-20160816; b=hyijZNTIdGf6meUWTTdCr5UAV1+vcHfUCYaJjDEiIknCJuwatLKcXZGWdfviHaqRUw Tr0RQEwDh0ea0Fv7Bb/HczuuYnUXfhT2mUisMV9J1hY2vOJ0NFll2wcU9TTqb2JvS8sm /YpIaekBisbhhZ5PMhrokSyhxSgZOCsM8Ij4reKG58W5EbXDVAlm8HQtSc/ogd20R2B0 It1dDBZJlsBmRPF/izsg4ons9LjT3nH3YcPT9dCuIpLsUQbx8/M4MPdzhf1ct2yNBeeE fic3/LWizUj6JKSVEZhYCxGjrpsYNKc2hG87QkzJZOqCdhKg7lE1i5LQ4oJkmXc8KQhQ m6tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=evus2rmXxsiGt0ZBiblDbDDAWb+NNWXrICTuofo/0S4=; b=cPZ+5dqziYh2B73KiCFnTwixozDJ46v8HOUf7vOkdTyEdQGI/gOxgPLJpwzo7q0jrg Uw056wZtPBv760nuIrvDuZOXGeRej/WMK9aw0W+9xhjLctbgwN/83s65VusL/J0gefpo dgizxK3T5iqJbrTvLU5rizWD34/1m5J/Y8KKrs84Cy9LvX0bSCuhQmokkgMDGDgsOAC8 m4AmspSjl6j2h5lqsext96JoAy0V4J7IugcbKQPBdlpWCsnmrOVztfIHtg99bwqd0WB/ q9qre7Hw41WSnLOuZv28855VvzGXTFCZ+ZNQFpgBIw8S+WNqwqIWXYQxM46eErnEJG8q lDCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 204si1554599pgc.742.2017.10.06.11.40.00; Fri, 06 Oct 2017 11:40:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751654AbdJFSkA (ORCPT + 8 others); Fri, 6 Oct 2017 14:40:00 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:38320 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751491AbdJFSj7 (ORCPT ); Fri, 6 Oct 2017 14:39:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23E831529; Fri, 6 Oct 2017 11:39:59 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 56EEC3F53D; Fri, 6 Oct 2017 11:39:57 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, jolsa@kernel.org, acme@redhat.com Cc: Mark Rutland , stable@vger.kernel.org, Adrian Hunter , Borislav Petkov , David Ahern , Namhyung Kim , Peter Zijlstra , Will Deacon Subject: [PATCH] perf tools: unbreak perf record for arm/arm64 Date: Fri, 6 Oct 2017 19:38:22 +0100 Message-Id: <1507315102-5942-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Currently, perf record is broken on arm/arm64 systems when the PMU is specified explicitly as part of the event, e.g. $ ./perf record -e armv8_cortex_a53/cpu_cycles/u true In such cases, perf record fails to open events unless perf_event_paranoid is set to -1, even if the PMU in question supports mode exclusion. Further, even when perf_event_paranoid is toggled, no samples are recorded. This is an unintended side effect of commit: e3ba76deef23064f ("perf tools: Force uncore events to system wide monitoring) ... which assumes that if a PMU has an associated cpu_map, it is an uncore PMU, and forces events for such PMUs to be system-wide. This is not true for arm/arm64 systems, which can have heterogeneous CPUs. To account for this, multiple CPU PMUs are exposed, each with a "cpus" field under sysfs, which the perf tool parses into a cpu_map. ARM PMUs do not have a "cpumask" file, and only have a "cpus" file. For the gory details as to why, see commit: 7e3fcffe95544010 ("perf pmu: Support alternative sysfs cpumask") Given all of this, we can instead identify uncore PMUs by explicitly checking for a "cpumask" file, and restore arm/arm64 PMU support back to a working state. This patch does so, adding a new perf_pmu::is_uncore field, and splitting the existing cpumask parsing so that it can be reused. Signed-off-by: Mark Rutland Fixes: e3ba76deef23064f ("perf tools: Force uncore events to system wide monitoring) Cc: stable@vger.kernel.org Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Cc: Borislav Petkov Cc: David Ahern Cc: Jiri Olsa Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Will Deacon --- tools/perf/util/parse-events.c | 9 ++++--- tools/perf/util/pmu.c | 56 +++++++++++++++++++++++++++++++----------- tools/perf/util/pmu.h | 1 + 3 files changed, 47 insertions(+), 19 deletions(-) -- 1.9.1 Acked-by: Will Deacon diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index f6257fb..39b1596 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -309,10 +309,11 @@ static char *get_config_name(struct list_head *head_terms) static struct perf_evsel * __add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, - char *name, struct cpu_map *cpus, + char *name, struct perf_pmu *pmu, struct list_head *config_terms, bool auto_merge_stats) { struct perf_evsel *evsel; + struct cpu_map *cpus = pmu ? pmu->cpus : NULL; event_attr_init(attr); @@ -323,7 +324,7 @@ static char *get_config_name(struct list_head *head_terms) (*idx)++; evsel->cpus = cpu_map__get(cpus); evsel->own_cpus = cpu_map__get(cpus); - evsel->system_wide = !!cpus; + evsel->system_wide = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats; if (name) @@ -1233,7 +1234,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, if (!head_config) { attr.type = pmu->type; - evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL, auto_merge_stats); + evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats); return evsel ? 0 : -ENOMEM; } @@ -1254,7 +1255,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, return -EINVAL; evsel = __add_event(list, &parse_state->idx, &attr, - get_config_name(head_config), pmu->cpus, + get_config_name(head_config), pmu, &config_terms, auto_merge_stats); if (evsel) { evsel->unit = info.unit; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ac16a9d..1c4d7b4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -470,17 +470,36 @@ static void pmu_read_sysfs(void) closedir(dir); } +static struct cpu_map *__pmu_cpumask(const char *path) +{ + FILE *file; + struct cpu_map *cpus; + + file = fopen(path, "r"); + if (!file) + return NULL; + + cpus = cpu_map__read(file); + fclose(file); + return cpus; +} + +/* + * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) + * may have a "cpus" file. + */ +#define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" +#define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" + static struct cpu_map *pmu_cpumask(const char *name) { - struct stat st; char path[PATH_MAX]; - FILE *file; struct cpu_map *cpus; const char *sysfs = sysfs__mountpoint(); const char *templates[] = { - "%s/bus/event_source/devices/%s/cpumask", - "%s/bus/event_source/devices/%s/cpus", - NULL + CPUS_TEMPLATE_UNCORE, + CPUS_TEMPLATE_CPU, + NULL }; const char **template; @@ -489,20 +508,25 @@ static struct cpu_map *pmu_cpumask(const char *name) for (template = templates; *template; template++) { snprintf(path, PATH_MAX, *template, sysfs, name); - if (stat(path, &st) == 0) - break; + cpus = __pmu_cpumask(path); + if (cpus) + return cpus; } - if (!*template) - return NULL; + return NULL; +} - file = fopen(path, "r"); - if (!file) - return NULL; +static bool pmu_is_uncore(const char *name) +{ + char path[PATH_MAX]; + struct cpu_map *cpus; + const char *sysfs = sysfs__mountpoint(); - cpus = cpu_map__read(file); - fclose(file); - return cpus; + snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name); + cpus = __pmu_cpumask(path); + cpu_map__put(cpus); + + return !!cpus; } /* @@ -617,6 +641,8 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->cpus = pmu_cpumask(name); + pmu->is_uncore = pmu_is_uncore(name); + INIT_LIST_HEAD(&pmu->format); INIT_LIST_HEAD(&pmu->aliases); list_splice(&format, &pmu->format); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 389e972..fe0de05 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -22,6 +22,7 @@ struct perf_pmu { char *name; __u32 type; bool selectable; + bool is_uncore; struct perf_event_attr *default_config; struct cpu_map *cpus; struct list_head format; /* HEAD struct perf_pmu_format -> list */