From owner-svn-src-stable@freebsd.org Thu Nov 28 18:50:33 2019 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E949C1B364C; Thu, 28 Nov 2019 18:50:33 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47P6CY5whRz3RFg; Thu, 28 Nov 2019 18:50:33 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AF87B2015; Thu, 28 Nov 2019 18:50:33 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xASIoXbf004338; Thu, 28 Nov 2019 18:50:33 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xASIoXGv004337; Thu, 28 Nov 2019 18:50:33 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201911281850.xASIoXGv004337@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Thu, 28 Nov 2019 18:50:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r355184 - stable/12/lib/libpmc X-SVN-Group: stable-12 X-SVN-Commit-Author: manu X-SVN-Commit-Paths: stable/12/lib/libpmc X-SVN-Commit-Revision: 355184 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Nov 2019 18:50:34 -0000 Author: manu Date: Thu Nov 28 18:50:33 2019 New Revision: 355184 URL: https://svnweb.freebsd.org/changeset/base/355184 Log: MFC r354549-r354550 r354549: libpmc: Match on the cpuid with a regex The CPUID is, or can be, a regex to be matched. Use regex from libc instead of strcmp Tested-by: gallatin r354550: libpmc: Forgot regex.h Reported by: ci X-MFC-With: r354549 Modified: stable/12/lib/libpmc/libpmc_pmu_util.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libpmc/libpmc_pmu_util.c ============================================================================== --- stable/12/lib/libpmc/libpmc_pmu_util.c Thu Nov 28 18:44:06 2019 (r355183) +++ stable/12/lib/libpmc/libpmc_pmu_util.c Thu Nov 28 18:50:33 2019 (r355184) @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -165,8 +166,11 @@ struct pmu_event_desc { static const struct pmu_events_map * pmu_events_map_get(const char *cpuid) { - size_t s; + regex_t re; + regmatch_t pmatch[1]; + size_t s, len; char buf[64]; + int match; const struct pmu_events_map *pme; if (cpuid != NULL) { @@ -179,9 +183,20 @@ pmu_events_map_get(const char *cpuid) (void *)NULL, 0) == -1) return (NULL); } - for (pme = pmu_events_map; pme->cpuid != NULL; pme++) - if (strcmp(buf, pme->cpuid) == 0) - return (pme); + for (pme = pmu_events_map; pme->cpuid != NULL; pme++) { + if (regcomp(&re, pme->cpuid, REG_EXTENDED) != 0) { + printf("regex '%s' failed to compile, ignoring\n", + pme->cpuid); + continue; + } + match = regexec(&re, buf, 1, pmatch, 0); + regfree(&re); + if (match == 0) { + len = pmatch[0].rm_eo - pmatch[0].rm_so; + if(len == strlen(buf)) + return (pme); + } + } return (NULL); }