Skip to content

Commit 8b80d1a

Browse files
authored
Backport Qthreads Fix For ppc64le (#27075)
The fast context swap is broken on little-endian ppc. This switches to using the fallback implementation from the system in that case. [Contributed by @insertinterestingnamehere, reviewed and merged by @jabraham17]
2 parents 924a78e + a254f2f commit 8b80d1a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

third-party/qthread/README

+33
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,36 @@ Prevent CMake from overriding the OSX deployment target
7777

7878
set(THREADS_PREFER_PTHREAD_FLAG ON)
7979

80+
81+
Backport a patch from qthreads that switches to the fallback implementation of context swapping on ppc64le since the fast one is broken there.
82+
--- a/third-party/qthread/qthread-src/src/CMakeLists.txt
83+
+++ b/third-party/qthread/qthread-src/src/CMakeLists.txt
84+
@@ -8,7 +8,26 @@ set(QTHREADS_DEFAULT_STACK_SIZE 32768 CACHE STRING "Default qthread stack size."
85+
set(QTHREADS_HASHMAP hashmap CACHE STRING "Which hashmap implementation to use. Valid values are \"hashmap\" and \"lf_hashmap\".")
86+
set(QTHREADS_DICT_TYPE shavit CACHE STRING "Which dictionary implementation to use. Valid values are \"shavit\", \"trie\", and \"simple\".")
87+
set(QTHREADS_TIMER_TYPE gettimeofday CACHE STRING "Which timer implementation to use. Valid values are \"clock_gettime\", \"mach\", \"gettimeofday\", and \"gethrtime\".")
88+
-set(QTHREADS_CONTEXT_SWAP_IMPL fastcontext CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
89+
+# Only default to the fastcontext implementation in cases where it's confirmed to work.
90+
+# Note: apparently 32-bit x86 may show up as i386, i486, i586, or i686.
91+
+# Little-endian powerpc variants are excluded here as they're known not to work
92+
+# due to an unresolved bug in our fastcontext code.
93+
+if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
94+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
95+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR
96+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64" OR
97+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR
98+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
99+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i486" OR
100+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i586" OR
101+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686" OR
102+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64" OR
103+
+ "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc")
104+
+ set(QTHREADS_CONTEXT_SWAP_IMPL fastcontext CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
105+
+else()
106+
+ message(WARNING "No fast context swap available on this system, falling back to the system-provided one.")
107+
+ set(QTHREADS_CONTEXT_SWAP_IMPL system CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
108+
+endif()
109+
set(QTHREADS_HWLOC_GET_TOPOLOGY_FUNCTION "" CACHE STRING "function to get hwloc topology (otherwise uses hwloc_topology_init and hwloc_topology_load)")
110+
set(QTHREADS_GUARD_PAGES OFF CACHE BOOL "Whether or not to guard memory pages to help with debugging stack overflows. Default is OFF.")
111+
set(QTHREADS_CONDWAIT_QUEUE OFF CACHE BOOL "Use a waiting queue based on pthread condition variables instead of a spin-based queue for inter-thread communication. Default is OFF.")
112+

third-party/qthread/qthread-src/src/CMakeLists.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,26 @@ set(QTHREADS_DEFAULT_STACK_SIZE 32768 CACHE STRING "Default qthread stack size."
88
set(QTHREADS_HASHMAP hashmap CACHE STRING "Which hashmap implementation to use. Valid values are \"hashmap\" and \"lf_hashmap\".")
99
set(QTHREADS_DICT_TYPE shavit CACHE STRING "Which dictionary implementation to use. Valid values are \"shavit\", \"trie\", and \"simple\".")
1010
set(QTHREADS_TIMER_TYPE gettimeofday CACHE STRING "Which timer implementation to use. Valid values are \"clock_gettime\", \"mach\", \"gettimeofday\", and \"gethrtime\".")
11-
set(QTHREADS_CONTEXT_SWAP_IMPL fastcontext CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
11+
# Only default to the fastcontext implementation in cases where it's confirmed to work.
12+
# Note: apparently 32-bit x86 may show up as i386, i486, i586, or i686.
13+
# Little-endian powerpc variants are excluded here as they're known not to work
14+
# due to an unresolved bug in our fastcontext code.
15+
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
16+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
17+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR
18+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64" OR
19+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR
20+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
21+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i486" OR
22+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i586" OR
23+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686" OR
24+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64" OR
25+
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc")
26+
set(QTHREADS_CONTEXT_SWAP_IMPL fastcontext CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
27+
else()
28+
message(WARNING "No fast context swap available on this system, falling back to the system-provided one.")
29+
set(QTHREADS_CONTEXT_SWAP_IMPL system CACHE STRING "Which context swap implementation to use. Valid values are \"system\" and \"fastcontext\".")
30+
endif()
1231
set(QTHREADS_HWLOC_GET_TOPOLOGY_FUNCTION "" CACHE STRING "function to get hwloc topology (otherwise uses hwloc_topology_init and hwloc_topology_load)")
1332
set(QTHREADS_GUARD_PAGES OFF CACHE BOOL "Whether or not to guard memory pages to help with debugging stack overflows. Default is OFF.")
1433
set(QTHREADS_CONDWAIT_QUEUE OFF CACHE BOOL "Use a waiting queue based on pthread condition variables instead of a spin-based queue for inter-thread communication. Default is OFF.")

0 commit comments

Comments
 (0)