From 709f8e97cc642e446d357612a6d6512d5a4c5330 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Oct 2012 21:15:11 -0700 Subject: implementation for the top block global config --- lib/block.cpp | 1 - lib/block_allocator.cpp | 5 +---- lib/block_handlers.cpp | 13 ++++++++++--- lib/element_impl.hpp | 1 + lib/gras_impl/block_actor.hpp | 6 +++--- lib/gras_impl/debug.hpp | 2 +- lib/gras_impl/messages.hpp | 5 ----- lib/register_messages.cpp | 3 ++- lib/top_block.cpp | 14 ++++++++++++++ 9 files changed, 32 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/block.cpp b/lib/block.cpp index d6f6e2b..84ae09e 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -46,7 +46,6 @@ Block::Block(const std::string &name): (*this)->block->topology_init = false; (*this)->block->forecast_fail = false; (*this)->block->block_ptr = this; - (*this)->block->hint = 0; (*this)->block->block_state = BlockActor::BLOCK_STATE_INIT; //call block methods to init stuff diff --git a/lib/block_allocator.cpp b/lib/block_allocator.cpp index 2161eb9..9b70824 100644 --- a/lib/block_allocator.cpp +++ b/lib/block_allocator.cpp @@ -89,12 +89,9 @@ void BlockActor::handle_top_alloc(const TopAllocMessage &, const Theron::Address this->output_buffer_tokens.resize(num_outputs); for (size_t i = 0; i < num_outputs; i++) { - size_t hint_items = this->hint; - if (hint_items == 0) hint_items = AT_LEAST_DEFAULT_ITEMS; - const size_t bytes = recommend_length( this->output_allocation_hints[i], - hint_items*this->output_items_sizes[i], + AT_LEAST_DEFAULT_ITEMS*this->output_items_sizes[i], this->output_configs[i].reserve_items*this->output_items_sizes[i], this->output_configs[i].maximum_items*this->output_items_sizes[i] ); diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index 2e71ac1..1366e68 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -108,13 +108,20 @@ void BlockActor::handle_top_token( this->Send(0, from); //ACK } -void BlockActor::handle_top_hint( - const TopHintMessage &message, +void BlockActor::handle_top_config( + const GlobalBlockConfig &message, const Theron::Address from ){ MESSAGE_TRACER(); - this->hint = message.hint; + //overwrite with global config only if maxium_items is not set (zero) + for (size_t i = 0; i < this->output_configs.size(); i++) + { + if (this->output_configs[i].maximum_items == 0) + { + this->output_configs[i].maximum_items = message.maximum_output_items; + } + } this->Send(0, from); //ACK } diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 90c4fe2..95f4f3a 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -45,6 +45,7 @@ struct ElementImpl //top block stuff SharedThreadGroup thread_group; Token token; + GlobalBlockConfig top_config; //things may be in this element boost::shared_ptr topology; diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp index bbe6d6c..023011d 100644 --- a/lib/gras_impl/block_actor.hpp +++ b/lib/gras_impl/block_actor.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -59,7 +60,7 @@ struct BlockActor : Apology::Worker this->RegisterHandler(this, &BlockActor::handle_top_active); this->RegisterHandler(this, &BlockActor::handle_top_inert); this->RegisterHandler(this, &BlockActor::handle_top_token); - this->RegisterHandler(this, &BlockActor::handle_top_hint); + this->RegisterHandler(this, &BlockActor::handle_top_config); this->RegisterHandler(this, &BlockActor::handle_top_thread_group); this->RegisterHandler(this, &BlockActor::handle_input_tag); @@ -85,7 +86,7 @@ struct BlockActor : Apology::Worker void handle_top_active(const TopActiveMessage &, const Theron::Address); void handle_top_inert(const TopInertMessage &, const Theron::Address); void handle_top_token(const TopTokenMessage &, const Theron::Address); - void handle_top_hint(const TopHintMessage &, const Theron::Address); + void handle_top_config(const GlobalBlockConfig &, const Theron::Address); void handle_top_thread_group(const SharedThreadGroup &, const Theron::Address); void handle_input_tag(const InputTagMessage &, const Theron::Address); @@ -180,7 +181,6 @@ struct BlockActor : Apology::Worker BLOCK_STATE_LIVE, BLOCK_STATE_DONE, } block_state; - size_t hint; //some kind of allocation hint Affinity buffer_affinity; std::vector > output_allocation_hints; diff --git a/lib/gras_impl/debug.hpp b/lib/gras_impl/debug.hpp index 03ad30f..2fae424 100644 --- a/lib/gras_impl/debug.hpp +++ b/lib/gras_impl/debug.hpp @@ -37,7 +37,7 @@ extern void *operator new(std::size_t n) throw (std::bad_alloc); //-- define to enable these debugs: //---------------------------------------------------------------------- //#define WORK_DEBUG -//#define ASSERTING +#define ASSERTING //#define MESSAGE_TRACING //---------------------------------------------------------------------- diff --git a/lib/gras_impl/messages.hpp b/lib/gras_impl/messages.hpp index 81c66b7..ef87398 100644 --- a/lib/gras_impl/messages.hpp +++ b/lib/gras_impl/messages.hpp @@ -50,11 +50,6 @@ struct TopTokenMessage Token token; }; -struct TopHintMessage -{ - size_t hint; -}; - //---------------------------------------------------------------------- //-- message to an input port //-- do not ack diff --git a/lib/register_messages.cpp b/lib/register_messages.cpp index 18a3cd8..7c894fa 100644 --- a/lib/register_messages.cpp +++ b/lib/register_messages.cpp @@ -15,6 +15,7 @@ // along with io_sig program. If not, see . #include +#include #include #include #include @@ -24,7 +25,7 @@ THERON_REGISTER_MESSAGE(gnuradio::TopAllocMessage); THERON_REGISTER_MESSAGE(gnuradio::TopActiveMessage); THERON_REGISTER_MESSAGE(gnuradio::TopInertMessage); THERON_REGISTER_MESSAGE(gnuradio::TopTokenMessage); -THERON_REGISTER_MESSAGE(gnuradio::TopHintMessage); +THERON_REGISTER_MESSAGE(gnuradio::GlobalBlockConfig); THERON_REGISTER_MESSAGE(gnuradio::SharedThreadGroup); THERON_REGISTER_MESSAGE(gnuradio::InputTagMessage); diff --git a/lib/top_block.cpp b/lib/top_block.cpp index c93bda5..4973b59 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -53,6 +53,16 @@ void ElementImpl::top_block_cleanup(void) << std::flush; } +GlobalBlockConfig TopBlock::global_config(void) const +{ + return (*this)->top_config; +} + +void TopBlock::set_global_config(const GlobalBlockConfig &config) +{ + (*this)->top_config = config; +} + void TopBlock::commit(void) { this->start(); //ok to re-start, means update @@ -69,6 +79,10 @@ void TopBlock::start(void) message.token = (*this)->token; (*this)->executor->post_all(message); } + { + //send the global block config before alloc + (*this)->executor->post_all((*this)->top_config); + } { (*this)->executor->post_all(TopAllocMessage()); } -- cgit