MelaniButtazzo.java 3.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
package mvd.jester.tests;

import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.google.common.math.DoubleMath;
import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.TerminationInfo;
import mvd.jester.model.DagTask;
import mvd.jester.model.SortedTaskSet;
Michael Schmid committed
12
import mvd.jester.model.SystemManager;
13 14 15 16 17 18 19 20 21
import mvd.jester.model.Task;
import mvd.jester.priority.PriorityManager;
import mvd.jester.priority.RateMonotonic;

public class MelaniButtazzo extends AbstractTest<DagTask> {

    private final Map<Task, TerminationInfo> responseTimes;
    private final PriorityManager priorityManager;

Michael Schmid committed
22 23
    public MelaniButtazzo(final SystemManager manager) {
        super(manager);
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
        this.responseTimes = new HashMap<>();
        this.priorityManager = new RateMonotonic();
    }

    @Override
    public PriorityManager getPriorityManager() {
        return priorityManager;
    }

    @Override
    public String getName() {
        return "MelaniButtazzo";
    }

    @Override
39
    public SchedulingInfo runSchedulabilityCheck(final SortedTaskSet<DagTask> tasks) {
40
        responseTimes.clear();
41 42 43
        for (final DagTask t : tasks) {
            final long responseTime = calculateResponseTime(tasks, t);
            responseTimes.put(t, new TerminationInfo(t.getDeadline(), responseTime));
44 45
        }

46
        return new SchedulingInfo(responseTimes.values());
47 48
    }

49
    private long calculateResponseTime(final Set<DagTask> tasks, final DagTask task) {
Michael Schmid committed
50 51
        final long criticalPath = task.getCriticalPath();
        long responseTime = criticalPath;
52 53 54 55 56 57
        long previousResponseTime = 0;

        do {
            previousResponseTime = responseTime;
            double taskInterference = 0;

58
            for (final DagTask t : tasks) {
59 60 61 62 63
                if (t.getPeriod() < task.getPeriod()) {
                    taskInterference += getTaskInterference(t, responseTime);
                }
            }

Michael Schmid committed
64
            taskInterference /= manager.getNumberOfProcessors();
65
            final double selfInterference = getSelfInterference(task);
Michael Schmid committed
66
            // TODO: Einzeln abrunden oder self interference als long abrunden
67
            final long totalInterference = (long) Math.floor(taskInterference + selfInterference);
68

Michael Schmid committed
69
            responseTime = criticalPath + totalInterference;
70 71 72 73 74
        } while (previousResponseTime != responseTime);

        return responseTime;
    }

75 76 77
    private double getSelfInterference(final DagTask task) {
        final long criticalPath = task.getCriticalPath();
        final long workload = task.getWorkload();
78

Michael Schmid committed
79
        return (double) (workload - criticalPath) / manager.getNumberOfProcessors();
80 81 82
    }


83
    private double getTaskInterference(final DagTask task, final long interval) {
84
        if (responseTimes.containsKey(task)) {
85 86 87
            final long responseTime = responseTimes.get(task).getResponseTime();
            final long singleWorkload = task.getWorkload();
            final long period = task.getPeriod();
88

Michael Schmid committed
89 90
            final double nominator = (interval + responseTime
                    - (double) singleWorkload / manager.getNumberOfProcessors());
91 92
            final long amountOfJobs =
                    DoubleMath.roundToLong(nominator / period, RoundingMode.FLOOR);
93

Michael Schmid committed
94 95
            final double carryOutPortion = Math.min(singleWorkload,
                    manager.getNumberOfProcessors() * (nominator % period));
96

97
            final double interference = amountOfJobs * singleWorkload + carryOutPortion;
98 99 100 101 102 103 104 105 106


            return interference;
        } else {
            throw new RuntimeException("Task was not found in task set!");
        }
    }

}