From c88d56cfd50d9e4591699b65901b510d8156e140 Mon Sep 17 00:00:00 2001 From: sletz Date: Mon, 10 Oct 2011 11:45:56 +0000 Subject: [PATCH] John Emmas patch for DSP CPU computation. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4547 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 5 +++++ common/JackEngineControl.cpp | 30 ++++++++++++++++++++++-------- common/JackEngineControl.h | 12 ++++++------ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 65c719ba..6e1d2648 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,11 +30,16 @@ Adrian Knoth David Garcia Garzon Valerio Pilo Chris Caudle +John Emmas --------------------------- Jackdmp changes log --------------------------- +2011-10-10 Stephane Letz + + * John Emmas patch for DSP CPU computation. + 2011-09-27 Stephane Letz * Gabriel Beddingfield patch for ALSA driver: error when source is non-native byte-order float. diff --git a/common/JackEngineControl.cpp b/common/JackEngineControl.cpp index d9ab2b16..4af6f68d 100644 --- a/common/JackEngineControl.cpp +++ b/common/JackEngineControl.cpp @@ -53,23 +53,37 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table, } // Store the execution time for later averaging - fRollingClientUsecs[fRollingClientUsecsIndex++] = last_cycle_end - fPrevCycleTime; + if (last_cycle_end > 0) + fRollingClientUsecs[fRollingClientUsecsIndex++] = last_cycle_end - fPrevCycleTime; if (fRollingClientUsecsIndex >= JACK_ENGINE_ROLLING_COUNT) fRollingClientUsecsIndex = 0; - // Every so often, recompute the current maximum use over the - // last JACK_ENGINE_ROLLING_COUNT client iterations. - - if (++fRollingClientUsecsCnt % fRollingInterval == 0) { - + // Each time we have a full set of iterations, recompute the current + // usage from the latest JACK_ENGINE_ROLLING_COUNT client entries. + if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0)) { + jack_time_t avg_usecs = 0; jack_time_t max_usecs = 0; - for (int i = 0; i < JACK_ENGINE_ROLLING_COUNT; i++) + + for (int i = 0; i < JACK_ENGINE_ROLLING_COUNT; i++) { + avg_usecs += fRollingClientUsecs[i]; // This is really a running + // total to be averaged later max_usecs = JACK_MAX(fRollingClientUsecs[i], max_usecs); + } fMaxUsecs = JACK_MAX(fMaxUsecs, max_usecs); - fSpareUsecs = jack_time_t((max_usecs < fPeriodUsecs) ? fPeriodUsecs - max_usecs : 0); + + if (max_usecs < ((fPeriodUsecs * 95) / 100)) { + // Average the values from our JACK_ENGINE_ROLLING_COUNT array + fSpareUsecs = (jack_time_t)(fPeriodUsecs - (avg_usecs / JACK_ENGINE_ROLLING_COUNT)); + } else { + // Use the 'worst case' value (or zero if we exceeded 'fPeriodUsecs') + fSpareUsecs = jack_time_t((max_usecs < fPeriodUsecs) ? fPeriodUsecs - max_usecs : 0); + } + fCPULoad = ((1.f - (float(fSpareUsecs) / float(fPeriodUsecs))) * 50.f + (fCPULoad * 0.5f)); } + + fRollingClientUsecsCnt++; } void JackEngineControl::ResetRollingUsecs() diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index 3ba54b87..412ade55 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -69,12 +69,12 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem bool fVerbose; // CPU Load - jack_time_t fPrevCycleTime; - jack_time_t fCurCycleTime; - jack_time_t fSpareUsecs; - jack_time_t fMaxUsecs; - jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT]; - int fRollingClientUsecsCnt; + jack_time_t fPrevCycleTime; + jack_time_t fCurCycleTime; + jack_time_t fSpareUsecs; + jack_time_t fMaxUsecs; + jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT]; + unsigned int fRollingClientUsecsCnt; int fRollingClientUsecsIndex; int fRollingInterval; float fCPULoad;