aboutsummaryrefslogtreecommitdiff
path: root/rtc_base
diff options
context:
space:
mode:
authorMarkus Handell <handellm@webrtc.org>2020-05-26 18:09:55 +0200
committerCommit Bot <commit-bot@chromium.org>2020-05-26 17:41:51 +0000
commitb7c63ab83ae2b991ff8350bc0aa6427588629287 (patch)
treedec63ac3d5175b3a457f96e17ec5c4f989d06335 /rtc_base
parentb41316cd4c22e4cc86e899a8f9c7e96548190927 (diff)
downloadwebrtc-b7c63ab83ae2b991ff8350bc0aa6427588629287.tar.gz
PhysicalSocketServer: remove heap-based epoll_event handling.
This change deletes heap-based handling of dynamic number of epoll events handled per call to epoll, with the assumption that PSS load is likely not dominated by the epoll syscalls. This simplifies the logic in the code and removes a heap allocation. Bug: webrtc:11567 Change-Id: I34fbe1fa8bf0a037bf849a4adac1a0a333c9dd86 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175563 Commit-Queue: Markus Handell <handellm@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31358}
Diffstat (limited to 'rtc_base')
-rw-r--r--rtc_base/physical_socket_server.cc22
-rw-r--r--rtc_base/physical_socket_server.h10
2 files changed, 10 insertions, 22 deletions
diff --git a/rtc_base/physical_socket_server.cc b/rtc_base/physical_socket_server.cc
index cf65300b4a..3a95331669 100644
--- a/rtc_base/physical_socket_server.cc
+++ b/rtc_base/physical_socket_server.cc
@@ -1365,12 +1365,6 @@ bool PhysicalSocketServer::WaitSelect(int cmsWait, bool process_io) {
#if defined(WEBRTC_USE_EPOLL)
-// Initial number of events to process with one call to "epoll_wait".
-static const size_t kInitialEpollEvents = 128;
-
-// Maximum number of events to process with one call to "epoll_wait".
-static const size_t kMaxEpollEvents = 8192;
-
void PhysicalSocketServer::AddEpoll(Dispatcher* pdispatcher) {
RTC_DCHECK(epoll_fd_ != INVALID_SOCKET);
int fd = pdispatcher->GetDescriptor();
@@ -1437,20 +1431,13 @@ bool PhysicalSocketServer::WaitEpoll(int cmsWait) {
tvStop = TimeAfter(cmsWait);
}
- if (epoll_events_.empty()) {
- // The initial space to receive events is created only if epoll is used.
- epoll_events_.resize(kInitialEpollEvents);
- }
-
fWait_ = true;
-
while (fWait_) {
// Wait then call handlers as appropriate
// < 0 means error
// 0 means timeout
// > 0 means count of descriptors ready
- int n = epoll_wait(epoll_fd_, &epoll_events_[0],
- static_cast<int>(epoll_events_.size()),
+ int n = epoll_wait(epoll_fd_, epoll_events_.data(), epoll_events_.size(),
static_cast<int>(tvWait));
if (n < 0) {
if (errno != EINTR) {
@@ -1483,13 +1470,6 @@ bool PhysicalSocketServer::WaitEpoll(int cmsWait) {
}
}
- if (static_cast<size_t>(n) == epoll_events_.size() &&
- epoll_events_.size() < kMaxEpollEvents) {
- // We used the complete space to receive events, increase size for future
- // iterations.
- epoll_events_.resize(std::max(epoll_events_.size() * 2, kMaxEpollEvents));
- }
-
if (cmsWait != kForever) {
tvWait = TimeDiff(tvStop, TimeMillis());
if (tvWait < 0) {
diff --git a/rtc_base/physical_socket_server.h b/rtc_base/physical_socket_server.h
index 2f53d4d4fe..e21e53b8ec 100644
--- a/rtc_base/physical_socket_server.h
+++ b/rtc_base/physical_socket_server.h
@@ -16,6 +16,7 @@
#define WEBRTC_USE_EPOLL 1
#endif
+#include <array>
#include <memory>
#include <set>
#include <vector>
@@ -81,6 +82,9 @@ class RTC_EXPORT PhysicalSocketServer : public SocketServer {
void Update(Dispatcher* dispatcher);
private:
+ // The number of events to process with one call to "epoll_wait".
+ static constexpr size_t kNumEpollEvents = 128;
+
typedef std::set<Dispatcher*> DispatcherSet;
void AddRemovePendingDispatchers() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
@@ -95,8 +99,12 @@ class RTC_EXPORT PhysicalSocketServer : public SocketServer {
bool WaitEpoll(int cms);
bool WaitPoll(int cms, Dispatcher* dispatcher);
+ // This array is accessed in isolation by a thread calling into Wait().
+ // It's useless to use a SequenceChecker to guard it because a socket
+ // server can outlive the thread it's bound to, forcing the Wait call
+ // to have to reset the sequence checker on Wait calls.
+ std::array<epoll_event, kNumEpollEvents> epoll_events_;
const int epoll_fd_ = INVALID_SOCKET;
- std::vector<struct epoll_event> epoll_events_;
#endif // WEBRTC_USE_EPOLL
DispatcherSet dispatchers_ RTC_GUARDED_BY(crit_);
DispatcherSet pending_add_dispatchers_ RTC_GUARDED_BY(crit_);