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 #include "ust-helper.h"
17 void lttng_ust_getcpu_init(void);
20 extern int (*lttng_get_cpu
)(void);
22 #ifdef LTTNG_UST_DEBUG_VALGRIND
25 * Fallback on cpu 0 if liblttng-ust is build with Valgrind support.
26 * get_cpu() returns the current CPU number. It may change due to
27 * migration, so it is only statistically accurate.
30 int lttng_ust_get_cpu_internal(void)
42 #if !HAVE_SCHED_GETCPU
43 #include <sys/syscall.h>
44 #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache)
46 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
49 int lttng_ust_get_cpu_internal(void)
53 ret
= __getcpu(&cpu
, NULL
, NULL
);
54 if (caa_unlikely(ret
< 0))
58 #else /* HAVE_SCHED_GETCPU */
62 * If getcpu is not implemented in the kernel, use cpu 0 as fallback.
65 int lttng_ust_get_cpu_internal(void)
70 if (caa_unlikely(cpu
< 0))
74 #endif /* HAVE_SCHED_GETCPU */
76 #elif (defined(__FreeBSD__) || defined(__CYGWIN__))
79 * FreeBSD and Cygwin do not allow query of CPU ID. Always use CPU
80 * number 0, with the assocated performance degradation on SMP.
83 int lttng_ust_get_cpu_internal(void)
89 #error "Please add support for your OS into liblttng-ust/compat.h."
95 int lttng_ust_get_cpu(void)
97 int (*getcpu
)(void) = CMM_LOAD_SHARED(lttng_get_cpu
);
99 if (caa_likely(!getcpu
)) {
100 return lttng_ust_get_cpu_internal();
106 #endif /* _LTTNG_GETCPU_H */
This page took 0.038599 seconds and 4 git commands to generate.