22 #include <netinet/in.h>
26 #ifndef __NO_MULTICAST__
42 return !(gid->raw[8] | gid->raw[9] | gid->raw[10] | gid->raw[11] |
43 gid->raw[12] | gid->raw[13] | gid->raw[14] | gid->raw[15]);
50 dabc::Object(0, pool->GetName()),
53 fLastChangeCounter(0),
62 DOUT4(
"~PoolRegistry %s refs %u", GetName(), NumReferences());
66 DOUT4(
"~PoolRegistry %s refs %u done", GetName(), NumReferences());
81 EOUT(
"!!!!!!!!! Hard error - memory pool %s destroyed behind the scene", fPool->GetName());
90 DOUT3(
"CleanMRStructure %s call ibv_dereg_mr %u", GetName(), f_nummr);
92 for (
unsigned n=0;n<f_nummr;n++)
94 DOUT5(
"CleanMRStructure %s mr[%u] = %p", GetName(), n, f_mr[n]);
96 ibv_dereg_mr(f_mr[n]);
99 DOUT5(
"CleanMRStructure %s mr[%u] = %p done", GetName(), n, f_mr[n]);
112 if (fPool==0)
return;
114 DOUT5(
"CreateMRStructure %s for pool %p numrefs %u", GetName(), fPool, NumReferences());
116 std::vector<void*> bufs;
117 std::vector<unsigned> sizes;
129 if (!fPool->_GetPoolInfo(bufs, sizes, &fLastChangeCounter))
return;
131 if (f_nummr!=0) CleanMRStructure();
133 DOUT5(
"CreateMRStructure %p for pool %p size %u",
this, fPool, bufs.size());
135 f_nummr = bufs.size();
137 f_mr =
new struct ibv_mr* [f_nummr];
139 for (
unsigned n=0;n<f_nummr;n++) {
141 f_mr[n] = ibv_reg_mr(fContext.pd(), bufs[n], sizes[n],
142 (ibv_access_flags) (IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE));
144 DOUT5(
"CreateMRStructure %p for pool %p mr[%u] = %p done",
this, fPool, n, f_mr[n]);
147 EOUT(
"Fail to register VERBS memory - HALT");
153 DOUT5(
"CreateMRStructure %p for pool %p size %u done",
this, fPool, bufs.size());
164 dabc::Object(0,
"VERBS"),
177 DOUT0(
"VERBS Context destroyed");
184 DOUT1(
"Call verbs::Context::OpenVerbs multicast=%s",
DBOOL(withmulticast));
186 #ifndef __NO_MULTICAST__
189 if (!fOsm->Init())
return false;
195 struct ibv_device **dev_list = ibv_get_device_list(&num_of_hcas);
197 if ((dev_list==0) || (num_of_hcas<=0)) {
198 EOUT(
"No verbs devices found");
202 DOUT1(
"Number of hcas %d", num_of_hcas);
204 struct ibv_device *selected_device = 0;
209 selected_device = dev_list[0];
211 devicename = ibv_get_device_name(selected_device);
214 if (fIbPort<=0) fIbPort = 1;
215 for (
int n=0;n<num_of_hcas;n++)
216 if (strcmp(ibv_get_device_name(dev_list[n]), devicename)==0)
217 selected_device = dev_list[n];
218 if (selected_device==0) {
219 EOUT(
"No verbs device with name %s", devicename);
223 if (selected_device==0)
goto cleanup;
225 fContext = ibv_open_device(selected_device);
227 EOUT(
"Cannot open device %s", devicename);
231 if (ibv_query_device(fContext, &fDeviceAttr)) {
232 EOUT(
"Failed to query device props");
236 gid = ibv_get_device_guid(selected_device);
237 DOUT1(
"Open device: %s gid: %016lx", devicename, be64toh(gid));
239 fPD = ibv_alloc_pd(fContext);
241 EOUT(
"Couldn't allocate protection domain (PD)");
245 if (ibv_query_port(fContext, fIbPort, &fPortAttr)) {
246 EOUT(
"Fail to query port attributes");
252 DOUT1(
"verbs::Context::OpenVerbs done");
258 ibv_free_device_list(dev_list);
266 if (fContext==0)
return true;
270 if (ibv_dealloc_pd(fPD)) {
271 EOUT(
"Fail to deallocate PD");
274 if (ibv_close_device(fContext)) {
275 EOUT(
"Fail to close device context");
282 #ifndef __NO_MULTICAST__
296 if (GetObject())
return true;
298 DOUT1(
"Creating new context object");
303 DOUT1(
"Creating new context done");
305 if (!ctx->
OpenVerbs(withmulticast, devicename, ibport)) {
311 SetAutoDestroy(
true);
326 #ifndef __NO_MULTICAST__
328 OpenSM osm = GetObject() ? GetObject()->fOsm : 0;
330 if (osm==0)
return 0;
332 case mcst_Error:
return mcst_Error;
333 case mcst_Ok:
return mcst_Ok;
345 if (mlid!=0)
return mcst_Ok;
348 case mcst_Unregister:
360 memset(&ah_attr, 0,
sizeof(ah_attr));
361 ah_attr.is_global = 0;
362 ah_attr.dlid = dest_lid;
364 ah_attr.src_path_bits = 0;
365 ah_attr.port_num = IbPort();
367 ibv_ah *ah = ibv_create_ah(pd(), &ah_attr);
369 EOUT(
"Failed to create Address Handle");
376 ibv_ah_attr mah_attr;
377 memset(&mah_attr, 0,
sizeof(ibv_ah_attr));
379 mah_attr.dlid = mlid;
380 mah_attr.port_num = IbPort();
382 mah_attr.static_rate = 0;
384 mah_attr.is_global = 1;
385 memcpy(&(mah_attr.grh.dgid), &mgid,
sizeof(ibv_gid));
386 mah_attr.grh.sgid_index = 0;
388 mah_attr.grh.flow_label = 0;
389 mah_attr.grh.hop_limit = 63;
390 mah_attr.grh.traffic_class = 0;
394 struct ibv_ah* f_ah = ibv_create_ah(pd(), &mah_attr);
396 EOUT(
"Failed to create Multicast Address Handle");
405 if (pool==0)
return 0;
414 EOUT(
"Error - cannot create pool registry object for pool %s", pool->
GetName());
420 if (ref()->GetPool() != pool) {
421 EOUT(
"Registry entry for name %s exists but pool pointer mismatch", pool->
GetName());
426 ref()->SyncMRStructure();
436 DOUT5(
"Search for gid in table: %016lx : %016lx ",
437 be64toh(lookgid->global.subnet_prefix),
438 be64toh(lookgid->global.interface_id));
440 for (
int i = 0; !ret; i++) {
441 ret = ibv_query_gid(context(), IbPort(), i, &gid);
447 DOUT5(
" gid[%2d]: %016lx : %016lx ", i,
448 be64toh(gid.global.subnet_prefix),
449 be64toh(gid.global.interface_id));
452 if (!ret && !memcmp(lookgid, &gid,
sizeof(ibv_gid)))
return i;
int null_gid(union ibv_gid *gid)
Lock guard for posix mutex.
Base class for most of the DABC classes.
unsigned NumReferences()
Return number of references on the object.
const char * GetName() const
Returns name of the object, thread safe
void SetAutoDestroy(bool on=true)
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will b...
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
Reference on the arbitrary object
bool AddChild(Object *obj)
Add child to list of object children.
Object * GetObject() const
Return pointer on the object.
bool RemoveChild(const char *name, bool cleanup=true)
Remove child with given name and return reference on that child.
bool null() const
Returns true if reference contains nullptr.
Reference to verbs::Context
struct ibv_ah * CreateAH(uint32_t dest_lid)
dabc::Reference RegisterPool(dabc::MemoryPool *pool)
bool OpenVerbs(bool withmulticast=false, const char *devicename=0, int ibport=-1)
struct ibv_ah * CreateMAH(ibv_gid &mgid, uint32_t mlid)
int ManageMulticast(int action, ibv_gid &mgid, uint16_t &mlid)
int GetGidIndex(ibv_gid *lookgid)
Context for all VERBS operations.
bool OpenVerbs(bool withmulticast=false, const char *devicename=0, int ibport=-1)
Interface class to opensm.
bool QueryMyltucastGroup(uint8_t *mgid, uint16_t &mlid)
bool ManageMultiCastGroup(bool isadd, uint8_t *mgid, uint16_t *mlid)
Reference on verbs::PoolRegistry
Registry object for memory pool.
PoolRegistry(ContextRef ctx, dabc::MemoryPool *pool)
virtual void ObjectDestroyed(dabc::Object *obj)
Method called by the manager when registered dependent object is destroyed Should be used in user cla...
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...