Skip to content
Snippets Groups Projects
Commit da83c7a7 authored by Martin Karsten's avatar Martin Karsten
Browse files

- change pollfibre to try nonblocking poll before blocking

- clerical updates in BaseProcessor
parent f564e23a
No related branches found
No related tags found
No related merge requests found
...@@ -66,12 +66,16 @@ inline void BasePoller::pollLoop(T& This, bool pollerFibre) { ...@@ -66,12 +66,16 @@ inline void BasePoller::pollLoop(T& This, bool pollerFibre) {
} }
inline int PollerThread::blockingPoll() { inline int PollerThread::blockingPoll() {
int evcnt;
for (;;) {
#if __FreeBSD__ #if __FreeBSD__
int evcnt = kevent(pollFD, nullptr, 0, events, maxPoll, nullptr); // blocking evcnt = kevent(pollFD, nullptr, 0, events, maxPoll, nullptr); // blocking
#else // __linux__ below #else // __linux__ below
int evcnt = epoll_wait(pollFD, events, maxPoll, -1); // blocking evcnt = epoll_wait(pollFD, events, maxPoll, -1); // blocking
#endif #endif
if (evcnt < 0) { GENASSERT1(errno == EINTR, errno); } // gracefully handle EINTR if (evcnt > 0) break;
if (evcnt < 0) { GENASSERT1(errno == EINTR, errno); } // gracefully handle EINTR
}
if (paused) pauseSem.P(); if (paused) pauseSem.P();
return evcnt; return evcnt;
} }
...@@ -116,14 +120,18 @@ void Poller::stop() { ...@@ -116,14 +120,18 @@ void Poller::stop() {
} }
inline int Poller::blockingPoll() { inline int Poller::blockingPoll() {
_lfEventEngine->blockPollFD(pollFD); int evcnt;
for (;;) {
#if __FreeBSD__ #if __FreeBSD__
static const timespec ts = Time::zero(); static const timespec ts = Time::zero();
int evcnt = kevent(pollFD, nullptr, 0, events, maxPoll, &ts); evcnt = kevent(pollFD, nullptr, 0, events, maxPoll, &ts);
#else // __linux__ below #else // __linux__ below
int evcnt = epoll_wait(pollFD, events, maxPoll, 0); evcnt = epoll_wait(pollFD, events, maxPoll, 0);
#endif #endif
if (evcnt < 0) { GENASSERT1(errno == EINTR, errno); } // gracefully handle EINTR if (evcnt > 0) break;
if (evcnt < 0) { GENASSERT1(errno == EINTR, errno); } // gracefully handle EINTR
_lfEventEngine->blockPollFD(pollFD);
}
if (paused) pauseSem.P(); if (paused) pauseSem.P();
return evcnt; return evcnt;
} }
......
...@@ -44,11 +44,13 @@ bool BaseProcessor::findWork() { ...@@ -44,11 +44,13 @@ bool BaseProcessor::findWork() {
#endif #endif
for (size_t spin = 0; spin < spinMax; spin += 1) { for (size_t spin = 0; spin < spinMax; spin += 1) {
if (StackContext::idleYield(_friend<BaseProcessor>())) return true; if (StackContext::idleYield(_friend<BaseProcessor>())) return true;
if (terminate) return true;
Pause();
} }
return false; return false;
} }
inline bool BaseProcessor::tryDequeue(StackContext*& s) { inline bool BaseProcessor::tryLocal(StackContext*& s) {
#if TESTING_WORK_STEALING #if TESTING_WORK_STEALING
s = readyQueue.dequeueSafe(); s = readyQueue.dequeueSafe();
#else #else
...@@ -100,7 +102,7 @@ inline bool BaseProcessor::tryBorrow(StackContext*& s) { ...@@ -100,7 +102,7 @@ inline bool BaseProcessor::tryBorrow(StackContext*& s) {
StackContext* BaseProcessor::schedule(_friend<StackContext>) { StackContext* BaseProcessor::schedule(_friend<StackContext>) {
StackContext* nextStack; StackContext* nextStack;
if (tryDequeue(nextStack)) return nextStack; if (tryLocal(nextStack)) return nextStack;
if (terminate) return idleStack; if (terminate) return idleStack;
#if TESTING_POLLER_FIBRES #if TESTING_POLLER_FIBRES
if (tryBorrow(nextStack)) return nextStack; if (tryBorrow(nextStack)) return nextStack;
......
...@@ -192,7 +192,7 @@ typedef IntrusiveList<BaseProcessor,0,1> ProcessorList; ...@@ -192,7 +192,7 @@ typedef IntrusiveList<BaseProcessor,0,1> ProcessorList;
#endif #endif
class BaseProcessor : public ProcessorList::Link, public VirtualProcessor { class BaseProcessor : public ProcessorList::Link, public VirtualProcessor {
inline bool tryDequeue(StackContext*& s); inline bool tryLocal(StackContext*& s);
inline bool tryStage(StackContext*& s); inline bool tryStage(StackContext*& s);
inline bool trySteal(StackContext*& s); inline bool trySteal(StackContext*& s);
inline bool tryBorrow(StackContext*& s); inline bool tryBorrow(StackContext*& s);
......
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