Implement lttng_ust_get_cpu()
[lttng-ust.git] / libringbuffer / getcpu.h
1 #ifndef _LTTNG_GETCPU_H
2 #define _LTTNG_GETCPU_H
3
4 /*
5 * Copyright (c) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #define _GNU_SOURCE
23 #include <urcu/compiler.h>
24 #include <sched.h>
25
26 #ifdef UST_VALGRIND
27
28 /*
29 * Fallback on cpu 0 if liblttng-ust is build with Valgrind support.
30 * get_cpu() returns the current CPU number. It may change due to
31 * migration, so it is only statistically accurate.
32 */
33 static inline
34 int lttng_ust_get_cpu(void)
35 {
36 return 0;
37 }
38
39 #else
40
41 /*
42 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
43 */
44 static inline
45 int lttng_ust_get_cpu(void)
46 {
47 int cpu;
48
49 cpu = sched_getcpu();
50 if (caa_unlikely(cpu < 0))
51 return 0;
52 return cpu;
53 }
54
55 #endif
56
57 #endif /* _LTTNG_GETCPU_H */
This page took 0.031064 seconds and 5 git commands to generate.