File: test_cycles_per_loop.c

package info (click to toggle)
liburcu 0.15.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,356 kB
  • sloc: ansic: 23,361; xml: 23,227; sh: 6,480; makefile: 1,045; cpp: 15
file content (30 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

/*
 * Userspace RCU library - test cycles per loop
 */

#include <urcu/arch.h>
#include <stdio.h>

#define NR_LOOPS 1000000UL

static inline void loop_sleep(unsigned long loops)
{
	while (loops-- != 0)
		caa_cpu_relax();
}

int main()
{
	caa_cycles_t time1, time2;

	time1 = caa_get_cycles();
	loop_sleep(NR_LOOPS);
	time2 = caa_get_cycles();
	printf("CPU clock cycles per loop: %g\n", (time2 - time1) /
						  (double)NR_LOOPS);
	return 0;
}