From 4d93b401c5d1eedeb382fcf1b2065a0835b9de5c Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 3 Aug 2021 18:48:22 -0400 Subject: [PATCH 1/2] Trying to enable cache miss tracking under AMD. --- benchmarks/bulk-insert-and-query.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/benchmarks/bulk-insert-and-query.cc b/benchmarks/bulk-insert-and-query.cc index 1aa538a..abc3b0d 100644 --- a/benchmarks/bulk-insert-and-query.cc +++ b/benchmarks/bulk-insert-and-query.cc @@ -153,6 +153,28 @@ struct samples { }; typedef struct samples samples_t; +#ifdef __linux__ +bool is_amd() { + FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); + if(cpuinfo == NULL) { return false; } + char line[256]; + while(fgets(line, 256, cpuinfo) { + if(strncmp(line, "vendor_id", 9) == 0) { + char *colon = strchr(line, ':'); + if(colon == NULL || colon[1] == 0) { + fclose(cpuinfo); + return false; + } + const char * target = "AuthenticAMD"; + bool answer = (strncmp(colon + 2, target, strlen(target)) == 0); + fclose(cpuinfo); + return answer; + } + } + fclose(cpuinfo); + return false; +} +#endif template Statistics FilterBenchmark( @@ -169,7 +191,8 @@ Statistics FilterBenchmark( vector evts; evts.push_back(PERF_COUNT_HW_CPU_CYCLES); evts.push_back(PERF_COUNT_HW_INSTRUCTIONS); - evts.push_back(PERF_COUNT_HW_CACHE_MISSES); + // patch: https://lore.kernel.org/patchwork/patch/222439/ + evts.push_back(is_amd() ? 0x037E : PERF_COUNT_HW_CACHE_MISSES); evts.push_back(PERF_COUNT_HW_BRANCH_MISSES); LinuxEvents unified(evts); vector results; From 0d4b2401cae89477a3e9879317cb6dbdf59f9057 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 3 Aug 2021 18:48:51 -0400 Subject: [PATCH 2/2] Tweak. --- benchmarks/bulk-insert-and-query.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bulk-insert-and-query.cc b/benchmarks/bulk-insert-and-query.cc index abc3b0d..76ee421 100644 --- a/benchmarks/bulk-insert-and-query.cc +++ b/benchmarks/bulk-insert-and-query.cc @@ -158,7 +158,7 @@ bool is_amd() { FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); if(cpuinfo == NULL) { return false; } char line[256]; - while(fgets(line, 256, cpuinfo) { + while(fgets(line, 256, cpuinfo)) { if(strncmp(line, "vendor_id", 9) == 0) { char *colon = strchr(line, ':'); if(colon == NULL || colon[1] == 0) {