From b920557788fc5435915584bec6ab16a97d7c6090 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 27 Apr 2010 09:42:36 -0700 Subject: work on controlling the socket buffer sizes from the front end api --- host/lib/usrp/usrp2/usrp2_impl.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 4079357f9..ffcdbb43d 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include //htonl and ntohl #include @@ -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(device_addr["recv_buff_size"])); + size_t actual_bytes = data_transport->set_recv_buff_size(num_byes); + std::cout << boost::format( + "Target recv buffer size: %d" + "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(device_addr["send_buff_size"])); + size_t actual_bytes = data_transport->set_send_buff_size(num_byes); + std::cout << boost::format( + "Target send buffer size: %d" + "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) -- cgit v1.2.3 From 04dae4bf6b11b5aad383f95be6a77863a7c2f6ec Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 27 Apr 2010 15:20:53 -0700 Subject: setting size of buffers from device args --- host/docs/usrp2.rst | 35 ++++++++++++++++++++++++++++ host/include/uhd/transport/udp_zero_copy.hpp | 8 +++---- host/lib/device.cpp | 11 +++++---- host/lib/transport/udp_zero_copy_asio.cpp | 10 ++++---- host/lib/usrp/usrp2/usrp2_impl.cpp | 14 +++++------ host/utils/uhd_find_devices.cpp | 2 +- 6 files changed, 57 insertions(+), 23 deletions(-) (limited to 'host/lib/usrp/usrp2') 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= + sudo sysctl -w net.core.wmem_max= diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp index 117f24b2f..c74e6d7b7 100644 --- a/host/include/uhd/transport/udp_zero_copy.hpp +++ b/host/include/uhd/transport/udp_zero_copy.hpp @@ -54,18 +54,18 @@ public: static sptr make(const std::string &addr, const std::string &port); /*! - * The the rx buffer size on the socket. + * 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 set_recv_buff_size(size_t num_bytes) = 0; + virtual size_t resize_recv_buff_size(size_t num_bytes) = 0; /*! - * The the tx buffer size on the socket. + * 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 set_send_buff_size(size_t num_bytes) = 0; + virtual size_t resize_send_buff_size(size_t num_bytes) = 0; }; 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 > hash_to_device; diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 315ae49d2..09386a60c 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -103,8 +103,8 @@ public: managed_send_buffer::sptr get_send_buff(void); //resize - size_t set_recv_buff_size(size_t num_bytes); - size_t set_send_buff_size(size_t num_bytes); + 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; @@ -157,16 +157,14 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){ ); } -//sysctl -w net.core.rmem_max=VALUE -size_t udp_zero_copy_impl::set_recv_buff_size(size_t num_bytes){ +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(); } -//sysctl -w net.core.wmem_max=VALUE -size_t udp_zero_copy_impl::set_send_buff_size(size_t num_bytes){ +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); diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index ffcdbb43d..2b974fb9b 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -51,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 @@ -121,9 +121,9 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ //resize the recv data transport buffers if (device_addr.has_key("recv_buff_size")){ size_t num_byes = size_t(boost::lexical_cast(device_addr["recv_buff_size"])); - size_t actual_bytes = data_transport->set_recv_buff_size(num_byes); - std::cout << boost::format( - "Target recv buffer size: %d" + 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; } @@ -131,9 +131,9 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ //resize the send data transport buffers if (device_addr.has_key("send_buff_size")){ size_t num_byes = size_t(boost::lexical_cast(device_addr["send_buff_size"])); - size_t actual_bytes = data_transport->set_send_buff_size(num_byes); - std::cout << boost::format( - "Target send buffer size: %d" + 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; } 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; -- cgit v1.2.3 From dd8373063684418eb978cdd1a2b0896923ba1d47 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 30 Apr 2010 12:22:23 -0700 Subject: made buffer size args part of constructor --- host/include/uhd/transport/udp_zero_copy.hpp | 24 ++++-------- host/lib/transport/udp_zero_copy_asio.cpp | 57 +++++++++++++++++++--------- host/lib/usrp/usrp2/usrp2_impl.cpp | 32 ++++++---------- 3 files changed, 59 insertions(+), 54 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp index c74e6d7b7..525606a9f 100644 --- a/host/include/uhd/transport/udp_zero_copy.hpp +++ b/host/include/uhd/transport/udp_zero_copy.hpp @@ -50,23 +50,15 @@ public: * * \param addr a string representing the destination address * \param port a string representing the destination port + * \param recv_buff_size size in bytes for the recv buffer, 0 for automatic + * \param send_buff_size size in bytes for the send buffer, 0 for automatic */ - 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; - + static sptr make( + const std::string &addr, + const std::string &port, + size_t recv_buff_size = 0, + size_t send_buff_size = 0 + ); }; }} //namespace diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 09386a60c..ee44803f4 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include using namespace uhd::transport; @@ -103,8 +105,18 @@ public: 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); + size_t resize_recv_buff(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(); + } + size_t resize_send_buff(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(); + } private: boost::asio::ip::udp::socket *_socket; @@ -157,25 +169,34 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){ ); } -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(); -} - -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(); -} - /*********************************************************************** * UDP zero copy make function **********************************************************************/ udp_zero_copy::sptr udp_zero_copy::make( - const std::string &addr, const std::string &port + const std::string &addr, + const std::string &port, + size_t recv_buff_size, + size_t send_buff_size ){ - return sptr(new udp_zero_copy_impl(addr, port)); + boost::shared_ptr udp_trans(new udp_zero_copy_impl(addr, port)); + + //resize the recv buffer if size was provided + if (recv_buff_size > 0){ + size_t actual_bytes = udp_trans->resize_recv_buff(recv_buff_size); + if (recv_buff_size != actual_bytes) std::cout << boost::format( + "Target recv buffer size: %d\n" + "Actual recv byffer size: %d" + ) % recv_buff_size % actual_bytes << std::endl; + } + + //resize the send buffer if size was provided + if (send_buff_size > 0){ + size_t actual_bytes = udp_trans->resize_send_buff(send_buff_size); + if (send_buff_size != actual_bytes) std::cout << boost::format( + "Target send buffer size: %d\n" + "Actual send byffer size: %d" + ) % send_buff_size % actual_bytes << std::endl; + } + + return udp_trans; } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 2b974fb9b..1dde8c054 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -113,31 +113,23 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ device_addr["addr"], num2str(USRP2_UDP_CTRL_PORT) ); - //create a data transport - udp_zero_copy::sptr data_transport = udp_zero_copy::make( - device_addr["addr"], num2str(USRP2_UDP_DATA_PORT) - ); - - //resize the recv data transport buffers + //extract the receive and send buffer sizes + size_t recv_buff_size = 0, send_buff_size= 0 ; if (device_addr.has_key("recv_buff_size")){ - size_t num_byes = size_t(boost::lexical_cast(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; + recv_buff_size = size_t(boost::lexical_cast(device_addr["recv_buff_size"])); } - - //resize the send data transport buffers if (device_addr.has_key("send_buff_size")){ - size_t num_byes = size_t(boost::lexical_cast(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; + send_buff_size = size_t(boost::lexical_cast(device_addr["send_buff_size"])); } + //create a data transport + udp_zero_copy::sptr data_transport = udp_zero_copy::make( + device_addr["addr"], + num2str(USRP2_UDP_DATA_PORT), + recv_buff_size, + send_buff_size + ); + //create the usrp2 implementation guts return device::sptr( new usrp2_impl(ctrl_transport, data_transport) -- cgit v1.2.3