GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2004,2009,2010 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more detail. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_GR_BLOCK_DETAIL_H 00024 #define INCLUDED_GR_BLOCK_DETAIL_H 00025 00026 #include <gr_core_api.h> 00027 #include <gr_runtime_types.h> 00028 #include <gr_tpb_detail.h> 00029 #include <gr_tags.h> 00030 #include <gruel/high_res_timer.h> 00031 #include <stdexcept> 00032 00033 /*! 00034 * \brief Implementation details to support the signal processing abstraction 00035 * \ingroup internal 00036 * 00037 * This class contains implementation detail that should be "out of sight" 00038 * of almost all users of GNU Radio. This decoupling also means that 00039 * we can make changes to the guts without having to recompile everything. 00040 */ 00041 class GR_CORE_API gr_block_detail { 00042 public: 00043 ~gr_block_detail (); 00044 00045 int ninputs () const { return d_ninputs; } 00046 int noutputs () const { return d_noutputs; } 00047 bool sink_p () const { return d_noutputs == 0; } 00048 bool source_p () const { return d_ninputs == 0; } 00049 00050 void set_done (bool done); 00051 bool done () const { return d_done; } 00052 00053 void set_input (unsigned int which, gr_buffer_reader_sptr reader); 00054 gr_buffer_reader_sptr input (unsigned int which) 00055 { 00056 if (which >= d_ninputs) 00057 throw std::invalid_argument ("gr_block_detail::input"); 00058 return d_input[which]; 00059 } 00060 00061 void set_output (unsigned int which, gr_buffer_sptr buffer); 00062 gr_buffer_sptr output (unsigned int which) 00063 { 00064 if (which >= d_noutputs) 00065 throw std::invalid_argument ("gr_block_detail::output"); 00066 return d_output[which]; 00067 } 00068 00069 /*! 00070 * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. 00071 */ 00072 void consume (int which_input, int how_many_items); 00073 00074 /*! 00075 * \brief Tell the scheduler \p how_many_items were consumed on each input stream. 00076 */ 00077 void consume_each (int how_many_items); 00078 00079 /*! 00080 * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. 00081 */ 00082 void produce (int which_output, int how_many_items); 00083 00084 /*! 00085 * \brief Tell the scheduler \p how_many_items were produced on each output stream. 00086 */ 00087 void produce_each (int how_many_items); 00088 00089 // Return the number of items read on input stream which_input 00090 uint64_t nitems_read(unsigned int which_input); 00091 00092 // Return the number of items written on output stream which_output 00093 uint64_t nitems_written(unsigned int which_output); 00094 00095 00096 /*! 00097 * \brief Adds a new tag to the given output stream. 00098 * 00099 * Calls gr_buffer::add_item_tag(), 00100 * which appends the tag onto its deque. 00101 * 00102 * \param which_output an integer of which output stream to attach the tag 00103 * \param tag the tag object to add 00104 */ 00105 void add_item_tag(unsigned int which_output, const gr_tag_t &tag); 00106 00107 /*! 00108 * \brief Removes a tag from the given input stream. 00109 * 00110 * Calls gr_buffer::remove_item_tag(). 00111 * The tag in question will then no longer appear on subsequent calls of get_tags_in_range(). 00112 * 00113 * \param which_input an integer of which input stream to remove the tag from 00114 * \param tag the tag object to add 00115 * \param id The unique block ID (use gr_block::unique_id()) 00116 */ 00117 void remove_item_tag(unsigned int which_input, const gr_tag_t &tag, long id); 00118 00119 /*! 00120 * \brief Given a [start,end), returns a vector of all tags in the range. 00121 * 00122 * Pass-through function to gr_buffer_reader to get a vector of tags 00123 * in given range. Range of counts is from start to end-1. 00124 * 00125 * Tags are tuples of: 00126 * (item count, source id, key, value) 00127 * 00128 * \param v a vector reference to return tags into 00129 * \param which_input an integer of which input stream to pull from 00130 * \param abs_start a uint64 count of the start of the range of interest 00131 * \param abs_end a uint64 count of the end of the range of interest 00132 * \param id Block ID 00133 */ 00134 void get_tags_in_range(std::vector<gr_tag_t> &v, 00135 unsigned int which_input, 00136 uint64_t abs_start, 00137 uint64_t abs_end, 00138 long id); 00139 00140 /*! 00141 * \brief Given a [start,end), returns a vector of all tags in the range 00142 * with a given key. 00143 * 00144 * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of 00145 * tags from the buffers. This function then provides a secondary filter to 00146 * the tags to extract only tags with the given 'key'. 00147 * 00148 * Tags are tuples of: 00149 * (item count, source id, key, value) 00150 * 00151 * \param v a vector reference to return tags into 00152 * \param which_input an integer of which input stream to pull from 00153 * \param abs_start a uint64 count of the start of the range of interest 00154 * \param abs_end a uint64 count of the end of the range of interest 00155 * \param key a PMT symbol to select only tags of this key 00156 * \param id Block ID 00157 */ 00158 void get_tags_in_range(std::vector<gr_tag_t> &v, 00159 unsigned int which_input, 00160 uint64_t abs_start, 00161 uint64_t abs_end, 00162 const pmt::pmt_t &key, 00163 long id); 00164 00165 /*! 00166 * \brief Set core affinity of block to the cores in the vector mask. 00167 * 00168 * \param mask a vector of ints of the core numbers available to this block. 00169 */ 00170 void set_processor_affinity(const std::vector<int> &mask); 00171 00172 /*! 00173 * \brief Unset core affinity. 00174 */ 00175 void unset_processor_affinity(); 00176 00177 bool threaded; // set if thread is currently running. 00178 gruel::gr_thread_t thread; // portable thread handle 00179 00180 void start_perf_counters(); 00181 void stop_perf_counters(int noutput_items, int nproduced); 00182 void reset_perf_counters(); 00183 00184 // Calls to get performance counter items 00185 float pc_noutput_items(); 00186 float pc_nproduced(); 00187 float pc_input_buffers_full(size_t which); 00188 std::vector<float> pc_input_buffers_full(); 00189 float pc_output_buffers_full(size_t which); 00190 std::vector<float> pc_output_buffers_full(); 00191 float pc_work_time(); 00192 00193 float pc_noutput_items_var(); 00194 float pc_nproduced_var(); 00195 float pc_input_buffers_full_var(size_t which); 00196 std::vector<float> pc_input_buffers_full_var(); 00197 float pc_output_buffers_full_var(size_t which); 00198 std::vector<float> pc_output_buffers_full_var(); 00199 float pc_work_time_var(); 00200 00201 gr_tpb_detail d_tpb; // used by thread-per-block scheduler 00202 int d_produce_or; 00203 00204 // ---------------------------------------------------------------------------- 00205 00206 private: 00207 unsigned int d_ninputs; 00208 unsigned int d_noutputs; 00209 std::vector<gr_buffer_reader_sptr> d_input; 00210 std::vector<gr_buffer_sptr> d_output; 00211 bool d_done; 00212 00213 // Performance counters 00214 float d_avg_noutput_items; 00215 float d_var_noutput_items; 00216 float d_avg_nproduced; 00217 float d_var_nproduced; 00218 std::vector<float> d_avg_input_buffers_full; 00219 std::vector<float> d_var_input_buffers_full; 00220 std::vector<float> d_avg_output_buffers_full; 00221 std::vector<float> d_var_output_buffers_full; 00222 gruel::high_res_timer_type d_start_of_work, d_end_of_work; 00223 float d_avg_work_time; 00224 float d_var_work_time; 00225 float d_pc_counter; 00226 00227 gr_block_detail (unsigned int ninputs, unsigned int noutputs); 00228 00229 friend struct gr_tpb_detail; 00230 00231 friend GR_CORE_API gr_block_detail_sptr 00232 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00233 }; 00234 00235 GR_CORE_API gr_block_detail_sptr 00236 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00237 00238 GR_CORE_API long 00239 gr_block_detail_ncurrently_allocated (); 00240 00241 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */