Skip to content

Commit fadb386

Browse files
committed
mpi(hwloc): spin-lock receiver threads and pin to a core
1 parent d94f61a commit fadb386

24 files changed

+390
-76
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
runs-on: ubuntu-latest
2222
container:
2323
image: faasm.azurecr.io/faabric:0.16.0
24+
env:
25+
FAABRIC_DEPLOYMENT_TYPE: gha-ci
2426
steps:
2527
- name: "Check-out code"
2628
uses: actions/checkout@v4
@@ -59,7 +61,7 @@ jobs:
5961
needs: [conan-cache]
6062
runs-on: ubuntu-latest
6163
env:
62-
HOST_TYPE: ci
64+
FAABRIC_DEPLOYMENT_TYPE: gha-ci
6365
REDIS_QUEUE_HOST: redis
6466
REDIS_STATE_HOST: redis
6567
container:
@@ -98,7 +100,7 @@ jobs:
98100
matrix:
99101
sanitiser: [None, Address, Thread, Undefined]
100102
env:
101-
HOST_TYPE: ci
103+
FAABRIC_DEPLOYMENT_TYPE: gha-ci
102104
REDIS_QUEUE_HOST: redis
103105
REDIS_STATE_HOST: redis
104106
container:
@@ -145,7 +147,7 @@ jobs:
145147
needs: [conan-cache]
146148
runs-on: ubuntu-latest
147149
env:
148-
HOST_TYPE: ci
150+
FAABRIC_DEPLOYMENT_TYPE: gha-ci
149151
REDIS_QUEUE_HOST: redis
150152
REDIS_STATE_HOST: redis
151153
container:

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option(FAABRIC_BUILD_TESTS "Build Faabric tests" ON)
66
option(FAABRIC_SELF_TRACING "Turn on system tracing using the logger" OFF)
77
option(FAABRIC_CODE_COVERAGE "Build Faabric with code coverage profiling" OFF)
88
option(FAABRIC_TARGET_CPU "CPU to optimise for, e.g. skylake, icelake or native" OFF)
9+
option(FAABRIC_USE_SPINLOCK "Use spinlocks for low-latency messaging" ON)
910

1011
# Enable colorized compiler output
1112
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
@@ -38,6 +39,15 @@ if(${FAABRIC_SELF_TRACING})
3839
add_definitions(-DTRACE_ALL=1)
3940
endif()
4041

42+
# We want to disable the usage of spinlocks (and CPU pinning) in GHA runners
43+
# as they have a very low number of vCPU cores
44+
if (${FAABRIC_USE_SPINLOCK} AND NOT ENV{DEPLOYMENT_TYPE} STREQUAL "gha-ci")
45+
message(STATUS "Faabric: Activated spin-locks")
46+
add_definitions(-DFAABRIC_USE_SPINLOCK)
47+
else()
48+
message(STATUS "Faabric: Disabled spin-locks")
49+
endif()
50+
4151
# Set-up use of sanitisers
4252
if (FAABRIC_USE_SANITISER STREQUAL "Address")
4353
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")

cmake/ExternalProjects.cmake

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
1515
TLS_VERIFY ON)
1616
endif()
1717

18+
set(CONAN_CMAKE_SILENT_OUTPUT ON CACHE INTERNAL "")
1819
include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)
1920

2021
conan_check(VERSION 1.63.0 REQUIRED)
@@ -73,19 +74,19 @@ conan_cmake_install(PATH_OR_REFERENCE .
7374

7475
include(${CMAKE_CURRENT_BINARY_DIR}/conan_paths.cmake)
7576

76-
find_package(absl REQUIRED)
77-
find_package(Boost 1.80.0 REQUIRED)
78-
find_package(Catch2 REQUIRED)
79-
find_package(flatbuffers REQUIRED)
80-
find_package(fmt REQUIRED)
81-
find_package(hiredis REQUIRED)
77+
find_package(absl QUIET REQUIRED)
78+
find_package(Boost 1.80.0 QUIET REQUIRED)
79+
find_package(Catch2 QUIET REQUIRED)
80+
find_package(flatbuffers QUIET REQUIRED)
81+
find_package(fmt QUIET REQUIRED)
82+
find_package(hiredis QUIET REQUIRED)
8283
# 27/01/2023 - Pin OpenSSL to a specific version to avoid incompatibilities
8384
# with the system's (i.e. Ubuntu 22.04) OpenSSL
84-
find_package(OpenSSL 3.0.2 REQUIRED)
85-
find_package(Protobuf 3.20.0 REQUIRED)
86-
find_package(readerwriterqueue REQUIRED)
87-
find_package(spdlog REQUIRED)
88-
find_package(ZLIB REQUIRED)
85+
find_package(OpenSSL 3.0.2 QUIET REQUIRED)
86+
find_package(Protobuf 3.20.0 QUIET REQUIRED)
87+
find_package(readerwriterqueue QUIET REQUIRED)
88+
find_package(spdlog QUIET REQUIRED)
89+
find_package(ZLIB QUIET REQUIRED)
8990

9091
# --------------------------------
9192
# Fetch content dependencies
@@ -109,16 +110,26 @@ set(ZSTD_LZ4_SUPPORT OFF CACHE INTERNAL "")
109110
# nng (Conan version out of date)
110111
set(NNG_TESTS OFF CACHE INTERNAL "")
111112

112-
FetchContent_Declare(zstd_ext
113-
GIT_REPOSITORY "https://github.com/facebook/zstd"
114-
GIT_TAG "v1.5.2"
115-
SOURCE_SUBDIR "build/cmake"
113+
FetchContent_Declare(atomic_queue_ext
114+
GIT_REPOSITORY "https://github.com/max0x7ba/atomic_queue"
115+
GIT_TAG "7c36f0997979a0fee5be84c9511ee0f6032057ec"
116116
)
117117
FetchContent_Declare(nng_ext
118118
GIT_REPOSITORY "https://github.com/nanomsg/nng"
119119
# NNG tagged version 1.7.1
120120
GIT_TAG "ec4b5722fba105e3b944e3dc0f6b63c941748b3f"
121121
)
122+
FetchContent_Declare(zstd_ext
123+
GIT_REPOSITORY "https://github.com/facebook/zstd"
124+
GIT_TAG "v1.5.2"
125+
SOURCE_SUBDIR "build/cmake"
126+
)
127+
128+
FetchContent_MakeAvailable(atomic_queue_ext)
129+
add_library(atomic_queue::atomic_queue ALIAS atomic_queue)
130+
131+
FetchContent_MakeAvailable(nng_ext)
132+
add_library(nng::nng ALIAS nng)
122133

123134
FetchContent_MakeAvailable(zstd_ext)
124135
# Work around zstd not declaring its targets properly
@@ -127,9 +138,6 @@ target_include_directories(libzstd_shared SYSTEM INTERFACE $<BUILD_INTERFACE:${z
127138
add_library(zstd::libzstd_static ALIAS libzstd_static)
128139
add_library(zstd::libzstd_shared ALIAS libzstd_shared)
129140

130-
FetchContent_MakeAvailable(nng_ext)
131-
add_library(nng::nng ALIAS nng)
132-
133141
# Group all external dependencies into a convenient virtual CMake library
134142
add_library(faabric_common_dependencies INTERFACE)
135143
target_include_directories(faabric_common_dependencies INTERFACE
@@ -141,6 +149,7 @@ target_link_libraries(faabric_common_dependencies INTERFACE
141149
absl::flat_hash_set
142150
absl::flat_hash_map
143151
absl::strings
152+
atomic_queue::atomic_queue
144153
Boost::Boost
145154
Boost::system
146155
flatbuffers::flatbuffers

dist-test/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pushd ${PROJ_ROOT} >> /dev/null
88
# Run the build
99
docker compose \
1010
run \
11+
-e FAABRIC_DEPLOYMENT_TYPE=gha-ci \
1112
--rm \
1213
cli \
1314
/code/faabric/dist-test/build_internal.sh

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ services:
2929
tty: true
3030
privileged: true
3131
environment:
32+
- DEPLOYMENT_TYPE=${FAABRIC_DEPLOYMENT_TYPE:-compose}
3233
- LOG_LEVEL=${LOG_LEVEL:-debug}
3334
- PLANNER_HOST=planner
3435
- PLANNER_PORT=8080
@@ -48,6 +49,7 @@ services:
4849
- ./conan-cache/:/root/.conan
4950
working_dir: /build/faabric/static
5051
environment:
52+
- DEPLOYMENT_TYPE=${FAABRIC_DEPLOYMENT_TYPE:-compose}
5153
- LOG_LEVEL=debug
5254
- PLANNER_HOST=planner
5355
- PLANNER_PORT=8080

include/faabric/mpi/MpiWorld.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ namespace faabric::mpi {
2626
// as the broker already has mocking capabilities
2727
std::vector<MpiMessage> getMpiMockedMessages(int sendRank);
2828

29+
#ifdef FAABRIC_USE_SPINLOCK
30+
typedef faabric::util::SpinLockQueue<MpiMessage> InMemoryMpiQueue;
31+
#else
2932
typedef faabric::util::FixedCapacityQueue<MpiMessage> InMemoryMpiQueue;
33+
#endif
3034

3135
class MpiWorld
3236
{

include/faabric/transport/tcp/RecvSocket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ class RecvSocket
3131
int port;
3232

3333
std::deque<int> openConnections;
34+
35+
void setSocketOptions(int connFd);
3436
};
3537
}

include/faabric/transport/tcp/SocketOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ void setReuseAddr(int connFd);
55
void setNoDelay(int connFd);
66
void setQuickAck(int connFd);
77

8+
// Blocking/Non-blocking sockets
89
void setNonBlocking(int connFd);
910
void setBlocking(int connFd);
10-
1111
bool isNonBlocking(int connFd);
12+
13+
// Enable busy polling for non-blocking sockets
14+
void setBusyPolling(int connFd);
1215
}

include/faabric/util/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SystemConfig
2727

2828
// Scheduling
2929
int overrideCpuCount;
30+
int overrideFreeCpuStart;
3031
std::string batchSchedulerMode;
3132

3233
// Worker-related timeouts

include/faabric/util/hwloc.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <pthread.h>
5+
6+
namespace faabric::util {
7+
8+
const int NO_CPU_IDX = -1;
9+
const int GHA_CPU_IDX = -2;
10+
11+
class FaabricCpuSet
12+
{
13+
public:
14+
FaabricCpuSet(int cpuIdxIn = NO_CPU_IDX);
15+
FaabricCpuSet& operator=(const FaabricCpuSet&) = delete;
16+
FaabricCpuSet(const FaabricCpuSet&) = delete;
17+
18+
~FaabricCpuSet();
19+
20+
cpu_set_t* get() { return &cpuSet; }
21+
22+
private:
23+
cpu_set_t cpuSet;
24+
25+
// CPU index in internal CPU accounting
26+
int cpuIdx = NO_CPU_IDX;
27+
};
28+
29+
// Pin thread to any "unpinned" CPUs. Returns the CPU set it was pinned to.
30+
// We return a unique pointer to enforce RAII on the pinned-to CPU
31+
std::unique_ptr<FaabricCpuSet> pinThreadToFreeCpu(pthread_t thread);
32+
}

0 commit comments

Comments
 (0)