diff options
author | Tom Rondeau <tom@trondeau.com> | 2013-10-29 14:19:20 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2013-10-29 14:21:15 -0400 |
commit | e140069eaa05a0b71bbacb014d596dc218383940 (patch) | |
tree | ecaf88321e4a42a12843ff670c9ede600269a668 | |
parent | 9b9768baefeb995dc4516168287c6f865c92b60a (diff) |
runtime: add concept up an automatic update_rate to gr::block.
When enabled, uses nitems_written/nitems_read to update the relative_rate of a block. Useful for blocks that change their relative rate based on activity in the work function. Disabled by default.
digital: PFB clock sync blocks set update_rate to True.
-rw-r--r-- | gnuradio-runtime/include/gnuradio/block.h | 5 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 16 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block_executor.cc | 23 | ||||
-rw-r--r-- | gnuradio-runtime/lib/buffer.cc | 8 | ||||
-rw-r--r-- | gr-digital/lib/pfb_clock_sync_ccf_impl.cc | 3 | ||||
-rw-r--r-- | gr-digital/lib/pfb_clock_sync_fff_impl.cc | 3 |
6 files changed, 39 insertions, 19 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h index e725bd09ed..026e4476ef 100644 --- a/gnuradio-runtime/include/gnuradio/block.h +++ b/gnuradio-runtime/include/gnuradio/block.h @@ -557,6 +557,8 @@ namespace gr { */ int set_thread_priority(int priority); + bool update_rate() const; + // ---------------------------------------------------------------------------- private: @@ -576,6 +578,7 @@ namespace gr { std::vector<int> d_affinity; // thread affinity proc. mask int d_priority; // thread priority level bool d_pc_rpc_set; + bool d_update_rate; // should sched update rel rate? protected: block(void) {} // allows pure virtual interface sub-classes @@ -692,6 +695,8 @@ namespace gr { uint64_t abs_end, const pmt::pmt_t &key); + void enable_update_rate(bool en); + std::vector<long> d_max_output_buffer; std::vector<long> d_min_output_buffer; diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index e1369f9d47..af963c9977 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -52,6 +52,7 @@ namespace gr { d_tag_propagation_policy(TPP_ALL_TO_ALL), d_priority(-1), d_pc_rpc_set(false), + d_update_rate(false), d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { @@ -444,7 +445,20 @@ namespace gr { else d_min_output_buffer[port] = min_output_buffer; } - + + + bool + block::update_rate() const + { + return d_update_rate; + } + + void + block::enable_update_rate(bool en) + { + d_update_rate = en; + } + float block::pc_noutput_items() { diff --git a/gnuradio-runtime/lib/block_executor.cc b/gnuradio-runtime/lib/block_executor.cc index 85cf4bb2ab..ee22ef55e3 100644 --- a/gnuradio-runtime/lib/block_executor.cc +++ b/gnuradio-runtime/lib/block_executor.cc @@ -451,16 +451,12 @@ namespace gr { m->set_is_unaligned(m->unaligned() != 0); } - if(n == block::WORK_DONE) - goto were_done; - - if(n != block::WORK_CALLED_PRODUCE) - d->produce_each (n); // advance write pointers - - // Wait til after we've consumed and produced and recalculate - // the relative rate. - if(!d->sink_p() && !d->source_p()) { - rrate = ((double)m->nitems_written(0)) / ((double)m->nitems_read(0)); + // For some blocks that can change their produce/consume ratio + // (the relative_rate), we might want to automatically update + // based on the amount of items written/read. + // In the block constructor, use enable_update_rate(true). + if(m->update_rate()) { + rrate = ((double)(m->nitems_written(0)+n)) / ((double)m->nitems_read(0)); if(rrate > 0) m->set_relative_rate(rrate); } @@ -471,8 +467,13 @@ namespace gr { d_returned_tags, m->unique_id())) goto were_done; + if(n == block::WORK_DONE) + goto were_done; + + if(n != block::WORK_CALLED_PRODUCE) + d->produce_each(n); // advance write pointers - if(d->d_produce_or > 0) // block produced something + if(d->d_produce_or > 0) // block produced something return READY; // We didn't produce any output even though we called general_work. diff --git a/gnuradio-runtime/lib/buffer.cc b/gnuradio-runtime/lib/buffer.cc index b266c250c9..b5cc19c35b 100644 --- a/gnuradio-runtime/lib/buffer.cc +++ b/gnuradio-runtime/lib/buffer.cc @@ -225,13 +225,7 @@ namespace gr { buffer::add_item_tag(const tag_t &tag) { gr::thread::scoped_lock guard(*mutex()); - if(d_readers.size()) { - tag_t t = tag; - d_item_tags.push_back(t); - } - else { - d_item_tags.push_back(tag); - } + d_item_tags.push_back(tag); } void diff --git a/gr-digital/lib/pfb_clock_sync_ccf_impl.cc b/gr-digital/lib/pfb_clock_sync_ccf_impl.cc index 3e3ae9538d..98c088ab34 100644 --- a/gr-digital/lib/pfb_clock_sync_ccf_impl.cc +++ b/gr-digital/lib/pfb_clock_sync_ccf_impl.cc @@ -68,6 +68,9 @@ namespace gr { d_max_dev(max_rate_deviation), d_osps(osps), d_error(0), d_out_idx(0) { + // Let scheduler adjust our relative_rate. + enable_update_rate(true); + d_nfilters = filter_size; d_sps = floor(sps); diff --git a/gr-digital/lib/pfb_clock_sync_fff_impl.cc b/gr-digital/lib/pfb_clock_sync_fff_impl.cc index d73b564302..60ce56c02b 100644 --- a/gr-digital/lib/pfb_clock_sync_fff_impl.cc +++ b/gr-digital/lib/pfb_clock_sync_fff_impl.cc @@ -65,6 +65,9 @@ namespace gr { d_max_dev(max_rate_deviation), d_osps(osps), d_error(0), d_out_idx(0) { + // Let scheduler adjust our relative_rate. + enable_update_rate(true); + d_nfilters = filter_size; d_sps = floor(sps); |