Skip to content

Commit

Permalink
Fix JackEngineControl::CalcCPULoad for max value
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Jan 28, 2025
1 parent 56bfdcb commit e90cdfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions common/JackEngineControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,

// 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)) {
if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0 || fRollingClientUsecsCnt == fRollingInterval)) {
jack_time_t avg_usecs = 0;
jack_time_t max_usecs = 0;

Expand All @@ -74,6 +74,12 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,

fMaxUsecs = JACK_MAX(fMaxUsecs, max_usecs);

if (fRollingClientUsecsCnt == fRollingInterval)
{
fMaxUsecs = max_usecs;
fRollingClientUsecsCnt = 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));
Expand All @@ -83,7 +89,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,
}

fCPULoad = ((1.f - (float(fSpareUsecs) / float(fPeriodUsecs))) * 50.f + (fCPULoad * 0.5f));
fMaxCPULoad = 1.f - (float(fMaxUsecs) / float(fPeriodUsecs));
fMaxCPULoad = (1.f - float(fMaxUsecs < fPeriodUsecs ? fPeriodUsecs - fMaxUsecs : 0) / float(fPeriodUsecs)) * 100.f;
}

fRollingClientUsecsCnt++;
Expand Down
4 changes: 2 additions & 2 deletions common/JackEngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
jack_time_t fMaxUsecs;
jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
unsigned int fRollingClientUsecsCnt;
int fRollingClientUsecsIndex;
int fRollingInterval;
unsigned int fRollingClientUsecsIndex;
unsigned int fRollingInterval;
float fCPULoad;
float fMaxCPULoad;

Expand Down

0 comments on commit e90cdfa

Please sign in to comment.