21 #include "JackClientInterface.h"
22 #include "JackEngineControl.h"
23 #include "JackGraphManager.h"
24 #include "JackClientControl.h"
31 static inline jack_time_t JACK_MAX(jack_time_t a, jack_time_t b)
33 return (a < b) ? b : a;
36 void JackEngineControl::CalcCPULoad(JackClientInterface** table,
37 JackGraphManager* manager,
38 jack_time_t cur_cycle_begin,
39 jack_time_t prev_cycle_end)
41 fPrevCycleTime = fCurCycleTime;
42 fCurCycleTime = cur_cycle_begin;
43 jack_time_t last_cycle_end = prev_cycle_end;
47 for (
int i = fDriverNum; i < CLIENT_NUM; i++) {
48 JackClientInterface* client = table[i];
49 JackClientTiming* timing = manager->GetClientTiming(i);
50 if (client && client->GetClientControl()->fActive && timing->fStatus == Finished)
51 last_cycle_end = JACK_MAX(last_cycle_end, timing->fFinishedAt);
56 if (last_cycle_end > 0)
57 fRollingClientUsecs[fRollingClientUsecsIndex++] = last_cycle_end - fPrevCycleTime;
58 if (fRollingClientUsecsIndex >= JACK_ENGINE_ROLLING_COUNT)
59 fRollingClientUsecsIndex = 0;
63 if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0)) {
64 jack_time_t avg_usecs = 0;
65 jack_time_t max_usecs = 0;
67 for (
int i = 0; i < JACK_ENGINE_ROLLING_COUNT; i++) {
68 avg_usecs += fRollingClientUsecs[i];
70 max_usecs = JACK_MAX(fRollingClientUsecs[i], max_usecs);
73 fMaxUsecs = JACK_MAX(fMaxUsecs, max_usecs);
75 if (max_usecs < ((fPeriodUsecs * 95) / 100)) {
77 fSpareUsecs = (jack_time_t)(fPeriodUsecs - (avg_usecs / JACK_ENGINE_ROLLING_COUNT));
80 fSpareUsecs = jack_time_t((max_usecs < fPeriodUsecs) ? fPeriodUsecs - max_usecs : 0);
83 fCPULoad = ((1.f - (float(fSpareUsecs) / float(fPeriodUsecs))) * 50.f + (fCPULoad * 0.5f));
86 fRollingClientUsecsCnt++;
89 void JackEngineControl::ResetRollingUsecs()
91 memset(fRollingClientUsecs, 0,
sizeof(fRollingClientUsecs));
92 fRollingClientUsecsIndex = 0;
93 fRollingClientUsecsCnt = 0;
95 fRollingInterval = int(floor((JACK_ENGINE_ROLLING_INTERVAL * 1000.f) / fPeriodUsecs));
98 void JackEngineControl::NotifyXRun(jack_time_t callback_usecs,
float delayed_usecs)
100 ResetFrameTime(callback_usecs);
101 fXrunDelayedUsecs = delayed_usecs;
102 if (delayed_usecs > fMaxDelayedUsecs) {
103 fMaxDelayedUsecs = delayed_usecs;