From f2b06ce5c82dee9874917a235358fb371e23fc96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Sun, 19 Apr 2020 11:05:41 +0200 Subject: [PATCH] Reduces unnecessary thread wakeups in TaskQueuePacedSender. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL is functionally a noop but may reduce thread wakupes in some cases. In particular, consider a send task scheduled for time T. While waiting for that, a higher-priority packet than the top of the current queue is added (e.g. an audio packet), and a send is executed immediately. After sending, it resets the field indicating that a scheduled task is expected at time T. It then polls NextSendTime() and schedules a new task, likely at or very close to T. Causing unnecessary task queue churn and behavior that is more difficult to reason about. Bug: webrtc:10809 Change-Id: Ic5706f2cc06df3f27cc3e7b473d4de29a669473b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173700 Reviewed-by: Sebastian Jansson Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/master@{#31116} --- modules/pacing/task_queue_paced_sender.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/pacing/task_queue_paced_sender.cc b/modules/pacing/task_queue_paced_sender.cc index 778d79f843..a4ce9fe9d6 100644 --- a/modules/pacing/task_queue_paced_sender.cc +++ b/modules/pacing/task_queue_paced_sender.cc @@ -188,12 +188,15 @@ void TaskQueuePacedSender::MaybeProcessPackets( // anyway and clear any schedule. Timestamp next_process_time = pacing_controller_.NextSendTime(); const Timestamp now = clock_->CurrentTime(); - if ((scheduled_process_time.IsFinite() && - scheduled_process_time == next_process_time_) || + const bool is_scheduled_call = next_process_time_ == scheduled_process_time; + if (is_scheduled_call) { + // Indicate no pending scheduled call. + next_process_time_ = Timestamp::MinusInfinity(); + } + if (is_scheduled_call || (now >= next_process_time && (next_process_time_.IsInfinite() || next_process_time < next_process_time_))) { pacing_controller_.ProcessPackets(); - next_process_time_ = Timestamp::MinusInfinity(); next_process_time = pacing_controller_.NextSendTime(); }