Skip to content

Commit 3b54411

Browse files
Kan Liangacmel
authored andcommitted
perf vendor events: Add stepping in CPUID string for x86
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 <[email protected]> Reviewed-by: Jiri Olsa <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent eb08d00 commit 3b54411

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

tools/perf/arch/x86/util/header.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55
#include <stdlib.h>
66
#include <string.h>
7+
#include <regex.h>
78

89
#include "../../util/header.h"
910

@@ -70,9 +71,72 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
7071
{
7172
char *buf = malloc(128);
7273

73-
if (buf && __get_cpuid(buf, 128, "%s-%u-%X$") < 0) {
74+
if (buf && __get_cpuid(buf, 128, "%s-%u-%X-%X$") < 0) {
7475
free(buf);
7576
return NULL;
7677
}
7778
return buf;
7879
}
80+
81+
/* Full CPUID format for x86 is vendor-family-model-stepping */
82+
static bool is_full_cpuid(const char *id)
83+
{
84+
const char *tmp = id;
85+
int count = 0;
86+
87+
while ((tmp = strchr(tmp, '-')) != NULL) {
88+
count++;
89+
tmp++;
90+
}
91+
92+
if (count == 3)
93+
return true;
94+
95+
return false;
96+
}
97+
98+
int strcmp_cpuid_str(const char *mapcpuid, const char *id)
99+
{
100+
regex_t re;
101+
regmatch_t pmatch[1];
102+
int match;
103+
bool full_mapcpuid = is_full_cpuid(mapcpuid);
104+
bool full_cpuid = is_full_cpuid(id);
105+
106+
/*
107+
* Full CPUID format is required to identify a platform.
108+
* Error out if the cpuid string is incomplete.
109+
*/
110+
if (full_mapcpuid && !full_cpuid) {
111+
pr_info("Invalid CPUID %s. Full CPUID is required, "
112+
"vendor-family-model-stepping\n", id);
113+
return 1;
114+
}
115+
116+
if (regcomp(&re, mapcpuid, REG_EXTENDED) != 0) {
117+
/* Warn unable to generate match particular string. */
118+
pr_info("Invalid regular expression %s\n", mapcpuid);
119+
return 1;
120+
}
121+
122+
match = !regexec(&re, id, 1, pmatch, 0);
123+
regfree(&re);
124+
if (match) {
125+
size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so);
126+
size_t cpuid_len;
127+
128+
/* If the full CPUID format isn't required,
129+
* ignoring the stepping.
130+
*/
131+
if (!full_mapcpuid && full_cpuid)
132+
cpuid_len = strrchr(id, '-') - id;
133+
else
134+
cpuid_len = strlen(id);
135+
136+
/* Verify the entire string matched. */
137+
if (match_len == cpuid_len)
138+
return 0;
139+
}
140+
141+
return 1;
142+
}

tools/perf/pmu-events/arch/x86/mapfile.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ GenuineIntel-6-2A,v15,sandybridge,core
3131
GenuineIntel-6-2C,v2,westmereep-dp,core
3232
GenuineIntel-6-25,v2,westmereep-sp,core
3333
GenuineIntel-6-2F,v2,westmereex,core
34-
GenuineIntel-6-55,v1,skylakex,core
34+
GenuineIntel-6-55-[01234],v1,skylakex,core

tools/perf/util/pmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
670670
* cpuid string generated on this platform.
671671
* Otherwise return non-zero.
672672
*/
673-
int strcmp_cpuid_str(const char *mapcpuid, const char *cpuid)
673+
int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid)
674674
{
675675
regex_t re;
676676
regmatch_t pmatch[1];

0 commit comments

Comments
 (0)