GNU Radio 3.6.4.2 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(), which removes the tag from its deque. 00111 * 00112 * \param which_input an integer of which input stream to remove the tag from 00113 * \param tag the tag object to add 00114 */ 00115 void remove_item_tag(unsigned int which_input, const gr_tag_t &tag); 00116 00117 /*! 00118 * \brief Given a [start,end), returns a vector of all tags in the range. 00119 * 00120 * Pass-through function to gr_buffer_reader to get a vector of tags 00121 * in given range. Range of counts is from start to end-1. 00122 * 00123 * Tags are tuples of: 00124 * (item count, source id, key, value) 00125 * 00126 * \param v a vector reference to return tags into 00127 * \param which_input an integer of which input stream to pull from 00128 * \param abs_start a uint64 count of the start of the range of interest 00129 * \param abs_end a uint64 count of the end of the range of interest 00130 */ 00131 void get_tags_in_range(std::vector<gr_tag_t> &v, 00132 unsigned int which_input, 00133 uint64_t abs_start, 00134 uint64_t abs_end); 00135 00136 /*! 00137 * \brief Given a [start,end), returns a vector of all tags in the range 00138 * with a given key. 00139 * 00140 * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of 00141 * tags from the buffers. This function then provides a secondary filter to 00142 * the tags to extract only tags with the given 'key'. 00143 * 00144 * Tags are tuples of: 00145 * (item count, source id, key, value) 00146 * 00147 * \param v a vector reference to return tags into 00148 * \param which_input an integer of which input stream to pull from 00149 * \param abs_start a uint64 count of the start of the range of interest 00150 * \param abs_end a uint64 count of the end of the range of interest 00151 * \param key a PMT symbol to select only tags of this key 00152 */ 00153 void get_tags_in_range(std::vector<gr_tag_t> &v, 00154 unsigned int which_input, 00155 uint64_t abs_start, 00156 uint64_t abs_end, 00157 const pmt::pmt_t &key); 00158 00159 /*! 00160 * \brief Set core affinity of block to the cores in the vector mask. 00161 * 00162 * \param mask a vector of ints of the core numbers available to this block. 00163 */ 00164 void set_processor_affinity(const std::vector<int> &mask); 00165 00166 /*! 00167 * \brief Unset core affinity. 00168 */ 00169 void unset_processor_affinity(); 00170 00171 bool threaded; // set if thread is currently running. 00172 gruel::gr_thread_t thread; // portable thread handle 00173 00174 void start_perf_counters(); 00175 void stop_perf_counters(int noutput_items, int nproduced); 00176 void reset_perf_counters(); 00177 00178 // Calls to get performance counter items 00179 float pc_noutput_items(); 00180 float pc_nproduced(); 00181 float pc_input_buffers_full(size_t which); 00182 std::vector<float> pc_input_buffers_full(); 00183 float pc_output_buffers_full(size_t which); 00184 std::vector<float> pc_output_buffers_full(); 00185 float pc_work_time(); 00186 00187 float pc_noutput_items_var(); 00188 float pc_nproduced_var(); 00189 float pc_input_buffers_full_var(size_t which); 00190 std::vector<float> pc_input_buffers_full_var(); 00191 float pc_output_buffers_full_var(size_t which); 00192 std::vector<float> pc_output_buffers_full_var(); 00193 float pc_work_time_var(); 00194 00195 gr_tpb_detail d_tpb; // used by thread-per-block scheduler 00196 int d_produce_or; 00197 00198 // ---------------------------------------------------------------------------- 00199 00200 private: 00201 unsigned int d_ninputs; 00202 unsigned int d_noutputs; 00203 std::vector<gr_buffer_reader_sptr> d_input; 00204 std::vector<gr_buffer_sptr> d_output; 00205 bool d_done; 00206 00207 // Performance counters 00208 float d_avg_noutput_items; 00209 float d_var_noutput_items; 00210 float d_avg_nproduced; 00211 float d_var_nproduced; 00212 std::vector<float> d_avg_input_buffers_full; 00213 std::vector<float> d_var_input_buffers_full; 00214 std::vector<float> d_avg_output_buffers_full; 00215 std::vector<float> d_var_output_buffers_full; 00216 gruel::high_res_timer_type d_start_of_work, d_end_of_work; 00217 float d_avg_work_time; 00218 float d_var_work_time; 00219 float d_pc_counter; 00220 00221 gr_block_detail (unsigned int ninputs, unsigned int noutputs); 00222 00223 friend struct gr_tpb_detail; 00224 00225 friend GR_CORE_API gr_block_detail_sptr 00226 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00227 }; 00228 00229 GR_CORE_API gr_block_detail_sptr 00230 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); 00231 00232 GR_CORE_API long 00233 gr_block_detail_ncurrently_allocated (); 00234 00235 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */