risc-v: Implement benchmark timestamp

Implements timestamp function used by benchmark logging utilities.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
Signed-off-by: Curtis Millar <curtis@curtism.me>
This commit is contained in:
Curtis Millar 2020-09-10 10:50:36 +10:00 committed by Curtis Millar
parent a00c2c16cf
commit e4b5099cbc
No known key found for this signature in database
GPG key ID: 836B6EBF7E3C490A
4 changed files with 35 additions and 1 deletions

View file

@ -79,5 +79,24 @@ static inline uint64_t riscv_read_time(void)
return ((uint64_t)((uint64_t) nH1 << 32)) | (nL);
}
static inline uint64_t riscv_read_cycle(void)
{
uint32_t nH1, nL, nH2;
asm volatile(
"rdcycleh %0\n"
"rdcycle %1\n"
"rdcycleh %2\n"
: "=r"(nH1), "=r"(nL), "=r"(nH2));
if (nH1 != nH2) {
/* Ensure that the time is correct if there is a rollover in the
* high bits between reading the low and high bits. */
asm volatile(
"rdcycle %0\n"
: "=r"(nL));
nH1 = nH2;
}
return ((uint64_t)((uint64_t) nH1 << 32)) | (nL);
}
#endif /* __ASSEMBLER__ */

View file

@ -121,5 +121,14 @@ static inline uint64_t riscv_read_time(void)
return n;
}
static inline uint64_t riscv_read_cycle(void)
{
uint64_t n;
asm volatile(
"rdcycle %0"
: "=r"(n));
return n;
}
#endif /* __ASSEMBLER__ */

View file

@ -9,8 +9,12 @@
#include <config.h>
#include <arch/object/structures.h>
#include <mode/hardware.h>
#ifdef CONFIG_ENABLE_BENCHMARK
#error "RISC-V doesn't support timestamp() function yet"
static inline timestamp_t timestamp(void)
{
return riscv_read_cycle();
}
#endif /* CONFIG_ENABLE_BENCHMARK */

View file

@ -33,6 +33,8 @@ typedef node_id_t seL4_NodeId;
typedef paddr_t seL4_PAddr;
typedef dom_t seL4_Domain;
typedef uint64_t timestamp_t;
#define wordBits BIT(wordRadix)
typedef struct kernel_frame {