From 3ded5b6aecabb2e1e415af5cdff7cc367dafe9d2 Mon Sep 17 00:00:00 2001 From: Manoj Takasi <133196374+ManojTakasi@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:28:36 +0530 Subject: [PATCH] Added enable()function to the wait_ip_interrupt(timeout) (#8628) * Added wait_ip_interrupt(timeout) functionality on edge side (#8611) Signed-off-by: Manoj Takasi Co-authored-by: Manoj Takasi (cherry picked from commit db95e70ea4139dd2dd4e5483414837aa7fbcc2e3) * Added enable()function to the wait_ip_interrupt(timeout) (#8627) Signed-off-by: Manoj Takasi Co-authored-by: Manoj Takasi (cherry picked from commit c5fe317ad8e43586620c0dd0a3c02df5202052d9) * Added override to ensure the functions correctly overrides a base class virtual function. Signed-off-by: Manoj Takasi (cherry picked from commit fb102eea6f63731840445a3eaa4fb1d45020b783) --------- Co-authored-by: Manoj Takasi --- src/runtime_src/core/common/api/xrt_ip.cpp | 7 +++-- .../core/edge/user/device_linux.cpp | 23 ++++++++++++++++ src/runtime_src/core/edge/user/device_linux.h | 27 ++++++++++--------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_ip.cpp b/src/runtime_src/core/common/api/xrt_ip.cpp index cc4367beb54..4911541001f 100644 --- a/src/runtime_src/core/common/api/xrt_ip.cpp +++ b/src/runtime_src/core/common/api/xrt_ip.cpp @@ -116,10 +116,13 @@ class ip::interrupt_impl } [[nodiscard]] std::cv_status - wait(const std::chrono::milliseconds& timeout) const + wait(const std::chrono::milliseconds& timeout) { // Waits for interrupt, or return on timeout - return device->wait_ip_interrupt(handle, static_cast(timeout.count())); + auto status = device->wait_ip_interrupt(handle, static_cast(timeout.count())); + if (status == std::cv_status::no_timeout) + enable(); //re-enable interrupts + return status; } }; diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 5c14c881b02..ce371ad81fb 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -17,6 +17,7 @@ #include "core/edge/user/aie/profile_object.h" #include #include +#include #include #include @@ -1293,4 +1294,26 @@ wait_ip_interrupt(xclInterruptNotifyHandle handle) throw error(errno, "wait_ip_interrupt failed POSIX read"); } +std::cv_status +device_linux:: +wait_ip_interrupt(xclInterruptNotifyHandle handle, int32_t timeout) +{ + struct pollfd pfd = {.fd=handle, .events=POLLIN}; + int32_t ret = 0; + + //Checking for only one fd; Only of one CU + //Timeout value in milli seconds + ret = ::poll(&pfd, 1, timeout); + if (ret < 0) + throw error(errno, "wait_timeout: failed POSIX poll"); + + if (ret == 0) //Timeout occured + return std::cv_status::timeout; + + if (pfd.revents & POLLIN) //Interrupt received + return std::cv_status::no_timeout; + + throw error(-EINVAL, boost::str(boost::format("wait_timeout: POSIX poll unexpected event: %d") % pfd.revents)); +} + } // xrt_core diff --git a/src/runtime_src/core/edge/user/device_linux.h b/src/runtime_src/core/edge/user/device_linux.h index 068065fa107..d6a220df252 100644 --- a/src/runtime_src/core/edge/user/device_linux.h +++ b/src/runtime_src/core/edge/user/device_linux.h @@ -26,8 +26,8 @@ class device_linux : public shim // query functions virtual void read_dma_stats(boost::property_tree::ptree& pt) const; - virtual void read(uint64_t addr, void* buf, uint64_t len) const; - virtual void write(uint64_t addr, const void* buf, uint64_t len) const; + virtual void read(uint64_t addr, void* buf, uint64_t len) const override; + virtual void write(uint64_t addr, const void* buf, uint64_t len) const override; virtual void reset(const query::reset_type) const; //////////////////////////////////////////////////////////////// @@ -70,26 +70,29 @@ class device_linux : public shim // Custom ip interrupt handling // Redefined from xrt_core::ishim //////////////////////////////////////////////////////////////// - virtual xclInterruptNotifyHandle - open_ip_interrupt_notify(unsigned int ip_index) + xclInterruptNotifyHandle + open_ip_interrupt_notify(unsigned int ip_index) override { return xclOpenIPInterruptNotify(get_device_handle(), ip_index, 0); } - virtual void - close_ip_interrupt_notify(xclInterruptNotifyHandle handle) + void + close_ip_interrupt_notify(xclInterruptNotifyHandle handle) override { xclCloseIPInterruptNotify(get_device_handle(), handle); } - virtual void - enable_ip_interrupt(xclInterruptNotifyHandle); + void + enable_ip_interrupt(xclInterruptNotifyHandle) override; - virtual void - disable_ip_interrupt(xclInterruptNotifyHandle); + void + disable_ip_interrupt(xclInterruptNotifyHandle) override; + + void + wait_ip_interrupt(xclInterruptNotifyHandle) override; - virtual void - wait_ip_interrupt(xclInterruptNotifyHandle); + std::cv_status + wait_ip_interrupt(xclInterruptNotifyHandle, int32_t timeout) override; virtual std::unique_ptr create_hw_context(const xrt::uuid& xclbin_uuid,