diff --git a/src/vault/gear/scheduler-commutator.hpp b/src/vault/gear/scheduler-commutator.hpp index f38fa388e..010679754 100644 --- a/src/vault/gear/scheduler-commutator.hpp +++ b/src/vault/gear/scheduler-commutator.hpp @@ -64,7 +64,7 @@ namespace gear { /** - * Scheduler Layer-2 : coordination. + * Scheduler Layer-2 : execution of Scheduler Activities. * * @see SchedulerInvocation (Layer-1) * @see SchedulerCommutator_test @@ -95,7 +95,7 @@ namespace gear { ThreadID expect_noThread; // expect no one else to be in... ThreadID myself = std::this_thread::get_id(); return groomingToken_.compare_exchange_strong (expect_noThread, myself - ,memory_order_acquire // success also constitutes an acquire barrier + ,memory_order_acquire // success also constitutes an acquire barrier ,memory_order_relaxed // failure has no synchronisation ramifications ); } @@ -125,6 +125,22 @@ namespace gear { } + /** + * Decide if Activities shall be performed now and in this thread. + * @param when the indicated time of start of the first Activity + * @param now current scheduler time + * @return allow dispatch if acquired GroomingToken and time is due + * @warning accesses current ThreadID and changes GroomingToken state + */ + bool + decideDispatchNow (Time when, Time now) + { + auto myself = std::this_thread::get_id(); + return (when <= now) + and (holdsGroomingToken (myself) + or acquireGoomingToken()); + } + Activity* findWork (SchedulerInvocation& layer1) diff --git a/src/vault/gear/scheduler-invocation.hpp b/src/vault/gear/scheduler-invocation.hpp index 946822c1f..9d18290e7 100644 --- a/src/vault/gear/scheduler-invocation.hpp +++ b/src/vault/gear/scheduler-invocation.hpp @@ -22,7 +22,7 @@ /** @file scheduler-invocation.hpp - ** Layer-1 of the Scheduler: dispatch and invocation of activities. + ** Layer-1 of the Scheduler: queueing and prioritisation of activities. ** This is the lower layer of the implementation and provides low-level functionality. ** ** @see SchedulerInvocation_test @@ -66,7 +66,7 @@ namespace gear { /** - * Scheduler Layer-1 : invocation. + * Scheduler Layer-1 : time based dispatch. * * @see Scheduler * @see SchedulerInvocation_test diff --git a/tests/vault/gear/scheduler-commutator-test.cpp b/tests/vault/gear/scheduler-commutator-test.cpp index c2adf62c4..8f6282935 100644 --- a/tests/vault/gear/scheduler-commutator-test.cpp +++ b/tests/vault/gear/scheduler-commutator-test.cpp @@ -31,11 +31,11 @@ #include "lib/test/microbenchmark.hpp" #include "lib/time/timevalue.hpp" #include "lib/format-cout.hpp" +#include "lib/thread.hpp" //#include "lib/util.hpp" #include "lib/test/diagnostic-output.hpp"///////////////////////////TODO TOD-Oh //#include -#include #include using test::Test; @@ -58,6 +58,15 @@ namespace test { namespace {// Test parameters const size_t NUM_THREADS = 20; const size_t REPETITIONS = 100; + + inline void + ___ensureGroomingTokenReleased(SchedulerCommutator& sched) + { + auto myself = std::this_thread::get_id(); + CHECK (not sched.holdsGroomingToken(myself)); + CHECK (sched.acquireGoomingToken()); + sched.dropGroomingToken(); + } } @@ -124,6 +133,7 @@ namespace test { sched.dropGroomingToken(); CHECK (not sched.holdsGroomingToken (myself)); + ___ensureGroomingTokenReleased(sched); } @@ -163,6 +173,7 @@ namespace test { CHECK (brokenSum < checkSum); CHECK (checkSum = NUM_THREADS * REPETITIONS*(REPETITIONS-1)/2); + ___ensureGroomingTokenReleased(sched); } @@ -174,7 +185,53 @@ namespace test { void verify_DispatchDecision() { - UNIMPLEMENTED ("DispatchDecision"); + SchedulerCommutator sched; + ___ensureGroomingTokenReleased(sched); + + Time t1{10,0}; + Time t2{20,0}; + Time t3{30,0}; + Time now{t2}; + + auto myself = std::this_thread::get_id(); + CHECK (sched.decideDispatchNow (t1, now)); + CHECK (sched.holdsGroomingToken (myself)); + + CHECK (sched.decideDispatchNow (t1, now)); + CHECK (sched.holdsGroomingToken (myself)); + + CHECK (sched.decideDispatchNow (t2, now)); + CHECK (sched.holdsGroomingToken (myself)); + + CHECK (not sched.decideDispatchNow (t3, now)); + CHECK (sched.holdsGroomingToken (myself)); + sched.dropGroomingToken(); + + CHECK (not sched.decideDispatchNow (t3, now)); + CHECK (not sched.holdsGroomingToken (myself)); + + std::atomic_bool stop{false}; + lib::ThreadJoinable theHog{"grooming-hog" + , [&]{ + CHECK (sched.acquireGoomingToken()); + do sleep_for (100us); + while (not stop); + sched.dropGroomingToken(); + }}; + sleep_for (500us); + CHECK (not sched.acquireGoomingToken()); + + CHECK (not sched.decideDispatchNow (t1, now)); + CHECK (not sched.holdsGroomingToken (myself)); + + CHECK (not sched.decideDispatchNow (t2, now)); + CHECK (not sched.holdsGroomingToken (myself)); + + stop = true; + theHog.join().maybeThrow(); + + CHECK (sched.decideDispatchNow (t2, now)); + CHECK (sched.holdsGroomingToken (myself)); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 59055f8cb..3a5e4541f 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -84897,11 +84897,13 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + - + + @@ -84969,8 +84971,14 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + @@ -85034,11 +85042,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + - + @@ -85077,9 +85085,83 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ versuche GroomingToken zu erlangen (Seiteneffekt) +

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

+ ...weil im normalen Control-flow direkt danach die Activity in die Queue gestellt wird — und da können wir eine signifikannte Beschleunigung erziehlen wenn wir das GroomingToken halten und deshalb nicht durch die Instruct-Queue gehen müssen +

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

+ ...und zwar, weil sie infolge der hier getroffenen Entscheidung unmittelbar in den Dispatch gehen können; wäre das nicht so, dann würde u.U aus der Priority-Queue zunächst eine noch dringendere/frühere Aufgabe entnommen werden. +

+ + +
+ +
@@ -86024,7 +86106,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + @@ -86163,8 +86247,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -89208,6 +89292,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + +