Skip to content

Commit

Permalink
Added enable()function to the wait_ip_interrupt(timeout) (#8628)
Browse files Browse the repository at this point in the history
* Added wait_ip_interrupt(timeout) functionality on edge side (#8611)

Signed-off-by: Manoj Takasi <[email protected]>
Co-authored-by: Manoj Takasi <[email protected]>
(cherry picked from commit db95e70)

* Added enable()function to the wait_ip_interrupt(timeout) (#8627)

Signed-off-by: Manoj Takasi <[email protected]>
Co-authored-by: Manoj Takasi <[email protected]>
(cherry picked from commit c5fe317)

* Added override to ensure the functions correctly overrides a base class virtual function.

Signed-off-by: Manoj Takasi <[email protected]>
(cherry picked from commit fb102ee)

---------

Co-authored-by: Manoj Takasi <[email protected]>
  • Loading branch information
ManojTakasi and Manoj Takasi authored Dec 3, 2024
1 parent 981dd5e commit 3ded5b6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/runtime_src/core/common/api/xrt_ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(timeout.count()));
auto status = device->wait_ip_interrupt(handle, static_cast<int32_t>(timeout.count()));
if (status == std::cv_status::no_timeout)
enable(); //re-enable interrupts
return status;
}
};

Expand Down
23 changes: 23 additions & 0 deletions src/runtime_src/core/edge/user/device_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "core/edge/user/aie/profile_object.h"
#include <map>
#include <memory>
#include <poll.h>
#include <string>

#include <fcntl.h>
Expand Down Expand Up @@ -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
27 changes: 15 additions & 12 deletions src/runtime_src/core/edge/user/device_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class device_linux : public shim<device_edge>
// 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;

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -70,26 +70,29 @@ class device_linux : public shim<device_edge>
// 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<hwctx_handle>
create_hw_context(const xrt::uuid& xclbin_uuid,
Expand Down

0 comments on commit 3ded5b6

Please sign in to comment.