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

adding riscv cycle counter #348

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
adding riscv cycle counter
ct-clmsn committed Mar 5, 2024
commit 918f6a414ee20a62bee2f02daa78c4a7579b35f8
22 changes: 22 additions & 0 deletions kernel/cycle.h
Original file line number Diff line number Diff line change
@@ -562,3 +562,25 @@ static inline ticks getticks(void)
INLINE_ELAPSED(inline)
#define HAVE_TICK_COUNTER
#endif

/*----------------------------------------------------------------*/
/*
* RISC_V 64-bit cycle counter (RV64G)
*/
#if defined(__riscv) && (__riscv_xlen == 64) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long ticks;

static __inline__ ticks getticks(void)
{
ticks ret;

__asm__ __volatile__ ("csrrs %0, 0xc00, x0" : "=r" (ret) );

/* no input, nothing else clobbered */
return ret;
}

INLINE_ELAPSED(inline)

#define HAVE_TICK_COUNTER
#endif