diff options
-rw-r--r-- | host/docs/usrp2.rst | 35 | ||||
-rw-r--r-- | host/include/uhd/transport/udp_zero_copy.hpp | 15 | ||||
-rw-r--r-- | host/include/uhd/usrp/usrp2.hpp | 4 | ||||
-rw-r--r-- | host/lib/device.cpp | 11 | ||||
-rw-r--r-- | host/lib/transport/udp_zero_copy_asio.cpp | 32 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 23 | ||||
-rw-r--r-- | host/utils/uhd_find_devices.cpp | 2 |
7 files changed, 94 insertions, 28 deletions
diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst index 092332442..f4c36fb27 100644 --- a/host/docs/usrp2.rst +++ b/host/docs/usrp2.rst @@ -126,3 +126,38 @@ MAC addresses, control packets, and fast-path settings. **Monitor the host network traffic:** Use wireshark to monitor packets sent to and received from the USRP2. + +------------------------------------------------------------------------ +Resize the send and receive buffers +------------------------------------------------------------------------ +It may be useful increase the size of the socket buffers to +move the burden of buffering samples into the kernel, or to +buffer incoming samples faster than they can be processed. +However, if you application cannot process samples fast enough, +no amount of buffering can save you. + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Device address params +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +To set the size of the buffers, +the usrp2 will accept two optional parameters in the device address. +Each parameter will accept a numeric value for the number of bytes. + +* recv_buff_size +* send_buff_size + +Example, set the args string to the following: +:: + + addr=192.168.10.2, recv_buff_size=100e6 + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +OS specific notes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +On linux, the maximum buffer sizes are capped by the sysctl values +**net.core.rmem_max** and **net.core.wmem_max**. +To change the maximum values, run the following commands: +:: + + sudo sysctl -w net.core.rmem_max=<new value> + sudo sysctl -w net.core.wmem_max=<new value> diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp index fd1cec46e..c74e6d7b7 100644 --- a/host/include/uhd/transport/udp_zero_copy.hpp +++ b/host/include/uhd/transport/udp_zero_copy.hpp @@ -52,6 +52,21 @@ public: * \param port a string representing the destination port */ static sptr make(const std::string &addr, const std::string &port); + + /*! + * Resize the the rx buffer size on the socket. + * \param num_bytes the new size for the socket buffer + * \return the actual number of bytes allowed by the OS + */ + virtual size_t resize_recv_buff_size(size_t num_bytes) = 0; + + /*! + * Resize the the tx buffer size on the socket. + * \param num_bytes the new size for the socket buffer + * \return the actual number of bytes allowed by the OS + */ + virtual size_t resize_send_buff_size(size_t num_bytes) = 0; + }; }} //namespace diff --git a/host/include/uhd/usrp/usrp2.hpp b/host/include/uhd/usrp/usrp2.hpp index 613b40ae3..7387e5dd4 100644 --- a/host/include/uhd/usrp/usrp2.hpp +++ b/host/include/uhd/usrp/usrp2.hpp @@ -35,6 +35,10 @@ public: * hint["addr"] = address, where address is a resolvable address * or ip address, which may or may not be a broadcast address. * + * Other optional device address keys: + * recv_buff_size: resizes the recv buffer on the data socket + * send_buff_size: resizes the send buffer on the data socket + * * \param hint a device addr with the usrp2 address filled in * \return a vector of device addresses for all usrp2s found */ diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 706f64951..88bd2cff4 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -97,11 +97,6 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){ - //copy keys that were in hint but not in dev_addr - //this way, we can pass additional transport arguments - BOOST_FOREACH(const std::string &key, hint.keys()){ - if (not dev_addr.has_key(key)) dev_addr[key] = hint[key]; - } //append the discovered address and its factory function dev_addr_makers.push_back(dev_addr_make_t(dev_addr, fcn.get<1>())); } @@ -127,6 +122,12 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ size_t dev_hash = hash_device_addr(dev_addr); //std::cout << boost::format("Hash: %u") % dev_hash << std::endl; + //copy keys that were in hint but not in dev_addr + //this way, we can pass additional transport arguments + BOOST_FOREACH(const std::string &key, hint.keys()){ + if (not dev_addr.has_key(key)) dev_addr[key] = hint[key]; + } + //map device address hash to created devices static uhd::dict<size_t, boost::weak_ptr<device> > hash_to_device; diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 7e643abad..09386a60c 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -19,8 +19,6 @@ #include <boost/cstdint.hpp> #include <boost/asio.hpp> #include <boost/thread.hpp> -#include <boost/format.hpp> -#include <iostream> using namespace uhd::transport; @@ -104,12 +102,13 @@ public: managed_recv_buffer::sptr get_recv_buff(void); managed_send_buffer::sptr get_send_buff(void); + //resize + size_t resize_recv_buff_size(size_t num_bytes); + size_t resize_send_buff_size(size_t num_bytes); + private: boost::asio::ip::udp::socket *_socket; boost::asio::io_service _io_service; - - size_t get_recv_buff_size(void); - void set_recv_buff_size(size_t); }; udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::string &port){ @@ -124,18 +123,6 @@ udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::strin _socket = new boost::asio::ip::udp::socket(_io_service); _socket->open(boost::asio::ip::udp::v4()); _socket->connect(receiver_endpoint); - - // set the rx socket buffer size: - // pick a huge size, and deal with whatever we get - set_recv_buff_size(size_t(54321e3)); //some big number! - size_t current_buff_size = get_recv_buff_size(); - std::cout << boost::format( - "Current rx socket buffer size: %d\n" - ) % current_buff_size; - if (current_buff_size < size_t(.1e6)) std::cout << boost::format( - "Adjust max rx socket buffer size (linux only):\n" - " sysctl -w net.core.rmem_max=VALUE\n" - ); } udp_zero_copy_impl::~udp_zero_copy_impl(void){ @@ -170,15 +157,18 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){ ); } -size_t udp_zero_copy_impl::get_recv_buff_size(void){ - boost::asio::socket_base::receive_buffer_size option; +size_t udp_zero_copy_impl::resize_recv_buff_size(size_t num_bytes){ + boost::asio::socket_base::receive_buffer_size option(num_bytes); + _socket->set_option(option); _socket->get_option(option); return option.value(); } -void udp_zero_copy_impl::set_recv_buff_size(size_t new_size){ - boost::asio::socket_base::receive_buffer_size option(new_size); +size_t udp_zero_copy_impl::resize_send_buff_size(size_t num_bytes){ + boost::asio::socket_base::send_buffer_size option(num_bytes); _socket->set_option(option); + _socket->get_option(option); + return option.value(); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 4079357f9..2b974fb9b 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -24,6 +24,7 @@ #include <boost/assign/list_of.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> +#include <boost/lexical_cast.hpp> #include <boost/bind.hpp> #include <boost/asio.hpp> //htonl and ntohl #include <iostream> @@ -50,7 +51,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ if (if_addrs.inet == asio::ip::address_v4::loopback().to_string()) continue; //create a new hint with this broadcast address - device_addr_t new_hint = hint; + device_addr_t new_hint; new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results @@ -117,6 +118,26 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ device_addr["addr"], num2str(USRP2_UDP_DATA_PORT) ); + //resize the recv data transport buffers + if (device_addr.has_key("recv_buff_size")){ + size_t num_byes = size_t(boost::lexical_cast<double>(device_addr["recv_buff_size"])); + size_t actual_bytes = data_transport->resize_recv_buff_size(num_byes); + if (num_byes != actual_bytes) std::cout << boost::format( + "Target recv buffer size: %d\n" + "Actual recv byffer size: %d" + ) % num_byes % actual_bytes << std::endl; + } + + //resize the send data transport buffers + if (device_addr.has_key("send_buff_size")){ + size_t num_byes = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"])); + size_t actual_bytes = data_transport->resize_send_buff_size(num_byes); + if (num_byes != actual_bytes) std::cout << boost::format( + "Target send buffer size: %d\n" + "Actual send byffer size: %d" + ) % num_byes % actual_bytes << std::endl; + } + //create the usrp2 implementation guts return device::sptr( new usrp2_impl(ctrl_transport, data_transport) diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp index 8222dc1f4..69e550fd4 100644 --- a/host/utils/uhd_find_devices.cpp +++ b/host/utils/uhd_find_devices.cpp @@ -53,7 +53,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "-- UHD Device " << i << std::endl; std::cout << "--------------------------------------------------" << std::endl; std::cout << device_addrs[i].to_string() << std::endl << std::endl; - uhd::device::make(device_addrs[i]); //test make + //uhd::device::make(device_addrs[i]); //test make } return 0; |