Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Riscv cyclecounter #361

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions kernel/cycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,28 @@ static inline ticks getticks(void)
INLINE_ELAPSED(inline)
#define HAVE_TICK_COUNTER
#endif

#if defined(__riscv_xlen) && !defined(HAVE_TICK_COUNTER)
typedef uint64_t ticks;
static inline ticks getticks(void)
{
uint64_t result;
#if __riscv_xlen == 64
asm volatile("rdtime %0" : "=r" (result));
#elif __riscv_xlen == 32
uint32_t l, h, h2;
asm volatile( "start:\n"
"rdtimeh %0\n"
"rdtime %1\n"
"rdtimeh %2\n"
"bne %0, %2, start\n"
: "=r" (h), "=r" (l), "=r" (h2));
result = (((uint64_t)h)<<32) | ((uint64_t)l);
#else
#error "unknown __riscv_xlen"
#endif
return result;
}
INLINE_ELAPSED(inline)
#define HAVE_TICK_COUNTER
#endif