aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmarks/common/syscalls.c9
-rw-r--r--benchmarks/common/util.h4
2 files changed, 12 insertions, 1 deletions
diff --git a/benchmarks/common/syscalls.c b/benchmarks/common/syscalls.c
index 0a7d6b7..47d889d 100644
--- a/benchmarks/common/syscalls.c
+++ b/benchmarks/common/syscalls.c
@@ -33,7 +33,7 @@ static uintptr_t syscall(uintptr_t which, uint64_t arg0, uint64_t arg1, uint64_t
return magic_mem[0];
}
-#define NUM_COUNTERS 2
+#define NUM_COUNTERS 4
static uintptr_t counters[NUM_COUNTERS];
static char* counter_names[NUM_COUNTERS];
@@ -47,8 +47,15 @@ void setStats(int enable)
counters[i++] = csr; \
} while (0)
+ if (enable) {
+ write_csr(mhpmevent3, 0x0401);
+ write_csr(mhpmevent4, 0x2001);
+ }
+
READ_CTR(mcycle);
READ_CTR(minstret);
+ READ_CTR(mhpmcounter3);
+ READ_CTR(mhpmcounter4);
#undef READ_CTR
}
diff --git a/benchmarks/common/util.h b/benchmarks/common/util.h
index 081cfd6..70bd06e 100644
--- a/benchmarks/common/util.h
+++ b/benchmarks/common/util.h
@@ -80,11 +80,15 @@ static uintptr_t insn_len(uintptr_t pc)
#define stringify(s) stringify_1(s)
#define stats(code, iter) do { \
unsigned long _c = -read_csr(mcycle), _i = -read_csr(minstret); \
+ unsigned long _b = -read_csr(hpmcounter9), _m = -read_csr(hpmcounter24); \
code; \
_c += read_csr(mcycle), _i += read_csr(minstret); \
+ _b += read_csr(hpmcounter9), _m += read_csr(hpmcounter24); \
if (cid == 0) \
printf("\n%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
stringify(code), _c, _c/iter, 10*_c/iter%10, _c/_i, 10*_c/_i%10); \
+ printf("%ld branches, %ld mispredicts, %ld.%ld mispredict rate\n", \
+ _b, _m, _m/_b, (10*_m/_b)%10); \
} while(0)
#endif //__UTIL_H