MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::EventQueue Class Reference

RAII Wrapper around a libfabric event queue (fi_eq). More...

#include <EventQueue.hpp>

Inheritance diagram for mxl::lib::fabrics::ofi::EventQueue:
Collaboration diagram for mxl::lib::fabrics::ofi::EventQueue:

Classes

struct  Attributes
 Attributes to configure newly created event queues. More...

Public Member Functions

 EventQueue (EventQueue &&)=delete
 EventQueue (EventQueue const &)=delete
EventQueue & operator= (EventQueue &&)=delete
void operator= (EventQueue const &)=delete
::fid_eq const * raw () const noexcept
 Returns a raw handle to the event queue.
::fid_eq * raw () noexcept
 Returns a raw handle to the event queue.
std::optional< Event > read ()
 Perform a non-blocking read on the event queue. If no event is available in the queue, this function returns std::nullopt.
std::optional< Event > readBlocking (std::chrono::steady_clock::duration timeout)
 Perform a blocking read on the event queue.
 ~EventQueue ()

Static Public Member Functions

static std::shared_ptr< EventQueue > open (std::shared_ptr< Fabric >, Attributes const &attr=Attributes::defaults())
 Create a new event queue associated with the specified fabric.

Private Member Functions

void close ()
 Releases all underlying resources. This is called from the destructor and the move-assignment operator.
 EventQueue (::fid_eq *raw, std::shared_ptr< Fabric > fabric)
 Construct and event queue.
std::optional< Event > handleReadResult (ssize_t, std::uint32_t, ::fi_eq_entry const &)
 Handle the result of a blocking or non-blocking read.

Private Attributes

std::shared_ptr< Fabric > _fabric
::fid_eq * _raw

Detailed Description

RAII Wrapper around a libfabric event queue (fi_eq).

Definition at line 18 of file EventQueue.hpp.

Constructor & Destructor Documentation

◆ ~EventQueue()

mxl::lib::fabrics::ofi::EventQueue::~EventQueue ( )

Definition at line 87 of file EventQueue.cpp.

88 {
89 catchAndLogFabricError([this]() { close(); }, "Failed to close event queue");
90 }
void close()
Releases all underlying resources. This is called from the destructor and the move-assignment operato...
void catchAndLogFabricError(F &&fun, std::string_view msg)

◆ EventQueue() [1/3]

mxl::lib::fabrics::ofi::EventQueue::EventQueue ( EventQueue const & )
delete

◆ EventQueue() [2/3]

mxl::lib::fabrics::ofi::EventQueue::EventQueue ( EventQueue && )
delete

◆ EventQueue() [3/3]

mxl::lib::fabrics::ofi::EventQueue::EventQueue ( ::fid_eq * raw,
std::shared_ptr< Fabric > fabric )
private

Construct and event queue.

The completion queue can only exists behind a shared_ptr. Some events need to carry a reference to the completion queue. To prevent the queue from beeing released before all these events have be released, they own a shared_ptr to the queue they have originated from.

Definition at line 82 of file EventQueue.cpp.

83 : _raw(raw)
84 , _fabric(std::move(fabric))
85 {}
std::shared_ptr< Fabric > _fabric
::fid_eq * raw() noexcept
Returns a raw handle to the event queue.

Member Function Documentation

◆ close()

void mxl::lib::fabrics::ofi::EventQueue::close ( )
private

Releases all underlying resources. This is called from the destructor and the move-assignment operator.

Definition at line 102 of file EventQueue.cpp.

103 {
104 if (_raw)
105 {
106 fiCall(::fi_close, "Failed to close event queue", &_raw->fid);
107 _raw = nullptr;
108 }
109 }
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.

◆ handleReadResult()

std::optional< Event > mxl::lib::fabrics::ofi::EventQueue::handleReadResult ( ssize_t ret,
std::uint32_t eventType,
::fi_eq_entry const & entry )
private

Handle the result of a blocking or non-blocking read.

This takes a raw event queue entry and generate an Event instance.

Definition at line 111 of file EventQueue.cpp.

112 {
113 if (ret == -FI_EAGAIN)
114 {
115 // No event available
116 return std::nullopt;
117 }
118
119 if (ret == -FI_EAVAIL)
120 {
121 ::fi_eq_err_entry eq_err{};
122 fi_eq_readerr(_raw, &eq_err, 0);
123
124 return Event::fromError(this->shared_from_this(), &eq_err);
125 }
126
127 if (ret < 0)
128 {
129 throw FabricException::make(ret, "Failed to read from event queue: {}", ::fi_strerror(ret));
130 }
131
132 switch (eventType)
133 {
134 case FI_CONNECTED:
135 case FI_CONNREQ:
136 case FI_SHUTDOWN: return Event::fromRawCMEntry(*reinterpret_cast<fi_eq_cm_entry const*>(&entry), eventType); break;
137 case FI_NOTIFY:
138 case FI_MR_COMPLETE:
139 case FI_AV_COMPLETE:
140 case FI_JOIN_COMPLETE: return Event::fromRawEntry(entry, eventType); break;
141 default: MXL_WARN("Unhandled event on event queue: code: {}", eventType); return std::nullopt;
142 }
143 }
#define MXL_WARN(...)
Definition Logging.hpp:56
static Event fromRawCMEntry(::fi_eq_cm_entry const &raw, std::uint32_t eventType)
create an Event from a libfabric Connection Management event
Definition Event.cpp:91
static Event fromRawEntry(::fi_eq_entry const &raw, std::uint32_t eventType)
Definition Event.cpp:86
static Event fromError(std::shared_ptr< EventQueue > queue, ::fi_eq_err_entry const *raw)
create an Event from a libfabric event error entry
Definition Event.cpp:104
static FabricException make(int fiErrno, fmt::format_string< T... > fmt, T &&... args)
Create a new exception object.

◆ open()

std::shared_ptr< EventQueue > mxl::lib::fabrics::ofi::EventQueue::open ( std::shared_ptr< Fabric > fabric,
EventQueue::Attributes const & attr = Attributes::defaults() )
static

Create a new event queue associated with the specified fabric.

Definition at line 38 of file EventQueue.cpp.

39 {
40 ::fid_eq* eq;
41 auto eq_attr = attr.raw();
42
43 fiCall(::fi_eq_open, "Failed to open event queue", fabric->raw(), &eq_attr, &eq, nullptr);
44
45 // expose the private constructor to std::make_shared inside this function
46 struct MakeSharedEnabler : public EventQueue
47 {
48 MakeSharedEnabler(::fid_eq* raw, std::shared_ptr<Fabric> fabric)
49 : EventQueue(raw, fabric)
50 {}
51 };
52
53 return std::make_shared<MakeSharedEnabler>(eq, fabric);
54 }
EventQueue(EventQueue const &)=delete
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.

◆ operator=() [1/2]

EventQueue & mxl::lib::fabrics::ofi::EventQueue::operator= ( EventQueue && )
delete

◆ operator=() [2/2]

void mxl::lib::fabrics::ofi::EventQueue::operator= ( EventQueue const & )
delete

◆ raw() [1/2]

fid_eq const * mxl::lib::fabrics::ofi::EventQueue::raw ( ) const
nodiscardnoexcept

Returns a raw handle to the event queue.

Definition at line 97 of file EventQueue.cpp.

98 {
99 return _raw;
100 }

◆ raw() [2/2]

fid_eq * mxl::lib::fabrics::ofi::EventQueue::raw ( )
noexcept

Returns a raw handle to the event queue.

Definition at line 92 of file EventQueue.cpp.

93 {
94 return _raw;
95 }

◆ read()

std::optional< Event > mxl::lib::fabrics::ofi::EventQueue::read ( )

Perform a non-blocking read on the event queue. If no event is available in the queue, this function returns std::nullopt.

Definition at line 56 of file EventQueue.cpp.

57 {
58 std::uint32_t eventType;
59 ::fi_eq_entry entry;
60
61 auto const ret = fi_eq_read(_raw, &eventType, &entry, sizeof(entry), 0);
62
63 return handleReadResult(ret, eventType, entry);
64 }
std::optional< Event > handleReadResult(ssize_t, std::uint32_t, ::fi_eq_entry const &)
Handle the result of a blocking or non-blocking read.

◆ readBlocking()

std::optional< Event > mxl::lib::fabrics::ofi::EventQueue::readBlocking ( std::chrono::steady_clock::duration timeout)

Perform a blocking read on the event queue.

This function will block until the specified timeout has elapsed, the process is signalled, or an event is available on the queue. If no event was available after the timeout, the function returns std::nullopt. If the process is signalled while blocking on this function, an exception will be thrown.

Definition at line 66 of file EventQueue.cpp.

67 {
68 auto timeoutMs = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
69 if (timeoutMs == 0)
70 {
71 return read();
72 }
73
74 std::uint32_t eventType;
75 ::fi_eq_entry entry;
76
77 auto const ret = fi_eq_sread(_raw, &eventType, &entry, sizeof(entry), timeoutMs, 0);
78
79 return handleReadResult(ret, eventType, entry);
80 }
std::optional< Event > read()
Perform a non-blocking read on the event queue. If no event is available in the queue,...

Member Data Documentation

◆ _fabric

std::shared_ptr<Fabric> mxl::lib::fabrics::ofi::EventQueue::_fabric
private

Pointer to the fabric for which the event queue was created.

Definition at line 96 of file EventQueue.hpp.

◆ _raw

::fid_eq* mxl::lib::fabrics::ofi::EventQueue::_raw
private

Raw resource reference

Definition at line 95 of file EventQueue.hpp.


The documentation for this class was generated from the following files: