From b20a541d7ef07f218beb6239beb13c30e8b52a93 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 28 Jun 2021 14:47:18 -0600 Subject: [PATCH] change PBD::microseconds_t to a signed type and check for -1 in TimingStats::update This may help a Windows issue with the return value of QueryPerformanceCounter --- libs/ardour/ardour/plugin_insert.h | 2 +- libs/ardour/plugin_insert.cc | 2 +- libs/pbd/pbd/microseconds.h | 2 +- libs/pbd/pbd/timing.h | 24 ++++++++++++------------ libs/pbd/timing.cc | 10 +++++----- libs/surfaces/mackie/surface.cc | 2 +- libs/surfaces/us2400/surface.cc | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h index 8b4b55f6e4..e992416333 100644 --- a/libs/ardour/ardour/plugin_insert.h +++ b/libs/ardour/ardour/plugin_insert.h @@ -198,7 +198,7 @@ public: bool load_preset (Plugin::PresetRecord); bool provides_stats () const; - bool get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const; + bool get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& avg, double& dev) const; void clear_stats (); /** A control that manipulates a plugin parameter (control port). */ diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 1d91bc76be..d337ee44f4 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -3383,7 +3383,7 @@ PluginInsert::provides_stats () const } bool -PluginInsert::get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const +PluginInsert::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& avg, double& dev) const { /* TODO: consider taking a try/lock: Don't run concurrently with * TimingStats::update, TimingStats::reset. diff --git a/libs/pbd/pbd/microseconds.h b/libs/pbd/pbd/microseconds.h index 0b61f9247c..b4abce60bf 100644 --- a/libs/pbd/pbd/microseconds.h +++ b/libs/pbd/pbd/microseconds.h @@ -26,7 +26,7 @@ #include "pbd/libpbd_visibility.h" namespace PBD { - typedef uint64_t microseconds_t; + typedef int64_t microseconds_t; LIBPBD_API microseconds_t get_microseconds(); void microsecond_timer_init (); } diff --git a/libs/pbd/pbd/timing.h b/libs/pbd/pbd/timing.h index c6a7cf089e..303727ab9f 100644 --- a/libs/pbd/pbd/timing.h +++ b/libs/pbd/pbd/timing.h @@ -116,8 +116,7 @@ public: return elapsed () / 1000; } -private: - + protected: microseconds_t m_start_val; microseconds_t m_last_val; @@ -138,17 +137,18 @@ public: reset (); } else { Timing::update (); - calc (); - } - } - /* interval computed externally */ - void update (microseconds_t interval) - { - if (_queue_reset) { - reset (); - } else { - Timing::update (interval); + /* 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_val < 0 || m_last_val < 0 || m_start_val > m_last_val) { + return; + } + calc (); } } diff --git a/libs/pbd/timing.cc b/libs/pbd/timing.cc index 44b0701807..3d11039d74 100644 --- a/libs/pbd/timing.cc +++ b/libs/pbd/timing.cc @@ -26,17 +26,17 @@ namespace PBD { bool -get_min_max_avg_total (const std::vector& values, uint64_t& min, uint64_t& max, uint64_t& avg, uint64_t& total) +get_min_max_avg_total (const std::vector& values, microseconds_t& min, microseconds_t& max, microseconds_t& avg, microseconds_t& total) { if (values.empty()) { return false; } total = 0; - min = std::numeric_limits::max(); + min = std::numeric_limits::max(); max = 0; avg = 0; - for (std::vector::const_iterator ci = values.begin(); ci != values.end(); ++ci) { + for (std::vector::const_iterator ci = values.begin(); ci != values.end(); ++ci) { total += *ci; min = std::min (min, *ci); max = std::max (max, *ci); @@ -47,11 +47,11 @@ get_min_max_avg_total (const std::vector& values, uint64_t& min, uint6 } std::string -timing_summary (const std::vector& values) +timing_summary (const std::vector& values) { std::ostringstream oss; - uint64_t min, max, avg, total; + microseconds_t min, max, avg, total; if (get_min_max_avg_total (values, min, max, avg, total)) { oss << "Count: " << values.size() diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc index 65f9f23d53..891856308f 100644 --- a/libs/surfaces/mackie/surface.cc +++ b/libs/surfaces/mackie/surface.cc @@ -951,7 +951,7 @@ Surface::zero_controls () } void -Surface::periodic (uint64_t now_usecs) +Surface::periodic (PBD::microseconds_t now_usecs) { master_gain_changed(); for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { diff --git a/libs/surfaces/us2400/surface.cc b/libs/surfaces/us2400/surface.cc index f22bca5dbf..2f55c30d55 100644 --- a/libs/surfaces/us2400/surface.cc +++ b/libs/surfaces/us2400/surface.cc @@ -909,7 +909,7 @@ Surface::zero_controls () } void -Surface::periodic (uint64_t now_usecs) +Surface::periodic (PBD::microseconds_t now_usecs) { if (_active) { master_gain_changed();