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

[patch-axel-26] inline RESET_CYCLES #125

Open
wants to merge 3 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
31 changes: 19 additions & 12 deletions src/arch/riscv/machine/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#include <arch/machine.h>
#include <arch/smp/ipi.h>

#ifndef CONFIG_KERNEL_MCS
#define RESET_CYCLES ((TIMER_CLOCK_HZ / MS_IN_S) * CONFIG_TIMER_TICK_MS)
#endif /* !CONFIG_KERNEL_MCS */

#define IS_IRQ_VALID(X) (((X)) <= maxIRQ && (X) != irqInvalid)

word_t PURE getRestartPC(tcb_t *thread)
Expand Down Expand Up @@ -224,21 +220,32 @@ static inline void ackInterrupt(irq_t irq)
#ifndef CONFIG_KERNEL_MCS
void resetTimer(void)
{
uint64_t target;
// repeatedly try and set the timer in a loop as otherwise there is a race and we
// may set a timeout in the past, resulting in it never getting triggered
do {
target = riscv_read_time() + RESET_CYCLES;
sbi_set_timer(target);
} while (riscv_read_time() > target);
/* timer must be > 1 kHz */
SEL4_COMPILE_ASSERT(timer_clock_1mhz, TIMER_CLOCK_HZ > 1000);
const uint64_t ticks_per_ms = TIMER_CLOCK_HZ / MS_IN_S;
const uint64_t delta = ticks_per_ms * CONFIG_TIMER_TICK_MS;
uint64_t target = riscv_read_time() + delta;
sbi_set_timer(target);
#if defined(CONFIG_PLAT_QEMU_RISCV_VIRT) || defined(CONFIG_PLAT_SPIKE)
/* Perform a sanity check that the margin is big enough that we end up
* with a timestamp in the future. Seems it happened in QEMU that the
* simulation was too slow.
*/
uint64_t now = riscv_read_time();
if (likely(now >= target)) {
printf("Timer reset failed, %"PRIu64" (now) >= %"PRIu64"\n", now, target);
fail("Timer reset failed");
UNREACHABLE();
}
#endif
}

/**
DONT_TRANSLATE
*/
BOOT_CODE void initTimer(void)
{
sbi_set_timer(riscv_read_time() + RESET_CYCLES);
resetTimer();
}
#endif /* !CONFIG_KERNEL_MCS */

Expand Down
Loading