GNU Radio C++ API Reference: block_detail.h Source File

| GNU Radio C++ API Reference 3.10.12.0 The Free & Open Software Radio Ecosystem |

Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
12#define INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/buffer.h>
16#include <gnuradio/buffer_reader.h>
17#include <gnuradio/high_res_timer.h>
18#include <gnuradio/logger.h>
19#include <gnuradio/runtime_types.h>
20#include <gnuradio/tags.h>
21#include <gnuradio/tpb_detail.h>
22#include <stdexcept>
23
24namespace gr {
25
26/*!
27 * \brief Implementation details to support the signal processing abstraction
28 * \ingroup internal
29 *
30 * This class contains implementation detail that should be "out of
31 * sight" of almost all users of GNU Radio. This decoupling also
32 * means that we can make changes to the guts without having to
33 * recompile everything.
34 */
35 class GR_RUNTIME_API block_detail
36{
37public:
38 ~block_detail();
39
40 int ninputs() const { return d_ninputs; }
41 int noutputs() const { return d_noutputs; }
42 bool sink_p() const { return d_noutputs == 0; }
43 bool source_p() const { return d_ninputs == 0; }
44
45 void set_done(bool done);
46 bool done() const { return d_done; }
47
48 void set_input(unsigned int which, buffer_reader_sptr reader);
49 buffer_reader_sptr input(unsigned int which)
50 {
51 if (which >= d_ninputs)
52 throw std::invalid_argument("block_detail::input");
53 return d_input[which];
54 }
55
56 void set_output(unsigned int which, buffer_sptr buffer);
57 buffer_sptr output(unsigned int which)
58 {
59 if (which >= d_noutputs)
60 throw std::invalid_argument("block_detail::output");
61 return d_output[which];
62 }
63
64 /*!
65 * \brief Tell the scheduler \p how_many_items of input stream \p
66 * which_input were consumed.
67 */
68 void consume(int which_input, int how_many_items);
69
70 /*!
71 * \brief Tell the scheduler \p how_many_items were consumed on
72 * each input stream.
73 */
74 void consume_each(int how_many_items);
75
76 /*!
77 * \brief Tell the scheduler \p how_many_items were produced on
78 * output stream \p which_output.
79 */
80 void produce(int which_output, int how_many_items);
81
82 /*!
83 * \brief Tell the scheduler \p how_many_items were produced on
84 * each output stream.
85 */
86 void produce_each(int how_many_items);
87
88 // Return the number of items read on input stream which_input
89 uint64_t nitems_read(unsigned int which_input);
90
91 // Return the number of items written on output stream which_output
92 uint64_t nitems_written(unsigned int which_output);
93
94 // sets nitems_read and nitems_written to 0 for all input/output
95 // buffers.
96 void reset_nitem_counters();
97
98 // Clears all tags from the input buffers.
99 void clear_tags();
100
101 /*!
102 * \brief Adds a new tag to the given output stream.
103 *
104 * Calls gr::buffer::add_item_tag(),
105 * which appends the tag onto its deque.
106 *
107 * \param which_output an integer of which output stream to attach the tag
108 * \param tag the tag object to add
109 */
110 void add_item_tag(unsigned int which_output, const tag_t& tag);
111
112 /*!
113 * \brief Removes a tag from the given input stream.
114 *
115 * Calls gr::buffer::remove_item_tag().
116 * The tag in question will then no longer appear on subsequent calls of
117 * get_tags_in_range().
118 *
119 * \param which_input an integer of which input stream to remove the tag from
120 * \param tag the tag object to add
121 * \param id The unique block ID (use gr::block::unique_id())
122 */
123 void remove_item_tag(unsigned int which_input, const tag_t& tag, long id);
124
125 /*!
126 * \brief Given a [start,end), returns a vector of all tags in the range.
127 *
128 * Pass-through function to gr::buffer_reader to get a vector of
129 * tags in given range. Range of counts is from start to end-1.
130 *
131 * Tags are tuples of:
132 * (item count, source id, key, value)
133 *
134 * \param v a vector reference to return tags into
135 * \param which_input an integer of which input stream to pull from
136 * \param abs_start a uint64 count of the start of the range of interest
137 * \param abs_end a uint64 count of the end of the range of interest
138 * \param id Block ID
139 */
140 void get_tags_in_range(std::vector<tag_t>& v,
141 unsigned int which_input,
142 uint64_t abs_start,
143 uint64_t abs_end,
144 long id);
145
146 /*!
147 * \brief Given a [start,end), returns a vector of all tags in the
148 * range with a given key.
149 *
150 * Calls get_tags_in_range(which_input, abs_start, abs_end) to get
151 * a vector of tags from the buffers. This function then provides
152 * a secondary filter to the tags to extract only tags with the
153 * given 'key'.
154 *
155 * Tags are tuples of:
156 * (item count, source id, key, value)
157 *
158 * \param v a vector reference to return tags into
159 * \param which_input an integer of which input stream to pull from
160 * \param abs_start a uint64 count of the start of the range of interest
161 * \param abs_end a uint64 count of the end of the range of interest
162 * \param key a PMT symbol to select only tags of this key
163 * \param id Block ID
164 */
165 void get_tags_in_range(std::vector<tag_t>& v,
166 unsigned int which_input,
167 uint64_t abs_start,
168 uint64_t abs_end,
169 const pmt::pmt_t& key,
170 long id);
171
172 /*!
173 * \brief Set core affinity of block to the cores in the vector
174 * mask.
175 *
176 * \param mask a vector of ints of the core numbers available to
177 * this block.
178 */
179 void set_processor_affinity(const std::vector<int>& mask);
180
181 /*!
182 * \brief Unset core affinity.
183 */
184 void unset_processor_affinity();
185
186 /*!
187 * \brief Get the current thread priority
188 */
189 int thread_priority();
190
191 /*!
192 * \brief Set the current thread priority
193 *
194 * \param priority the new thread priority to set
195 */
196 int set_thread_priority(int priority);
197
198 /*!
199 * Post general_work() cleanup to decrement the active counts for all inputs
200 * and outputs.
201 */
202 void post_work_cleanup()
203 {
204 // Decrement active counts for all inputs and outputs
205 for (int i = 0; i < noutputs(); i++)
206 output(i)->decrement_active();
207 for (int i = 0; i < ninputs(); i++)
208 input(i)->buffer()->decrement_active();
209 }
210
211 bool threaded; // set if thread is currently running.
212 gr::thread::gr_thread_t thread; // portable thread handle
213
214 void start_perf_counters();
215 void stop_perf_counters(int noutput_items, int nproduced);
216 void reset_perf_counters();
217
218 // Calls to get performance counter items
219 float pc_noutput_items();
220 float pc_nproduced();
221 float pc_input_buffers_full(size_t which);
222 std::vector<float> pc_input_buffers_full();
223 float pc_output_buffers_full(size_t which);
224 std::vector<float> pc_output_buffers_full();
225 float pc_work_time();
226
227 float pc_noutput_items_avg();
228 float pc_nproduced_avg();
229 float pc_input_buffers_full_avg(size_t which);
230 std::vector<float> pc_input_buffers_full_avg();
231 float pc_output_buffers_full_avg(size_t which);
232 std::vector<float> pc_output_buffers_full_avg();
233 float pc_work_time_avg();
234 float pc_throughput_avg();
235
236 float pc_noutput_items_var();
237 float pc_nproduced_var();
238 float pc_input_buffers_full_var(size_t which);
239 std::vector<float> pc_input_buffers_full_var();
240 float pc_output_buffers_full_var(size_t which);
241 std::vector<float> pc_output_buffers_full_var();
242 float pc_work_time_var();
243
244 float pc_work_time_total();
245
246 tpb_detail d_tpb; // used by thread-per-block scheduler
247 int d_produce_or;
248
249 int consumed() const;
250
251 // necessary because stupidly block_executor.cc's "propagate_tags" is a function, not
252 // any class member
253 gr::logger_ptr d_logger, d_debug_logger;
254
255 // ----------------------------------------------------------------------------
256
257private:
258 unsigned int d_ninputs;
259 unsigned int d_noutputs;
260 std::vector<buffer_reader_sptr> d_input;
261 std::vector<buffer_sptr> d_output;
262 bool d_done;
263 int d_consumed;
264
265 // Performance counters
266 float d_ins_noutput_items;
267 float d_avg_noutput_items;
268 float d_var_noutput_items;
269 float d_total_noutput_items;
270 gr::high_res_timer_type d_pc_start_time;
271 gr::high_res_timer_type d_pc_last_work_time;
272 float d_ins_nproduced;
273 float d_avg_nproduced;
274 float d_var_nproduced;
275 std::vector<float> d_ins_input_buffers_full;
276 std::vector<float> d_avg_input_buffers_full;
277 std::vector<float> d_var_input_buffers_full;
278 std::vector<float> d_ins_output_buffers_full;
279 std::vector<float> d_avg_output_buffers_full;
280 std::vector<float> d_var_output_buffers_full;
281 gr::high_res_timer_type d_start_of_work, d_end_of_work;
282 float d_ins_work_time;
283 float d_avg_work_time;
284 float d_var_work_time;
285 float d_total_work_time;
286 float d_avg_throughput;
287 float d_pc_counter;
288
289 block_detail(unsigned int ninputs, unsigned int noutputs);
290
291 friend struct tpb_detail;
292
293 friend GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs,
294 unsigned int noutputs);
295};
296
297 GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs,
298 unsigned int noutputs);
299
300 GR_RUNTIME_API long block_detail_ncurrently_allocated();
301
302} /* namespace gr */
303
304#endif /* INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H */
buffer.h
buffer_reader.h
gr::block_detail::pc_work_time
float pc_work_time()
gr::block_detail::pc_work_time_total
float pc_work_time_total()
gr::block_detail::threaded
bool threaded
Definition block_detail.h:211
gr::block_detail::set_processor_affinity
void set_processor_affinity(const std::vector< int > &mask)
Set core affinity of block to the cores in the vector mask.
gr::block_detail::make_block_detail
friend GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs, unsigned int noutputs)
gr::block_detail::done
bool done() const
Definition block_detail.h:46
gr::block_detail::remove_item_tag
void remove_item_tag(unsigned int which_input, const tag_t &tag, long id)
Removes a tag from the given input stream.
gr::block_detail::pc_noutput_items_avg
float pc_noutput_items_avg()
gr::block_detail::pc_nproduced_avg
float pc_nproduced_avg()
gr::block_detail::pc_input_buffers_full_avg
float pc_input_buffers_full_avg(size_t which)
gr::block_detail::thread_priority
int thread_priority()
Get the current thread priority.
gr::block_detail::input
buffer_reader_sptr input(unsigned int which)
Definition block_detail.h:49
gr::block_detail::d_tpb
tpb_detail d_tpb
Definition block_detail.h:246
gr::block_detail::start_perf_counters
void start_perf_counters()
gr::block_detail::tpb_detail
friend struct tpb_detail
Definition block_detail.h:291
gr::block_detail::pc_output_buffers_full_avg
float pc_output_buffers_full_avg(size_t which)
gr::block_detail::d_debug_logger
gr::logger_ptr d_debug_logger
Definition block_detail.h:253
gr::block_detail::set_output
void set_output(unsigned int which, buffer_sptr buffer)
gr::block_detail::pc_nproduced
float pc_nproduced()
gr::block_detail::produce_each
void produce_each(int how_many_items)
Tell the scheduler how_many_items were produced on each output stream.
gr::block_detail::pc_nproduced_var
float pc_nproduced_var()
gr::block_detail::pc_work_time_avg
float pc_work_time_avg()
gr::block_detail::sink_p
bool sink_p() const
Definition block_detail.h:42
gr::block_detail::pc_output_buffers_full_var
std::vector< float > pc_output_buffers_full_var()
gr::block_detail::pc_output_buffers_full
float pc_output_buffers_full(size_t which)
gr::block_detail::noutputs
int noutputs() const
Definition block_detail.h:41
gr::block_detail::pc_noutput_items_var
float pc_noutput_items_var()
gr::block_detail::nitems_written
uint64_t nitems_written(unsigned int which_output)
gr::block_detail::pc_input_buffers_full
std::vector< float > pc_input_buffers_full()
gr::block_detail::pc_output_buffers_full
std::vector< float > pc_output_buffers_full()
gr::block_detail::nitems_read
uint64_t nitems_read(unsigned int which_input)
gr::block_detail::add_item_tag
void add_item_tag(unsigned int which_output, const tag_t &tag)
Adds a new tag to the given output stream.
gr::block_detail::d_logger
gr::logger_ptr d_logger
Definition block_detail.h:253
gr::block_detail::pc_input_buffers_full
float pc_input_buffers_full(size_t which)
gr::block_detail::pc_noutput_items
float pc_noutput_items()
gr::block_detail::pc_input_buffers_full_var
std::vector< float > pc_input_buffers_full_var()
gr::block_detail::consume
void consume(int which_input, int how_many_items)
Tell the scheduler how_many_items of input stream which_input were consumed.
gr::block_detail::d_produce_or
int d_produce_or
Definition block_detail.h:247
gr::block_detail::pc_output_buffers_full_avg
std::vector< float > pc_output_buffers_full_avg()
gr::block_detail::get_tags_in_range
void get_tags_in_range(std::vector< tag_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, long id)
Given a [start,end), returns a vector of all tags in the range.
gr::block_detail::consume_each
void consume_each(int how_many_items)
Tell the scheduler how_many_items were consumed on each input stream.
gr::block_detail::source_p
bool source_p() const
Definition block_detail.h:43
gr::block_detail::clear_tags
void clear_tags()
gr::block_detail::get_tags_in_range
void get_tags_in_range(std::vector< tag_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt::pmt_t &key, long id)
Given a [start,end), returns a vector of all tags in the range with a given key.
gr::block_detail::thread
gr::thread::gr_thread_t thread
Definition block_detail.h:212
gr::block_detail::consumed
int consumed() const
gr::block_detail::pc_input_buffers_full_avg
std::vector< float > pc_input_buffers_full_avg()
gr::block_detail::pc_work_time_var
float pc_work_time_var()
gr::block_detail::pc_output_buffers_full_var
float pc_output_buffers_full_var(size_t which)
gr::block_detail::set_thread_priority
int set_thread_priority(int priority)
Set the current thread priority.
gr::block_detail::produce
void produce(int which_output, int how_many_items)
Tell the scheduler how_many_items were produced on output stream which_output.
gr::block_detail::set_input
void set_input(unsigned int which, buffer_reader_sptr reader)
gr::block_detail::reset_perf_counters
void reset_perf_counters()
gr::block_detail::pc_throughput_avg
float pc_throughput_avg()
gr::block_detail::reset_nitem_counters
void reset_nitem_counters()
gr::block_detail::output
buffer_sptr output(unsigned int which)
Definition block_detail.h:57
gr::block_detail::unset_processor_affinity
void unset_processor_affinity()
Unset core affinity.
gr::block_detail::pc_input_buffers_full_var
float pc_input_buffers_full_var(size_t which)
gr::block_detail::stop_perf_counters
void stop_perf_counters(int noutput_items, int nproduced)
gr::block_detail::post_work_cleanup
void post_work_cleanup()
Definition block_detail.h:202
gr::block_detail::set_done
void set_done(bool done)
gr::block_detail::ninputs
int ninputs() const
Definition block_detail.h:40
gr::block_detail::~block_detail
~block_detail()
gr::buffer
Single writer, multiple reader fifo.
Definition buffer.h:67
api.h
GR_RUNTIME_API
#define GR_RUNTIME_API
Definition gnuradio-runtime/include/gnuradio/api.h:18
high_res_timer.h
logger.h
gr::thread::gr_thread_t
pthread_t gr_thread_t
a system-dependent typedef for the underlying thread type.
Definition thread.h:50
gr
GNU Radio logging wrapper.
Definition basic_block.h:29
gr::make_block_detail
GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs, unsigned int noutputs)
gr::logger_ptr
std::shared_ptr< logger > logger_ptr
Definition logger.h:250
gr::high_res_timer_type
signed long long high_res_timer_type
Typedef for the timer tick count.
Definition high_res_timer.h:40
gr::block_detail_ncurrently_allocated
GR_RUNTIME_API long block_detail_ncurrently_allocated()
pmt::pmt_t
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition pmt.h:83
runtime_types.h
gr::tag_t
Definition tags.h:19
v
Definition cc_common.h:35
tags.h
tpb_detail.h