From 7887941c89fb0794c4d03e600ef1672334cf55d8 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 2 Nov 2023 16:46:08 +0100 Subject: [PATCH] Scheduler: prepare for dropping obsoleted entries ...it is clear that there must be a way to flush the scheduler queues an thereby silently drop any obsoleted or irrelevant entries. This topic turns out to be somewhat involved, as it requires to consider the deadline (due to the memory management, which is based on deadlines). Furthermore there is a relation to yet another challenging conceptual requirement, which is the support for other operation modes beyond just time-bound rendering; these concerns make it desirable to expand the internal representation of entries in the queue. Concerns regarding performance are postponed deliberately, until we can demonstrate the Scheduler-Service running under regular operational conditions. --- src/vault/gear/activity-lang.cpp | 8 + src/vault/gear/activity.hpp | 26 ++ src/vault/gear/scheduler-invocation.hpp | 31 +- .../vault/gear/scheduler-invocation-test.cpp | 32 ++ wiki/thinkPad.ichthyo.mm | 358 ++++++++++++++++-- 5 files changed, 428 insertions(+), 27 deletions(-) diff --git a/src/vault/gear/activity-lang.cpp b/src/vault/gear/activity-lang.cpp index 7a0557406..e44b0812f 100644 --- a/src/vault/gear/activity-lang.cpp +++ b/src/vault/gear/activity-lang.cpp @@ -34,6 +34,7 @@ #include "lib/format-obj.hpp" #include +#include ////////////////////////////////////////////////////////////TODO should be in a scheduler translation-unit / extract scheduler-API using std::string; using lib::time::Time; @@ -45,6 +46,13 @@ namespace gear { namespace activity { Hook::~Hook() { } // emit VTable here... } + ///////////////////////////////////////////////////////////////////////////////////////////////TODO should be in a scheduler translation-unit / extract scheduler-API + HashVal + hash_value (ManifestationID const& id) + { + return hash_value (uint32_t{id}); + } + ///////////////////////////////////////////////////////////////////////////////////////////////TODO extract scheduler-API Activity::operator string() const diff --git a/src/vault/gear/activity.hpp b/src/vault/gear/activity.hpp index 07aa6bd06..2580907a5 100644 --- a/src/vault/gear/activity.hpp +++ b/src/vault/gear/activity.hpp @@ -81,6 +81,32 @@ namespace gear { namespace error = lumiera::error; + ///////////////////////////////////////////////////////////////////////////////////////////////TODO placed here for convenience while developing the Scheduler + /////////////////////////////////////////////////////////////////////////////////////////////// extract scheduler-API + /** + * Marker for current (and obsolete) manifestations + * of a CalcStream processed by the Render-Engine. + * An opaque, copyable and comparable value object. + * @remark to be maintained by the PlayProcess and used + * by the Scheduler to discard superseded planning. + */ + class ManifestationID + { + uint32_t id_; + + public: + ManifestationID (uint32_t rawID =0) + : id_{rawID} + { } + // standard copy operations acceptable + + explicit operator uint32_t() const { return id_;} + + friend bool operator== (ManifestationID const& a, ManifestationID const& b) { return a.id_ == b.id_; } + friend bool operator!= (ManifestationID const& a, ManifestationID const& b) { return not (a == b); } + }; + HashVal hash_value (ManifestationID const& id); + ///////////////////////////////////////////////////////////////////////////////////////////////TODO extract scheduler-API class Activity; diff --git a/src/vault/gear/scheduler-invocation.hpp b/src/vault/gear/scheduler-invocation.hpp index a55035973..f0c038e5d 100644 --- a/src/vault/gear/scheduler-invocation.hpp +++ b/src/vault/gear/scheduler-invocation.hpp @@ -81,8 +81,13 @@ namespace gear { /** @internal data record passed through the queues */ struct ActOrder { - int64_t waterlevel{0}; Activity* activity{nullptr}; + int64_t waterlevel{0}; + int64_t deathlevel{0}; + + uint32_t manifestationID :32; + char :0; + bool isCompulsory :1; /** @internal ordering function for time based scheduling * @note reversed order as required by std::priority_queue @@ -93,6 +98,8 @@ namespace gear { { return waterlevel > o.waterlevel; } + + ActOrder() =default; //////////////////////////////////////////////////////////////////////////////TICKET #1245 : use direct bit-field initialiser in C++20 }; using InstructQueue = boost::lockfree::queue; @@ -121,9 +128,16 @@ namespace gear { * Accept an Activity for time-bound execution */ void - instruct (Activity& activity, Time when) + instruct (Activity& activity, Time when + , Time dead =Time::NEVER + , ManifestationID manID =ManifestationID() + , bool compulsory =false) { - bool success = instruct_.push (ActOrder{waterLevel(when), &activity}); + bool success = instruct_.push (ActOrder{&activity + , waterLevel(when) + , waterLevel(dead) + , uint32_t(manID) + , compulsory}); if (not success) throw error::Fatal{"Scheduler entrance: memory allocation failed"}; } @@ -148,9 +162,16 @@ namespace gear { * @remark Layer-2 uses this shortcut when in »grooming mode«. */ void - feedPrioritisation (Activity& activity, Time when) + feedPrioritisation (Activity& activity, Time when + , Time dead =Time::NEVER + , ManifestationID manID =ManifestationID() + , bool compulsory =false) { - priority_.push (ActOrder{waterLevel(when), &activity}); + priority_.push (ActOrder{&activity + , waterLevel(when) + , waterLevel(dead) + , uint32_t(manID) + , compulsory}); } diff --git a/tests/vault/gear/scheduler-invocation-test.cpp b/tests/vault/gear/scheduler-invocation-test.cpp index 76b276461..6b93a34a8 100644 --- a/tests/vault/gear/scheduler-invocation-test.cpp +++ b/tests/vault/gear/scheduler-invocation-test.cpp @@ -28,6 +28,7 @@ #include "lib/test/run.hpp" #include "vault/gear/scheduler-invocation.hpp" #include "lib/util.hpp" +#include "lib/test/diagnostic-output.hpp"///////////////////TODO using test::Test; using util::isSameObject; @@ -54,6 +55,7 @@ namespace test { simpleUsage(); verify_Queuing(); verify_WaterLevel(); + verify_Significance(); verify_stability(); verify_isDue(); } @@ -140,6 +142,36 @@ namespace test { + /** @test verify that obsoleted or rejected entries are dropped transparently + */ + void + verify_Significance() + { + SchedulerInvocation sched; + Activity a1{1u,1u}; + Activity a2{2u,2u}; + Activity a3{3u,3u}; + Activity a4{4u,4u}; + + UNIMPLEMENTED ("transparentely discard obsoleted entries from schedule"); + sched.instruct (a2, Time{2,0}); + sched.instruct (a4, Time{4,0}); + sched.feedPrioritisation(); + CHECK (isSameObject (*sched.peekHead(), a2)); + + sched.instruct (a3, Time{3,0}); + sched.instruct (a1, Time{1,0}); + CHECK (isSameObject (*sched.peekHead(), a2)); + + sched.feedPrioritisation(); + CHECK (isSameObject (*sched.pullHead(), a1)); + CHECK (isSameObject (*sched.pullHead(), a2)); + CHECK (isSameObject (*sched.pullHead(), a3)); + CHECK (isSameObject (*sched.pullHead(), a4)); + } + + + /** @test sort order is not necessarily stable * if using identical time specs on entrance */ diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 75fce81ae..133ee4118 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -71261,7 +71261,14 @@ - + + + + + + + + @@ -71310,7 +71317,7 @@ - + @@ -71333,10 +71340,43 @@ + + + + + + + + + + + + + + + + + +

+ um fliegende Änderungen durchführen zu können +

+ +
+ + + + +
+
+
+
+ + + @@ -71358,7 +71398,7 @@ - + @@ -71373,10 +71413,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -72607,6 +72680,24 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + +

+ ...dient als Bezugspunkt um im Scheduler einen »fliegenden Wechsel« der unterliegenden Definition zu ermöglichen +

+ +
+ + + +
+
@@ -78838,6 +78929,16 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + +
@@ -81879,6 +81980,33 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + +

+ Letzten Endes sind das immer nur ein paar Dutzend Aufrufe, und die Zeitmessungen der letzten Tage zeigen wieder einmal mehr als deutlich, daß das Vermeiden virtueller Calls auf dem Level keine Rolle spielt. Es sollte locker möglich sein, 20 neue Jobs in 100µs an den Scheduler zu übergeben... +

+ +
+ +
+
+
@@ -81902,11 +82030,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + - - + + @@ -81973,8 +82101,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -82022,15 +82150,16 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - - + + + @@ -82382,8 +82511,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -82572,8 +82701,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -82648,10 +82777,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + @@ -83894,6 +84024,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + +
@@ -83965,6 +84098,103 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + +

+ Implementierung: +

+

+ »zusätzliche Markierungen« +

+ +
+ + + + + + + + + +

+ Habe im Vorgriff diverse Bedenken +

+
    +
  • + eine Priority-Queue vertauscht Elemente; die Kosten dafür steigen mit der Größe +
  • +
  • + Spielt es eine Rolle, wenn Allokationen nicht eine 2-er-Potenz sind? +
  • +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ übergreifendes Thema: fliegende Änderungen in Play-Prozessen +

+ +
+
+
@@ -83976,6 +84206,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + +
@@ -88570,7 +88805,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -88594,6 +88829,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + @@ -88980,7 +89219,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -93737,6 +93976,18 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + @@ -94139,7 +94390,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200

- + +
+ +
@@ -94205,7 +94459,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200

- +
@@ -94238,6 +94492,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + +
+ + + + + + + + + + + + + + + @@ -94333,6 +94606,34 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + +

+ ermöglicht, einen CalcStream inkompatibel zu verändern und die Reste der damit obsoleten Manifestation fliegend zu verwerfen +

+ +
+ + + + + + + + + + + + + + + + + @@ -94949,7 +95250,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + @@ -95369,6 +95671,13 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + @@ -95431,6 +95740,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + +