Project

General

Profile

Feature #21068

TouchBuffer convinence function

Added by Eric Flumerfelt almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
Additional Functionality
Target version:
Start date:
10/09/2018
Due date:
% Done:

0%

Estimated time:
Experiment:
-
Co-Assignees:
Duration:

Description

SharedMemoryEventManager needs a function to call to update the touch time of a buffer for bugfix/SMEM_RaceCondition_DoneWritingFragment. This function is implemented in artdaq-core/feature/TouchBufferFunction.

touchBuffer_ was also updated to check the ShmBuffer pointer passed as a parameter before dereferencing.

The check can be verified by calling TouchBuffer with an invalid buffer index number. This should cause an error message from getBufferInfo_, which will return nullptr, and touchBuffer_ will do nothing.

History

#1 Updated by Kurt Biery over 1 year ago

I ran the suggested test in an artdaq-demo system on mu2edaq01. I copied the call to TouchBuffer(buffer) and changed 'buffer' to 33:

[biery@mu2edaq01 artdaq]$ git diff
diff --git a/artdaq/DAQrate/SharedMemoryEventManager.cc b/artdaq/DAQrate/SharedMemoryEventManager.cc
index 6ac818c4..13727984 100644
--- a/artdaq/DAQrate/SharedMemoryEventManager.cc
+++ b/artdaq/DAQrate/SharedMemoryEventManager.cc
@@ -254,6 +254,7 @@ void artdaq::SharedMemoryEventManager::DoneWritingFragment(detail::RawFragmentHe

                TLOG(TLVL_TRACE) << "DoneWritingFragment: Updating buffer touch time";
                TouchBuffer(buffer);
+               TouchBuffer(33);

                buffer_writes_pending_[buffer]--;
                if (buffer_writes_pending_[buffer] != 0)

The result was more dramatic than what I expected, though. The EventBuilder process exited:

[biery@mu2edaq01 331Demo]$ tshowt | grep ' 1395 ' | head
   1395 01-08 21:10:59.396680 16981 16981   3                     SharedMemoryManager nfo . buffer = 0x7f777cb0f090
   5662 01-08 21:10:27.885747  1395 17770   3                     SharedMemoryManager err . Calling default signal handler
   5663 01-08 21:10:27.885713  1395 17770   3                     SharedMemoryManager err . A signal of type 6 was caught by SharedMemoryManager. Detaching all Shared Memory segments, then proceeding with default handlers!
   5664 01-08 21:10:27.885079  1395 17770   3                     SharedMemoryManager err . ArgumentOutOfRange: The specified buffer does not exist!
   5665 01-08 21:10:27.885035  1395 17770   3                     SharedMemoryManager d04 . touchBuffer_: Touching buffer at 0x7f830d4f4040 with sequence_id 1
   5666 01-08 21:10:27.884972  1395 17770   3                     SharedMemoryManager nfo . buffer = 0x7f830d4f4040
   5667 01-08 21:10:27.884954  1395 17770   3  EventBuilder3_SharedMemoryEventManager dbg . DoneWritingFragment: Received Fragment with sequence ID 1 and fragment id 0 (type 2)
   5668 01-08 21:10:27.884810  1395 17770   3                     SharedMemoryManager d04 . touchBuffer_: Touching buffer at 0x7f830d4f4040 with sequence_id 1
   5669 01-08 21:10:27.884734  1395 17770   3                     SharedMemoryManager nfo . buffer = 0x7f830d4f4040
   5670 01-08 21:10:27.884734  1395 17770   3                     SharedMemoryManager d04 . checkBuffer_: Checking that 

This is because getBufferInfo_ calls Detach() with a first argument of "true" indicating that an exception should be thrown.

None of this invalidates the usefulness of checking for a non-null buffer pointer in touchBuffer_, of course. In order to test that, I will create a fake call with touchBuffer_(nullptr).

#2 Updated by Kurt Biery over 1 year ago

A direct call to touchBuffer_() with a zero buffer pointer showed no problems, as expected:

[biery@mu2edaq01 artdaq_core]$ git diff
diff --git a/artdaq-core/Core/SharedMemoryManager.cc b/artdaq-core/Core/SharedMemoryManager.cc
index 4e8d677..33430a7 100644
--- a/artdaq-core/Core/SharedMemoryManager.cc
+++ b/artdaq-core/Core/SharedMemoryManager.cc
@@ -1011,6 +1011,7 @@ bool artdaq::SharedMemoryManager::checkBuffer_(ShmBuffer* buffer, BufferSemaphor

 void artdaq::SharedMemoryManager::touchBuffer_(ShmBuffer* buffer)
 {
+  TLOG(TLVL_INFO) << "buffer = " << buffer;
        if (!buffer || (buffer->sem_id != -1 && buffer->sem_id != manager_id_)) return;
        TLOG(TLVL_TRACE) << "touchBuffer_: Touching buffer at " << (void*)buffer << " with sequence_id " << buffer->sequence_id;
        buffer->last_touch_time = TimeUtils::gettimeofday_us();
diff --git a/artdaq-core/Core/SharedMemoryManager.hh b/artdaq-core/Core/SharedMemoryManager.hh
index b3179ec..7c6c591 100644
--- a/artdaq-core/Core/SharedMemoryManager.hh
+++ b/artdaq-core/Core/SharedMemoryManager.hh
@@ -343,7 +343,7 @@ namespace artdaq
                /**
                 * \brief Touch the given buffer (update its last_touch_time)
                 */
-               void TouchBuffer(int buffer) { return touchBuffer_(getBufferInfo_(buffer)); }
+          void TouchBuffer(int buffer) { touchBuffer_(0); return touchBuffer_(getBufferInfo_(buffer)); }
        private:
                struct ShmBuffer
                {

#3 Updated by Eric Flumerfelt over 1 year ago

  • Status changed from Resolved to Reviewed
  • Co-Assignees Kurt Biery added

#4 Updated by Eric Flumerfelt over 1 year ago

  • Target version set to artdaq_core v3_04_09
  • Status changed from Reviewed to Closed


Also available in: Atom PDF