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

Add BufferMgr resize policy basic implementation: release_unused

* Attempt to return memory to OS when switching Single/Accumulation mode
parent 4c85e405
Pipeline #41823 passed with stages
in 20 minutes and 36 seconds
......@@ -165,6 +165,7 @@ namespace lima
ThresholdCallback* m_threshold_cb;
int m_last_acc_frame_nb;
bool m_last_continue_flag;
bool m_prev_active_flag;
// --- Methodes for acquisition
void prepare();
......
......@@ -26,6 +26,10 @@
#include "processlib/SinkTaskMgr.h"
#include <algorithm>
#ifdef __unix
#include <malloc.h>
#endif
using std::min;
using std::max;
......@@ -252,7 +256,8 @@ CtAccumulation::CtAccumulation(CtControl &ct) :
m_calc_ready(true),
m_threshold_cb(NULL),
m_last_acc_frame_nb(-1),
m_last_continue_flag(true)
m_last_continue_flag(true),
m_prev_active_flag(false)
{
m_calc_end = new _CalcEndCBK(*this);
m_calc_mgr = new _CalcSaturatedTaskMgr();
......@@ -596,6 +601,12 @@ void CtAccumulation::prepare()
m_last_continue_flag = true;
m_last_acc_frame_nb = -1;
#ifdef __unix
//If leaving Accumulation mode, release allocated memory to OS
if(m_prev_active_flag != m_pars.active)
malloc_trim(0);
#endif
m_prev_active_flag = m_pars.active;
}
/** @brief this is an internal call from CtBuffer in case of accumulation
*/
......
......@@ -258,6 +258,9 @@ void CtBuffer::setup(CtControl *ct)
m_hw_buffer->setFrameDim(fdim);
m_hw_buffer->setNbConcatFrames(concat_nframes);
bool release_unused = (mode == Accumulation);
m_hw_buffer->setBufferMgrResizePolicy(release_unused);
long max_nbuffers;
getMaxNumber(max_nbuffers);
if (hwNbBuffer > max_nbuffers)
......
......@@ -65,6 +65,9 @@ public:
virtual void registerFrameCallback(HwFrameCallback& frame_cb) = 0;
virtual void unregisterFrameCallback(HwFrameCallback& frame_cb) = 0;
static void setBufferMgrResizePolicy(bool release_unused);
static void getBufferMgrResizePolicy(bool& release_unused);
class LIMACORE_API Callback
{
public:
......@@ -75,6 +78,9 @@ public:
};
virtual Callback *getBufferCallback();
protected:
static bool m_release_unused;
};
} // namespace lima
......
......@@ -92,6 +92,8 @@ class LIMACORE_API SoftBufferAllocMgr : public BufferAllocMgr
virtual void *getBufferPtr(int buffer_nb);
static bool m_release_unused;
protected:
typedef std::vector<MemBuffer> BufferList;
typedef BufferList::const_reverse_iterator BufferListCRIt;
......
......@@ -23,6 +23,8 @@
using namespace lima;
bool HwBufferCtrlObj::m_release_unused = false;
HwBufferCtrlObj::HwBufferCtrlObj()
{
DEB_CONSTRUCTOR();
......@@ -33,6 +35,20 @@ HwBufferCtrlObj::~HwBufferCtrlObj()
DEB_DESTRUCTOR();
}
void HwBufferCtrlObj::setBufferMgrResizePolicy(bool release_unused)
{
DEB_STATIC_FUNCT();
DEB_PARAM() << DEB_VAR1(release_unused);
m_release_unused = release_unused;
}
void HwBufferCtrlObj::getBufferMgrResizePolicy(bool& release_unused)
{
DEB_STATIC_FUNCT();
release_unused = m_release_unused;
DEB_RETURN() << DEB_VAR1(release_unused);
}
HwBufferCtrlObj::Callback *HwBufferCtrlObj::getBufferCallback()
{
return NULL;
......
......@@ -59,6 +59,8 @@ void BufferAllocMgr::clearAllBuffers()
* SoftBufferAllocMgr
*******************************************************************/
bool SoftBufferAllocMgr::m_release_unused = false;
SoftBufferAllocMgr::SoftBufferAllocMgr()
: m_allocator(Allocator::defaultAllocator())
{
......@@ -113,8 +115,9 @@ void SoftBufferAllocMgr::allocBuffers(int nb_buffers,
try {
BufferList& bl = m_buffer_list;
bl.resize(nb_buffers, MemBuffer(m_allocator));
if (to_alloc > 0) {
if ((to_alloc > 0) || m_release_unused)
bl.resize(nb_buffers, MemBuffer(m_allocator));
if (to_alloc > 0) {
DEB_TRACE() << "Allocating " << to_alloc << " buffers";
for (int i = curr_nb_buffers; i < nb_buffers; i++)
bl[i].alloc(frame_size);
......@@ -751,6 +754,8 @@ void SoftBufferCtrlObj::getFrameDim(FrameDim& frame_dim)
void SoftBufferCtrlObj::setNbBuffers(int nb_buffers)
{
bool release_unused = HwBufferCtrlObj::m_release_unused;
SoftBufferAllocMgr::m_release_unused = release_unused;
m_mgr.setNbBuffers(nb_buffers);
}
......
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