File: test_looplen.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 (59 lines) | stat: -rw-r--r-- 1,153 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

/*
 * Userspace RCU library - test program
 */

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <sched.h>
#include <errno.h>

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

#ifndef DYNAMIC_LINK_TEST
#define _LGPL_SOURCE
#else
#define debug_yield_read()
#endif
#include <urcu.h>

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

#define LOOPS 1048576
#define TESTS 10

int main(void)
{
	unsigned long i;
	caa_cycles_t time1, time2;
	caa_cycles_t time_tot = 0;
	double cpl;

	for (i = 0; i < TESTS; i++) {
		time1 = caa_get_cycles();
		loop_sleep(LOOPS);
		time2 = caa_get_cycles();
		time_tot += time2 - time1;
	}
	cpl = ((double)time_tot) / (double)TESTS / (double)LOOPS;

	printf("CALIBRATION : %g cycles per loop\n", cpl);
	printf("time_tot = %llu, LOOPS = %d, TESTS = %d\n",
	       (unsigned long long) time_tot, LOOPS, TESTS);

	return 0;
}