DABC (Data Acquisition Backbone Core)  2.9.9
MemoryPool.cxx
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 #include "verbs/MemoryPool.h"
15 
16 #include "verbs/QueuePair.h"
17 #include "verbs/Device.h"
18 
19 
21  const char* name,
22  int32_t number,
23  int64_t bufsize,
24  bool isud,
25  bool without_wr) :
26  dabc::MemoryPool(name, false),
27  fUD(isud),
28  fSendBufferOffset(isud ? VERBS_UD_MEMADDON : 0),
29  fReg(),
30  f_rwr(0),
31  f_swr(0),
32  f_sge(0)
33 {
34  DOUT4("Create verbs::Pool %s %p", GetName(), this);
35 
36  if (isud && (bufsize>0x1000)) bufsize = 0x1000;
37 
38  SetAlignment((bufsize<0x100) ? 0x10 : 0x100);
39 
40  Allocate(bufsize, number);
41 
42  fReg = new PoolRegistry(ctx, this);
43  fReg()->SyncMRStructure();
44 
45  if (without_wr) return;
46 
47  f_rwr = new ibv_recv_wr [number];
48  f_swr = new ibv_send_wr [number];
49  f_sge = new ibv_sge [number];
50 
51  for (int32_t id = 0; id<number; id++) {
52  f_sge[id].addr = (uintptr_t) 0; // must be specified later
53  f_sge[id].length = 0; // must be specified later
54  f_sge[id].lkey = // must be set later;
55 
56  f_swr[id].wr_id = 0; // must be set later
57  f_swr[id].sg_list = &(f_sge[id]);
58  f_swr[id].num_sge = 1;
59  f_swr[id].opcode = IBV_WR_SEND;
60  f_swr[id].next = NULL;
61  f_swr[id].send_flags = IBV_SEND_SIGNALED;
62 
63  f_rwr[id].wr_id = 0; // must be set later
64  f_rwr[id].sg_list = &(f_sge[id]);
65  f_rwr[id].num_sge = 1;
66  f_rwr[id].next = NULL;
67  }
68 
69 }
70 
72 {
73  DOUT4("Destroy verbs::Pool %s %p refs:%u", GetName(), this, NumReferences());
74 
75  fReg.Destroy();
76 
77  delete[] f_rwr; f_rwr = 0;
78  delete[] f_swr; f_swr = 0;
79  delete[] f_sge; f_sge = 0;
80 
81  DOUT4("Destroy verbs::Pool %s %p refs:%u DONE", GetName(), this, NumReferences());
82 
83 }
84 
85 struct ibv_recv_wr* verbs::MemoryPool::GetRecvWR(unsigned bufid)
86 {
87  // special case, when working without Buffer objects at all
88 
89  if ((f_rwr==0) || (f_sge==0)) return 0;
90 
91  f_sge[bufid].addr = (uintptr_t) GetBufferLocation(bufid);
92  f_sge[bufid].length = GetBufferSize(bufid);
93  f_sge[bufid].lkey = GetLkey(bufid); // we knew that here we work with 0 block always
94 
95  f_rwr[bufid].wr_id = bufid;
96  f_rwr[bufid].sg_list = &(f_sge[bufid]);
97  f_rwr[bufid].num_sge = 1;
98  f_rwr[bufid].next = NULL;
99 
100  return &(f_rwr[bufid]);
101 }
102 
103 struct ibv_send_wr* verbs::MemoryPool::GetSendWR(unsigned bufid, uint64_t size)
104 {
105  // special case, when working without Buffer objects at all
106 
107  if ((f_swr==0) || (f_sge==0)) return 0;
108 
109  if (size==0) size = GetBufferSize(bufid) - fSendBufferOffset;
110 
111  f_sge[bufid].addr = (uintptr_t) GetSendBufferLocation(bufid);
112  f_sge[bufid].length = size;
113  f_sge[bufid].lkey = GetLkey(bufid); // here we always works
114 
115  f_swr[bufid].wr_id = bufid;
116  f_swr[bufid].sg_list = &(f_sge[bufid]);
117  f_swr[bufid].num_sge = 1;
118  f_swr[bufid].opcode = IBV_WR_SEND;
119  f_swr[bufid].next = NULL;
120  if (size <= VERBS_MAX_INLINE)
121  f_swr[bufid].send_flags = (ibv_send_flags) (IBV_SEND_SIGNALED | IBV_SEND_INLINE);
122  else
123  f_swr[bufid].send_flags = IBV_SEND_SIGNALED;
124 
125  return &(f_swr[bufid]);
126 }
127 
129 {
130  return (char*)GetBufferLocation(bufid) + fSendBufferOffset;
131 }
#define VERBS_MAX_INLINE
Definition: QueuePair.h:17
#define VERBS_UD_MEMADDON
Definition: QueuePair.h:20
unsigned NumReferences()
Return number of references on the object.
Definition: Object.cxx:557
const char * GetName() const
Returns name of the object, thread safe
Definition: Object.h:295
void Destroy()
Release reference and starts destroyment of referenced object.
Definition: Reference.cxx:148
Reference to verbs::Context
Definition: Context.h:74
struct ibv_send_wr * GetSendWR(unsigned id, uint64_t size)
Definition: MemoryPool.cxx:103
void * GetSendBufferLocation(unsigned id)
Definition: MemoryPool.cxx:128
PoolRegistryRef fReg
Definition: MemoryPool.h:35
MemoryPool(ContextRef ctx, const char *name, int32_t number, int64_t bufsize, bool isud, bool without_wr=false)
Definition: MemoryPool.cxx:20
struct ibv_recv_wr * GetRecvWR(unsigned id)
Definition: MemoryPool.cxx:85
virtual ~MemoryPool()
Definition: MemoryPool.cxx:71
struct ibv_recv_wr * f_rwr
Definition: MemoryPool.h:36
struct ibv_sge * f_sge
Definition: MemoryPool.h:38
struct ibv_send_wr * f_swr
Definition: MemoryPool.h:37
#define DOUT4(args ...)
Definition: logging.h:182
Event manipulation API.
Definition: api.h:23