Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
a3a10d4
Replace `volatile bool`s with `std::atomic<bool>`s
Bidski Jun 6, 2023
e07753d
Add sanitisation compile options
Bidski Jun 6, 2023
fb37432
Add colourised compiler output
Bidski Jun 6, 2023
24a7848
Replace `volatile bool`s with `std::atomic<bool>`s
Bidski Jun 6, 2023
619ee7c
Add unit test for sync priority queue
Bidski Jun 6, 2023
4aa971d
Add missing include
Bidski Jun 6, 2023
76526bd
Add extra source annotations to improve valgrind support
Bidski Jun 6, 2023
b76b397
Add missing includes
Bidski Jun 6, 2023
75a98f6
Replace `volatile bool`s with `std::atomic<bool>`s
Bidski Jun 6, 2023
69480c4
Lock mutex before calling `notify_all()`
Bidski Jun 6, 2023
a65fe4c
Use `lock_guard`
Bidski Jun 6, 2023
b7a590a
Store `true` rather than `false`
Bidski Jun 6, 2023
b3a8525
Merge remote-tracking branch 'origin/main' into biddulph/stuff
Bidski Jun 8, 2023
0d6722a
Add missing includes
Bidski Jun 8, 2023
2b90f12
Add a Group fusion word
Bidski Jun 8, 2023
8e15607
Add a Pool fusion word
Bidski Jun 8, 2023
f3e69e3
Update CallbackGenerator to use `pool` and `group`
Bidski Jun 8, 2023
0d4fd91
Rewrite TaskScheduler to handle everything
Bidski Jun 8, 2023
6243f00
Add missing `Pool` word to `Reactor`
Bidski Jun 8, 2023
1f7101a
Add an `immediate` flag to `ReactionTask` for `Direct` emits
Bidski Jun 8, 2023
bfa865f
Rewrite `Always` to suit new `TaskScheduler`
Bidski Jun 8, 2023
6f5e82b
Change `Initialise` emits to an emit with no delay
Bidski Jun 8, 2023
56ee199
Change `MainThread` to use the main thread pool
Bidski Jun 8, 2023
6a1a774
Implement `Pool` `DSL`
Bidski Jun 8, 2023
ee85a92
`#undef` valgrind symbols before setting them
Bidski Jun 8, 2023
7a3c4ef
Remove reschedule
TrentHouliston Jun 9, 2023
daa6ce9
formatting
TrentHouliston Jun 10, 2023
35729a2
Merge remote-tracking branch 'origin/main' into biddulph/stuff
Bidski Jun 13, 2023
7eb0215
Apply clang-tidy fixes
Bidski Jun 14, 2023
0b9c0d8
Make Always work
Bidski Jun 14, 2023
c193a19
Fix MainThread
Bidski Jun 14, 2023
06c2bcc
Fix parsing
Bidski Jun 14, 2023
3984a07
Fix ChronoController shutdown
Bidski Jun 14, 2023
2bc1ea2
Remove `keep_alive`
Bidski Jun 14, 2023
d0da0b7
Control when threads are started
Bidski Jun 14, 2023
6f91b63
Update unit tests
Bidski Jun 14, 2023
706653a
Add a group descriptor to handle group concurrency
Bidski Jun 14, 2023
5acdda8
Fix task sort order
Bidski Jun 14, 2023
975e276
Fix task sort order
Bidski Jun 14, 2023
91041a5
Move task running to separate function
Bidski Jun 14, 2023
bf567e5
Initialise thread pools to zero threads
Bidski Jun 14, 2023
d5e5f65
Add labels to single reactions
Bidski Jun 14, 2023
f965646
Shutdown before require in main thread
Bidski Jun 14, 2023
ea2cd23
Use vector of strings for single sync test
Bidski Jun 14, 2023
594304d
Fix group usage in scheduler
Bidski Jun 14, 2023
b3e1e1f
Apply clang-tidy fixes
Bidski Jun 14, 2023
d515115
Fix main thread issue
Bidski Jun 15, 2023
c595a35
Simplify `Always` code
Bidski Jun 16, 2023
3fdecbd
Fix group descriptor generation
Bidski Jun 16, 2023
f0e81b8
Fix pool descriptor generation
Bidski Jun 16, 2023
0dd75b6
Fix log test
Bidski Jun 16, 2023
2ebcfe7
Create a task queue per thread pool
Bidski Jun 16, 2023
cfb3a04
Silence clang-tidy
Bidski Jun 16, 2023
b7c6ef5
Keep running even if one gcc job fails
Bidski Jun 16, 2023
c472441
Move thread pool descriptor constant initalisers to cpp file
Bidski Jun 16, 2023
8003149
Don't use `std::enable_if_t`
Bidski Jun 16, 2023
7028145
Apply `remove_cvref` to `enable_if` call
Bidski Jun 18, 2023
0429f98
Increase group count earlier
Bidski Jun 19, 2023
7f5fe18
Rewrite immediate logic
Bidski Jun 19, 2023
ceeb116
Poke thread pools before joining
Bidski Jun 19, 2023
82ca926
Fix comment
Bidski Jun 19, 2023
d7172f2
Fix segfault
Bidski Jun 19, 2023
14112a2
Reduce number of mutexes
Bidski Jun 20, 2023
e029540
Fix up comments for always
Bidski Jun 20, 2023
b3a266e
Fix unbinder for always
Bidski Jun 20, 2023
dade557
Add labels to reactions
Bidski Jun 20, 2023
920ad53
Fix comment reflow
Bidski Jun 20, 2023
78104e7
Fix comment
Bidski Jun 20, 2023
f3e4b44
Simplify diff in ChronoController
Bidski Jun 20, 2023
3884744
Simplify statics for pools and groups
Bidski Jun 20, 2023
d1628b9
RAII-ify `current_task`
Bidski Jun 20, 2023
1d37e20
Make sure `nullptr`s are sorted first
Bidski Jun 20, 2023
1003343
Unify thread pool structs
Bidski Jun 20, 2023
6fad9fb
Make CallbackGenerator constructor explicit
Bidski Jun 20, 2023
73653dc
Revert "Make CallbackGenerator constructor explicit"
Bidski Jun 20, 2023
7ae4e75
Fix post-shutdown logging
Bidski Jun 21, 2023
071f074
Emit a lot more messages for `SingleSync` test
Bidski Jun 21, 2023
312d28d
Fix up comments
Bidski Jun 21, 2023
fcffd7b
Revert RAII-ify
Bidski Jun 21, 2023
eebe07d
Do thread poking once before joining
Bidski Jun 21, 2023
6281e95
Base `Sync` on `Group`
Bidski Jun 21, 2023
8395569
Include `Group` in `Reactor`
Bidski Jun 21, 2023
fdd1469
Remove valgrind and sanitiser stuff
Bidski Jun 21, 2023
bbb3abc
Add options for valgrind, sanitisers, and profiling
Bidski Jun 21, 2023
cbb3134
Fix up cmake formatting
Bidski Jun 21, 2023
9ea6f63
clang-tidy
Bidski Jun 21, 2023
79f576d
Merge branch 'biddulph/stuff' into biddulph/sanitisers
Bidski Jun 21, 2023
68da88a
Rebase on main
Bidski Jun 23, 2023
21cfbed
Finish rebase
Bidski Jun 23, 2023
61eca93
Finish finish rebase
Bidski Jun 23, 2023
f8e138a
Merge branch 'main' into biddulph/sanitisers
Bidski Jun 29, 2023
69d899d
Merge branch 'main' into biddulph/sanitisers
TrentHouliston Sep 15, 2023
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
9 changes: 3 additions & 6 deletions .cmake-format
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ command_case: lower
# Format keywords consistently as 'lower' or 'upper' case
keyword_case: upper

# enable comment markup parsing and reflow
enable_markup: False

# Setup all the additional commands
additional_commands:
header_library:
kwargs:
NAME: "*"
HEADER: "*"
PATH_SUFFIX: "*"
URL: "*"
header_library:
kwargs:
NAME: "*"
Expand Down
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,64 @@ if(CI_BUILD)
endif()
endif(CI_BUILD)

# When using valgrind data race detector or helgrind (both are for debugging issues with threading and data races)
# certain symbols need to be overridden to enable better stack traces. This option enables those extra things
# See https://valgrind.org/docs/manual/drd-manual.html#drd-manual.CXX11 for more details
#
# This is disabled by default and will only be enabled when this option is enabled AND NDEBUG is NOT defined (so compiling in debug mode)
option(USE_VALGRIND "Add extra annotations for better valgrind handling" OFF)
if(USE_VALGRIND)
add_compile_options(-DUSE_VALGRIND)
endif(USE_VALGRIND)

###############################################################################
### Options for enabling different sanitisers. ###
### ###
### User beware: ###
### Not all sanitisers can be enabled at the same time. ###
###############################################################################
option(USE_ASAN "Enable address sanitization" OFF)
if(USE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common)
add_link_options(-fsanitize=address)
link_libraries(asan)
endif(USE_ASAN)

option(USE_LSAN "Enable leak sanitization" OFF)
if(USE_LSAN)
add_compile_options(-fsanitize=leak -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common)
add_link_options(-fsanitize=leak)
link_libraries(lsan)
endif(USE_LSAN)

option(USE_TSAN "Enable thread sanitization" OFF)
if(USE_TSAN)
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common)
add_link_options(-fsanitize=thread)
link_libraries(tsan)
endif(USE_TSAN)

option(USE_UBSAN "Enable undefined behaviour sanitization" OFF)
if(USE_UBSAN)
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer -U_FORTIFY_SOURCE -fno-common)
add_link_options(-fsanitize=undefined)
link_libraries(ubsan)
endif(USE_UBSAN)

# Option for enabling code profiling. Disabled by default
option(ENABLE_PROFILING "Compile with profiling support enabled.")
if(ENABLE_PROFILING)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(
WARNING
"Profiling is enabled but no debugging symbols will be kept in the compiled binaries. This may cause fine-grained profilling data to be lost."
)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -fprofile-arcs")
set(CMAKE_LINKER "${CMAKE_LINKER_FLAGS} -pg -fprofile-arcs")
endif(ENABLE_PROFILING)

# Make the compiler display colours always (even when we build with ninja)
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
add_compile_options(-fdiagnostics-color=always)
Expand Down
6 changes: 6 additions & 0 deletions src/PowerPlant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#ifndef NUCLEAR_POWERPLANT_HPP
#define NUCLEAR_POWERPLANT_HPP

// This file needs to be included in a spot that means it will be included everywhere
// See https://valgrind.org/docs/manual/drd-manual.html#drd-manual.CXX11
#if defined(USE_VALGRIND) && !defined(NDEBUG)
#include "util/valgrind/valgrind.hpp"
#endif // defined(USE_VALGRIND) && !defined(NDEBUG)

#include <atomic>
#include <iostream>
#include <map>
Expand Down
54 changes: 54 additions & 0 deletions src/util/valgrind/valgrind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2023 Alex Biddulph <bidskii@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#if defined(USE_VALGRIND) && !defined(NDEBUG)
// NOLINTBEGIN
// _State_ptr and State are private members od std::thread, this define allows them to not be private
#define _GLIBCXX_THREAD_IMPL 1
#include <thread>
#undef _GLIBCXX_THREAD_IMPL

#include <system_error>

namespace std {
extern "C" {
static void* execute_native_thread_routine(void* __p) {
thread::_State_ptr __t{static_cast<thread::_State*>(__p)};
__t->_M_run();
return nullptr;
}
void thread::_M_start_thread(_State_ptr state, void (*depend)()) {
// Make sure it's not optimized out, not even with LTO.
asm("" : : "rm"(depend));

if (!__gthread_active_p()) {
#if __cpp_exceptions
throw system_error(make_error_code(errc::operation_not_permitted), "Enable multithreading to use std::thread");
#else
__builtin_abort();
#endif
}

const int err = __gthread_create(&_M_id._M_thread, &execute_native_thread_routine, state.get());
if (err)
__throw_system_error(err);
state.release();
}
}
} // namespace std
// NOLINTEND
#endif // defined(USE_VALGRIND) && !defined(NDEBUG)
25 changes: 25 additions & 0 deletions src/util/valgrind/valgrind.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2023 Alex Biddulph <bidskii@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// See https://valgrind.org/docs/manual/drd-manual.html#drd-manual.CXX11
#if defined(USE_VALGRIND) && !defined(NDEBUG)
#include <valgrind/drd.h>
#undef _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE
#undef _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(addr) ANNOTATE_HAPPENS_BEFORE(addr) // NOLINT
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(addr) ANNOTATE_HAPPENS_AFTER(addr) // NOLINT
#endif // defined(USE_VALGRIND) && !defined(NDEBUG)