Add check for invalid timer values from the DummyBackend
authorTim Mayberry <mojofunk@gmail.com>
Fri, 11 Sep 2015 12:29:52 +0000 (22:29 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Wed, 16 Sep 2015 01:22:16 +0000 (11:22 +1000)
Needed for systems where the Windows QPC timer returns erratic values

libs/ardour/ardour/dsp_load_calculator.h
libs/ardour/dsp_load_calculator.cc

index 6e1ac25cb0bcb45a7df4182901f63941d89d12c2..f3c5fea2274b356deef886d2996062923734d818 100644 (file)
@@ -88,6 +88,8 @@ public:
 private: // methods
        static uint32_t max_value_history () { return 16; }
 
+       int64_t max_timer_error () { return 4 * m_max_time_us; }
+
 private: // data
        int64_t m_max_time_us;
        int64_t m_start_timestamp_us;
index 99147c6a14809704ea751c01f1ac03f6462e9f57..6b8e2b70e7fb6aa84641bf71aa59d1ad145a559e 100644 (file)
@@ -28,6 +28,19 @@ DSPLoadCalculator::set_stop_timestamp_us(int64_t stop_timestamp_us)
        // which would mean consistent overhead for small values of m_max_time_us
 
        m_stop_timestamp_us = stop_timestamp_us;
+
+       /* querying the performance counter can fail occasionally (-1).
+        * Also on some multi-core systems, timers are CPU specific and not
+        * synchronized. We assume they differ more than a few milliseconds
+        * (4 * nominal cycle time) and simply ignore cases where the
+        * execution switches cores.
+        */
+       if (m_start_timestamp_us < 0 || m_stop_timestamp_us < 0 ||
+           m_start_timestamp_us > m_stop_timestamp_us ||
+           elapsed_time_us() > max_timer_error()) {
+                  return;
+       }
+
        float load = 0;
 
        if (elapsed_time_us() > m_max_time_us) {