diff options
20 files changed, 145 insertions, 65 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 4950e8666c..674e52084a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -300,7 +300,7 @@ gr_block::is_set_max_noutput_items() } void -gr_block::set_processor_affinity(const std::vector<unsigned int> &mask) +gr_block::set_processor_affinity(const std::vector<int> &mask) { d_affinity = mask; if(d_detail) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index e4b30267e6..402c8ee7f1 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -459,9 +459,9 @@ class GR_CORE_API gr_block : public gr_basic_block { /*! * \brief Set the thread's affinity to processor core \p n. * - * \param mask a vector of unsigned ints of the core numbers available to this block. + * \param mask a vector of ints of the core numbers available to this block. */ - void set_processor_affinity(const std::vector<unsigned int> &mask); + void set_processor_affinity(const std::vector<int> &mask); /*! * \brief Remove processor affinity to a specific core. @@ -471,7 +471,7 @@ class GR_CORE_API gr_block : public gr_basic_block { /*! * \brief Get the current processor affinity. */ - std::vector<unsigned int> processor_affinity() { return d_affinity; } + std::vector<int> processor_affinity() { return d_affinity; } // ---------------------------------------------------------------------------- @@ -489,7 +489,7 @@ class GR_CORE_API gr_block : public gr_basic_block { int d_max_noutput_items; // value of max_noutput_items for this block int d_min_noutput_items; tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream - std::vector<unsigned int> d_affinity; // thread affinity proc. mask + std::vector<int> d_affinity; // thread affinity proc. mask protected: gr_block (void){} //allows pure virtual interface sub-classes diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index a80f64d027..a53489f9a2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -83,9 +83,9 @@ class gr_block : public gr_basic_block { float pc_work_time_var(); // Methods to manage processor affinity. - void set_processor_affinity(const gr_vector_uint &mask); + void set_processor_affinity(const std::vector<int> &mask); void unset_processor_affinity(); - gr_vector_uint processor_affinity(); + std::vector<int> processor_affinity(); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 82081039ac..af80e61cff 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -215,7 +215,7 @@ gr_block_detail::get_tags_in_range(std::vector<gr_tag_t> &v, } void -gr_block_detail::set_processor_affinity(const std::vector<unsigned int> &mask) +gr_block_detail::set_processor_affinity(const std::vector<int> &mask) { if(threaded) { try { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 32a01e763a..15d85135ae 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -159,9 +159,9 @@ class GR_CORE_API gr_block_detail { /*! * \brief Set core affinity of block to the cores in the vector mask. * - * \param mask a vector of unsigned ints of the core numbers available to this block. + * \param mask a vector of ints of the core numbers available to this block. */ - void set_processor_affinity(const std::vector<unsigned int> &mask); + void set_processor_affinity(const std::vector<int> &mask); /*! * \brief Unset core affinity. diff --git a/gnuradio-core/src/lib/runtime/gr_logger.h b/gnuradio-core/src/lib/runtime/gr_logger.h index 2ccd498822..2931a29172 100644 --- a/gnuradio-core/src/lib/runtime/gr_logger.h +++ b/gnuradio-core/src/lib/runtime/gr_logger.h @@ -44,6 +44,7 @@ #include <gr_core_api.h> #include <assert.h> #include <iostream> +#include <boost/format.hpp> //#ifndef ENABLE_GR_LOG //#define ENABLE_GR_LOG 1 diff --git a/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc index 3c4a75fd37..26ce2231aa 100644 --- a/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc @@ -24,6 +24,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_tagged_stream_block.h> gr_tagged_stream_block::gr_tagged_stream_block (const std::string &name, @@ -111,7 +112,8 @@ gr_tagged_stream_block::general_work (int noutput_items, } for (unsigned i = 0; i < input_items.size(); i++) { if (d_n_input_items_reqd[i] == -1) { - throw std::runtime_error("Missing length tag."); + GR_LOG_FATAL(d_logger, boost::format("Missing a required length tag on port %1% at item #%2%") % i % nitems_read(i)); + throw std::runtime_error("Missing length tag."); } if (d_n_input_items_reqd[i] > ninput_items[i]) { return 0; diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index 1d3dafadf8..6bbc9ceb89 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -269,7 +269,7 @@ void qa_gr_top_block::t11_set_block_affinity() gr_block_sptr src (gr_make_null_source(sizeof(float))); gr_block_sptr snk (gr_make_null_sink(sizeof(float))); - std::vector<unsigned int> set(1, 0), ret; + std::vector<int> set(1, 0), ret; src->set_processor_affinity(set); tb->connect(src, 0, snk, 0); diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_affinity.py b/gnuradio-core/src/python/gnuradio/gr/qa_affinity.py new file mode 100644 index 0000000000..7b3ca6ed63 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_affinity.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# Copyright 2013 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 details. +# +# 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. +# + +from gnuradio import gr, gr_unittest + +class test_affinity(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000(self): + # Just run some data through and make sure it doesn't puke. + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + + src = gr.vector_source_f(src_data) + snk = gr.vector_sink_f() + + src.set_processor_affinity([0,]) + self.tb.connect(src, snk) + self.tb.run() + + a = src.processor_affinity() + + self.assertEqual((0,), a) + +if __name__ == '__main__': + gr_unittest.run(test_affinity, "test_affinity.xml") diff --git a/gr-digital/include/digital/packet_headergenerator_bb.h b/gr-digital/include/digital/packet_headergenerator_bb.h index 8d92bf84ed..cec860fd55 100644 --- a/gr-digital/include/digital/packet_headergenerator_bb.h +++ b/gr-digital/include/digital/packet_headergenerator_bb.h @@ -33,18 +33,33 @@ namespace gr { * \brief Generates a header for a tagged, streamed packet. * \ingroup digital * - * Input: A tagged stream. The first element must have a tag with the key - * specified in len_tag_key, which hold the exact number of elements - * in the PDU. - * Output: An tagged stream of length header_len. The output is determined - * by a header formatter. + * Input: A tagged stream. This is consumed entirely, it is not appended + * to the output stream. + * Output: An tagged stream containing the header. The details on the header + * are set in a header formatter object (of type packet_header_default + * or a subclass thereof). If only a number of bits is specified, a + * default header is generated (see packet_header_default). */ class DIGITAL_API packet_headergenerator_bb : virtual public gr_tagged_stream_block { public: typedef boost::shared_ptr<packet_headergenerator_bb> sptr; - static sptr make(const packet_header_default::sptr &header_formatter); + /* \param header_formatter A header formatter object. + * \param len_tag_key Length tag key. Note that for header generation, + * it is irrelevant which tag names are set in the + * formatter object, only this value is relevant! + */ + static sptr make( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key="packet_len" + ); + + /* \param header_len If this value is given, a packet_header_default + * object is used to generate the header. This is + * the number of bits per header. + * \param len_tag_key Length tag key. + */ static sptr make( long header_len, const std::string &len_tag_key = "packet_len"); diff --git a/gr-digital/include/digital/packet_headerparser_b.h b/gr-digital/include/digital/packet_headerparser_b.h index a3db069cbd..2dc6a80717 100644 --- a/gr-digital/include/digital/packet_headerparser_b.h +++ b/gr-digital/include/digital/packet_headerparser_b.h @@ -35,7 +35,11 @@ namespace gr { * * In a sense, this is the inverse block to packet_headergenerator_bb. * The difference is, the parsed header is not output as a stream, - * but as a message. + * but as a PMT dictionary, which is published to message port with + * the id "header_data". + * The dictionary consists of the tags created by the header formatter + * object. You should be able to use the exact same formatter object + * as used on the Tx side in the packet_headergenerator_bb. * * If only a header length is given, this block uses the default header * format. diff --git a/gr-digital/lib/packet_header_default.cc b/gr-digital/lib/packet_header_default.cc index dac57512d3..2bcbf59957 100644 --- a/gr-digital/lib/packet_header_default.cc +++ b/gr-digital/lib/packet_header_default.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <string.h> #include <digital/packet_header_default.h> namespace gr { diff --git a/gr-digital/lib/packet_headergenerator_bb_impl.cc b/gr-digital/lib/packet_headergenerator_bb_impl.cc index 2698977728..3232858148 100644 --- a/gr-digital/lib/packet_headergenerator_bb_impl.cc +++ b/gr-digital/lib/packet_headergenerator_bb_impl.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_io_signature.h> #include "packet_headergenerator_bb_impl.h" @@ -30,9 +31,12 @@ namespace gr { namespace digital { packet_headergenerator_bb::sptr - packet_headergenerator_bb::make(const packet_header_default::sptr &header_formatter) + packet_headergenerator_bb::make( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key + ) { - return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter)); + return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter, len_tag_key)); } @@ -45,25 +49,23 @@ namespace gr { const packet_header_default::sptr header_formatter( new packet_header_default(header_len, len_tag_key) ); - return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter)); + return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter, len_tag_key)); } packet_headergenerator_bb_impl::packet_headergenerator_bb_impl( - const gr::digital::packet_header_default::sptr &header_formatter + const gr::digital::packet_header_default::sptr &header_formatter, + const std::string &len_tag_key ) : gr_tagged_stream_block("packet_headergenerator_bb_impl", gr_make_io_signature(1, 1, sizeof (char)), gr_make_io_signature(1, 1, sizeof (char)), - pmt::pmt_symbol_to_string(header_formatter->len_tag_key())), - d_formatter(header_formatter), - d_input_size(1), - d_header_len(header_formatter->header_len()), - d_len_tag_value(pmt::pmt_from_long(d_header_len)) + len_tag_key), + d_formatter(header_formatter) { - set_output_multiple(d_header_len); + set_output_multiple(d_formatter->header_len()); // This is the worst case rate, because we don't know the true value, of course - set_relative_rate(d_header_len); + set_relative_rate(d_formatter->header_len()); set_tag_propagation_policy(TPP_DONT); } @@ -79,10 +81,11 @@ namespace gr { { unsigned char *out = (unsigned char *) output_items[0]; if (!d_formatter->header_formatter(ninput_items[0], out)) { + GR_LOG_FATAL(d_logger, boost::format("header_formatter() returned false (this shouldn't happen). Offending header started at %1%") % nitems_read(0)); throw std::runtime_error("header formatter returned false."); } - return d_header_len; + return d_formatter->header_len(); } } /* namespace digital */ diff --git a/gr-digital/lib/packet_headergenerator_bb_impl.h b/gr-digital/lib/packet_headergenerator_bb_impl.h index 7d2494cf8b..ce60fdf76c 100644 --- a/gr-digital/lib/packet_headergenerator_bb_impl.h +++ b/gr-digital/lib/packet_headergenerator_bb_impl.h @@ -31,16 +31,16 @@ namespace gr { { private: gr::digital::packet_header_default::sptr d_formatter; - int d_input_size; - int d_header_len; - pmt::pmt_t d_len_tag_value; public: - packet_headergenerator_bb_impl(const packet_header_default::sptr &header_formatter); + packet_headergenerator_bb_impl( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key + ); ~packet_headergenerator_bb_impl(); void remove_length_tags(const std::vector<std::vector<gr_tag_t> > &tags) {}; - int calculate_output_stream_length(const gr_vector_int &ninput_items) { return d_header_len; }; + int calculate_output_stream_length(const gr_vector_int &ninput_items) { return d_formatter->header_len(); }; int work(int noutput_items, gr_vector_int &ninput_items, diff --git a/gr-digital/lib/packet_headerparser_b_impl.cc b/gr-digital/lib/packet_headerparser_b_impl.cc index 65883f5515..5f8f0cd560 100644 --- a/gr-digital/lib/packet_headerparser_b_impl.cc +++ b/gr-digital/lib/packet_headerparser_b_impl.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_io_signature.h> #include "packet_headerparser_b_impl.h" @@ -73,6 +74,7 @@ namespace gr { std::vector<gr_tag_t> tags; if (!d_header_formatter->header_parser(in, tags)) { + GR_LOG_INFO(d_logger, boost::format("Detected an invalid packet at item %1%") % nitems_read(0)); message_port_pub(msg_port_id, pmt::PMT_F); } else { pmt::pmt_t dict(pmt::pmt_make_dict()); diff --git a/gr-digital/python/ofdm_txrx.py b/gr-digital/python/ofdm_txrx.py index 2734e9cc1c..de9811a646 100644 --- a/gr-digital/python/ofdm_txrx.py +++ b/gr-digital/python/ofdm_txrx.py @@ -128,10 +128,10 @@ class ofdm_tx(gr.hier_block2): total_sync_word = sync_word1 + sync_word2 crc = digital.crc32_bb(False, self.frame_length_tag_key) formatter_object = digital.packet_header_ofdm( - occupied_carriers, 1, "", "", "", - bps_header + occupied_carriers=occupied_carriers, n_syms=1, + bits_per_sym=self.bps_header ) - header_gen = digital.packet_headergenerator_bb(formatter_object.base()) + header_gen = digital.packet_headergenerator_bb(formatter_object.base(), self.frame_length_tag_key) header_payload_mux = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, self.frame_length_tag_key) self.connect(self, crc, header_gen, header_mod, (header_payload_mux, 0)) payload_constellation = _get_constellation(bps_payload) diff --git a/gr-digital/python/qa_ofdm_txrx.py b/gr-digital/python/qa_ofdm_txrx.py index 778f03f515..ad5a996b2c 100755 --- a/gr-digital/python/qa_ofdm_txrx.py +++ b/gr-digital/python/qa_ofdm_txrx.py @@ -21,8 +21,11 @@ # import numpy +import random from gnuradio import gr, gr_unittest -import digital_swig +import digital_swig as digital +from ofdm_txrx import ofdm_tx, ofdm_rx +from utils import tagged_streams class test_ofdm_txrx (gr_unittest.TestCase): diff --git a/gr-digital/python/qa_packet_headergenerator_bb.py b/gr-digital/python/qa_packet_headergenerator_bb.py index 1aeaa86063..11f6ebfe79 100755 --- a/gr-digital/python/qa_packet_headergenerator_bb.py +++ b/gr-digital/python/qa_packet_headergenerator_bb.py @@ -109,7 +109,7 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): tag3.value = pmt.pmt_from_long(4) src = gr.vector_source_b(data, False, 1, (tag1, tag2, tag3)) formatter_object = digital.packet_header_default(12, tagname) - header = digital.packet_headergenerator_bb(formatter_object.formatter()) + header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname) sink = gr.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() @@ -141,7 +141,7 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, tagname) self.assertEqual(formatter_object.header_len(), 6) self.assertEqual(pmt.pmt_symbol_to_string(formatter_object.len_tag_key()), tagname) - header = digital.packet_headergenerator_bb(formatter_object.formatter()) + header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname) sink = gr.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 60832675cd..10c6c38ccc 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -75,7 +75,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(const std::vector<unsigned int> &mask); + GRUEL_API void thread_bind_to_processor(const std::vector<int> &mask); /*! \brief Convineince function to bind the current thread to a single core. * @@ -87,7 +87,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(unsigned int n); + GRUEL_API void thread_bind_to_processor(int n); /*! \brief Bind a thread to a set of cores. * @@ -101,7 +101,7 @@ namespace gruel { * support in this way since 10.5 is not what we want or can use in * this fashion). */ - GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector<unsigned int> &mask); + GRUEL_API void thread_bind_to_processor(gr_thread_t thread, const std::vector<int> &mask); /*! \brief Convineince function to bind the a thread to a single core. diff --git a/gruel/src/lib/thread.cc b/gruel/src/lib/thread.cc index 8ebe822fbf..a5116b687b 100644 --- a/gruel/src/lib/thread.cc +++ b/gruel/src/lib/thread.cc @@ -38,33 +38,33 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { - std::vector<unsigned int> mask(1, n); + std::vector<int> mask(1, n); thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(const std::vector<unsigned int> &mask) + thread_bind_to_processor(const std::vector<int> &mask) { thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { - std::vector<unsigned int> mask(1, n); + std::vector<int> mask(1, n); thread_bind_to_processor(thread, mask); } void - thread_bind_to_processor(gr_thread_t thread, const std::vector<unsigned int> &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector<int> &mask) { //DWORD_PTR mask = (1 << n); DWORD_PTR dword_mask = 0; - std::vector<unsigned int> _mask = mask; - std::vector<unsigned int>::iterator itr; + std::vector<int> _mask = mask; + std::vector<int>::iterator itr; for(itr = _mask.begin(); itr != _mask.end(); itr++) dword_mask |= (1 << (*itr)); @@ -106,25 +106,25 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { // Not implemented on OSX } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { // Not implemented on OSX } void - thread_bind_to_processor(const std::vector<unsigned int> &mask) + thread_bind_to_processor(const std::vector<int> &mask) { // Not implemented on OSX } void - thread_bind_to_processor(gr_thread_t thread, const std::vector<unsigned int> &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector<int> &mask) { // Not implemented on OSX } @@ -157,32 +157,32 @@ namespace gruel { } void - thread_bind_to_processor(unsigned int n) + thread_bind_to_processor(int n) { - std::vector<unsigned int> mask(1, n); + std::vector<int> mask(1, n); thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(const std::vector<unsigned int> &mask) + thread_bind_to_processor(const std::vector<int> &mask) { thread_bind_to_processor(get_current_thread_id(), mask); } void - thread_bind_to_processor(gr_thread_t thread, unsigned int n) + thread_bind_to_processor(gr_thread_t thread, int n) { - std::vector<unsigned int> mask(1, n); + std::vector<int> mask(1, n); thread_bind_to_processor(thread, mask); } void - thread_bind_to_processor(gr_thread_t thread, const std::vector<unsigned int> &mask) + thread_bind_to_processor(gr_thread_t thread, const std::vector<int> &mask) { cpu_set_t set; size_t len = sizeof(cpu_set_t); - std::vector<unsigned int> _mask = mask; - std::vector<unsigned int>::iterator itr; + std::vector<int> _mask = mask; + std::vector<int>::iterator itr; CPU_ZERO(&set); for(itr = _mask.begin(); itr != _mask.end(); itr++) |