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 committed Oct 8, 2019
1 parent 5c53e55 commit ca88d46
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 @@ -206,6 +206,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 @@ -215,11 +221,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 ca88d46

Please sign in to comment.