rx_arping for 10g mode (#359)

* test for rx_arping

* arping ip and interface from client interface

* apring thread added to thread ids

* clean code for thread for arping

* removing the assumption that udpip1 fill be updated along with udpip2

* review, replacing syscall(sys_gettid) with gettid()
This commit is contained in:
Dhanya Thattil 2022-02-04 10:12:57 +01:00 committed by GitHub
parent dae77a50e6
commit 771b1e7877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 316 additions and 39 deletions

View File

@ -28,6 +28,8 @@ This document describes the differences between v6.1.0 and v6.0.0.
- changed default vref of adc9257 to 2V for moench (from 1.33V) - changed default vref of adc9257 to 2V for moench (from 1.33V)
- moench and ctb - can set the starting frame number of next acquisition - moench and ctb - can set the starting frame number of next acquisition
- mythen server kernel check incompatible (cet timezone) - mythen server kernel check incompatible (cet timezone)
- rx_arping
- rx_threadsids max is now 9 (breaking api)
- m3 server crash (vthrehsold) - m3 server crash (vthrehsold)
- allow vtrim to be interpolated for Eiger settings - allow vtrim to be interpolated for Eiger settings

View File

@ -258,7 +258,7 @@ class Detector(CppDetectorApi):
@element @element
def rx_threads(self): def rx_threads(self):
""" """
Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1]. Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping].
Note Note
----- -----
@ -268,6 +268,17 @@ class Detector(CppDetectorApi):
""" """
return self.getRxThreadIds() return self.getRxThreadIds()
@property
@element
def rx_arping(self):
"""Starts a thread in slsReceiver to arping the interface it is listening every minute. Useful in 10G mode. """
return self.getRxArping()
@rx_arping.setter
def rx_arping(self, value):
ut.set_using_dict(self.setRxArping, value)
@property @property
@element @element
def dr(self): def dr(self):

View File

@ -768,6 +768,13 @@ void init_det(py::module &m) {
(Result<std::array<pid_t, 8>>(Detector::*)(sls::Positions) const) & (Result<std::array<pid_t, 8>>(Detector::*)(sls::Positions) const) &
Detector::getRxThreadIds, Detector::getRxThreadIds,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getRxArping",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getRxArping,
py::arg() = Positions{})
.def("setRxArping",
(void (Detector::*)(bool, sls::Positions)) & Detector::setRxArping,
py::arg(), py::arg() = Positions{})
.def("getFileFormat", .def("getFileFormat",
(Result<defs::fileFormat>(Detector::*)(sls::Positions) const) & (Result<defs::fileFormat>(Detector::*)(sls::Positions) const) &
Detector::getFileFormat, Detector::getFileFormat,

View File

@ -878,10 +878,18 @@ class Detector {
Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const; Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const;
/** Get thread ids from the receiver in order of [parent, tcp, listener 0, /** Get thread ids from the receiver in order of [parent, tcp, listener 0,
* processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no * processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. If
* streamer yet or there is no second interface, it gives 0 in its place. */ * no streamer yet or there is no second interface, it gives 0 in its place.
*/
Result<std::array<pid_t, NUM_RX_THREAD_IDS>> Result<std::array<pid_t, NUM_RX_THREAD_IDS>>
getRxThreadIds(Positions pos = {}) const; getRxThreadIds(Positions pos = {}) const;
Result<bool> getRxArping(Positions pos = {}) const;
/** Starts a thread in slsReceiver to arping the interface it is listening
* every minute. Useful in 10G mode. */
void setRxArping(bool value, Positions pos = {});
///@} ///@}
/** @name File */ /** @name File */

View File

@ -903,6 +903,7 @@ class CmdProxy {
{"rx_lock", &CmdProxy::rx_lock}, {"rx_lock", &CmdProxy::rx_lock},
{"rx_lastclient", &CmdProxy::rx_lastclient}, {"rx_lastclient", &CmdProxy::rx_lastclient},
{"rx_threads", &CmdProxy::rx_threads}, {"rx_threads", &CmdProxy::rx_threads},
{"rx_arping", &CmdProxy::rx_arping},
/* File */ /* File */
{"fformat", &CmdProxy::fformat}, {"fformat", &CmdProxy::fformat},
@ -1738,13 +1739,16 @@ class CmdProxy {
rx_lastclient, getRxLastClientIP, rx_lastclient, getRxLastClientIP,
"\n\tClient IP Address that last communicated with the receiver."); "\n\tClient IP Address that last communicated with the receiver.");
GET_COMMAND( GET_COMMAND(rx_threads, getRxThreadIds,
rx_threads, getRxThreadIds, "\n\tGet thread ids from the receiver in order of [parent, "
"\n\tGet thread ids from the receiver in order of [parent, tcp, " "tcp, listener 0, processor 0, streamer 0, listener 1, "
"listener 0, " "processor 1, streamer 1, arping]. If no streamer yet or there "
"processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no " "is no second interface, it gives 0 in its place.");
"streamer yet or there is no second interface, it gives 0 in its "
"place."); INTEGER_COMMAND_VEC_ID(rx_arping, getRxArping, setRxArping, StringTo<int>,
"[0, 1]\n\tStarts a thread in slsReceiver to arping "
"the interface it is "
"listening to every minute. Useful in 10G mode.");
/* File */ /* File */

View File

@ -1170,6 +1170,14 @@ Detector::getRxThreadIds(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverThreadIds, pos); return pimpl->Parallel(&Module::getReceiverThreadIds, pos);
} }
Result<bool> Detector::getRxArping(Positions pos) const {
return pimpl->Parallel(&Module::getRxArping, pos);
}
void Detector::setRxArping(bool value, Positions pos) {
pimpl->Parallel(&Module::setRxArping, pos, value);
}
// File // File
Result<defs::fileFormat> Detector::getFileFormat(Positions pos) const { Result<defs::fileFormat> Detector::getFileFormat(Positions pos) const {

View File

@ -1318,6 +1318,14 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Module::getReceiverThreadIds() const {
F_GET_RECEIVER_THREAD_IDS); F_GET_RECEIVER_THREAD_IDS);
} }
bool Module::getRxArping() const {
return sendToReceiver<int>(F_GET_RECEIVER_ARPING);
}
void Module::setRxArping(bool enable) {
sendToReceiver(F_SET_RECEIVER_ARPING, static_cast<int>(enable), nullptr);
}
// File // File
slsDetectorDefs::fileFormat Module::getFileFormat() const { slsDetectorDefs::fileFormat Module::getFileFormat() const {
return sendToReceiver<fileFormat>(F_GET_RECEIVER_FILE_FORMAT); return sendToReceiver<fileFormat>(F_GET_RECEIVER_FILE_FORMAT);

View File

@ -283,6 +283,8 @@ class Module : public virtual slsDetectorDefs {
void setReceiverLock(bool lock); void setReceiverLock(bool lock);
sls::IpAddr getReceiverLastClientIP() const; sls::IpAddr getReceiverLastClientIP() const;
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const; std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
bool getRxArping() const;
void setRxArping(bool enable);
/************************************************** /**************************************************
* * * *

View File

@ -385,6 +385,30 @@ TEST_CASE("rx_threads", "[.cmd][.rx]") {
REQUIRE_NOTHROW(proxy.Call("rx_threads", {}, -1, GET, oss)); REQUIRE_NOTHROW(proxy.Call("rx_threads", {}, -1, GET, oss));
} }
TEST_CASE("rx_arping", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getRxArping();
{
std::ostringstream oss;
proxy.Call("rx_arping", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
proxy.Call("rx_arping", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
proxy.Call("rx_arping", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_arping 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxArping(prev_val[i], {i});
}
}
/* File */ /* File */
TEST_CASE("fformat", "[.cmd]") { TEST_CASE("fformat", "[.cmd]") {

View File

@ -12,6 +12,7 @@ set(SOURCES
src/DataProcessor.cpp src/DataProcessor.cpp
src/DataStreamer.cpp src/DataStreamer.cpp
src/Fifo.cpp src/Fifo.cpp
src/Arping.cpp
) )
set(PUBLICHEADERS set(PUBLICHEADERS

View File

@ -0,0 +1,114 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Arping.h"
#include <chrono>
#include <unistd.h>
void Arping::SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip) {
if (interface.empty() || ip.empty()) {
throw sls::RuntimeError("Could not arping. Interface name and ip not "
"set up for interface " +
std::to_string(index));
}
// create commands to arping
std::ostringstream os;
os << "arping -c 1 -U -I " << interface << " " << ip;
// to read error messages
os << " 2>&1";
std::string cmd = os.str();
commands[index] = cmd;
}
pid_t Arping::GetThreadId() const { return threadId; }
bool Arping::IsRunning() const { return runningFlag; }
void Arping::StartThread() {
TestCommands();
try {
t = std::thread(&Arping::ThreadExecution, this);
} catch (...) {
throw sls::RuntimeError("Could not start arping thread");
}
runningFlag = true;
}
void Arping::StopThread() {
runningFlag = false;
t.join();
}
void Arping::ThreadExecution() {
threadId = gettid();
LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]";
while (runningFlag) {
std::string error = ExecuteCommands();
// just print (was already tested at thread start)
if (!error.empty()) {
LOG(logERROR) << error;
}
// wait for 60s as long as thread not killed
int nsecs = 0;
while (runningFlag && nsecs != 60) {
std::this_thread::sleep_for(std::chrono::seconds(1));
++nsecs;
}
}
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]";
threadId = 0;
}
void Arping::TestCommands() {
// atleast one interface must be set up
if (commands[0].empty()) {
throw sls::RuntimeError(
"Could not arping. Interface not set up in apring thread");
}
// test if arping commands throw an error
std::string error = ExecuteCommands();
if (!error.empty()) {
throw sls::RuntimeError(error);
}
}
std::string Arping::ExecuteCommands() {
for (auto cmd : commands) {
// empty if 2nd interface not enabled
if (cmd.empty())
continue;
LOG(logDEBUG) << "Executing Arping Command: " << cmd;
// execute command
FILE *sysFile = popen(cmd.c_str(), "r");
if (sysFile == NULL) {
std::ostringstream os;
os << "Could not Arping [" << cmd << " ] : Popen fail";
return os.str();
}
// copy output
char output[MAX_STR_LENGTH] = {0};
fgets(output, sizeof(output), sysFile);
output[sizeof(output) - 1] = '\0';
// check exit status of command
if (pclose(sysFile)) {
std::ostringstream os;
os << "Could not arping[" << cmd << "] : " << output;
return os.str();
} else {
LOG(logDEBUG) << output;
}
}
return std::string();
}

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
/**
*@short creates/destroys an ARPing thread to arping the interfaces slsReceiver
is listening to.
*/
#include "receiver_defs.h"
#include "sls/logger.h"
#include <atomic>
#include <thread>
class Arping {
public:
void SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip);
pid_t GetThreadId() const;
bool IsRunning() const;
void StartThread();
void StopThread();
private:
void TestCommands();
std::string ExecuteCommands();
void ThreadExecution();
std::vector<std::string> commands =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
std::atomic<bool> runningFlag{false};
std::thread t;
std::atomic<pid_t> threadId{0};
};

View File

@ -19,7 +19,6 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
@ -41,7 +40,7 @@ ClientInterface::ClientInterface(int portNumber)
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2), portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2),
server(portNumber) { server(portNumber) {
functionTable(); functionTable();
parentThreadId = syscall(SYS_gettid); parentThreadId = gettid();
tcpThread = tcpThread =
sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this); sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
} }
@ -76,7 +75,7 @@ void ClientInterface::registerCallBackRawDataModifyReady(
} }
void ClientInterface::startTCPServer() { void ClientInterface::startTCPServer() {
tcpThreadId = syscall(SYS_gettid); tcpThreadId = gettid();
LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]"; LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]";
LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber
<< '\n'; << '\n';
@ -210,7 +209,8 @@ int ClientInterface::functionTable(){
flist[F_SET_RECEIVER_STREAMING_HWM] = &ClientInterface::set_streaming_hwm; flist[F_SET_RECEIVER_STREAMING_HWM] = &ClientInterface::set_streaming_hwm;
flist[F_RECEIVER_SET_ALL_THRESHOLD] = &ClientInterface::set_all_threshold; flist[F_RECEIVER_SET_ALL_THRESHOLD] = &ClientInterface::set_all_threshold;
flist[F_RECEIVER_SET_DATASTREAM] = &ClientInterface::set_detector_datastream; flist[F_RECEIVER_SET_DATASTREAM] = &ClientInterface::set_detector_datastream;
flist[F_GET_RECEIVER_ARPING] = &ClientInterface::get_arping;
flist[F_SET_RECEIVER_ARPING] = &ClientInterface::set_arping;
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
LOG(logDEBUG1) << "function fnum: " << i << " (" << LOG(logDEBUG1) << "function fnum: " << i << " (" <<
@ -1398,6 +1398,10 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
if (detType == EIGER) { if (detType == EIGER) {
impl()->setEthernetInterface2(eth); impl()->setEthernetInterface2(eth);
} }
// update locally to use for arping
udpips[0] = arg.str();
// get mac address // get mac address
auto retval = sls::InterfaceNameToMac(eth); auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0) { if (retval == 0) {
@ -1430,6 +1434,9 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
} }
impl()->setEthernetInterface2(eth); impl()->setEthernetInterface2(eth);
// update locally to use for arping
udpips[1] = arg.str();
// get mac address // get mac address
auto retval = sls::InterfaceNameToMac(eth); auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0) { if (retval == 0) {
@ -1697,3 +1704,20 @@ int ClientInterface::set_detector_datastream(Interface &socket) {
impl()->setDetectorDataStream(port, enable); impl()->setDetectorDataStream(port, enable);
return socket.Send(OK); return socket.Send(OK);
} }
int ClientInterface::get_arping(Interface &socket) {
auto retval = static_cast<int>(impl()->getArping());
LOG(logDEBUG1) << "arping thread status:" << retval;
return socket.sendResult(retval);
}
int ClientInterface::set_arping(Interface &socket) {
auto value = socket.Receive<int>();
if (value < 0) {
throw RuntimeError("Invalid arping value: " + std::to_string(value));
}
verifyIdle(socket);
LOG(logDEBUG1) << "Starting/ Killing arping thread:" << value;
impl()->setArping(value, udpips);
return socket.Send(OK);
}

View File

@ -163,6 +163,8 @@ class ClientInterface : private virtual slsDetectorDefs {
int set_streaming_hwm(sls::ServerInterface &socket); int set_streaming_hwm(sls::ServerInterface &socket);
int set_all_threshold(sls::ServerInterface &socket); int set_all_threshold(sls::ServerInterface &socket);
int set_detector_datastream(sls::ServerInterface &socket); int set_detector_datastream(sls::ServerInterface &socket);
int get_arping(sls::ServerInterface &socket);
int set_arping(sls::ServerInterface &socket);
Implementation *impl() { Implementation *impl() {
if (receiver != nullptr) { if (receiver != nullptr) {
@ -190,4 +192,6 @@ class ClientInterface : private virtual slsDetectorDefs {
pid_t parentThreadId{0}; pid_t parentThreadId{0};
pid_t tcpThreadId{0}; pid_t tcpThreadId{0};
std::vector<std::string> udpips =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
}; };

View File

@ -107,6 +107,7 @@ void Implementation::SetupFifoStructure() {
* ************************************************/ * ************************************************/
void Implementation::setDetectorType(const detectorType d) { void Implementation::setDetectorType(const detectorType d) {
detType = d; detType = d;
switch (detType) { switch (detType) {
case GOTTHARD: case GOTTHARD:
@ -320,9 +321,33 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Implementation::getThreadIds() const {
retval[id++] = 0; retval[id++] = 0;
} }
} }
retval[NUM_RX_THREAD_IDS - 1] = arping.GetThreadId();
return retval; return retval;
} }
bool Implementation::getArping() const { return arping.IsRunning(); }
pid_t Implementation::getArpingThreadId() const { return arping.GetThreadId(); }
void Implementation::setArping(const bool i,
const std::vector<std::string> ips) {
if (i != arping.IsRunning()) {
if (!i) {
arping.StopThread();
} else {
// setup interface
for (int i = 0; i != numUDPInterfaces; ++i) {
// ignore eiger with 2 interfaces (only udp port)
if (i == 1 && (numUDPInterfaces == 1 || detType == EIGER)) {
break;
}
arping.SetInterfacesAndIps(i, eth[i], ips[i]);
}
arping.StartThread();
}
}
}
/************************************************** /**************************************************
* * * *
* File Parameters * * File Parameters *

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-other // SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once #pragma once
#include "Arping.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
@ -49,6 +50,9 @@ class Implementation : private virtual slsDetectorDefs {
void setFramePaddingEnable(const bool i); void setFramePaddingEnable(const bool i);
void setThreadIds(const pid_t parentTid, const pid_t tcpTid); void setThreadIds(const pid_t parentTid, const pid_t tcpTid);
std::array<pid_t, NUM_RX_THREAD_IDS> getThreadIds() const; std::array<pid_t, NUM_RX_THREAD_IDS> getThreadIds() const;
bool getArping() const;
pid_t getArpingThreadId() const;
void setArping(const bool i, const std::vector<std::string> ips);
/************************************************** /**************************************************
* * * *
@ -379,6 +383,7 @@ class Implementation : private virtual slsDetectorDefs {
std::vector<std::unique_ptr<DataProcessor>> dataProcessor; std::vector<std::unique_ptr<DataProcessor>> dataProcessor;
std::vector<std::unique_ptr<DataStreamer>> dataStreamer; std::vector<std::unique_ptr<DataStreamer>> dataStreamer;
std::vector<std::unique_ptr<Fifo>> fifo; std::vector<std::unique_ptr<Fifo>> fifo;
Arping arping;
std::mutex hdf5Lib; std::mutex hdf5Lib;
}; };

View File

@ -11,7 +11,6 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <sys/wait.h> //wait #include <sys/wait.h> //wait
#include <unistd.h> #include <unistd.h>
@ -172,8 +171,7 @@ int main(int argc, char *argv[]) {
(!sscanf(argv[3], "%d", &withCallback)))) (!sscanf(argv[3], "%d", &withCallback))))
printHelp(); printHelp();
cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
(long)syscall(SYS_gettid));
cprintf(RESET, "Number of Receivers: %d\n", numReceivers); cprintf(RESET, "Number of Receivers: %d\n", numReceivers);
cprintf(RESET, "Start TCP Port: %d\n", startTCPPort); cprintf(RESET, "Start TCP Port: %d\n", startTCPPort);
cprintf(RESET, "Callback Enable: %d\n", withCallback); cprintf(RESET, "Callback Enable: %d\n", withCallback);
@ -215,16 +213,14 @@ int main(int argc, char *argv[]) {
/** - if child process */ /** - if child process */
else if (pid == 0) { else if (pid == 0) {
cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, (long)gettid());
(long)syscall(SYS_gettid));
std::unique_ptr<sls::Receiver> receiver = nullptr; std::unique_ptr<sls::Receiver> receiver = nullptr;
try { try {
receiver = sls::make_unique<sls::Receiver>(startTCPPort + i); receiver = sls::make_unique<sls::Receiver>(startTCPPort + i);
} catch (...) { } catch (...) {
LOG(logINFOBLUE) LOG(logINFOBLUE)
<< "Exiting Child Process [ Tid: " << syscall(SYS_gettid) << "Exiting Child Process [ Tid: " << gettid() << " ]";
<< " ]";
throw; throw;
} }
/** - register callbacks. remember to set file write enable to 0 /** - register callbacks. remember to set file write enable to 0
@ -254,7 +250,7 @@ int main(int argc, char *argv[]) {
sem_wait(&semaphore); sem_wait(&semaphore);
sem_destroy(&semaphore); sem_destroy(&semaphore);
cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n", cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n",
(long)syscall(SYS_gettid)); (long)gettid());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
} }

View File

@ -14,7 +14,6 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
namespace sls { namespace sls {
@ -68,8 +67,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
case 'v': case 'v':
std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x" std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x"
<< std::hex << APIRECEIVER << ")" << std::endl; << std::hex << APIRECEIVER << ")" << std::endl;
LOG(logINFOBLUE) LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
<< "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':

View File

@ -8,7 +8,6 @@
#include <csignal> //SIGINT #include <csignal> //SIGINT
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
sem_t semaphore; sem_t semaphore;
@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Created [ Tid: " << gettid() << " ]";
// Catch signal SIGINT to close files and call destructors properly // Catch signal SIGINT to close files and call destructors properly
struct sigaction sa; struct sigaction sa;
@ -50,7 +49,7 @@ int main(int argc, char *argv[]) {
} catch (...) { } catch (...) {
// pass // pass
} }
LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(logINFO) << "Exiting Receiver"; LOG(logINFO) << "Exiting Receiver";
return 0; return 0;
} }

View File

@ -8,7 +8,6 @@
#include "ThreadObject.h" #include "ThreadObject.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include <iostream> #include <iostream>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
ThreadObject::ThreadObject(int threadIndex, std::string threadType) ThreadObject::ThreadObject(int threadIndex, std::string threadType)
@ -39,7 +38,7 @@ void ThreadObject::StartRunning() { runningFlag = true; }
void ThreadObject::StopRunning() { runningFlag = false; } void ThreadObject::StopRunning() { runningFlag = false; }
void ThreadObject::RunningThread() { void ThreadObject::RunningThread() {
threadId = syscall(SYS_gettid); threadId = gettid();
LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index
<< ", Tid: " << threadId << "]"; << ", Tid: " << threadId << "]";
while (!killThread) { while (!killThread) {

View File

@ -21,14 +21,6 @@ class ThreadObject : private virtual slsDetectorDefs {
protected: protected:
const int index{0}; const int index{0};
private:
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
pid_t threadId{0};
public: public:
ThreadObject(int threadIndex, std::string threadType); ThreadObject(int threadIndex, std::string threadType);
virtual ~ThreadObject(); virtual ~ThreadObject();
@ -47,4 +39,11 @@ class ThreadObject : private virtual slsDetectorDefs {
* Then it exits the thread on its own if killThread is true * Then it exits the thread on its own if killThread is true
*/ */
void RunningThread(); void RunningThread();
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
std::atomic<pid_t> threadId{0};
}; };

View File

@ -73,7 +73,7 @@
#define DEFAULT_STREAMING_TIMER_IN_MS 500 #define DEFAULT_STREAMING_TIMER_IN_MS 500
#define NUM_RX_THREAD_IDS 8 #define NUM_RX_THREAD_IDS 9
#ifdef __cplusplus #ifdef __cplusplus
class slsDetectorDefs { class slsDetectorDefs {

View File

@ -361,6 +361,8 @@ enum detFuncs {
F_SET_RECEIVER_STREAMING_HWM, F_SET_RECEIVER_STREAMING_HWM,
F_RECEIVER_SET_ALL_THRESHOLD, F_RECEIVER_SET_ALL_THRESHOLD,
F_RECEIVER_SET_DATASTREAM, F_RECEIVER_SET_DATASTREAM,
F_GET_RECEIVER_ARPING,
F_SET_RECEIVER_ARPING,
NUM_REC_FUNCTIONS NUM_REC_FUNCTIONS
}; };
@ -720,6 +722,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_RECEIVER_STREAMING_HWM: return "F_SET_RECEIVER_STREAMING_HWM"; case F_SET_RECEIVER_STREAMING_HWM: return "F_SET_RECEIVER_STREAMING_HWM";
case F_RECEIVER_SET_ALL_THRESHOLD: return "F_RECEIVER_SET_ALL_THRESHOLD"; case F_RECEIVER_SET_ALL_THRESHOLD: return "F_RECEIVER_SET_ALL_THRESHOLD";
case F_RECEIVER_SET_DATASTREAM: return "F_RECEIVER_SET_DATASTREAM"; case F_RECEIVER_SET_DATASTREAM: return "F_RECEIVER_SET_DATASTREAM";
case F_GET_RECEIVER_ARPING: return "F_GET_RECEIVER_ARPING";
case F_SET_RECEIVER_ARPING: return "F_SET_RECEIVER_ARPING";
case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS";
default: return "Unknown Function"; default: return "Unknown Function";