mcs: Avoid missing a timer tick

Preemption can be via the timer interrupt. In this case we need to
update the timestamp so we can reprogram the timer for the next timeout
and guarantee it is in the future, otherwise we will end up setting a
timeout in the past.
This commit is contained in:
Anna Lyons 2019-05-09 16:04:32 +10:00 committed by Kent Mcleod
parent b358a1c59c
commit 86e50d0703
3 changed files with 7 additions and 3 deletions

View file

@ -209,14 +209,12 @@ void chargeBudget(ticks_t capacity, ticks_t consumed, bool_t canTimeoutFault, wo
*
* Should be called on every kernel entry
* where threads can be billed.
*
* @pre (NODE_STATE(ksConsumed) == 0
*/
static inline void updateTimestamp(void)
{
time_t prev = NODE_STATE(ksCurTime);
NODE_STATE(ksCurTime) = getCurrentTime();
NODE_STATE(ksConsumed) = NODE_STATE(ksCurTime) - prev;
NODE_STATE(ksConsumed) += (NODE_STATE(ksCurTime) - prev);
}
/* Check if the current thread/domain budget has expired.

View file

@ -70,6 +70,7 @@ typedef enum _platform_irq_t {
typedef uint8_t irq_t;
#define KERNEL_TIMER_IRQ int_timer
#define BIOS_PADDR_START 0x0e0000
#define BIOS_PADDR_END 0x100000

View file

@ -520,6 +520,11 @@ static void handleRecv(bool_t isBlocking)
#ifdef CONFIG_KERNEL_MCS
static inline void mcsIRQ(irq_t irq)
{
if (irq == KERNEL_TIMER_IRQ) {
/* if this is a timer irq we must update the time as we need to reprogram the timer, and we
* can't lose the time that has just been used by the kernel. */
updateTimestamp();
}
checkBudget();
}
#else