Commit 8b0d95eb authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline
Browse files

Using Lima Thread ID management, add test_thread_cpu_affinity

parent 7f8384cd
......@@ -616,9 +616,6 @@ typedef RegEx::MatchListType MatchList;
typedef MatchList::const_iterator MatchListIt;
pid_t gettid();
} // namespace SlsDetector
} // namespace lima
......
......@@ -69,8 +69,8 @@ private:
Port(Receiver& recv, int port);
pid_t getTID()
{ return m_thread.getTID(); }
pid_t getThreadID()
{ return m_thread.getThreadID(); }
void prepareAcq();
......@@ -111,9 +111,6 @@ private:
Thread(Port& port);
virtual ~Thread();
pid_t getTID()
{ return m_tid; }
virtual void start();
protected:
......
......@@ -640,7 +640,7 @@ void Camera::setRecvCPUAffinity(const RecvCPUAffinity& recv_affinity)
RecvPortList port_list = getRecvPortList();
RecvPortList::iterator pit, pend = port_list.end();
for (pit = port_list.begin(); pit != pend; ++pit) {
pid_t tid = (*pit)->getTID();
pid_t tid = (*pit)->getThreadID();
writers_affinity.applyToTask(tid, false);
}
}
......
......@@ -24,8 +24,6 @@
#include "lima/MiscUtils.h"
#include <glob.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <cmath>
using namespace std;
......@@ -797,8 +795,3 @@ ostream& lima::SlsDetector::operator <<(ostream& os, const Stats& s)
return os << ">";
}
pid_t lima::SlsDetector::gettid() {
return syscall(SYS_gettid);
}
......@@ -65,8 +65,6 @@ void Receiver::Port::Thread::threadFunction()
{
DEB_MEMBER_FUNCT();
m_tid = gettid();
m_end = false;
while (!m_end)
m_port.pollFrameFinished();
......
......@@ -21,7 +21,8 @@
############################################################################
set(test_src test_slsdetector
test_slsdetector_control)
test_slsdetector_control
test_thread_cpu_affinity)
limatools_run_camera_tests("${test_src}" ${NAME})
#include "lima/Timestamp.h"
#include "lima/MiscUtils.h"
#include "lima/ThreadUtils.h"
#include "SlsDetectorCPUAffinity.h"
using namespace std;
using namespace lima;
using namespace lima::SlsDetector;
DEB_GLOBAL(DebModTest);
class TestThread : public Thread {
DEB_CLASS(DebModTest, "TestThread");
public:
TestThread(int cpu, Cond& cond, volatile bool& active);
int getCPU() const
{ return m_cpu; }
uint64_t getCount() const
{ return m_count; }
protected:
virtual void threadFunction();
private:
AutoMutex lock()
{ return m_cond.mutex(); }
int m_cpu;
Cond& m_cond;
volatile bool& m_active;
uint64_t m_count;
};
TestThread::TestThread(int cpu, Cond& cond, volatile bool& active)
: m_cpu(cpu), m_cond(cond), m_active(active)
{
DEB_CONSTRUCTOR();
m_count = -1;
start();
{
AutoMutex l = lock();
while (m_count != 0)
m_cond.wait();
}
CPUAffinity aff(1L << cpu);
aff.applyToTask(getThreadID(), false, false);
}
void TestThread::threadFunction()
{
DEB_MEMBER_FUNCT();
{
AutoMutex l = lock();
m_count = 0;
m_cond.broadcast();
DEB_TRACE() << "Thread " << m_cpu << " started";
while (!m_active)
m_cond.wait();
}
DEB_TRACE() << "Thread " << m_cpu << " active";
while (m_active) {
for (int i = 0; i < 1000; ++i)
;
++m_count;
}
}
int main(int argc, char *argv[])
{
DEB_GLOBAL_FUNCT();
bool debug = false;
if (debug)
DebParams::setTypeFlags(DebParams::AllFlags);
int mask = 0;
if (argc > 1) {
istringstream is(argv[1]);
is >> mask;
}
SystemCPUAffinityMgr mgr;
mgr.setOtherCPUAffinity(CPUAffinity(0x001));
NetDevGroupCPUAffinityList netdev_aff_list;
NetDevGroupCPUAffinity netdev_aff;
const char *netdev_group_0[] = {"eth0", "eth1", "eth2", "eth4",
"eth6", "eth7", "eth8", "eth9"};
netdev_aff.name_list = StringList(C_LIST_ITERS(netdev_group_0));
netdev_aff.processing = CPUAffinity(0x001);
netdev_aff_list.push_back(netdev_aff);
const char *netdev_group_1[] = {"eth3", "eth5"};
netdev_aff.name_list = StringList(C_LIST_ITERS(netdev_group_1));
netdev_aff.processing = CPUAffinity(0x002);
netdev_aff_list.push_back(netdev_aff);
CPUAffinity this_aff = 0x001;
DEB_TRACE() << "Setting " << DEB_VAR1(this_aff);
this_aff.applyToTask(GetThreadID(), false, false);
Cond cond;
volatile bool active = false;
int nb_cpus = CPUAffinity::getNbCPUs();
int test_cpus = mask ? mask : (1 << nb_cpus) - 1;
DEB_ALWAYS() << DEB_VAR1(DebHex(test_cpus));
typedef vector<AutoPtr<TestThread> > ThreadList;
ThreadList thread_list;
for (int i = 0; i < nb_cpus; ++i) {
if (1 << i & test_cpus) {
TestThread *t = new TestThread(i, cond, active);
int cpu = t->getCPU();
DEB_ALWAYS() << DEB_VAR1(cpu);
thread_list.push_back(t);
}
}
DEB_ALWAYS() << "Starting";
active = true;
cond.broadcast();
Sleep(5);
DEB_ALWAYS() << "Stopping";
active = false;
ThreadList::iterator it, end = thread_list.end();
for (it = thread_list.begin(); it != end; ++it) {
TestThread *t = *it;
int cpu = t->getCPU();
(*it)->join();
float count = t->getCount();
DEB_ALWAYS() << DEB_VAR2(cpu, count);
}
return 0;
}
Supports Markdown
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