From c8311e8dbf45bbb5cf9748dbb051db1597a4a837 Mon Sep 17 00:00:00 2001 From: Joel Smith <140545543+joelsmithTT@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:19:27 -0600 Subject: [PATCH] Add default value parameter to read_sysfs (#327) ### Issue https://github.com/tenstorrent/tt-umd/issues/326 ### Description For some reason, a kernel I booted on a RISC-V dev board didn't have the `numa_node` entry in sysfs -- this commit fixes the assumption that this file will always exist. ### List of the changes Adds function for reading from sysfs with a default return value if the read fails. ### Testing Manual ### API Changes There are no API changes in this PR. --- device/pcie/pci_device.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/device/pcie/pci_device.cpp b/device/pcie/pci_device.cpp index d0427b3f..bc2fd5f6 100644 --- a/device/pcie/pci_device.cpp +++ b/device/pcie/pci_device.cpp @@ -79,6 +79,15 @@ static T read_sysfs(const PciDeviceInfo &device_info, const std::string &attribu return value; } +template +T read_sysfs(const PciDeviceInfo &device_info, const std::string &attribute_name, const T &default_value) { + try { + return read_sysfs(device_info, attribute_name); + } catch (...) { + return default_value; + } +} + static PciDeviceInfo read_device_info(int fd) { tenstorrent_get_device_info info{}; info.in.output_size_bytes = sizeof(info.out); @@ -255,7 +264,7 @@ PCIDevice::PCIDevice(int pci_device_number, int logical_device_id) : logical_id(logical_device_id), pci_device_file_desc(open(device_path.c_str(), O_RDWR | O_CLOEXEC)), info(read_device_info(pci_device_file_desc)), - numa_node(read_sysfs(info, "numa_node")), + numa_node(read_sysfs(info, "numa_node", -1)), // default to -1 if not found revision(read_sysfs(info, "revision")), arch(detect_arch(info.device_id, revision)), architecture_implementation(tt::umd::architecture_implementation::create(arch)),