Move include/ust/ to include/lttng/
[lttng-ust.git] / libringbuffer / smp.h
1 #ifndef _LIBRINGBUFFER_SMP_H
2 #define _LIBRINGBUFFER_SMP_H
3
4 /*
5 * libringbuffer/smp.h
6 *
7 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Dual LGPL v2.1/GPL v2 license.
10 */
11
12 #include <lttng/core.h>
13
14 /*
15 * 4kB of per-cpu data available. Enough to hold the control structures,
16 * but not ring buffers.
17 */
18 #define PER_CPU_MEM_SIZE 4096
19
20 extern int __num_possible_cpus;
21 extern void _get_num_possible_cpus(void);
22
23 static inline
24 int num_possible_cpus(void)
25 {
26 if (!__num_possible_cpus)
27 _get_num_possible_cpus();
28 return __num_possible_cpus;
29 }
30
31 /*
32 * get_cpu() returns the current CPU number. It may change due to
33 * migration, so it is only statistically accurate.
34 */
35 #ifndef UST_VALGRIND
36 static inline
37 int get_cpu(void)
38 {
39 int cpu;
40
41 cpu = sched_getcpu();
42 if (caa_likely(cpu >= 0))
43 return cpu;
44 /*
45 * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback.
46 */
47 return 0;
48 }
49
50 #else /* #else #ifndef UST_VALGRIND */
51 static inline
52 int get_cpu(void)
53 {
54 /*
55 * Valgrind does not support the sched_getcpu() vsyscall.
56 * It causes it to detect a segfault in the program and stop it.
57 * So if we want to check libust with valgrind, we have to refrain
58 * from using this call. TODO: it would probably be better to return
59 * other values too, to better test it.
60 */
61 return 0;
62 }
63 #endif /* #else #ifndef UST_VALGRIND */
64
65 static inline
66 void put_cpu(void)
67 {
68 }
69
70 #define for_each_possible_cpu(cpu) \
71 for ((cpu) = 0; (cpu) < num_possible_cpus(); (cpu)++)
72
73 #endif /* _LIBRINGBUFFER_SMP_H */
This page took 0.031999 seconds and 5 git commands to generate.