MelaniButtazzo.java 3.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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;
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;

21
    public MelaniButtazzo(final long numberOfProcessors) {
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
        super(numberOfProcessors);
        this.responseTimes = new HashMap<>();
        this.priorityManager = new RateMonotonic();
    }

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

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

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

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

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

        do {
            previousResponseTime = responseTime;
            double taskInterference = 0;

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

            taskInterference /= numberOfProcessors;
64
            final double selfInterference = getSelfInterference(task);
65

66
            final long totalInterference = (long) Math.floor(taskInterference + selfInterference);
67 68 69 70 71 72 73

            responseTime = minimumWcet + totalInterference;
        } while (previousResponseTime != responseTime);

        return responseTime;
    }

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

        return (double) (workload - criticalPath) / numberOfProcessors;
    }


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

88
            final double nominator =
89
                    (interval + responseTime - (double) singleWorkload / numberOfProcessors);
90 91
            final long amountOfJobs =
                    DoubleMath.roundToLong(nominator / period, RoundingMode.FLOOR);
92

93
            final double carryOutPortion =
94 95
                    Math.min(singleWorkload, numberOfProcessors * (nominator % period));

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


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

}