Received: by 10.223.185.116 with SMTP id b49csp3753537wrg; Tue, 13 Feb 2018 07:16:10 -0800 (PST) X-Google-Smtp-Source: AH8x2276JW7O9rQJwiFr2UBkyK/dQKlR3gPuaN/n0jasYpGDmfmkf/ObfNM7mWMrUdd1iSFVmy1x X-Received: by 10.101.64.193 with SMTP id u1mr1296114pgp.24.1518534970628; Tue, 13 Feb 2018 07:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518534970; cv=none; d=google.com; s=arc-20160816; b=Wjfo1vSGF+UbN7J+dwB2lDfh7UraaOVrFomWTBSmdlbgeCNqT7QRXYa5BdAXYWppM5 V1Do8DNjJmTxH2mYdasB5WU7XtBZci//uvX+keuRYlOp408mra/aiWVkGG0kYFoXOkQ8 4edWPa4hTbr6MdMLQdme5WdiM/h8Oimi9AJTRjT2oq7WTIOcOHL/zzZloN5oGDdp2Yjq u3yr+oblL1PxnAlMKCNTZxWVcmDJqu0QjfdEiTs47wWuwRxohYvnYNOBmwa9c7FezIJE wZeTA40oa8lCB9yr6uL77SzLxbbigg+b0y2MMN0JBacg0ad8tEs/3kL8YewNh5BDUbG5 TTAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=ViPE8mox6tNsjLC+9dkladBhjMhAZ5Oce9mrHQ2oyGM=; b=DkZUWG8Af+g1yeE10XYKx2mycz0UTbNkZ+cbCBfNTHnPRI5zSJwZ63xX4ZbUgF57Fh krgIgPVO9miwWZsAzjJ+4xcQUySbQ15IVK0G4ag1ObkJD2RlxicRMWBBfFvaHTj9IWhc aLaxgmLsK/kpDhnByei3SrpvE7qhrGBAPeN8kwxonpinsXwtzBHmNtTkTXNMqVwIIrI6 vBno6IDvGs5oueTdEodzxAwm7xKEYQBvDrw3KdeeTgqgRCI+0r5fshJj+6BPG/9btVRi 4z/4snwBhzBikuJKC2P3x14u5s/4pcQ+SMzcor2u03QKkpwJJhHjVL+K7Wbg4lnYWqp1 l7IQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w74si19121pfj.89.2018.02.13.07.15.56; Tue, 13 Feb 2018 07:16:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965259AbeBMPPA (ORCPT + 99 others); Tue, 13 Feb 2018 10:15:00 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46984 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965215AbeBMPOi (ORCPT ); Tue, 13 Feb 2018 10:14:38 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1DFBxwp054359 for ; Tue, 13 Feb 2018 10:14:38 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2g3wjr5bkg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 13 Feb 2018 10:14:38 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Feb 2018 15:14:36 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Feb 2018 15:14:33 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1DFEXRH46858300; Tue, 13 Feb 2018 15:14:33 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E109711C06C; Tue, 13 Feb 2018 15:07:46 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF4ED11C052; Tue, 13 Feb 2018 15:07:46 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 13 Feb 2018 15:07:46 +0000 (GMT) From: Thomas Richter To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, Thomas Richter Subject: [PATCH 3/4] perf cpuid: Introduce a platform specfic cpuid compare function Date: Tue, 13 Feb 2018 16:14:18 +0100 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180213151419.80737-1-tmricht@linux.vnet.ibm.com> References: <20180213151419.80737-1-tmricht@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18021315-0020-0000-0000-000003F53CCE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18021315-0021-0000-0000-00004287C8DD Message-Id: <20180213151419.80737-3-tmricht@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-13_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802130180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 3d29ba47edce..90360272ced6 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -142,3 +142,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 f28aaaa3a440..942bdec6d70d 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 57e38fdf0b34..1111d5bf15ca 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; -- 2.14.3