Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TransferEngine] fix: use ibv_get_device_list to get the IB devices. #102

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all 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
19 changes: 8 additions & 11 deletions mooncake-transfer-engine/src/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <ctype.h>
#include <dirent.h>
#include <infiniband/verbs.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -44,28 +45,25 @@ struct InfinibandDevice {
};

static std::vector<InfinibandDevice> listInfiniBandDevices() {
DIR *dir = opendir("/sys/class/infiniband");
struct dirent *entry;
int num_devices = 0;
std::vector<InfinibandDevice> devices;

if (dir == NULL) {
PLOG(WARNING) << "Failed to open /sys/class/infiniband";
struct ibv_device **device_list = ibv_get_device_list(&num_devices);
if (!device_list || num_devices <= 0) {
LOG(WARNING) << "No IB devices found";
return {};
}
while ((entry = readdir(dir))) {
if (entry->d_name[0] == '.') {
continue;
}

std::string device_name = entry->d_name;
for (int i = 0; i < num_devices; ++i) {
std::string device_name = ibv_get_device_name(device_list[i]);

char path[PATH_MAX + 32];
char resolved_path[PATH_MAX];
// Get the PCI bus id for the infiniband device. Note that
// "/sys/class/infiniband/mlx5_X/" is a symlink to
// "/sys/devices/pciXXXX:XX/XXXX:XX:XX.X/infiniband/mlx5_X/".
snprintf(path, sizeof(path), "/sys/class/infiniband/%s/../..",
entry->d_name);
device_name.c_str());
if (realpath(path, resolved_path) == NULL) {
PLOG(ERROR) << "Failed to parse realpath";
continue;
Expand All @@ -80,7 +78,6 @@ static std::vector<InfinibandDevice> listInfiniBandDevices() {
.pci_bus_id = std::move(pci_bus_id),
.numa_node = numa_node});
}
(void)closedir(dir);
return devices;
}

Expand Down