Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 8c2fb12

Browse files
committed
tools/perf: use get_cpuid instead of proc/cpuinfo
Signed-off-by: Bobo <[email protected]>
1 parent 082757c commit 8c2fb12

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

tools/perf/util/arm-spe.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "arm-spe.h"
3434
#include "arm-spe-decoder/arm-spe-decoder.h"
3535
#include "arm-spe-decoder/arm-spe-pkt-decoder.h"
36+
#include "../../arch/arm64/include/asm/cputype.h"
3637

3738
#define MAX_TIMESTAMP (~0ULL)
3839

@@ -358,6 +359,13 @@ static u64 arm_spe__synth_data_source(const struct arm_spe_record *record)
358359
return data_src.val;
359360
}
360361

362+
static const struct midr_range neoverse_spe[] = {
363+
MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1),
364+
MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2),
365+
MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1),
366+
{},
367+
};
368+
361369
static const char *hw_dsrc_altra_translate(union perf_mem_data_src data_src)
362370
{
363371
/* arm-spe has valid hardware data source in load operation only */
@@ -388,34 +396,18 @@ static const char *hw_dsrc_altra_translate(union perf_mem_data_src data_src)
388396

389397
const char *hw_dsrc_translate(union perf_mem_data_src data_src)
390398
{
391-
FILE *file;
392-
size_t len;
393-
long int cpu_impl = LONG_MAX;
394-
const char *search = "CPU implementer";
395-
char *start = NULL, *buf = NULL;
396-
397-
file = fopen("/proc/cpuinfo", "r");
398-
if (!file)
399-
return NULL;
399+
static u64 midr = 0;
400400

401-
while (getline(&buf, &len, file) > 0) {
402-
if (!strncmp(buf, search, strlen(search))) {
403-
start = strchr(buf, ':');
404-
break;
405-
}
406-
}
407-
fclose(file);
401+
if (!midr) {
402+
char cpuid[128];
408403

409-
if (start)
410-
cpu_impl = strtol(start + 1, NULL, 16);
411-
free(buf);
412-
413-
switch (cpu_impl) {
414-
case 0x41: // ARM or Altra
415-
return hw_dsrc_altra_translate(data_src);
416-
default:
417-
break;
404+
if (get_cpuid(cpuid, sizeof(cpuid)))
405+
return NULL;
406+
midr = strtol(cpuid, NULL, 16);
418407
}
408+
409+
if (is_midr_in_range(midr, neoverse_spe))
410+
return hw_dsrc_altra_translate(data_src);
419411
return NULL;
420412
}
421413

0 commit comments

Comments
 (0)