From 824a626c2e6444a84344e77ba5402b3b78ced68e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 12 Jul 2023 19:19:41 +0200 Subject: [PATCH] Block-Flow: investigate proper working of on-demand allocation Library: add "obvious" utility to the IterExplorer, allowing to materialise all contents of the Pipeline into a container ...use this to take a snapshot of all currently active Extent addresses --- src/lib/diff/mutation-message.hpp | 2 +- src/lib/iter-adapter-ptr-deref.hpp | 2 +- src/lib/iter-explorer.hpp | 38 +++++++++++++++ src/vault/mem/extent-family.hpp | 34 +++++++++----- tests/library/iter-explorer-test.cpp | 26 +++++++++++ tests/vault/mem/extent-family-test.cpp | 41 +++++++++++++++-- wiki/thinkPad.ichthyo.mm | 64 +++++++++++++++++++++++--- 7 files changed, 183 insertions(+), 24 deletions(-) diff --git a/src/lib/diff/mutation-message.hpp b/src/lib/diff/mutation-message.hpp index 5460def67..b5aed6736 100644 --- a/src/lib/diff/mutation-message.hpp +++ b/src/lib/diff/mutation-message.hpp @@ -155,7 +155,7 @@ namespace diff{ /** * Convenience builder for consuming an brace enclosed initializer_list - * @note initialiser elements will be _copied_ into a _heap alloacated_ + * @note initialiser elements will be _copied_ into a _heap allocated_ * snapshot (vector), which is then managed by `shared_ptr` */ MutationMessage(std::initializer_list const&& ili) diff --git a/src/lib/iter-adapter-ptr-deref.hpp b/src/lib/iter-adapter-ptr-deref.hpp index 1081b8e3c..6acf0f679 100644 --- a/src/lib/iter-adapter-ptr-deref.hpp +++ b/src/lib/iter-adapter-ptr-deref.hpp @@ -242,7 +242,7 @@ namespace lib { if (i_.isValid()) currPtr_ = & (*i_); else - currPtr_ = 0; + currPtr_ = nullptr; } diff --git a/src/lib/iter-explorer.hpp b/src/lib/iter-explorer.hpp index 8e9a88dcb..8a6d10182 100644 --- a/src/lib/iter-explorer.hpp +++ b/src/lib/iter-explorer.hpp @@ -118,6 +118,12 @@ #include +//Forward declaration to allow a default result container for IterExplorer::effuse +namespace std { + template class vector; +} + + namespace lib { using std::move; @@ -1695,6 +1701,38 @@ namespace lib { { return SRC {move(*this)}; } + + /** _terminal builder_ to pour and materialise all results from this Pipeline. + * @tparam CON a STL compliant container to store generated values (defaults to `vector`) + * @return new instance of the target container, filled with all values + * pulled from this Pipeline until exhaustion. + */ + template class CON =std::vector> + auto + effuse() + { + CON con{}; + this->effuse (con); + return con; + } + + template + auto + effuse (CON&& sink) -> CON + { + CON con{move(sink)}; + this->effuse (con); + return con; + } + + /** _terminal builder to fill an existing container with all results from this Pipeline */ + template + void + effuse (CON& con) + { + for (auto& val : *this) + con.push_back (val); + } }; diff --git a/src/vault/mem/extent-family.hpp b/src/vault/mem/extent-family.hpp index b33a3e949..fd55a993b 100644 --- a/src/vault/mem/extent-family.hpp +++ b/src/vault/mem/extent-family.hpp @@ -45,7 +45,6 @@ #include "vault/common.hpp" -//#include "lib/symbol.hpp" #include "lib/iter-adapter.hpp" #include "lib/nocopy.hpp" #include "lib/util.hpp" @@ -70,6 +69,10 @@ namespace mem { /** * Memory manager to provide a sequence of Extents for cyclic usage. + * Storage extents, once allocated, will be re-used without invoking any + * ctors or dtors on the objects nominally located in »slots« within the Extent. + * @tparam T payload type living in the Extent's »slots« + * @tparam siz number of »slots« per Extent * @todo WIP-WIP 7/2023 * @see ExtentFamily_test */ @@ -77,12 +80,13 @@ namespace mem { class ExtentFamily : util::NonCopyable { - /** number of excess new extents - * to add whenever new storage is required - */ + /** number of excess new extents to add + * whenever new storage is required */ static const size_t EXCESS_ALLOC{5}; + public: + /** logical structure of a memory Extent */ struct Extent : std::array { @@ -90,7 +94,9 @@ namespace mem { using SIZ = std::integral_constant; }; + private: + /** Entry in the Extents management datastructure */ struct Storage : std::unique_ptr { @@ -168,7 +174,7 @@ namespace mem { void reserve (size_t expectedMaxExtents) - { + { // pertaining management data only extents_.reserve (expectedMaxExtents); } @@ -183,7 +189,7 @@ namespace mem { openNew (size_t cnt =1) { if (not canAccomodate (cnt)) - {//insufficient reserve -> allocate + {//insufficient reserve => allocate size_t oldSiz = extents_.size(); size_t addSiz = cnt - freeSlotCnt() + EXCESS_ALLOC; @@ -211,7 +217,7 @@ namespace mem { { REQUIRE (cnt <= activeSlotCnt()); incWrap (start_, cnt); - } ////////////////////////////////////////////////////////////////////////////TICKET #1316 : should reduce excess allocation (with apropriate damping to avoid oscillations) + } ////////////////////////////////////////////////////////////////////////////TICKET #1316 : should reduce excess allocation (with appropriate damping to avoid oscillations) /** allow transparent iteration of Extents, @@ -223,12 +229,15 @@ namespace mem { void expandAlloc(){ this->stateCore().exFam->openNew();} }; - + /** iterate over all the currently active Extents */ iterator begin() { return iterator{IdxLink{this, start_}}; } iterator end() { return iterator{IdxLink{this, after_}}; } + friend iterator begin (ExtentFamily& exFam) { return exFam.begin(); } + friend iterator end (ExtentFamily& exFam) { return exFam.end(); } - private: + + private: /* ====== storage management implementation ====== */ bool isWrapped() const { @@ -249,7 +258,7 @@ namespace mem { size_t freeSlotCnt() const - { // always keep one in reserve... + { // always keep one in reserve... REQUIRE (activeSlotCnt() < extents_.size()); return extents_.size() - activeSlotCnt(); @@ -258,8 +267,9 @@ namespace mem { bool canAccomodate (size_t addCnt) const { - return addCnt < freeSlotCnt(); // keep one in reserve - } + return addCnt < freeSlotCnt(); + } // keep one in reserve to allow for + // unambiguous iteration end in wrapped state /** increment index, but wrap at array end. * @remark using the array cyclically diff --git a/tests/library/iter-explorer-test.cpp b/tests/library/iter-explorer-test.cpp index 8f199c3b2..e4a6117d5 100644 --- a/tests/library/iter-explorer-test.cpp +++ b/tests/library/iter-explorer-test.cpp @@ -115,6 +115,13 @@ namespace test{ if (not checkPoint()) return; --p; } + + bool + operator== (CountDown const& o) const + { + return e == o.e + and p == o.p; + } }; @@ -279,6 +286,7 @@ namespace test{ verify_FilterChanges(); verify_asIterSource(); verify_IterSource(); + verify_effuse(); verify_depthFirstExploration(); demonstrate_LayeredEvaluation(); @@ -1061,6 +1069,24 @@ namespace test{ + /** @test verify _terminal operation_ to append all results into a container. + */ + void + verify_effuse() + { + auto solidified = explore(CountDown{20}) + .filter ([](uint i){ return i % 2; }) + .transform([](uint i){ return 0.5*i; }) + .effuse(); + + using Res = decltype(solidified); + CHECK (lib::test::showType() == "vector"_expect); + CHECK (util::join(solidified, "|") == "9.5|8.5|7.5|6.5|5.5|4.5|3.5|2.5|1.5|0.5"_expect); + } + + + + /** @test package the resulting Iterator as automatically managed, * polymorphic opaque entity implementing the IterSource interface. * The builder operations on IterExplorer each generate a distinct, implementation diff --git a/tests/vault/mem/extent-family-test.cpp b/tests/vault/mem/extent-family-test.cpp index b845f3ec9..caa675df7 100644 --- a/tests/vault/mem/extent-family-test.cpp +++ b/tests/vault/mem/extent-family-test.cpp @@ -29,7 +29,8 @@ #include "vault/mem/extent-family.hpp" //#include "lib/time/timevalue.hpp" //#include "lib/format-cout.hpp"////////////////////TODO -#include "lib/test/diagnostic-output.hpp" +#include "lib/test/diagnostic-output.hpp"////////////////////TODO +#include "lib/iter-explorer.hpp" //#include "lib/util.hpp" #include @@ -38,6 +39,7 @@ using test::Test; //using std::move; using util::isnil; using util::isSameObject; +using lib::explore; namespace vault{ @@ -99,7 +101,7 @@ namespace test { void use_and_drop() { - ExtentFamily extents{5}; + Extents extents{5}; CHECK ( 0 == watch(extents).first()); CHECK ( 0 == watch(extents).last()); CHECK ( 0 == watch(extents).active()); @@ -180,7 +182,7 @@ namespace test { ~Probe() { val = 0; } }; - using SpecialExtents = ExtentFamily; + using SpecialExtents = ExtentFamily; SpecialExtents spex{3}; spex.openNew(2); @@ -245,6 +247,39 @@ namespace test { void wrapAround() { + Extents extents{5}; + CHECK ( 0 == watch(extents).first()); + CHECK ( 0 == watch(extents).last()); + CHECK ( 0 == watch(extents).active()); + CHECK ( 5 == watch(extents).size()); + + extents.openNew(4); + CHECK ( 0 == watch(extents).first()); + CHECK ( 4 == watch(extents).last()); + CHECK ( 4 == watch(extents).active()); + CHECK ( 5 == watch(extents).size()); + + auto takeAdr = [](auto& x){ return &*x; }; + auto snapshot = explore(extents).transform(takeAdr).effuse(); +SHOW_EXPR(snapshot.size()) +SHOW_EXPR(snapshot[0]) +SHOW_EXPR(snapshot[3]) + + extents.openNew(); +SHOW_EXPR(watch(extents).first()) +SHOW_EXPR(watch(extents).last()) +SHOW_EXPR(watch(extents).active()) +SHOW_EXPR(watch(extents).size()) + CHECK ( 0 == watch(extents).first()); + CHECK ( 5 == watch(extents).last()); + CHECK ( 5 == watch(extents).active()); + CHECK (10 == watch(extents).size()); // Note: heuristics to over-allocate to some degree + auto it = extents.begin(); + for (auto oldAddr : snapshot) + { + CHECK (isSameObject(*oldAddr, *it)); + ++it; + } } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 05af905a9..469b2978b 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -78083,6 +78083,30 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + +

+ dieses würde auch auf das GATE aufgeschaltet, welches dadurch mit einem höheren Latch startet; erst nachdem das NOTIFY eigens aktiviert wurde, könnte das GATE grundsätzlich freigeben +

+ +
+ +
+ + + + +

+ dazu allerdings müßte dieses unterscheiden können, ob es vom Scheduler explizit aktiviert wird, oder ob es durch eine Notification freigeschaltet wurde +

+ +
+
@@ -78414,6 +78438,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + +
@@ -78528,6 +78556,14 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + @@ -78818,8 +78854,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + @@ -86677,7 +86716,9 @@ class Something - + + + @@ -86758,6 +86799,7 @@ class Something + @@ -86815,6 +86857,14 @@ class Something + + + + + + + + @@ -86835,13 +86885,13 @@ class Something - + - + - + - +