GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
block_detail.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2009,2010,2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more detail.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
24 #define INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
25 
26 #include <gnuradio/api.h>
27 #include <gnuradio/runtime_types.h>
28 #include <gnuradio/tpb_detail.h>
29 #include <gnuradio/tags.h>
31 #include <stdexcept>
32 
33 namespace gr {
34 
35  /*!
36  * \brief Implementation details to support the signal processing abstraction
37  * \ingroup internal
38  *
39  * This class contains implementation detail that should be "out of
40  * sight" of almost all users of GNU Radio. This decoupling also
41  * means that we can make changes to the guts without having to
42  * recompile everything.
43  */
45  {
46  public:
47  ~block_detail();
48 
49  int ninputs() const { return d_ninputs; }
50  int noutputs() const { return d_noutputs; }
51  bool sink_p() const { return d_noutputs == 0; }
52  bool source_p() const { return d_ninputs == 0; }
53 
54  void set_done(bool done);
55  bool done() const { return d_done; }
56 
57  void set_input(unsigned int which, buffer_reader_sptr reader);
58  buffer_reader_sptr input(unsigned int which)
59  {
60  if(which >= d_ninputs)
61  throw std::invalid_argument("block_detail::input");
62  return d_input[which];
63  }
64 
65  void set_output(unsigned int which, buffer_sptr buffer);
66  buffer_sptr output(unsigned int which)
67  {
68  if(which >= d_noutputs)
69  throw std::invalid_argument("block_detail::output");
70  return d_output[which];
71  }
72 
73  /*!
74  * \brief Tell the scheduler \p how_many_items of input stream \p
75  * which_input were consumed.
76  */
77  void consume(int which_input, int how_many_items);
78 
79  /*!
80  * \brief Tell the scheduler \p how_many_items were consumed on
81  * each input stream.
82  */
83  void consume_each(int how_many_items);
84 
85  /*!
86  * \brief Tell the scheduler \p how_many_items were produced on
87  * output stream \p which_output.
88  */
89  void produce(int which_output, int how_many_items);
90 
91  /*!
92  * \brief Tell the scheduler \p how_many_items were produced on
93  * each output stream.
94  */
95  void produce_each(int how_many_items);
96 
97  // Return the number of items read on input stream which_input
98  uint64_t nitems_read(unsigned int which_input);
99 
100  // Return the number of items written on output stream which_output
101  uint64_t nitems_written(unsigned int which_output);
102 
103  /*!
104  * \brief Adds a new tag to the given output stream.
105  *
106  * Calls gr::buffer::add_item_tag(),
107  * which appends the tag onto its deque.
108  *
109  * \param which_output an integer of which output stream to attach the tag
110  * \param tag the tag object to add
111  */
112  void add_item_tag(unsigned int which_output, const tag_t &tag);
113 
114  /*!
115  * \brief Removes a tag from the given input stream.
116  *
117  * Calls gr::buffer::remove_item_tag().
118  * The tag in question will then no longer appear on subsequent calls of get_tags_in_range().
119  *
120  * \param which_input an integer of which input stream to remove the tag from
121  * \param tag the tag object to add
122  * \param id The unique block ID (use gr::block::unique_id())
123  */
124  void remove_item_tag(unsigned int which_input, const tag_t &tag, long id);
125 
126  /*!
127  * \brief Given a [start,end), returns a vector of all tags in the range.
128  *
129  * Pass-through function to gr::buffer_reader to get a vector of
130  * tags in given range. Range of counts is from start to end-1.
131  *
132  * Tags are tuples of:
133  * (item count, source id, key, value)
134  *
135  * \param v a vector reference to return tags into
136  * \param which_input an integer of which input stream to pull from
137  * \param abs_start a uint64 count of the start of the range of interest
138  * \param abs_end a uint64 count of the end of the range of interest
139  * \param id Block ID
140  */
141  void get_tags_in_range(std::vector<tag_t> &v,
142  unsigned int which_input,
143  uint64_t abs_start,
144  uint64_t abs_end,
145  long id);
146 
147  /*!
148  * \brief Given a [start,end), returns a vector of all tags in the
149  * range with a given key.
150  *
151  * Calls get_tags_in_range(which_input, abs_start, abs_end) to get
152  * a vector of tags from the buffers. This function then provides
153  * a secondary filter to the tags to extract only tags with the
154  * given 'key'.
155  *
156  * Tags are tuples of:
157  * (item count, source id, key, value)
158  *
159  * \param v a vector reference to return tags into
160  * \param which_input an integer of which input stream to pull from
161  * \param abs_start a uint64 count of the start of the range of interest
162  * \param abs_end a uint64 count of the end of the range of interest
163  * \param key a PMT symbol to select only tags of this key
164  * \param id Block ID
165  */
166  void get_tags_in_range(std::vector<tag_t> &v,
167  unsigned int which_input,
168  uint64_t abs_start,
169  uint64_t abs_end,
170  const pmt::pmt_t &key,
171  long id);
172 
173  /*!
174  * \brief Set core affinity of block to the cores in the vector
175  * mask.
176  *
177  * \param mask a vector of ints of the core numbers available to
178  * this block.
179  */
180  void set_processor_affinity(const std::vector<int> &mask);
181 
182  /*!
183  * \brief Unset core affinity.
184  */
185  void unset_processor_affinity();
186 
187  /*!
188  * \brief Get the current thread priority
189  */
190  int thread_priority();
191 
192  /*!
193  * \brief Set the current thread priority
194  *
195  * \param priority the new thread priority to set
196  */
197  int set_thread_priority(int priority);
198 
199  bool threaded; // set if thread is currently running.
200  gr::thread::gr_thread_t thread; // portable thread handle
201 
202  void start_perf_counters();
203  void stop_perf_counters(int noutput_items, int nproduced);
204  void reset_perf_counters();
205 
206  // Calls to get performance counter items
207  float pc_noutput_items();
208  float pc_nproduced();
209  float pc_input_buffers_full(size_t which);
210  std::vector<float> pc_input_buffers_full();
211  float pc_output_buffers_full(size_t which);
212  std::vector<float> pc_output_buffers_full();
213  float pc_work_time();
214 
215  float pc_noutput_items_avg();
216  float pc_nproduced_avg();
217  float pc_input_buffers_full_avg(size_t which);
218  std::vector<float> pc_input_buffers_full_avg();
219  float pc_output_buffers_full_avg(size_t which);
220  std::vector<float> pc_output_buffers_full_avg();
221  float pc_work_time_avg();
222  float pc_throughput_avg();
223 
224  float pc_noutput_items_var();
225  float pc_nproduced_var();
226  float pc_input_buffers_full_var(size_t which);
227  std::vector<float> pc_input_buffers_full_var();
228  float pc_output_buffers_full_var(size_t which);
229  std::vector<float> pc_output_buffers_full_var();
230  float pc_work_time_var();
231 
232  float pc_work_time_total();
233 
234  tpb_detail d_tpb; // used by thread-per-block scheduler
236 
237  // ----------------------------------------------------------------------------
238 
239  private:
240  unsigned int d_ninputs;
241  unsigned int d_noutputs;
242  std::vector<buffer_reader_sptr> d_input;
243  std::vector<buffer_sptr> d_output;
244  bool d_done;
245 
246  // Performance counters
247  float d_ins_noutput_items;
248  float d_avg_noutput_items;
249  float d_var_noutput_items;
250  float d_total_noutput_items;
251  gr::high_res_timer_type d_pc_start_time;
252  gr::high_res_timer_type d_pc_last_work_time;
253  float d_ins_nproduced;
254  float d_avg_nproduced;
255  float d_var_nproduced;
256  std::vector<float> d_ins_input_buffers_full;
257  std::vector<float> d_avg_input_buffers_full;
258  std::vector<float> d_var_input_buffers_full;
259  std::vector<float> d_ins_output_buffers_full;
260  std::vector<float> d_avg_output_buffers_full;
261  std::vector<float> d_var_output_buffers_full;
262  gr::high_res_timer_type d_start_of_work, d_end_of_work;
263  float d_ins_work_time;
264  float d_avg_work_time;
265  float d_var_work_time;
266  float d_total_work_time;
267  float d_avg_throughput;
268  float d_pc_counter;
269 
270  block_detail(unsigned int ninputs, unsigned int noutputs);
271 
272  friend struct tpb_detail;
273 
274  friend GR_RUNTIME_API block_detail_sptr
275  make_block_detail(unsigned int ninputs, unsigned int noutputs);
276  };
277 
278  GR_RUNTIME_API block_detail_sptr
279  make_block_detail(unsigned int ninputs, unsigned int noutputs);
280 
281  GR_RUNTIME_API long
283 
284 } /* namespace gr */
285 
286 #endif /* INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H */
Definition: tags.h:31
buffer_reader_sptr input(unsigned int which)
Definition: block_detail.h:58
GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs, unsigned int noutputs)
Implementation details to support the signal processing abstractionThis class contains implementation...
Definition: block_detail.h:44
gr::thread::gr_thread_t thread
Definition: block_detail.h:200
pthread_t gr_thread_t
a system-dependent typedef for the underlying thread type.
Definition: thread.h:57
Definition: cc_common.h:45
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
GR_RUNTIME_API int set_thread_priority(gr_thread_t thread, int priority)
set current thread priority for a given thread ID
GR_RUNTIME_API long block_detail_ncurrently_allocated()
Single writer, multiple reader fifo.
Definition: buffer.h:55
Include this header to use the message passing features.
Definition: logger.h:131
int d_produce_or
Definition: block_detail.h:235
bool sink_p() const
Definition: block_detail.h:51
GR_RUNTIME_API int thread_priority(gr_thread_t thread)
get current thread priority for a given thread ID
bool done() const
Definition: block_detail.h:55
signed long long high_res_timer_type
Typedef for the timer tick count.
Definition: high_res_timer.h:49
used by thread-per-block scheduler
Definition: tpb_detail.h:37
bool threaded
Definition: block_detail.h:199
tpb_detail d_tpb
Definition: block_detail.h:234
bool source_p() const
Definition: block_detail.h:52
buffer_sptr output(unsigned int which)
Definition: block_detail.h:66
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
int ninputs() const
Definition: block_detail.h:49
int noutputs() const
Definition: block_detail.h:50