76#ifndef SRC_VAULT_GEAR_LOAD_CONTROLLER_H_
77#define SRC_VAULT_GEAR_LOAD_CONTROLLER_H_
111 using std::chrono_literals::operator
""ms;
112 using std::chrono_literals::operator
""us;
114 using std::atomic_int64_t;
115 using std::memory_order_relaxed;
184 double lag = _raw(std::clamp<TimeVar> (now - (head.
isRegular()? head:now)
188 int64_t average =
sampledLag_.load (memory_order_relaxed);
190 do newAverage = std::floor (lag*alpha + (1-alpha)*average);
191 while (not
sampledLag_.compare_exchange_weak (average, newAverage, memory_order_relaxed));
218 return sampledLag_.exchange(lag, memory_order_relaxed);
232 lag -= _raw(STANDARD_LAG);
233 lag /= _raw(WORK_HORIZON);
235 double lagFactor = lag<0? 1/(1-lag): 1+lag;
237 return loadFactor * lagFactor;
247 if (lag > _raw(WORK_HORIZON))
267 if (startHorizon > 2* SLEEP_HORIZON)
312 if (off > SLEEP_HORIZON)
return IDLEWAIT;
313 if (off > WORK_HORIZON)
return WORKTIME;
314 if (off > NEAR_HORIZON)
return NEARTIME;
363 auto scatter = [&](
Duration horizon)
366 ENSURE (0 <= wrap and wrap < _raw(horizon));
378 return Offset{headDistance};
380 return Offset{headDistance + scatter(
Offset{limited (NEAR_HORIZON,headDistance,WORK_HORIZON)})};
383 return Offset{headDistance + scatter(SLEEP_HORIZON)};
385 NOTREACHED (
"uncovered work capacity classification.");
Duration is the internal Lumiera time metric.
Offset measures a distance in time.
basic constant internal time value.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Any copy and copy construction prohibited.
Controller to coordinate resource usage related to the Scheduler.
void tendNext(Time nextHead)
Mark the indicated next head time as tended.
function< void(uint)> stepUpWorkForce
void markLagSample(Time head, Time now)
int64_t setCurrentAverageLag(int64_t lag)
double effectiveLoad() const
function< size_t()> currWorkForceSize
LoadController(Wiring &&wiring)
int64_t averageLag() const
void markWorkerExit()
statistics update on scaling down the WorkForce
Offset scatteredDelayTime(Time now, Capacity capacity)
Generate a time offset to relocate currently unused capacity to a time range where it's likely to be ...
void updateState(Time)
periodic call to build integrated state indicators
atomic_int64_t sampledLag_
static Capacity classifyTimeHorizon(Offset off)
classification of time horizon for scheduling
Capacity
Allocation of capacity to time horizon of expected work.
@ NEARTIME
capacity for active processing required
@ IDLEWAIT
time to go to sleep
@ TENDNEXT
reserved for next task
@ WORKTIME
typical stable work task rhythm expected
@ SPINTIME
awaiting imminent activities
Capacity markIncomingCapacity(Time head, Time now)
decide how this thread's capacity shall be used when returning from idle wait and asking for work
bool tendedNext(Time nextHead) const
did we already tend for the indicated next relevant head time?
Capacity markOutgoingCapacity(Time head, Time now)
decide how this thread's capacity shall be used after it returned from being actively employed
function< size_t()> maxCapacity
void ensureCapacity(Time startHorizon)
Hook to check and possibly scale up WorkForce to handle one additional job.
Lumiera error handling (C++ interface).
int64_t raw_time_64
Raw µ-tick time representation used in Lumiera.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
constexpr NUM limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively
Duration SLEEP_HORIZON
schedules beyond that horizon justify going idle
TimeValue _uTicks(std::chrono::microseconds us)
Duration WORK_HORIZON
the scope of activity currently in the works
Duration NEAR_HORIZON
what counts as "imminent" (e.g. for spin-waiting)
const double LAG_SAMPLE_DAMPING
smoothing factor for exponential moving average of lag;
Duration STANDARD_LAG
Experience shows that on average scheduling happens with 200µs delay.
HashVal hash_value(ManifestationID const &id)
Vault-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...