Commit 73d72c04 by Nicolas Capens

Update Marl to 5f31df137

5f31df137 aarch64: Fix saving/restoring register r29 on fiber switch 76f093bce Kokoro:Add bazel presubmits ea671dced Kokoro: Split build rules by build system 767915fdb Scheduler: Don't work-steal on the single threaded workers. 4fbdf5946 Bazel build support (#28) Bug: b/140967243 Change-Id: Ia7ee9d37f83313e8524fda9757fd23b487f937be
parents b6fa949c 9e5f50fa
/.vscode/ /.vscode/
/build/ /build/
\ No newline at end of file bazel-*
# Copyright 2019 The Marl Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cc_library(
name = "marl",
srcs = glob(
[
"src/**/*.cpp",
"src/**/*.c",
"src/**/*.h",
],
exclude = glob([
"src/**/*_test.cpp",
]),
) + select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": glob(["src/**/*.S"]),
}),
hdrs = glob([
"include/marl/**/*.h",
]),
includes = [
"include",
],
linkopts = select({
"@bazel_tools//src/conditions:linux_x86_64": ["-pthread"],
"//conditions:default": [],
}),
visibility = [
"//visibility:public",
],
)
cc_test(
name = "tests",
srcs = glob([
"src/**/*_test.cpp",
]),
deps = [
"//:marl",
"@googletest//:gtest",
],
)
# Copyright 2019 The Marl Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
local_repository(
name = "googletest",
path = "./third_party/googletest",
)
# Copyright 2019 The Marl Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cc_binary(
name = "fractal",
srcs = [
"fractal.cpp",
],
deps = [
"//:marl",
],
)
cc_binary(
name = "primes",
srcs = [
"primes.cpp",
],
deps = [
"//:marl",
],
)
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
# Location of the continuous bash script in Git. # Location of the continuous bash script in Git.
build_file: "marl/kokoro/linux/presubmit.sh" build_file: "marl/kokoro/linux/presubmit.sh"
env_vars {
key: "BUILD_SYSTEM"
value: "bazel"
}
# Format: //devtools/kokoro/config/proto/build.proto
# Location of the continuous bash script in Git.
build_file: "marl/kokoro/linux/presubmit.sh"
env_vars {
key: "BUILD_SYSTEM"
value: "cmake"
}
...@@ -3,21 +3,39 @@ ...@@ -3,21 +3,39 @@
set -e # Fail on any error. set -e # Fail on any error.
set -x # Display commands being run. set -x # Display commands being run.
BUILD_ROOT=$PWD
cd github/marl cd github/marl
git submodule update --init git submodule update --init
mkdir build if [ "$BUILD_SYSTEM" == "cmake" ]; then
cd build mkdir build
cd build
build_and_run() { build_and_run() {
cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 -DMARL_WARNINGS_AS_ERRORS=1 $1 cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 -DMARL_WARNINGS_AS_ERRORS=1 $1
make --jobs=$(nproc) make --jobs=$(nproc)
./marl-unittests ./marl-unittests
./fractal ./fractal
} ./primes > /dev/null
}
build_and_run "" build_and_run ""
build_and_run "-DMARL_ASAN=1" build_and_run "-DMARL_ASAN=1"
build_and_run "-DMARL_MSAN=1" build_and_run "-DMARL_MSAN=1"
\ No newline at end of file elif [ "$BUILD_SYSTEM" == "bazel" ]; then
# Get bazel
curl -L -k -O -s https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-installer-linux-x86_64.sh
mkdir $BUILD_ROOT/bazel
bash bazel-0.29.1-installer-linux-x86_64.sh --prefix=$BUILD_ROOT/bazel
rm bazel-0.29.1-installer-linux-x86_64.sh
# Build and run
$BUILD_ROOT/bazel/bin/bazel test //:tests
$BUILD_ROOT/bazel/bin/bazel run //examples:fractal
$BUILD_ROOT/bazel/bin/bazel run //examples:primes > /dev/null
else
echo "Unknown build system: $BUILD_SYSTEM"
exit 1
fi
\ No newline at end of file
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
# Location of the continuous bash script in Git. # Location of the continuous bash script in Git.
build_file: "marl/kokoro/macos/presubmit.sh" build_file: "marl/kokoro/macos/presubmit.sh"
env_vars {
key: "BUILD_SYSTEM"
value: "bazel"
}
# Format: //devtools/kokoro/config/proto/build.proto
# Location of the continuous bash script in Git.
build_file: "marl/kokoro/macos/presubmit.sh"
env_vars {
key: "BUILD_SYSTEM"
value: "cmake"
}
...@@ -3,15 +3,34 @@ ...@@ -3,15 +3,34 @@
set -e # Fail on any error. set -e # Fail on any error.
set -x # Display commands being run. set -x # Display commands being run.
BUILD_ROOT=$PWD
cd github/marl cd github/marl
git submodule update --init git submodule update --init
mkdir build if [ "$BUILD_SYSTEM" == "cmake" ]; then
cd build mkdir build
cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 -DMARL_WARNINGS_AS_ERRORS=1 cd build
make -j$(sysctl -n hw.logicalcpu)
cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 -DMARL_WARNINGS_AS_ERRORS=1
make -j$(sysctl -n hw.logicalcpu)
./marl-unittests ./marl-unittests
./fractal ./fractal
./primes > /dev/null
elif [ "$BUILD_SYSTEM" == "bazel" ]; then
# Get bazel
curl -L -k -O -s https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-installer-darwin-x86_64.sh
mkdir $BUILD_ROOT/bazel
sh bazel-0.29.1-installer-darwin-x86_64.sh --prefix=$BUILD_ROOT/bazel
rm bazel-0.29.1-installer-darwin-x86_64.sh
# Build and run
$BUILD_ROOT/bazel/bin/bazel test //:tests
$BUILD_ROOT/bazel/bin/bazel run //examples:fractal
$BUILD_ROOT/bazel/bin/bazel run //examples:primes > /dev/null
else
echo "Unknown build system: $BUILD_SYSTEM"
exit 1
fi
\ No newline at end of file
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
# Location of the continuous bash script in Git. # Location of the continuous bash script in Git.
build_file: "marl/kokoro/windows/presubmit.bat" build_file: "marl/kokoro/windows/presubmit.bat"
env_vars {
key: "BUILD_SYSTEM"
value: "bazel"
}
# Format: //devtools/kokoro/config/proto/build.proto
# Location of the continuous bash script in Git.
build_file: "marl/kokoro/windows/presubmit.bat"
env_vars {
key: "BUILD_SYSTEM"
value: "cmake"
}
...@@ -2,30 +2,62 @@ ...@@ -2,30 +2,62 @@
SETLOCAL ENABLEDELAYEDEXPANSION SETLOCAL ENABLEDELAYEDEXPANSION
SET BUILD_ROOT=%cd%
SET PATH=C:\python36;C:\Program Files\cmake\bin;%PATH% SET PATH=C:\python36;C:\Program Files\cmake\bin;%PATH%
set SRC=%cd%\github\marl SET SRC=%cd%\github\marl
cd %SRC% cd %SRC%
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
git submodule update --init git submodule update --init
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
SET MSBUILD="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild" SET MSBUILD="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild"
SET CONFIG=Release SET CONFIG=Release
mkdir %SRC%\build mkdir %SRC%\build
cd %SRC%\build cd %SRC%\build
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
cmake .. -G "Visual Studio 15 2017 Win64" -Thost=x64 "-DMARL_BUILD_TESTS=1" "-DMARL_BUILD_EXAMPLES=1" "-DMARL_WARNINGS_AS_ERRORS=1" IF /I "%BUILD_SYSTEM%"=="cmake" (
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! cmake .. -G "Visual Studio 15 2017 Win64" -Thost=x64 "-DMARL_BUILD_TESTS=1" "-DMARL_BUILD_EXAMPLES=1" "-DMARL_WARNINGS_AS_ERRORS=1"
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
%MSBUILD% /p:Configuration=%CONFIG% Marl.sln %MSBUILD% /p:Configuration=%CONFIG% Marl.sln
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
Release\marl-unittests.exe
Release\marl-unittests.exe if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! Release\fractal.exe
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
Release\fractal.exe Release\primes.exe > nul
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
) ELSE IF /I "%BUILD_SYSTEM%"=="bazel" (
REM Fix up the MSYS environment.
wget -q http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc-7.3.0-2-any.pkg.tar.xz
wget -q http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc-libs-7.3.0-2-any.pkg.tar.xz
c:\tools\msys64\usr\bin\bash --login -c "pacman -R --noconfirm catgets libcatgets"
c:\tools\msys64\usr\bin\bash --login -c "pacman -Syu --noconfirm"
c:\tools\msys64\usr\bin\bash --login -c "pacman -Sy --noconfirm mingw-w64-x86_64-crt-git patch"
c:\tools\msys64\usr\bin\bash --login -c "pacman -U --noconfirm mingw-w64-x86_64-gcc*-7.3.0-2-any.pkg.tar.xz"
set PATH=C:\tools\msys64\mingw64\bin;c:\tools\msys64\usr\bin;!PATH!
set BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe
REM Install Bazel
SET BAZEL_DIR=!BUILD_ROOT!\bazel
mkdir !BAZEL_DIR!
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
wget -q https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-windows-x86_64.zip
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
unzip -q bazel-0.29.1-windows-x86_64.zip -d !BAZEL_DIR!
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
REM Build and run
!BAZEL_DIR!\bazel test //:tests --test_output=all
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
!BAZEL_DIR!\bazel run //examples:fractal
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
!BAZEL_DIR!\bazel run //examples:primes > nul
if !ERRORLEVEL! neq 0 exit !ERRORLEVEL!
) ELSE (
echo "Unknown build system: %BUILD_SYSTEM%"
exit /b 1
)
...@@ -44,6 +44,7 @@ MARL_ASM_SYMBOL(marl_fiber_swap): ...@@ -44,6 +44,7 @@ MARL_ASM_SYMBOL(marl_fiber_swap):
str x26, [x0, #MARL_REG_r26] str x26, [x0, #MARL_REG_r26]
str x27, [x0, #MARL_REG_r27] str x27, [x0, #MARL_REG_r27]
str x28, [x0, #MARL_REG_r28] str x28, [x0, #MARL_REG_r28]
str x29, [x0, #MARL_REG_r29]
str d8, [x0, #MARL_REG_v8] str d8, [x0, #MARL_REG_v8]
str d9, [x0, #MARL_REG_v9] str d9, [x0, #MARL_REG_v9]
...@@ -78,6 +79,7 @@ MARL_ASM_SYMBOL(marl_fiber_swap): ...@@ -78,6 +79,7 @@ MARL_ASM_SYMBOL(marl_fiber_swap):
ldr x26, [x7, #MARL_REG_r26] ldr x26, [x7, #MARL_REG_r26]
ldr x27, [x7, #MARL_REG_r27] ldr x27, [x7, #MARL_REG_r27]
ldr x28, [x7, #MARL_REG_r28] ldr x28, [x7, #MARL_REG_r28]
ldr x29, [x7, #MARL_REG_r29]
ldr d8, [x7, #MARL_REG_v8] ldr d8, [x7, #MARL_REG_v8]
ldr d9, [x7, #MARL_REG_v9] ldr d9, [x7, #MARL_REG_v9]
......
...@@ -27,16 +27,17 @@ ...@@ -27,16 +27,17 @@
#define MARL_REG_r26 0x60 #define MARL_REG_r26 0x60
#define MARL_REG_r27 0x68 #define MARL_REG_r27 0x68
#define MARL_REG_r28 0x70 #define MARL_REG_r28 0x70
#define MARL_REG_v8 0x78 #define MARL_REG_r29 0x78
#define MARL_REG_v9 0x80 #define MARL_REG_v8 0x80
#define MARL_REG_v10 0x88 #define MARL_REG_v9 0x88
#define MARL_REG_v11 0x90 #define MARL_REG_v10 0x90
#define MARL_REG_v12 0x98 #define MARL_REG_v11 0x98
#define MARL_REG_v13 0xa0 #define MARL_REG_v12 0xa0
#define MARL_REG_v14 0xa8 #define MARL_REG_v13 0xa8
#define MARL_REG_v15 0xb0 #define MARL_REG_v14 0xb0
#define MARL_REG_SP 0xb8 #define MARL_REG_v15 0xb8
#define MARL_REG_LR 0xc0 #define MARL_REG_SP 0xc0
#define MARL_REG_LR 0xc8
#if defined(__APPLE__) #if defined(__APPLE__)
#define MARL_ASM_SYMBOL(x) _##x #define MARL_ASM_SYMBOL(x) _##x
...@@ -71,6 +72,7 @@ struct marl_fiber_context { ...@@ -71,6 +72,7 @@ struct marl_fiber_context {
uintptr_t r26; uintptr_t r26;
uintptr_t r27; uintptr_t r27;
uintptr_t r28; uintptr_t r28;
uintptr_t r29;
uintptr_t v8; uintptr_t v8;
uintptr_t v9; uintptr_t v9;
...@@ -117,6 +119,8 @@ static_assert(offsetof(marl_fiber_context, r27) == MARL_REG_r27, ...@@ -117,6 +119,8 @@ static_assert(offsetof(marl_fiber_context, r27) == MARL_REG_r27,
"Bad register offset"); "Bad register offset");
static_assert(offsetof(marl_fiber_context, r28) == MARL_REG_r28, static_assert(offsetof(marl_fiber_context, r28) == MARL_REG_r28,
"Bad register offset"); "Bad register offset");
static_assert(offsetof(marl_fiber_context, r29) == MARL_REG_r29,
"Bad register offset");
static_assert(offsetof(marl_fiber_context, v8) == MARL_REG_v8, static_assert(offsetof(marl_fiber_context, v8) == MARL_REG_v8,
"Bad register offset"); "Bad register offset");
static_assert(offsetof(marl_fiber_context, v9) == MARL_REG_v9, static_assert(offsetof(marl_fiber_context, v9) == MARL_REG_v9,
......
...@@ -408,7 +408,7 @@ _Requires_lock_held_(lock) void Scheduler::Worker::waitForWork( ...@@ -408,7 +408,7 @@ _Requires_lock_held_(lock) void Scheduler::Worker::waitForWork(
std::unique_lock<std::mutex>& lock) { std::unique_lock<std::mutex>& lock) {
MARL_ASSERT(work.num == work.fibers.size() + work.tasks.size(), MARL_ASSERT(work.num == work.fibers.size() + work.tasks.size(),
"work.num out of sync"); "work.num out of sync");
if (work.num == 0) { if (work.num == 0 && mode == Mode::MultiThreaded) {
scheduler->onBeginSpinning(id); scheduler->onBeginSpinning(id);
lock.unlock(); lock.unlock();
spinForWork(); spinForWork();
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
#include "marl_test.h" #include "marl_test.h"
#include "marl/defer.h"
#include "marl/waitgroup.h" #include "marl/waitgroup.h"
#include <unordered_set>
TEST(WithoutBoundScheduler, SchedulerConstructAndDestruct) { TEST(WithoutBoundScheduler, SchedulerConstructAndDestruct) {
auto scheduler = new marl::Scheduler(); auto scheduler = new marl::Scheduler();
delete scheduler; delete scheduler;
...@@ -102,4 +105,27 @@ TEST_P(WithBoundScheduler, FibersResumeOnSameStdThread) { ...@@ -102,4 +105,27 @@ TEST_P(WithBoundScheduler, FibersResumeOnSameStdThread) {
for (auto& thread : threads) { for (auto& thread : threads) {
thread.join(); thread.join();
} }
}
TEST(WithoutBoundScheduler, TasksOnlyScheduledOnWorkerThreads) {
auto scheduler = std::unique_ptr<marl::Scheduler>(new marl::Scheduler());
scheduler->bind();
scheduler->setWorkerThreadCount(8);
std::mutex mutex;
std::unordered_set<std::thread::id> threads;
marl::WaitGroup wg;
for (int i = 0; i < 10000; i++) {
wg.add(1);
marl::schedule([&mutex, &threads, wg] {
defer(wg.done());
std::unique_lock<std::mutex> lock(mutex);
threads.emplace(std::this_thread::get_id());
});
}
wg.wait();
ASSERT_EQ(threads.size(), 8U);
ASSERT_EQ(threads.count(std::this_thread::get_id()), 0U);
scheduler->unbind();
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment