Skip to content
Snippets Groups Projects
Commit 839731d1 authored by John Romein's avatar John Romein
Browse files

bug 225:

Fixed race condition.  Hopefully, the interrupt version works reliably now.
parent 2ddd1cc2
No related branches found
No related tags found
No related merge requests found
#include <lofar_config.h>
#if defined HAVE_BGP_ION
#include <fcntl.h>
#include <sys/file.h>
#include <sys/mman.h>
......@@ -112,6 +116,22 @@ static Semaphore recvSema(1); // could have used mutex, but this is slower!???
static volatile bool stop, stopped;
static void setAffinity()
{
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
for (unsigned cpu = 1; cpu < 4; cpu ++)
CPU_SET(cpu, &cpu_set);
if (sched_setaffinity(0, sizeof cpu_set, &cpu_set) != 0) {
std::cerr << "WARNING: sched_setaffinity failed" << std::endl;
perror("sched_setaffinity");
}
}
// Reading the tree status words seems to be expensive. These wrappers
// minimize the number of status word reads. Do not read/send packets
// without consulting these functions!
......@@ -327,14 +347,15 @@ static void handleWriteRequest(RequestPacket *request, char *ptr, size_t bytesTo
static void *pollThread(void *)
{
RequestPacket request __attribute__((aligned(16)));
unsigned nrInterrupts = 0;
//setAffinity();
while (!stop) {
_BGP_TreePtpHdr header;
_BGP_TreePtpHdr header;
RequestPacket request __attribute__((aligned(16)));
unsigned nrInterrupts = 0;
if (useInterrupts) {
if (!checkForIncomingPacket()) {
if (useInterrupts) {
while (!stop) {
/*if (!checkForIncomingPacket())*/ { // not thread safe!
int word;
read(fd, &word, sizeof word); // wait for Irq packet
......@@ -350,7 +371,12 @@ static void *pollThread(void *)
}
recvSema.up();
} else {
}
std::clog << "received " << nrInterrupts << " vc0 interrupts" << std::endl;
stopped = true;
} else {
while (!stop) {
if (checkForIncomingPacket()) {
_bgp_vcX_pkt_receive(&header.word, &request, vc0);
assert(header.Irq);
......@@ -372,10 +398,6 @@ static void *pollThread(void *)
}
}
if (useInterrupts)
std::clog << "received " << nrInterrupts << " vc0 interrupts" << std::endl;
stopped = true;
return 0;
}
......@@ -468,22 +490,6 @@ void writeUnaligned(unsigned rankInPSet, const void *ptr, size_t size)
#endif
static void setAffinity()
{
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
for (unsigned cpu = 1; cpu < 4; cpu ++)
CPU_SET(cpu, &cpu_set);
if (sched_setaffinity(0, sizeof cpu_set, &cpu_set) != 0) {
std::cerr << "WARNING: sched_setaffinity failed" << std::endl;
perror("sched_setaffinity");
}
}
static void openVC0()
{
fd = open("/dev/tree0", O_RDWR);
......@@ -620,3 +626,5 @@ void end()
}
} // namespace FCNP_ION
#endif // defined HAVE_BGP_ION
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment