Commit | Line | Data |
---|---|---|
ce29b371 MJ |
1 | // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2 | // | |
3 | // SPDX-License-Identifier: GPL-2.0-or-later | |
4 | ||
fd6a23f2 | 5 | /* |
fd6a23f2 | 6 | * Userspace RCU library - test program |
fd6a23f2 MD |
7 | */ |
8 | ||
fd6a23f2 MD |
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> | |
fd6a23f2 | 17 | #include <sched.h> |
94b343fd | 18 | #include <errno.h> |
fd6a23f2 | 19 | |
ec4e58a3 | 20 | #include <urcu/arch.h> |
01477510 | 21 | #include <urcu/assert.h> |
fd6a23f2 | 22 | |
fd6a23f2 MD |
23 | #ifndef DYNAMIC_LINK_TEST |
24 | #define _LGPL_SOURCE | |
25 | #else | |
26 | #define debug_yield_read() | |
27 | #endif | |
ec4e58a3 | 28 | #include <urcu.h> |
fd6a23f2 | 29 | |
ab0aacbe | 30 | static inline void loop_sleep(unsigned long loops) |
fd6a23f2 | 31 | { |
ab0aacbe | 32 | while (loops-- != 0) |
06f22bdb | 33 | caa_cpu_relax(); |
fd6a23f2 MD |
34 | } |
35 | ||
36 | #define LOOPS 1048576 | |
37 | #define TESTS 10 | |
38 | ||
70469b43 | 39 | int main(void) |
fd6a23f2 MD |
40 | { |
41 | unsigned long i; | |
3fa18286 MD |
42 | caa_cycles_t time1, time2; |
43 | caa_cycles_t time_tot = 0; | |
85d2a666 | 44 | double cpl; |
fd6a23f2 MD |
45 | |
46 | for (i = 0; i < TESTS; i++) { | |
06f22bdb | 47 | time1 = caa_get_cycles(); |
fd6a23f2 | 48 | loop_sleep(LOOPS); |
06f22bdb | 49 | time2 = caa_get_cycles(); |
fd6a23f2 MD |
50 | time_tot += time2 - time1; |
51 | } | |
85d2a666 | 52 | cpl = ((double)time_tot) / (double)TESTS / (double)LOOPS; |
fd6a23f2 | 53 | |
85d2a666 PM |
54 | printf("CALIBRATION : %g cycles per loop\n", cpl); |
55 | printf("time_tot = %llu, LOOPS = %d, TESTS = %d\n", | |
9ee07024 | 56 | (unsigned long long) time_tot, LOOPS, TESTS); |
fd6a23f2 MD |
57 | |
58 | return 0; | |
59 | } |