| 1 | // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | |
| 5 | /* |
| 6 | * Userspace RCU library - test cycles per loop |
| 7 | */ |
| 8 | |
| 9 | #include <urcu/arch.h> |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | #define NR_LOOPS 1000000UL |
| 13 | |
| 14 | static inline void loop_sleep(unsigned long loops) |
| 15 | { |
| 16 | while (loops-- != 0) |
| 17 | caa_cpu_relax(); |
| 18 | } |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | caa_cycles_t time1, time2; |
| 23 | |
| 24 | time1 = caa_get_cycles(); |
| 25 | loop_sleep(NR_LOOPS); |
| 26 | time2 = caa_get_cycles(); |
| 27 | printf("CPU clock cycles per loop: %g\n", (time2 - time1) / |
| 28 | (double)NR_LOOPS); |
| 29 | return 0; |
| 30 | } |