-
Notifications
You must be signed in to change notification settings - Fork 27
[build]: support LoongArch host toolchains #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,49 @@ | ||
| set(CLI11_PRECOMPILED OFF CACHE BOOL "do not precompile CLI11") | ||
| add_subdirectory(CLI11 EXCLUDE_FROM_ALL) | ||
| unset(CLI11_PRECOMPILED CACHE) | ||
| # Bundled googletest requires CMake 3.16. Keep XSched's platform tests | ||
| # buildable with older toolchains without enabling libipc's own tests. | ||
| set(XSCHED_BUILD_TEST_TMP "${BUILD_TEST}") | ||
| if(CMAKE_VERSION VERSION_LESS 3.16) | ||
| set(BUILD_TEST OFF) | ||
| endif() | ||
| add_subdirectory(ipc EXCLUDE_FROM_ALL) | ||
| set(BUILD_TEST "${XSCHED_BUILD_TEST_TMP}") | ||
| unset(XSCHED_BUILD_TEST_TMP) | ||
|
|
||
| set(HTTPLIB_INSTALL OFF CACHE BOOL "do not install cpp-httplib") | ||
| set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF CACHE BOOL "disable openssl for cpp-httplib") | ||
| set(HTTPLIB_USE_ZLIB_IF_AVAILABLE OFF CACHE BOOL "disable zlib for cpp-httplib") | ||
| set(HTTPLIB_USE_BROTLI_IF_AVAILABLE OFF CACHE BOOL "disable brotli for cpp-httplib") | ||
| add_subdirectory(cpp-httplib EXCLUDE_FROM_ALL) | ||
| unset(HTTPLIB_USE_OPENSSL_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_USE_ZLIB_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_USE_BROTLI_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_INSTALL CACHE) | ||
| if(PLATFORM_CUDA) | ||
| add_subdirectory(cuxtra EXCLUDE_FROM_ALL) | ||
| endif() | ||
|
|
||
| add_subdirectory(ipc EXCLUDE_FROM_ALL) | ||
| if(BUILD_SERVICE) | ||
| if(CMAKE_VERSION VERSION_LESS 3.14) | ||
| message(FATAL_ERROR "BUILD_SERVICE requires CMake 3.14 or newer") | ||
| endif() | ||
|
|
||
| add_subdirectory(cuxtra EXCLUDE_FROM_ALL) | ||
| set(CLI11_PRECOMPILED OFF CACHE BOOL "do not precompile CLI11") | ||
| add_subdirectory(CLI11 EXCLUDE_FROM_ALL) | ||
| unset(CLI11_PRECOMPILED CACHE) | ||
|
|
||
| set(HTTPLIB_INSTALL OFF CACHE BOOL "do not install cpp-httplib") | ||
| set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF CACHE BOOL "disable openssl for cpp-httplib") | ||
| set(HTTPLIB_USE_ZLIB_IF_AVAILABLE OFF CACHE BOOL "disable zlib for cpp-httplib") | ||
| set(HTTPLIB_USE_BROTLI_IF_AVAILABLE OFF CACHE BOOL "disable brotli for cpp-httplib") | ||
| add_subdirectory(cpp-httplib EXCLUDE_FROM_ALL) | ||
| unset(HTTPLIB_USE_OPENSSL_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_USE_ZLIB_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_USE_BROTLI_IF_AVAILABLE CACHE) | ||
| unset(HTTPLIB_INSTALL CACHE) | ||
|
|
||
| set(JSONCPP_WITH_TESTS OFF CACHE BOOL "do not build jsoncpp tests") | ||
| set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "disable jsoncpp post build unit test") | ||
| set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "disable jsoncpp pkgconfig support") | ||
| set(JSONCPP_WITH_CMAKE_PACKAGE OFF CACHE BOOL "disable jsoncpp cmake package") | ||
| set(BUILD_SHARED_LIBS OFF CACHE BOOL "do not build jsoncpp shared library") | ||
| set(BUILD_OBJECT_LIBS OFF CACHE BOOL "do not build jsoncpp object library") | ||
| set(JSONCPP_WITH_TESTS OFF CACHE BOOL "do not build jsoncpp tests") | ||
| set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "disable jsoncpp post build unit test") | ||
| set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "disable jsoncpp pkgconfig support") | ||
| set(JSONCPP_WITH_CMAKE_PACKAGE OFF CACHE BOOL "disable jsoncpp cmake package") | ||
| set(BUILD_SHARED_LIBS OFF CACHE BOOL "do not build jsoncpp shared library") | ||
| set(BUILD_OBJECT_LIBS OFF CACHE BOOL "do not build jsoncpp object library") | ||
| add_subdirectory(jsoncpp EXCLUDE_FROM_ALL) | ||
| unset(JSONCPP_WITH_TESTS CACHE) | ||
| unset(JSONCPP_WITH_POST_BUILD_UNITTEST CACHE) | ||
| unset(JSONCPP_WITH_PKGCONFIG_SUPPORT CACHE) | ||
| unset(JSONCPP_WITH_CMAKE_PACKAGE CACHE) | ||
| unset(BUILD_SHARED_LIBS CACHE) | ||
| unset(BUILD_OBJECT_LIBS CACHE) | ||
| unset(JSONCPP_WITH_TESTS CACHE) | ||
| unset(JSONCPP_WITH_POST_BUILD_UNITTEST CACHE) | ||
| unset(JSONCPP_WITH_PKGCONFIG_SUPPORT CACHE) | ||
| unset(JSONCPP_WITH_CMAKE_PACKAGE CACHE) | ||
| unset(BUILD_SHARED_LIBS CACHE) | ||
| unset(BUILD_OBJECT_LIBS CACHE) | ||
|
|
||
| add_subdirectory(ftxui EXCLUDE_FROM_ALL) | ||
| add_subdirectory(ftxui EXCLUDE_FROM_ALL) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,63 @@ | ||
| #include "xsched/utils/lock.h" | ||
| #include "xsched/utils/common.h" | ||
|
|
||
| #if defined(__linux__) | ||
| #if defined(ARCH_X86_64) | ||
| #define memory_barrier() asm volatile("pause" ::: "memory") | ||
| #elif defined(ARCH_AARCH64) | ||
| #define memory_barrier() asm volatile("yield" ::: "memory") | ||
| #endif | ||
| #elif defined(_WIN32) | ||
| #if defined(_WIN32) | ||
| #include <intrin.h> | ||
| #define memory_barrier() _mm_pause() | ||
| #endif | ||
|
|
||
| using namespace xsched::utils; | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| inline void CpuRelax() | ||
| { | ||
| #if defined(_WIN32) | ||
| _mm_pause(); | ||
| #elif defined(ARCH_X86) || defined(ARCH_X86_64) | ||
| asm volatile("pause" ::: "memory"); | ||
| #elif defined(ARCH_ARM) || defined(ARCH_AARCH64) | ||
| asm volatile("yield" ::: "memory"); | ||
| #else | ||
| // LoongArch has no userspace pause/yield instruction. The Linux kernel's | ||
| // cpu_relax() is a compiler barrier on this architecture as well. | ||
| std::atomic_signal_fence(std::memory_order_seq_cst); | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| thread_local MCSLock::MCSNode MCSLock::me; | ||
|
|
||
| void MCSLock::lock() | ||
| { | ||
| MCSNode *tail = nullptr; | ||
| me.flag = kLockWaiting; | ||
| me.next = nullptr; | ||
| tail = tail_.exchange(&me); | ||
| if (tail) { | ||
| tail->next = &me; | ||
| while (me.flag != kLockGranted) { | ||
| memory_barrier(); | ||
| me.flag.store(kLockWaiting, std::memory_order_relaxed); | ||
| me.next.store(nullptr, std::memory_order_relaxed); | ||
|
|
||
| MCSNode *predecessor = tail_.exchange(&me, std::memory_order_acq_rel); | ||
| if (predecessor != nullptr) { | ||
| predecessor->next.store(&me, std::memory_order_release); | ||
| while (me.flag.load(std::memory_order_acquire) != kLockGranted) { | ||
| CpuRelax(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void MCSLock::unlock() | ||
| { | ||
| if (!me.next) { | ||
| MCSNode *me_ptr = &me; | ||
| if (tail_.compare_exchange_strong(me_ptr, nullptr)) { | ||
| MCSNode *successor = me.next.load(std::memory_order_acquire); | ||
| if (successor == nullptr) { | ||
| MCSNode *expected = &me; | ||
| if (tail_.compare_exchange_strong(expected, nullptr, | ||
| std::memory_order_release, | ||
| std::memory_order_relaxed)) { | ||
| return; | ||
| } | ||
| while (!me.next) { | ||
| memory_barrier(); | ||
| } | ||
| do { | ||
| CpuRelax(); | ||
| successor = me.next.load(std::memory_order_acquire); | ||
| } while (successor == nullptr); | ||
| } | ||
| me.next->flag = kLockGranted; | ||
|
|
||
| successor->flag.store(kLockGranted, std::memory_order_release); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.