Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
971f512
[#56] Fix update current thread priority for linux and make an enum
CMurtagh-LGTM Dec 15, 2024
016dce3
add documentation to Priority DSL and util
CMurtagh-LGTM Dec 15, 2024
2dba179
fix tests
CMurtagh-LGTM Dec 15, 2024
078dfd9
Restore the API keeping the enums, and make ThreadPriority be an RAII…
TrentHouliston Dec 23, 2024
d128891
Refactor logging and allow setting a minimum log level that should no…
TrentHouliston Dec 19, 2024
bf98d60
Merge remote-tracking branch 'origin/main' into houliston/priority-ch…
TrentHouliston Dec 23, 2024
11b2b5d
Some smart enum fixes
TrentHouliston Dec 23, 2024
2b6c08d
Didn't need this
TrentHouliston Dec 23, 2024
d3b15fd
Merge branch 'main' into houliston/priority-changes
TrentHouliston Dec 23, 2024
5dcba82
Minor fixes
TrentHouliston Dec 23, 2024
f3ad6e6
.
TrentHouliston Dec 23, 2024
cebe293
clang-tidy
TrentHouliston Dec 23, 2024
82f8464
clang-tidy
TrentHouliston Dec 23, 2024
f13936b
Fix deleted constructor
TrentHouliston Dec 23, 2024
36079f2
clang-tidy
TrentHouliston Dec 23, 2024
e8ed950
Redundant static
TrentHouliston Dec 23, 2024
353d437
clang-tidy and make setting scheduler priority ignore unknown enum va…
TrentHouliston Dec 23, 2024
32c767b
Swap to using a different mechanism for osx
TrentHouliston Dec 23, 2024
925dca0
remove header
TrentHouliston Dec 23, 2024
15c6c3b
Better macos setup
TrentHouliston Dec 23, 2024
27b1a9c
.
TrentHouliston Dec 23, 2024
a77fd65
Flag PriorityLevel and LogLevel constructors as noexcept
TrentHouliston Dec 23, 2024
7ca97d8
.
TrentHouliston Dec 23, 2024
4fefe3c
Adjust the sync-multi test to just care about relative order of event…
TrentHouliston Dec 23, 2024
c665e1f
Try to work out what's wrong with gcovr
TrentHouliston Dec 24, 2024
9b85a71
.
TrentHouliston Dec 24, 2024
1b768ce
change coverage flags
TrentHouliston Dec 24, 2024
81ea199
Try ignoring this error since it's all the Catch2 framework stuff tha…
TrentHouliston Dec 24, 2024
3e70785
Add priority level tests, fix headers and standardise with log level …
TrentHouliston Dec 24, 2024
bd611d2
Find a better way to get sonarqube to run
TrentHouliston Dec 24, 2024
9258b5a
missing newline
TrentHouliston Dec 24, 2024
4c095fe
missed removing an enum
TrentHouliston Dec 24, 2024
e743781
Put coverage just on the nuclear library and things that link to it
TrentHouliston Dec 25, 2024
66a7add
.
TrentHouliston Dec 25, 2024
e2b6f11
Fix including within a namespace
TrentHouliston Dec 25, 2024
d5dd07a
Went a little crazy on the find and replace
TrentHouliston Dec 25, 2024
cff873d
Merge branch 'main' into houliston/priority-changes
TrentHouliston Dec 25, 2024
e1dba71
The size returned is unchanged, so it just had a bunch of nulls in it
TrentHouliston Dec 31, 2024
e423040
Add more priority levels so realtime tasks aren't interrupted by thre…
TrentHouliston Dec 31, 2024
b32a743
Merge branch 'main' into houliston/priority-changes
TrentHouliston Dec 31, 2024
e9e797c
Missed some changes
TrentHouliston Dec 31, 2024
08a9699
Merge branch 'main' into houliston/priority-changes
TrentHouliston Jan 2, 2025
ff0c77b
clang-tidy
TrentHouliston Jan 2, 2025
5097525
clang-tidy
TrentHouliston Jan 2, 2025
fd86199
Merge branch 'main' into houliston/priority-changes
TrentHouliston Jan 25, 2025
8723bde
thread_local only now
TrentHouliston Feb 5, 2025
55e96a9
Merge branch 'main' into houliston/priority-changes
TrentHouliston Feb 5, 2025
8947753
iwyu
TrentHouliston Feb 5, 2025
fb4bd64
Merge branch 'main' into houliston/priority-changes
TrentHouliston Feb 5, 2025
6e5558f
Add a default case
TrentHouliston Feb 5, 2025
fd41569
IWYU
TrentHouliston Feb 5, 2025
a3749b9
.
TrentHouliston Feb 5, 2025
cd81cd2
Merge branch 'main' into houliston/priority-changes
TrentHouliston Feb 6, 2025
18618ef
Fix handling of priority and don't change if it's the same value
TrentHouliston Feb 10, 2025
80a2543
Turn mac back to the old format
TrentHouliston Feb 10, 2025
0229942
This did nothing!
TrentHouliston Feb 10, 2025
869edc1
Try doing nothing on mac
TrentHouliston Feb 11, 2025
47f11cc
foiled by Werror
TrentHouliston Feb 11, 2025
e00464a
Match the pool priority even though it doesn't matter (system was alr…
TrentHouliston Feb 11, 2025
9629085
Fix date
TrentHouliston Feb 11, 2025
a2551d5
Measure accuracy for the waiting at the thread priority you run at
TrentHouliston Feb 11, 2025
80cf28d
re-enable mac priority
TrentHouliston Feb 11, 2025
24457d6
fix date
TrentHouliston Feb 12, 2025
f59065e
Should be realtime
TrentHouliston Feb 12, 2025
d0c167b
Fix bug where priority isn't set
TrentHouliston Feb 12, 2025
504e267
Test removing setting priority for the thread pool parts
TrentHouliston Feb 12, 2025
168221f
Undo change
TrentHouliston Feb 12, 2025
f25b758
Add a test that thread priority
TrentHouliston Feb 12, 2025
89971e0
.
TrentHouliston Feb 12, 2025
b3a88cd
clang-tidy
TrentHouliston Feb 12, 2025
2871306
Add the nice capability to the test binaries so they can use the real…
TrentHouliston Feb 12, 2025
c850856
Set priority to normal to start with
TrentHouliston Feb 12, 2025
8fcd0a3
add sudo to the container
TrentHouliston Feb 12, 2025
44db792
Fix Get SCHED_FIFO Calculation.
WongAaronSW Feb 12, 2025
358bc2f
make the gcc runners privliged so they can use cap_sys_nice
TrentHouliston Feb 12, 2025
02c3091
clang-tidy
TrentHouliston Feb 12, 2025
0470de8
clang-tidy
TrentHouliston Feb 12, 2025
8309ea3
clang-tidy
TrentHouliston Feb 13, 2025
b983322
Give SonarCloud more time to Run Tests.
WongAaronSW Feb 13, 2025
165d759
Drop the Number of Loops in IdleSingleGlobal
WongAaronSW Feb 13, 2025
bdd071b
Revert the SonarCloud TimeUnit Change
WongAaronSW Feb 13, 2025
afb7483
Change ReactionStatistics and TimeTravel Timeout to use TimeUnits.
WongAaronSW Feb 13, 2025
2c65b6c
Merge branch 'main' into houliston/priority-changes
TrentHouliston Mar 6, 2025
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: 7 additions & 2 deletions .github/workflows/gcc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
continue-on-error: true

# Use the container for this specific version of gcc
container: ${{ matrix.toolchain.container }}
container:
image: ${{ matrix.toolchain.container }}
options: --privileged

steps:
- name: Checkout Code
Expand All @@ -49,7 +51,7 @@ jobs:
# Update for all the actions that need to install stuff
- run: |
apt-get update
apt-get install -y software-properties-common unzip
apt-get install -y software-properties-common unzip sudo

- name: Install GCC
run: |
Expand Down Expand Up @@ -90,6 +92,9 @@ jobs:
- name: CCache Stats
run: ccache --show-stats

- name: Add capabilities for scheduler
run: find build/tests -type f -executable -exec sudo setcap cap_sys_nice=eip {} \; || true

- name: Test
timeout-minutes: 2
working-directory: build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sonarcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:
timeout-minutes: 30
run: cmake --build build/ --config Release

- name: Add capabilities for scheduler
run: find build/tests -type f -executable -exec sudo setcap cap_sys_nice=eip {} \; || true

- name: Run tests to generate coverage statistics
timeout-minutes: 10
working-directory: build
Expand Down
6 changes: 3 additions & 3 deletions src/LogLevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class LogLevel {
*
* @param value The value to construct the LogLevel from
*/
constexpr LogLevel(const Value& value = Value::UNKNOWN) : value(value) {};
constexpr LogLevel(const Value& value = Value::UNKNOWN) noexcept : value(value) {}

/**
* Construct a LogLevel from a string
Expand Down Expand Up @@ -168,7 +168,7 @@ class LogLevel {
*
* @return The ostream that was passed in
*/
friend std::ostream& operator<<(std::ostream& os, LogLevel level) {
friend std::ostream& operator<<(std::ostream& os, const LogLevel& level) {
return os << static_cast<std::string>(level);
}

Expand Down Expand Up @@ -208,11 +208,11 @@ class LogLevel {
friend bool operator!=(const std::string& lhs, const LogLevel& rhs) { return lhs != static_cast<std::string>(rhs); }
// clang-format on


private:
/// The stored enum value
Value value;
};

} // namespace NUClear

#endif // NUCLEAR_LOGLEVEL_HPP
156 changes: 156 additions & 0 deletions src/PriorityLevel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* MIT License
*
* Copyright (c) 2024 NUClear Contributors
*
* This file is part of the NUClear codebase.
* See https://github.com/Fastcode/NUClear for further info.
*
* 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.
*/

#ifndef NUCLEAR_PRIORITY_LEVEL_HPP
#define NUCLEAR_PRIORITY_LEVEL_HPP

#include <cstdint>
#include <string>

namespace NUClear {

class PriorityLevel {
public:
enum Value : uint8_t {
UNKNOWN = 0,
IDLE = 1,
LOWEST = 2,
LOW = 3,
NORMAL = 4,
HIGH = 5,
HIGHEST = 6,
REALTIME = 7
};

/**
* Construct a PriorityLevel from a Value
*
* @param value The value to construct the PriorityLevel from
*/
constexpr PriorityLevel(const Value& value = Value::NORMAL) noexcept : value(value) {}

/**
* Construct a PriorityLevel from a string
*
* @param level The string to construct the PriorityLevel from
*/
PriorityLevel(const std::string& level)
: value(level == "IDLE" ? Value::IDLE
: level == "LOWEST" ? Value::LOWEST
: level == "LOW" ? Value::LOW
: level == "NORMAL" ? Value::NORMAL
: level == "HIGH" ? Value::HIGH
: level == "HIGHEST" ? Value::HIGHEST
: level == "REALTIME" ? Value::REALTIME
: Value::NORMAL) {}

/**
* A call operator which will return the value of the PriorityLevel
* This can be useful in situations where the implicit conversion operators are ambiguous.
*
* @return The value of the PriorityLevel
*/
constexpr Value operator()() const {
return value;
}

/**
* A conversion operator which will return the value of the PriorityLevel
*
* @return The value of the PriorityLevel
*/
constexpr operator Value() const {
return value;
}

/**
* A conversion operator which will return the string representation of the PriorityLevel
*
* @return The string representation of the PriorityLevel
*/
operator std::string() const {
return value == Value::IDLE ? "IDLE"
: value == Value::LOWEST ? "LOWEST"
: value == Value::LOW ? "LOW"
: value == Value::NORMAL ? "NORMAL"
: value == Value::HIGH ? "HIGH"
: value == Value::HIGHEST ? "HIGHEST"
: value == Value::REALTIME ? "REALTIME"
: "UNKNOWN";
}

/**
* Stream the PriorityLevel to an ostream, it will output the string representation of the PriorityLevel
*
* @param os The ostream to output to
* @param level The PriorityLevel to output
*
* @return The ostream that was passed in
*/
friend std::ostream& operator<<(std::ostream& os, const PriorityLevel& level) {
return os << static_cast<std::string>(level);
}

// Operators to compare PriorityLevel values and PriorityLevel to Value
// clang-format off
friend constexpr bool operator<(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value < rhs.value; }
friend constexpr bool operator>(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value > rhs.value; }
friend constexpr bool operator<=(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value <= rhs.value; }
friend constexpr bool operator>=(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value >= rhs.value; }
friend constexpr bool operator==(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value == rhs.value; }
friend constexpr bool operator!=(const PriorityLevel& lhs, const PriorityLevel& rhs) { return lhs.value != rhs.value; }

friend constexpr bool operator<(const PriorityLevel& lhs, const Value& rhs) { return lhs.value < rhs; }
friend constexpr bool operator>(const PriorityLevel& lhs, const Value& rhs) { return lhs.value > rhs; }
friend constexpr bool operator<=(const PriorityLevel& lhs, const Value& rhs) { return lhs.value <= rhs; }
friend constexpr bool operator>=(const PriorityLevel& lhs, const Value& rhs) { return lhs.value >= rhs; }
friend constexpr bool operator==(const PriorityLevel& lhs, const Value& rhs) { return lhs.value == rhs; }
friend constexpr bool operator!=(const PriorityLevel& lhs, const Value& rhs) { return lhs.value != rhs; }
friend constexpr bool operator<(const Value& lhs, const PriorityLevel& rhs) { return lhs < rhs.value; }
friend constexpr bool operator>(const Value& lhs, const PriorityLevel& rhs) { return lhs > rhs.value; }
friend constexpr bool operator<=(const Value& lhs, const PriorityLevel& rhs) { return lhs <= rhs.value; }
friend constexpr bool operator>=(const Value& lhs, const PriorityLevel& rhs) { return lhs >= rhs.value; }
friend constexpr bool operator==(const Value& lhs, const PriorityLevel& rhs) { return lhs == rhs.value; }
friend constexpr bool operator!=(const Value& lhs, const PriorityLevel& rhs) { return lhs != rhs.value; }

friend bool operator<(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) < rhs; }
friend bool operator>(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) > rhs; }
friend bool operator<=(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) <= rhs; }
friend bool operator>=(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) >= rhs; }
friend bool operator==(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) == rhs; }
friend bool operator!=(const PriorityLevel& lhs, const std::string& rhs) { return static_cast<std::string>(lhs) != rhs; }
friend bool operator<(const std::string& lhs, const PriorityLevel& rhs) { return lhs < static_cast<std::string>(rhs); }
friend bool operator>(const std::string& lhs, const PriorityLevel& rhs) { return lhs > static_cast<std::string>(rhs); }
friend bool operator<=(const std::string& lhs, const PriorityLevel& rhs) { return lhs <= static_cast<std::string>(rhs); }
friend bool operator>=(const std::string& lhs, const PriorityLevel& rhs) { return lhs >= static_cast<std::string>(rhs); }
friend bool operator==(const std::string& lhs, const PriorityLevel& rhs) { return lhs == static_cast<std::string>(rhs); }
friend bool operator!=(const std::string& lhs, const PriorityLevel& rhs) { return lhs != static_cast<std::string>(rhs); }
// clang-format on

private:
/// The stored enum value
Value value;
};

} // namespace NUClear

#endif // NUCLEAR_PRIORITY_LEVEL_HPP
6 changes: 3 additions & 3 deletions src/dsl/Parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ namespace dsl {
Parse<Sentence...>>(task);
}

static int priority(threading::ReactionTask& task) {
static PriorityLevel priority(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_priority<DSL>::value, DSL, fusion::NoOp>::template priority<
Parse<Sentence...>>(task);
}

static auto scope(threading::ReactionTask& task)
-> decltype(std::conditional_t<fusion::has_scope<DSL>::value, DSL, fusion::NoOp>::template scope<
Parse<Sentence...>>(task)) {
return std::conditional_t<fusion::has_scope<DSL>::value, DSL, fusion::NoOp>::template scope<Parse<Sentence...>>(
task);
return std::conditional_t<fusion::has_scope<DSL>::value, DSL, fusion::NoOp>::template scope<
Parse<Sentence...>>(task);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/dsl/fusion/NoOp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ namespace dsl {
}

template <typename DSL>
static int priority(const threading::ReactionTask& /*task*/) {
return word::Priority::NORMAL::value;
static PriorityLevel priority(const threading::ReactionTask& /*task*/) {
return PriorityLevel::NORMAL;
}

template <typename DSL>
Expand Down
4 changes: 2 additions & 2 deletions src/dsl/fusion/PriorityFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace dsl {
struct PriorityFuser<std::tuple<Word>> {

template <typename DSL>
static int priority(threading::ReactionTask& task) {
static PriorityLevel priority(threading::ReactionTask& task) {

// Return our priority
return Word::template priority<DSL>(task);
Expand All @@ -56,7 +56,7 @@ namespace dsl {
struct PriorityFuser<std::tuple<Word1, Word2, WordN...>> {

template <typename DSL>
static int priority(threading::ReactionTask& task) {
static PriorityLevel priority(threading::ReactionTask& task) {

// Choose our maximum priority
return std::max(Word1::template priority<DSL>(task),
Expand Down
17 changes: 10 additions & 7 deletions src/dsl/word/Always.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@ namespace dsl {
static std::unique_ptr<threading::ReactionTask> make_idle_task(
const std::shared_ptr<threading::Reaction>& reaction) {

auto idle_task = std::make_unique<threading::ReactionTask>(
reaction,
false,
[](threading::ReactionTask& task) { return DSL::priority(task) - 1; },
DSL::run_inline,
DSL::pool,
DSL::group);
auto idle_task = std::make_unique<threading::ReactionTask>(reaction,
false,
DSL::priority,
DSL::run_inline,
DSL::pool,
DSL::group);


// Manipulate the id so it always runs after the always task
idle_task->id = std::numeric_limits<NUClear::id_t>::max();

idle_task->callback = [](threading::ReactionTask& task) {
// Submit the always and idle tasks to the scheduler
Expand Down
Loading
Loading