From 0bd233e64210c6605e8a6ec1424fa81f9ea8a681 Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Thu, 17 Oct 2019 08:44:11 -0500 Subject: uhd: Introduce I/O service manager - Implement I/O service detach link methods - The I/O service manager instantiates new I/O services or connects links to existing I/O services based on options provided by the user in stream_args. - Add a streamer ID parameter to methods to create transports so that the I/O service manager can group transports appropriately when using offload threads. - Change X300 and MPMD to use I/O service manager to connect links to I/O services. - There is now a single I/O service manager per rfnoc_graph (and it is also stored in the graph) - The I/O service manager now also knows the device args for the rfnoc_graph it was created with, and can make decisions based upon those (e.g, use a specific I/O service for DPDK, share cores between streamers, etc.) - The I/O Service Manager does not get any decision logic with this commit, though - The MB ifaces for mpmd and x300 now access this global I/O service manager - Add configuration of link parameters with overrides Co-Authored-By: Martin Braun Co-Authored-By: Aaron Rossetto --- .../include/uhdlib/transport/inline_io_service.hpp | 6 +- host/lib/include/uhdlib/transport/io_service.hpp | 13 +++- host/lib/include/uhdlib/transport/links.hpp | 3 +- .../uhdlib/transport/offload_io_service.hpp | 14 +--- host/lib/include/uhdlib/transport/udp_common.hpp | 75 ++++++++++++++++++++++ 5 files changed, 94 insertions(+), 17 deletions(-) (limited to 'host/lib/include/uhdlib/transport') diff --git a/host/lib/include/uhdlib/transport/inline_io_service.hpp b/host/lib/include/uhdlib/transport/inline_io_service.hpp index f207d15a0..fe41b96b6 100644 --- a/host/lib/include/uhdlib/transport/inline_io_service.hpp +++ b/host/lib/include/uhdlib/transport/inline_io_service.hpp @@ -37,6 +37,9 @@ public: void attach_recv_link(recv_link_if::sptr link); void attach_send_link(send_link_if::sptr link); + void detach_recv_link(recv_link_if::sptr link); + void detach_send_link(send_link_if::sptr link); + recv_io_if::sptr make_recv_client(recv_link_if::sptr data_link, size_t num_recv_frames, recv_callback_t cb, @@ -102,8 +105,7 @@ private: inline_recv_cb* recv_io_cb, recv_link_if* recv_link, int32_t timeout_ms); /* Track whether link is muxed and the callback */ - std::unordered_map> + std::unordered_map> _recv_tbl; /* Shared ptr kept to avoid untimely release */ diff --git a/host/lib/include/uhdlib/transport/io_service.hpp b/host/lib/include/uhdlib/transport/io_service.hpp index 69a3a523e..399b693dc 100644 --- a/host/lib/include/uhdlib/transport/io_service.hpp +++ b/host/lib/include/uhdlib/transport/io_service.hpp @@ -282,10 +282,19 @@ public: */ virtual void attach_send_link(send_link_if::sptr link) = 0; - /* TODO: Cleanup functions + /*! + * Detach a recv_link_if previously attached to this I/O service. + * + * \param link the recv_link_if to detach + */ virtual void detach_recv_link(recv_link_if::sptr link) = 0; + + /*! + * Detach a send_link_if previously attached to this I/O service. + * + * \param link the send_link_if to detach + */ virtual void detach_send_link(send_link_if::sptr link) = 0; - */ /*! * Create a send_io_if so a transport may send packets through the link. diff --git a/host/lib/include/uhdlib/transport/links.hpp b/host/lib/include/uhdlib/transport/links.hpp index 64673f02f..09872b145 100644 --- a/host/lib/include/uhdlib/transport/links.hpp +++ b/host/lib/include/uhdlib/transport/links.hpp @@ -16,8 +16,7 @@ namespace uhd { namespace transport { enum class link_type_t { CTRL = 0, ASYNC_MSG, TX_DATA, RX_DATA }; //! Contains all information regarding a link interface -using both_links_t = std::tuple +#include namespace uhd { namespace transport { @@ -21,18 +22,9 @@ namespace uhd { namespace transport { class offload_io_service : public io_service { public: - enum client_type_t - { - RECV_ONLY, - SEND_ONLY, - BOTH_SEND_AND_RECV - }; + enum client_type_t { RECV_ONLY, SEND_ONLY, BOTH_SEND_AND_RECV }; - enum wait_mode_t - { - POLL, - BLOCK - }; + enum wait_mode_t { POLL, BLOCK }; /*! * Options for configuring offload I/O service diff --git a/host/lib/include/uhdlib/transport/udp_common.hpp b/host/lib/include/uhdlib/transport/udp_common.hpp index 5f5a18c27..6c87ef498 100644 --- a/host/lib/include/uhdlib/transport/udp_common.hpp +++ b/host/lib/include/uhdlib/transport/udp_common.hpp @@ -10,7 +10,10 @@ #include #include +#include +#include #include +#include #include #include #include @@ -194,6 +197,78 @@ UHD_INLINE size_t resize_udp_socket_buffer_with_warning( return actual_size; } +/*! + * Determines a set of values to use for a UDP CHDR link based on defaults and + * any overrides that the user may have provided. In cases where both device + * and stream arguments can be used to override a value, note that the stream + * argument will always take precedence. + * + * \param link_type the link type (CTRL, RX, TX) to calculate parameters for + * \param send_mtu the MTU of link for Tx cases + * \param recv_mtu the MTU of link for Rx cases + * \param default_link_params default values to use for the link parameters + * \param device_args device-level argument dictionary for overrides + * \param link_args argument dictionary with stream-level overrides (come from + * stream params) + * \return Parameters to apply + */ +inline link_params_t calculate_udp_link_params( + const uhd::transport::link_type_t link_type, + const size_t send_mtu, + const size_t recv_mtu, + const link_params_t& default_link_params, + const uhd::device_addr_t& device_args, + const uhd::device_addr_t& link_args) +{ + // Apply any device-level overrides to the default values first. + // If the MTU is overridden, it will be capped to the value provided by + // the caller. + const size_t constrained_send_mtu = + std::min(send_mtu, device_args.cast("mtu", send_mtu)); + const size_t constrained_recv_mtu = + std::min(recv_mtu, device_args.cast("mtu", recv_mtu)); + + link_params_t link_params; + link_params.num_send_frames = + device_args.cast("num_send_frames", default_link_params.num_send_frames); + link_params.num_recv_frames = + device_args.cast("num_recv_frames", default_link_params.num_recv_frames); + link_params.send_frame_size = + device_args.cast("send_frame_size", default_link_params.send_frame_size); + link_params.recv_frame_size = + device_args.cast("recv_frame_size", default_link_params.recv_frame_size); + link_params.send_buff_size = + device_args.cast("send_buff_size", default_link_params.send_buff_size); + link_params.recv_buff_size = + device_args.cast("recv_buff_size", default_link_params.recv_buff_size); + + // Now apply stream-level overrides based on the link type. + if (link_type == link_type_t::CTRL) { + // Control links typically do not allow the number of frames to be + // configured. + link_params.num_recv_frames = + uhd::rfnoc::CMD_FIFO_SIZE / uhd::rfnoc::MAX_CMD_PKT_SIZE; + } else if (link_type == link_type_t::TX_DATA) { + // Note that the send frame size will be capped to the Tx MTU. + link_params.send_frame_size = link_args.cast("send_frame_size", + std::min(link_params.send_frame_size, constrained_send_mtu)); + link_params.num_send_frames = + link_args.cast("num_send_frames", link_params.num_send_frames); + link_params.send_buff_size = + link_args.cast("send_buff_size", link_params.send_buff_size); + } else if (link_type == link_type_t::RX_DATA) { + // Note that the receive frame size will be capped to the Rx MTU. + link_params.recv_frame_size = link_args.cast("recv_frame_size", + std::min(link_params.recv_frame_size, constrained_recv_mtu)); + link_params.num_recv_frames = + link_args.cast("num_recv_frames", link_params.num_recv_frames); + link_params.recv_buff_size = + link_args.cast("recv_buff_size", link_params.recv_buff_size); + } + + return link_params; +} + }} // namespace uhd::transport -- cgit v1.2.3