aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorChristopher Celio <celio@eecs.berkeley.edu>2014-08-07 18:44:48 -0700
committerChristopher Celio <celio@eecs.berkeley.edu>2014-08-07 18:44:48 -0700
commit5eba64df88be49c4f2aaddeda3f3f81d7b4b34f3 (patch)
tree0f59124bce23058795d55dc5fba6937a9a02e3ce /pk
parent929d2f0109570a84f9455b153d2547b172b0ac01 (diff)
downloadriscv-pk-5eba64df88be49c4f2aaddeda3f3f81d7b4b34f3.zip
riscv-pk-5eba64df88be49c4f2aaddeda3f3f81d7b4b34f3.tar.gz
riscv-pk-5eba64df88be49c4f2aaddeda3f3f81d7b4b34f3.tar.bz2
Added "-c" option to track uarch counter info.
Diffstat (limited to 'pk')
-rw-r--r--pk/init.c26
-rw-r--r--pk/pk.h5
-rw-r--r--pk/syscall.c24
3 files changed, 55 insertions, 0 deletions
diff --git a/pk/init.c b/pk/init.c
index df9df6d..e6a97c3 100644
--- a/pk/init.c
+++ b/pk/init.c
@@ -13,6 +13,10 @@ int have_vm = 1; // unless -p flag is given
int have_fp;
int have_accelerator;
+int uarch_counters_enabled;
+long uarch_counters[NUM_COUNTERS];
+char* uarch_counter_names[NUM_COUNTERS];
+
void init_tf(trapframe_t* tf, long pc, long sp, int user64)
{
memset(tf,0,sizeof(*tf));
@@ -33,6 +37,11 @@ static void handle_option(const char* s)
current.t0 = 1;
break;
+ case 'c': // print uarch counters upon termination
+ // If your HW doesn't support uarch counters, then don't use this flag!
+ uarch_counters_enabled = 1;
+ break;
+
case 'p': // physical memory mode
have_vm = 0;
break;
@@ -122,6 +131,23 @@ static void user_init(struct mainvars* args)
if (current.t0) // start timer if so requested
current.t0 = rdcycle();
+ if (uarch_counters_enabled) { // start tracking the uarch counters if requested
+ size_t i = 0;
+ #define READ_CTR_INIT(name) do { \
+ while (i >= NUM_COUNTERS) ; \
+ long csr = read_csr(name); \
+ uarch_counters[i++] = csr; \
+ } while (0)
+ READ_CTR_INIT(cycle); READ_CTR_INIT(instret);
+ READ_CTR_INIT(uarch0); READ_CTR_INIT(uarch1); READ_CTR_INIT(uarch2);
+ READ_CTR_INIT(uarch3); READ_CTR_INIT(uarch4); READ_CTR_INIT(uarch5);
+ READ_CTR_INIT(uarch6); READ_CTR_INIT(uarch7); READ_CTR_INIT(uarch8);
+ READ_CTR_INIT(uarch9); READ_CTR_INIT(uarch10); READ_CTR_INIT(uarch11);
+ READ_CTR_INIT(uarch12); READ_CTR_INIT(uarch13); READ_CTR_INIT(uarch14);
+ READ_CTR_INIT(uarch15);
+ #undef READ_CTR_INIT
+ }
+
trapframe_t tf;
init_tf(&tf, current.entry, stack_top, current.elf64);
__clear_cache(0, 0);
diff --git a/pk/pk.h b/pk/pk.h
index 282530c..e7a8d8e 100644
--- a/pk/pk.h
+++ b/pk/pk.h
@@ -82,6 +82,11 @@ static inline int insn_len(long insn)
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+#define NUM_COUNTERS (18)
+extern int uarch_counters_enabled;
+extern long uarch_counters[NUM_COUNTERS];
+extern char* uarch_counter_names[NUM_COUNTERS];
+
#ifdef __cplusplus
}
#endif
diff --git a/pk/syscall.c b/pk/syscall.c
index 338ac74..f32bbe1 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -27,6 +27,30 @@ void sys_exit(int code)
if (current.t0)
printk("%ld cycles\n", rdcycle() - current.t0);
+ if (uarch_counters_enabled) {
+ size_t i = 0;
+ #define READ_CTR_FINI(name) do { \
+ while (i >= NUM_COUNTERS) ; \
+ long csr = read_csr(name); \
+ csr -= uarch_counters[i]; uarch_counter_names[i] = #name; \
+ uarch_counters[i++] = csr; \
+ } while (0)
+ READ_CTR_FINI(cycle); READ_CTR_FINI(instret);
+ READ_CTR_FINI(uarch0); READ_CTR_FINI(uarch1); READ_CTR_FINI(uarch2);
+ READ_CTR_FINI(uarch3); READ_CTR_FINI(uarch4); READ_CTR_FINI(uarch5);
+ READ_CTR_FINI(uarch6); READ_CTR_FINI(uarch7); READ_CTR_FINI(uarch8);
+ READ_CTR_FINI(uarch9); READ_CTR_FINI(uarch10); READ_CTR_FINI(uarch11);
+ READ_CTR_FINI(uarch12); READ_CTR_FINI(uarch13); READ_CTR_FINI(uarch14);
+ READ_CTR_FINI(uarch15);
+ #undef READ_CTR_FINI
+
+ for (int i = 0; i < NUM_COUNTERS; i++) {
+ if (uarch_counters[i]) {
+ printk("%s = %d\n", uarch_counter_names[i], uarch_counters[i]);
+ }
+ }
+ }
+
frontend_syscall(SYS_exit, code, 0, 0, 0, 0);
clear_csr(status, SR_EI);
while (1);