From 16a3d5c40e9b53383ba36cd13cd4fe5449f0570e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 3 Apr 2016 00:34:02 +0200 Subject: [PATCH] Tweak queue length policy to avoid pointless safe point increases. --- mixer.cpp | 6 +++++- mixer.h | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index f0b0694..d65cdac 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -114,15 +114,19 @@ string generate_local_dump_filename(int frame) void QueueLengthPolicy::update_policy(int queue_length) { if (queue_length < 0) { // Starvation. - if (safe_queue_length < 5) { + if (been_at_safe_point_since_last_starvation && safe_queue_length < 5) { ++safe_queue_length; fprintf(stderr, "Card %u: Starvation, increasing safe limit to %u frames\n", card_index, safe_queue_length); } frames_with_at_least_one = 0; + been_at_safe_point_since_last_starvation = false; return; } if (queue_length > 0) { + if (queue_length >= int(safe_queue_length)) { + been_at_safe_point_since_last_starvation = true; + } if (++frames_with_at_least_one >= 50 && safe_queue_length > 0) { --safe_queue_length; fprintf(stderr, "Card %u: Spare frames for more than 50 frames, reducing safe limit to %u frames\n", diff --git a/mixer.h b/mixer.h index af97698..ee701e5 100644 --- a/mixer.h +++ b/mixer.h @@ -71,10 +71,12 @@ class QSurfaceFormat; // // N is reduced as follows: If the queue has had at least one spare frame for // at least 50 (master) frames (ie., it's been too conservative for a second), -// we reduce N by 1 and reset the timers. +// we reduce N by 1 and reset the timers. TODO: Only do this if N ever actually +// touched the limit. // -// Whenever the queue is starved (we needed a frame but there was none), N was -// obviously too low, so we increment N. We will never set N above 5, though. +// Whenever the queue is starved (we needed a frame but there was none), +// and we've been at N since the last starvation, N was obviously too low, +// so we increment it. We will never set N above 5, though. class QueueLengthPolicy { public: QueueLengthPolicy() {} @@ -82,6 +84,7 @@ public: this->card_index = card_index; safe_queue_length = 0; frames_with_at_least_one = 0; + been_at_safe_point_since_last_starvation = false; } void update_policy(int queue_length); // Give in -1 for starvation. @@ -91,6 +94,7 @@ private: unsigned card_index; // For debugging only. unsigned safe_queue_length = 0; // Called N in the comments. unsigned frames_with_at_least_one = 0; + bool been_at_safe_point_since_last_starvation = false; }; class Mixer { -- 2.39.2