Skip to content

Commit

Permalink
Require PCI addr to configure available interface
Browse files Browse the repository at this point in the history
Fixed EAL argc/argv construction too. This makes it possible to hide and
show only PCIe devices that we want for the module/process. To be tested
  • Loading branch information
roland-sipos committed Dec 18, 2023
1 parent 741b14e commit ae7eb67
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 15 deletions.
15 changes: 7 additions & 8 deletions include/dpdklibs/EALSetup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,16 @@ get_mempool(const std::string& pool_name,
return std::unique_ptr<rte_mempool>(mbuf_pool);
}

std::vector<char*>
string_to_eal_args(const std::string& params)
{
auto parts = boost::program_options::split_unix(params);
std::vector<char*> cstrings;
for(auto& str : parts){
cstrings.push_back(const_cast<char*> (str.c_str()));
std::vector<char*>
construct_eal_argv(std::vector<std::string> &std_argv){
std::vector<char*> vec_argv;
for (int i=0; i < std_argv.size() ; i++){
vec_argv.insert(vec_argv.end(), std_argv[i].data());
}
return cstrings;
return vec_argv;
}


void
init_eal(int argc, char* argv[]) {

Expand Down
21 changes: 21 additions & 0 deletions include/dpdklibs/RTEIfaceSetup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ get_iface_mac_str(uint16_t iface)
}
}

inline std::string
get_iface_pci_str(uint16_t iface)
{
std::string iface_pci_addr_str;
int retval = -1;
struct rte_eth_dev_info dev_info;
// Get interface info
retval = rte_eth_dev_info_get(iface, &dev_info);
if (retval != 0) {
TLOG() << "Error during getting device (iface " << iface << ") retval: " << retval;
} else if (dev_info.device) {
auto dev_name = rte_dev_name(dev_info.device);
iface_pci_addr_str = dev_name;
//TLOG() << "Dev name: " << dev_name;
//const auto bus = rte_dev_bus(dev_info.device);
//const auto bus_info = rte_dev_bus_info(dev_info.device);
//const auto dev_driver = rte_dev_driver(dev_info.device);
}
return iface_pci_addr_str;
}

inline int
iface_reset(uint16_t iface)
{
Expand Down
28 changes: 22 additions & 6 deletions plugins/NICReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,49 @@ NICReceiver::do_configure(const data_t& args)

// EAL setup
TLOG() << "Setting up EAL with params from config.";
std::vector<char*> eal_params = ealutils::string_to_eal_args(m_cfg.eal_arg_list);
ealutils::init_eal(eal_params.size(), eal_params.data());
std::vector<std::string> eal_args;
eal_args.push_back("daq_application");
std::istringstream iss(m_cfg.eal_arg_list);
std::string arg_from_str;
while (iss >> arg_from_str) {
if (!arg_from_str.empty()) {
eal_args.push_back(arg_from_str);
}
}
std::vector<char*> eal_argv = ealutils::construct_eal_argv(eal_args);
char** constructed_eal_argv = eal_argv.data();
int constructed_eal_argc = eal_args.size();
ealutils::init_eal(constructed_eal_argc, constructed_eal_argv);

// Get available Interfaces from EAL
auto available_ifaces = ifaceutils::get_num_available_ifaces();
TLOG() << "Number of available interfaces: " << available_ifaces;
for (unsigned int ifc_id=0; ifc_id<available_ifaces; ++ifc_id) {
std::string mac_addr_str = ifaceutils::get_iface_mac_str(ifc_id);
std::string pci_addr_str = ifaceutils::get_iface_pci_str(ifc_id);
m_mac_to_id_map[mac_addr_str] = ifc_id;
TLOG() << "Available iface with MAC=" << mac_addr_str << " logical ID=" << ifc_id;
m_pci_to_id_map[pci_addr_str] = ifc_id;
TLOG() << "Available iface with MAC=" << mac_addr_str << " PCIe=" << pci_addr_str << " logical ID=" << ifc_id;
}

// Configure expected (and available!) interfaces
auto ifaces_cfg = m_cfg.ifaces;
for (const auto& iface_cfg : ifaces_cfg) {
auto iface_mac_addr = iface_cfg.mac_addr;
if (m_mac_to_id_map.count(iface_mac_addr) != 0) {
auto iface_pci_addr = iface_cfg.pci_addr;
if ((m_mac_to_id_map.count(iface_mac_addr) != 0) &&
(m_pci_to_id_map.count(iface_pci_addr) != 0)) {
auto iface_id = m_mac_to_id_map[iface_mac_addr];
TLOG() << "Configuring expected interface with MAC=" << iface_mac_addr << " Logical ID=" << iface_id;
TLOG() << "Configuring expected interface with MAC=" << iface_mac_addr
<< "PCIe=" << iface_pci_addr << " Logical ID=" << iface_id;
m_ifaces[iface_id] = std::make_unique<IfaceWrapper>(iface_id, m_sources, m_run_marker);
m_ifaces[iface_id]->conf(iface_cfg);
m_ifaces[iface_id]->allocate_mbufs();
m_ifaces[iface_id]->setup_interface();
m_ifaces[iface_id]->setup_flow_steering();
m_ifaces[iface_id]->setup_xstats();
} else {
TLOG() << "No available interface with MAC=" << iface_mac_addr;
TLOG() << "No available interface with MAC=" << iface_mac_addr << " PCI=" << iface_pci_addr;
ers::fatal(dunedaq::readoutlibs::InitializationError(
ERS_HERE, "NICReceiver configuration failed due expected but unavailable interface!"));
}
Expand Down
1 change: 1 addition & 0 deletions plugins/NICReceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class NICReceiver : public dunedaq::appfwk::DAQModule

// Interfaces (logical ID, MAC) -> IfaceWrapper
std::map<std::string, uint16_t> m_mac_to_id_map;
std::map<std::string, uint16_t> m_pci_to_id_map;
std::map<uint16_t, std::unique_ptr<IfaceWrapper>> m_ifaces;

// Sinks (SourceConcepts)
Expand Down
5 changes: 4 additions & 1 deletion schema/dpdklibs/nicreader.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ local nicreader = {

ipv4: s.string("ipv4", pattern=moo.re.ipv4, doc="ipv4 string"),

pci: s.string("pci", doc="PCIe address string"),

mac: s.string("mac", pattern="^[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}$", doc="mac string"),

float : s.number("Float", "f4", doc="A float number"),
Expand Down Expand Up @@ -67,7 +69,8 @@ local nicreader = {
], doc="Source field"),

iface : s.record("Interface", [
s.field("mac_addr", self.mac, "AA:BB:CC:DD:EE:FF", doc="Logical Interface ID"),
s.field("pci_addr", self.pci, "0000:00:00.0", doc="PCIe address of the interface"),
s.field("mac_addr", self.mac, "AA:BB:CC:DD:EE:FF", doc="MAC address of the interface"),
s.field("ip_addr", self.ipv4, "192.168.0.1", doc="IP address of interface"),
s.field("with_flow_control", self.choice, true, doc="FlowAPI enabled"),
s.field("promiscuous_mode", self.choice, false, doc="Promiscuous mode enabled"),
Expand Down
4 changes: 4 additions & 0 deletions test/apps/test_dpdk_stats.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Application will run until quit or killed. */

#include "dpdklibs/EALSetup.hpp"
#include "dpdklibs/RTEIfaceSetup.hpp"
#include "logging/Logging.hpp"
#include "dpdklibs/udp/PacketCtor.hpp"
#include "dpdklibs/udp/Utils.hpp"
Expand Down Expand Up @@ -198,6 +199,9 @@ main(int argc, char* argv[])
auto nb_ifaces = rte_eth_dev_count_avail();
TLOG() << "# of available interfaces: " << nb_ifaces;
TLOG() << "Initialize interface " << iface_id;
TLOG() << " -> Iface MAC: " << ifaceutils::get_iface_mac_str(iface_id);
TLOG() << " -> Iface PCI: " << ifaceutils::get_iface_pci_str(iface_id);

ealutils::iface_init(iface_id, rx_qs, tx_qs, rx_ring_size, tx_ring_size, mbuf_pools, false, false);
ealutils::iface_promiscuous_mode(iface_id, false); // should come from config

Expand Down

0 comments on commit ae7eb67

Please sign in to comment.