Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Nov 2019 18:50:33 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
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
Message-ID:  <201911281850.xASIoXGv004337@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <stddef.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <regex.h>
 #include <string.h>
 #include <pmc.h>
 #include <pmclog.h>
@@ -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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911281850.xASIoXGv004337>