Files
linux-kernel-module-cheat/userland/gcc/busy_loop.c
Ciro Santilli 六四事件 法轮功 3aa9fbf972 busy_loop: fix type of loop variable!
2020-03-14 00:00:01 +00:00

32 lines
852 B
C

/* https://cirosantilli.com/linux-kernel-module-cheat#micro-benchmarks
* https://cirosantilli.com/linux-kernel-module-cheat#infinite-busy-loop
* https://cirosantilli.com/linux-kernel-module-cheat#benchmark-emulators-on-userland-executables */
#include <stdlib.h>
void __attribute__ ((noinline)) busy_loop(
unsigned long long max,
unsigned long long max2
) {
for (unsigned long long i = 0; i < max; i++) {
for (unsigned long long j = 0; j < max2; j++) {
__asm__ __volatile__ ("" : "+g" (j), "+g" (j) : :);
}
}
}
int main(int argc, char **argv) {
unsigned long long max, max2;
if (argc > 1) {
max = strtoll(argv[1], NULL, 0);
} else {
max = 1;
}
if (argc > 2) {
max2 = strtoll(argv[2], NULL, 0);
} else {
max2 = 1;
}
busy_loop(max, max2);
}