SchmidMottok.java 4.1 KB
Newer Older
1 2 3
package mvd.jester.tests;

import java.math.RoundingMode;
4 5
import java.util.HashMap;
import java.util.Map;
6
import java.util.Set;
7
import com.google.common.math.LongMath;
8 9
import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.TerminationInfo;
10
import mvd.jester.model.DagTask;
11
import mvd.jester.model.Segment;
12
import mvd.jester.model.SortedTaskSet;
Michael Schmid committed
13
import mvd.jester.model.SystemManager;
14
import mvd.jester.model.Task;
15
import mvd.jester.priority.PriorityManager;
16
import mvd.jester.priority.RateMonotonic;
17 18 19 20

/**
 * SchmidMottok
 */
21
public class SchmidMottok extends AbstractTest<DagTask> {
22

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

Michael Schmid committed
26 27
    public SchmidMottok(final SystemManager manager) {
        super(manager);
28 29
        this.responseTimes = new HashMap<>();
        this.priorityManager = new RateMonotonic();
30 31 32
    }

    @Override
33 34 35 36 37
    public PriorityManager getPriorityManager() {
        return priorityManager;
    }

    @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 50 51 52
    }

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

53 54
    private long calculateResponseTime(final Set<DagTask> tasks, final DagTask task) {
        final long minimumWcet = task.getCriticalPath();
55 56 57 58 59
        long responseTime = minimumWcet;
        long previousResponseTime = 0;

        do {
            previousResponseTime = responseTime;
60
            double taskInterference = 0;
61

62
            for (final DagTask t : tasks) {
63
                if (t.getPeriod() < task.getPeriod()) {
64
                    final long numberOfThreads = t.getNumberOfThreads();
65
                    for (int p = 0; p < numberOfThreads; ++p) {
66
                        taskInterference += Math.min(getTaskInterference(t, responseTime, p + 1),
Michael Schmid committed
67 68
                                responseTime - minimumWcet + 1);
                    }
69 70 71
                }
            }

Michael Schmid committed
72
            taskInterference /= manager.getNumberOfProcessors();
73
            final double selfInterference = getSelfInterference(task);
74

75
            final long totalInterference = (long) Math.floor(taskInterference + selfInterference);
76 77 78 79 80 81 82 83

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

        return responseTime;
    }


84
    private double getSelfInterference(final DagTask task) {
Michael Schmid committed
85 86 87
        // final long numberOfThreads = task.getNumberOfThreads();
        // TODO: Change back to number of threads
        final long numberOfThreads = manager.getNumberOfProcessors();
88

Michael Schmid committed
89
        double interference = task.getWorkload() - task.getCriticalPath();
90
        interference /= numberOfThreads;
91

92 93 94
        return interference;
    }

Michael Schmid committed
95

96 97
    private double getTaskInterference(final DagTask task, final long interval,
            final long parallelism) {
Michael Schmid committed
98
        if (responseTimes.containsKey(task)) {
99 100 101 102
            final long responseTime = responseTimes.get(task).getResponseTime();
            final long minWcet = task.getCriticalPath();
            final long period = task.getPeriod();
            final long amountOfJobs =
Michael Schmid committed
103 104 105 106 107
                    (LongMath.divide(interval + responseTime - minWcet, period, RoundingMode.FLOOR)
                            + 1);

            double workload = 0;

108 109 110
            for (final Segment s : task.getWorkloadDistribution()) {
                final long numberOfThreads =
                        s.getNumberOfJobs() > 1 ? task.getNumberOfThreads() : 1;
111 112
                if (numberOfThreads >= parallelism) {
                    workload += s.getNumberOfJobs() * s.getJobWcet() / numberOfThreads;
Michael Schmid committed
113 114
                }
            }
115

116
            final double interference = amountOfJobs * workload;
Michael Schmid committed
117 118 119 120 121

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

}