Skip to content

Commit

Permalink
Add option to prioritize timers
Browse files Browse the repository at this point in the history
Summary: libev allows you to set prioritiy for watchers. This sets the priority of timers to the max, for both libev timer watchers and the timer fds. It's not clear if this will make a big difference

Reviewed By: kvtsoy

Differential Revision: D65384729

fbshipit-source-id: 95e7882d63254311caa8e99eff29a4d6c92901c3
  • Loading branch information
Matt Joras authored and facebook-github-bot committed Nov 3, 2024
1 parent 0f61a4d commit a2514f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion quic/common/events/LibevQuicEventBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void LibevQuicEventBase::scheduleLibevTimeoutImpl(
libEvTimeoutCallback,
seconds /* after */,
0. /* repeat */);
if (prioritizeTimers_) {
ev_set_priority(&wrapper->ev_timer_, EV_MAXPRI);
}
setImplHandle(timerCallback, wrapper);
} else {
// We already have a wrapper. Just re-arm it.
Expand All @@ -144,7 +147,8 @@ void LibevQuicEventBase::scheduleTimerFDTimeoutImpl(
if (wrapper == nullptr) {
// This is the first time this timer callback is getting scheduled. Create
// a wrapper for it.
wrapper = new TimerCallbackWrapperTimerFD(timerCallback, ev_loop_);
wrapper = new TimerCallbackWrapperTimerFD(
timerCallback, ev_loop_, prioritizeTimers_);
wrapper->ev_io_watcher_.data = wrapper;
setImplHandle(timerCallback, wrapper);
}
Expand Down
13 changes: 11 additions & 2 deletions quic/common/events/LibevQuicEventBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class LibevQuicEventBase
#endif
}

void prioritizeTimers() {
prioritizeTimers_ = true;
}

struct ev_loop* getLibevLoop() {
return ev_loop_;
}
Expand Down Expand Up @@ -191,9 +195,10 @@ class LibevQuicEventBase
class TimerCallbackWrapperTimerFD
: public QuicTimerCallback::TimerCallbackImpl {
public:
explicit TimerCallbackWrapperTimerFD(
TimerCallbackWrapperTimerFD(
QuicTimerCallback* callback,
struct ev_loop* ev_loop)
struct ev_loop* ev_loop,
bool prioritizeTimers)
: callback_(callback), ev_loop_(ev_loop) {
#if defined(HAS_TIMERFD)
ev_io_watcher_.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
Expand All @@ -211,6 +216,9 @@ class LibevQuicEventBase
},
ev_io_watcher_.fd,
EV_READ);
if (prioritizeTimers) {
ev_set_priority(&ev_io_watcher_, EV_MAXPRI);
}
#else
LOG(FATAL) << "TimerFD not supported on this platform";
#endif
Expand Down Expand Up @@ -339,5 +347,6 @@ class LibevQuicEventBase
ev_timer ev_timer_internal_;
bool internalTimerInitialized_{false};
bool useTimerFd_{false};
bool prioritizeTimers_{false};
};
} // namespace quic

0 comments on commit a2514f0

Please sign in to comment.