From 99d6d0a93f9c83b63343a00693d5085e3949fe1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Marques?= Date: Tue, 22 Oct 2019 17:56:54 +0100 Subject: Make performance counters always 64 bits wide (#178) This prevents the counters from easily overflowing for a 32-bit pk. --- pk/syscall.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'pk/syscall.c') diff --git a/pk/syscall.c b/pk/syscall.c index 8903ecc..07fa41d 100644 --- a/pk/syscall.c +++ b/pk/syscall.c @@ -16,14 +16,15 @@ typedef long (*syscall_t)(long, long, long, long, long, long, long); void sys_exit(int code) { 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); + uint64_t dt = rdtime64() - current.time0; + uint64_t dc = rdcycle64() - current.cycle0; + uint64_t di = rdinstret64() - current.instret0; + + printk("%lld ticks\n", dt); + printk("%lld cycles\n", dc); + printk("%lld instructions\n", di); + printk("%d.%d%d CPI\n", (int)(dc/di), (int)(10ULL*dc/di % 10), + (int)((100ULL*dc + di/2)/di % 10)); } shutdown(code); } @@ -353,7 +354,7 @@ int sys_rt_sigaction(int sig, const void* act, void* oact, size_t sssz) long sys_time(long* loc) { - uintptr_t t = rdcycle() / CLOCK_FREQ; + uint64_t t = rdcycle64() / CLOCK_FREQ; if (loc) *loc = t; return t; @@ -361,7 +362,7 @@ long sys_time(long* loc) int sys_times(long* loc) { - uintptr_t t = rdcycle(); + uint64_t t = rdcycle64(); kassert(CLOCK_FREQ % 1000000 == 0); loc[0] = t / (CLOCK_FREQ / 1000000); loc[1] = 0; @@ -373,7 +374,7 @@ int sys_times(long* loc) int sys_gettimeofday(long* loc) { - uintptr_t t = rdcycle(); + uint64_t t = rdcycle64(); loc[0] = t / CLOCK_FREQ; loc[1] = (t % CLOCK_FREQ) / (CLOCK_FREQ / 1000000); @@ -382,7 +383,7 @@ int sys_gettimeofday(long* loc) long sys_clock_gettime(int clk_id, long *loc) { - uintptr_t t = rdcycle(); + uint64_t t = rdcycle64(); loc[0] = t / CLOCK_FREQ; loc[1] = (t % CLOCK_FREQ) / (CLOCK_FREQ / 1000000000); -- cgit v1.1