summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-05 15:52:21 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-05 15:52:21 +0200
commit935de2a8ec8fce9f6b51cf10f7d4d1ed29625420 (patch)
tree158cf4615f9a901826edf7860db461390688c8c2
parent3b430b906317d4114e5ebe3e35bdd0ac430a463a (diff)
WatchDog and IO functions: ensure we return it to normal timeout in case of exceptions in the middle of function.
Change-Id: I5d2e119f19c3e3214fdbe8108ea35af899ab49a5 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp13
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp10
-rw-r--r--src/trex_watchdog.h27
3 files changed, 32 insertions, 18 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index d2546740..4d73714e 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -637,11 +637,9 @@ TrexRpcCmdPushRemote::_run(const Json::Value &params, Json::Value &result) {
}
- /* IO might take time, increase timeout of WD */
- TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
- if (cur_monitor != NULL) {
- cur_monitor->io_begin();
- }
+ /* IO might take time, increase timeout of WD inside this function */
+ TrexWatchDog::IOFunction dummy;
+ (void)dummy;
try {
port->push_remote(pcap_filename, ipg_usec, min_ipg_sec, speedup, count, duration, is_dual);
@@ -649,11 +647,6 @@ TrexRpcCmdPushRemote::_run(const Json::Value &params, Json::Value &result) {
generate_execute_err(result, ex.what());
}
- /* revert timeout of WD */
- if (cur_monitor != NULL) {
- cur_monitor->io_end();
- }
-
result["result"] = Json::objectValue;
return (TREX_RPC_CMD_OK);
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index 0a317170..d8563e95 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -1282,10 +1282,7 @@ bool CGenNodePCAP::create(uint8_t port_id,
m_min_ipg_sec = min_ipg_sec;
/* increase timeout of WD due to io */
- TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
- if (cur_monitor != NULL) {
- cur_monitor->io_begin();
- }
+ TrexWatchDog::IOFunction::io_begin();
/* mark this node as slow path */
set_slow_path(true);
@@ -1351,10 +1348,7 @@ void CGenNodePCAP::destroy() {
}
/* end of io, return normal timeout of WD */
- TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
- if (cur_monitor != NULL) {
- cur_monitor->io_end();
- }
+ TrexWatchDog::IOFunction::io_end();
m_state = PCAP_INVALID;
}
diff --git a/src/trex_watchdog.h b/src/trex_watchdog.h
index 67dbb80d..b4512b6e 100644
--- a/src/trex_watchdog.h
+++ b/src/trex_watchdog.h
@@ -193,6 +193,8 @@ public:
return instance;
}
+ class IOFunction;
+
void init(bool enable);
/**
@@ -252,5 +254,30 @@ private:
static bool g_signal_init;
};
+class TrexWatchDog::IOFunction {
+public:
+ static void io_begin() {
+ TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
+ if (cur_monitor != NULL) {
+ cur_monitor->io_begin();
+ }
+ }
+
+ static void io_end() {
+ TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
+ if (cur_monitor != NULL) {
+ cur_monitor->io_end();
+ }
+ }
+
+ IOFunction() {
+ IOFunction::io_begin();
+ }
+
+ ~IOFunction() {
+ IOFunction::io_end();
+ }
+
+};
#endif /* __TREX_WATCHDOG_H__ */