Skip to content

Commit 28a4f96

Browse files
authored
Add argument to pass allow PCI to DPDK (#60)
1 parent 646be53 commit 28a4f96

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

core/dpdk.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include <cstdio>
4646
#include <cstdlib>
4747
#include <cstring>
48+
#include <sstream>
4849
#include <string>
50+
#include <vector>
4951

5052
#include "memory.h"
5153
#include "opts.h"
@@ -128,6 +130,22 @@ void init_eal(int dpdk_mb_per_socket, std::string nonworker_corelist) {
128130
if (FLAGS_iova != "")
129131
rte_args.Append({"--iova", FLAGS_iova});
130132

133+
if (FLAGS_allow != "") {
134+
LOG(INFO) << "FLAGS_allow value(s): " << FLAGS_allow;
135+
std::istringstream iss(FLAGS_allow);
136+
std::vector<std::string> pciAddresses;
137+
std::string temp;
138+
139+
while (std::getline(iss, temp, ',')) {
140+
pciAddresses.push_back(temp);
141+
}
142+
143+
for (const std::string &address : pciAddresses) {
144+
LOG(INFO) << "PCI address is: " << address;
145+
rte_args.Append({"--allow", address});
146+
}
147+
}
148+
131149
if (dpdk_mb_per_socket <= 0) {
132150
rte_args.Append({"--no-huge"});
133151

core/opts.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <glog/logging.h>
3535

3636
#include <cstdint>
37+
#include <regex>
3738

3839
#include "bessd.h"
3940
#include "worker.h"
@@ -67,6 +68,27 @@ DEFINE_string(iova, "", "DPDK IOVA mode: pa or va. Set auto if not specified");
6768
static bool _iova_dummy [[maybe_unused]] =
6869
google::RegisterFlagValidator(&FLAGS_iova, &ValidateIovaMode);
6970

71+
static bool ValidateAllow(const char *, const std::string &value) {
72+
std::regex pciAddressRegex(
73+
R"(^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$)");
74+
std::istringstream iss(value);
75+
std::string temp;
76+
while (std::getline(iss, temp, ',')) {
77+
if (temp.empty()) {
78+
continue;
79+
}
80+
if (!std::regex_match(temp, pciAddressRegex)) {
81+
return false;
82+
}
83+
}
84+
return true;
85+
}
86+
DEFINE_string(
87+
allow, "",
88+
"Allow PCI list (comma separated). Set as all available if not specified");
89+
static bool _allow_dummy [[maybe_unused]] =
90+
google::RegisterFlagValidator(&FLAGS_allow, &ValidateAllow);
91+
7092
static bool ValidateCoreID(const char *, int32_t value) {
7193
if (!is_cpu_present(value)) {
7294
LOG(ERROR) << "Invalid core ID: " << value;

core/opts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ DECLARE_bool(no_crashlog);
5353
DECLARE_int32(buffers);
5454
DECLARE_bool(dpdk);
5555
DECLARE_string(iova);
56+
DECLARE_string(allow);
5657

5758
#endif // BESS_OPTS_H_

0 commit comments

Comments
 (0)