aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorCiro Nishiguchi <ciro.nishiguchi@ni.com>2019-12-03 19:18:46 -0600
committerBrent Stapleton <brent.stapleton@ettus.com>2019-12-20 16:32:22 -0800
commitd7e5a630edbec5a9b9b3a2794ee1133ffcc405f5 (patch)
tree5a70bf9d6a27b540dc0460bbfcfba6d8b3018d01 /host/lib
parent378dc931ab697ee13352008a025ec4732f6f46e1 (diff)
downloaduhd-d7e5a630edbec5a9b9b3a2794ee1133ffcc405f5.tar.gz
uhd-d7e5a630edbec5a9b9b3a2794ee1133ffcc405f5.tar.bz2
uhd-d7e5a630edbec5a9b9b3a2794ee1133ffcc405f5.zip
usrp: Add I/O service manager for DPDK
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/include/uhdlib/usrp/common/dpdk_io_service_mgr.hpp69
-rw-r--r--host/lib/usrp/common/CMakeLists.txt8
-rw-r--r--host/lib/usrp/common/io_service_mgr.cpp16
3 files changed, 93 insertions, 0 deletions
diff --git a/host/lib/include/uhdlib/usrp/common/dpdk_io_service_mgr.hpp b/host/lib/include/uhdlib/usrp/common/dpdk_io_service_mgr.hpp
new file mode 100644
index 000000000..018f78f38
--- /dev/null
+++ b/host/lib/include/uhdlib/usrp/common/dpdk_io_service_mgr.hpp
@@ -0,0 +1,69 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#ifndef INCLUDED_UHDLIB_TRANSPORT_DPDK_IO_SERVICE_MGR_HPP
+#define INCLUDED_UHDLIB_TRANSPORT_DPDK_IO_SERVICE_MGR_HPP
+
+#include <uhdlib/transport/dpdk/common.hpp>
+#include <uhdlib/transport/dpdk_io_service.hpp>
+#include <uhdlib/transport/udp_dpdk_link.hpp>
+#include <uhdlib/usrp/common/io_service_mgr.hpp>
+
+namespace uhd { namespace usrp {
+
+class dpdk_io_service_mgr_impl : public io_service_mgr
+{
+public:
+ dpdk_io_service_mgr_impl()
+ {
+ _dpdk_ctx = transport::dpdk::dpdk_ctx::get();
+ }
+
+ transport::io_service::sptr connect_links(transport::recv_link_if::sptr recv_link,
+ transport::send_link_if::sptr send_link,
+ const transport::link_type_t /*link_type*/,
+ const io_service_args_t& /*default_args*/,
+ const uhd::device_addr_t& /*stream_args*/,
+ const std::string& /*streamer_id*/)
+ {
+ auto io_srv = _get_io_service(recv_link, send_link);
+ io_srv->attach_recv_link(recv_link);
+ io_srv->attach_send_link(send_link);
+ return io_srv;
+ }
+
+ void disconnect_links(
+ transport::recv_link_if::sptr recv_link, transport::send_link_if::sptr send_link)
+ {
+ auto io_srv = _get_io_service(recv_link, send_link);
+ io_srv->detach_recv_link(recv_link);
+ io_srv->detach_send_link(send_link);
+ }
+
+private:
+ transport::io_service::sptr _get_io_service(
+ transport::recv_link_if::sptr recv_link, transport::send_link_if::sptr send_link)
+ {
+ using namespace transport::dpdk;
+
+ // For DPDK, the same object implements the send and recv link
+ // interfaces so we should always have both parameters.
+ UHD_ASSERT_THROW(recv_link && send_link);
+
+ auto link = std::dynamic_pointer_cast<transport::udp_dpdk_link>(recv_link);
+ port_id_t port_id = link->get_port()->get_port_id();
+
+ auto io_srv = _dpdk_ctx->get_io_service(port_id);
+ UHD_ASSERT_THROW(io_srv);
+ return io_srv;
+ }
+
+ transport::dpdk::dpdk_ctx::sptr _dpdk_ctx;
+};
+
+}} // namespace uhd::usrp
+
+#endif /* INCLUDED_UHDLIB_TRANSPORT_DPDK_IO_SERVICE_MGR_HPP */
diff --git a/host/lib/usrp/common/CMakeLists.txt b/host/lib/usrp/common/CMakeLists.txt
index e4048fdf7..7a6a4fe27 100644
--- a/host/lib/usrp/common/CMakeLists.txt
+++ b/host/lib/usrp/common/CMakeLists.txt
@@ -36,3 +36,11 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/io_service_mgr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_service_args.cpp
)
+
+if(ENABLE_DPDK)
+ set_property(
+ SOURCE
+ ${CMAKE_CURRENT_SOURCE_DIR}/io_service_mgr.cpp
+ PROPERTY COMPILE_DEFINITIONS HAVE_DPDK
+ )
+endif(ENABLE_DPDK)
diff --git a/host/lib/usrp/common/io_service_mgr.cpp b/host/lib/usrp/common/io_service_mgr.cpp
index 707618c11..19c06a826 100644
--- a/host/lib/usrp/common/io_service_mgr.cpp
+++ b/host/lib/usrp/common/io_service_mgr.cpp
@@ -10,7 +10,11 @@
#include <uhd/utils/log.hpp>
#include <uhdlib/transport/inline_io_service.hpp>
#include <uhdlib/transport/offload_io_service.hpp>
+#ifdef HAVE_DPDK
+# include <uhdlib/usrp/common/dpdk_io_service_mgr.hpp>
+#endif
#include <uhdlib/usrp/common/io_service_mgr.hpp>
+#include <uhdlib/usrp/constrained_device_args.hpp>
#include <map>
#include <vector>
@@ -450,6 +454,18 @@ private:
io_service_mgr::sptr io_service_mgr::make(const uhd::device_addr_t& args)
{
+ constrained_device_args_t::bool_arg use_dpdk("use_dpdk", false);
+ if (args.has_key(use_dpdk.key())) {
+ use_dpdk.parse(args[use_dpdk.key()]);
+ }
+
+ if (use_dpdk.get()) {
+#ifdef HAVE_DPDK
+ return std::make_shared<dpdk_io_service_mgr_impl>();
+#else
+ UHD_LOG_WARNING(LOG_ID, "Cannot instantiate DPDK I/O service. Proceeding with regular I/O service.");
+#endif
+ }
return std::make_shared<io_service_mgr_impl>(args);
}