From f9c0d4c2e39aa28cc501ceb6479afc32f7849b11 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 9 Sep 2013 00:01:07 -0700 Subject: gras: work on global config that works on hier --- lib/block.cpp | 10 ---------- lib/block_allocator.cpp | 10 +++++++--- lib/block_config.cpp | 21 +++++++++++++++++++++ lib/block_handlers.cpp | 20 +++++--------------- lib/element.cpp | 10 ++++++++++ lib/element_impl.hpp | 6 +++--- lib/gras_impl/block_data.hpp | 1 - lib/hier_block.cpp | 10 ++++++++++ lib/task_main.cpp | 2 +- lib/top_block.cpp | 14 ++------------ lib/top_block_query.cpp | 12 ++++++------ 11 files changed, 65 insertions(+), 51 deletions(-) (limited to 'lib') diff --git a/lib/block.cpp b/lib/block.cpp index acb05d3..406e33c 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -121,16 +121,6 @@ typename V::value_type &vector_get_resize(V &v, const size_t index) return v[index]; } -const GlobalBlockConfig &Block::global_config(void) const -{ - return (*this)->block_data->global_config; -} - -GlobalBlockConfig &Block::global_config(void) -{ - return (*this)->block_data->global_config; -} - InputPortConfig &Block::input_config(const size_t which_input) { return vector_get_resize((*this)->block_data->input_configs, which_input); diff --git a/lib/block_allocator.cpp b/lib/block_allocator.cpp index 8246037..6f59ef6 100644 --- a/lib/block_allocator.cpp +++ b/lib/block_allocator.cpp @@ -61,11 +61,15 @@ void BlockActor::handle_top_alloc(const TopAllocMessage &, const Theron::Address const size_t num_outputs = worker->get_num_outputs(); for (size_t i = 0; i < num_outputs; i++) { + size_t reserve_items = data->output_configs[i].reserve_items; + size_t maximum_items = data->output_configs[i].maximum_items; + if (maximum_items == 0) maximum_items = data->block->global_config().maximum_output_items; + const size_t bytes = recommend_length( data->output_allocation_hints[i], my_round_up_mult(AT_LEAST_BYTES, data->output_configs[i].item_size), - data->output_configs[i].reserve_items*data->output_configs[i].item_size, - data->output_configs[i].maximum_items*data->output_configs[i].item_size + reserve_items*data->output_configs[i].item_size, + maximum_items*data->output_configs[i].item_size ); SBufferDeleter deleter = boost::bind(&buffer_returner, this->thread_pool, this->GetAddress(), i, _1); @@ -74,7 +78,7 @@ void BlockActor::handle_top_alloc(const TopAllocMessage &, const Theron::Address SBufferConfig config; config.memory = NULL; config.length = bytes; - config.affinity = data->global_config.buffer_affinity; + config.affinity = data->block->global_config().buffer_affinity; config.token = token; BufferQueueSptr queue = data->block->output_buffer_allocator(i, config); diff --git a/lib/block_config.cpp b/lib/block_config.cpp index 165ab47..e34aa0c 100644 --- a/lib/block_config.cpp +++ b/lib/block_config.cpp @@ -11,6 +11,27 @@ GlobalBlockConfig::GlobalBlockConfig(void) interruptible_work = false; } +void GlobalBlockConfig::merge(const GlobalBlockConfig &config) +{ + //overwrite with global config only if maxium_items is not set (zero) + if (this->maximum_output_items == 0) + { + this->maximum_output_items = config.maximum_output_items; + } + + //overwrite with global node affinity setting for buffers if not set + if (this->buffer_affinity == -1) + { + this->buffer_affinity = config.buffer_affinity; + } + + //overwrite with global interruptable setting for work if not set + if (this->interruptible_work == false) + { + this->interruptible_work = config.interruptible_work; + } +} + InputPortConfig::InputPortConfig(void) { item_size = 1; diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index ca1ad97..57e24c1 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -83,29 +83,19 @@ void BlockActor::handle_top_config( const Theron::Address from ){ MESSAGE_TRACER(); - const GlobalBlockConfig &config = message.config; + + //merge in the non-defaults + data->block->global_config().merge(message.config); //overwrite with global config only if maxium_items is not set (zero) for (size_t i = 0; i < data->output_configs.size(); i++) { if (data->output_configs[i].maximum_items == 0) { - data->output_configs[i].maximum_items = config.maximum_output_items; + data->output_configs[i].maximum_items = data->block->global_config().maximum_output_items; } } - //overwrite with global node affinity setting for buffers if not set - if (data->global_config.buffer_affinity == -1) - { - data->global_config.buffer_affinity = config.buffer_affinity; - } - - //overwrite with global interruptable setting for work if not set - if (data->global_config.interruptible_work == false) - { - data->global_config.interruptible_work = config.interruptible_work; - } - this->Send(0, from); //ACK } @@ -120,7 +110,7 @@ void BlockActor::handle_top_thread_group( //spawn a new thread if this block is a source data->thread_group = message.thread_group; data->interruptible_thread.reset(); //erase old one - if (data->global_config.interruptible_work) + if (data->block->global_config().interruptible_work) { data->interruptible_thread = boost::make_shared( data->thread_group, boost::bind(&BlockActor::task_work, this) diff --git a/lib/element.cpp b/lib/element.cpp index 9f3c5fb..5574c02 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -84,6 +84,16 @@ std::string Element::to_string(void) const return (*this)->repr; } +const GlobalBlockConfig &Element::global_config(void) const +{ + return (*this)->global_config; +} + +GlobalBlockConfig &Element::global_config(void) +{ + return (*this)->global_config; +} + void Element::adopt_element(const std::string &name, const Element &child) { if (child->parent) throw std::invalid_argument(str(boost::format( diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 91497ed..dca7963 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -38,7 +38,7 @@ struct ElementImpl //top block stuff SharedThreadGroup thread_group; Token token; - GlobalBlockConfig top_config; + GlobalBlockConfig global_config; //element tree stuff Element parent; @@ -63,14 +63,14 @@ struct ElementImpl void bcast_prio_msg(const MessageType &msg) { Theron::Receiver receiver; - BOOST_FOREACH(Apology::Worker *w, this->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, this->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); MessageType message = msg; message.prio_token = actor->prio_token; actor->GetFramework().Send(message, receiver.GetAddress(), actor->GetAddress()); } - size_t outstandingCount(this->executor->get_workers().size()); + size_t outstandingCount(this->topology->get_workers().size()); while (outstandingCount != 0) { outstandingCount -= receiver.Wait(outstandingCount); diff --git a/lib/gras_impl/block_data.hpp b/lib/gras_impl/block_data.hpp index d6af53d..f4dd9bd 100644 --- a/lib/gras_impl/block_data.hpp +++ b/lib/gras_impl/block_data.hpp @@ -69,7 +69,6 @@ struct BlockData //is the fg running? BlockState block_state; - GlobalBlockConfig global_config; std::vector > output_allocation_hints; diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index abbdec1..5d497de 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -3,6 +3,7 @@ #include "element_impl.hpp" #include #include +#include #include using namespace gras; @@ -23,6 +24,15 @@ HierBlock::~HierBlock(void) //NOP } +void HierBlock::commit_config(void) +{ + BOOST_FOREACH(Apology::Worker *w, (*this)->topology->get_workers()) + { + BlockActor *actor = dynamic_cast(w->get_actor()); + actor->data->block->global_config().merge((*this)->global_config); + } +} + void ElementImpl::hier_block_cleanup(void) { this->topology->clear_all(); diff --git a/lib/task_main.cpp b/lib/task_main.cpp index 5547b08..803a5e3 100644 --- a/lib/task_main.cpp +++ b/lib/task_main.cpp @@ -106,7 +106,7 @@ void BlockActor::task_main(void) buff.unique() and data->input_configs[i].inline_buffer and output_inline_index < num_outputs and - buff.get_affinity() == data->global_config.buffer_affinity + buff.get_affinity() == data->block->global_config().buffer_affinity ){ data->output_queues.set_inline(output_inline_index++, buff); } diff --git a/lib/top_block.cpp b/lib/top_block.cpp index 0c8572d..dd2fd5d 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -31,16 +31,6 @@ void ElementImpl::top_block_cleanup(void) this->executor->commit(); } -const GlobalBlockConfig &TopBlock::global_config(void) const -{ - return (*this)->top_config; -} - -GlobalBlockConfig &TopBlock::global_config(void) -{ - return (*this)->top_config; -} - void TopBlock::commit(void) { this->start(); //ok to re-start, means update @@ -62,7 +52,7 @@ void TopBlock::start(void) { //send the global block config before alloc TopConfigMessage message; - message.config = (*this)->top_config; + message.config = (*this)->global_config; (*this)->bcast_prio_msg(message); } { @@ -127,7 +117,7 @@ void TopBlock::wait(void) } //loop through blocks looking for non-done blocks with done inputs - BOOST_FOREACH(Apology::Worker *w, (*this)->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, (*this)->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); if (actor->data->block_state == BLOCK_STATE_DONE) has_a_done = true; diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index ccc5c29..68a56ef 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -31,7 +31,7 @@ static ptree query_blocks(ElementImpl *self, const ptree &) { ptree root; ptree e; - BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, self->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); ptree prop_e; @@ -61,7 +61,7 @@ static ptree query_stats(ElementImpl *self, const ptree &query) //get stats with custom receiver and set high prio GetStatsReceiver receiver; size_t outstandingCount(0); - BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, self->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); @@ -93,7 +93,7 @@ static ptree query_stats(ElementImpl *self, const ptree &query) //thread pool counts std::set thread_pools; - BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, self->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); thread_pools.insert(actor->thread_pool); @@ -161,7 +161,7 @@ static ptree query_calls(ElementImpl *self, const ptree &query) ptree root; const std::string block_id = query.get("block"); const std::string call_name = query.get("name"); - BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, self->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); if (actor->data->block->get_uid() != block_id) continue; @@ -189,7 +189,7 @@ static std::string query_topology(ElementImpl *self, const ptree &query) buff += "rankdir=LR;\n"; buff += "node [shape=record, fontsize=10];\n"; - BOOST_FOREACH(Apology::Worker *w, self->executor->get_workers()) + BOOST_FOREACH(Apology::Worker *w, self->topology->get_workers()) { BlockActor *actor = dynamic_cast(w->get_actor()); std::string in_ports_str, out_ports_str; @@ -222,7 +222,7 @@ static std::string query_topology(ElementImpl *self, const ptree &query) ); } - BOOST_FOREACH(const Apology::Flow &flow, self->executor->get_flat_flows()) + BOOST_FOREACH(const Apology::Flow &flow, self->topology->get_flat_flows()) { buff += str(boost::format("%u:out%u -> %u:in%u;\n") % dynamic_cast(flow.src.elem)->get_actor()->GetAddress().AsInteger() -- cgit From 1494e66b4b448132030c233ef75dd9210b90e9ef Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 12 Sep 2013 23:06:12 -0700 Subject: gras: added thread pool to global config --- lib/block.cpp | 13 ++++++++++++- lib/block_config.cpp | 12 +++++++++--- lib/element.cpp | 5 +++++ lib/hier_block.cpp | 1 + lib/top_block.cpp | 6 ++++++ 5 files changed, 33 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/block.cpp b/lib/block.cpp index 406e33c..51b661f 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -144,6 +144,18 @@ const OutputPortConfig &Block::output_config(const size_t which_output) const void Block::commit_config(void) { Theron::Actor &actor = *((*this)->block_actor); + + //handle thread pool migration + const ThreadPool &thread_pool = this->global_config().thread_pool; + if (thread_pool and thread_pool != (*this)->block_actor->thread_pool) + { + boost::shared_ptr old_actor = (*this)->block_actor; + (*this)->block_actor.reset(BlockActor::make(thread_pool)); + (*this)->setup_actor(); + wait_actor_idle((*this)->repr, *old_actor); + } + + //update messages for in and out ports for (size_t i = 0; i < (*this)->worker->get_num_inputs(); i++) { InputUpdateMessage message; @@ -156,7 +168,6 @@ void Block::commit_config(void) message.index = i; actor.GetFramework().Send(message, Theron::Address::Null(), actor.GetAddress()); } - } void Block::notify_active(void) diff --git a/lib/block_config.cpp b/lib/block_config.cpp index e34aa0c..227ae08 100644 --- a/lib/block_config.cpp +++ b/lib/block_config.cpp @@ -13,23 +13,29 @@ GlobalBlockConfig::GlobalBlockConfig(void) void GlobalBlockConfig::merge(const GlobalBlockConfig &config) { - //overwrite with global config only if maxium_items is not set (zero) + //overwrite with config's max items only if maxium_items is not set (zero) if (this->maximum_output_items == 0) { this->maximum_output_items = config.maximum_output_items; } - //overwrite with global node affinity setting for buffers if not set + //overwrite with config's node affinity setting for buffers if not set if (this->buffer_affinity == -1) { this->buffer_affinity = config.buffer_affinity; } - //overwrite with global interruptable setting for work if not set + //overwrite with config's interruptable setting for work if not set if (this->interruptible_work == false) { this->interruptible_work = config.interruptible_work; } + + //overwrite with config's thread pool for actor if not set + if (not this->thread_pool) + { + this->thread_pool = config.thread_pool; + } } InputPortConfig::InputPortConfig(void) diff --git a/lib/element.cpp b/lib/element.cpp index 5574c02..efd8dfd 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -94,6 +94,11 @@ GlobalBlockConfig &Element::global_config(void) return (*this)->global_config; } +void Element::commit_config(void) +{ + //NOP -- this call gets overridden +} + void Element::adopt_element(const std::string &name, const Element &child) { if (child->parent) throw std::invalid_argument(str(boost::format( diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index 5d497de..5ca74a9 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -30,6 +30,7 @@ void HierBlock::commit_config(void) { BlockActor *actor = dynamic_cast(w->get_actor()); actor->data->block->global_config().merge((*this)->global_config); + actor->data->block->commit_config(); } } diff --git a/lib/top_block.cpp b/lib/top_block.cpp index dd2fd5d..4892e77 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -31,8 +31,14 @@ void ElementImpl::top_block_cleanup(void) this->executor->commit(); } +void TopBlock::commit_config(void) +{ + HierBlock::commit_config(); +} + void TopBlock::commit(void) { + this->commit_config(); this->start(); //ok to re-start, means update } -- cgit From 75d2c6cc485714efe4b136ade34e78a7b0fb2744 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Sep 2013 13:44:22 -0700 Subject: gras: removed set_thread_pool, use the config --- lib/block.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib') diff --git a/lib/block.cpp b/lib/block.cpp index 51b661f..aa130d7 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -184,11 +184,3 @@ void Block::notify_topology(const size_t, const size_t) { return; } - -void Block::set_thread_pool(const ThreadPool &thread_pool) -{ - boost::shared_ptr old_actor = (*this)->block_actor; - (*this)->block_actor.reset(BlockActor::make(thread_pool)); - (*this)->setup_actor(); - wait_actor_idle((*this)->repr, *old_actor); -} -- cgit