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);
16 extern int (*lttng_get_cpu
)(void);
18 #ifdef LTTNG_UST_DEBUG_VALGRIND
21 * Fallback on cpu 0 if liblttng-ust is build with Valgrind support.
22 * get_cpu() returns the current CPU number. It may change due to
23 * migration, so it is only statistically accurate.
26 int lttng_ust_get_cpu_internal(void)
38 #if !HAVE_SCHED_GETCPU
39 #include <sys/syscall.h>
40 #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache)
42 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
45 int lttng_ust_get_cpu_internal(void)
49 ret
= __getcpu(&cpu
, NULL
, NULL
);
50 if (caa_unlikely(ret
< 0))
54 #else /* HAVE_SCHED_GETCPU */
58 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
61 int lttng_ust_get_cpu_internal(void)
66 if (caa_unlikely(cpu
< 0))
70 #endif /* HAVE_SCHED_GETCPU */
72 #elif (defined(__FreeBSD__) || defined(__CYGWIN__))
75 * FreeBSD and Cygwin do not allow query of CPU ID. Always use CPU
76 * number 0, with the assocated performance degradation on SMP.
79 int lttng_ust_get_cpu_internal(void)
85 #error "Please add support for your OS into liblttng-ust/compat.h."
91 int lttng_ust_get_cpu(void)
93 int (*getcpu
)(void) = CMM_LOAD_SHARED(lttng_get_cpu
);
95 if (caa_likely(!getcpu
)) {
96 return lttng_ust_get_cpu_internal();
102 #endif /* _LTTNG_GETCPU_H */
This page took 0.034409 seconds and 5 git commands to generate.