Skip to content

Commit

Permalink
More uniform timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
mroda88 committed Jul 20, 2024
1 parent e3cd583 commit b67ef74
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 38 deletions.
7 changes: 3 additions & 4 deletions plugins/DaphneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ DaphneController::do_conf(const data_t& conf_as_json)
const std::lock_guard<std::mutex> lock(m_mutex);

create_interface(conf_as_cpp.daphne_address,
conf_as_cpp.command_timeout_ms,
conf_as_cpp.socket_timeout_us);
std::chrono::milliseconds(conf_as_cpp.timeout_ms) );

validate_configuration(conf_as_cpp);

Expand Down Expand Up @@ -298,7 +297,7 @@ DaphneController::do_scrap(const data_t&)


void
DaphneController::create_interface(const std::string & ip, timeout_t cmd, timeout_t sock) {
DaphneController::create_interface(const std::string & ip, std::chrono::milliseconds timeout) {

static std::regex ip_regex("[0-9]+.[0-9]+.[0-9]+.([0-9]+)");

Expand All @@ -310,7 +309,7 @@ DaphneController::create_interface(const std::string & ip, timeout_t cmd, timeou

TLOG() << get_name() << ": using daphne at " << ip << " with slot " << (int)m_slot;

m_interface.reset( new DaphneInterface( ip.c_str(), 2001, std::chrono::milliseconds(cmd), std::chrono::microseconds(sock)) );
m_interface.reset( new DaphneInterface( ip.c_str(), 2001, timeout ) );

}

Expand Down
3 changes: 1 addition & 2 deletions plugins/DaphneController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ class DaphneController : public dunedaq::appfwk::DAQModule
void dump_buffers(const data_t&);

// specific actions
using timeout_t = decltype(daphnecontroller::Conf::socket_timeout_us);
void create_interface( const std::string & ip, timeout_t cmd, timeout_t sock ) ;
void create_interface( const std::string & ip, std::chrono::milliseconds timeout ) ;
void validate_configuration(const daphnecontroller::Conf &);
void configure_timing_endpoints();
void configure_analog_chain(bool intial_config);
Expand Down
6 changes: 2 additions & 4 deletions python/daphnemodules/daphnemodulesapp_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def to_lna( j : dict ) -> daphnecontroller.LNAConf :
def get_daphnemodules_app(
slot : int,
ip : str,
socket_timeout_us : int,
command_timeout_ms : int,
timeout_ms : int,
biasctrl : int,
afe_gain : int,
channel_gain : int,
Expand Down Expand Up @@ -132,8 +131,7 @@ def get_daphnemodules_app(
conf = daphnecontroller.Conf(
daphne_address=ip,
slot=slot,
socket_timeout_us=socket_timeout_us,
command_timeout_ms=command_timeout_ms,
timeout_ms=timeout_ms,
biasctrl=biasctrl,
afes = afes,
channels = channels,
Expand Down
6 changes: 2 additions & 4 deletions schema/daphnemodules/confgen.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ local cs = {
daphne_input: s.record("DaphneInput", [
s.field( "daphnes", self.daphne_list, default=[],
doc="List of the daphne to use, identified by slot"),
s.field( "socket_timeout_us", self.uint4, default = 1000000,
doc = "timeout for socket interactions in microseconds"),
s.field( "command_timeout_ms", self.uint4, default = 1000,
doc = "timeout for command response reception in milliseconds"),
s.field( "timeout_ms", self.uint4, default = 500,
doc = "timeout for any interaction with the board; in milliseconds"),
s.field( "biasctrl", self.uint4, default = 4095,
doc = "Biasctr to be used for all boards"),
s.field( "afe_gain", self.uint4, default = 2667,
Expand Down
6 changes: 2 additions & 4 deletions schema/daphnemodules/daphnecontroller.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ local types = {
doc="addresses of the daphne connection point"),
s.field("slot", self.uint4,
doc="Slot of the board, also used to identify the board"),
s.field("socket_timeout_us", self.uint4, 200,
doc="timeout used for the socket in microseconds"),
s.field("command_timeout_ms", self.uint4, 50,
doc="timeout used for the command replies in milliseconds"),
s.field("timeout_ms", self.uint4, 500,
doc="timeout used for board interactions in milliseconds"),
s.field("biasctrl", self.uint4,
doc="V Bias Control"),
s.field("channels", self.channels,
Expand Down
3 changes: 1 addition & 2 deletions scripts/daphne_gen
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def cli(config,
nickname = f"controller_{slot}",
slot = slot,
ip = ip,
socket_timeout_us = daphne_block.socket_timeout_us,
command_timeout_ms = daphne_block.command_timeout_ms,
timeout_ms = daphne_block.timeout_ms,
biasctrl = daphne_block.biasctrl,
afe_gain = daphne_block.afe_gain,
channel_gain = daphne_block.channel_gain,
Expand Down
21 changes: 10 additions & 11 deletions src/DaphneInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
using namespace dunedaq::daphnemodules;

DaphneInterface::DaphneInterface( const char* ipaddr, int port,
std::chrono::milliseconds cmd_timeout,
std::chrono::microseconds sock_timeout )
: m_cmd_timeout(cmd_timeout)
, m_socket_timeout(sock_timeout) {
std::chrono::milliseconds timeout)
: m_timeout(timeout) {

m_connection_id = socket(AF_INET, SOCK_DGRAM, 0);

Expand Down Expand Up @@ -149,16 +147,17 @@ command_result DaphneInterface::send_command( std::string cmd) const {
}
}
auto now = std::chrono::high_resolution_clock::now();

auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time);

if ( delay > m_cmd_timeout ) {
auto delay = now - start_time;
if ( delay > m_timeout ) {
TLOG() << "Details of timeout";
for ( size_t i = 0; i < data_block.size(); ++i ) {
TLOG() << i << "\t" << std::hex << data_block[i] << std::dec;
}
TLOG() << "Received so far: " << res.result;
throw CommandTimeout(ERS_HERE, cmd, delay.count());
auto delay_us = std::chrono::duration_cast<std::chrono::microseconds>(delay);
throw CommandTimeout(ERS_HERE, cmd, delay_us.count());
}

std::this_thread::sleep_for(std::chrono::milliseconds(1));
Expand All @@ -184,8 +183,8 @@ std::vector<uint64_t> DaphneInterface::read(uint8_t command_id,


struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = m_socket_timeout.count();
timeout.tv_sec = m_timeout.count() / 1000 ;
timeout.tv_usec = (m_timeout.count() % 1000) * 1000 ;
fd_set readfds, masterfds;

FD_ZERO(&masterfds);
Expand Down
11 changes: 5 additions & 6 deletions src/DaphneInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ namespace dunedaq {

ERS_DECLARE_ISSUE( daphnemodules,
CommandTimeout,
"Command " << command << " timed out after " << ms << " ms",
((std::string)command)((unsigned int)ms)
"Command " << command << " timed out after " << timeout_us << " microseconds",
((std::string)command)((unsigned int)timeout_us)
)

ERS_DECLARE_ISSUE( daphnemodules,
Expand All @@ -78,8 +78,8 @@ namespace dunedaq::daphnemodules {

public:
DaphneInterface( const char* ipaddr, int port,
std::chrono::milliseconds cmd_timeout,
std::chrono::microseconds sock_timeout = std::chrono::microseconds(100) );
std::chrono::milliseconds timeout = std::chrono::milliseconds(500));

~DaphneInterface() { if(m_connection_id>0) close();}

DaphneInterface(const DaphneInterface &) = delete;
Expand Down Expand Up @@ -115,8 +115,7 @@ namespace dunedaq::daphnemodules {
private:
int m_connection_id = -1;
sockaddr_in m_target;
std::chrono::milliseconds m_cmd_timeout{5};
std::chrono::microseconds m_socket_timeout{1000};
std::chrono::milliseconds m_timeout{5};
mutable std::mutex m_access_mutex;
mutable std::mutex m_command_mutex;
};
Expand Down
2 changes: 1 addition & 1 deletion unittest/DaphneInterface_test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(Construction)

using namespace std::chrono;

BOOST_CHECK_THROW( dunedaq::daphnemodules::DaphneInterface i("non.exising.ip", 1000, milliseconds(50), microseconds(200)),
BOOST_CHECK_THROW( dunedaq::daphnemodules::DaphneInterface i("non.exising.ip", 1000, milliseconds(5)),
dunedaq::daphnemodules::InvalidIPAddress );

}
Expand Down

0 comments on commit b67ef74

Please sign in to comment.