rogue
Loading...
Searching...
No Matches
Server.h
Go to the documentation of this file.
1
18#ifndef __ROGUE_PROTOCOLS_ROCEV2_SERVER_H__
19#define __ROGUE_PROTOCOLS_ROCEV2_SERVER_H__
20#include "rogue/Directives.h"
21
22#include <infiniband/verbs.h>
23#include <stdint.h>
24
25#include <atomic>
26#include <memory>
27#include <string>
28#include <thread>
29#include <vector>
30
36
37namespace rogue {
38namespace protocols {
39namespace rocev2 {
40
44 private:
45 // -----------------------------------------------------------------------
46 // ibverbs resources
47 // -----------------------------------------------------------------------
48 struct ibv_cq* cq_;
49 struct ibv_qp* qp_;
50 struct ibv_mr* mr_;
51
52 // Contiguous slab — subdivided into numBufs_ fixed-size slots.
53 // Registered with the HCA once; never copied from.
54 uint8_t* slab_;
55 uint32_t slabSize_;
56 uint32_t numBufs_;
57 uint32_t bufSize_; // == maxPayload_ (no GRH on RC)
58
59 // -----------------------------------------------------------------------
60 // Host-side RC parameters. All initialized to 0 in the member-init list
61 // so an early throw inside the ctor body cannot leave a reader of the
62 // getters (e.g. a getXxx() hooked into a LocalVariable's localGet in the
63 // failed-construction propagation path) observing indeterminate values.
64 // Real values are written inside the ctor body as each ibverbs stage
65 // completes successfully.
66 // -----------------------------------------------------------------------
67 uint32_t hostQpn_;
68 uint8_t hostGid_[16];
69 uint32_t hostRqPsn_;
70 uint32_t hostSqPsn_;
71 uint64_t mrAddr_;
72 uint32_t mrRkey_;
73
74 // FPGA GID — set by setFpgaGid() before completeConnection()
75 uint8_t fpgaGid_[16];
76
77 // -----------------------------------------------------------------------
78 // Receive thread
79 // -----------------------------------------------------------------------
80 std::thread* thread_;
81 std::atomic<bool> threadEn_;
82
83 // Intentional shadow: both Core and stream::Slave expose a `log_` member,
84 // so any unqualified `log_` from inside Server would otherwise be
85 // ambiguous. Declaring our own `log_` here consolidates both names onto
86 // Server's "rocev2.Server" logger (assigned in the Server ctor) and
87 // silences the multiple-inheritance ambiguity.
88 std::shared_ptr<rogue::Logging> log_;
89
90 // RX counters
91 std::atomic<uint64_t> frameCount_;
92 std::atomic<uint64_t> byteCount_;
93
94 void postRecvWr(uint32_t slot);
95 void runThread(std::weak_ptr<int> lockPtr);
96
97 // Idempotent helper that releases every ibverbs / heap resource owned by
98 // Server in reverse allocation order. Called by stop() and from the
99 // failed-construction path in the constructor.
100 void cleanupResources();
101
102 protected:
103 // -----------------------------------------------------------------------
104 // Zero-copy hook — called by Buffer::~Buffer() when the last downstream
105 // reference to a frame is released. Re-posts the slab slot to the QP.
106 // The slot index is encoded in the lower 24 bits of meta.
107 // -----------------------------------------------------------------------
108 void retBuffer(uint8_t* data, uint32_t meta, uint32_t rawSize) override;
109
110 public:
111 static std::shared_ptr<rogue::protocols::rocev2::Server> create(
112 const std::string& deviceName,
113 uint8_t ibPort,
114 uint8_t gidIndex,
115 uint32_t maxPayload = DefaultMaxPayload,
116 uint32_t rxQueueDepth = DefaultRxQueueDepth);
117
118 Server(const std::string& deviceName,
119 uint8_t ibPort,
120 uint8_t gidIndex,
121 uint32_t maxPayload,
122 uint32_t rxQueueDepth);
123
124 ~Server();
125 void stop();
126
127 void setFpgaGid(const std::string& gidBytes);
128
129 // minRnrTimer: IB spec RNR timer code embedded in RNR NAK packets.
130 // 1=0.01ms 14=1ms 18=4ms 22=16ms 31=491ms
131 void completeConnection(uint32_t fpgaQpn,
132 uint32_t fpgaRqPsn,
133 uint32_t pmtu = 5,
134 uint32_t minRnrTimer = 1);
135
136 uint32_t getQpn() const { return hostQpn_; }
137 std::string getGid() const;
138 uint32_t getRqPsn() const { return hostRqPsn_; }
139 uint32_t getSqPsn() const { return hostSqPsn_; }
140 uint64_t getMrAddr() const { return mrAddr_; }
141 uint32_t getMrRkey() const { return mrRkey_; }
142 uint64_t getFrameCount() const { return frameCount_.load(); }
143 uint64_t getByteCount() const { return byteCount_.load(); }
144
146
147 static void setup_python();
148};
149
150typedef std::shared_ptr<rogue::protocols::rocev2::Server> ServerPtr;
151
152} // namespace rocev2
153} // namespace protocols
154} // namespace rogue
155
156#endif
Stream master endpoint.
Definition Master.h:65
static std::shared_ptr< rogue::interfaces::stream::Master > create()
Creates a stream master.
Definition Master.cpp:40
Stream slave endpoint and default frame pool.
Definition Slave.h:72
uint32_t maxPayload() const
Definition Core.h:65
uint64_t getFrameCount() const
Definition Server.h:142
void retBuffer(uint8_t *data, uint32_t meta, uint32_t rawSize) override
Definition Server.cpp:452
void setFpgaGid(const std::string &gidBytes)
Definition Server.cpp:281
uint64_t getMrAddr() const
Definition Server.h:140
uint32_t getMrRkey() const
Definition Server.h:141
uint32_t getRqPsn() const
Definition Server.h:138
uint32_t getSqPsn() const
Definition Server.h:139
std::string getGid() const
Definition Server.cpp:396
void completeConnection(uint32_t fpgaQpn, uint32_t fpgaRqPsn, uint32_t pmtu=5, uint32_t minRnrTimer=1)
Definition Server.cpp:293
void acceptFrame(rogue::interfaces::stream::FramePtr frame) override
Definition Server.cpp:590
uint64_t getByteCount() const
Definition Server.h:143
std::shared_ptr< rogue::interfaces::stream::Frame > FramePtr
Shared pointer alias for Frame.
Definition Frame.h:549
std::shared_ptr< rogue::protocols::rocev2::Server > ServerPtr
Definition Server.h:150
static const uint32_t DefaultMaxPayload
Definition Core.h:40
static const uint32_t DefaultRxQueueDepth
Definition Core.h:35