1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/* -*- c++ -*- */
/*
* Copyright 2004,2009,2010 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more detail.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_GR_BLOCK_DETAIL_H
#define INCLUDED_GR_BLOCK_DETAIL_H
#include <gr_runtime_api.h>
#include <gr_runtime_types.h>
#include <gr_tpb_detail.h>
#include <gr_tags.h>
#include <high_res_timer.h>
#include <stdexcept>
/*!
* \brief Implementation details to support the signal processing abstraction
* \ingroup internal
*
* This class contains implementation detail that should be "out of sight"
* of almost all users of GNU Radio. This decoupling also means that
* we can make changes to the guts without having to recompile everything.
*/
class GR_RUNTIME_API gr_block_detail {
public:
~gr_block_detail ();
int ninputs () const { return d_ninputs; }
int noutputs () const { return d_noutputs; }
bool sink_p () const { return d_noutputs == 0; }
bool source_p () const { return d_ninputs == 0; }
void set_done (bool done);
bool done () const { return d_done; }
void set_input (unsigned int which, gr_buffer_reader_sptr reader);
gr_buffer_reader_sptr input (unsigned int which)
{
if (which >= d_ninputs)
throw std::invalid_argument ("gr_block_detail::input");
return d_input[which];
}
void set_output (unsigned int which, gr_buffer_sptr buffer);
gr_buffer_sptr output (unsigned int which)
{
if (which >= d_noutputs)
throw std::invalid_argument ("gr_block_detail::output");
return d_output[which];
}
/*!
* \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed.
*/
void consume (int which_input, int how_many_items);
/*!
* \brief Tell the scheduler \p how_many_items were consumed on each input stream.
*/
void consume_each (int how_many_items);
/*!
* \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output.
*/
void produce (int which_output, int how_many_items);
/*!
* \brief Tell the scheduler \p how_many_items were produced on each output stream.
*/
void produce_each (int how_many_items);
// Return the number of items read on input stream which_input
uint64_t nitems_read(unsigned int which_input);
// Return the number of items written on output stream which_output
uint64_t nitems_written(unsigned int which_output);
/*!
* \brief Adds a new tag to the given output stream.
*
* Calls gr_buffer::add_item_tag(),
* which appends the tag onto its deque.
*
* \param which_output an integer of which output stream to attach the tag
* \param tag the tag object to add
*/
void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
/*!
* \brief Removes a tag from the given input stream.
*
* Calls gr_buffer::remove_item_tag(), which removes the tag from its deque.
*
* \param which_input an integer of which input stream to remove the tag from
* \param tag the tag object to add
*/
void remove_item_tag(unsigned int which_input, const gr_tag_t &tag);
/*!
* \brief Given a [start,end), returns a vector of all tags in the range.
*
* Pass-through function to gr_buffer_reader to get a vector of tags
* in given range. Range of counts is from start to end-1.
*
* Tags are tuples of:
* (item count, source id, key, value)
*
* \param v a vector reference to return tags into
* \param which_input an integer of which input stream to pull from
* \param abs_start a uint64 count of the start of the range of interest
* \param abs_end a uint64 count of the end of the range of interest
*/
void get_tags_in_range(std::vector<gr_tag_t> &v,
unsigned int which_input,
uint64_t abs_start,
uint64_t abs_end);
/*!
* \brief Given a [start,end), returns a vector of all tags in the range
* with a given key.
*
* Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of
* tags from the buffers. This function then provides a secondary filter to
* the tags to extract only tags with the given 'key'.
*
* Tags are tuples of:
* (item count, source id, key, value)
*
* \param v a vector reference to return tags into
* \param which_input an integer of which input stream to pull from
* \param abs_start a uint64 count of the start of the range of interest
* \param abs_end a uint64 count of the end of the range of interest
* \param key a PMT symbol to select only tags of this key
*/
void get_tags_in_range(std::vector<gr_tag_t> &v,
unsigned int which_input,
uint64_t abs_start,
uint64_t abs_end,
const pmt::pmt_t &key);
/*!
* \brief Set core affinity of block to the cores in the vector mask.
*
* \param mask a vector of ints of the core numbers available to this block.
*/
void set_processor_affinity(const std::vector<int> &mask);
/*!
* \brief Unset core affinity.
*/
void unset_processor_affinity();
bool threaded; // set if thread is currently running.
gr::thread::gr_thread_t thread; // portable thread handle
void start_perf_counters();
void stop_perf_counters(int noutput_items, int nproduced);
void reset_perf_counters();
// Calls to get performance counter items
float pc_noutput_items();
float pc_nproduced();
float pc_input_buffers_full(size_t which);
std::vector<float> pc_input_buffers_full();
float pc_output_buffers_full(size_t which);
std::vector<float> pc_output_buffers_full();
float pc_work_time();
float pc_noutput_items_avg();
float pc_nproduced_avg();
float pc_input_buffers_full_avg(size_t which);
std::vector<float> pc_input_buffers_full_avg();
float pc_output_buffers_full_avg(size_t which);
std::vector<float> pc_output_buffers_full_avg();
float pc_work_time_avg();
float pc_noutput_items_var();
float pc_nproduced_var();
float pc_input_buffers_full_var(size_t which);
std::vector<float> pc_input_buffers_full_var();
float pc_output_buffers_full_var(size_t which);
std::vector<float> pc_output_buffers_full_var();
float pc_work_time_var();
gr_tpb_detail d_tpb; // used by thread-per-block scheduler
int d_produce_or;
// ----------------------------------------------------------------------------
private:
unsigned int d_ninputs;
unsigned int d_noutputs;
std::vector<gr_buffer_reader_sptr> d_input;
std::vector<gr_buffer_sptr> d_output;
bool d_done;
// Performance counters
float d_ins_noutput_items;
float d_avg_noutput_items;
float d_var_noutput_items;
float d_ins_nproduced;
float d_avg_nproduced;
float d_var_nproduced;
std::vector<float> d_ins_input_buffers_full;
std::vector<float> d_avg_input_buffers_full;
std::vector<float> d_var_input_buffers_full;
std::vector<float> d_ins_output_buffers_full;
std::vector<float> d_avg_output_buffers_full;
std::vector<float> d_var_output_buffers_full;
gr::high_res_timer_type d_start_of_work, d_end_of_work;
float d_ins_work_time;
float d_avg_work_time;
float d_var_work_time;
float d_pc_counter;
gr_block_detail (unsigned int ninputs, unsigned int noutputs);
friend struct gr_tpb_detail;
friend GR_RUNTIME_API gr_block_detail_sptr
gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
};
GR_RUNTIME_API gr_block_detail_sptr
gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
GR_RUNTIME_API long
gr_block_detail_ncurrently_allocated ();
#endif /* INCLUDED_GR_BLOCK_DETAIL_H */
|