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') 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