Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit d96aaeb

Browse files
sbeamerpalmer-dabbelt
authored andcommitted
make CSR_TIME return cycles to add determinism and remove dependency on clock_gettime
1 parent 16f6194 commit d96aaeb

File tree

2 files changed

+2
-27
lines changed

2 files changed

+2
-27
lines changed

sim/riscv/Makefile.in

-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ SIM_OBJS = \
3131
interp.o \
3232
machs.o \
3333
sim-main.o
34-
SIM_EXTRA_LIBS = -lrt
3534

3635
## COMMON_POST_CONFIG_FRAG

sim/riscv/sim-main.c

+2-26
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,8 @@ fetch_csr (SIM_CPU *cpu, const char *name, int csr, unsigned_word *reg)
8080
/* Allow certain registers only in respective modes. */
8181
case CSR_CYCLEH:
8282
case CSR_INSTRETH:
83-
RISCV_ASSERT_RV32 (cpu, "CSR: %s", name);
84-
break;
85-
86-
/* Load time regs on demand. */
8783
case CSR_TIMEH:
8884
RISCV_ASSERT_RV32 (cpu, "CSR: %s", name);
89-
case CSR_TIME:
90-
{
91-
struct timespec ts;
92-
93-
#if defined(CLOCK_BOOTTIME)
94-
if (clock_gettime (CLOCK_BOOTTIME, &ts) == 0)
95-
#else
96-
if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
97-
#endif
98-
99-
{
100-
uint64_t time = (uint64_t)ts.tv_sec * 1000 * 1000 + ts.tv_nsec;
101-
*reg = (csr == CSR_TIME) ? time : (time >> 32);
102-
}
103-
else
104-
{
105-
/* This shouldn't error, but it's cheap to be semi-sane. */
106-
*reg += 1;
107-
}
108-
}
10985
break;
11086
}
11187

@@ -569,12 +545,12 @@ execute_i (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op)
569545
break;
570546
case MATCH_RDTIME:
571547
TRACE_INSN (cpu, "rdtime %s;", rd_name);
572-
store_rd (cpu, rd, fetch_csr (cpu, "time", CSR_TIME, &cpu->csr.time));
548+
store_rd (cpu, rd, fetch_csr (cpu, "time", CSR_TIME, &cpu->csr.cycle));
573549
break;
574550
case MATCH_RDTIMEH:
575551
TRACE_INSN (cpu, "rdtimeh %s;", rd_name);
576552
RISCV_ASSERT_RV32 (cpu, "insn: %s", op->name);
577-
store_rd (cpu, rd, fetch_csr (cpu, "timeh", CSR_TIMEH, &cpu->csr.timeh));
553+
store_rd (cpu, rd, fetch_csr (cpu, "timeh", CSR_TIMEH, &cpu->csr.cycleh));
578554
break;
579555

580556
case MATCH_FENCE:

0 commit comments

Comments
 (0)