From patchwork Fri Jun 28 14:35:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 168095 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3782524ilk; Fri, 28 Jun 2019 07:37:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUNG0/sxbQL5j/d9JGudM3mrbvxeBCKQlg2eKa9dzbuIRF8yeyYC/2vDddieMPaWr1KnDc X-Received: by 2002:a17:90a:22c6:: with SMTP id s64mr13888263pjc.5.1561732666003; Fri, 28 Jun 2019 07:37:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561732665; cv=none; d=google.com; s=arc-20160816; b=pf6Ikqm4XmL+aNjv+wvvEaqrY5carjgUk/J4dRbNGWDwyRmmuOpeDHOOB4VVZWJKlD FfGA3rhS7CxTUa46cf6zGqtIVw5q9J2pLHSfCMjApIXhyirjCoYQKUTRoc/fSBVOtieE c7FuQCwb5xp+2cCgvVsNb6RkYgh+AWygCx41GL9x7oTeOXVdyY4oO02eJ0Pkmwl2+Eik 42biplqI32/MqHA9BgFC9jKTRv6pPT00VpmWDA9evZVD2TD5zG6VbZVhAjVSsKlTdLow +xHrS+BcDhqJYNPXPE56xIFw5dpik+0iYEh/dZTbTQX8j0Czt6lAffdh88Z73YR/kbnN A5hg== 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=D2Bzr1zTWxiJGNKG2FhMGONlH0DAczWc3RVHaCQFZOc=; b=ajWJrgYvrPEi0oskGvB60SQx1UeHC7GVah2xmWXu4CXhn3oMAb9yta+UFqHS1MEzHP LT9PV2rjKlnlIpZVkfBkJpfHzicMaKNRUfhA7Yn2+vfzB/tx65qXXFMmLiUTAnrz9faT NfzuWwcmeyum+Ipo72V7RR5ydLyDhONNmdEl24A7eXLsT3xUFswR0PZM4t5U1xrs9xA0 eN0isGfYBV+Kc5yDplxV7tLu0O99NBsM6JVPceZTC0/w10V/pP00JdY3lTqmuNY1JCOO pVCr5ip8Yg0zTsW4JIHdZKdErBknsyaASgVDqvWoMLwgaiSy0Ml6p8SR8JNb6rxaegQ5 I8GQ== 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 p2si2682188pff.164.2019.06.28.07.37.45; Fri, 28 Jun 2019 07:37:45 -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 S1726967AbfF1Oho (ORCPT + 30 others); Fri, 28 Jun 2019 10:37:44 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57350 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726836AbfF1Oh3 (ORCPT ); Fri, 28 Jun 2019 10:37:29 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 43BCE9BEFCADED0D27FC; Fri, 28 Jun 2019 22:37:27 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 28 Jun 2019 22:37:21 +0800 From: John Garry To: , , , , , , , , , , , , CC: , , , , , John Garry Subject: [PATCH v3 1/4] perf pmu: Support more complex PMU event aliasing Date: Fri, 28 Jun 2019 22:35:49 +0800 Message-ID: <1561732552-143038-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561732552-143038-1-git-send-email-john.garry@huawei.com> References: <1561732552-143038-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 for 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 | 46 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 7e7299fee550..cfc916819c59 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -700,6 +700,46 @@ 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 + */ + tok = strtok_r(str, ",", &tmp); + if (strncmp(pmu_name, tok, strlen(tok))) { + res = false; + goto out; + } + + /* + * Match more complex aliases where the alias name is a comma-delimited + * list of tokens, orderly contained in the matching PMU name. + * + * Example: For alias "socket,pmuname" and PMU "socketX_pmunameY", we + * match "socket" in "socketX_pmunameY" and then "pmuname" in + * "pmunameY". + */ + 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 +770,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))