summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-27 09:42:36 -0700
committerJosh Blum <josh@joshknows.com>2010-04-27 09:42:36 -0700
commitb920557788fc5435915584bec6ab16a97d7c6090 (patch)
tree36ad5dc6058cd7164f11f47430ba6d0ace84e6ab
parent8497eb2ac016f72e2b9a9028e5126bc73f5b0c9a (diff)
downloaduhd-b920557788fc5435915584bec6ab16a97d7c6090.tar.gz
uhd-b920557788fc5435915584bec6ab16a97d7c6090.tar.bz2
uhd-b920557788fc5435915584bec6ab16a97d7c6090.zip
work on controlling the socket buffer sizes from the front end api
-rw-r--r--host/include/uhd/transport/udp_zero_copy.hpp15
-rw-r--r--host/include/uhd/usrp/usrp2.hpp4
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp34
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp21
4 files changed, 53 insertions, 21 deletions
diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp
index fd1cec46e..117f24b2f 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);
+
+ /*!
+ * 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;
+
+ /*!
+ * 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;
+
};
}} //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/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 7e643abad..315ae49d2 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 set_recv_buff_size(size_t num_bytes);
+ size_t set_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,20 @@ 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;
+//sysctl -w net.core.rmem_max=VALUE
+size_t udp_zero_copy_impl::set_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);
+//sysctl -w net.core.wmem_max=VALUE
+size_t udp_zero_copy_impl::set_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..ffcdbb43d 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>
@@ -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->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<double>(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)