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