diff options
author | Ciro Nishiguchi <ciro.nishiguchi@ni.com> | 2018-10-27 11:10:26 -0500 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-10 17:26:18 -0800 |
commit | fd3f5d011fb99304402cbf3c1e8c596478316119 (patch) | |
tree | 17d98a9879d7dff88227cbe53fab342119963675 /host/tests/common | |
parent | e934e56ce2f8ca0c2f843577032f1a22bf938930 (diff) | |
download | uhd-fd3f5d011fb99304402cbf3c1e8c596478316119.tar.gz uhd-fd3f5d011fb99304402cbf3c1e8c596478316119.tar.bz2 uhd-fd3f5d011fb99304402cbf3c1e8c596478316119.zip |
tests: Add benchmark of streaming code paths
Add a benchmark of packet handlers and device3 flow control. Benchmarks
use mock transport objects.
Diffstat (limited to 'host/tests/common')
-rw-r--r-- | host/tests/common/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/tests/common/mock_zero_copy.cpp | 40 | ||||
-rw-r--r-- | host/tests/common/mock_zero_copy.hpp | 82 |
3 files changed, 104 insertions, 20 deletions
diff --git a/host/tests/common/CMakeLists.txt b/host/tests/common/CMakeLists.txt index e48e85c2f..58299c688 100644 --- a/host/tests/common/CMakeLists.txt +++ b/host/tests/common/CMakeLists.txt @@ -12,4 +12,4 @@ add_library(uhd_test ${CMAKE_CURRENT_SOURCE_DIR}/mock_ctrl_iface_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_zero_copy.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/graph_impl.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/async_msg_handler.cpp -)
\ No newline at end of file +) diff --git a/host/tests/common/mock_zero_copy.cpp b/host/tests/common/mock_zero_copy.cpp index eee96234d..bc49c3f10 100644 --- a/host/tests/common/mock_zero_copy.cpp +++ b/host/tests/common/mock_zero_copy.cpp @@ -11,8 +11,12 @@ using namespace uhd::transport; mock_zero_copy::mock_zero_copy( - vrt::if_packet_info_t::link_type_t link_type -) : _link_type(link_type) { + vrt::if_packet_info_t::link_type_t link_type, + size_t recv_frame_size, + size_t send_frame_size +) : _link_type(link_type) + , _recv_frame_size(recv_frame_size) + , _send_frame_size(send_frame_size) { } uhd::transport::managed_recv_buffer::sptr mock_zero_copy::get_recv_buff(double) { @@ -22,18 +26,32 @@ uhd::transport::managed_recv_buffer::sptr mock_zero_copy::get_recv_buff(double) if (_rx_mems.empty()) { return uhd::transport::managed_recv_buffer::sptr(); // timeout } - _mrbs.push_back(boost::make_shared<mock_mrb>()); + uhd::transport::managed_recv_buffer::sptr mrb = - _mrbs.back()->get_new(_rx_mems.front(), _rx_lens.front()); - _rx_mems.pop_front(); - _rx_lens.pop_front(); + _mrb.get_new(_rx_mems.front(), _rx_lens.front()); + + if (not _reuse_recv_memory) { + _rx_mems.pop_front(); + _rx_lens.pop_front(); + } + return mrb; } uhd::transport::managed_send_buffer::sptr mock_zero_copy::get_send_buff(double) { - _msbs.push_back(boost::make_shared<mock_msb>()); - _tx_mems.push_back( - boost::shared_array<uint8_t>(new uint8_t[SEND_BUFF_SIZE])); - _tx_lens.push_back(SEND_BUFF_SIZE); - return _msbs.back()->get_new(_tx_mems.back(), &_tx_lens.back()); + if (not _reuse_send_memory or _tx_mems.size() == 0) { + _tx_mems.push_back( + boost::shared_array<uint8_t>(new uint8_t[_send_frame_size])); + _tx_lens.push_back(_send_frame_size); + } + + return _msb.get_new(_tx_mems.back(), &_tx_lens.back()); +} + +void mock_zero_copy::set_reuse_recv_memory(bool reuse_recv) { + _reuse_recv_memory = reuse_recv; +} + +void mock_zero_copy::set_reuse_send_memory(bool reuse_send) { + _reuse_send_memory = reuse_send; } diff --git a/host/tests/common/mock_zero_copy.hpp b/host/tests/common/mock_zero_copy.hpp index 867300ac5..8d27c9b46 100644 --- a/host/tests/common/mock_zero_copy.hpp +++ b/host/tests/common/mock_zero_copy.hpp @@ -13,6 +13,7 @@ #include <uhd/transport/zero_copy.hpp> #include <uhd/types/endianness.hpp> #include <uhd/types/sid.hpp> +#include <uhd/exception.hpp> #include <uhd/utils/byteswap.hpp> #include <uhd/exception.hpp> #include <boost/make_shared.hpp> @@ -29,8 +30,8 @@ * Tx and Rx are separate. We can access the other end of the FIFOs from * this class. */ -static constexpr size_t SEND_BUFF_SIZE = 1024; -static constexpr size_t RECV_BUFF_SIZE = 1024; +static constexpr size_t DEFAULT_SEND_FRAME_SIZE = 1024; +static constexpr size_t DEFAULT_RECV_FRAME_SIZE = 1024; /*********************************************************************** * Dummy managed buffers for testing @@ -68,15 +69,28 @@ class mock_zero_copy : public uhd::transport::zero_copy_if { public: typedef boost::shared_ptr<mock_zero_copy> sptr; - mock_zero_copy(uhd::transport::vrt::if_packet_info_t::link_type_t type); + mock_zero_copy( + uhd::transport::vrt::if_packet_info_t::link_type_t type, + size_t recv_frame_size = DEFAULT_RECV_FRAME_SIZE, + size_t send_frame_size = DEFAULT_SEND_FRAME_SIZE + ); uhd::transport::managed_recv_buffer::sptr get_recv_buff(double); uhd::transport::managed_send_buffer::sptr get_send_buff(double); size_t get_num_recv_frames(void) const { return 1; } size_t get_num_send_frames(void) const { return 1; } - size_t get_recv_frame_size(void) const { return RECV_BUFF_SIZE; } - size_t get_send_frame_size(void) const { return SEND_BUFF_SIZE; } + size_t get_recv_frame_size(void) const { return _recv_frame_size; } + size_t get_send_frame_size(void) const { return _send_frame_size; } + + template <typename T> + void push_back_packet( + uhd::transport::vrt::if_packet_info_t& ifpi, + const std::vector<T>& otw_data = std::vector<T>(), + uhd::endianness_t endianness = uhd::ENDIANNESS_BIG); + + void set_reuse_recv_memory(bool reuse_recv); + void set_reuse_send_memory(bool reuse_send); void set_simulate_io_error(bool status) { _simulate_io_error = status; } @@ -93,6 +107,13 @@ class mock_zero_copy : public uhd::transport::zero_copy_if { ); template <uhd::endianness_t endianness = uhd::ENDIANNESS_BIG> + void push_back_flow_ctrl_packet( + uhd::transport::vrt::if_packet_info_t::packet_type_t type, + uint32_t packet_count, + uint32_t byte_count + ); + + template <uhd::endianness_t endianness = uhd::ENDIANNESS_BIG> void pop_send_packet( uhd::transport::vrt::if_packet_info_t &ifpi ); @@ -104,11 +125,18 @@ class mock_zero_copy : public uhd::transport::zero_copy_if { std::list<boost::shared_array<uint8_t>> _rx_mems; std::list<size_t> _rx_lens; - std::vector<boost::shared_ptr<mock_msb>> _msbs; - std::vector<boost::shared_ptr<mock_mrb>> _mrbs; + mock_msb _msb; + mock_mrb _mrb; uhd::transport::vrt::if_packet_info_t::link_type_t _link_type; + size_t _recv_frame_size = DEFAULT_RECV_FRAME_SIZE; + size_t _send_frame_size = DEFAULT_RECV_FRAME_SIZE; + bool _simulate_io_error = false; + + bool _reuse_recv_memory = false; + bool _reuse_send_memory = false; + }; template <typename T, uhd::endianness_t endianness> @@ -130,7 +158,7 @@ void mock_zero_copy::push_back_recv_packet( const size_t max_pkt_len = ifpi.num_payload_words32*sizeof(uint32_t)+max_hdr_len; - UHD_ASSERT_THROW(max_pkt_len <= RECV_BUFF_SIZE); + UHD_ASSERT_THROW(max_pkt_len <= _recv_frame_size); // Create recv buffer _rx_mems.push_back(boost::shared_array<uint8_t>(new uint8_t[max_pkt_len])); @@ -199,4 +227,42 @@ void mock_zero_copy::pop_send_packet( _tx_lens.pop_front(); } +template <uhd::endianness_t endianness> +void mock_zero_copy::push_back_flow_ctrl_packet( + uhd::transport::vrt::if_packet_info_t::packet_type_t type, + uint32_t packet_count, + uint32_t byte_count +) +{ + using namespace uhd::transport; + + UHD_ASSERT_THROW( + type == vrt::if_packet_info_t::PACKET_TYPE_FC or + type == vrt::if_packet_info_t::PACKET_TYPE_ACK); + + // Only implemented for chdr packets currently + UHD_ASSERT_THROW(_link_type == vrt::if_packet_info_t::LINK_TYPE_CHDR); + + const size_t packet_len_in_words32 = 2; + + vrt::if_packet_info_t ifpi; + ifpi.packet_type = type; + ifpi.num_payload_words32 = packet_len_in_words32; + ifpi.num_payload_bytes = ifpi.num_payload_words32*sizeof(uint32_t); + ifpi.has_tsf = false; + + std::vector<uint32_t> data(packet_len_in_words32, 0); + + if (endianness == uhd::ENDIANNESS_BIG) { + data[0] = uhd::ntohx(packet_count); + data[1] = uhd::ntohx(byte_count); + } + else { + data[0] = uhd::wtohx(packet_count); + data[1] = uhd::wtohx(byte_count); + } + + push_back_recv_packet<uint32_t, endianness>(ifpi, data); +} + #endif /*INCLUDED_MOCK_XPORT_HPP*/ |