GitLab will be upgraded on June 23th evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit b4bee62b authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

[WIP] Use packet FifoDepth instead of aux. AcqBuffer

* Allocate per-thread buffer for raw data
  in Jungfrau GainPedCorr ImgSrc
parent 7d6bdb71
Pipeline #46226 failed with stages
in 7 minutes and 42 seconds
......@@ -33,56 +33,40 @@ namespace lima
namespace SlsDetector
{
enum BufferType {
AcqBuffer, LimaBuffer
};
inline Data GetMappedData(void *buffer, const FrameDim& frame_dim)
{
Data d;
switch (frame_dim.getImageType()) {
case Bpp8: d.type = Data::UINT8; break;
case Bpp16: d.type = Data::UINT16; break;
case Bpp32: d.type = Data::UINT32; break;
default: throw LIMA_HW_EXC(Error, "Invalid image type");
}
const Size& size = frame_dim.getSize();
d.dimensions = {size.getWidth(), size.getHeight()};
Buffer *b = new Buffer;
b->owner = Buffer::MAPPED;
b->data = buffer;
d.setBuffer(b);
b->unref();
return d;
}
class BufferCtrlObj : public NumaSoftBufferCtrlObj {
public:
BufferCtrlObj() : m_type(AcqBuffer) {}
void releaseBuffers() { getBuffer().releaseBuffers(); }
void setType(BufferType type)
{
if (type == m_type)
return;
releaseBuffers();
m_type = type;
}
virtual void getMaxNbBuffers(int& max_nb_buffers)
{
if (m_type == LimaBuffer)
max_nb_buffers = 1024;
else
NumaSoftBufferCtrlObj::getMaxNbBuffers(max_nb_buffers);
}
{ max_nb_buffers = 1024; }
Data getFrameData(FrameType frame)
{
Data d;
StdBufferCbMgr& buffer = getBuffer();
void *buffer_ptr = buffer.getFrameBufferPtr(frame);
const FrameDim& frame_dim = buffer.getFrameDim();
switch (frame_dim.getImageType()) {
case Bpp8: d.type = Data::UINT8; break;
case Bpp16: d.type = Data::UINT16; break;
case Bpp32: d.type = Data::UINT32; break;
default: throw LIMA_HW_EXC(Error, "Invalid image type");
}
const Size& size = frame_dim.getSize();
d.dimensions = {size.getWidth(), size.getHeight()};
Buffer *b = new Buffer;
b->owner = Buffer::MAPPED;
b->data = buffer.getFrameBufferPtr(frame);;
d.setBuffer(b);
b->unref();
return d;
return GetMappedData(buffer_ptr, frame_dim);
}
private:
BufferType m_type;
};
class BufferMgr
......@@ -90,8 +74,6 @@ class BufferMgr
DEB_CLASS_NAMESPC(DebModCamera, "BufferMgr", "SlsDetector");
public:
enum Mode { Single, Dual };
void setLimaBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj);
void setAcqBufferCPUAffinity(CPUAffinity buffer_affinity);
......@@ -99,16 +81,12 @@ public:
void waitLimaFrame(FrameType frame_nb, AutoMutex& l);
char *getAcqFrameBufferPtr(FrameType frame_nb);
BufferCtrlObj *getBufferCtrlObj(BufferType type)
{
bool lima = ((type == LimaBuffer) || (m_mode == Single));
return lima ? m_lima_buffer_ctrl_obj :
m_acq_buffer_ctrl_obj.getPtr();
}
BufferCtrlObj *getBufferCtrlObj()
{ return m_lima_buffer_ctrl_obj; }
StdBufferCbMgr *getBufferCbMgr(BufferType type)
StdBufferCbMgr *getBufferCbMgr()
{
BufferCtrlObj *buffer = getBufferCtrlObj(type);
BufferCtrlObj *buffer = getBufferCtrlObj();
return buffer ? &buffer->getBuffer() : NULL;
}
......@@ -117,9 +95,6 @@ public:
void getMaxNbBuffers(long& nb_buffers);
void setMode(Mode mode);
void getMode(Mode& mode);
void prepareAcq();
void clearAllBuffers();
......@@ -133,11 +108,9 @@ private:
Camera *m_cam;
Cond& m_cond;
Mode m_mode;
CPUAffinity m_buffer_affinity;
BufferCtrlObj *m_lima_buffer_ctrl_obj;
BufferSync *m_lima_buffer_sync;
AutoPtr<BufferCtrlObj> m_acq_buffer_ctrl_obj;
int m_max_memory;
};
......
......@@ -228,6 +228,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq();
virtual void clear();
virtual bool consumesRawData() = 0;
virtual void processFrame(Data& data) = 0;
protected:
......@@ -347,6 +348,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw);
virtual void clear();
virtual bool consumesRawData() { return true; }
virtual void processFrame(Data& data);
void readGainADCMaps(Data& gain_map, Data& adc_map,
......@@ -387,6 +389,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw);
virtual void clear();
virtual bool consumesRawData() { return true; }
virtual void processFrame(Data& data);
void readProcMap(Data& proc_map, FrameType& frame);
......@@ -421,6 +424,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw);
virtual void clear();
virtual bool consumesRawData() { return false; }
virtual void processFrame(Data& data);
void readAveMap(Data& ave_map, FrameType& nb_frames,
......@@ -523,13 +527,7 @@ class Jungfrau : public Model
void doSetImgProcConfig(std::string config, bool force);
Data getRawData(Data& data)
{
if (m_img_src == Raw)
return data;
BufferMgr *buffer_mgr = getBuffer();
BufferCtrlObj *buffer = buffer_mgr->getBufferCtrlObj(AcqBuffer);
return buffer->getFrameData(data.frameNumber);
}
{ return m_reconstruction->getRawData(data); }
int getNbJungfrauModules()
{ return getNbDetModules(); }
......
......@@ -96,8 +96,6 @@ class Model
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
char *getAcqFrameBufferPtr(FrameType frame_nb);
virtual bool checkSettings(Settings settings) = 0;
virtual void prepareAcq() = 0;
......
......@@ -60,26 +60,42 @@ public:
Reconstruction *m_r;
};
enum LimaBufferMode { RawData, CorrData };
Reconstruction(Camera *cam);
virtual ~Reconstruction();
void setActive(bool active);
void getActive(bool& active);
void setLimaBufferMode(LimaBufferMode lima_buffer_mode);
void getLimaBufferMode(LimaBufferMode& lima_buffer_mode);
virtual void prepare();
void addFramePackets(DetFrameImagePackets&& det_frame_packets);
Data getRawData(Data& data);
virtual Data process(Data& data);
virtual Data processModel(Data& data) = 0;
virtual void cleanUp();
private:
struct ThreadData {
void *ptr;
long size;
};
static void releaseThreadData(void *thread_data);
friend class CtrlObjProxy;
Camera *m_cam;
CtrlObjProxy *m_proxy;
bool m_active;
LimaBufferMode m_lima_buffer_mode;
FrameDim m_raw_frame_dim;
Mutex m_mutex;
FramePacketMap m_frame_packet_map;
};
......
......@@ -30,11 +30,6 @@ namespace SlsDetector
class BufferMgr
{
public:
enum Mode { Single, Dual };
void setMode(SlsDetector::BufferMgr::Mode mode);
void getMode(SlsDetector::BufferMgr::Mode& mode /Out/);
void setMaxMemory(short max_memory);
void getMaxMemory(short& max_memory /Out/);
......
......@@ -79,8 +79,6 @@ protected:
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
char *getAcqFrameBufferPtr(unsigned long frame_nb);
virtual
bool checkSettings(SlsDetector::Defs::Settings settings) = 0;
......
......@@ -28,56 +28,12 @@ using namespace lima::SlsDetector;
BufferMgr::BufferMgr(Camera *cam)
: m_cam(cam), m_cond(m_cam->m_cond), m_mode(Single),
m_lima_buffer_ctrl_obj(NULL),
: m_cam(cam), m_cond(m_cam->m_cond), m_lima_buffer_ctrl_obj(NULL),
m_max_memory(70)
{
DEB_CONSTRUCTOR();
}
void BufferMgr::setMode(Mode mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(mode, m_mode);
if (mode == m_mode)
return;
m_mode = mode;
m_acq_buffer_ctrl_obj = (m_mode == Dual) ? new BufferCtrlObj() : NULL;
DEB_TRACE() << DEB_VAR2(m_lima_buffer_ctrl_obj, m_acq_buffer_ctrl_obj);
BufferCtrlObj *buffer;
buffer = getBufferCtrlObj(AcqBuffer);
if (buffer) {
buffer->setType(AcqBuffer);
buffer->setCPUAffinityMask(m_buffer_affinity);
}
buffer = getBufferCtrlObj(LimaBuffer);
if (buffer && (m_mode == Dual)) {
buffer->setType(LimaBuffer);
buffer->setCPUAffinityMask(CPUAffinity());
}
Model *model = m_cam->m_model;
if (!model)
return;
if (m_acq_buffer_ctrl_obj) {
FrameDim frame_dim;
model->getAcqFrameDim(frame_dim, m_cam->m_raw_mode);
m_acq_buffer_ctrl_obj->setFrameDim(frame_dim);
}
m_cam->updateImageSize();
}
void BufferMgr::getMode(Mode& mode)
{
DEB_MEMBER_FUNCT();
mode = m_mode;
DEB_RETURN() << DEB_VAR1(mode);
}
void BufferMgr::setLimaBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj)
{
DEB_MEMBER_FUNCT();
......@@ -110,7 +66,7 @@ char *BufferMgr::getAcqFrameBufferPtr(FrameType frame_nb)
{
DEB_MEMBER_FUNCT();
StdBufferCbMgr *cb_mgr = getBufferCbMgr(AcqBuffer);
StdBufferCbMgr *cb_mgr = getBufferCbMgr();
if (!cb_mgr)
THROW_HW_ERROR(InvalidValue) << "No BufferCbMgr defined";
void *ptr = cb_mgr->getFrameBufferPtr(frame_nb);
......@@ -121,7 +77,7 @@ void BufferMgr::setAcqBufferCPUAffinity(CPUAffinity buffer_affinity)
{
DEB_MEMBER_FUNCT();
DEB_ALWAYS() << DEB_VAR1(buffer_affinity);
BufferCtrlObj *buffer = getBufferCtrlObj(AcqBuffer);
BufferCtrlObj *buffer = getBufferCtrlObj();
if (buffer)
buffer->setCPUAffinityMask(buffer_affinity);
m_buffer_affinity = buffer_affinity;
......@@ -146,14 +102,14 @@ void BufferMgr::getMaxMemory(short& max_memory)
void BufferMgr::getMaxNbBuffers(long& nb_buffers)
{
DEB_MEMBER_FUNCT();
if (m_acq_buffer_ctrl_obj) {
int max_nb_buffers;
m_acq_buffer_ctrl_obj->getMaxNbBuffers(max_nb_buffers);
nb_buffers = int(max_nb_buffers * m_max_memory / 100.0);
DEB_TRACE() << DEB_VAR2(max_nb_buffers, nb_buffers);
} else {
nb_buffers = 0;
}
bool raw_mode;
m_cam->getRawMode(raw_mode);
FrameDim frame_dim;
Model *model = m_cam->getModel();
model->getAcqFrameDim(frame_dim, raw_mode);
int max_nb_buffers = GetDefMaxNbBuffers(frame_dim);
nb_buffers = int(max_nb_buffers * m_max_memory / 100.0);
DEB_TRACE() << DEB_VAR2(max_nb_buffers, nb_buffers);
DEB_RETURN() << DEB_VAR1(nb_buffers);
}
......@@ -161,16 +117,16 @@ void BufferMgr::prepareAcq()
{
DEB_MEMBER_FUNCT();
if (m_acq_buffer_ctrl_obj) {
FrameType nb_frames;
m_cam->getNbFrames(nb_frames);
long max_nb_buffers;
getMaxNbBuffers(max_nb_buffers);
int nb_buffers = (nb_frames < max_nb_buffers) ? nb_frames :
max_nb_buffers;
m_acq_buffer_ctrl_obj->setNbBuffers(nb_buffers);
}
FrameType nb_frames;
m_cam->getNbFrames(nb_frames);
long max_nb_buffers;
getMaxNbBuffers(max_nb_buffers);
int nb_buffers = (nb_frames < max_nb_buffers) ? nb_frames :
max_nb_buffers;
const int min_nb_buffers = 128;
if (nb_buffers < min_nb_buffers)
nb_buffers = min_nb_buffers;
m_cam->setReceiverFifoDepth(nb_buffers);
}
void BufferMgr::releaseBuffers()
......@@ -179,8 +135,6 @@ void BufferMgr::releaseBuffers()
bool prev_release_unused;
// BufferCtrlObj::getBufferMgrResizePolicy(prev_release_unused);
// BufferCtrlObj::setBufferMgrResizePolicy(true);
if (m_acq_buffer_ctrl_obj)
m_acq_buffer_ctrl_obj->releaseBuffers();
if (m_lima_buffer_ctrl_obj)
m_lima_buffer_ctrl_obj->releaseBuffers();
// BufferCtrlObj::setBufferMgrResizePolicy(prev_release_unused);
......@@ -189,13 +143,9 @@ void BufferMgr::releaseBuffers()
void BufferMgr::clearAllBuffers()
{
DEB_MEMBER_FUNCT();
StdBufferCbMgr *buffer;
buffer = getBufferCbMgr(AcqBuffer);
StdBufferCbMgr *buffer = getBufferCbMgr();
if (buffer)
buffer->clearAllBuffers();
buffer = getBufferCbMgr(LimaBuffer);
if (buffer && (m_mode == Dual))
buffer->clearAllBuffers();
Camera::RecvList::iterator it, end = m_cam->m_recv_list.end();
for (it = m_cam->m_recv_list.begin(); it != end; ++it)
......
......@@ -153,7 +153,7 @@ Camera::AcqThread::Status Camera::AcqThread::newFrameReady(FrameType frame)
DEB_MEMBER_FUNCT();
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame;
StdBufferCbMgr *cb_mgr = m_cam->m_buffer.getBufferCbMgr(LimaBuffer);
StdBufferCbMgr *cb_mgr = m_cam->m_buffer.getBufferCbMgr();
bool cont_acq = cb_mgr->newFrameReady(frame_info);
bool acq_end = (frame == m_cam->m_lima_nb_frames - 1);
cont_acq &= !acq_end;
......@@ -409,7 +409,7 @@ Camera::Camera(string config_fname, int det_id)
EXC_CHECK(m_det->setRxSilentMode(1));
EXC_CHECK(m_det->setRxFrameDiscardPolicy(
slsDetectorDefs::DISCARD_PARTIAL_FRAMES));
setReceiverFifoDepth(16);
setReceiverFifoDepth(128);
sls::Result<int> dr_res;
EXC_CHECK(dr_res = m_det->getDynamicRange());
......@@ -880,11 +880,9 @@ void Camera::prepareAcq()
{
DEB_MEMBER_FUNCT();
StdBufferCbMgr *cb_mgr = m_buffer.getBufferCbMgr(AcqBuffer);
StdBufferCbMgr *cb_mgr = m_buffer.getBufferCbMgr();
if (!cb_mgr)
THROW_HW_ERROR(Error) << "No Acq BufferCbMgr defined";
else if (!m_buffer.getBufferCbMgr(LimaBuffer))
THROW_HW_ERROR(Error) << "No Lima BufferCbMgr defined";
if (!m_model)
THROW_HW_ERROR(Error) << "No Model defined";
......@@ -941,7 +939,7 @@ void Camera::startAcq()
if (m_acq_thread)
THROW_HW_ERROR(Error) << "Must call prepareAcq first";
StdBufferCbMgr *cb_mgr = m_buffer.getBufferCbMgr(LimaBuffer);
StdBufferCbMgr *cb_mgr = m_buffer.getBufferCbMgr();
cb_mgr->setStartTimestamp(Timestamp::now());
m_acq_thread = new AcqThread(this);
......@@ -1004,8 +1002,11 @@ void Camera::assemblePackets(DetFrameImagePackets&& det_frame_packets)
const FrameType& frame = det_frame_packets.first;
DetImagePackets& det_packets = det_frame_packets.second;
char *bptr = m_buffer.getAcqFrameBufferPtr(frame);
Data frame_data = m_buffer.getBufferCtrlObj()->getFrameData(frame);
Reconstruction *reconstruct = m_model->getReconstruction();
Data raw_data = reconstruct->getRawData(frame_data);
char *bptr = (char *) raw_data.data();
int nb_recvs = getNbRecvs();
for (int i = 0; i < nb_recvs; ++i) {
......
......@@ -242,10 +242,13 @@ void Jungfrau::ImgProcTask::process(Data& data)
DEB_PARAM() << DEB_VAR2(data.frameNumber, data.data());
bool img_is_raw = (m_jungfrau->m_img_src == Raw);
ImgProcList& img_proc_list = m_jungfrau->m_img_proc_list;
ImgProcList::iterator it, end = img_proc_list.end();
for (it = img_proc_list.begin(); it != end; ++it)
(*it)->processFrame(data);
if ((*it)->consumesRawData() == img_is_raw)
(*it)->processFrame(data);
}
......@@ -534,10 +537,13 @@ Data Jungfrau::ModelReconstruction::processModel(Data& data)
Data ret = _processingInPlaceFlag ? data : data.copy();
FrameType frame = ret.frameNumber;
BufferMgr *buffer_mgr = m_jungfrau->getBuffer();
BufferCtrlObj *buffer = buffer_mgr->getBufferCtrlObj(AcqBuffer);
Data raw = buffer->getFrameData(frame);
ImgProcList& img_proc_list = m_jungfrau->m_img_proc_list;
ImgProcList::iterator it, end = img_proc_list.end();
for (it = img_proc_list.begin(); it != end; ++it)
if ((*it)->consumesRawData())
(*it)->processFrame(data);
Data raw = m_jungfrau->getRawData(data);
DEB_TRACE() << DEB_VAR1(raw);
GainPed& gain_ped = m_jungfrau->m_gain_ped_img_proc->m_gain_ped;
gain_ped.processFrame(raw, ret);
......@@ -588,15 +594,17 @@ void Jungfrau::setImgSrc(ImgSrc img_src)
return;
m_img_src = img_src;
bool do_proc = (m_img_src == GainPedCorr);
bool do_corr = (m_img_src == GainPedCorr);
doSetImgProcConfig(m_img_proc_config, true);
m_reconstruction->setActive(do_proc);
Reconstruction::LimaBufferMode lbm;
lbm = do_corr ? Reconstruction::CorrData : Reconstruction::RawData;
m_reconstruction->setLimaBufferMode(lbm);
m_reconstruction->setActive(do_corr);
BufferMgr *buffer = getCamera()->getBuffer();
buffer->releaseBuffers();
buffer->setMode(do_proc ? BufferMgr::Dual : BufferMgr::Single);
}
void Jungfrau::getImgSrc(ImgSrc& img_src)
......
......@@ -101,11 +101,6 @@ BufferMgr *Model::getBuffer()
return m_cam->getBuffer();
}
char *Model::getAcqFrameBufferPtr(FrameType frame_nb)
{
return getBuffer()->getAcqFrameBufferPtr(frame_nb);
}
void Model::getAcqFrameDim(FrameDim& frame_dim, bool raw)
{
DEB_MEMBER_FUNCT();
......
......@@ -59,7 +59,8 @@ LinkTask *Reconstruction::CtrlObjProxy::getReconstructionTask()
}
Reconstruction::Reconstruction(Camera *cam)
: m_cam(cam), m_proxy(NULL), m_active(false)
: m_cam(cam), m_proxy(NULL), m_active(false),
m_lima_buffer_mode(RawData)
{
DEB_CONSTRUCTOR();
}
......@@ -76,8 +77,6 @@ void Reconstruction::setActive(bool active)
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(active, m_active);
m_active = active;
if (m_proxy)
m_proxy->reconstructionChange(this);
}
void Reconstruction::getActive(bool& active)
......@@ -87,13 +86,70 @@ void Reconstruction::getActive(bool& active)
DEB_RETURN() << DEB_VAR1(active);
}
void Reconstruction::setLimaBufferMode(LimaBufferMode lima_buffer_mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(lima_buffer_mode, m_lima_buffer_mode);
m_lima_buffer_mode = lima_buffer_mode;
}
void Reconstruction::getLimaBufferMode(LimaBufferMode& lima_buffer_mode)
{
DEB_MEMBER_FUNCT();
lima_buffer_mode = m_lima_buffer_mode;
DEB_RETURN() << DEB_VAR1(lima_buffer_mode);
}
void Reconstruction::prepare()
{
DEB_MEMBER_FUNCT();
Model *model = m_cam->getModel();
if (!model)
THROW_HW_ERROR(Error) << "Camera has no model";
model->getAcqFrameDim(m_raw_frame_dim, m_cam->m_raw_mode);
AutoMutex l(m_mutex);
m_frame_packet_map.clear();
}
Data Reconstruction::getRawData(Data& data)
{
DEB_MEMBER_FUNCT();
if (m_lima_buffer_mode == RawData)
return data;
static pthread_key_t thread_data_key;
EXEC_ONCE(pthread_key_create(&thread_data_key, &releaseThreadData));
ThreadData *d = (ThreadData *) pthread_getspecific(thread_data_key);
if (d == NULL) {
d = new ThreadData();
pthread_setspecific(thread_data_key, d);
d->ptr = NULL;
d->size = 0;
}
long size = m_raw_frame_dim.getMemSize();
if (d->size != size) {
void *p = realloc(d->ptr, size);
if (!p)
THROW_HW_ERROR(Error) << "Cannot re-allocate "
<< size << " bytes";
d->ptr = p;
d->size = size;
}
return GetMappedData(d->ptr, m_raw_frame_dim);
}
void Reconstruction::releaseThreadData(void *thread_data)
{
ThreadData *d = (ThreadData *) thread_data;
free(d->ptr);
delete d;
}
void Reconstruction::cleanUp()
{
DEB_MEMBER_FUNCT();
......
......@@ -549,7 +549,7 @@ class SlsDetectorClass(PyTango.DeviceClass):
"or CPU(<cpu1>[, ..., <cpuN>]) for independent CPU enumeration", []],
'buffer_max_memory':
[PyTango.DevString,
"The maximum memory (percent) for Acq image buffers in Dual mode, "
"The maximum memory (percent) for image packet buffers (Fifo length), "
"similar to LimaCCDs.BufferMaxMemory", []],
}
......
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