aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoward Mao <zhehao.mao@gmail.com>2018-03-01 14:58:58 -0800
committerHoward Mao <zhehao.mao@gmail.com>2018-03-01 14:58:58 -0800
commitecbb5a6cc530a98a6fe4d28c5ac1b0c891b11cb3 (patch)
treed6598be03012e586110144d4b27a53c4a594606a
parentffa920340430f62e767fb2397f4ee41ffaf441ce (diff)
downloadriscv-tests-cs152-sp18-lab3.zip
riscv-tests-cs152-sp18-lab3.tar.gz
riscv-tests-cs152-sp18-lab3.tar.bz2
read branch count and mispredicts in setStatscs152-sp18-lab3
-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