DABC (Data Acquisition Backbone Core)  2.9.9
Thread.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_Thread
15 #define VERBS_Thread
16 
17 #ifndef DABC_Thread
18 #include "dabc/Thread.h"
19 #endif
20 
21 #ifndef VERBS_Context
22 #include "verbs/Context.h"
23 #endif
24 
25 #include <map>
26 #include <cstdint>
27 
28 struct ibv_comp_channel;
29 struct ibv_wc;
30 
31 #define VERBS_USING_PIPE
32 
33 namespace verbs {
34 
35  class MemoryPool;
36 
37  class Worker;
38  class TimeoutWorker;
39 
40  class QueuePair;
41  class ComplQueue;
42 
46  class Thread : public dabc::Thread {
47 
48  typedef std::map<uint32_t, uint32_t> WorkersMap;
49 
50  enum { LoopBackQueueSize = 10 };
51 
55  };
56 
57  protected:
59 
61  struct ibv_comp_channel *fChannel;
62  #ifdef VERBS_USING_PIPE
63  int fPipe[2];
64  #else
65  QueuePair *fLoopBackQP;
66  MemoryPool *fLoopBackPool;
67  int fLoopBackCnt;
68  TimeoutWorker *fTimeout; // use to produce timeouts
69  #endif
70  ComplQueue *fMainCQ; // completion queue used for the whole thread to be able organize polling instead of waiting for the completion channel
72  WorkersMap fMap; // for 1000 elements one need about 50 nanosec to get value from it
73  int fWCSize; // size of array
74  struct ibv_wc* fWCs; // list of event completion
75  long fFastModus; // makes polling over MainCQ before starting wait - defines pooling number
76  bool fCheckNewEvents; // indicate if we should check verbs events even if there are some in the queue
77  public:
78  // list of all events for all kind of socket processors
79 
80  Thread(dabc::Reference parent, const std::string &name, dabc::Command cmd, ContextRef ctx);
81  virtual ~Thread();
82 
83  void CloseThread();
84 
85  struct ibv_comp_channel* Channel() const { return fChannel; }
86 
87  ComplQueue* MakeCQ();
88 
89  bool IsFastModus() const { return fFastModus > 0; }
90 
91  virtual const char* ClassName() const { return verbs::typeThread; }
92 
93  virtual bool CompatibleClass(const std::string &clname) const;
94 
95  static const char* StatusStr(int code);
96 
97  protected:
98 
99  virtual int ExecuteThreadCommand(dabc::Command cmd);
100 
101  virtual bool WaitEvent(dabc::EventId& evid, double tmout);
102 
103  virtual void _Fire(const dabc::EventId& evnt, int nq);
104 
105  virtual void WorkersSetChanged();
106 
107  virtual void ProcessExtraThreadEvent(const dabc::EventId&);
108 
109  };
110 
111  // ___________________________________________________________
112 
115  class ThreadRef : public dabc::ThreadRef {
116 
118 
119  };
120 
121 
122 }
123 
124 #endif
#define DABC_REFERENCE(RefClass, ParentClass, T)
Definition: Reference.h:222
Represents command with its arguments.
Definition: Command.h:99
Reference on the arbitrary object
Definition: Reference.h:73
friend class Thread
Definition: threads.h:321
Reference on the dabc::Thread class
Definition: Thread.h:482
Represent thread functionality.
Definition: Thread.h:109
@ evntLastThrd
Definition: Thread.h:324
Wrapper for IB VERBS completion queue
Definition: ComplQueue.h:35
Reference to verbs::Context
Definition: Context.h:74
Special memory pool, which automatically includes PoolRegistry.
Definition: MemoryPool.h:31
Represent VERBS queue pair functionality.
Definition: QueuePair.h:37
Reference on verbs::Thread
Definition: Thread.h:115
VERBS thread.
Definition: Thread.h:46
virtual int ExecuteThreadCommand(dabc::Command cmd)
Definition: Thread.cxx:195
virtual void _Fire(const dabc::EventId &evnt, int nq)
Definition: Thread.cxx:209
struct ibv_comp_channel * Channel() const
Definition: Thread.h:85
virtual bool CompatibleClass(const std::string &clname) const
Definition: Thread.cxx:140
virtual bool WaitEvent(dabc::EventId &evid, double tmout)
Definition: Thread.cxx:230
int fWCSize
Definition: Thread.h:73
ContextRef fContext
Definition: Thread.h:60
void CloseThread()
Definition: Thread.cxx:146
int fPipe[2]
Definition: Thread.h:63
virtual void WorkersSetChanged()
Virtual method, called from thread context to inform that number of workers are changed.
Definition: Thread.cxx:418
bool IsFastModus() const
Definition: Thread.h:89
virtual ~Thread()
Definition: Thread.cxx:133
virtual void ProcessExtraThreadEvent(const dabc::EventId &)
Method to process events which are not processed by Thread class itself Should be used in derived cla...
Definition: Thread.cxx:403
bool fCheckNewEvents
Definition: Thread.h:76
EWaitStatus fWaitStatus
Definition: Thread.h:71
ComplQueue * fMainCQ
Definition: Thread.h:70
EVerbsThreadEvents
Definition: Thread.h:52
@ evntLastVerbsThrdEvent
last event, which can be used by verbs thread
Definition: Thread.h:54
@ evntEnableCheck
event to enable again checking sockets for new events
Definition: Thread.h:53
WorkersMap fMap
Definition: Thread.h:72
virtual const char * ClassName() const
Returns class name of the object instance.
Definition: Thread.h:91
static const char * StatusStr(int code)
Definition: Thread.cxx:446
struct ibv_wc * fWCs
Definition: Thread.h:74
ComplQueue * MakeCQ()
Definition: Thread.cxx:186
@ LoopBackQueueSize
Definition: Thread.h:50
long fFastModus
Definition: Thread.h:75
std::map< uint32_t, uint32_t > WorkersMap
Definition: Thread.h:48
struct ibv_comp_channel * fChannel
Definition: Thread.h:61
Timeout producer for verbs::Thread when pipe cannot be used.
Definition: Thread.cxx:39
Support of InfiniBand verbs.
Definition: Device.cxx:54
const char * typeThread
Definition: Context.cxx:36
Event structure, exchanged between DABC threads.
Definition: Thread.h:70