MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
RCInitiator.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "RCInitiator.hpp"
6#include <cassert>
7#include <chrono>
8#include <cstdint>
9#include <algorithm>
10#include <ranges>
11#include <thread>
12#include <uuid.h>
14#include <rdma/fabric.h>
15#include "mxl-internal/Flow.hpp"
16#include "Domain.hpp"
17#include "Exception.hpp"
18#include "FabricInfo.hpp"
19#include "FabricInfoHelpers.hpp"
20#include "Protocol.hpp"
21#include "Region.hpp"
22#include "SliceRange.hpp"
23#include "VariantUtils.hpp"
24
26{
27 RCInitiatorEndpoint::RCInitiatorEndpoint(Endpoint ep, std::unique_ptr<EgressProtocol> proto, TargetInfo info)
28 : _proto(std::move(proto))
29 , _info(std::move(info))
30 , _state(Idle{.ep = std::move(ep), .idleSince = std::chrono::steady_clock::time_point{}})
31 {}
32
33 TargetInfo const& RCInitiatorEndpoint::info() const noexcept
34 {
35 return _info;
36 }
37
38 bool RCInitiatorEndpoint::isIdle() const noexcept
39 {
40 return std::holds_alternative<Idle>(_state);
41 }
42
43 bool RCInitiatorEndpoint::canEvict() const noexcept
44 {
45 return std::holds_alternative<Done>(_state);
46 }
47
49 {
50 return std::visit(
52 [](std::monostate) { return false; }, // Something went wrong with this target, but there is probably no work to do.
53 [](Idle const&) { return false; }, // An idle target has nothing in flight, and is not connected.
54 [](Connecting const&) { return true; }, // In the connecting state, the target is waiting for a connected event.
55 [&](Connected const&) { return _proto->hasPendingWork(); }, // While connected, a target has pending work when
56 // there are transfers that have not yet completed.
57 [](Flushing const&) { return true; }, // While flushing, the target waits for a shutdown event and outstanding completions.
58 [](Disconnected const&) { return false; }, // A disconnected target only waits to be removed.
59 [](Done const&) { return false; }, // In the done state, there is no pending work.
60 },
61 _state);
62 }
63
65 {
66 _state = std::visit(
68 [](Idle) -> State
69 {
70 MXL_INFO("Shutdown requested while waiting to activate, aborting.");
71 return Done{};
72 },
73 [](Connecting) -> State
74 {
75 MXL_INFO("Shutdown requested while trying to connect, aborting.");
76 return Done{};
77 },
78 [&](Connected state) -> State
79 {
80 MXL_INFO("Shutting down");
81 auto pending = _proto->reset();
82 state.ep.shutdown();
83
84 return startFlush(std::move(state.ep), pending, false, AfterFlush::Done);
85 },
86 [](Flushing state) -> State
87 {
88 MXL_INFO("Shutdown requested while the endpoint is already flushing.");
89 state.next = AfterFlush::Done;
90 return state;
91 },
92 [](Disconnected) -> State { return Done{}; },
93 [](Done state) -> State { return state; },
94 },
95 std::move(_state));
96 }
97
99 {
100 auto const state = std::get_if<Flushing>(&_state);
101 if (state == nullptr)
102 {
103 return;
104 }
105
106 auto const nextName = [next = state->next]()
107 {
108 switch (next)
109 {
110 case AfterFlush::Reconnect: return "idle";
111 case AfterFlush::Disconnect: return "disconnected";
112 case AfterFlush::Done: return "done";
113 }
114 return "unknown";
115 }();
116 if (state->shutdownReceived && (state->pending == 0))
117 {
118 MXL_INFO("Flushing complete, transitioning to {} state.", nextName);
119 }
120 else if (std::chrono::steady_clock::now() >= state->deadline)
121 {
122 MXL_WARN("Flushing timed out with {} outstanding operations, shutdown event received: {}. Transitioning to {} state.",
123 state->pending,
124 state->shutdownReceived,
125 nextName);
126 }
127 else
128 {
129 return;
130 }
131
132 switch (state->next)
133 {
134 case AfterFlush::Reconnect: _state = restart(state->ep); break;
136 case AfterFlush::Done: _state = Done{}; break;
137 }
138 }
139
140 RCInitiatorEndpoint::Flushing RCInitiatorEndpoint::startFlush(Endpoint ep, std::size_t pending, bool shutdownReceived, AfterFlush next)
141 {
142 return Flushing{.ep = std::move(ep),
143 .pending = pending,
144 .shutdownReceived = shutdownReceived,
145 .next = next,
146 .deadline = std::chrono::steady_clock::now() + FlushTimeout};
147 }
148
149 void RCInitiatorEndpoint::activate(std::shared_ptr<CompletionQueue> const& cq, std::shared_ptr<EventQueue> const& eq)
150 {
151 _state = std::visit(
153 [&](Idle state) -> State
154 {
155 // If the target is in the idle state for more than 5 seconds, it will be restarted.
156 auto idleDuration = std::chrono::steady_clock::now() - state.idleSince;
157 if (idleDuration < std::chrono::seconds(5))
158 {
159 return state;
160 }
161
162 MXL_INFO("Endpoint has been idle for {}ms, activating",
163 std::chrono::duration_cast<std::chrono::milliseconds>(idleDuration).count());
164
165 // The endpoint in an idle target is always fresh and thus needs to be bound the the queues.
166 state.ep.bind(eq);
167 state.ep.bind(cq, FI_TRANSMIT);
168
169 // Transition into the connecting state
170 auto const faddr = _info.fabricAddress.decode();
171 MXL_INFO("Connecting to {}", faddr.toString());
172 state.ep.connect(_info.fabricAddress);
173 return Connecting{.ep = std::move(state.ep)};
174 },
175 [](Connecting state) -> State { return state; },
176 [](Connected state) -> State { return state; },
177 [](Flushing state) -> State { return state; },
178 [](Disconnected state) -> State { return state; },
179 [](Done state) -> State { return state; },
180 },
181 std::move(_state));
182 }
183
185 {
186 _state = std::visit(
188 [](Idle state) -> State { return state; }, // Nothing to do when idle.
189 [&](Connecting state) -> State
190 {
191 if (ev.isError())
192 {
193 MXL_ERROR("Failed to connect endpoint: {}", ev.error().toString());
194
195 // Go into the idle state with a new endpoint
196 return restart(state.ep);
197 }
198 else if (ev.isConnected())
199 {
200 MXL_INFO("Endpoint is now connected");
201 return Connected{.ep = std::move(state.ep)};
202 }
203 else if (ev.isShutdown())
204 {
205 MXL_WARN("Received a shutdown event while connecting, going idle");
206
207 // Go to idle state with a new endpoint
208 return restart(state.ep);
209 }
210
211 MXL_WARN("Received an unexpected event while establishing a connection");
212 return state;
213 },
214 [&](Connected state) -> State
215 {
216 if (ev.isError())
217 {
218 MXL_WARN("Received an error event in connected state, going idle after flushing. Error: {}", ev.error().toString());
219 catchAndLogFabricError([&]() { state.ep.shutdown(); }, "Failed to shut down the endpoint after an error event");
220 return startFlush(std::move(state.ep), _proto->reset(), true, AfterFlush::Reconnect);
221 }
222 else if (ev.isShutdown())
223 {
224 // A target closes the connection only when it is destroyed. A restarted target has new target info, so the
225 // endpoint does not reconnect. The target stays added, so that it can be removed.
226 MXL_INFO("Remote endpoint has closed the connection.");
227 catchAndLogFabricError([&]() { state.ep.shutdown(); },
228 "Failed to shut down the endpoint after the remote endpoint closed it");
229 return startFlush(std::move(state.ep), _proto->reset(), true, AfterFlush::Disconnect);
230 }
231
232 return state;
233 },
234 [&](Flushing state) -> State
235 {
236 if (ev.isShutdown())
237 {
238 MXL_INFO("Received a shutdown event while flushing the completion queue");
239 state.shutdownReceived = true;
240 }
241 else if (ev.isError())
242 {
243 // The connection is gone and no shutdown event will follow. Outstanding operations can still complete.
244 MXL_ERROR("Received an error while shutting down: {}", ev.error().toString());
245 state.shutdownReceived = true;
246 }
247 else
248 {
249 MXL_ERROR("Received an unexpected event while shutting down");
250 }
251 return state;
252 },
253 [](Disconnected state) -> State { return state; },
254 [](Done state) -> State { return state; },
255 },
256 std::move(_state));
257 }
258
260 {
261 auto const error = completion.tryErr();
262
263 std::visit(
265 [](Idle const&) { MXL_WARN("Received a completion event while idle, ignoring."); },
266 [](Connecting const&) { MXL_WARN("Received a completion event while connecting, ignoring."); },
267 [&](Connected const&)
268 {
269 // A failed operation is finished as well, so it is counted like a successful one.
270 if (error)
271 {
272 MXL_ERROR("Received a completion error: {}", error->toString());
273 }
274 _proto->processCompletion(completion);
275 },
276 [&](Flushing& state)
277 {
278 // Operations that were still queued when the connection was shut down complete with an error. They count as flushed.
279 if (error)
280 {
281 MXL_DEBUG("Received a completion error while flushing: {}", error->toString());
282 }
283 if (state.pending > 0)
284 {
285 --state.pending;
286 }
287 },
288 [](Disconnected const&) { MXL_DEBUG("Ignoring completion after the target closed the connection."); },
289 [](Done const&) { MXL_DEBUG("Ignoring completion after shutdown."); },
290 },
291 _state);
292 }
293
294 void RCInitiatorEndpoint::transferGrain(std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t remotePayloadOffset,
295 SliceRange const& sliceRange)
296 {
297 if (auto const state = std::get_if<Connected>(&_state); state != nullptr)
298 {
299 _proto->transferGrain(state->ep, localIndex, remoteIndex, remotePayloadOffset, sliceRange);
300 }
301 }
302
303 void RCInitiatorEndpoint::transferSamples(std::uint64_t headIndex, std::size_t count)
304 {
305 if (auto const state = std::get_if<Connected>(&_state); state != nullptr)
306 {
307 _proto->transferSamples(state->ep, headIndex, count);
308 }
309 }
310
312 {
313 return Idle{.ep = Endpoint::create(old.domain(), old.id(), old.info()), .idleSince = std::chrono::steady_clock::now()};
314 }
315
316 std::unique_ptr<RCInitiator> RCInitiator::setup(mxlFabricsInitiatorConfig const& config, FabricInfoView info,
317 InitiatorSetupOptions const& options)
318 {
319 requireCapability(info, FI_WRITE, "Interface is missing required write capability");
320 MXL_DEBUG("{}", fi_tostr(info.raw(), FI_TYPE_INFO));
321
322 auto fabric = Fabric::open(info);
323 auto domain = Domain::open(fabric);
324
325 auto eq = EventQueue::open(fabric);
327 if (options.cqDepth)
328 {
329 cqAttr.size = *options.cqDepth;
330 }
331 auto cq = CompletionQueue::open(domain, cqAttr);
332
333 auto regions = MxlRegions::forReader(config.reader);
334 auto proto = selectEgressProtocol(regions.dataLayout(), regions.regions());
335 proto->registerMemory(domain);
336
337 struct MakeUniqueEnabler : RCInitiator
338 {
339 MakeUniqueEnabler(std::shared_ptr<Domain> domain, std::shared_ptr<CompletionQueue> cq, std::shared_ptr<EventQueue> eq,
340 std::unique_ptr<EgressProtocolTemplate> proto)
341 : RCInitiator(std::move(domain), std::move(cq), std::move(eq), std::move(proto))
342 {}
343 };
344
345 return std::make_unique<MakeUniqueEnabler>(std::move(domain), std::move(cq), std::move(eq), std::move(proto));
346 }
347
348 RCInitiator::RCInitiator(std::shared_ptr<Domain> domain, std::shared_ptr<CompletionQueue> cq, std::shared_ptr<EventQueue> eq,
349 std::unique_ptr<EgressProtocolTemplate> proto)
350 : _domain(std::move(domain))
351 , _cq(std::move(cq))
352 , _eq(std::move(eq))
353 , _proto(std::move(proto))
354 {}
355
356 void RCInitiator::addTarget(TargetInfo const& targetInfo)
357 {
358 auto endpoint = Endpoint::create(_domain);
359 auto id = endpoint.id();
360 auto proto = _proto->createInstance(Endpoint::tokenFromId(id), targetInfo);
361 proto->registerMemory(_domain);
362
363 _targets.emplace(id, RCInitiatorEndpoint{std::move(endpoint), std::move(proto), targetInfo});
364 }
365
366 void RCInitiator::removeTarget(TargetInfo const& targetInfo)
367 {
368 if (auto target = std::ranges::find_if(_targets, [&targetInfo](auto const& item) { return item.second.info().id == targetInfo.id; });
369 target != _targets.end())
370 {
371 target->second.shutdown();
372 }
373 else
374 {
375 throw Exception::notFound("Target with id {} not found", targetInfo.id);
376 }
377 }
378
379 void RCInitiator::transferGrain(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice)
380 {
381 // Post a transfer work item to all targets. If the target is not in a connected state
382 // this is a no-op.
383 for (auto& [_, target] : _targets)
384 {
385 activateIfIdle(target);
386 target.transferGrain(grainIndex, grainIndex, MXL_GRAIN_PAYLOAD_OFFSET, SliceRange::make(startSlice, endSlice));
387 }
388 }
389
390 void RCInitiator::transferGrainToTarget(Endpoint::Id targetId, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t payloadOffset,
391 std::uint16_t startSlice, std::uint16_t endSlice)
392 {
393 auto it = _targets.find(targetId);
394 if (it == _targets.end())
395 {
396 throw Exception::notFound("Target with id {} not found", targetId);
397 }
398
399 activateIfIdle(it->second);
400 it->second.transferGrain(localIndex, remoteIndex, payloadOffset, SliceRange::make(startSlice, endSlice));
401 }
402
403 void RCInitiator::transferSamples(std::uint64_t headIndex, std::size_t count)
404 {
405 for (auto& [_, target] : _targets)
406 {
407 activateIfIdle(target);
408 target.transferSamples(headIndex, count);
409 }
410 }
411
413 {
414 if (target.isIdle())
415 {
416 target.activate(_cq, _eq);
417 }
418 }
419
421 {
422 // Check if any of the targets have pending work.
423 for (auto& [_, target] : _targets)
424 {
425 if (target.hasPendingWork())
426 {
427 return Initiator::NotReady{};
428 }
429 }
430
431 return Initiator::Ready{};
432 }
433
434 bool RCInitiator::hasTarget() const noexcept
435 {
436 return _targets.size() > 0;
437 }
438
440 {
441 // Call the activate function on all endpoints. This is a no-op when the endpoint is not idle
442 // and there is probably not that many of them.
443 for (auto& [_, target] : _targets)
444 {
445 target.activate(_cq, _eq);
446 }
447 }
448
450 {
451 for (auto& [_, target] : _targets)
452 {
453 target.finishFlush();
454 }
455 }
456
458 {
459 std::erase_if(_targets, [](auto const& item) { return item.second.canEvict(); });
460 }
461
462 Initiator::MakeProgressResult RCInitiator::blockOnCQ(std::chrono::steady_clock::duration timeout)
463 {
464 // A zero timeout would cause the queue to block indefinetly, which
465 // is not our documented behaviour.
466 if (timeout == std::chrono::milliseconds::zero())
467 {
468 // So just behave exactly like the non-blocking variant.
469 makeProgress();
470 return afterProgressResult();
471 }
472
473 for (;;)
474 {
475 try
476 {
477 auto completion = _cq->readBlocking(timeout);
478 if (!completion)
479 {
480 return afterProgressResult();
481 }
482
483 // Find the endpoint that this completion was generated from
484 auto ep = _targets.find(Endpoint::idFromToken(completion->token()));
485 if (ep == _targets.end())
486 {
487 // The endpoint can already be evicted, for example after a flush timeout.
488 MXL_WARN("Received completion for an unknown endpoint");
489
490 return afterProgressResult();
491 }
492
493 ep->second.consume(*completion);
494
495 return afterProgressResult();
496 }
497 catch (FabricException const& ex)
498 {
499 if (ex.isInterrupted())
500 {
501 return Initiator::Interrupted{};
502 }
503
504 throw;
505 }
506 }
507 }
508
510 {
511 for (;;)
512 {
513 auto completion = _cq->read();
514 if (!completion)
515 {
516 break;
517 }
518
519 // Find the endpoint this completion was generated from.
520 auto ep = _targets.find(Endpoint::idFromToken(completion->token()));
521 if (ep == _targets.end())
522 {
523 MXL_WARN("Received completion for an unknown endpoint");
524
525 continue;
526 }
527
528 ep->second.consume(*completion);
529 }
530 }
531
533 {
534 for (;;)
535 {
536 auto event = _eq->read();
537 if (!event)
538 {
539 break;
540 }
541
542 // Find the endpoint this event was generated from.
543 auto ep = _targets.find(Endpoint::idFromFID(event->fid()));
544 if (ep == _targets.end())
545 {
546 MXL_WARN("Received event for an unknown endpoint");
547
548 continue;
549 }
550
551 ep->second.consume(*event);
552 }
553 }
554
556 {
557 if (!hasTarget())
558 {
559 return Initiator::Ready{};
560 }
561
562 // Activate any peers that might be idle and waiting for activation.
564
565 // Poll the completion and event queue once and process pending events.
566 pollCQ();
567 pollEQ();
568
569 // Complete the shutdown of endpoints that have received all outstanding completions and the shutdown event.
571
572 // Evict any peers that are dead and no longer will make progress.
574
575 return afterProgressResult();
576 }
577
578 Initiator::MakeProgressResult RCInitiator::makeProgressBlocking(std::chrono::steady_clock::duration timeout)
579 {
580 // If the timeout is less than our maintainance interval, just check all the queues once, execute all maintainance tasks once
581 // and block on the completion queue for the rest of the time.
582 if (timeout < EQPollInterval)
583 {
584 if (std::holds_alternative<Initiator::Ready>(makeProgress()))
585 {
586 return Initiator::Ready{};
587 }
588 return blockOnCQ(timeout);
589 }
590
591 auto deadline = std::chrono::steady_clock::now() + timeout;
592
593 for (;;)
594 {
595 // Poll all queues, execute all maintainance actions
596 if (std::holds_alternative<Initiator::Ready>(makeProgress()))
597 {
598 return Initiator::Ready{};
599 }
600
601 // Calculate the remaining time until the user wants the blocking function to return. If there is no time left
602 // (millisecond precision) return right away.
603 auto timeUntilDeadline = std::chrono::duration_cast<std::chrono::milliseconds>(deadline - std::chrono::steady_clock::now());
604 if (timeUntilDeadline <= decltype(timeUntilDeadline){0})
605 {
606 return afterProgressResult();
607 }
608
609 // Block on the completion queue until a completion arrives, or the interval timeout occurs.
610 auto const res = blockOnCQ(std::min(EQPollInterval, timeUntilDeadline));
611 if (std::holds_alternative<Initiator::NotReady>(res))
612 {
613 continue;
614 }
615
616 return res;
617 }
618 }
619
621 {
622 for (auto& [_, target] : _targets)
623 {
624 target.shutdown();
625 }
626
627 auto const deadline = std::chrono::steady_clock::now() + ShutdownTimeout;
628 for (;;)
629 {
630 pollCQ();
631 pollEQ();
634
635 if (_targets.empty())
636 {
637 return;
638 }
639
640 if (std::chrono::steady_clock::now() >= deadline)
641 {
642 MXL_WARN("{} endpoints did not shut down in time.", _targets.size());
643 return;
644 }
645
646 std::this_thread::sleep_for(ShutdownPollInterval);
647 }
648 }
649}
Internal shared-memory headers for discrete grains and event slots.
#define MXL_ERROR(...)
Definition Logging.hpp:67
#define MXL_WARN(...)
Definition Logging.hpp:56
#define MXL_DEBUG(...)
Definition Logging.hpp:34
#define MXL_INFO(...)
Definition Logging.hpp:45
static std::shared_ptr< CompletionQueue > open(std::shared_ptr< Domain > domain, Attributes const &attr=Attributes::defaults())
Create a new completion queue in the specified domain.
Type to represent a completion entry from a CompletionQueue.
std::optional< Error > tryErr() const noexcept
Attempt to access the error variant. Returns std::nullopt if this is a data entry.
static std::shared_ptr< Domain > open(std::shared_ptr< Fabric > fabric)
Open a new domain associated with the specified fabric.
Definition Domain.cpp:30
RAII Wrapper around a libfabric endpoint (fi_ep).
Definition Endpoint.hpp:29
static constexpr Id idFromToken(Completion::Token token) noexcept
Convert a completion token value to an endpoint id value. Convert a completion token to an endpoint i...
Definition Endpoint.hpp:82
static Id idFromFID(::fid_t) noexcept
Read the endpoint id from a libfabric object reference.
Definition Endpoint.cpp:41
std::shared_ptr< Domain > domain() const
Get the domain that the endpoint has beed created on.
Definition Endpoint.cpp:302
std::uintptr_t Id
An id type that can be used to reference this endpoint from completions and events.
Definition Endpoint.hpp:38
static Endpoint create(std::shared_ptr< Domain > domain, FabricInfoView info)
Allocates (active) new endpoint.
Definition Endpoint.cpp:56
FabricInfoView info() const noexcept
Get the fabric information passed to Endpoint::create() initially.
Definition Endpoint.cpp:307
Id id() const noexcept
Get the id of this endpoint.
Definition Endpoint.cpp:83
static constexpr Completion::Token tokenFromId(Id id) noexcept
Convert an endpoint id value to a completion token value. Convert an endpoint id to a completion toke...
Definition Endpoint.hpp:69
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.
std::string toString() const
Convert the error to a human-readable string.
Definition Event.cpp:71
Type to represent an event entry from an EventQueue.
Definition Event.hpp:21
bool isConnected() const noexcept
Returns true if this event is a FI_CONNECTED.
Definition Event.cpp:129
bool isError() const noexcept
Returns true if this event is an error entry.
Definition Event.cpp:149
bool isShutdown() const noexcept
returns true if this event is a FI_SHUTDOWN
Definition Event.cpp:139
Error const & error() const
Get an error representation of the event. Throws if the event is an error. Users should previously ch...
Definition Event.cpp:154
static Exception notFound(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_NOT_FOUND exception.
Definition Exception.hpp:75
An internal exception type that extends.
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
::fi_info * raw() noexcept
Returns the raw fi_info object associated with this view.
static std::shared_ptr< Fabric > open(FabricInfoView info)
Open a fabric object based on the provided FabricInfoView.
Definition Fabric.cpp:15
std::variant< Ready, NotReady, Interrupted > MakeProgressResult
Definition Initiator.hpp:42
static MxlRegions forReader(mxlFlowReader)
Definition Region.cpp:105
A single endpoint connected to a target that will be created when the user adds a target to an initia...
std::variant< Idle, Connecting, Connected, Flushing, Disconnected, Done > State
The various states that the endpoint can be in are stored inside a variant that we move from and then...
void transferGrain(std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t remotePayloadOffset, SliceRange const &sliceRange)
Post a data transfer request to this endpoint.
void shutdown()
Initiate a shutdown process.
RCInitiatorEndpoint(Endpoint, std::unique_ptr< EgressProtocol > proto, TargetInfo info)
Construct a new RCInitiatorEndpoint object.
AfterFlush
The state that the endpoint goes to when a flush is complete.
static constexpr auto FlushTimeout
Upper bound for the flushing state. Some providers do not report a local shutdown event,...
void consume(Event event)
Consume an event that was posted to the associated event queue.
static Flushing startFlush(Endpoint ep, std::size_t pending, bool shutdownReceived, AfterFlush next)
Create a flushing state that waits for the given number of outstanding operations.
Idle restart(Endpoint const &endpoint)
Restarts the endpoint. Produces a new Idle state from any previous state.
void transferSamples(std::uint64_t headIndex, std::size_t count)
Post a data transfer request to this endpoint.
TargetInfo const & info() const noexcept
Get the target info of the remote endpoint.
void finishFlush()
Move the endpoint out of the flushing state when the flush is complete.
bool isIdle() const noexcept
Returns true if the endpoint is idle and could be actived.
void activate(std::shared_ptr< CompletionQueue > const &cq, std::shared_ptr< EventQueue > const &eq)
Try to activate the endpoint.
std::unique_ptr< EgressProtocol > _proto
bool canEvict() const noexcept
Returns true if the endpoint was shut down and can be evicted from the initiator.
bool hasPendingWork() const noexcept
Returns true if there is any pending events that the endpoint is waiting for, and for which the queue...
std::shared_ptr< EventQueue > _eq
void activateIfIdle(RCInitiatorEndpoint &target)
Try to activate the endpoint if it is idle. Called before a transfer is posted to the endpoint.
void evictDeadEndpoints()
Evict any dead endpoints that are no longer used.
std::unique_ptr< EgressProtocolTemplate > _proto
virtual void transferSamples(std::uint64_t headIndex, std::size_t count) final
Transfer samples to all targets.
RCInitiator(std::shared_ptr< Domain > domain, std::shared_ptr< CompletionQueue > cq, std::shared_ptr< EventQueue > eq, std::unique_ptr< EgressProtocolTemplate > proto)
Initiator::MakeProgressResult afterProgressResult() const noexcept
Returns true if any of the endpoints contained in this initiator have pending work.
virtual void addTarget(TargetInfo const &targetInfo) final
Add a target to the initiator.
virtual Initiator::MakeProgressResult makeProgressBlocking(std::chrono::steady_clock::duration) final
Attempts to progress execution, including connection management and data operations.
Initiator::MakeProgressResult blockOnCQ(std::chrono::steady_clock::duration timeout)
Block on the completion queue with a timeout.
static constexpr auto EQPollInterval
When making progress and using blocking queue reads, this is the minimum interval at which the event ...
static constexpr auto ShutdownPollInterval
Sleep time between two queue reads in shutdown().
virtual void shutdown() final
Shut down the initiator gracefully.
void activateIdleEndpoints()
Try to activate any idle endpoints.
virtual Initiator::MakeProgressResult makeProgress() final
Attempts to progress execution, including connection management and data operations.
void finishFlushingEndpoints()
Move endpoints that have finished flushing to the done state.
std::shared_ptr< CompletionQueue > _cq
virtual void transferGrain(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice) final
Transfer a grain to all targets.
std::map< Completion::Token, RCInitiatorEndpoint > _targets
void pollEQ()
Poll the event queue and process the returned events until the queue is empty.
std::shared_ptr< Domain > _domain
bool hasTarget() const noexcept
Returns true if the initiator has at least 1 target added no matter what the state is.
static std::unique_ptr< RCInitiator > setup(mxlFabricsInitiatorConfig const &config, FabricInfoView info, InitiatorSetupOptions const &options={})
Set up a fresh initiator without any targets assigned to it.
virtual void transferGrainToTarget(Endpoint::Id targetId, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t payloadOffset, std::uint16_t startSlice, std::uint16_t endSlice) final
Transfer a grain to a specific target.
static constexpr auto ShutdownTimeout
Upper bound for shutdown(). It is longer than RCInitiatorEndpoint::FlushTimeout, so that each flush e...
virtual void removeTarget(TargetInfo const &targetInfo) final
Remove a target from the initiator.
void pollCQ()
Poll the completion queue and process the events until the queue is empty.
A SliceRange represents a range of slices within a grain.
static SliceRange make(std::uint16_t start, std::uint16_t end)
Create a SliceRange representing the range [start, end).
struct mxlFabricsInitiatorConfig_t mxlFabricsInitiatorConfig
void catchAndLogFabricError(F &&fun, std::string_view msg)
std::unique_ptr< EgressProtocolTemplate > selectEgressProtocol(DataLayout const &layout, std::vector< Region > regions)
Select an appropriate egress protocol based on the data layout.
Definition Protocol.cpp:33
void requireCapability(FabricInfoView info, std::uint64_t cap, std::string_view message)
constexpr auto const MXL_GRAIN_PAYLOAD_OFFSET
Definition Flow.hpp:38
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
static Attributes defaults()
Returns the a CompletionQueueAttr with all of its attributes set to reasonable defaults.
Provider-independent tuning options for initiator setup.
Definition Initiator.hpp:19
std::optional< std::size_t > cqDepth
Desired completion-queue depth.
Definition Initiator.hpp:25
The endpoint is done and can be evicted from the initiator.
TargetInfo contains all the information required by an initiator to operate transfers to the given ta...