Commit 164699cb authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

More efficient code, same behavior

parent db866d89
......@@ -48,24 +48,26 @@ int TrueHeteroPrio::chooseTask(int worker, double now) {
if (resultTask != -1)
unfavorable = ins->execType(wType, resultTask) > ins->execType(1-wType, resultTask);
bool otherTypeHasAnIdleProc = false;
int chosenVictim = -1;
if(resultTask == -1 || unfavorable) {
int bestTask = -1;
// Steal: copy/paste from GreedyPerType
for (int victim = 0; victim < ins->totalWorkers; victim++) {
int victimType = ins->getType(victim);
// ins->getType not efficient, but easier to read
if (victimType != wType && runningTasks[victim] != -1
&& ins->isValidType(wType, runningTasks[victim])
&& now + ins->execType(wType, runningTasks[victim]) < endTimesWorkers[victim]) {
int task = runningTasks[victim];
if(bestTask == -1 || isBetterSteal(task, endTimesWorkers[victim], bestTask, endTimesWorkers[chosenVictim], wType)) {
bestTask = task;
chosenVictim = victim;
}
}
}
int victim = wType == 1 ? 0 : ins->nbWorkers[0];
for(int i = 0; i < ins->nbWorkers[1-wType]; ++i,++victim){
int& task = runningTasks[victim];
if(task < 0)
otherTypeHasAnIdleProc = true;
else if(ins->isValidType(wType, task)
&& now + ins->execType(wType, task) < endTimesWorkers[victim]) {
if(bestTask == -1 || isBetterSteal(task, endTimesWorkers[victim], bestTask, endTimesWorkers[chosenVictim], wType)) {
bestTask = task;
chosenVictim = victim;
}
}
}
if(bestTask != -1) {
resultTask = bestTask;
chosenFromQueue = false;
......@@ -77,14 +79,6 @@ int TrueHeteroPrio::chooseTask(int worker, double now) {
if(resultTask == -1)
return -1;
int k = wType == 1 ? 0 : ins->nbWorkers[0];
bool otherTypeHasAnIdleProc = false;
for(int i = 0; i < ins->nbWorkers[1-wType]; ++i,++k){
if(runningTasks[k] < 0){
otherTypeHasAnIdleProc = true;
break;
}
}
if(otherTypeHasAnIdleProc && unfavorable)
// Stay idle if another processor could do better than me
return -1;
......
Markdown is supported
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