Skip to content

Commit

Permalink
waste_cpu_cycles: Use a more deterministic loop body
Browse files Browse the repository at this point in the history
Previous implementation based on ldexp() was not always giving consistent
results from one run to another. Using more basic operations without extra
branches makes the execution time of the body much more predictable, leading to
more stable calibration values and precise reproduction of duty cycles.

Signed-off-by: Douglas RAILLARD <[email protected]>
  • Loading branch information
douglas-raillard-arm authored and DouglasRaillard committed Mar 12, 2021
1 parent 9e5707f commit 884775a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/rt-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ void __attribute__((noinline, optimize("O0"))) waste_cpu_cycles(unsigned long lo
double n;
unsigned long long i;

/*
* Adjust the number of loops to get calibration values close to what
* they used to be with the previous loop body.
*/
load_loops *= 10;

param = 0.95;
n = 4;
for (i = 0 ; i < load_loops ; i++) {
Expand All @@ -220,11 +226,7 @@ void __attribute__((noinline, optimize("O0"))) waste_cpu_cycles(unsigned long lo
* documentation of "noinline" function attribute for details.
*/
asm("");

result = ldexp(param , (ldexp(param , ldexp(param , n))));
result = ldexp(param , (ldexp(param , ldexp(param , n))));
result = ldexp(param , (ldexp(param , ldexp(param , n))));
result = ldexp(param , (ldexp(param , ldexp(param , n))));
result = n/i;
}
return;
}
Expand Down

0 comments on commit 884775a

Please sign in to comment.