Peano
Loading...
Searching...
No Matches
tarch::multicore::taskfusion::FusableTasksQueue Class Reference

Represents a queue of fusable tasks. More...

#include <FusableTasksQueue.h>

Collaboration diagram for tarch::multicore::taskfusion::FusableTasksQueue:

Public Member Functions

 FusableTasksQueue (int type_)
 
 ~FusableTasksQueue ()=default
 
 FusableTasksQueue (const FusableTasksQueue &)=delete
 
void insertReadyTask (Task *task, int taskNumber)
 Insert a new ready task into the local queues.
 
void drainReadyTasks ()
 Drain all the ready tasks.
 
TaskNumber getFirstReadyTaskNumber ()
 Return number of first ready task.
 
std::pair< TaskNumber, Task * > extractFirstReadyTask (TaskNumber handlingTask)
 Get first ready task.
 
TaskextractReadyTask (TaskNumber taskNumber, TaskNumber handlingTask)
 Extract specific ready task.
 
void runningTaskFinished (TaskNumber taskNumber)
 
TaskNumber getTaskHandlingRunningTask (TaskNumber taskNumber)
 
void updateTaskFusionProbabilities (bool triggerFusion)
 Update the internal stats.
 
std::pair< TaskNumber, Task * > extractReadyTask (TaskNumber handlingTask)
 
bool isTaskReadyOrRunning (int taskNumber, bool tryLock)
 
bool isTaskReady (int taskNumber, bool tryLock)
 
int getType () const
 
int getNumberOfReadyTasks ()
 Query the number of ready tasks.
 

Static Public Attributes

static constexpr int AnyTask = -1
 
static const std::string SizeOfFusableTaskQueueStatisticsIdentifier
 
static constexpr bool UseTryLockAndReturnTrueIfLockFailed = true
 Can be used with the queries below if you prefer those names over the boolean values.
 
static constexpr bool LockQueueAndReturnReliableResult = false
 

Private Types

using ReadyTasks = std::map< int, tarch::multicore::Task* >
 Each task in the queue is identified through a pointer to the task plus a task (dependency) number.
 
using RunningTasks = std::map< int, int >
 Map fusable task (number) onto the number of the ProcessReadyTask which actually handles them.
 

Private Attributes

const int _type
 
ReadyTasks _readyTasks
 Tasks that are ready to go.
 
RunningTasks _runningTasks
 Tasks that are currently running.
 
tarch::multicore::BooleanSemaphore _readyTasksSemaphore
 
tarch::multicore::BooleanSemaphore _runningTasksSemaphore
 
tarch::multicore::BooleanSemaphore _statisticsSemaphore
 
tarch::timing::GlidingAverageMeasurement _numberOfReadyTasksPerProcessTaskExecution
 
tarch::timing::GlidingAverageMeasurement _probabilityThatTaskIsCompleted
 

Static Private Attributes

static tarch::logging::Log _log
 

Detailed Description

Represents a queue of fusable tasks.

Each queue object is tied to one particular task type. We can query this type via getType().

The task queue does not implement a particular task fusion strategy, but is a mere tool used by various strategies. The documentation of tarch::multicore::orchestration::FusionImplementation provides an overview of these strategies. That means: the queue itself offers a small set of operations, which is really all the tools you need to actually construct a fusion. The different strategies then differ in the way they use these operations, the order how they invoke them, and so forth.

Task states

The queue distinguishes three different task states: pending, ready and running. When we insert a task, we label it as either pending (with incoming dependencies which are not yet fulfilled) or ready. If the tasking subsystem manages to fullfill the in-dependencies of a pending task, it is the responsibility of the task system to move the task within the queue from pending to running through a call to movePendingTaskIntoReadyTaskQueue().

If tasks are starting to run, we have to label them as running as well. There are no routines for this, as the task queue is always paired up with instances of ProcessOneReadyTask or ProcessSetOfReadyTasks. See remark on the queue usage below.

Usage pattern

We hand over a task to the task queue either by inserting it directly into the task queue, or by telling the queue that a previously pending task has now become ready. After that, we have given up ownership of this fusable task. The ownership resides within the queue.

However, we can construct instances of ProcessOneReadyTask and ProcessSetOfReadyTasks over the task queue. They are responsible for the lifecycle management within the queue and allow us to work with the tasks that we have dumped into it.

The decision when or which of these two tasks to construct over the queue is influenced by the queue's status, as well as by our chosen task fusion strategy. All strategies handle the tasks within the queue by constructing new tasks of type ProcessOneReadyTask and ProcessSetOfReadyTasks over the task queue. If they wait for any of these tasks immediately, we have blocking semantics. As we issue the tasks in certain orders and quantities, we can construct various task processing patterns.

Definition at line 78 of file FusableTasksQueue.h.

Member Typedef Documentation

◆ ReadyTasks

Each task in the queue is identified through a pointer to the task plus a task (dependency) number.

Definition at line 198 of file FusableTasksQueue.h.

◆ RunningTasks

Map fusable task (number) onto the number of the ProcessReadyTask which actually handles them.

Definition at line 204 of file FusableTasksQueue.h.

Constructor & Destructor Documentation

◆ FusableTasksQueue() [1/2]

tarch::multicore::taskfusion::FusableTasksQueue::FusableTasksQueue ( int type_)

◆ ~FusableTasksQueue()

tarch::multicore::taskfusion::FusableTasksQueue::~FusableTasksQueue ( )
default

◆ FusableTasksQueue() [2/2]

tarch::multicore::taskfusion::FusableTasksQueue::FusableTasksQueue ( const FusableTasksQueue & )
delete

Member Function Documentation

◆ drainReadyTasks()

void tarch::multicore::taskfusion::FusableTasksQueue::drainReadyTasks ( )

Drain all the ready tasks.

This routine is used by tarch::multicore::taskfusion::processAllReadyTasks().

◆ extractFirstReadyTask()

std::pair< TaskNumber, Task * > tarch::multicore::taskfusion::FusableTasksQueue::extractFirstReadyTask ( TaskNumber handlingTask)

Get first ready task.

Takes the ready task out of the queue and also leaves an entry that handlingTask will handle this task.

Returns
Task* will be nullptr if there are no tasks left

◆ extractReadyTask() [1/2]

std::pair< TaskNumber, Task * > tarch::multicore::taskfusion::FusableTasksQueue::extractReadyTask ( TaskNumber handlingTask)

◆ extractReadyTask() [2/2]

Task * tarch::multicore::taskfusion::FusableTasksQueue::extractReadyTask ( TaskNumber taskNumber,
TaskNumber handlingTask )

Extract specific ready task.

◆ getFirstReadyTaskNumber()

TaskNumber tarch::multicore::taskfusion::FusableTasksQueue::getFirstReadyTaskNumber ( )

Return number of first ready task.

This routine gives you the number of the first ready task in the queue, or it returns tarch::multicore::NoOutDependencies if there's no task left. Even if you get a valid entry, there's no guarantee that this task still remains in the queue. Some ProcessSetOfReadyTasks instance might have grabbed it straight after this routine returned.

◆ getNumberOfReadyTasks()

int tarch::multicore::taskfusion::FusableTasksQueue::getNumberOfReadyTasks ( )

Query the number of ready tasks.

In principle, we would be fine with making this routine not thread-safe, i.e. we could accept if it returned a value smaller than the actual size. However, such an unsafe version confuses the thread sanitizer, and I'm also not sure if there could be further knock-on effects, so I eventually decided to make the routine thread-safe.

As we employ a sempahore internally, the routine cannot be const.

◆ getTaskHandlingRunningTask()

TaskNumber tarch::multicore::taskfusion::FusableTasksQueue::getTaskHandlingRunningTask ( TaskNumber taskNumber)

◆ getType()

int tarch::multicore::taskfusion::FusableTasksQueue::getType ( ) const

◆ insertReadyTask()

void tarch::multicore::taskfusion::FusableTasksQueue::insertReadyTask ( Task * task,
int taskNumber )

Insert a new ready task into the local queues.

Is used by run() but we might also want to use it externally. Before we insert the actual task, we also remove the task's completedTaskNumbers, so noone thinks ahead of time that we are done already.

◆ isTaskReady()

bool tarch::multicore::taskfusion::FusableTasksQueue::isTaskReady ( int taskNumber,
bool tryLock )

◆ isTaskReadyOrRunning()

bool tarch::multicore::taskfusion::FusableTasksQueue::isTaskReadyOrRunning ( int taskNumber,
bool tryLock )

◆ runningTaskFinished()

void tarch::multicore::taskfusion::FusableTasksQueue::runningTaskFinished ( TaskNumber taskNumber)

◆ updateTaskFusionProbabilities()

void tarch::multicore::taskfusion::FusableTasksQueue::updateTaskFusionProbabilities ( bool triggerFusion)

Update the internal stats.

This routine updates the internal statistics tied to the queue, and if there's a complete data set, it also dumps the stats into whoever will listen.

Semaphores

We obviously need to lock _statisticsSemaphore as we write into the statistics. But we also need to lock _readyTasksSemaphore as we read out the queue size.

Parameters
triggerFusionIf this is true, we have just triggered the fusion. If it is false however, then it means that we skip any fusion, as our task of interest has finished already.

Field Documentation

◆ _log

tarch::logging::Log tarch::multicore::taskfusion::FusableTasksQueue::_log
staticprivate

Definition at line 190 of file FusableTasksQueue.h.

◆ _numberOfReadyTasksPerProcessTaskExecution

tarch::timing::GlidingAverageMeasurement tarch::multicore::taskfusion::FusableTasksQueue::_numberOfReadyTasksPerProcessTaskExecution
private

Definition at line 220 of file FusableTasksQueue.h.

◆ _probabilityThatTaskIsCompleted

tarch::timing::GlidingAverageMeasurement tarch::multicore::taskfusion::FusableTasksQueue::_probabilityThatTaskIsCompleted
private

Definition at line 221 of file FusableTasksQueue.h.

◆ _readyTasks

ReadyTasks tarch::multicore::taskfusion::FusableTasksQueue::_readyTasks
private

Tasks that are ready to go.

Definition at line 209 of file FusableTasksQueue.h.

◆ _readyTasksSemaphore

tarch::multicore::BooleanSemaphore tarch::multicore::taskfusion::FusableTasksQueue::_readyTasksSemaphore
private

Definition at line 216 of file FusableTasksQueue.h.

◆ _runningTasks

RunningTasks tarch::multicore::taskfusion::FusableTasksQueue::_runningTasks
private

Tasks that are currently running.

Definition at line 214 of file FusableTasksQueue.h.

◆ _runningTasksSemaphore

tarch::multicore::BooleanSemaphore tarch::multicore::taskfusion::FusableTasksQueue::_runningTasksSemaphore
private

Definition at line 217 of file FusableTasksQueue.h.

◆ _statisticsSemaphore

tarch::multicore::BooleanSemaphore tarch::multicore::taskfusion::FusableTasksQueue::_statisticsSemaphore
private

Definition at line 219 of file FusableTasksQueue.h.

◆ _type

◆ AnyTask

constexpr int tarch::multicore::taskfusion::FusableTasksQueue::AnyTask = -1
staticconstexpr

Definition at line 80 of file FusableTasksQueue.h.

◆ LockQueueAndReturnReliableResult

constexpr bool tarch::multicore::taskfusion::FusableTasksQueue::LockQueueAndReturnReliableResult = false
staticconstexpr

Definition at line 163 of file FusableTasksQueue.h.

◆ SizeOfFusableTaskQueueStatisticsIdentifier

const std::string tarch::multicore::taskfusion::FusableTasksQueue::SizeOfFusableTaskQueueStatisticsIdentifier
static

Definition at line 82 of file FusableTasksQueue.h.

◆ UseTryLockAndReturnTrueIfLockFailed

constexpr bool tarch::multicore::taskfusion::FusableTasksQueue::UseTryLockAndReturnTrueIfLockFailed = true
staticconstexpr

Can be used with the queries below if you prefer those names over the boolean values.

Makes it clearer what a function does.

Definition at line 162 of file FusableTasksQueue.h.


The documentation for this class was generated from the following file: