Commit ed7e420e authored by Samuel Debionne's avatar Samuel Debionne
Browse files

Merge branch 'check_data_xfer_state' into 'master'

Check data Xfer state

Closes #21

See merge request !12
parents 04d7c71f d7952daa
Pipeline #28047 failed with stages
in 15 minutes and 53 seconds
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "SlsDetectorArgs.h" #include "SlsDetectorArgs.h"
#include "SlsDetectorReceiver.h" #include "SlsDetectorReceiver.h"
#include "SlsDetectorCPUAffinity.h" #include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorBebTools.h"
#include "slsDetectorUsers.h" #include "slsDetectorUsers.h"
...@@ -172,6 +173,13 @@ private: ...@@ -172,6 +173,13 @@ private:
typedef std::queue<int> FrameQueue; typedef std::queue<int> FrameQueue;
typedef std::vector<AutoPtr<Receiver> > RecvList; typedef std::vector<AutoPtr<Receiver> > RecvList;
struct Beb {
BebShell shell;
BebFpgaMem fpga_mem;
Beb(const std::string& host_name);
};
typedef std::vector<AutoPtr<Beb> > BebList;
struct AppInputData struct AppInputData
{ {
DEB_CLASS_NAMESPC(DebModCamera, "Camera::AppInputData", DEB_CLASS_NAMESPC(DebModCamera, "Camera::AppInputData",
...@@ -289,6 +297,7 @@ private: ...@@ -289,6 +297,7 @@ private:
Cond m_cond; Cond m_cond;
AutoPtr<AppInputData> m_input_data; AutoPtr<AppInputData> m_input_data;
AutoPtr<slsDetectorUsers> m_det; AutoPtr<slsDetectorUsers> m_det;
BebList m_beb_list;
FrameMap m_frame_map; FrameMap m_frame_map;
RecvList m_recv_list; RecvList m_recv_list;
TrigMode m_trig_mode; TrigMode m_trig_mode;
......
...@@ -47,6 +47,8 @@ class Eiger : public Model ...@@ -47,6 +47,8 @@ class Eiger : public Model
typedef unsigned short Word; typedef unsigned short Word;
typedef unsigned int Long; typedef unsigned int Long;
typedef std::vector<unsigned long> PtrDiffList;
typedef Defs::ClockDiv ClockDiv; typedef Defs::ClockDiv ClockDiv;
enum ParallelMode { enum ParallelMode {
...@@ -265,6 +267,10 @@ class Eiger : public Model ...@@ -265,6 +267,10 @@ class Eiger : public Model
Geometry *getGeometry() Geometry *getGeometry()
{ return &m_geom; } { return &m_geom; }
void getFpgaFramePtrDiff(PtrDiffList& ptr_diff);
virtual bool isXferActive();
protected: protected:
virtual int getNbFrameMapItems(); virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map); virtual void updateFrameMapItems(FrameMap *map);
...@@ -608,6 +614,10 @@ class Eiger : public Model ...@@ -608,6 +614,10 @@ class Eiger : public Model
static const LinScale ChipXfer2Buff; static const LinScale ChipXfer2Buff;
static const LinScale ChipRealReadout; static const LinScale ChipRealReadout;
static const unsigned long BebFpgaWritePtrAddr;
static const unsigned long BebFpgaReadPtrAddr;
static const unsigned long BebFpgaPtrRange;
Geometry m_geom; Geometry m_geom;
CorrList m_corr_list; CorrList m_corr_list;
RecvList m_recv_list; RecvList m_recv_list;
......
...@@ -93,6 +93,8 @@ class Model ...@@ -93,6 +93,8 @@ class Model
virtual void processBadItemFrame(FrameType frame, int item, virtual void processBadItemFrame(FrameType frame, int item,
char *bptr) = 0; char *bptr) = 0;
virtual bool isXferActive() = 0;
protected: protected:
void updateCameraModel(); void updateCameraModel();
void updateTimeRanges(); void updateTimeRanges();
......
...@@ -93,6 +93,10 @@ class Eiger : public SlsDetector::Model ...@@ -93,6 +93,10 @@ class Eiger : public SlsDetector::Model
void setTxFrameDelay(int tx_frame_delay); void setTxFrameDelay(int tx_frame_delay);
void getTxFrameDelay(int& tx_frame_delay /Out/); void getTxFrameDelay(int& tx_frame_delay /Out/);
void getFpgaFramePtrDiff(std::vector<unsigned long>& ptr_diff /Out/);
virtual bool isXferActive();
protected: protected:
virtual int getNbFrameMapItems(); virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map); virtual void updateFrameMapItems(FrameMap *map);
......
...@@ -72,6 +72,8 @@ public: ...@@ -72,6 +72,8 @@ public:
virtual void processBadItemFrame(unsigned long frame, int item, virtual void processBadItemFrame(unsigned long frame, int item,
char *bptr) = 0; char *bptr) = 0;
virtual bool isXferActive() = 0;
protected: protected:
void updateCameraModel(); void updateCameraModel();
......
...@@ -84,6 +84,11 @@ void Camera::AppInputData::parseConfigFile() ...@@ -84,6 +84,11 @@ void Camera::AppInputData::parseConfigFile()
} }
} }
Camera::Beb::Beb(const std::string& host_name)
: shell(host_name), fpga_mem(shell)
{
}
Camera::AcqThread::ExceptionCleanUp::ExceptionCleanUp(AcqThread& thread) Camera::AcqThread::ExceptionCleanUp::ExceptionCleanUp(AcqThread& thread)
: Thread::ExceptionCleanUp(thread) : Thread::ExceptionCleanUp(thread)
{ {
...@@ -275,7 +280,10 @@ void Camera::AcqThread::stopAcq() ...@@ -275,7 +280,10 @@ void Camera::AcqThread::stopAcq()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
slsDetectorUsers *det = m_cam->m_det; slsDetectorUsers *det = m_cam->m_det;
if (m_cam->getDetStatus() == Defs::Running) { DetStatus det_status = m_cam->getDetStatus();
bool xfer_active = m_cam->m_model->isXferActive();
DEB_ALWAYS() << DEB_VAR2(det_status, xfer_active);
if ((det_status == Defs::Running) || xfer_active) {
DEB_TRACE() << "calling stopAcquisition"; DEB_TRACE() << "calling stopAcquisition";
det->stopAcquisition(); det->stopAcquisition();
Timestamp t0 = Timestamp::now(); Timestamp t0 = Timestamp::now();
...@@ -355,6 +363,12 @@ Camera::Camera(string config_fname, int det_id) ...@@ -355,6 +363,12 @@ Camera::Camera(string config_fname, int det_id)
DEB_TRACE() << "Forcing 10G Ethernet flow control"; DEB_TRACE() << "Forcing 10G Ethernet flow control";
setFlowControl10G(true); setFlowControl10G(true);
} }
for (int i = 0; i < getNbDetModules(); ++i) {
const string& host_name = m_input_data->host_name_list[i];
Beb *beb = new Beb(host_name);
m_beb_list.push_back(beb);
}
} }
Camera::~Camera() Camera::~Camera()
...@@ -664,7 +678,7 @@ void Camera::setRecvCPUAffinity(const RecvCPUAffinityList& recv_affinity_list) ...@@ -664,7 +678,7 @@ void Camera::setRecvCPUAffinity(const RecvCPUAffinityList& recv_affinity_list)
RecvCPUAffinityList::const_iterator ait = recv_affinity_list.begin(); RecvCPUAffinityList::const_iterator ait = recv_affinity_list.begin();
RecvList::iterator rit = m_recv_list.begin(); RecvList::iterator rit = m_recv_list.begin();
for (int i = 0; i < nb_recv; ++i, ++ait, ++rit) { for (unsigned int i = 0; i < nb_recv; ++i, ++ait, ++rit) {
Model::Recv *recv = m_model->getRecv(i); Model::Recv *recv = m_model->getRecv(i);
const RecvCPUAffinity& aff = *ait; const RecvCPUAffinity& aff = *ait;
recv->setNbProcessingThreads(aff.recv_threads.size()); recv->setNbProcessingThreads(aff.recv_threads.size());
......
...@@ -43,6 +43,10 @@ const double Eiger::MaxFebBebBandwidth = 25600; // Mbit/s ...@@ -43,6 +43,10 @@ const double Eiger::MaxFebBebBandwidth = 25600; // Mbit/s
const Eiger::LinScale Eiger::ChipXfer2Buff(2.59, 0.85); const Eiger::LinScale Eiger::ChipXfer2Buff(2.59, 0.85);
const Eiger::LinScale Eiger::ChipRealReadout(1.074, -4); const Eiger::LinScale Eiger::ChipRealReadout(1.074, -4);
const unsigned long Eiger::BebFpgaWritePtrAddr = 0xD10000C4;
const unsigned long Eiger::BebFpgaReadPtrAddr = 0xD10000E4;
const unsigned long Eiger::BebFpgaPtrRange = 0x10000000;
Eiger::CorrBase::CorrBase(Eiger *eiger) Eiger::CorrBase::CorrBase(Eiger *eiger)
: m_eiger(eiger) : m_eiger(eiger)
{ {
...@@ -1474,6 +1478,35 @@ double Eiger::getBorderCorrFactor(int det, int line) ...@@ -1474,6 +1478,35 @@ double Eiger::getBorderCorrFactor(int det, int line)
} }
} }
void Eiger::getFpgaFramePtrDiff(PtrDiffList& ptr_diff)
{
DEB_MEMBER_FUNCT();
Camera::BebList& beb_list = getCamera()->m_beb_list;
for (int i = 0; i != beb_list.size(); ++i) {
BebFpgaMem& fpga_mem = beb_list[i]->fpga_mem;
unsigned long wr_ptr = fpga_mem.read(BebFpgaWritePtrAddr);
unsigned long rd_ptr = fpga_mem.read(BebFpgaReadPtrAddr);
if (rd_ptr > wr_ptr)
wr_ptr += BebFpgaPtrRange;
unsigned long diff = wr_ptr - rd_ptr;
DEB_RETURN() << DEB_VAR2(i, diff);
ptr_diff.push_back(diff);
}
}
bool Eiger::isXferActive()
{
DEB_MEMBER_FUNCT();
PtrDiffList ptr_diff;
getFpgaFramePtrDiff(ptr_diff);
PtrDiffList::const_iterator it, end = ptr_diff.end();
bool xfer_active = false;
for (it = ptr_diff.begin(); (it != end) && !xfer_active; ++it)
xfer_active = (*it != 0);
DEB_RETURN() << DEB_VAR1(xfer_active);
return xfer_active;
}
ostream& lima::SlsDetector::operator <<(ostream& os, Eiger::ParallelMode mode) ostream& lima::SlsDetector::operator <<(ostream& os, Eiger::ParallelMode mode)
{ {
const char *name = "Invalid"; const char *name = "Invalid";
......
...@@ -88,6 +88,7 @@ class SlsDetector(PyTango.Device_4Impl): ...@@ -88,6 +88,7 @@ class SlsDetector(PyTango.Device_4Impl):
'fixed_clock_div', 'fixed_clock_div',
'threshold_energy', 'threshold_energy',
'tx_frame_delay', 'tx_frame_delay',
'fpga_frame_ptr_diff',
] ]
def __init__(self,*args) : def __init__(self,*args) :
...@@ -662,6 +663,10 @@ class SlsDetectorClass(PyTango.DeviceClass): ...@@ -662,6 +663,10 @@ class SlsDetectorClass(PyTango.DeviceClass):
[[PyTango.DevLong, [[PyTango.DevLong,
PyTango.SCALAR, PyTango.SCALAR,
PyTango.READ_WRITE]], PyTango.READ_WRITE]],
'fpga_frame_ptr_diff':
[[PyTango.DevULong,
PyTango.SPECTRUM,
PyTango.READ, 64]],
} }
def __init__(self,name) : def __init__(self,name) :
......
import sys
import time
import contextlib
import numpy as np
from PyTango import DeviceProxy
dev_name = 'id00/slsdetector/eiger500k'
if len(sys.argv) > 1:
dev_name = sys.argv[1]
eiger_dev = DeviceProxy(dev_name)
data = []
ref = eiger_dev.fpga_frame_ptr_diff
nb_hosts = len(ref)
zeros = np.zeros((nb_hosts,), 'uint32')
if (ref != zeros).any():
raise RuntimeError(f'Invalid reference: {ref}')
max_val = np.array(zeros)
max_i = np.array(zeros)
t0 = None
print('Ready')
while True:
i = len(data)
d = eiger_dev.fpga_frame_ptr_diff
d > max_val
if (d != ref).all():
t = time.time()
if t0 is None:
t0 = t
print('Starting')
data.append(((t - t0), d))
elif i > 0:
break
elapsed = time.time() - t0
print(f'Finished: {elapsed:.3f} sec, {len(data)} points')
ofname = '/tmp/fpga_frame_ptr_diff.dat'
with contextlib.closing(open(ofname, 'wt')) as f:
for t0, d in data:
f.write('\t'.join([str(x) for x in [t0] + list(d)]) + '\n')
print(f'Saved {ofname}')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment