Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve busy loop stability #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/rt-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,32 @@ static int create_thread(const thread_data_t *td, int index, int forked, int nfo
/*
* Function: to do some useless operation.
* TODO: improve the waste loop with more heavy functions
*
* This function must be protected against compiler optimizations, as it is
* somewhat pure and has not result.
*/
void waste_cpu_cycles(unsigned long long load_loops)
void __attribute__((noinline, optimize("O0"))) waste_cpu_cycles(unsigned long long load_loops)
{
double param, result;
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++) {
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))));
/*
* Add a "side-effect" to that function, so compilers will not
* try to remove the call to it altogether. See GCC
* documentation of "noinline" function attribute for details.
*/
asm("");
result = n/i;
}
return;
}
Expand Down