76#ifndef SRC_VAULT_GEAR_BLOCK_FLOW_H_
77#define SRC_VAULT_GEAR_BLOCK_FLOW_H_
105 namespace blockFlow {
159 static const CONF configInstance;
160 return configInstance;
166 return config().EPOCH_SIZ /
config().ACTIVITIES_PER_FRAME;
172 return config().INITIAL_STREAMS *
config().REFERENCE_FPS;
196 return config().BOOST_FACTOR;
202 return pow(
config().BOOST_FACTOR, 5.0/
config().EPOCH_SIZ);
228 using SIZ = ALO::Extent::SIZ;
256 ENSURE (
next !=
this);
277 return firstAllocPoint -
next;
301 return double(
gate().filledSlots()) / (
SIZ()-1);
308 Epoch& target =
static_cast<Epoch&
> (*storageSlot);
326 class FlowDiagnostic;
340 template<
class CONF = blockFlow::DefaultConfig>
365 return static_cast<Epoch&
> (extent);
380 return RawIter::checkPoint()? &
asEpoch (RawIter::yield())
406 RawIter::validatePos(
curr_);
414 RawIter::expandAlloc(cnt);
470 template<
typename...ARGS>
486 epoch_->gate().hasFreeSlot()))
502 return epoch_->gate().claimNextSlot();
534 auto distance = _raw(deadline) - _raw(lastDeadline);
536 ENSURE (not nextEpoch);
537 auto requiredNew = distance / _raw(
epochStep_);
541 nextEpoch.expandAlloc (requiredNew);
543 for ( ; 0 < requiredNew; --requiredNew)
548 if (deadline <= lastDeadline)
550 ENSURE (requiredNew == 1);
555 NOTREACHED (
"Logic of counting new Epochs");
559 if (epochIt->deadline() >= deadline)
562 NOTREACHED (
"Inconsistency in BlockFlow Epoch deadline organisation");
583 if (epoch.gate().isAlive (deadline))
586 auto currDeadline = epoch.deadline();
624 auto interpolate = [&](
auto f,
auto v1,
auto v2) {
return f*v2 + (1-f)*v1; };
627 fillFactor /=
config().TARGET_FILL;
628 auto THRESH =
config().DAMP_THRESHOLD;
630 fillFactor > THRESH? fillFactor
634 double contribution = double(_raw(actualLen)) / _raw(
epochStep_) / adjust;
638 double avgFactor = (contribution + N-1) / N;
655 currFps += additionalFps;
665 REQUIRE (not isnil (
alloc_));
671 REQUIRE (not isnil (
alloc_));
703 throw err::Fatal{
"Deadline expansion causes allocation of "
706 , err::LUMIERA_ERROR_CAPACITY};
747 return epoch.deadline();
767 cnt += epoch.gate().filledSlots();
773 inline FlowDiagnostic<CONF>
Descriptor for a piece of operational logic performed by the scheduler.
Duration is the internal Lumiera time metric.
Framerate specified as frames per second.
basic constant internal time value.
static const raw_time_64 SCALE
Number of micro ticks (µs) per second as basic time scale.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
static const Time NEVER
border condition marker value. NEVER >= any time value
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Derived specific exceptions within Lumiera's exception hierarchy.
Any copy and copy construction prohibited.
Record to describe an Activity, to happen within the Scheduler's control flow.
Activity * next
Activities are organised into chains to represent relations based on verbs.
Local handle to allow allocating a collection of Activities, all sharing a common deadline.
Activity & create(ARGS &&...args)
Main API operation: allocate a new Activity record.
Time currDeadline() const
AllocatorHandle(RawIter slot, BlockFlow *parent)
Adapt the access to the raw storage to present the Extents as Epoch; also caches the address resoluti...
StorageAdaptor(RawIter it)
void expandAlloc(size_t cnt=1)
Allocation scheme for the Scheduler, based on Epoch(s).
blockFlow::Epoch< Allocator > Epoch
void adjustEpochStep(double factor)
Duration _cache_timeStep_cutOff
void markEpochOverflow()
Notify and adjust Epoch capacity as consequence of exhausting an Epoch.
CONF const & config() const
static constexpr size_t EPOCH_SIZ
void markEpochUnderflow(TimeVar actualLen, double fillFactor)
On clean-up of past Epochs, the actual fill factor is checked to guess an Epoch duration to make opti...
Allocator::iterator RawIter
lib::IterableDecorator< StorageAdaptor > EpochIter
Adapted storage-Extent iterator, directly exposing Epoch&.
void ___sanityCheckAlloc(size_t newBlockCnt)
static Epoch & asEpoch(Extent &extent)
Duration getEpochStep() const
void discardBefore(Time deadline)
Clean-up all storage related to activities before the given deadline.
AllocatorHandle until(Time deadline)
initiate allocations for activities to happen until some deadline
double _cache_boostFactorOverflow
Time updatePastDeadline(TimeVar newDeadline)
void announceAdditionalFlow(FrameRate additionalFps)
provide a hint to the self-regulating allocation scheme.
std::string allEpochs()
render deadlines of all currently active Epochs
size_t cntElm()
count all currently active allocated elements
BlockFlow< CONF > & flow_
BlockFlow< CONF >::Epoch Epoch
FlowDiagnostic(BlockFlow< CONF > &theFlow)
TimeValue find(Activity &someActivity)
find out in which Epoch the given Activity was placed
< special definitions for the Scheduler activity language
Allocation Extent holding scheduler Activities to be performed altogether before a common deadline.
static Epoch & setup(RawIter storageSlot, Time deadline)
static Epoch & implantInto(RawIter storageSlot)
iterator last()
positioned to the last / latest storage extent opened
void openNew(size_t cnt=1)
claim next cnt extents, possibly allocate.
void dropOld(size_t cnt)
discard oldest cnt extents
iterator begin()
iterate over all the currently active Extents
lib::IterableDecorator< IdxLink > iterator
allow transparent iteration of Extents, with the ability to expand storage
Memory management scheme for cyclically used memory extents.
Building tree expanding and backtracking evaluations within hierarchical scopes.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
string showSize(size_t val) noexcept
string join(COLL &&coll, string const &delim=", ")
enumerate a collection's contents, separated by delimiter.
bool isnil(lib::time::Duration const &dur)
const size_t BLOCK_EXPAND_SAFETY_LIMIT
< Parametrisation of Scheduler memory management scheme
FlowDiagnostic< CONF > watch(BlockFlow< CONF > &theFlow)
Vault-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Instant dead
alive while time < dead
bool isDead(Time now) const
Lightweight yet safe parametrisation of memory management.
const size_t ACTIVITIES_PER_FRAME
how many Activity records are typically used to implement a single frame
const Duration DUTY_CYCLE
typical relaxation time or average pre-roll to deadline
const double TARGET_FILL
aim at using this fraction of Epoch space on average (slightly below 100%)
const size_t INITIAL_STREAMS
Number of streams with REFERENCE_FPS to expect for normal use.
const size_t REFERENCE_FPS
frame rate to use as reference point to relate DUTY_CYCLE and default counts
const double BOOST_FACTOR
adjust capacity by this factor on Epoch overflow/underflow events
const size_t OVERLOAD_LIMIT
load factor over normal use where to assume saturation and limit throughput
static const size_t EPOCH_SIZ
Number of storage slots to fit into one »Epoch«
const double DAMP_THRESHOLD
do not account for (almost) empty Epochs to avoid overshooting regulation
specifically rigged GATE Activity, used for managing Epoch metadata
Activity * claimNextSlot()
size_t filledSlots() const
activity::Instant & deadline()
bool isAlive(Time deadline)
Parametrisation tuned for Render Engine performance.
const size_t INITIAL_STREAMS
static const size_t EPOCH_SIZ
Policy template to mix into the BlockFlow allocator, providing the parametrisation for self-regulatio...
Duration initialEpochStep() const
size_t averageEpochs() const
CONF const & config() const
size_t initialEpochCnt() const
< reserve allocation headroom for two duty cycles
double boostFactorOverflow() const
< reduced logarithmically, since overflow is detected on individual allocations
Duration timeStep_cutOff() const
< prevent stalling Epoch progression when reaching saturation
size_t initialFrameRate() const
double boostFactor() const
size_t framesPerEpoch() const
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...
Basic set of definitions and includes commonly used together (Vault).