Fix: counter-api: always inline counter add function
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 6 Jan 2021 20:07:01 +0000 (15:07 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Jan 2021 16:39:43 +0000 (11:39 -0500)
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 <mathieu.desnoyers@efficios.com>
Change-Id: I1adccd1382e71abc5880e0351d976b779245468a

include/counter/counter-api.h

index 12520445fb30a8538ac1f958ce955149916ffcda..fbc65818858f6128559abbfb978b0f31c4b81863 100644 (file)
@@ -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)
 {
This page took 0.027239 seconds and 5 git commands to generate.