Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake:reuse OpenAMP own CMake script for CMake build #12516

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

xuxin930
Copy link
Contributor

@xuxin930 xuxin930 commented Jun 17, 2024

Summary

  • use nuttx_add_external_library to reuse OpenAMP CMake scripts for CMake build
  • automatically detect HAVE_STDATOMIC_H with CMake
  • add support for 64-bit ATOMIC checks to both Makefile and CMake

Impact

Testing

CI test

openamp/libmetal.cmake Outdated Show resolved Hide resolved
@xuxin930
Copy link
Contributor Author

hi @anchao @yf13
i try to reuse OpenAMP own CMake scrpits
this will directly solve the existing compilation problem, and automatically detect HAVEATOMIC_H
please review

@xuxin930 xuxin930 changed the title cmake:openamp/libmetal.cmake sync with libmetal.defs cmake:reuse OpenAMP own CMake script for CMake build Jun 20, 2024
@xuxin930 xuxin930 force-pushed the cmake-bugfig-0617 branch 2 times, most recently from f2bb8ea to b0d1c73 Compare June 24, 2024 12:04
@xuxin930
Copy link
Contributor Author

image
image

The same link error also appears in the Makefile compilation. Does anyone know why this is?

@xiaoxiang781216
Copy link
Contributor

please talk with @CV-Bowen

@anchao
Copy link
Contributor

anchao commented Jun 25, 2024

The same link error also appears in the Makefile compilation. Does anyone know why this is?

arm32 toolchain does not support 64-bit atomic, which may require special processing in this architecture, see:
#10401 (comment)

@xuxin930
Copy link
Contributor Author

xuxin930 commented Jun 25, 2024

arm32 toolchain does not support 64-bit atomic, which may require special processing in this architecture, see: #10401 (comment)

https://github.com/OpenAMP/libmetal/blob/3aee6be866b190d2e2b4997fedbd976a0c37c0c6/lib/io.h#L288-L292
I found that we can use this macro NO_ATOMIC_64_SUPPORT to disable 64-bit ATOMIC in libmetal,
so I added 64-bit ATOMIC detect support to the current toolchain in both CMake and Makefile.

please check latest patchset @anchao @raiden00pl @xiaoxiang781216 @CV-Bowen
maybe this can solve these issues #10401 , #12514, #12489

Check whether 64-bit atomic is supported

Co-authored-by: xuxin19 <[email protected]>
Co-authored-by: Bowen Wang <[email protected]>
ATOMIC_DETECT_CODE := detect_64_atomic.c
ATOMIC_DETECT_BIN := detect_64_atomic_bin
DETECT_ATOMIC_SUPPORT = \
echo '\#include <stdatomic.h>' > $(ATOMIC_DETECT_CODE); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid generate the temp file to test 64bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid generate the temp file to test 64bit?

I think this is related to the current toolchain, and there may be no better way. any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anchao do you have better idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC/CLANG( all GNU ) toolchains have built-in properties to indicate whether support atomic64:

(base) archer@archer:~/code/nuttx/n3/nuttx$ arm-none-eabi-gcc -Wstrict-prototypes -Wno-attributes -Wno-unknown-pragmas -Wno-psabi -fomit-frame-pointer -fno-common -Wall -Wshadow -Wundef -ffunction-sections -fdata-sections -g -mlittle-endian -march=armv7e-m -mtune=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -isystem /home/archer/code/nuttx/n3/nuttx/include -D__NuttX__ -DNDEBUG -D__KERNEL__  -pipe -DMETAL_INTERNAL -dM -E - < /dev/null | grep SYNC
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
(base) archer@archer:~/code/nuttx/n3/nuttx$ clang -dM -E - < /dev/null  | grep SYNC
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
(base) archer@archer:~/code/nuttx/n3/nuttx$ gcc -dM -E - < /dev/null  | grep SYNC
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1

Is it more elegant to check atomic64 use __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8?

Copy link
Contributor

@anchao anchao Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuxin930 @xiaoxiang781216
If __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 is more reasonable, please contribute to the openamp community

diff --git a/openamp/libmetal/lib/io.h b/openamp/libmetal/lib/io.h
index ba416dd505..1de65739ec 100644
--- a/openamp/libmetal/lib/io.h
+++ b/openamp/libmetal/lib/io.h
@@ -30,7 +30,8 @@ extern "C" {
  *  @{
  */
 
-#ifdef __MICROBLAZE__
+#if defined(__MICROBLAZE__) || \
+   (defined(__GNUC__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8))
 #define NO_ATOMIC_64_SUPPORT
 #endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change needs patch libmetal, the hack in cmake need keep until the next release of OpenAMP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the hot-fix for this patch? there are a lot of patch files in openamp subdirectory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuxin930 xuxin930 requested a review from anchao June 25, 2024 07:36
@xiaoxiang781216
Copy link
Contributor

Ok, let's merge it first, and find the better method later.

@xiaoxiang781216 xiaoxiang781216 merged commit 0e8aecf into apache:master Jun 25, 2024
26 checks passed
@raiden00pl
Copy link
Contributor

I confirm that this PR fixes #10401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants