File tree Expand file tree Collapse file tree 3 files changed +42
-15
lines changed
Expand file tree Collapse file tree 3 files changed +42
-15
lines changed Original file line number Diff line number Diff line change 1111
1212#include " src/__support/CPP/type_traits.h"
1313#include " src/__support/GPU/utils.h"
14- #include " src/__support/macros/attributes.h" // LIBC_INLINE
14+ #include " src/__support/macros/attributes.h"
1515#include " src/__support/macros/properties/architectures.h"
16+ #include " src/__support/threads/sleep.h"
1617#include " src/string/memory_utils/generic/byte_per_byte.h"
1718#include " src/string/memory_utils/inline_memcpy.h"
1819
1920namespace LIBC_NAMESPACE {
2021namespace rpc {
2122
22- // / Suspend the thread briefly to assist the thread scheduler during busy loops.
23- LIBC_INLINE void sleep_briefly () {
24- #if defined(LIBC_TARGET_ARCH_IS_NVPTX)
25- if (__nvvm_reflect (" __CUDA_ARCH" ) >= 700 )
26- LIBC_INLINE_ASM (" nanosleep.u32 64;" ::: " memory" );
27- #elif defined(LIBC_TARGET_ARCH_IS_AMDGPU)
28- __builtin_amdgcn_s_sleep (2 );
29- #elif defined(LIBC_TARGET_ARCH_IS_X86)
30- __builtin_ia32_pause ();
31- #else
32- // Simply do nothing if sleeping isn't supported on this platform.
33- #endif
34- }
35-
3623// / Conditional to indicate if this process is running on the GPU.
3724LIBC_INLINE constexpr bool is_process_gpu () {
3825#if defined(LIBC_TARGET_ARCH_IS_GPU)
Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ add_header_library(
44 mutex_common.h
55)
66
7+ add_header_library(
8+ sleep
9+ HDRS
10+ sleep.h
11+ )
12+
713if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${LIBC_TARGET_OS} )
814 add_subdirectory (${LIBC_TARGET_OS} )
915endif ()
Original file line number Diff line number Diff line change 1+ // ===-- Utilities for suspending threads ----------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H
10+ #define LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H
11+
12+ #include " src/__support/macros/attributes.h"
13+
14+ namespace LIBC_NAMESPACE {
15+
16+ // / Suspend the thread briefly to assist the thread scheduler during busy loops.
17+ LIBC_INLINE void sleep_briefly () {
18+ #if defined(LIBC_TARGET_ARCH_IS_NVPTX)
19+ if (__nvvm_reflect (" __CUDA_ARCH" ) >= 700 )
20+ LIBC_INLINE_ASM (" nanosleep.u32 64;" ::: " memory" );
21+ #elif defined(LIBC_TARGET_ARCH_IS_AMDGPU)
22+ __builtin_amdgcn_s_sleep (2 );
23+ #elif defined(LIBC_TARGET_ARCH_IS_X86)
24+ __builtin_ia32_pause ();
25+ #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
26+ __builtin_arm_isb (0xf );
27+ #else
28+ // Simply do nothing if sleeping isn't supported on this platform.
29+ #endif
30+ }
31+
32+ } // namespace LIBC_NAMESPACE
33+
34+ #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_SLEEP_H
You can’t perform that action at this time.
0 commit comments