Commit 6a825295 authored by CARDOSI Paul's avatar CARDOSI Paul
Browse files

Simplify task manager listener notification logic.

Commit history :
Simplify task manager listener notification logic.

Assert was in wrong block.
parent 960831ed
#ifndef SPSCHEDULERINFORMER_HPP
#define SPSCHEDULERINFORMER_HPP
#ifndef SPTASKMANAGERLISTENER_HPP
#define SPTASKMANAGERLISTENER_HPP
class SpAbstractTask;
class SpAbstractToKnowReady{
class SpTaskManagerListener {
public:
virtual ~SpAbstractToKnowReady(){}
virtual ~SpTaskManagerListener(){}
virtual void thisTaskIsReady(SpAbstractTask*, const bool isNotCalledInAContextOfTaskCreation) = 0;
};
......
......@@ -20,9 +20,9 @@
#include "Utils/SpTimePoint.hpp"
#include "SpSimpleScheduler.hpp"
#include "SpPrioScheduler.hpp"
#include "SpSchedulerInformer.hpp"
#include "Utils/small_vector.hpp"
#include "Compute/SpComputeEngine.hpp"
#include "SpTaskManagerListener.hpp"
//! The runtime is the main component of spetabaru.
class SpTasksManager{
......@@ -77,7 +77,11 @@ class SpTasksManager{
aTask->setState(SpTaskState::READY);
aTask->releaseControl();
informAllReady<isNotCalledInAContextOfTaskCreation>(aTask);
auto l = listener.load();
if(l) {
l->thisTaskIsReady(aTask, isNotCalledInAContextOfTaskCreation);
}
if(!ce) {
readyTasks.push_back(aTask);
......@@ -100,43 +104,17 @@ class SpTasksManager{
}
///////////////////////////////////////////////////////////////////////////////////////
std::atomic<SpTaskManagerListener*> listener;
std::mutex listenersReadyMutex;
small_vector<SpAbstractToKnowReady*> listenersReady;
template <const bool isNotCalledInAContextOfTaskCreation>
void informAllReady(SpAbstractTask* aTask){
if constexpr (isNotCalledInAContextOfTaskCreation){
listenersReadyMutex.lock();
}
for(SpAbstractToKnowReady* listener : listenersReady){
listener->thisTaskIsReady(aTask, isNotCalledInAContextOfTaskCreation);
}
if constexpr (isNotCalledInAContextOfTaskCreation){
listenersReadyMutex.unlock();
}
}
public:
void lockListenersReadyMutex(){
listenersReadyMutex.lock();
}
void unlockListenersReadyMutex(){
listenersReadyMutex.unlock();
}
void registerListener(SpAbstractToKnowReady* aListener){
std::unique_lock<std::mutex> locker(listenersReadyMutex);
listenersReady.push_back(aListener);
void setListener(SpTaskManagerListener* inListener){
listener = inListener;
}
///////////////////////////////////////////////////////////////////////////////////////
explicit SpTasksManager() : ce(nullptr), nbRunningTasks(0), nbPushedTasks(0), nbReadyTasks(0), nbFinishedTasks(0) {}
explicit SpTasksManager() : ce(nullptr), nbRunningTasks(0), nbPushedTasks(0), nbReadyTasks(0), nbFinishedTasks(0), listener(nullptr) {}
// No copy or move
SpTasksManager(const SpTasksManager&) = delete;
......
......@@ -28,6 +28,7 @@
#include "Speculation/SpSpeculativeModel.hpp"
#include "SpAbstractTaskGraph.hpp"
#include "Compute/SpComputeEngine.hpp"
#include "Schedulers/SpTaskManagerListener.hpp"
template <const bool isSpeculativeTaskGraph>
class SpTaskGraphCommon : public SpAbstractTaskGraph {
......@@ -288,7 +289,7 @@ protected:
};
template <SpSpeculativeModel SpecModel = SpSpeculativeModel::SP_MODEL_1>
class SpTaskGraph : public SpTaskGraphCommon<true>, public SpAbstractToKnowReady {
class SpTaskGraph : public SpTaskGraphCommon<true>, public SpTaskManagerListener {
static_assert(SpecModel == SpSpeculativeModel::SP_MODEL_1
|| SpecModel == SpSpeculativeModel::SP_MODEL_2
......@@ -582,8 +583,7 @@ private:
template <const bool isPotentialTask, class CallableTupleTy, class DataDependencyTupleTy>
auto preCoreTaskCreation(const SpPriority& inPriority, const SpProbability& inProbability, DataDependencyTupleTy&& dataDepTuple, CallableTupleTy&& callableTuple) {
this->scheduler.lockListenersReadyMutex();
specGroupMutex.lock();
std::unique_lock<std::mutex> lock(specGroupMutex);
bool isPathResultingFromMerge = false;
auto executionPaths = getCorrespondingExecutionPaths(std::forward<DataDependencyTupleTy>(dataDepTuple));
......@@ -695,9 +695,6 @@ private:
removeOriginalAddressesFromHashMap(originalAddressesOfWrittenHandles);
}
}
specGroupMutex.unlock();
this->scheduler.unlockListenersReadyMutex();
return res;
}
......@@ -1518,29 +1515,17 @@ private:
///////////////////////////////////////////////////////////////////////////
void thisTaskIsReady(SpAbstractTask* aTask, const bool isNotCalledInAContextOfTaskCreation) final {
SpGeneralSpecGroup<SpecModel>* specGroup = aTask->getSpecGroup<SpGeneralSpecGroup<SpecModel>>();
SpDebugPrint() << "SpTaskGraph -- thisTaskIsReady -- will test ";
/*
* ATTENTION!
* TO DO :
* We should verify that this double checking doesn't cause any trouble.
*/
if(isNotCalledInAContextOfTaskCreation){
specGroupMutex.lock();
}
SpGeneralSpecGroup<SpecModel>* specGroup = aTask->getSpecGroup<SpGeneralSpecGroup<SpecModel>>();
if(specGroup && specGroup->isSpeculationNotSet()){
if(isNotCalledInAContextOfTaskCreation){
specGroupMutex.lock();
}
if(specGroup->isSpeculationNotSet()){
if(specFormula){
if(specFormula(this->scheduler.getNbReadyTasks(), specGroup->getAllProbability())){
SpDebugPrint() << "SpTaskGraph -- thisTaskIsReady -- enableSpeculation ";
specGroup->setSpeculationActivation(true);
}
else{
specGroup->setSpeculationActivation(false);
}
}
else if(this->scheduler.getNbReadyTasks() == 0){
if(specFormula){
if(specFormula(this->scheduler.getNbReadyTasks(), specGroup->getAllProbability())){
SpDebugPrint() << "SpTaskGraph -- thisTaskIsReady -- enableSpeculation ";
specGroup->setSpeculationActivation(true);
}
......@@ -1548,13 +1533,20 @@ private:
specGroup->setSpeculationActivation(false);
}
}
if(isNotCalledInAContextOfTaskCreation){
specGroupMutex.unlock();
else if(this->scheduler.getNbReadyTasks() == 0){
SpDebugPrint() << "SpTaskGraph -- thisTaskIsReady -- enableSpeculation ";
specGroup->setSpeculationActivation(true);
}
else{
specGroup->setSpeculationActivation(false);
}
assert(!specGroup->isSpeculationNotSet());
}
if(isNotCalledInAContextOfTaskCreation){
specGroupMutex.unlock();
}
}
//=====--------------------=====
......@@ -1566,7 +1558,7 @@ public:
///////////////////////////////////////////////////////////////////////////
explicit SpTaskGraph() : currentSpecGroup(nullptr) {
this->scheduler.registerListener(this);
this->scheduler.setListener(this);
}
///////////////////////////////////////////////////////////////////////////
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment