aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-08-10 12:46:09 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-08-10 12:46:09 -0700
commit0a7862c79ffcf931d5369d50b15774cc1ec8f396 (patch)
tree8e703ef3164e19938b773982094373e6c8f10ea2
parent7520a474199df8b9ef7cee32eebcea7577813814 (diff)
downloadriscv-pk-0a7862c79ffcf931d5369d50b15774cc1ec8f396.zip
riscv-pk-0a7862c79ffcf931d5369d50b15774cc1ec8f396.tar.gz
riscv-pk-0a7862c79ffcf931d5369d50b15774cc1ec8f396.tar.bz2
when -s is passed, print time, instret, cycle, and CPI
-rw-r--r--pk/boot.h4
-rw-r--r--pk/pk.c9
-rw-r--r--pk/syscall.c12
3 files changed, 19 insertions, 6 deletions
diff --git a/pk/boot.h b/pk/boot.h
index d2a619d..f16ab15 100644
--- a/pk/boot.h
+++ b/pk/boot.h
@@ -20,7 +20,9 @@ typedef struct {
size_t brk_max;
size_t mmap_max;
size_t stack_top;
- size_t t0;
+ size_t time0;
+ size_t cycle0;
+ size_t instret0;
} elf_info;
extern elf_info current;
diff --git a/pk/pk.c b/pk/pk.c
index 45fad14..954bcb3 100644
--- a/pk/pk.c
+++ b/pk/pk.c
@@ -13,7 +13,7 @@ static void handle_option(const char* s)
switch (s[1])
{
case 's': // print cycle count upon termination
- current.t0 = 1;
+ current.cycle0 = 1;
break;
default:
@@ -105,8 +105,11 @@ static void run_loaded_program(size_t argc, char** argv, uintptr_t kstack_top)
STACK_INIT(uintptr_t);
- if (current.t0) // start timer if so requested
- current.t0 = rdcycle();
+ if (current.cycle0) { // start timer if so requested
+ current.time0 = rdtime();
+ current.cycle0 = rdcycle();
+ current.instret0 = rdinstret();
+ }
trapframe_t tf;
init_tf(&tf, current.entry, stack_top);
diff --git a/pk/syscall.c b/pk/syscall.c
index 8d9a661..85139e4 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -15,8 +15,16 @@ typedef long (*syscall_t)(long, long, long, long, long, long, long);
void sys_exit(int code)
{
- if (current.t0)
- printk("%ld cycles\n", rdcycle() - current.t0);
+ if (current.cycle0) {
+ size_t dt = rdtime() - current.time0;
+ size_t dc = rdcycle() - current.cycle0;
+ size_t di = rdinstret() - current.instret0;
+
+ printk("%ld ticks\n", dt);
+ printk("%ld cycles\n", dc);
+ printk("%ld instructions\n", di);
+ printk("%d.%d%d CPI\n", dc/di, 10ULL*dc/di % 10, (100ULL*dc + di/2)/di % 10);
+ }
shutdown(code);
}