diff options
author | Yunsup Lee <yunsup@cs.berkeley.edu> | 2013-04-29 18:44:21 -0700 |
---|---|---|
committer | Yunsup Lee <yunsup@cs.berkeley.edu> | 2013-04-29 18:44:21 -0700 |
commit | 23507d668862dff15a898f20e109a46c6e95780d (patch) | |
tree | a3b620e117c1ded337e9508042e353c62a1a97a8 /benchmarks/common/util.h | |
parent | f8ea498f79ab4d6495f2966d1e5c3dd42f567752 (diff) | |
download | riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.zip riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.gz riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.bz2 |
benchmarks initial commit
Diffstat (limited to 'benchmarks/common/util.h')
-rw-r--r-- | benchmarks/common/util.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/benchmarks/common/util.h b/benchmarks/common/util.h new file mode 100644 index 0000000..83b2b6c --- /dev/null +++ b/benchmarks/common/util.h @@ -0,0 +1,32 @@ +// helpful utility and synch functions + +// relies on defining "ncores" before including this file... + +#ifndef __UTIL_H +#define __UTIL_H + +#define rdcycle() ({ unsigned long _c; asm volatile ("rdcycle %0" : "=r"(_c) :: "memory"); _c; }) +#define rdinstret() ({ unsigned long _c; asm volatile ("rdinstret %0" : "=r"(_c) :: "memory"); _c; }) + +void __attribute__((noinline)) barrier() +{ + static volatile int sense; + static volatile int count; + static __thread int threadsense; + + __sync_synchronize(); + + threadsense = !threadsense; + if (__sync_fetch_and_add(&count, 1) == ncores-1) + { + count = 0; + sense = threadsense; + } + else while(sense != threadsense) + ; + + __sync_synchronize(); +} + +#endif //__UTIL_H + |