Hi Quiang,

Please test the attached patch.

Cheers

On Sat, Jan 09, 2021 at 05:40:48AM +0000, Zhang, Qiang wrote:
> 
> 
> ________________________________________
> 发件人: Jonathan Rajotte-Julien <jonathan.rajotte-jul...@efficios.com>
> 发送时间: 2021年1月8日 0:54
> 收件人: Zhang, Qiang
> 抄送: lttng-dev
> 主题: Re: 回复: help modpost: "__bad_cmpxchg"
> 
> [Please note this e-mail is from an EXTERNAL e-mail address]
> 
> >Hi,
> >
> >Note
> >  The initial email was sent to the "owner" of the mailing list. Please
> >  *always* send email to the mailing list directly: 
> > lttng->d...@lists.lttng.org .
> > Otherwise we will not be interested in helping you in the future.
> >
> >Sorry forgot to ask you the following.
> >
> >What is the arm CPU you are compiling against? The more details the >more we 
> >can
> >help here.
> >
> >Please provide the .config file for the kernel (via pastebin please) and >the
>  
>  Hello
> 
>  Attached is the kernel configuration file
>  and compiler configuration file.
> 
>  bsp is xilinx-zynq (arm32, armv7),  v5.10 kernel have delete 
>  'CONFIG_OPTIMIZE_INLINING'  config option. 
> 
>  Cheers
> 
> >compiler used. Mathieu Desnoyers (CompuDJ) might have a lead >regarding 
> >cmpxchg
> >and __bad_cmpxchg linker error trick used by the implementation and >the
> >optimized inlining config option (CONFIG_OPTIMIZE_INLINING).
> >
> >These should help us validate this lead.
> 
> >
> >Cheers
> >
> >On Thu, Jan 07, 2021 at 01:20:54AM +0000, Zhang, Qiang wrote:
> >
> >
> > ________________________________________
> > 发件人: Jonathan Rajotte-Julien <jonathan.rajotte-jul...@efficios.com>
> > 发送时间: 2021年1月6日 23:03
> > 收件人: Zhang, Qiang
> > 抄送: lttng-dev-ow...@lists.lttng.org
> > 主题: Re: help modpost: "__bad_cmpxchg"
> >
> > [Please note this e-mail is from an EXTERNAL e-mail address]
> >
> > >Hi,
> > >
> > >What the kernel version are you compiling against?
> >
> >
> >    kernel version 5.10.2
> >    lttng-modules master branch commit :
> >    61e631e93e512b636ea6d52796bcce1c485a551b
> >
> >     Cheers
> >
> > >
> > >Cheers
> > >
> > >On Wed, Jan 06, 2021 at 05:20:06AM +0000, Zhang, Qiang wrote:
> > >
> > >
> > > The following error occurred when I compiled lttng modules under armv7 
> > > architecture
> > >
> > > ERROR: modpost: "__bad_cmpxchg" 
> > > [/buildarea1/OnDemand_CI_Build_World/build_dir/12251727-build_world/xilinx-zynq-standard-std-OE/build/tmp-glibc/work/xilinx_zynq-wrs-linux-gnueabi/lttng-modules/2.12.3+gitAUTOINC+61e631e93e-r0/git/src/lttng-counter-client-percpu-64-modular.ko]
> > >  undefined!
> > >
> > > ERROR: modpost: "__bad_cmpxchg" 
> > > [/buildarea1/OnDemand_CI_Build_World/build_dir/12251727-build_world/xilinx-zynq-standard-std-OE/build/tmp-glibc/work/xilinx_zynq-wrs-linux-gnueabi/lttng-modules/2.12.3+gitAUTOINC+61e631e93e-r0/git/src/lttng-counter-client-percpu-32-modular.ko]
> > >  undefined!
> > >
> > > I find  under the condition of
> > >
> > > COUNTER_SIZE_32_BIT,  cmpxchg_local  function trigger error in 
> > > counter-api.h file.
> > >
> > > is cmpxchg_local is support in amv7?
> >
> > --
> > Jonathan Rajotte-Julien
> > EfficiOS
> 
> --
> Jonathan Rajotte-Julien
> EfficiOS


> ./arm-wrs-linux-gnueabi-gcc -v
> Using built-in specs.
> COLLECT_GCC=./arm-wrs-linux-gnueabi-gcc
> COLLECT_LTO_WRAPPER=/buildarea1/qzhang2/jira/LINCD-3904/build/tmp-glibc/work/armv7at2hf-neon-wrs-linux-gnueabi/libgcc/10.2.0-r0/recipe-sysroot-native/usr/bin/arm-wrs-linux-gnueabi/../../libexec/arm-wrs-linux-gnueabi/gcc/arm-wrs-linux-gnueabi/10.2.0/lto-wrapper
> Target: arm-wrs-linux-gnueabi
> Configured with: 
> ../../../../../../work-shared/gcc-10.2.0-r0/gcc-10.2.0/configure 
> --build=x86_64-linux --host=x86_64-linux --target=arm-wrs-linux-gnueabi 
> --prefix=/host-native/usr --exec_prefix=/host-native/usr 
> --bindir=/host-native/usr/bin/arm-wrs-linux-gnueabi 
> --sbindir=/host-native/usr/bin/arm-wrs-linux-gnueabi 
> --libexecdir=/host-native/usr/libexec/arm-wrs-linux-gnueabi 
> --datadir=/host-native/usr/share --sysconfdir=/host-native/etc 
> --sharedstatedir=/host-native/com --localstatedir=/host-native/var 
> --libdir=/host-native/usr/lib/arm-wrs-linux-gnueabi 
> --includedir=/host-native/usr/include 
> --oldincludedir=/host-native/usr/include 
> --infodir=/host-native/usr/share/info --mandir=/host-native/usr/share/man 
> --disable-silent-rules --disable-dependency-tracking 
> --with-libtool-sysroot=/host-native --enable-clocale=generic --with-gnu-ld 
> --enable-shared --enable-languages=c,c++ --enable-threads=posix 
> --disable-multilib --enable-default-pie --enable-c99 --enable-long-long 
> --enable-symvers=gnu --enable-libstdcxx-pch 
> --program-prefix=arm-wrs-linux-gnueabi- --without-local-prefix 
> --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto 
> --disable-bootstrap --with-system-zlib --with-linker-hash-style=sysv 
> --enable-linker-build-id --with-ppl=no --with-cloog=no 
> --enable-checking=release --enable-cheaders=c_global --without-isl 
> --with-gxx-include-dir=/not/exist/usr/include/c++/10.2.0 
> --with-sysroot=/not/exist --with-build-sysroot=/host 
> --enable-poison-system-directories --with-system-zlib --disable-nls 
> --with-glibc-version=2.28 --enable-initfini-array
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 10.2.0 (GCC) 
> 


-- 
Jonathan Rajotte-Julien
EfficiOS
>From f08da105102561886a9d207c56b65dd89beb0de7 Mon Sep 17 00:00:00 2001
From: Mathieu Desnoyers <mathieu.desnoy...@efficios.com>
Date: Wed, 6 Jan 2021 15:07:01 -0500
Subject: [PATCH lttng-modules] 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 <mathieu.desnoy...@efficios.com>
Change-Id: I1adccd1382e71abc5880e0351d976b779245468a
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-jul...@efficios.com>
---
 include/counter/counter-api.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

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)
 {
-- 
2.25.1

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to