From 686b98ff1ee14c74aa05c8fd56331d0d59f91a68 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 16 Nov 2023 21:38:06 +0100 Subject: [PATCH] Chain-Load: mapping helper for control-rules writing a control-value rule for topology generation typically involves some modulus and then arthmetic operations to map only part of the value range to the expected output range. These calculations are generic, noisy and error-prone. Thus introduce a helper type, which allows the client just to mark up the target range of the provided value to map and transform to the actually expected result range, including some slight margin to absorb rounding errors. Moreover, all calculations done in double, to avoid the perils of unsigned-wrap-around. --- tests/vault/gear/test-chain-load.hpp | 67 +++++++++++++++++++++++++--- wiki/thinkPad.ichthyo.mm | 21 ++++++++- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/tests/vault/gear/test-chain-load.hpp b/tests/vault/gear/test-chain-load.hpp index 96fc3ff0c..fb98286db 100644 --- a/tests/vault/gear/test-chain-load.hpp +++ b/tests/vault/gear/test-chain-load.hpp @@ -88,6 +88,7 @@ #include "lib/iter-explorer.hpp" #include "lib/format-cout.hpp" #include "lib/dot-gen.hpp" +#include "lib/util.hpp" #include #include @@ -110,7 +111,9 @@ namespace test { // using lib::time::FSecs; // using lib::time::Offset; // using lib::meta::RebindVariadic; + using util::min; using util::max; + using util::limited; using util::unConst; using util::toString; using util::showHashLSB; @@ -125,9 +128,38 @@ namespace test { namespace { // Default definitions for topology generation const size_t DEFAULT_FAN = 16; const size_t DEFAULT_SIZ = 256; + + const double CAP_EPSILON = 0.001; ///< tiny bias to absorb rounding problems } + /** + * Helper to cap and map to a value range. + */ + struct Cap + { + double lower{0}; + double value{0}; + double upper{1}; + + Cap(int i) : value(i){ } + Cap(size_t s) : value(s){ } + Cap(double d) : value{d}{ } + + size_t + mapped (size_t scale) + { + if (value==lower) + return 0; + value -= lower; + value /= upper-lower; + value *= scale; + value += CAP_EPSILON; + value = limited (size_t(0), value, scale); + return size_t(value); + } + }; + /** * A Generator for synthetic Render Jobs for Scheduler load testing. @@ -225,7 +257,7 @@ namespace test { private: using NodeTab = typename Node::Tab; using NodeStorage = std::array; - using CtrlRule = std::function; + using CtrlRule = std::function; std::unique_ptr nodes_; @@ -256,6 +288,28 @@ namespace test { /* ===== topology control ===== */ + TestChainLoad&& + seedingRule (CtrlRule r) + { + seedingRule_ = r; + return move(*this); + } + + TestChainLoad&& + expansionRule (CtrlRule r) + { + expansionRule_ = r; + return move(*this); + } + + TestChainLoad&& + reductionRule (CtrlRule r) + { + reductionRule_ = r; + return move(*this); + } + + /** * Use current configuration and seed to (re)build Node connectivity. */ @@ -283,7 +337,8 @@ namespace test { }; auto apply = [&](CtrlRule& rule, Node* n) { - return rule (n->hash, height(level)); + Cap param = rule (n->hash, height(level)); + return param.mapped (maxFan); }; addNode(); // prime next with root node @@ -352,12 +407,11 @@ namespace test { Code TOP {"shape=box, style=rounded"}; Code DEFAULT{}; - auto nodeID = [&](Node& nn){ return size_t(&nn - &nodes_->front()); }; + auto nodeID = [&](Node& n){ return size_t(&n - &nodes_->front()); }; // prepare time-level zero size_t level(0); - auto timeLevel = scope(level); - layers += timeLevel.rank("min "); + auto timeLevel = scope(level).rank("min "); for (Node& n : allNodes()) { @@ -372,13 +426,14 @@ namespace test { if (level != n.level) {// switch to next time-level + layers += timeLevel; ++level; ENSURE (level == n.level); timeLevel = scope(level).rank("same"); - layers += timeLevel; } timeLevel.add (node(i)); } + layers += timeLevel; // close last layer // combine and render collected definitions as DOT-code return digraph (nodes, layers, topology); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 5823ccd83..abca44ff1 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -95887,6 +95887,16 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + @@ -96008,12 +96018,21 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + - +