perf vendor events: Add stepping in CPUID string for x86
authorKan Liang <kan.liang@linux.intel.com>
Wed, 14 Nov 2018 21:24:15 +0000 (13:24 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 22 Nov 2018 01:39:57 +0000 (22:39 -0300)
The perf tools cannot find the proper event list for the Cascadelake
server.  Because the Cascadelake server and the Skylake server have the
same CPU model number, which are used by the perf tools to find the
event list.

The stepping for Skylake server is up to 4.

The stepping for Cascadelake server starts from 5.

The stepping can be used to distinguish between them.

The stepping is added in get_cpuid_str().

The stepping information for Skylake server is updated in mapfile.csv.

A x86 specific strcmp_cpuid_cmp() function is added to handle two CPUID
formats in mapfile.csv, "vendor-family-model-stepping" and
"vendor-family-model":

- If a cpuid-regular-expression from the mapfile.csv using the new
  stepping format, a cpuid-string generated on the machine must include
  stepping. Otherwise, it is a mismatch.

- If the cpuid-regular-expression using the old non-stepping format,
  the stepping in the cpuid-string will be ignored.

The script, using environment string "PERF_CPUID" without stepping on
Skylake server, will be broken. If so, users must fix their scripts.

Committer notes:

Fixed this build error on centos:6 and debian:7:

  arch/x86/util/header.c: In function 'is_full_cpuid':
  arch/x86/util/header.c:82:39: error: declaration of 'cpuid' shadows a global declaration [-Werror=shadow]
  arch/x86/util/header.c:12:1: error: shadowed declaration is here [-Werror=shadow]
  arch/x86/util/header.c: In function 'strcmp_cpuid_str':
  arch/x86/util/header.c:98:56: error: declaration of 'cpuid' shadows a global declaration [-Werror=shadow]
  arch/x86/util/header.c:12:1: error: shadowed declaration is here [-Werror=shadow]
  cc1: all warnings being treated as errors

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20181114212416.15665-1-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/x86/util/header.c
tools/perf/pmu-events/arch/x86/mapfile.csv
tools/perf/util/pmu.c

index fb0d71afee8bb4a9d7680c09271f903894b31fa7..af9a9f2600be44217b60762043503ce9185d2fa3 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <regex.h>
 
 #include "../../util/header.h"
 
@@ -70,9 +71,72 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
 {
        char *buf = malloc(128);
 
-       if (buf && __get_cpuid(buf, 128, "%s-%u-%X$") < 0) {
+       if (buf && __get_cpuid(buf, 128, "%s-%u-%X-%X$") < 0) {
                free(buf);
                return NULL;
        }
        return buf;
 }
+
+/* Full CPUID format for x86 is vendor-family-model-stepping */
+static bool is_full_cpuid(const char *id)
+{
+       const char *tmp = id;
+       int count = 0;
+
+       while ((tmp = strchr(tmp, '-')) != NULL) {
+               count++;
+               tmp++;
+       }
+
+       if (count == 3)
+               return true;
+
+       return false;
+}
+
+int strcmp_cpuid_str(const char *mapcpuid, const char *id)
+{
+       regex_t re;
+       regmatch_t pmatch[1];
+       int match;
+       bool full_mapcpuid = is_full_cpuid(mapcpuid);
+       bool full_cpuid = is_full_cpuid(id);
+
+       /*
+        * Full CPUID format is required to identify a platform.
+        * Error out if the cpuid string is incomplete.
+        */
+       if (full_mapcpuid && !full_cpuid) {
+               pr_info("Invalid CPUID %s. Full CPUID is required, "
+                       "vendor-family-model-stepping\n", id);
+               return 1;
+       }
+
+       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, id, 1, pmatch, 0);
+       regfree(&re);
+       if (match) {
+               size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so);
+               size_t cpuid_len;
+
+               /* If the full CPUID format isn't required,
+                * ignoring the stepping.
+                */
+               if (!full_mapcpuid && full_cpuid)
+                       cpuid_len = strrchr(id, '-') - id;
+               else
+                       cpuid_len = strlen(id);
+
+               /* Verify the entire string matched. */
+               if (match_len == cpuid_len)
+                       return 0;
+       }
+
+       return 1;
+}
index 7e3cce3bcf3b8c69bb0553c4caf700b81bb2e1bd..183a42c99251e7cadfdf2a7121fc6b9aff071c96 100644 (file)
@@ -31,4 +31,4 @@ GenuineIntel-6-2A,v15,sandybridge,core
 GenuineIntel-6-2C,v2,westmereep-dp,core
 GenuineIntel-6-25,v2,westmereep-sp,core
 GenuineIntel-6-2F,v2,westmereex,core
-GenuineIntel-6-55,v1,skylakex,core
+GenuineIntel-6-55-[01234],v1,skylakex,core
index 7348eea0248fdbbe9bbbbf78adbc49f8ee624471..c660625d7d4bb1349113e9fa78fc060338a8e4dc 100644 (file)
@@ -670,7 +670,7 @@ char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
  * cpuid string generated on this platform.
  * Otherwise return non-zero.
  */
-int strcmp_cpuid_str(const char *mapcpuid, const char *cpuid)
+int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid)
 {
        regex_t re;
        regmatch_t pmatch[1];