summaryrefslogtreecommitdiffstats
path: root/host/lib/transport
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-10 23:29:22 -0700
committerJosh Blum <josh@joshknows.com>2010-08-10 23:29:22 -0700
commit293ccdccd1e111942e9cc48ab87690da5202e406 (patch)
tree4e861ca41fabc1e2664b7d0807242ab9c61544fd /host/lib/transport
parent1301d665d621358ec6eccb41a020a4689cb0b566 (diff)
parent9e419c7b7f35062ceb2ed4e508cadb163067593f (diff)
downloaduhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.gz
uhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.bz2
uhd-293ccdccd1e111942e9cc48ab87690da5202e406.zip
usrp-e: merged master, does not build
Diffstat (limited to 'host/lib/transport')
-rw-r--r--host/lib/transport/udp_simple.cpp21
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp26
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp52
-rw-r--r--host/lib/transport/zero_copy.cpp6
4 files changed, 60 insertions, 45 deletions
diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp
index f339127ad..89750f99d 100644
--- a/host/lib/transport/udp_simple.cpp
+++ b/host/lib/transport/udp_simple.cpp
@@ -34,12 +34,13 @@ using namespace uhd::transport;
* This is okay bacause this is the slow-path implementation.
*
* \param socket the asio socket
+ * \param timeout_ms the timeout in milliseconds
*/
static void reasonable_recv_timeout(
- boost::asio::ip::udp::socket &socket
+ boost::asio::ip::udp::socket &socket, size_t timeout_ms
){
boost::asio::deadline_timer timer(socket.get_io_service());
- timer.expires_from_now(boost::posix_time::milliseconds(100));
+ timer.expires_from_now(boost::posix_time::milliseconds(timeout_ms));
while (not (socket.available() or timer.expires_from_now().is_negative())){
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
@@ -55,8 +56,8 @@ public:
~udp_connected_impl(void);
//send/recv
- size_t send(const boost::asio::const_buffer &buff);
- size_t recv(const boost::asio::mutable_buffer &buff);
+ size_t send(const boost::asio::const_buffer &);
+ size_t recv(const boost::asio::mutable_buffer &, size_t);
private:
boost::asio::ip::udp::socket *_socket;
@@ -85,8 +86,8 @@ size_t udp_connected_impl::send(const boost::asio::const_buffer &buff){
return _socket->send(boost::asio::buffer(buff));
}
-size_t udp_connected_impl::recv(const boost::asio::mutable_buffer &buff){
- reasonable_recv_timeout(*_socket);
+size_t udp_connected_impl::recv(const boost::asio::mutable_buffer &buff, size_t timeout_ms){
+ reasonable_recv_timeout(*_socket, timeout_ms);
if (not _socket->available()) return 0;
return _socket->receive(boost::asio::buffer(buff));
}
@@ -101,8 +102,8 @@ public:
~udp_broadcast_impl(void);
//send/recv
- size_t send(const boost::asio::const_buffer &buff);
- size_t recv(const boost::asio::mutable_buffer &buff);
+ size_t send(const boost::asio::const_buffer &);
+ size_t recv(const boost::asio::mutable_buffer &, size_t);
private:
boost::asio::ip::udp::socket *_socket;
@@ -136,8 +137,8 @@ size_t udp_broadcast_impl::send(const boost::asio::const_buffer &buff){
return _socket->send_to(boost::asio::buffer(buff), _receiver_endpoint);
}
-size_t udp_broadcast_impl::recv(const boost::asio::mutable_buffer &buff){
- reasonable_recv_timeout(*_socket);
+size_t udp_broadcast_impl::recv(const boost::asio::mutable_buffer &buff, size_t timeout_ms){
+ reasonable_recv_timeout(*_socket, timeout_ms);
if (not _socket->available()) return 0;
boost::asio::ip::udp::endpoint sender_endpoint;
return _socket->receive_from(boost::asio::buffer(buff), sender_endpoint);
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index bfbcf62d8..ee989ee2b 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -18,6 +18,7 @@
#include <uhd/transport/udp_zero_copy.hpp>
#include <uhd/transport/udp_simple.hpp> //mtu
#include <uhd/utils/assert.hpp>
+#include <uhd/utils/warning.hpp>
#include <boost/cstdint.hpp>
#include <boost/asio.hpp>
#include <boost/format.hpp>
@@ -29,7 +30,11 @@ using namespace uhd::transport;
* Constants
**********************************************************************/
//enough buffering for half a second of samples at full rate on usrp2
-static const size_t MIN_SOCK_BUFF_SIZE = size_t(sizeof(boost::uint32_t) * 25e6 * 0.5);
+static const size_t MIN_RECV_SOCK_BUFF_SIZE = size_t(sizeof(boost::uint32_t) * 25e6 * 0.5);
+//Large buffers cause more underflow at high rates.
+//Perhaps this is due to the kernel scheduling,
+//but may change with host-based flow control.
+static const size_t MIN_SEND_SOCK_BUFF_SIZE = size_t(10e3);
static const double RECV_TIMEOUT = 0.1; //100 ms
/***********************************************************************
@@ -143,6 +148,10 @@ template<typename Opt> static void resize_buff_helper(
size_t target_size,
const std::string &name
){
+ size_t min_sock_buff_size = 0;
+ if (name == "recv") min_sock_buff_size = MIN_RECV_SOCK_BUFF_SIZE;
+ if (name == "send") min_sock_buff_size = MIN_SEND_SOCK_BUFF_SIZE;
+
//resize the buffer if size was provided
if (target_size > 0){
size_t actual_size = udp_trans->resize_buff<Opt>(target_size);
@@ -153,19 +162,18 @@ template<typename Opt> static void resize_buff_helper(
else std::cout << boost::format(
"Current %s sock buff size: %d bytes"
) % name % actual_size << std::endl;
- if (actual_size < target_size) std::cerr << boost::format(
- "Warning:\n"
- " The %s buffer is smaller than the requested size.\n"
- " The minimum recommended buffer size is %d bytes.\n"
- " See the USRP2 application notes on buffer resizing.\n"
- ) % name % MIN_SOCK_BUFF_SIZE << std::endl;
+ if (actual_size < target_size) uhd::print_warning(str(boost::format(
+ "The %s buffer is smaller than the requested size.\n"
+ "The minimum recommended buffer size is %d bytes.\n"
+ "See the USRP2 application notes on buffer resizing.\n"
+ ) % name % min_sock_buff_size));
}
//only enable on platforms that are happy with the large buffer resize
#if defined(UHD_PLATFORM_LINUX) || defined(UHD_PLATFORM_WIN32)
//otherwise, ensure that the buffer is at least the minimum size
- else if (udp_trans->get_buff_size<Opt>() < MIN_SOCK_BUFF_SIZE){
- resize_buff_helper<Opt>(udp_trans, MIN_SOCK_BUFF_SIZE, name);
+ else if (udp_trans->get_buff_size<Opt>() < min_sock_buff_size){
+ resize_buff_helper<Opt>(udp_trans, min_sock_buff_size, name);
}
#endif /*defined(UHD_PLATFORM_LINUX) || defined(UHD_PLATFORM_WIN32)*/
}
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index bd76cbb8f..7e0588f03 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -35,14 +35,25 @@
namespace vrt_packet_handler{
+template <typename T> UHD_INLINE T get_context_code(
+ const boost::uint32_t *vrt_hdr,
+ const uhd::transport::vrt::if_packet_info_t &if_packet_info
+){
+ //extract the context word (we dont know the endianness so mirror the bytes)
+ boost::uint32_t word0 = vrt_hdr[if_packet_info.num_header_words32] |
+ uhd::byteswap(vrt_hdr[if_packet_info.num_header_words32]);
+ return T(word0 & 0xff);
+}
+
/***********************************************************************
* vrt packet handler for recv
**********************************************************************/
typedef std::vector<uhd::transport::managed_recv_buffer::sptr> managed_recv_buffs_t;
typedef boost::function<bool(managed_recv_buffs_t &)> get_recv_buffs_t;
- typedef boost::function<void(size_t /*which channel*/)> handle_overrun_t;
+ typedef boost::function<void(size_t /*which channel*/)> handle_overflow_t;
+ typedef boost::function<void(const boost::uint32_t *, uhd::transport::vrt::if_packet_info_t &)> vrt_unpacker_t;
- static inline void handle_overrun_nop(size_t){}
+ static inline void handle_overflow_nop(size_t){}
struct recv_state{
//width of the receiver in channels
@@ -69,13 +80,12 @@ namespace vrt_packet_handler{
* Unpack a received vrt header and set the copy buffer.
* - helper function for vrt_packet_handler::_recv1
******************************************************************/
- template<typename vrt_unpacker_type>
static UHD_INLINE void _recv1_helper(
recv_state &state,
uhd::rx_metadata_t &metadata,
double tick_rate,
- vrt_unpacker_type vrt_unpacker,
- const handle_overrun_t &handle_overrun,
+ const vrt_unpacker_t &vrt_unpacker,
+ const handle_overflow_t &handle_overflow,
size_t vrt_header_offset_words32
){
//vrt unpack each managed buffer
@@ -92,22 +102,19 @@ namespace vrt_packet_handler{
const boost::uint32_t *vrt_hdr = state.managed_buffs[i]->cast<const boost::uint32_t *>() + vrt_header_offset_words32;
if_packet_info.num_packet_words32 = num_packet_words32 - vrt_header_offset_words32;
vrt_unpacker(vrt_hdr, if_packet_info);
- const boost::uint32_t *vrt_data = vrt_hdr + if_packet_info.num_header_words32;
//handle the non-data packet case and parse its contents
if (if_packet_info.packet_type != uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA){
- //extract the context word (we dont know the endianness so mirror the bytes)
- boost::uint32_t word0 = vrt_data[0] | uhd::byteswap(vrt_data[0]);
- if (word0 & uhd::rx_metadata_t::ERROR_CODE_OVERRUN) handle_overrun(i);
- metadata.error_code = uhd::rx_metadata_t::error_code_t(word0 & 0xf);
+ metadata.error_code = get_context_code<uhd::rx_metadata_t::error_code_t>(vrt_hdr, if_packet_info);
+ if (metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW) handle_overflow(i);
//break to exit loop and store metadata below
state.size_of_copy_buffs = 0; break;
}
//setup the buffer to point to the data
- state.copy_buffs[i] = reinterpret_cast<const boost::uint8_t *>(vrt_data);
+ state.copy_buffs[i] = reinterpret_cast<const boost::uint8_t *>(vrt_hdr + if_packet_info.num_header_words32);
//store the minimum payload length into the copy buffer length
size_t num_payload_bytes = if_packet_info.num_payload_words32*sizeof(boost::uint32_t);
@@ -131,7 +138,6 @@ namespace vrt_packet_handler{
* Recv data, unpack a vrt header, and copy-convert the data.
* - helper function for vrt_packet_handler::recv
******************************************************************/
- template<typename vrt_unpacker_type>
static UHD_INLINE size_t _recv1(
recv_state &state,
const std::vector<void *> &buffs,
@@ -141,9 +147,9 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- vrt_unpacker_type vrt_unpacker,
+ const vrt_unpacker_t &vrt_unpacker,
const get_recv_buffs_t &get_recv_buffs,
- const handle_overrun_t &handle_overrun,
+ const handle_overflow_t &handle_overflow,
size_t vrt_header_offset_words32
){
metadata.error_code = uhd::rx_metadata_t::ERROR_CODE_NONE;
@@ -158,7 +164,7 @@ namespace vrt_packet_handler{
try{
_recv1_helper(
state, metadata, tick_rate,
- vrt_unpacker, handle_overrun,
+ vrt_unpacker, handle_overflow,
vrt_header_offset_words32
);
}catch(const std::exception &e){
@@ -206,7 +212,6 @@ namespace vrt_packet_handler{
/*******************************************************************
* Recv vrt packets and copy convert the samples into the buffer.
******************************************************************/
- template<typename vrt_unpacker_type>
static UHD_INLINE size_t recv(
recv_state &state,
const std::vector<void *> &buffs,
@@ -216,9 +221,9 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- vrt_unpacker_type vrt_unpacker,
+ const vrt_unpacker_t &vrt_unpacker,
const get_recv_buffs_t &get_recv_buffs,
- const handle_overrun_t &handle_overrun = &handle_overrun_nop,
+ const handle_overflow_t &handle_overflow = &handle_overflow_nop,
size_t vrt_header_offset_words32 = 0
){
switch(recv_mode){
@@ -235,7 +240,7 @@ namespace vrt_packet_handler{
tick_rate,
vrt_unpacker,
get_recv_buffs,
- handle_overrun,
+ handle_overflow,
vrt_header_offset_words32
);
}
@@ -255,7 +260,7 @@ namespace vrt_packet_handler{
tick_rate,
vrt_unpacker,
get_recv_buffs,
- handle_overrun,
+ handle_overflow,
vrt_header_offset_words32
);
if (num_samps == 0) break; //had a recv timeout or error, break loop
@@ -273,6 +278,7 @@ namespace vrt_packet_handler{
**********************************************************************/
typedef std::vector<uhd::transport::managed_send_buffer::sptr> managed_send_buffs_t;
typedef boost::function<bool(managed_send_buffs_t &)> get_send_buffs_t;
+ typedef boost::function<void(boost::uint32_t *, uhd::transport::vrt::if_packet_info_t &)> vrt_packer_t;
struct send_state{
//init the expected seq number
@@ -287,7 +293,6 @@ namespace vrt_packet_handler{
* Pack a vrt header, copy-convert the data, and send it.
* - helper function for vrt_packet_handler::send
******************************************************************/
- template<typename vrt_packer_type>
static UHD_INLINE void _send1(
send_state &state,
const std::vector<const void *> &buffs,
@@ -296,7 +301,7 @@ namespace vrt_packet_handler{
uhd::transport::vrt::if_packet_info_t &if_packet_info,
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
- vrt_packer_type vrt_packer,
+ const vrt_packer_t &vrt_packer,
const get_send_buffs_t &get_send_buffs,
size_t vrt_header_offset_words32
){
@@ -334,7 +339,6 @@ namespace vrt_packet_handler{
/*******************************************************************
* Send vrt packets and copy convert the samples into the buffer.
******************************************************************/
- template<typename vrt_packer_type>
static UHD_INLINE size_t send(
send_state &state,
const std::vector<const void *> &buffs,
@@ -344,7 +348,7 @@ namespace vrt_packet_handler{
const uhd::io_type_t &io_type,
const uhd::otw_type_t &otw_type,
double tick_rate,
- vrt_packer_type vrt_packer,
+ const vrt_packer_t &vrt_packer,
const get_send_buffs_t &get_send_buffs,
size_t max_samples_per_packet,
size_t vrt_header_offset_words32 = 0
diff --git a/host/lib/transport/zero_copy.cpp b/host/lib/transport/zero_copy.cpp
index 42f69d77b..8a1cde694 100644
--- a/host/lib/transport/zero_copy.cpp
+++ b/host/lib/transport/zero_copy.cpp
@@ -54,12 +54,14 @@ private:
//! phony zero-copy recv interface implementation
struct phony_zero_copy_recv_if::impl{
+ impl(size_t max_buff_size) : max_buff_size(max_buff_size){
+ /* NOP */
+ }
size_t max_buff_size;
};
phony_zero_copy_recv_if::phony_zero_copy_recv_if(size_t max_buff_size){
- _impl = UHD_PIMPL_MAKE(impl, ());
- _impl->max_buff_size = max_buff_size;
+ _impl = UHD_PIMPL_MAKE(impl, (max_buff_size));
}
phony_zero_copy_recv_if::~phony_zero_copy_recv_if(void){