diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-11-05 10:10:33 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 12:21:33 -0800 |
commit | 2d110b1deda68351fdfbf6a8b7cc0c62897d57bc (patch) | |
tree | 46ba06a37a207faab5a9d7eb102d585a7e26084e | |
parent | b7488af14e6bf23eb52b815d30c3f37836834387 (diff) | |
download | uhd-2d110b1deda68351fdfbf6a8b7cc0c62897d57bc.tar.gz uhd-2d110b1deda68351fdfbf6a8b7cc0c62897d57bc.tar.bz2 uhd-2d110b1deda68351fdfbf6a8b7cc0c62897d57bc.zip |
rfnoc_graph: Modify find_blocks() to sort return value
With this patch, the elements of of the return value of find_blocks()
are sorted lexicographically (specifically, using
uhd::rfnoc::block_id_it::operator<()).
The underlying block_container class stores the blocks in an unordered
set, so the return value for find_blocks() was always sorted randomly.
multi_usrp_rfnoc had to sort the return values every time find_blocks()
was used to get a useful return value.
Because find_blocks() had no contract for the order of returned blocks,
this change simply sorts the return value before returning it.
multi_usrp_rfnoc is modified to remove all the sorts that are now
superfluous.
A good way to see the change is to run uhd_usrp_probe, which will now
contain content like this:
| _____________________________________________________
| /
| | RFNoC blocks on this device:
| |
| | * 0/DDC#0
| | * 0/DDC#1
| | * 0/DUC#0
| | * 0/DUC#1
| | * 0/DmaFIFO#0
| | * 0/Radio#0
| | * 0/Radio#1
Assuming the blocks don't change, the order of this list will always be
the same following this patch. Note that the order is unrelated to the
order on the control crossbar, which it never was.
-rw-r--r-- | host/include/uhd/rfnoc_graph.hpp | 12 | ||||
-rw-r--r-- | host/lib/rfnoc/block_container.cpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/multi_usrp_rfnoc.cpp | 37 |
3 files changed, 16 insertions, 38 deletions
diff --git a/host/include/uhd/rfnoc_graph.hpp b/host/include/uhd/rfnoc_graph.hpp index 34091ddbd..c62eaf558 100644 --- a/host/include/uhd/rfnoc_graph.hpp +++ b/host/include/uhd/rfnoc_graph.hpp @@ -57,17 +57,23 @@ public: * Block Discovery/Retrieval ******************************************/ /*! Returns the block ids of all blocks that match the specified hint + * * Uses block_id_t::match() internally. * If no matching block is found, it returns an empty vector. * - * To access specialized block controller classes (i.e. derived from noc_block_base), - * use the templated version of this function, e.g. + * The returned vector is sorted lexicographically. + * + * To access specialized block controller classes (i.e. derived from + * uhd::rfnoc::noc_block_base), use the templated version of this function: * \code{.cpp} * // Assume DEV is an rfnoc_graph::sptr - * auto null_blocks = DEV->find_blocks<null_noc_block>("NullSrcSink"); + * auto null_blocks = DEV->find_blocks<null_block_control>("NullSrcSink"); * if (null_blocks.empty()) { cout << "No null blocks found!" << endl; } * \endcode + * * \note this access is not thread safe if performed during block enumeration + * + * \returns A sorted list of block IDs that match the hint */ virtual std::vector<block_id_t> find_blocks( const std::string& block_id_hint) const = 0; diff --git a/host/lib/rfnoc/block_container.cpp b/host/lib/rfnoc/block_container.cpp index e7fd396ba..5b68134ab 100644 --- a/host/lib/rfnoc/block_container.cpp +++ b/host/lib/rfnoc/block_container.cpp @@ -48,6 +48,11 @@ std::vector<block_id_t> block_container_t::find_blocks( block_ids.push_back(id); } } + std::sort(block_ids.begin(), + block_ids.end(), + [](const uhd::rfnoc::block_id_t& i, const uhd::rfnoc::block_id_t& j) { + return i < j; + }); return block_ids; } diff --git a/host/lib/usrp/multi_usrp_rfnoc.cpp b/host/lib/usrp/multi_usrp_rfnoc.cpp index 5242da965..99c07dc8c 100644 --- a/host/lib/usrp/multi_usrp_rfnoc.cpp +++ b/host/lib/usrp/multi_usrp_rfnoc.cpp @@ -96,20 +96,9 @@ public: multi_usrp_rfnoc(rfnoc_graph::sptr graph, const device_addr_t& addr) : _args(addr), _graph(graph), _tree(_graph->get_tree()) { - // Discover all of the radios on our devices and create a mapping between radio - // chains and channel numbers + // Discover all of the radios on our devices and create a mapping between + // radio chains and channel numbers. The result is sorted. auto radio_blk_ids = _graph->find_blocks("Radio"); - // find_blocks doesn't sort, so we need to - std::sort(radio_blk_ids.begin(), - radio_blk_ids.end(), - [](uhd::rfnoc::block_id_t i, uhd::rfnoc::block_id_t j) -> bool { - if (i.get_device_no() != j.get_device_no()) { - return i.get_device_no() < j.get_device_no(); - } else { - return i.get_block_count() < j.get_block_count(); - } - }); - // If we don't find any radios, we don't have a multi_usrp object if (radio_blk_ids.empty()) { throw uhd::runtime_error( @@ -895,17 +884,6 @@ public: // Discover all of the radios on our devices and create a mapping between radio // chains and channel numbers auto radio_blk_ids = _graph->find_blocks(std::to_string(mboard) + "/Radio"); - // find_blocks doesn't sort, so we need to - std::sort(radio_blk_ids.begin(), - radio_blk_ids.end(), - [](uhd::rfnoc::block_id_t i, uhd::rfnoc::block_id_t j) -> bool { - if (i.get_device_no() != j.get_device_no()) { - return i.get_device_no() < j.get_device_no(); - } else { - return i.get_block_count() < j.get_block_count(); - } - }); - // If we don't find any radios, we don't have a multi_usrp object if (radio_blk_ids.empty()) { throw uhd::runtime_error( @@ -1515,17 +1493,6 @@ public: // Discover all of the radios on our devices and create a mapping between radio // chains and channel numbers auto radio_blk_ids = _graph->find_blocks(std::to_string(mboard) + "/Radio"); - // find_blocks doesn't sort, so we need to - std::sort(radio_blk_ids.begin(), - radio_blk_ids.end(), - [](uhd::rfnoc::block_id_t i, uhd::rfnoc::block_id_t j) -> bool { - if (i.get_device_no() != j.get_device_no()) { - return i.get_device_no() < j.get_device_no(); - } else { - return i.get_block_count() < j.get_block_count(); - } - }); - // If we don't find any radios, we don't have a multi_usrp object if (radio_blk_ids.empty()) { throw uhd::runtime_error( |