From patchwork Fri Jun 14 14:08:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 166816 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2111608ilk; Fri, 14 Jun 2019 07:09:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxliwNNgNtVd6uBtknTQ09/cxMX8CjmbhR4Jkf/9pah5LTYVJvg0MsaFDAnBhAJpJ3nbWtP X-Received: by 2002:a63:6157:: with SMTP id v84mr35306739pgb.36.1560521382083; Fri, 14 Jun 2019 07:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560521382; cv=none; d=google.com; s=arc-20160816; b=qqDD0VphO7I4ZZeoSzvKpbRNzogLSLW9qac9oebUJyedqlU5iPxk2IpBwL8spg+09v id+ZtWw8E1fVoh1B+XU8o5hlxMn16SfXGpQA2bo5Gg2YGWYRKwjN2Fszv9CHom0B9hOs KHE6BjkZdrN6oirT0gB3fgvRkyLQigiOJsHvzN5wVDfe5fu1wJLdWHBw/3IOXPo6nuW0 kItPuvfODxMe86eYgvoBBeaIravwfclTavAxee8bsq+nc34ciYy/zMVecwVuHmYK8lIc DmbbT9K1tt126NE9+1JaeBxT/QtBXJeIB3Dwge4QCgcVetrVKdxaR1rvzSBuQh0sIIa3 DbgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=qyn936JVCBE9ubzmo2vBtGkdBfg4MTm0PJp8dvQUEi0=; b=Szp1VSAdyFaMlyNtU8URNea66Cip3OnUJKeYofiLwrTrrW4nwzu23vgdIy3Axs4x9E 3Xo57BpVToFzOdF8LUgiHssoeeQPP+LDOsNrtnxxBuLNHZDO6mryPU9cQOOM7xTf1obD B9difE2L7H6Ge1J/lM+ObrRgwn6u2tMh0AYk3+2Typdl6NNZUN5S9AZwG2rDGM1r2ftX 6n3pjHQfKsV8Tbr1vVlNMHOyiGjIeJ1Q9pCqz6PGBe1T4f0J6x/soZu8I+EEHrzi4yJ7 a6o1w8esgWr3ub7AsTzQfSfyn3xycOjWoBkKydq6SVcorRTL6g4/RaVkcCGvD+gSHhG9 acCA== 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 a10si2523399pff.277.2019.06.14.07.09.41; Fri, 14 Jun 2019 07:09:42 -0700 (PDT) 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 S1728804AbfFNOJg (ORCPT + 16 others); Fri, 14 Jun 2019 10:09:36 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:48062 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728616AbfFNOJd (ORCPT ); Fri, 14 Jun 2019 10:09:33 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E1D6B358CEDAD55C03A2; Fri, 14 Jun 2019 22:09:29 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Fri, 14 Jun 2019 22:09:23 +0800 From: John Garry To: , , , , , , , , , , , , CC: , , , , "John Garry" Subject: [PATCH v2 2/5] perf pmu: Support more complex PMU event aliasing Date: Fri, 14 Jun 2019 22:08:00 +0800 Message-ID: <1560521283-73314-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1560521283-73314-1-git-send-email-john.garry@huawei.com> References: <1560521283-73314-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The jevent "Unit" field is used for uncore PMU alias definition. The form uncore_pmu_example_X is supported, where "X" is a wildcard, to support multiple instances of the same PMU in a system. Unfortunately this format not suitable for all uncore PMUs; take the Hisi DDRC uncore PMU for example, where the name is in the form hisi_scclX_ddrcY. For the current jevent parsing, we would be required to hardcode an uncore alias translation for each possible value of X. This is not scalable. Instead, add support for "Unit" field in the form "hisi_sccl,ddrc", where we can match by hisi_scclX and ddrcY. Tokens in Unit field are delimited by ','. Signed-off-by: John Garry --- tools/perf/util/pmu.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 7e7299fee550..bc71c60589b5 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -700,6 +700,39 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) return map; } +static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) +{ + char *tmp, *tok, *str; + bool res; + + str = strdup(pmu_name); + if (!str) + return false; + + /* + * uncore alias may be from different PMU with common + * prefix or matching tokens. + */ + tok = strtok_r(str, ",", &tmp); + if (strncmp(pmu_name, tok, strlen(tok))) { + res = false; + goto out; + } + + for (; tok; name += strlen(tok), tok = strtok_r(NULL, ",", &tmp)) { + name = strstr(name, tok); + if (!name) { + res = false; + goto out; + } + } + + res = true; +out: + free(str); + return res; +} + /* * From the pmu_events_map, find the table of PMU events that corresponds * to the current running CPU. Then, add all PMU events from that table @@ -730,12 +763,8 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) break; } - /* - * uncore alias may be from different PMU - * with common prefix - */ if (pmu_is_uncore(name) && - !strncmp(pname, name, strlen(pname))) + pmu_uncore_alias_match(pname, name)) goto new_alias; if (strcmp(pname, name))