aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp
diff options
context:
space:
mode:
authorCiro Nishiguchi <ciro.nishiguchi@ni.com>2019-11-07 16:19:01 -0600
committerMartin Braun <martin.braun@ettus.com>2019-11-26 12:21:33 -0800
commit837b89e2ec6be2735cede0a8ecc55caeff302b7f (patch)
treea656c22bb85e9227b14723b511de31a327c65fbf /host/lib/usrp
parent16c2bea50d0dfe5d2439a73baac5b0dde9b5634f (diff)
downloaduhd-837b89e2ec6be2735cede0a8ecc55caeff302b7f.tar.gz
uhd-837b89e2ec6be2735cede0a8ecc55caeff302b7f.tar.bz2
uhd-837b89e2ec6be2735cede0a8ecc55caeff302b7f.zip
rfnoc: Rename thread affinity args
Rename thread affinity args such that they do not end with an integer. Arg names ending with an integer are interpreted as being targeted at a specific motherboard index in device_addr methods.
Diffstat (limited to 'host/lib/usrp')
-rw-r--r--host/lib/usrp/common/io_service_args.cpp89
-rw-r--r--host/lib/usrp/common/io_service_mgr.cpp12
2 files changed, 52 insertions, 49 deletions
diff --git a/host/lib/usrp/common/io_service_args.cpp b/host/lib/usrp/common/io_service_args.cpp
index 04b58b047..8a55b8ee0 100644
--- a/host/lib/usrp/common/io_service_args.cpp
+++ b/host/lib/usrp/common/io_service_args.cpp
@@ -7,19 +7,21 @@
#include <uhd/utils/log.hpp>
#include <uhdlib/usrp/common/io_service_args.hpp>
#include <uhdlib/usrp/constrained_device_args.hpp>
+#include <boost/format.hpp>
+#include <regex>
#include <string>
-static const std::string LOG_ID = "IO_SRV";
-static const size_t MAX_NUM_XPORT_ADAPTERS = 2;
+static const std::string LOG_ID = "IO_SRV";
static const char* recv_offload_str = "recv_offload";
static const char* send_offload_str = "send_offload";
static const char* recv_offload_wait_mode_str = "recv_offload_wait_mode";
static const char* send_offload_wait_mode_str = "send_offload_wait_mode";
-static const char* recv_offload_thread_cpu_str = "recv_offload_thread_cpu";
-static const char* send_offload_thread_cpu_str = "send_offload_thread_cpu";
static const char* num_poll_offload_threads_str = "num_poll_offload_threads";
-static const char* poll_offload_thread_cpu_str = "poll_offload_thread_cpu_str";
+
+static const std::regex recv_offload_thread_cpu_expr("^recv_offload_thread_(\\d+)_cpu");
+static const std::regex send_offload_thread_cpu_expr("^send_offload_thread_(\\d+)_cpu");
+static const std::regex poll_offload_thread_cpu_expr("^poll_offload_thread_(\\d+)_cpu");
namespace uhd { namespace usrp {
@@ -73,36 +75,22 @@ io_service_args_t read_io_service_args(
io_srv_args.num_poll_offload_threads = 1;
}
- auto create_key = [](const std::string& base, size_t index) {
- return base + "_" + std::to_string(index);
- };
-
- for (size_t i = 0; i < MAX_NUM_XPORT_ADAPTERS; i++) {
- std::string key = create_key(recv_offload_thread_cpu_str, i);
- if (args.has_key(key)) {
- io_srv_args.recv_offload_thread_cpu.push_back(args.cast<size_t>(key, 0));
- } else {
- io_srv_args.recv_offload_thread_cpu.push_back({});
- }
- }
-
- for (size_t i = 0; i < MAX_NUM_XPORT_ADAPTERS; i++) {
- std::string key = create_key(send_offload_thread_cpu_str, i);
- if (args.has_key(key)) {
- io_srv_args.send_offload_thread_cpu.push_back(args.cast<size_t>(key, 0));
- } else {
- io_srv_args.send_offload_thread_cpu.push_back({});
+ auto read_thread_args = [&args](const std::regex& expr, std::map<size_t, size_t>& dest) {
+ auto keys = args.keys();
+ for (const auto& key : keys) {
+ std::smatch match;
+ if (std::regex_match(key, match, expr)) {
+ UHD_ASSERT_THROW(match.size() == 2); // first match is the entire key
+ const size_t thread = std::stoul(match.str(1));
+ const size_t cpu = args.cast<size_t>(key, 0);
+ dest[thread] = cpu;
+ }
}
- }
+ };
- for (size_t i = 0; i < io_srv_args.num_poll_offload_threads; i++) {
- std::string key = create_key(poll_offload_thread_cpu_str, i);
- if (args.has_key(key)) {
- io_srv_args.poll_offload_thread_cpu.push_back(args.cast<size_t>(key, 0));
- } else {
- io_srv_args.poll_offload_thread_cpu.push_back({});
- }
- }
+ read_thread_args(recv_offload_thread_cpu_expr, io_srv_args.recv_offload_thread_cpu);
+ read_thread_args(send_offload_thread_cpu_expr, io_srv_args.send_offload_thread_cpu);
+ read_thread_args(poll_offload_thread_cpu_expr, io_srv_args.poll_offload_thread_cpu);
return io_srv_args;
}
@@ -112,22 +100,37 @@ device_addr_t merge_io_service_dev_args(
{
device_addr_t args = stream_args;
- auto merge_args = [&dev_args, stream_args, &args](const char* key) {
+ auto merge_args = [](const device_addr_t& dev_args,
+ device_addr_t& stream_args,
+ const std::string& key) {
if (!stream_args.has_key(key)) {
if (dev_args.has_key(key)) {
- args[key] = dev_args[key];
+ stream_args[key] = dev_args[key];
+ }
+ }
+ };
+
+ merge_args(dev_args, args, recv_offload_str);
+ merge_args(dev_args, args, send_offload_str);
+ merge_args(dev_args, args, recv_offload_wait_mode_str);
+ merge_args(dev_args, args, send_offload_wait_mode_str);
+ merge_args(dev_args, args, num_poll_offload_threads_str);
+
+ auto merge_thread_args = [&merge_args](const device_addr_t& dev_args,
+ device_addr_t& stream_args,
+ const std::regex& expr) {
+ auto keys = dev_args.keys();
+ for (const auto& key : keys) {
+ std::smatch match;
+ if (std::regex_match(key, match, expr)) {
+ merge_args(dev_args, stream_args, key);
}
}
};
- merge_args(recv_offload_str);
- merge_args(send_offload_str);
- merge_args(recv_offload_wait_mode_str);
- merge_args(send_offload_wait_mode_str);
- merge_args(recv_offload_thread_cpu_str);
- merge_args(send_offload_thread_cpu_str);
- merge_args(num_poll_offload_threads_str);
- merge_args(poll_offload_thread_cpu_str);
+ merge_thread_args(dev_args, args, recv_offload_thread_cpu_expr);
+ merge_thread_args(dev_args, args, send_offload_thread_cpu_expr);
+ merge_thread_args(dev_args, args, poll_offload_thread_cpu_expr);
return args;
}
diff --git a/host/lib/usrp/common/io_service_mgr.cpp b/host/lib/usrp/common/io_service_mgr.cpp
index 437d77423..707618c11 100644
--- a/host/lib/usrp/common/io_service_mgr.cpp
+++ b/host/lib/usrp/common/io_service_mgr.cpp
@@ -247,13 +247,13 @@ io_service::sptr blocking_io_service_mgr::_create_new_io_service(
? offload_io_service::RECV_ONLY
: offload_io_service::SEND_ONLY;
- const auto& cpu_vtr = (link_type == link_type_t::RX_DATA)
+ const auto& cpu_map = (link_type == link_type_t::RX_DATA)
? args.recv_offload_thread_cpu
: args.send_offload_thread_cpu;
std::string cpu_affinity_str;
- if (cpu_vtr.size() > thread_index && cpu_vtr[thread_index]) {
- const size_t cpu = *cpu_vtr[thread_index];
+ if (cpu_map.count(thread_index) != 0) {
+ const size_t cpu = cpu_map.at(thread_index);
params.cpu_affinity_list = {cpu};
cpu_affinity_str = ", cpu affinity: " + std::to_string(cpu);
} else {
@@ -381,11 +381,11 @@ io_service::sptr polling_io_service_mgr::_create_new_io_service(
params.client_type = offload_io_service::BOTH_SEND_AND_RECV;
params.wait_mode = offload_io_service::POLL;
- const auto& cpu_vtr = args.poll_offload_thread_cpu;
+ const auto& cpu_map = args.poll_offload_thread_cpu;
std::string cpu_affinity_str;
- if (cpu_vtr.size() > thread_index && cpu_vtr[thread_index]) {
- const size_t cpu = *cpu_vtr[thread_index];
+ if (cpu_map.count(thread_index) != 0) {
+ const size_t cpu = cpu_map.at(thread_index);
params.cpu_affinity_list = {cpu};
cpu_affinity_str = ", cpu affinity: " + std::to_string(cpu);
} else {