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

3 4
import java.util.HashMap;
import java.util.Map;
5
import java.util.Set;
6 7
import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.TerminationInfo;
8
import mvd.jester.model.DagTask;
9
import mvd.jester.model.SortedTaskSet;
Michael Schmid committed
10
import mvd.jester.model.SystemManager;
11
import mvd.jester.model.Task;
12
import mvd.jester.priority.PriorityManager;
13
import mvd.jester.priority.RateMonotonic;
14 15 16 17

/**
 * SchmidMottok
 */
18
public class SchmidMottok extends AbstractTest<DagTask> {
19

20 21
    private final Map<Task, TerminationInfo> responseTimes;
    private final PriorityManager priorityManager;
22
    private final TypeFunction structure;
23

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

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

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

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

    @Override
    public String getName() {
49
        return "SchmidMottok" + "_" + structure.getType();
50 51
    }

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

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

61 62 63 64 65 66 67 68
            long occupiedProcessors = manager.getNumberOfProcessors() + 1;
            // for (final DagTask t : tasks) {
            // if (t.getPeriod() < task.getPeriod()) {
            // final long numberOfProcessors = structure.getNumerOfThreads(t);
            // occupiedProcessors += numberOfProcessors;
            // }
            // }

69
            for (final DagTask t : tasks) {
70
                if (t.getPeriod() < task.getPeriod()) {
71 72 73 74 75 76 77 78 79
                    final long numberOfProcessors = structure.getNumerOfThreads(t);
                    for (int p = 0; p < numberOfProcessors; ++p) {
                        if (occupiedProcessors > manager.getNumberOfProcessors()) {
                            taskInterference +=
                                    Math.min(
                                            structure.getTaskInterference(t, responseTimes,
                                                    responseTime, p + 1),
                                            responseTime - minimumWcet + 1);
                        }
Michael Schmid committed
80
                    }
81 82 83
                }
            }

Michael Schmid committed
84
            taskInterference /= manager.getNumberOfProcessors();
85
            final double selfInterference = structure.getSelfInterference(task);
86

87
            final long totalInterference = (long) Math.floor(taskInterference + selfInterference);
88 89 90 91 92 93 94 95

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

        return responseTime;
    }

}