Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,50 @@ static inline int ipv6_addr_v4mapped(const struct in6_addr *a) {
((a->s6_addr32[1] | (a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0UL));
}


static std::string readGidNdev(const std::string &device_name, uint8_t port, int gid_index) {
std::string sysfs_path = "/sys/class/infiniband/" + device_name +
"/ports/" + std::to_string(port) +
"/gid_attrs/ndevs/" + std::to_string(gid_index);
std::ifstream file(sysfs_path);
if (!file.is_open()) {
return "";
}

std::string ndev;
std::getline(file, ndev);
return ndev;
}

int RdmaContext::getBestGidIndex(const std::string &device_name,
struct ibv_context *context,
ibv_port_attr &port_attr, uint8_t port) {
int gid_index = 0, i;
struct ibv_gid_entry gid_entry;
bool fallback_found = false;

for (i = 0; i < port_attr.gid_tbl_len; i++) {
if (ibv_query_gid_ex(context, port, i, &gid_entry, 0)) {
PLOG(ERROR) << "Failed to query GID " << i << " on " << device_name
<< "/" << port;
continue; // if gid is invalid ibv_query_gid_ex() will return !0
}

if ((ipv6_addr_v4mapped((struct in6_addr *)gid_entry.gid.raw) &&
gid_entry.gid_type == IBV_GID_TYPE_ROCE_V2) ||
gid_entry.gid_type == IBV_GID_TYPE_IB) {
gid_index = i;
break;
// Check if this GID has an associated network device
std::string ndev = readGidNdev(device_name, port, i);
if (!ndev.empty()) {
// Found a GID with network device, this is the best choice
gid_index = i;
break;
}
// No network device, keep the first one as fallback candidate
if (!fallback_found) {
gid_index = i;
fallback_found = true;
}
}
}
return gid_index;
Expand Down
Loading