w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
Rw11Rdma.cpp
Go to the documentation of this file.
1// $Id: Rw11Rdma.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2015-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-02-23 1114 1.1.5 use std::bind instead of lambda
8// 2018-12-19 1090 1.1.4 use RosPrintf(bool)
9// 2018-12-15 1083 1.1.3 for std::function setups: use rval ref and move
10// 2018-12-15 1082 1.1.2 use lambda instead of boost::bind
11// 2017-04-02 865 1.1.1 Dump(): add detail arg
12// 2015-02-17 647 1.1 PreExecCB with nwdone and nwnext
13// 2015-01-04 627 1.0 Initial version
14// ---------------------------------------------------------------------------
15
20#include <algorithm>
21#include <functional>
22
24#include "librtools/RosFill.hpp"
27
28#include "Rw11Rdma.hpp"
29
30using namespace std;
31
37// all method definitions in namespace Retro
38namespace Retro {
39
40//------------------------------------------+-----------------------------------
42
43Rw11Rdma::Rw11Rdma(Rw11Cntl* pcntl, precb_t&& precb, postcb_t&& postcb)
44 : fpCntlBase(pcntl),
45 fPreExecCB(move(precb)),
46 fPostExecCB(move(postcb)),
47 fChunksize(0),
48 fStatus(kStatusDone),
49 fIsWMem(false),
50 fAddr(0),
51 fMode(0),
52 fNWordMax(0),
53 fNWordRest(0),
54 fNWordDone(0),
55 fpBlock(nullptr),
56 fStats()
57{
58 fStats.Define(kStatNQueRMem, "NQueRMem" , "RMem chains queued");
59 fStats.Define(kStatNQueWMem, "NQueWMem" , "WMem chains queued");
60 fStats.Define(kStatNRdmaRMem, "NRdmaRMem" , "RMem chunks done");
61 fStats.Define(kStatNRdmaWMem, "NRdmaWMem" , "WMem chunks done");
62 fStats.Define(kStatNExtClist, "NExtClist" , "clist extended");
63 fStats.Define(kStatNFailRdma, "NFailRdma" , "Rdma failures");
64}
65
66//------------------------------------------+-----------------------------------
68
70{}
71
72//------------------------------------------+-----------------------------------
74
75void Rw11Rdma::SetChunkSize(size_t chunk)
76{
77 size_t cmax = CntlBase().IsStarted() ? Connect().BlockSizePrudent() : 0;
78 if (chunk==0 || chunk>cmax) chunk = cmax;
79 fChunksize = chunk;
80 return;
81}
82
83//------------------------------------------+-----------------------------------
85
86void Rw11Rdma::QueueRMem(uint32_t addr, uint16_t* block, size_t size,
87 uint16_t mode)
88{
90 SetupRdma(false, addr, block, size, mode);
92 return;
93}
94
95//------------------------------------------+-----------------------------------
97
98void Rw11Rdma::QueueWMem(uint32_t addr, const uint16_t* block, size_t size,
99 uint16_t mode)
100{
102 SetupRdma(true, addr, const_cast<uint16_t*>(block), size, mode);
104 return;
105}
106
107//------------------------------------------+-----------------------------------
109
110void Rw11Rdma::Dump(std::ostream& os, int ind, const char* text,
111 int detail) const
112{
113 RosFill bl(ind);
114 os << bl << (text?text:"--") << "Rw11Rdma @ " << this << endl;
115
116 os << bl << " fChunkSize: " << RosPrintf(fChunksize,"d",4) << endl;
117 os << bl << " fStatus: " << fStatus << endl;
118 os << bl << " fIsWMem: " << RosPrintf(fIsWMem) << endl;
119 os << bl << " fAddr: " << RosPrintBvi(fAddr,8,22) << endl;
120 os << bl << " fMode: " << RosPrintBvi(fAddr,16,16) << endl;
121 os << bl << " fNWordMax: " << RosPrintf(fNWordMax,"d",4) << endl;
122 os << bl << " fNWordRest: " << RosPrintf(fNWordRest,"d",4) << endl;
123 os << bl << " fNWordDone: " << RosPrintf(fNWordDone,"d",4) << endl;
124 os << bl << " fpBlock: " << fpBlock << endl;
125 fStats.Dump(os, ind+2, "fStats: ", detail-1);
126 return;
127}
128
129//------------------------------------------+-----------------------------------
131
132void Rw11Rdma::SetupRdma(bool iswmem, uint32_t addr, uint16_t* block,
133 size_t size, uint16_t mode)
134{
135 if (IsActive())
136 throw Rexception("Rw11Rdma::SetupRdma", "Bad state: Rdma already active");
137
138 // if chunk size not yet defined use 'maximal prudent size from Connect
139 // Note: can't be done in ctor because linkage to Connect is set much
140 // later in Cntl::Start
142
144 fIsWMem = iswmem;
145 fAddr = addr;
146 fMode = mode;
148 fNWordRest = size;
149 fNWordDone = 0;
150 fpBlock = block;
151 return;
152}
153
154//------------------------------------------+-----------------------------------
156
158{
159 RlinkCommandList clist;
160
161 if (fNWordDone == 0) { // first chunk ?
162 PreRdmaHook();
163 }
164
165 size_t nwnext = min(fNWordRest, fNWordMax);
166 if (fIsWMem) {
168 Cpu().AddWMem(clist, fAddr, fpBlock, nwnext, fMode, true);
169 } else {
171 Cpu().AddRMem(clist, fAddr, fpBlock, nwnext, fMode, true);
172 }
173 size_t ncmd = clist.Size();
174
175 if (nwnext == fNWordRest) fStatus = kStatusBusyLast;
176
177 fPreExecCB(fStatus, fNWordDone, nwnext, clist);
178 if (clist.Size() != ncmd) fStats.Inc(kStatNExtClist);
179
180 Server().Exec(clist);
181
182 size_t nwdone = clist[ncmd-1].BlockDone();
183
184 fAddr += 2*nwdone;
185 fNWordRest -= nwdone;
186 fNWordDone += nwdone;
187 fpBlock += nwdone;
188
189 bool islast = false;
190 if (nwnext != nwdone) {
193 islast = true;
194 } else if (fNWordRest == 0) {
196 islast = true;
197 }
198
199 if (islast) {
201 }
202
203 fPostExecCB(fStatus, fNWordDone, clist, ncmd);
204
205 if (fStatus == kStatusBusy) {
206 return 1;
207 }
209 return 0;
210}
211
212//------------------------------------------+-----------------------------------
214
216{
217 return;
218}
219
220//------------------------------------------+-----------------------------------
222
223void Rw11Rdma::PostRdmaHook(size_t /*nwdone*/)
224{
225 return;
226}
227
228
229} // end namespace Retro
FIXME_docs.
Definition: Rexception.hpp:29
size_t Size() const
FIXME_docs.
size_t BlockSizePrudent() const
FIXME_docs.
void QueueAction(actnhdl_t &&actnhdl)
FIXME_docs.
bool Exec(RlinkCommandList &clist, RerrMsg &emsg)
FIXME_docs.
Definition: RlinkServer.ipp:60
I/O appicator to generate fill characters.
Definition: RosFill.hpp:24
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rstats.cpp:178
void Inc(size_t ind, double val=1.)
FIXME_docs.
Definition: Rstats.ipp:29
void Define(size_t ind, const std::string &name, const std::string &text)
FIXME_docs.
Definition: Rstats.cpp:72
FIXME_docs.
Definition: Rw11Cntl.hpp:42
bool IsStarted() const
FIXME_docs.
Definition: Rw11Cntl.ipp:144
int AddWMem(RlinkCommandList &clist, uint32_t addr, const uint16_t *buf, size_t size, uint16_t mode=kCPAH_M_22BIT, bool singleblk=false)
FIXME_docs.
Definition: Rw11Cpu.cpp:469
int AddRMem(RlinkCommandList &clist, uint32_t addr, uint16_t *buf, size_t size, uint16_t mode=kCPAH_M_22BIT, bool singleblk=false)
FIXME_docs.
Definition: Rw11Cpu.cpp:448
int RdmaHandler()
FIXME_docs.
Definition: Rw11Rdma.cpp:157
virtual void PostRdmaHook(size_t nwdone)
FIXME_docs.
Definition: Rw11Rdma.cpp:223
virtual ~Rw11Rdma()
Destructor.
Definition: Rw11Rdma.cpp:69
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11Rdma.cpp:110
Rw11Cntl & CntlBase() const
FIXME_docs.
Definition: Rw11Rdma.ipp:21
postcb_t fPostExecCB
post Exec callback
Definition: Rw11Rdma.hpp:99
enum status fStatus
dma status
Definition: Rw11Rdma.hpp:101
size_t fNWordRest
words to be done
Definition: Rw11Rdma.hpp:106
void SetupRdma(bool iswmem, uint32_t addr, uint16_t *block, size_t size, uint16_t mode)
FIXME_docs.
Definition: Rw11Rdma.cpp:132
bool IsActive() const
FIXME_docs.
Definition: Rw11Rdma.ipp:77
@ kStatNQueWMem
WMem chains queued.
Definition: Rw11Rdma.hpp:73
@ kStatNExtClist
clist extended
Definition: Rw11Rdma.hpp:76
@ kStatNRdmaWMem
WMem chunks done.
Definition: Rw11Rdma.hpp:75
@ kStatNRdmaRMem
RMem chunks done.
Definition: Rw11Rdma.hpp:74
@ kStatNFailRdma
Rdma failures.
Definition: Rw11Rdma.hpp:77
@ kStatNQueRMem
RMem chains queued.
Definition: Rw11Rdma.hpp:72
Rw11Rdma(Rw11Cntl *pcntl, precb_t &&precb, postcb_t &&postcb)
Constructor.
Definition: Rw11Rdma.cpp:43
std::function< void(int, size_t, RlinkCommandList &, size_t)> postcb_t
Definition: Rw11Rdma.hpp:40
precb_t fPreExecCB
pre Exec callback
Definition: Rw11Rdma.hpp:98
uint32_t fAddr
current mem address
Definition: Rw11Rdma.hpp:103
RlinkServer & Server() const
FIXME_docs.
Definition: Rw11Rdma.ipp:45
@ kStatusBusyLast
last chunk to come
Definition: Rw11Rdma.hpp:85
@ kStatusFailRdma
last rdma transfer failed
Definition: Rw11Rdma.hpp:86
@ kStatusBusy
more chunks to come
Definition: Rw11Rdma.hpp:84
@ kStatusDone
all chunks done and ok
Definition: Rw11Rdma.hpp:83
void QueueWMem(uint32_t addr, const uint16_t *block, size_t size, uint16_t mode)
FIXME_docs.
Definition: Rw11Rdma.cpp:98
bool fIsWMem
is memory write
Definition: Rw11Rdma.hpp:102
uint16_t fMode
current mode
Definition: Rw11Rdma.hpp:104
Rw11Cpu & Cpu() const
FIXME_docs.
Definition: Rw11Rdma.ipp:29
std::function< void(int, size_t, size_t, RlinkCommandList &)> precb_t
Definition: Rw11Rdma.hpp:38
size_t fChunksize
channel chunk size
Definition: Rw11Rdma.hpp:100
void QueueRMem(uint32_t addr, uint16_t *block, size_t size, uint16_t mode)
FIXME_docs.
Definition: Rw11Rdma.cpp:86
size_t fNWordMax
transfer chunk size
Definition: Rw11Rdma.hpp:105
void SetChunkSize(size_t chunk)
FIXME_docs.
Definition: Rw11Rdma.cpp:75
virtual void PreRdmaHook()
FIXME_docs.
Definition: Rw11Rdma.cpp:215
Rstats fStats
statistics
Definition: Rw11Rdma.hpp:109
uint16_t * fpBlock
current buffer pointer
Definition: Rw11Rdma.hpp:108
size_t fNWordDone
words transfered
Definition: Rw11Rdma.hpp:107
RlinkConnect & Connect() const
FIXME_docs.
Definition: Rw11Rdma.ipp:53
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47