Skip to content

Commit

Permalink
Add argument to pass allow PCI to DPDK (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo authored May 17, 2024
1 parent 646be53 commit 28a4f96
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/dpdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>

#include "memory.h"
#include "opts.h"
Expand Down Expand Up @@ -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<std::string> 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"});

Expand Down
22 changes: 22 additions & 0 deletions core/opts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <glog/logging.h>

#include <cstdint>
#include <regex>

#include "bessd.h"
#include "worker.h"
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions core/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ DECLARE_bool(no_crashlog);
DECLARE_int32(buffers);
DECLARE_bool(dpdk);
DECLARE_string(iova);
DECLARE_string(allow);

#endif // BESS_OPTS_H_

0 comments on commit 28a4f96

Please sign in to comment.