Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ option(BUILD_FUZZ_TESTS "Whether to build fuzz tests" OFF)
option(BUILD_BRPC_TOOLS "Whether to build brpc tools" ON)
option(DOWNLOAD_GTEST "Download and build a fresh copy of googletest. Requires Internet access." ON)

# see https://github.com/apache/brpc/pull/2727
add_compile_definitions(NO_PTHREAD_MUTEX_HOOK)

# Enable MACOSX_RPATH. Run "cmake --help-policy CMP0042" for policy details.
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
Expand Down Expand Up @@ -113,7 +116,10 @@ configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_SOURCE_DIR}/src/butil
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

find_package(GFLAGS REQUIRED)
find_path(ZLIB_INCLUDE_PATH NAMES zlib.h)

# needed by protobuf
include_directories(${ZLIB_INCLUDE_PATH})
include_directories(
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
Expand Down
124 changes: 124 additions & 0 deletions src/bthread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,129 @@ __asm (
" or $a0, $zero, $zero\n"
" bl _exit\n"
);
#endif

#if defined(BTHREAD_CONTEXT_PLATFORM_linux_mips64)
__asm (
".text\n"
".globl bthread_jump_fcontext\n"
".align 3\n"
".type bthread_jump_fcontext,@function\n"
".ent bthread_jump_fcontext\n"
"bthread_jump_fcontext:\n"
" # reserve space on stack\n"
" daddiu $sp, $sp, -160\n"
"\n"
" sd $s0, 64($sp) # save S0\n"
" sd $s1, 72($sp) # save S1\n"
" sd $s2, 80($sp) # save S2\n"
" sd $s3, 88($sp) # save S3\n"
" sd $s4, 96($sp) # save S4\n"
" sd $s5, 104($sp) # save S5\n"
" sd $s6, 112($sp) # save S6\n"
" sd $s7, 120($sp) # save S7\n"
" sd $fp, 128($sp) # save FP\n"
" sd $gp, 136($sp) # <<< --- 添加这一行 (SAVE GP)\n"
" sd $ra, 144($sp) # save RA\n"
" sd $ra, 152($sp) # save RA as PC\n"
"\n"
"#if defined(__mips_hard_float)\n"
" s.d $f24, 0($sp) # save F24\n"
" s.d $f25, 8($sp) # save F25\n"
" s.d $f26, 16($sp) # save F26\n"
" s.d $f27, 24($sp) # save F27\n"
" s.d $f28, 32($sp) # save F28\n"
" s.d $f29, 40($sp) # save F29\n"
" s.d $f30, 48($sp) # save F30\n"
" s.d $f31, 56($sp) # save F31\n"
"#endif\n"
"\n"
" # store SP (pointing to old context-data) in v0 as return\n"
" move $v0, $sp\n"
"\n"
" # get SP (pointing to new context-data) from a0 param\n"
" move $sp, $a0\n"
"\n"
"#if defined(__mips_hard_float)\n"
" l.d $f24, 0($sp) # restore F24\n"
" l.d $f25, 8($sp) # restore F25\n"
" l.d $f26, 16($sp) # restore F26\n"
" l.d $f27, 24($sp) # restore F27\n"
" l.d $f28, 32($sp) # restore F28\n"
" l.d $f29, 40($sp) # restore F29\n"
" l.d $f30, 48($sp) # restore F30\n"
" l.d $f31, 56($sp) # restore F31\n"
"#endif\n"
"\n"
" ld $s0, 64($sp) # restore S0\n"
" ld $s1, 72($sp) # restore S1\n"
" ld $s2, 80($sp) # restore S2\n"
" ld $s3, 88($sp) # restore S3\n"
" ld $s4, 96($sp) # restore S4\n"
" ld $s5, 104($sp) # restore S5\n"
" ld $s6, 112($sp) # restore S6\n"
" ld $s7, 120($sp) # restore S7\n"
" ld $fp, 128($sp) # restore FP\n"
" ld $gp, 136($sp) # <<< --- 添加这一行 (RESTORE GP)\n"
" ld $ra, 144($sp) # restore RAa\n"
"\n"
" # load PC\n"
" ld $t9, 152($sp)\n"
"\n"
" # adjust stack\n"
" daddiu $sp, $sp, 160\n"
"\n"
" move $a0, $v0 # move old sp from v0 to a0 as param\n"
" move $v1, $a1 # move *data from a1 to v1 as return\n"
"\n"
" # jump to context\n"
" jr $t9\n"
".end bthread_jump_fcontext\n"
".size bthread_jump_fcontext,.-bthread_jump_fcontext\n"
".section .note.GNU-stack,\"\",%progbits\n"
);
#endif

#if defined(BTHREAD_CONTEXT_PLATFORM_linux_mips64)
__asm (
".text\n"
".globl bthread_make_fcontext\n"
".align 3\n"
".type bthread_make_fcontext,@function\n"
".ent bthread_make_fcontext\n"
"bthread_make_fcontext:\n"
".set noreorder\n"
".cpload $t9\n"
".set reorder\n"
" # shift address in A0 to lower 16 byte boundary\n"
" li $v1, 0xfffffffffffffff0\n"
" and $v0, $v1, $a0\n"
" # reserve space for context-data on context-stack\n"
" daddiu $v0, $v0, -160\n"
" # third arg of make_fcontext() == address of context-function\n"
" sd $a2, 152($v0)\n"
" # save global pointer in context-data\n"
" sd $gp, 136($v0)\n"
" # pseudo instruction compute abs address of label finish based on GP\n"
" dla $t9, finish\n"
" # save address of finish as return-address for context-function\n"
" # will be entered after context-function returns\n"
" sd $t9, 144($v0)\n"
" jr $ra # return pointer to context-data\n"
"finish:\n"
" # reload our gp register (needed for la)\n"
" daddiu $t0, $sp, -160\n"
" ld $gp, 136($t0)\n"
" # call _exit(0)\n"
" # the previous function should have left the 16 bytes incoming argument\n"
" # area on the stack which we reuse for calling _exit\n"
" dla $t9, _exit\n"
" move $a0, $zero\n"
" jr $t9\n"
".end bthread_make_fcontext\n"
".size bthread_make_fcontext,.-bthread_make_fcontext\n"
".section .note.GNU-stack,\"\",%progbits\n"
);
#endif


3 changes: 3 additions & 0 deletions src/bthread/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#elif __loongarch64
#define BTHREAD_CONTEXT_PLATFORM_linux_loongarch64
#define BTHREAD_CONTEXT_CALL_CONVENTION
#elif __mips64
#define BTHREAD_CONTEXT_PLATFORM_linux_mips64
#define BTHREAD_CONTEXT_CALL_CONVENTION
#endif

#elif defined(__MINGW32__) || defined (__MINGW64__)
Expand Down
4 changes: 2 additions & 2 deletions src/bthread/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

namespace bthread {

DEFINE_uint32(key_table_list_size, 4000,
DEFINE_uint64(key_table_list_size, 4000,
"The maximum length of the KeyTableList. Once this value is "
"exceeded, a portion of the KeyTables will be moved to the "
"global free_keytables list.");

DEFINE_uint32(borrow_from_globle_size, 200,
DEFINE_uint64(borrow_from_globle_size, 200,
"The maximum number of KeyTables retrieved in a single operation "
"from the global free_keytables when no KeyTable exists in the "
"current thread's keytable_list.");
Expand Down
2 changes: 1 addition & 1 deletion src/bthread/task_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace bthread {

DEFINE_bool(enable_fast_unwind, true, "Whether to enable fast unwind");
DEFINE_uint32(signal_trace_timeout_ms, 50, "Timeout for signal trace in ms");
DEFINE_uint64(signal_trace_timeout_ms, 50, "Timeout for signal trace in ms");
BUTIL_VALIDATE_GFLAG(signal_trace_timeout_ms, butil::PositiveInteger<uint32_t>);

extern BAIDU_THREAD_LOCAL TaskMeta* pthread_fake_meta;
Expand Down
2 changes: 2 additions & 0 deletions src/butil/atomicops.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#include "butil/atomicops_internals_x86_gcc.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_MIPS_FAMILY)
#include "butil/atomicops_internals_mips_gcc.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_MIPS64_FAMILY)
#include "butil/atomicops_internals_mips64_gcc.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_LOONGARCH64_FAMILY)
#include "butil/atomicops_internals_loongarch64_gcc.h"
#else
Expand Down
Loading