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

Print hugepage 0 size warning only if mapping fails #278

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
### List of the changes
(Itemized list of all the changes.)

### Testing
(Comment on CI testing or Manual testing touching this change.)

### API Changes
(When making API changes, don't merge this PR until tt_metal and tt_debuda PRs are approved.)
(Then merge this PR, change the client PRs to point to UMD main, and then merge them.)
Expand Down
14 changes: 2 additions & 12 deletions device/hugepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "hugepage.h"

#include <sys/stat.h> // for umask, fstat
#include <sys/stat.h> // for umask
#include <fcntl.h> // for O_RDWR and other constants

#include "common/logger.hpp"
Expand Down Expand Up @@ -155,16 +155,6 @@ int open_hugepage_file(const std::string &dir, chip_id_t physical_device_id, uin
fd = open(filename.data(), O_RDWR | O_CREAT | O_CLOEXEC, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH );
}

// Verify opened file size.
struct stat st;
if (fstat(fd, &st) == -1) {
log_warning(LogSiliconDriver, "Error reading file size after opening: {}", filename_str);
} else {
if (st.st_size == 0) {
log_warning(LogSiliconDriver, "Opened hugepage file has zero size, mapping it might fail: {}. Verify that enough hugepages are provided.", filename_str);
}
}

// Restore original mask
umask(old_umask);

Expand All @@ -176,4 +166,4 @@ int open_hugepage_file(const std::string &dir, chip_id_t physical_device_id, uin
return fd;
}

} // namespace tt::umd
} // namespace tt::umd
10 changes: 10 additions & 0 deletions device/pcie/pci_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unistd.h> // for ::close
#include <sys/ioctl.h> // for ioctl
#include <sys/mman.h> // for mmap, munmap
#include <sys/stat.h> // for fstat
#include <linux/pci.h> // for PCI_SLOT, PCI_FUNC

#include "pci_device.hpp"
Expand Down Expand Up @@ -623,12 +624,21 @@ bool PCIDevice::init_hugepage(uint32_t num_host_mem_channels) {
continue;
}

// Verify opened file size.
struct stat hugepage_st;
if (fstat(hugepage_fd, &hugepage_st) == -1) {
log_warning(LogSiliconDriver, "Error reading hugepage file size after opening.");
}

std::byte *mapping = static_cast<std::byte*>(mmap(nullptr, hugepage_size, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_POPULATE, hugepage_fd, 0));

close(hugepage_fd);

if (mapping == MAP_FAILED) {
log_warning(LogSiliconDriver, "UMD: Mapping a hugepage failed. (device: {}, {}/{} errno: {}).", physical_device_id, ch, num_host_mem_channels, strerror(errno));
if (hugepage_st.st_size == 0) {
log_warning(LogSiliconDriver, "Opened hugepage file has zero size, mapping might've failed due to that. Verify that enough hugepages are provided.");
}
print_file_contents("/proc/cmdline");\
print_file_contents("/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages"); // Hardcoded for 1GB hugepage.
success = false;
Expand Down
Loading