Skip to content

Commit 1b6d6d7

Browse files
Task system: Send incoming tasks directly to waiting executors (#7315)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 47701f3 commit 1b6d6d7

32 files changed

+762
-374
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Checks: >
88
-bugprone-assignment-in-if-condition,
99
-bugprone-casting-through-void,
1010
cert-*,
11+
-cert-con36-c,
12+
-cert-con54-cpp,
1113
-cert-err58-cpp,
1214
-cert-dcl50-cpp,
1315
concurrency-*,

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ add_ccf_static_library(
279279
# CCF task system library
280280
add_ccf_static_library(
281281
ccf_tasks
282-
SRCS ${CCF_DIR}/src/tasks/task_system.cpp ${CCF_DIR}/src/tasks/job_board.cpp
282+
SRCS ${CCF_DIR}/src/tasks/task_system.cpp
283+
${CCF_DIR}/src/tasks/job_board.cpp
283284
${CCF_DIR}/src/tasks/ordered_tasks.cpp
284285
${CCF_DIR}/src/tasks/fan_in_tasks.cpp
286+
${CCF_DIR}/src/tasks/thread_manager.cpp
285287
)
286288

287289
# Common test args for Python scripts starting up CCF networks
@@ -564,6 +566,7 @@ if(BUILD_TESTS)
564566
${CMAKE_CURRENT_SOURCE_DIR}/src/tasks/test/ordered_tasks.cpp
565567
${CMAKE_CURRENT_SOURCE_DIR}/src/tasks/test/delayed_tasks.cpp
566568
${CMAKE_CURRENT_SOURCE_DIR}/src/tasks/test/fan_in_tasks.cpp
569+
${CMAKE_CURRENT_SOURCE_DIR}/src/tasks/test/tasks_api.cpp
567570
)
568571
target_link_libraries(task_system_test PRIVATE ccf_tasks)
569572

doc/build_apps/example_cpp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ A :cpp:type:`ccf::indexing::Strategy` may offload partial results to disk to avo
221221
Since the indexing system and all the strategies it manages exist entirely within the enclave, this has the same trust guarantees as any other in-enclave code - users can trust that the results are accurate and complete, and the query may process private data.
222222

223223
An example :cpp:type:`ccf::indexing::Strategy` is included in the logging app, to accelerate historical range queries.
224-
This :cpp:type:`strategy <ccf::indexing::strategies::SeqnosByKey_Bucketed_Untyped>` stores the list of seqnos where every key is written to, offloading completed ranges to disk to cap the total memory useage.
224+
This :cpp:type:`strategy <ccf::indexing::strategies::SeqnosByKey_Bucketed_Untyped>` stores the list of seqnos where every key is written to, offloading completed ranges to disk to cap the total memory usage.
225225
In the endpoint handler, rather than requesting every transaction in the requested range, the node relies on its index to fetch only the `interesting` transactions; those which write to the target key:
226226

227227
.. literalinclude:: ../../samples/apps/logging/logging.cpp

src/tasks/basic_task.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ namespace ccf::tasks
1313
Fn fn;
1414
const std::string name;
1515

16-
BasicTask(const Fn& _fn, const std::string& s = "[Anon]") : fn(_fn), name(s)
16+
BasicTask(const Fn& fn_, const std::string& s = "BasicTask") :
17+
fn(fn_),
18+
name(s)
1719
{}
1820

1921
void do_task_implementation() override
2022
{
2123
fn();
2224
}
2325

24-
std::string_view get_name() const override
26+
const std::string& get_name() const override
2527
{
2628
return name;
2729
}

src/tasks/fan_in_tasks.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace ccf::tasks
1414
{
1515
struct FanInTasks::PImpl
1616
{
17-
std::string name;
18-
IJobBoard& job_board;
17+
JobBoard& job_board;
1918

2019
// Synchronise access to pending_tasks and next_expected_task_index
2120
std::mutex pending_tasks_mutex;
@@ -71,16 +70,16 @@ namespace ccf::tasks
7170

7271
FanInTasks::FanInTasks(
7372
[[maybe_unused]] FanInTasks::Private force_private_constructor,
74-
IJobBoard& job_board_,
75-
const std::string& name_) :
76-
pimpl(std::make_unique<FanInTasks::PImpl>(name_, job_board_))
73+
JobBoard& job_board_) :
74+
pimpl(std::make_unique<FanInTasks::PImpl>(job_board_))
7775
{}
7876

7977
FanInTasks::~FanInTasks() = default;
8078

81-
std::string_view FanInTasks::get_name() const
79+
const std::string& FanInTasks::get_name() const
8280
{
83-
return pimpl->name;
81+
static const std::string name = "FanInTasks";
82+
return name;
8483
}
8584

8685
void FanInTasks::add_task(size_t task_index, Task task)
@@ -124,9 +123,8 @@ namespace ccf::tasks
124123
}
125124
}
126125

127-
std::shared_ptr<FanInTasks> FanInTasks::create(
128-
IJobBoard& job_board_, const std::string& name_)
126+
std::shared_ptr<FanInTasks> FanInTasks::create(JobBoard& job_board_)
129127
{
130-
return std::make_shared<FanInTasks>(Private{}, job_board_, name_);
128+
return std::make_shared<FanInTasks>(Private{}, job_board_);
131129
}
132130
}

src/tasks/fan_in_tasks.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5-
#include "tasks/job_board_interface.h"
5+
#include "tasks/job_board.h"
66
#include "tasks/task.h"
77

88
#include <memory>
@@ -27,13 +27,12 @@ namespace ccf::tasks
2727
};
2828

2929
public:
30-
FanInTasks(Private, IJobBoard& job_board_, const std::string& name_);
30+
FanInTasks(Private, JobBoard& job_board_);
3131
~FanInTasks();
3232

33-
static std::shared_ptr<FanInTasks> create(
34-
IJobBoard& job_board_, const std::string& name_ = "[FanIn]");
33+
static std::shared_ptr<FanInTasks> create(JobBoard& job_board_);
3534

36-
std::string_view get_name() const override;
35+
const std::string& get_name() const override;
3736

3837
void add_task(size_t task_index, Task task);
3938
};

0 commit comments

Comments
 (0)