DABC (Data Acquisition Backbone Core)  2.9.9
Context.h
Go to the documentation of this file.
1 /************************************************************
2  * The Data Acquisition Backbone Core (DABC) *
3  ************************************************************
4  * Copyright (C) 2009 - *
5  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
6  * Planckstr. 1, 64291 Darmstadt, Germany *
7  * Contact: http://dabc.gsi.de *
8  ************************************************************
9  * This software can be used under the GPL license *
10  * agreements as stated in LICENSE.txt file *
11  * which is part of the distribution. *
12  ************************************************************/
13 
14 #ifndef VERBS_Context
15 #define VERBS_Context
16 
17 #include <infiniband/verbs.h>
18 
19 #ifndef DABC_Object
20 #include "dabc/Object.h"
21 #endif
22 
23 #ifndef DABC_MemoryPool
24 #include "dabc/MemoryPool.h"
25 #endif
26 
27 
28 namespace verbs {
29 
30  class OpenSM;
31  class ContextRef;
32 
33  extern const char* typeThread;
34  extern const char* typeDevice;
35 
36  // ________________________________________________________
37 
38 
43  class Context : public dabc::Object {
44 
45  friend class ContextRef;
46 
47  protected:
48  uint8_t fIbPort; // infiniband port number
49 
50  struct ibv_context *fContext; // device context
51  struct ibv_pd *fPD; // protection domain
52  struct ibv_device_attr fDeviceAttr; // device attributes
53  struct ibv_port_attr fPortAttr; // port attributes
54 
55  OpenSM *fOsm; // osm object created when multicast is required
56 
57  static bool fThreadSafeVerbs; // identifies if verbs is thread safe
58 
59  Context();
60 
61  bool CloseVerbs();
62 
63  bool OpenVerbs(bool withmulticast = false, const char* devicename = 0, int ibport = -1);
64 
65  public:
66 
67  virtual ~Context();
68  };
69 
70  // _______________________________________________________________
71 
74  class ContextRef : public dabc::Reference {
75 
77 
78  public:
79 
81 
82  bool OpenVerbs(bool withmulticast = false, const char* devicename = 0, int ibport = -1);
83 
84  int IbPort() const { return GetObject() ? GetObject()->fIbPort : 0; }
85  bool IsMulticast() const { return GetObject() ? GetObject()->fOsm!=0 : false; }
86  struct ibv_pd *pd() const { return GetObject()->fPD; }
87  struct ibv_context *context() const { return GetObject()->fContext; }
88  uint16_t lid() const { return GetObject()->fPortAttr.lid; }
89  ibv_mtu mtu() const { return GetObject()->fPortAttr.active_mtu; }
90  unsigned max_sge() const { return GetObject()->fDeviceAttr.max_sge - 1; }
91 
93 
94  int GetGidIndex(ibv_gid* lookgid);
95 
96  struct ibv_ah* CreateAH(uint32_t dest_lid);
97 
98  int ManageMulticast(int action, ibv_gid& mgid, uint16_t& mlid);
99  struct ibv_ah* CreateMAH(ibv_gid& mgid, uint32_t mlid);
100  };
101 
102  // ________________________________________________________________________
103 
106  class PoolRegistry : public dabc::Object {
107  protected:
111  unsigned f_nummr; // size of f_mr array
112  struct ibv_mr* *f_mr;
113 
114  virtual void ObjectCleanup();
115 
116  public:
118  virtual ~PoolRegistry();
119 
120  dabc::MemoryPool* GetPool() const { return fPool; }
121 
122  inline void CheckMRStructure()
123  {
125  EOUT("POOL %p change counter now = %u", fPool, fLastChangeCounter);
126  throw dabc::Exception("Memory pool structure should not be changed at all");
127  }
128  }
129 
130  inline uint32_t GetLkey(unsigned id) { return id < f_nummr ? f_mr[id]->lkey : 0; }
131 
132  virtual void ObjectDestroyed(dabc::Object* obj);
133 
134  void SyncMRStructure();
135 
136  void CleanMRStructure();
137  };
138 
139  // ______________________________________________________
140 
144 
146 
147  };
148 
149 }
150 
151 #endif
#define DABC_REFERENCE(RefClass, ParentClass, T)
Definition: Reference.h:222
DABC exception.
Definition: Exception.h:57
bool CheckChangeCounter(unsigned &cnt)
Check if memory pool structure was changed since last call, do not involves memory pool mutex.
Definition: MemoryPool.cxx:603
Base class for most of the DABC classes.
Definition: Object.h:116
Reference on the arbitrary object
Definition: Reference.h:73
Object * GetObject() const
Return pointer on the object.
Definition: Reference.h:129
Reference to verbs::Context
Definition: Context.h:74
ibv_mtu mtu() const
Definition: Context.h:89
bool IsMulticast() const
Definition: Context.h:85
struct ibv_ah * CreateAH(uint32_t dest_lid)
Definition: Context.cxx:357
dabc::Reference RegisterPool(dabc::MemoryPool *pool)
Definition: Context.cxx:403
unsigned max_sge() const
Definition: Context.h:90
bool OpenVerbs(bool withmulticast=false, const char *devicename=0, int ibport=-1)
Definition: Context.cxx:294
struct ibv_pd * pd() const
Definition: Context.h:86
struct ibv_ah * CreateMAH(ibv_gid &mgid, uint32_t mlid)
Definition: Context.cxx:374
int ManageMulticast(int action, ibv_gid &mgid, uint16_t &mlid)
Definition: Context.cxx:316
struct ibv_context * context() const
Definition: Context.h:87
uint16_t lid() const
Definition: Context.h:88
int GetGidIndex(ibv_gid *lookgid)
Definition: Context.cxx:431
int IbPort() const
Definition: Context.h:84
Context for all VERBS operations.
Definition: Context.h:43
uint8_t fIbPort
Definition: Context.h:48
struct ibv_context * fContext
Definition: Context.h:50
virtual ~Context()
Definition: Context.cxx:173
OpenSM * fOsm
Definition: Context.h:55
bool CloseVerbs()
Definition: Context.cxx:264
struct ibv_device_attr fDeviceAttr
Definition: Context.h:52
static bool fThreadSafeVerbs
Definition: Context.h:57
bool OpenVerbs(bool withmulticast=false, const char *devicename=0, int ibport=-1)
Definition: Context.cxx:182
struct ibv_port_attr fPortAttr
Definition: Context.h:53
struct ibv_pd * fPD
Definition: Context.h:51
Interface class to opensm.
Definition: OpenSM.h:28
Reference on verbs::PoolRegistry
Definition: Context.h:143
Registry object for memory pool.
Definition: Context.h:106
PoolRegistry(ContextRef ctx, dabc::MemoryPool *pool)
Definition: Context.cxx:49
dabc::MemoryPool * fPool
Definition: Context.h:109
void CheckMRStructure()
Definition: Context.h:122
unsigned fLastChangeCounter
Definition: Context.h:110
virtual ~PoolRegistry()
Definition: Context.cxx:60
virtual void ObjectDestroyed(dabc::Object *obj)
Method called by the manager when registered dependent object is destroyed Should be used in user cla...
Definition: Context.cxx:78
struct ibv_mr ** f_mr
Definition: Context.h:112
ContextRef fContext
Definition: Context.h:108
unsigned f_nummr
Definition: Context.h:111
virtual void ObjectCleanup()
User method to cleanup object content before it will be destroyed Main motivation is to release any r...
Definition: Context.cxx:69
dabc::MemoryPool * GetPool() const
Definition: Context.h:120
void CleanMRStructure()
Definition: Context.cxx:88
uint32_t GetLkey(unsigned id)
Definition: Context.h:130
void SyncMRStructure()
Definition: Context.cxx:110
#define EOUT(args ...)
Definition: logging.h:150
Support of InfiniBand verbs.
Definition: Device.cxx:54
const char * typeThread
Definition: Context.cxx:36
const char * typeDevice
Definition: Context.cxx:37