Skip to content

Commit 32cdf93

Browse files
committed
bufix:自动选择最优的 gid index
1 parent 2694820 commit 32cdf93

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

mooncake-transfer-engine/src/transport/rdma_transport/rdma_context.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,23 +395,35 @@ static inline int ipv6_addr_v4mapped(const struct in6_addr *a) {
395395
int RdmaContext::getBestGidIndex(const std::string &device_name,
396396
struct ibv_context *context,
397397
ibv_port_attr &port_attr, uint8_t port) {
398-
int gid_index = 0, i;
398+
int best_gid_index = 0;
399+
int best_priority = -1;
399400
struct ibv_gid_entry gid_entry;
400401

401-
for (i = 0; i < port_attr.gid_tbl_len; i++) {
402+
for (int i = 0; i < port_attr.gid_tbl_len; i++) {
402403
if (ibv_query_gid_ex(context, port, i, &gid_entry, 0)) {
403404
PLOG(ERROR) << "Failed to query GID " << i << " on " << device_name
404405
<< "/" << port;
405406
continue; // if gid is invalid ibv_query_gid_ex() will return !0
406407
}
407-
if ((ipv6_addr_v4mapped((struct in6_addr *)gid_entry.gid.raw) &&
408-
gid_entry.gid_type == IBV_GID_TYPE_ROCE_V2) ||
409-
gid_entry.gid_type == IBV_GID_TYPE_IB) {
410-
gid_index = i;
411-
break;
408+
int priority = -1;
409+
bool is_ipv4_mapped = ipv6_addr_v4mapped((struct in6_addr *)gid_entry.gid.raw);
410+
411+
if (is_ipv4_mapped && gid_entry.gid_type == IBV_GID_TYPE_ROCE_V2) {
412+
priority = 3; // 最高优先级
413+
} else if (is_ipv4_mapped) {
414+
priority = 2;
415+
} else if (gid_entry.gid_type == IBV_GID_TYPE_IB) {
416+
priority = 1;
417+
} else if (gid_entry.gid_type == IBV_GID_TYPE_ROCE_V2) {
418+
priority = 0;
419+
}
420+
421+
if (priority > best_priority) {
422+
best_priority = priority;
423+
best_gid_index = i;
412424
}
413425
}
414-
return gid_index;
426+
return best_gid_index;
415427
}
416428

417429
int RdmaContext::openRdmaDevice(const std::string &device_name, uint8_t port,

0 commit comments

Comments
 (0)