1/* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#pragma once 8 9#ifdef CONFIG_KERNEL_MCS 10 11#include <types.h> 12#include <mode/util.h> 13#include <arch/sbi.h> 14#include <arch/machine/hardware.h> 15 16/* The scheduler clock is greater than 1MHz */ 17#define TICKS_IN_US (TIMER_CLOCK_HZ / (US_IN_MS * MS_IN_S)) 18 19static inline CONST time_t getKernelWcetUs(void) 20{ 21 /* Copied from x86_64. Hopefully it's an overestimate here. */ 22 return 10u; 23} 24 25static inline PURE ticks_t usToTicks(time_t us) 26{ 27 return us * TICKS_IN_US; 28} 29 30static inline PURE time_t ticksToUs(ticks_t ticks) 31{ 32 return div64(ticks, TICKS_IN_US); 33} 34 35static inline PURE ticks_t getTimerPrecision(void) 36{ 37 return usToTicks(1); 38} 39 40static inline CONST ticks_t getMaxTicksToUs(void) 41{ 42 return UINT64_MAX / TICKS_IN_US; 43} 44 45static inline PURE time_t getMaxUsToTicks(void) 46{ 47 return usToTicks(getMaxTicksToUs()); 48} 49 50/* Read the current time from the timer. */ 51static inline ticks_t getCurrentTime(void) 52{ 53 return riscv_read_time(); 54} 55 56/* set the next deadline irq - deadline is absolute */ 57static inline void setDeadline(ticks_t deadline) 58{ 59 assert(deadline > NODE_STATE(ksCurTime)); 60 /* Setting the timer acknowledges any existing IRQs */ 61 sbi_set_timer(deadline); 62} 63 64/* ack previous deadline irq */ 65static inline void ackDeadlineIRQ(void) 66{ 67} 68 69#endif /* CONFIG_KERNEL_MCS */ 70