Do not use cross-node ksCurTime

The code using ksCurTime assumes that ksCurTime is up-to-date,
but this assumption is wrong for ksCurTime of other CPU cores.
Those can be quite some time in the past.

The implications of using NODE_STATE(ksCurTime) is that clocks
on all cores must be synchronous:

- Riscv is okay: The specification states: "The real-time clocks
  of all hardware threads in a single user application should be
  synchronized to within one tick of the real-time clock."
- x86 okay if not ancient when Invariant TSC is supported.
- aarch64 is okay.
- arm32: arm_global.h is okay. Exynos timer seems okay. am335x and
  omap3430 are single-core.

See also #854.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
This commit is contained in:
Indan Zupancic
2022-05-30 16:52:18 +02:00
committed by Gerwin Klein
parent 0c8c386394
commit ba262f6d75
2 changed files with 4 additions and 4 deletions

View File

@@ -125,7 +125,7 @@ static inline bool_t refill_sufficient(sched_context_t *sc, ticks_t usage)
*/
static inline bool_t refill_ready(sched_context_t *sc)
{
return refill_head(sc)->rTime <= (NODE_STATE_ON_CORE(ksCurTime, sc->scCore) + getKernelWcetTicks());
return refill_head(sc)->rTime <= (NODE_STATE(ksCurTime) + getKernelWcetTicks());
}
/*

View File

@@ -167,7 +167,7 @@ void refill_new(sched_context_t *sc, word_t max_refills, ticks_t budget, ticks_t
/* full budget available */
refill_head(sc)->rAmount = budget;
/* budget can be used from now */
refill_head(sc)->rTime = NODE_STATE_ON_CORE(ksCurTime, core);
refill_head(sc)->rTime = NODE_STATE(ksCurTime);
maybe_add_empty_tail(sc);
REFILL_SANITY_CHECK(sc, budget);
}
@@ -194,7 +194,7 @@ void refill_update(sched_context_t *sc, ticks_t new_period, ticks_t new_budget,
sc->scPeriod = new_period;
if (refill_ready(sc)) {
refill_head(sc)->rTime = NODE_STATE_ON_CORE(ksCurTime, sc->scCore);
refill_head(sc)->rTime = NODE_STATE(ksCurTime);
}
if (refill_head(sc)->rAmount >= new_budget) {
@@ -327,7 +327,7 @@ void refill_unblock_check(sched_context_t *sc)
/* advance earliest activation time to now */
REFILL_SANITY_START(sc);
if (refill_ready(sc)) {
refill_head(sc)->rTime = NODE_STATE_ON_CORE(ksCurTime, sc->scCore);
refill_head(sc)->rTime = NODE_STATE(ksCurTime);
NODE_STATE(ksReprogram) = true;
/* merge available replenishments */