From patchwork Wed Jul 3 03:27:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168383 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp264152ilk; Tue, 2 Jul 2019 20:28:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqybV8GtIfNpn7Xp02voYO6LTZjUxso1qzWijVMlp+sitTYoaKbjXSJMro18jec05k2cyUzQ X-Received: by 2002:a17:90a:7d09:: with SMTP id g9mr9468005pjl.38.1562124514785; Tue, 02 Jul 2019 20:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562124514; cv=none; d=google.com; s=arc-20160816; b=yoekSs+3EvV+Zcsl13RIEatGispsE4p0wp1w4xmLttolFmkH27tDiT9tR+Qb6NgspA sXvyyQq04s43fHOT9qLGC5nYNATbKMSwCsyWtktv8DKJBnmxc+7/7DzBVNMcSUFMW5W6 jsKUDdGAjJPpsPJyUzsOze/ag+xTVPQZQDW8YkvZonDpapBdVtnz9TlBw2NDp+ku0V4b iI5g6CKEB8PsCUdsdPLYvfqK9bSNPxhufeeWzYEYnU0mTvZQgvkDCMPvAbsfWo3N4+vv BjiqX+SnI0p60Qi01VImt3GaqHZTfouf+O6f25k7MJmLg5KrV1KcLTh0NP4P0GqtCD6X Q0nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1sFfCto5ppMxlOEWQ6XrV9eJ6bq104fTCAcugQQB2XY=; b=iGrKoM0NJZ7EK0fn0liiqn78hR4gfhYIIsHrzRrY/0BmsnGMwdUQrjpOABxASastGj SuUVSbD+o4u3xO+PS+ze7dbSktUUPSnNRkSWL3HZHzCVXRy64gzRdQkxcWWd9uNyZrKQ QKOULT01qgPRvIVzaQkGJCpFiEAaKMw6Pn7HYrsIqMeUD+MC9iHHW2f6qwWmVAt6BSPR 8L0pnlJEBKYdgud7B7xk2ypN3XHyGX/onQ9Uo7p0+AEqlhBbaAF+gUmHR7XnPpLIQ704 +PyrKQ8qgRaESkzII3ChlTKG3rmxicBUxLpSVkAOxk43Eo78vby9749bCnRtpZRb9mWU YpPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WoJa7Iru; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66si862407pld.6.2019.07.02.20.28.34; Tue, 02 Jul 2019 20:28:34 -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; dkim=pass header.i=@kernel.org header.s=default header.b=WoJa7Iru; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727465AbfGCD2d (ORCPT + 30 others); Tue, 2 Jul 2019 23:28:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:56540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727373AbfGCD2b (ORCPT ); Tue, 2 Jul 2019 23:28:31 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BD4621850; Wed, 3 Jul 2019 03:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562124511; bh=E5HWvXZgTeSKHxIKhqZ/E3l3wGCI1IPSGpHB2y/QAV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WoJa7Iru2ljQE3R5Dx237lQe4g8tSPMFcFlQpuAmUygJ1ue3RnuBbQc4o5HoVJX+L SOihDqDB/DX22YgJFZO3OjPBav1B6kphrS6Tmaf5InsVmiyXN+CbnMtAKqhlKFeGvs KvG8grMKIJlw59KW4m6NXwhHJKdboRhAq9d3j3Y8= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, John Garry , Alexander Shishkin , Andi Kleen , Ben Hutchings , Hendrik Brueckner , Kan Liang , Mark Rutland , Mathieu Poirier , Peter Zijlstra , Shaokun Zhang , Thomas Richter , Will Deacon , linux-arm-kernel@lists.infradead.org, linuxarm@huawei.com, Arnaldo Carvalho de Melo Subject: [PATCH 09/18] perf pmu: Support more complex PMU event aliasing Date: Wed, 3 Jul 2019 00:27:37 -0300 Message-Id: <20190703032746.21692-10-acme@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703032746.21692-1-acme@kernel.org> References: <20190703032746.21692-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry 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 Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ben Hutchings Cc: Hendrik Brueckner Cc: Kan Liang Cc: Mark Rutland Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Shaokun Zhang Cc: Thomas Richter Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Cc: linuxarm@huawei.com Link: http://lkml.kernel.org/r/1561732552-143038-2-git-send-email-john.garry@huawei.com [ Shut up older gcc complianing about the last arg to strtok_r() being uninitialized, set that tmp to NULL ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 46 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8139a1f3ed39..55f4de6442e3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -701,6 +701,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 = NULL, *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 @@ -731,12 +771,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))