Skip to content

Commit

Permalink
damc: cpufreq: ignore first measure after changing frequency
Browse files Browse the repository at this point in the history
The measure cause bouncing between frequencies.
  • Loading branch information
amurzeau committed Aug 22, 2024
1 parent 5240e8e commit 0094a1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions damc/damc_simple_lib/CPUFrequencyScaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CPUFrequencyScaling::CPUFrequencyScaling(OscRoot* oscRoot)
oscRoot(oscRoot),
oscCurrentFrequency(this, "freq", SystemCoreClock),
current_ahb_divider(1),
recent_ahb_divider_change(false),
max_cpu_usage_ratio_per_million(0),
cpu_usage_points(0),
cpu_usage_points_target(0) {
Expand All @@ -63,6 +64,12 @@ void CPUFrequencyScaling::resetFrequencyToMaxPerformance() {
}

void CPUFrequencyScaling::notifyCurrentCpuUsage(uint32_t cpu_usage_ratio_per_million) {
// Skip first measure after a frequency change
if(recent_ahb_divider_change) {
recent_ahb_divider_change = false;
return;
}

cpu_usage_points++;
if(cpu_usage_ratio_per_million > max_cpu_usage_ratio_per_million) {
max_cpu_usage_ratio_per_million = cpu_usage_ratio_per_million;
Expand Down Expand Up @@ -120,6 +127,7 @@ uint32_t CPUFrequencyScaling::setAHBDivider(uint32_t divider) {
HAL_InitTick(TICK_INT_PRIORITY);

current_ahb_divider = ahb_divider;
recent_ahb_divider_change = true;

// Reset cpu usage stats
cpu_usage_points = 0;
Expand Down
1 change: 1 addition & 0 deletions damc/damc_simple_lib/CPUFrequencyScaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CPUFrequencyScaling : public OscContainer {
OscRoot* oscRoot;
OscReadOnlyVariable<int32_t> oscCurrentFrequency;
uint32_t current_ahb_divider;
bool recent_ahb_divider_change;

uint32_t max_cpu_usage_ratio_per_million;
uint32_t cpu_usage_points;
Expand Down

0 comments on commit 0094a1e

Please sign in to comment.