]> git.sesse.net Git - nageru/commitdiff
Tweak queue length policy to avoid pointless safe point increases.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 22:34:02 +0000 (00:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 22:34:02 +0000 (00:34 +0200)
mixer.cpp
mixer.h

index f0b06941225fb78d2e8f1ac35ac89698a7077413..d65cdacf44ee9aa08e71fe02ca95222c17de4416 100644 (file)
--- 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 af976985c91b3a52e442debb6e19e1c89c0e41ca..ee701e5b9815815f25da5db2d8e0817461ccf52f 100644 (file)
--- 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 {