Skip to content

Commit

Permalink
reactor: switch the syscall worker thread from signals to eventfd
Browse files Browse the repository at this point in the history
Instead of using a signal to wake the reactor thread, use the eventfd
which we're already using for smp wakeups.
  • Loading branch information
avikivity committed Dec 16, 2018
1 parent 51c2917 commit dd948d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/seastar/core/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ private:
};

class thread_pool {
reactor* _reactor;
uint64_t _aio_threaded_fallbacks = 0;
#ifndef HAVE_OSV
syscall_work_queue inter_thread_wq;
posix_thread _worker_thread;
std::atomic<bool> _stopped = { false };
std::atomic<bool> _main_thread_idle = { false };
pthread_t _notify;
public:
explicit thread_pool(sstring thread_name);
explicit thread_pool(reactor* r, sstring thread_name);
~thread_pool();
template <typename T, typename Func>
future<T> submit(Func func) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ reactor::reactor(unsigned id)
, _io_context(0)
, _reuseport(posix_reuseport_detect())
, _task_quota_timer_thread(&reactor::task_quota_timer_thread_fn, this)
, _thread_pool(seastar::format("syscall-{}", id)) {
, _thread_pool(this, seastar::format("syscall-{}", id)) {
_task_queues.push_back(std::make_unique<task_queue>(0, "main", 1000));
_task_queues.push_back(std::make_unique<task_queue>(1, "atexit", 1000));
_at_destroy_tasks = _task_queues.back().get();
Expand Down Expand Up @@ -3787,8 +3787,7 @@ void smp_message_queue::start(unsigned cpuid) {

/* not yet implemented for OSv. TODO: do the notification like we do class smp. */
#ifndef HAVE_OSV
thread_pool::thread_pool(sstring name) : _worker_thread([this, name] { work(name); }), _notify(pthread_self()) {
engine()._signals.handle_signal(SIGUSR1, [this] { inter_thread_wq.complete(); });
thread_pool::thread_pool(reactor* r, sstring name) : _reactor(r), _worker_thread([this, name] { work(name); }) {
}

void thread_pool::work(sstring name) {
Expand All @@ -3815,7 +3814,8 @@ void thread_pool::work(sstring name) {
inter_thread_wq._completed.push(wi);
}
if (_main_thread_idle.load(std::memory_order_seq_cst)) {
pthread_kill(_notify, SIGUSR1);
uint64_t one = 1;
::write(_reactor->_notify_eventfd.get(), &one, 8);
}
}
}
Expand Down

0 comments on commit dd948d1

Please sign in to comment.