| 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 program |
| 7 | */ |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <pthread.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <sys/wait.h> |
| 15 | #include <unistd.h> |
| 16 | #include <stdio.h> |
| 17 | #include <sched.h> |
| 18 | #include <errno.h> |
| 19 | |
| 20 | #include <urcu/arch.h> |
| 21 | #include <urcu/assert.h> |
| 22 | |
| 23 | #ifndef DYNAMIC_LINK_TEST |
| 24 | #define _LGPL_SOURCE |
| 25 | #else |
| 26 | #define debug_yield_read() |
| 27 | #endif |
| 28 | #include <urcu.h> |
| 29 | |
| 30 | static inline void loop_sleep(unsigned long loops) |
| 31 | { |
| 32 | while (loops-- != 0) |
| 33 | caa_cpu_relax(); |
| 34 | } |
| 35 | |
| 36 | #define LOOPS 1048576 |
| 37 | #define TESTS 10 |
| 38 | |
| 39 | int main(void) |
| 40 | { |
| 41 | unsigned long i; |
| 42 | caa_cycles_t time1, time2; |
| 43 | caa_cycles_t time_tot = 0; |
| 44 | double cpl; |
| 45 | |
| 46 | for (i = 0; i < TESTS; i++) { |
| 47 | time1 = caa_get_cycles(); |
| 48 | loop_sleep(LOOPS); |
| 49 | time2 = caa_get_cycles(); |
| 50 | time_tot += time2 - time1; |
| 51 | } |
| 52 | cpl = ((double)time_tot) / (double)TESTS / (double)LOOPS; |
| 53 | |
| 54 | printf("CALIBRATION : %g cycles per loop\n", cpl); |
| 55 | printf("time_tot = %llu, LOOPS = %d, TESTS = %d\n", |
| 56 | (unsigned long long) time_tot, LOOPS, TESTS); |
| 57 | |
| 58 | return 0; |
| 59 | } |