From 453027c1c327ad78f6217e78e0068724c0220e42 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 21 Sep 2019 16:30:43 -0400 Subject: [PATCH] kernel/scheduler: Add missing initializations to ThreadData::_InitBase(). fQuantumStart and fLastInterruptTime were not set to 0 here, so they would default to the "malloc-cleared" data and then always overflow the first time the interrupt time was tracked. I can't find any reason that was supposed to be the behavior, so just set them to 0. Also reorder the field initializations to be the same as the class definition, which should allow some store merging optimizations. Spotted by KUBSAN. --- .../kernel/scheduler/scheduler_thread.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/scheduler/scheduler_thread.cpp b/src/system/kernel/scheduler/scheduler_thread.cpp index af21c84a7e..bd525013a2 100644 --- a/src/system/kernel/scheduler/scheduler_thread.cpp +++ b/src/system/kernel/scheduler/scheduler_thread.cpp @@ -18,23 +18,27 @@ static bigtime_t sMaximumQuantumLengths[kMaximumQuantumLengthsCount]; void ThreadData::_InitBase() { - fPriorityPenalty = 0; - fAdditionalPenalty = 0; - fEffectivePriority = GetPriority(); - fBaseQuantum = sQuantumLengths[GetEffectivePriority()]; - - fTimeUsed = 0; fStolenTime = 0; - - fMeasureAvailableActiveTime = 0; - fLastMeasureAvailableTime = 0; - fMeasureAvailableTime = 0; + fQuantumStart = 0; + fLastInterruptTime = 0; fWentSleep = 0; fWentSleepActive = 0; fEnqueued = false; fReady = false; + + fPriorityPenalty = 0; + fAdditionalPenalty = 0; + + fEffectivePriority = GetPriority(); + fBaseQuantum = sQuantumLengths[GetEffectivePriority()]; + + fTimeUsed = 0; + + fMeasureAvailableActiveTime = 0; + fLastMeasureAvailableTime = 0; + fMeasureAvailableTime = 0; }