Received: by 10.223.185.116 with SMTP id b49csp1707679wrg; Sat, 17 Feb 2018 03:39:58 -0800 (PST) X-Google-Smtp-Source: AH8x224ZVUzMiF4bNJpfxJ3ximydbxUUqguKXH/xeEaz+pR1mXZRgQUEFO9S5q8xNdK9FzePH8K8 X-Received: by 2002:a17:902:848c:: with SMTP id c12-v6mr8805455plo.329.1518867598329; Sat, 17 Feb 2018 03:39:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518867598; cv=none; d=google.com; s=arc-20160816; b=O0sncaTHR3Hx5q/xoEl6UcAjUVGaKscx45vfeBMb2HNzGq9U9eqy1OAblcIPMWsHPu DH+T+PMx/o882RecOEj/xkp2qTgw2nGHddPfa33OKwvxgqp6WM0YkMalkb2Ma/3Y/gTy lyd64a6lpKQFZTYJpk7nVSlP7AoAef8IFUgrW77k93CQSG0vMB7YXBrcWbBHKfOIqLlI HK2TX81rHrhZq5YdbH35dioPPVM6jCyCU2f7XnqbOCah0JJF1MldbKgMI0w1EwmPu+H/ mK+dALnIQk0T8ey2ggy0O8+PQDaLLuOHnWgdH6QPy3lxX4DSLSNS+liJJNkv5qxAcmCV aPeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=UMS2K44fJsLx9Lf/cDhxRXmz8Dl0I5qhWkxoxXbdJbI=; b=mQULUDKBdAPHsVWBr0qXRWM2jxfuz/RwD3m3ED25fCzmomsE1ynXFAH+pU4bcidwjV LF6vovMKHBnqFPF3/oPsebpG0UzE6XbI3JvoiGDfLwkXAUsUafriyWlbkgjJEe0+BJdV 95GGoY7iMuCiwZiSM1IAsqIhq8n4oCww8R3iZdZ+I8O0BFMYREBP3wy2yuiLQiS21IEB tt/Mdfl5s9zN1prmFR+oHKUuqrzaxi2+sPr+ZWKShO6cE/7youSMhNra/mHBwKH5/1sp MnygUo73uJj37b27TeoKaTMIGpINfecWq+lUOQV3JaGeVV7+Ad79EsNgrDqULsMqNRNV cHIw== 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 t4si1169109pgr.205.2018.02.17.03.39.43; Sat, 17 Feb 2018 03:39:58 -0800 (PST) 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 S1751253AbeBQLie (ORCPT + 99 others); Sat, 17 Feb 2018 06:38:34 -0500 Received: from terminus.zytor.com ([198.137.202.136]:56209 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeBQLic (ORCPT ); Sat, 17 Feb 2018 06:38:32 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1HBcHWs008350; Sat, 17 Feb 2018 03:38:17 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1HBcHlq008345; Sat, 17 Feb 2018 03:38:17 -0800 Date: Sat, 17 Feb 2018 03:38:17 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Richter Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, acme@redhat.com, tglx@linutronix.de, schwidefsky@de.ibm.com, brueckner@linux.vnet.ibm.com, heiko.carstens@de.ibm.com, tmricht@linux.vnet.ibm.com Reply-To: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, acme@redhat.com, schwidefsky@de.ibm.com, brueckner@linux.vnet.ibm.com, tmricht@linux.vnet.ibm.com, heiko.carstens@de.ibm.com In-Reply-To: <20180213151419.80737-3-tmricht@linux.vnet.ibm.com> References: <20180213151419.80737-3-tmricht@linux.vnet.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf cpuid: Introduce a platform specific cpuid compare function Git-Commit-ID: 4cb7d3ecfca90684ad00f893c34a2028fcc5f764 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 4cb7d3ecfca90684ad00f893c34a2028fcc5f764 Gitweb: https://git.kernel.org/tip/4cb7d3ecfca90684ad00f893c34a2028fcc5f764 Author: Thomas Richter AuthorDate: Tue, 13 Feb 2018 16:14:18 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 16 Feb 2018 15:16:57 -0300 perf cpuid: Introduce a platform specific cpuid compare function The function get_cpuid_str() is called by perf_pmu__getcpuid() and on s390 returns a complete description of the CPU and its capabilities, which is a comma separated list. To map the CPU type with the value defined in the pmu-events/arch/s390/mapfile.csv, introduce an architecture specific cpuid compare function named strcmp_cpuid_str() The currently used regex algorithm is defined as the weak default and will be used if no platform specific one is defined. This matches the current behavior. Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Cc: Heiko Carstens Cc: Martin Schwidefsky Link: http://lkml.kernel.org/r/20180213151419.80737-3-tmricht@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/s390/util/header.c | 18 +++++++++++++++ tools/perf/util/header.h | 1 + tools/perf/util/pmu.c | 47 +++++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c index a78064c..231294b 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -146,3 +146,21 @@ char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) zfree(&buf); return buf; } + +/* + * Compare the cpuid string returned by get_cpuid() function + * with the name generated by the jevents file read from + * pmu-events/arch/s390/mapfile.csv. + * + * Parameter mapcpuid is the cpuid as stored in the + * pmu-events/arch/s390/mapfile.csv. This is just the type number. + * Parameter cpuid is the cpuid returned by function get_cpuid(). + */ +int strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) +{ + char *cp = strchr(cpuid, ','); + + if (cp == NULL) + return -1; + return strncmp(cp + 1, mapcpuid, strlen(mapcpuid)); +} diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index f28aaaa..942bdec 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -174,4 +174,5 @@ int write_padded(struct feat_fd *fd, const void *bf, int get_cpuid(char *buffer, size_t sz); char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); +int strcmp_cpuid_str(const char *s1, const char *s2); #endif /* __PERF_HEADER_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 57e38fd..1111d5b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -576,6 +576,34 @@ char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused) return NULL; } +/* Return zero when the cpuid from the mapfile.csv matches the + * cpuid string generated on this platform. + * Otherwise return non-zero. + */ +int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) +{ + regex_t re; + regmatch_t pmatch[1]; + int match; + + if (regcomp(&re, mapcpuid, REG_EXTENDED) != 0) { + /* Warn unable to generate match particular string. */ + pr_info("Invalid regular expression %s\n", mapcpuid); + return 1; + } + + match = !regexec(&re, cpuid, 1, pmatch, 0); + regfree(&re); + if (match) { + size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); + + /* Verify the entire string matched. */ + if (match_len == strlen(cpuid)) + return 0; + } + return 1; +} + static char *perf_pmu__getcpuid(struct perf_pmu *pmu) { char *cpuid; @@ -610,31 +638,14 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) i = 0; for (;;) { - regex_t re; - regmatch_t pmatch[1]; - int match; - map = &pmu_events_map[i++]; if (!map->table) { map = NULL; break; } - if (regcomp(&re, map->cpuid, REG_EXTENDED) != 0) { - /* Warn unable to generate match particular string. */ - pr_info("Invalid regular expression %s\n", map->cpuid); + if (!strcmp_cpuid_str(map->cpuid, cpuid)) break; - } - - match = !regexec(&re, cpuid, 1, pmatch, 0); - regfree(&re); - if (match) { - size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); - - /* Verify the entire string matched. */ - if (match_len == strlen(cpuid)) - break; - } } free(cpuid); return map;