Author: manu
Date: Fri Nov  8 16:56:48 2019
New Revision: 354549
URL: https://svnweb.freebsd.org/changeset/base/354549

Log:
  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
  MFC after:    1 week

Modified:
  head/lib/libpmc/libpmc_pmu_util.c

Modified: head/lib/libpmc/libpmc_pmu_util.c
==============================================================================
--- head/lib/libpmc/libpmc_pmu_util.c   Fri Nov  8 16:30:55 2019        
(r354548)
+++ head/lib/libpmc/libpmc_pmu_util.c   Fri Nov  8 16:56:48 2019        
(r354549)
@@ -165,8 +165,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 +182,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);
 }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to