Scheduler: define water-level for prioritisation

This commit is contained in:
Fischlurch 2023-10-17 03:38:28 +02:00
parent 152413589c
commit 430f1af4c5
4 changed files with 55 additions and 19 deletions

View file

@ -40,6 +40,8 @@
#include "vault/common.hpp"
#include "lib/nocopy.hpp"
#include "vault/gear/scheduler-invocation.hpp"
#include "lib/time/timevalue.hpp"
//#include "lib/symbol.hpp"
//#include "lib/util.hpp"
@ -49,6 +51,7 @@
namespace vault{
namespace gear {
using lib::time::Time;
// using util::isnil;
// using std::string;
@ -72,7 +75,7 @@ namespace gear {
doWork (SchedulerInvocation& layer1)
{
layer1.feedPriorisation();
while (layer1.isDue (currentLevel()))
while (layer1.isDue (currentSchedulerTime()))
{
Activity* activity = layer1.pullHead();
if (isInternalWork (activity))
@ -85,10 +88,10 @@ namespace gear {
}
}
size_t
currentLevel() const
Time
currentSchedulerTime() const
{
UNIMPLEMENTED ("define waterlevel based on current time");
UNIMPLEMENTED ("how to manage the current scheduler time");
}
bool

View file

@ -42,6 +42,7 @@
#include "lib/nocopy.hpp"
//#include "lib/symbol.hpp"
#include "vault/gear/activity.hpp"
#include "lib/time/timevalue.hpp"
//#include "lib/util.hpp"
//#include <string>
@ -52,12 +53,13 @@
namespace vault{
namespace gear {
namespace error = lumiera::error;
using lib::time::Time;
// using util::isnil;
// using std::string;
using std::move;
namespace error = lumiera::error;
namespace {// Internal defaults
const size_t INITIAL_CAPACITY = 128;
}
@ -74,7 +76,7 @@ namespace gear {
{
struct ActOrder
{
size_t waterlevel{0};
int64_t waterlevel{0};
Activity* activity{nullptr};
/** @internal ordering function for time based scheduling
@ -95,7 +97,6 @@ namespace gear {
PriorityQueue priority_;
public:
// explicit
SchedulerInvocation()
: instruct_{INITIAL_CAPACITY}
, priority_{}
@ -106,10 +107,9 @@ namespace gear {
* Accept an Activity for time-bound execution
*/
void
instruct (Activity& activity)
instruct (Activity& activity, Time when)
{
size_t waterLevel = 123; /////////////////////////////////////////////////////OOO derive water level from time window
bool success = instruct_.push (ActOrder{waterLevel, &activity});
bool success = instruct_.push (ActOrder{waterLevel(when), &activity});
if (not success)
throw error::Fatal{"Scheduler entrance: memory allocation failed"};
}
@ -128,6 +128,17 @@ namespace gear {
}
/**
* Feed the given Activity directly into time prioritisation,
* effectively bypassing the thread dispatching entrance queue.
*/
void
feedPriorisation (Activity& activity, Time when)
{
priority_.push (ActOrder{waterLevel(when), &activity});
}
/**
* @return `nullptr` if the queue is empty, else the Activity corresponding
* to the currently most urgent element (without dequeuing it).
@ -155,10 +166,17 @@ namespace gear {
/** Determine if there is work to do right now */
bool
isDue (size_t level) const
isDue (Time now) const
{
return not priority_.empty()
and priority_.top().waterlevel <= level;
and priority_.top().waterlevel <= waterLevel(now);
}
private:
static int64_t
waterLevel (Time time)
{
return _raw(time);
}
};

View file

@ -74,10 +74,11 @@ namespace test {
{
SchedulerInvocation sched;
Activity activity;
Time when{1,2,3};
CHECK (not sched.peekHead());
sched.instruct (activity);
sched.instruct (activity, when);
sched.feedPriorisation();
CHECK (sched.peekHead());

View file

@ -80345,8 +80345,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<i>wenn</i>&#160;es zur Ausf&#252;hrung kommt: when &#8801; now
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<icon BUILTIN="idea"/>
</node>
</node>
@ -81731,6 +81730,22 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</html></richcontent>
</node>
</node>
<node CREATED="1697505306938" ID="ID_1444202033" MODIFIED="1697505311892" TEXT="Datenformat">
<node CREATED="1697505316184" ID="ID_548736471" MODIFIED="1697505331986" TEXT="size_t ist Plattform-abh&#xe4;ngig">
<icon BUILTIN="clanbomber"/>
</node>
<node CREATED="1697505398490" ID="ID_330643485" MODIFIED="1697505433395" TEXT="32bit reichen nur f&#xfc;r 30min bei &#xb5;-Tick-Aufl&#xf6;sung"/>
<node CREATED="1697505448926" ID="ID_949778006" MODIFIED="1697505456585" TEXT="64bit sind nat&#xfc;rlich &#xfc;ppigst"/>
<node CREATED="1697505537920" ID="ID_1735492425" LINK="#ID_1475155102" MODIFIED="1697505580964" TEXT="habe mich schon einmal (bei den Activities) implizit auf 64bit festgelegt">
<node CREATED="1697505708923" ID="ID_983960656" MODIFIED="1697505735248" TEXT="&#x201e;implizit&#x201c; &#x27f9; meint bez&#xfc;glich Performance"/>
<node CREATED="1697505740479" ID="ID_1886185402" MODIFIED="1697505758509" TEXT="Activities und Zeitformat sind auf 64bit-Maschinen ausgelegt"/>
<node CREATED="1697505765393" ID="ID_1590658159" MODIFIED="1697505780854" TEXT="32bit-Maschinen m&#xfc;ssen doppelt so viel tun (rechnen aber auch korrekt)"/>
</node>
<node BACKGROUND_COLOR="#ccb59b" COLOR="#6e2a38" CREATED="1697505784265" ID="ID_1082970465" MODIFIED="1697506448892" TEXT="&#x27f9; Konsequenz: waterLevel mu&#xdf; int64_t sein">
<font ITALIC="true" NAME="SansSerif" SIZE="14"/>
<icon BUILTIN="yes"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1693173903557" ID="ID_61492355" MODIFIED="1693173987893" TEXT="Einspielen von Activities aus einem Activity-Term">
<linktarget COLOR="#95354f" DESTINATION="ID_61492355" ENDARROW="Default" ENDINCLINATION="-907;-55;" ID="Arrow_ID_1026469877" SOURCE="ID_1036154230" STARTARROW="None" STARTINCLINATION="-985;134;"/>
@ -81805,8 +81820,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
...es handelt sich offensichtlich bei Layer-1 um eine low-Level-Einrichtung und um ein internes API, das nicht gegen Mi&#223;brauch gewappnet sein mu&#223;
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<icon BUILTIN="yes"/>
<icon BUILTIN="button_cancel"/>
</node>
@ -85875,7 +85889,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697503875664" ID="ID_709664850" MODIFIED="1697503976308" TEXT="verify_Queuing">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697503841856" ID="ID_1434499377" MODIFIED="1697503853628" TEXT="verify_WaterLevel">
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697503841856" ID="ID_1434499377" LINK="#ID_1306162732" MODIFIED="1697505281285" TEXT="verify_WaterLevel">
<icon BUILTIN="flag-yellow"/>
</node>
</node>