From 28a4f96eb5978a7738d008d2fcd87a086548db2d Mon Sep 17 00:00:00 2001 From: gab-arrobo Date: Thu, 16 May 2024 18:15:14 -0700 Subject: [PATCH] Add argument to pass allow PCI to DPDK (#60) --- core/dpdk.cc | 18 ++++++++++++++++++ core/opts.cc | 22 ++++++++++++++++++++++ core/opts.h | 1 + 3 files changed, 41 insertions(+) diff --git a/core/dpdk.cc b/core/dpdk.cc index 50bdcfc21a..aa8c5fd92a 100644 --- a/core/dpdk.cc +++ b/core/dpdk.cc @@ -45,7 +45,9 @@ #include #include #include +#include #include +#include #include "memory.h" #include "opts.h" @@ -128,6 +130,22 @@ void init_eal(int dpdk_mb_per_socket, std::string nonworker_corelist) { if (FLAGS_iova != "") rte_args.Append({"--iova", FLAGS_iova}); + if (FLAGS_allow != "") { + LOG(INFO) << "FLAGS_allow value(s): " << FLAGS_allow; + std::istringstream iss(FLAGS_allow); + std::vector pciAddresses; + std::string temp; + + while (std::getline(iss, temp, ',')) { + pciAddresses.push_back(temp); + } + + for (const std::string &address : pciAddresses) { + LOG(INFO) << "PCI address is: " << address; + rte_args.Append({"--allow", address}); + } + } + if (dpdk_mb_per_socket <= 0) { rte_args.Append({"--no-huge"}); diff --git a/core/opts.cc b/core/opts.cc index 346d5e65ef..e117fc9f98 100644 --- a/core/opts.cc +++ b/core/opts.cc @@ -34,6 +34,7 @@ #include #include +#include #include "bessd.h" #include "worker.h" @@ -67,6 +68,27 @@ DEFINE_string(iova, "", "DPDK IOVA mode: pa or va. Set auto if not specified"); static bool _iova_dummy [[maybe_unused]] = google::RegisterFlagValidator(&FLAGS_iova, &ValidateIovaMode); +static bool ValidateAllow(const char *, const std::string &value) { + std::regex pciAddressRegex( + R"(^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$)"); + std::istringstream iss(value); + std::string temp; + while (std::getline(iss, temp, ',')) { + if (temp.empty()) { + continue; + } + if (!std::regex_match(temp, pciAddressRegex)) { + return false; + } + } + return true; +} +DEFINE_string( + allow, "", + "Allow PCI list (comma separated). Set as all available if not specified"); +static bool _allow_dummy [[maybe_unused]] = + google::RegisterFlagValidator(&FLAGS_allow, &ValidateAllow); + static bool ValidateCoreID(const char *, int32_t value) { if (!is_cpu_present(value)) { LOG(ERROR) << "Invalid core ID: " << value; diff --git a/core/opts.h b/core/opts.h index 2c0a38c943..02030c6096 100644 --- a/core/opts.h +++ b/core/opts.h @@ -53,5 +53,6 @@ DECLARE_bool(no_crashlog); DECLARE_int32(buffers); DECLARE_bool(dpdk); DECLARE_string(iova); +DECLARE_string(allow); #endif // BESS_OPTS_H_