2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef _LTTNG_GETCPU_H
8 #define _LTTNG_GETCPU_H
10 #include <urcu/compiler.h>
11 #include <urcu/system.h>
12 #include <urcu/arch.h>
14 void lttng_ust_getcpu_init(void)
15 __attribute__((visibility("hidden")));
17 extern int (*lttng_get_cpu
)(void)
18 __attribute__((visibility("hidden")));
20 #ifdef LTTNG_UST_DEBUG_VALGRIND
23 * Fallback on cpu 0 if liblttng-ust is build with Valgrind support.
24 * get_cpu() returns the current CPU number. It may change due to
25 * migration, so it is only statistically accurate.
28 int lttng_ust_get_cpu_internal(void)
40 #if !HAVE_SCHED_GETCPU
41 #include <sys/syscall.h>
42 #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache)
44 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
47 int lttng_ust_get_cpu_internal(void)
51 ret
= __getcpu(&cpu
, NULL
, NULL
);
52 if (caa_unlikely(ret
< 0))
56 #else /* HAVE_SCHED_GETCPU */
60 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
63 int lttng_ust_get_cpu_internal(void)
68 if (caa_unlikely(cpu
< 0))
72 #endif /* HAVE_SCHED_GETCPU */
74 #elif (defined(__FreeBSD__) || defined(__CYGWIN__))
77 * FreeBSD and Cygwin do not allow query of CPU ID. Always use CPU
78 * number 0, with the assocated performance degradation on SMP.
81 int lttng_ust_get_cpu_internal(void)
87 #error "Please add support for your OS into liblttng-ust/compat.h."
93 int lttng_ust_get_cpu(void)
95 int (*getcpu
)(void) = CMM_LOAD_SHARED(lttng_get_cpu
);
97 if (caa_likely(!getcpu
)) {
98 return lttng_ust_get_cpu_internal();
104 #endif /* _LTTNG_GETCPU_H */
This page took 0.032714 seconds and 4 git commands to generate.