Commit | Line | Data |
---|---|---|
2b2d6ff7 MD |
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 | ||
2b2d6ff7 MD |
22 | #include <urcu/compiler.h> |
23 | #include <sched.h> | |
24 | ||
25 | #ifdef UST_VALGRIND | |
26 | ||
27 | /* | |
28 | * Fallback on cpu 0 if liblttng-ust is build with Valgrind support. | |
29 | * get_cpu() returns the current CPU number. It may change due to | |
30 | * migration, so it is only statistically accurate. | |
31 | */ | |
32 | static inline | |
33 | int lttng_ust_get_cpu(void) | |
34 | { | |
35 | return 0; | |
36 | } | |
37 | ||
38 | #else | |
39 | ||
40 | /* | |
41 | * If getcpu is not implemented in the kernel, use cpu 0 as fallback. | |
42 | */ | |
43 | static inline | |
44 | int lttng_ust_get_cpu(void) | |
45 | { | |
46 | int cpu; | |
47 | ||
48 | cpu = sched_getcpu(); | |
49 | if (caa_unlikely(cpu < 0)) | |
50 | return 0; | |
51 | return cpu; | |
52 | } | |
53 | ||
54 | #endif | |
55 | ||
56 | #endif /* _LTTNG_GETCPU_H */ |