Loading...
Searching...
No Matches
block_detail.h
Go to the documentation of this file.
/* -*- c++ -*- */
/*
* Copyright 2004,2009,2010,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
#define INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H
#include <gnuradio/api.h>
#include <gnuradio/buffer.h>
#include <gnuradio/buffer_reader.h>
#include <gnuradio/high_res_timer.h>
#include <gnuradio/logger.h>
#include <gnuradio/runtime_types.h>
#include <gnuradio/tags.h>
#include <gnuradio/tpb_detail.h>
#include <stdexcept>
namespace gr {
/*!
* \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 block_detail
{
public:
~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, buffer_reader_sptr reader);
buffer_reader_sptr input(unsigned int which)
{
if (which >= d_ninputs)
throw std::invalid_argument("block_detail::input");
return d_input[which];
}
void set_output(unsigned int which, buffer_sptr buffer);
buffer_sptr output(unsigned int which)
{
if (which >= d_noutputs)
throw std::invalid_argument("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);
// sets nitems_read and nitems_written to 0 for all input/output
// buffers.
void reset_nitem_counters();
// Clears all tags from the input buffers.
void clear_tags();
/*!
* \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 tag_t& tag);
/*!
* \brief Removes a tag from the given input stream.
*
* Calls gr::buffer::remove_item_tag().
* The tag in question will then no longer appear on subsequent calls of
* get_tags_in_range().
*
* \param which_input an integer of which input stream to remove the tag from
* \param tag the tag object to add
* \param id The unique block ID (use gr::block::unique_id())
*/
void remove_item_tag(unsigned int which_input, const tag_t& tag, long id);
/*!
* \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
* \param id Block ID
*/
void get_tags_in_range(std::vector<tag_t>& v,
unsigned int which_input,
uint64_t abs_start,
uint64_t abs_end,
long id);
/*!
* \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
* \param id Block ID
*/
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);
/*!
* \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();
/*!
* \brief Get the current thread priority
*/
int thread_priority();
/*!
* \brief Set the current thread priority
*
* \param priority the new thread priority to set
*/
int set_thread_priority(int priority);
/*!
* Post general_work() cleanup to decrement the active counts for all inputs
* and outputs.
*/
void post_work_cleanup()
{
// Decrement active counts for all inputs and outputs
for (int i = 0; i < noutputs(); i++)
output(i)->decrement_active();
for (int i = 0; i < ninputs(); i++)
input(i)->buffer()->decrement_active();
}
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_throughput_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();
float pc_work_time_total();
tpb_detail d_tpb; // used by thread-per-block scheduler
int d_produce_or;
int consumed() const;
// necessary because stupidly block_executor.cc's "propagate_tags" is a function, not
// any class member
gr::logger_ptr d_logger, d_debug_logger;
// ----------------------------------------------------------------------------
private:
unsigned int d_ninputs;
unsigned int d_noutputs;
std::vector<buffer_reader_sptr> d_input;
std::vector<buffer_sptr> d_output;
bool d_done;
int d_consumed;
// Performance counters
float d_ins_noutput_items;
float d_avg_noutput_items;
float d_var_noutput_items;
float d_total_noutput_items;
gr::high_res_timer_type d_pc_start_time;
gr::high_res_timer_type d_pc_last_work_time;
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_total_work_time;
float d_avg_throughput;
float d_pc_counter;
block_detail(unsigned int ninputs, unsigned int noutputs);
friend struct tpb_detail;
friend GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs,
unsigned int noutputs);
};
GR_RUNTIME_API block_detail_sptr make_block_detail(unsigned int ninputs,
unsigned int noutputs);
GR_RUNTIME_API long block_detail_ncurrently_allocated();
} /* namespace gr */
#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:47
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:41
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