From: Mathieu Desnoyers Date: Wed, 6 Jan 2021 20:07:01 +0000 (-0500) Subject: Fix: counter-api: always inline counter add function X-Git-Tag: v2.13.0-rc1~56 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2b8161a4ae82a2438e553eef0828a94fb3e24ace;p=lttng-modules.git Fix: counter-api: always inline counter add function The counter add function uses cmpxchg() and cmpxchg_local() on 1, 2, 4, and 8 bytes types. In libcounter, the 8 bytes type is only supported on 64-bit architectures, but the 1, 2, 4 byte type code is present for all architectures, even though only the 4 byte code is currently used by lttng-modules. The ARM implementation of cmpxchg uses the "__bad_cmpxchg" linker error to report use of cmpxchg on an unsupported size. Considering that "inline" does not strictly mean always inline (depends on CONFIG_OPTIMIZE_INLINING on some kernels, and does not mean forced inlining in recent kernels), the compiler is free to generate a function rather than perform inlining. If that happens, then the __bad_cmpxchg linker error is generated even if the 1 and 2 bytes types are unused. Therefore, use __always_inline for functions in counter-api.h to force inlining, and therefore removal of unused code before linking, which is required by this Linux kernel __bad_cmpxchg linker error trick. Signed-off-by: Mathieu Desnoyers Change-Id: I1adccd1382e71abc5880e0351d976b779245468a --- diff --git a/include/counter/counter-api.h b/include/counter/counter-api.h index 12520445..fbc65818 100644 --- a/include/counter/counter-api.h +++ b/include/counter/counter-api.h @@ -20,7 +20,7 @@ /* * Using unsigned arithmetic because overflow is defined. */ -static inline int __lttng_counter_add(const struct lib_counter_config *config, +static __always_inline int __lttng_counter_add(const struct lib_counter_config *config, enum lib_counter_config_alloc alloc, enum lib_counter_config_sync sync, struct lib_counter *counter, @@ -226,7 +226,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, return 0; } -static inline int __lttng_counter_add_percpu(const struct lib_counter_config *config, +static __always_inline int __lttng_counter_add_percpu(const struct lib_counter_config *config, struct lib_counter *counter, const size_t *dimension_indexes, int64_t v) { @@ -243,7 +243,7 @@ static inline int __lttng_counter_add_percpu(const struct lib_counter_config *co return 0; } -static inline int __lttng_counter_add_global(const struct lib_counter_config *config, +static __always_inline int __lttng_counter_add_global(const struct lib_counter_config *config, struct lib_counter *counter, const size_t *dimension_indexes, int64_t v) { @@ -251,7 +251,7 @@ static inline int __lttng_counter_add_global(const struct lib_counter_config *co dimension_indexes, v, NULL); } -static inline int lttng_counter_add(const struct lib_counter_config *config, +static __always_inline int lttng_counter_add(const struct lib_counter_config *config, struct lib_counter *counter, const size_t *dimension_indexes, int64_t v) { @@ -266,14 +266,14 @@ static inline int lttng_counter_add(const struct lib_counter_config *config, } } -static inline int lttng_counter_inc(const struct lib_counter_config *config, +static __always_inline int lttng_counter_inc(const struct lib_counter_config *config, struct lib_counter *counter, const size_t *dimension_indexes) { return lttng_counter_add(config, counter, dimension_indexes, 1); } -static inline int lttng_counter_dec(const struct lib_counter_config *config, +static __always_inline int lttng_counter_dec(const struct lib_counter_config *config, struct lib_counter *counter, const size_t *dimension_indexes) {